Buildings.Utilities.Plotters

Package with blocks to create plots

Information

Package with blocks that allow generating time series and scatter plots, and writing these plots to one or several html files. The plots can be deactivated based on an input signal and a time delay, for example, to plot data only while the HVAC system operates for at least 30 minutes.

See Buildings.Utilities.Plotters.UsersGuide for instructions.

Extends from Modelica.Icons.Package (Icon for standard packages).

Package Content

Name Description
Buildings.Utilities.Plotters.UsersGuide UsersGuide User's Guide
Buildings.Utilities.Plotters.Configuration Configuration Configuration for plotters
Buildings.Utilities.Plotters.Scatter Scatter Block that plots one or multiple scatter plots
Buildings.Utilities.Plotters.TimeSeries TimeSeries Block that plots one or multiple time series
Buildings.Utilities.Plotters.Types Types Package with type definitions
Buildings.Utilities.Plotters.Examples Examples Collection of models that illustrate model use and test models
Buildings.Utilities.Plotters.Validation Validation Collection of validation models
Buildings.Utilities.Plotters.BaseClasses BaseClasses Package with base classes for Buildings.Utilities.Plotters

Buildings.Utilities.Plotters.Configuration Buildings.Utilities.Plotters.Configuration

Configuration for plotters

Buildings.Utilities.Plotters.Configuration

Information

This block can be used to globally configure the parameters for the blocks from the package Buildings.Utilities.Plotters. Use this block for example to set the same plot file name and sampling time.

To use this block, simply drag it at the top-most level, or higher, where your plotters are.

Extends from Modelica.Blocks.Icons.Block (Basic graphical layout of input/output block).

Parameters

TypeNameDefaultDescription
TimesamplePeriod Sample period of component [s]
StringfileNameModelica.Utilities.Files.ful...Name of html file
Labels
TimeUnittimeUnitTypes.TimeUnit.hoursTime unit for plot
Activation
GlobalActivationactivationBuildings.Utilities.Plotters...Set to true to enable an input that allows activating and deactivating the plotting
TimeactivationDelay0Time that needs to elapse to enable plotting after activate becomes true [s]

Connectors

TypeNameDescription
input BooleanInputactivateSet to true to enable plotting of time series after activationDelay elapsed

Modelica definition

model Configuration "Configuration for plotters" extends Modelica.Blocks.Icons.Block; parameter Modelica.SIunits.Time samplePeriod(min=1E-3) "Sample period of component"; parameter String fileName = Modelica.Utilities.Files.fullPathName("plots.html") "Name of html file"; parameter Buildings.Utilities.Plotters.Types.TimeUnit timeUnit = Types.TimeUnit.hours "Time unit for plot"; parameter Buildings.Utilities.Plotters.Types.GlobalActivation activation= Buildings.Utilities.Plotters.Types.GlobalActivation.always "Set to true to enable an input that allows activating and deactivating the plotting"; parameter Modelica.SIunits.Time activationDelay(min=0)=0 "Time that needs to elapse to enable plotting after activate becomes true"; Modelica.Blocks.Interfaces.BooleanInput activate if (activation == Buildings.Utilities.Plotters.Types.GlobalActivation.use_input) "Set to true to enable plotting of time series after activationDelay elapsed"; Boolean active "Flag, true if plots record data"; protected Modelica.Blocks.Interfaces.BooleanInput activate_internal "Internal connector to activate plots"; discrete Modelica.SIunits.Time tActivateLast "Time when plotter was the last time activated"; initial equation tActivateLast = time-2*activationDelay; equation if (activation == Buildings.Utilities.Plotters.Types.GlobalActivation.use_input) then connect(activate, activate_internal); else activate_internal = true; end if; when (activate_internal) then tActivateLast = time; end when; active = activate_internal and time >= tActivateLast + activationDelay; end Configuration;

Buildings.Utilities.Plotters.Scatter Buildings.Utilities.Plotters.Scatter

Block that plots one or multiple scatter plots

Buildings.Utilities.Plotters.Scatter

Information

Block that plots n time series that are connected at the input port y against the independent data that are connected at the input port x.

To use this block, set the parameter n to the number of time series y that you like to plot against x. Then, connect the signals for the independent data to x and the signals for the dependent data to y.

There can be multiple instances of this block. If they share the same value for fileName, then they will add their plot to the same output file. For convenience, we recommend to drag an instance of Buildings.Utilities.Plotters.Configuration at the top-level of your model. This instance can then be used to globally set the fileName and the samplePeriod for all plotters.

Extends from Buildings.Utilities.Plotters.BaseClasses.PartialPlotter (Partial block for plotters).

Parameters

TypeNameDefaultDescription
StringfileNameplotConfiguration.fileNameName of html file
Stringintroduction""Introduction text written below title and above the plot
Activation
TimesamplePeriodplotConfiguration.samplePeriodSample period of component [s]
LocalActivationactivationBuildings.Utilities.Plotters...Set to true to enable an input that allows activating and deactivating the plotting
TimeactivationDelayplotConfiguration.activation...Time that needs to elapse to enable plotting after activate becomes true [s]
Labels
StringtitlegetInstanceName()Title of the plot
Stringlegend[n] String array for legend, such as {"x1", "x2"}
Stringxlabel""x-label

Connectors

TypeNameDescription
input RealVectorInputy[n]y-data
input BooleanInputactivateSet to true to enable plotting of time series after activationDelay elapsed
input RealInputxx-data

Modelica definition

block Scatter "Block that plots one or multiple scatter plots" extends Buildings.Utilities.Plotters.BaseClasses.PartialPlotter; parameter String xlabel = "" "x-label"; Modelica.Blocks.Interfaces.RealInput x "x-data"; initial algorithm for i in 1:n loop Buildings.Utilities.Plotters.BaseClasses.sendTerminalString( plt=plt, string=" const struct_" + insNam + String(i) + " = { x: " + insNam + "[0], y: " + insNam + "[" + String(i) + "], type: 'scatter', " + plotMode + " name: '" + legend[i] + "' }; "); end for; Buildings.Utilities.Plotters.BaseClasses.sendTerminalString( plt=plt, string=" var data_" + insNam + " = ["); // Loop over all variables, and print them to the C implementation. // We print frequently as Dymola truncates the string if it becomes // too long. for i in 1:n loop Buildings.Utilities.Plotters.BaseClasses.sendTerminalString( plt=plt, string="struct_" + insNam + String(i)); Buildings.Utilities.Plotters.BaseClasses.sendTerminalString( plt=plt, string= if (i < n) then "," else "];"); end for; // Plot layout Buildings.Utilities.Plotters.BaseClasses.sendTerminalString( plt=plt, string=" var layout_" + insNam + " = { xaxis: { title: '" + xlabel + "'}" + (if (n == 1) then ", yaxis: { title: '" + legend[1] + "'}" else "") + " }; Plotly.newPlot('" + insNam + "', data_" + insNam + ", layout_" + insNam + "); </script> "); equation when sampleTrigger then Buildings.Utilities.Plotters.BaseClasses.sendReal( plt=plt, x = cat(1, {x}, y)); end when; end Scatter;

Buildings.Utilities.Plotters.TimeSeries Buildings.Utilities.Plotters.TimeSeries

Block that plots one or multiple time series

Buildings.Utilities.Plotters.TimeSeries

Information

Block that plots n time series.

To use this block, set the parameter n to the number of time series that you like to plot. Then, connect the signals for these time series to the input port y.

There can be multiple instances of this block. If they share the same value for fileName, then they will add their plot to the same output file. For convenience, we recommend to drag an instance of Buildings.Utilities.Plotters.Configuration at the top-level of your model. This instance can then be used to globally set the fileName and the samplePeriod for all plotters.

Extends from Buildings.Utilities.Plotters.BaseClasses.PartialPlotter (Partial block for plotters).

Parameters

TypeNameDefaultDescription
StringfileNameplotConfiguration.fileNameName of html file
Stringintroduction""Introduction text written below title and above the plot
Activation
TimesamplePeriodplotConfiguration.samplePeriodSample period of component [s]
LocalActivationactivationBuildings.Utilities.Plotters...Set to true to enable an input that allows activating and deactivating the plotting
TimeactivationDelayplotConfiguration.activation...Time that needs to elapse to enable plotting after activate becomes true [s]
Labels
StringtitlegetInstanceName()Title of the plot
Stringlegend[n] String array for legend, such as {"x1", "x2"}
TimeUnittimeUnitplotConfiguration.timeUnitTime unit for plot

Connectors

TypeNameDescription
input RealVectorInputy[n]y-data
input BooleanInputactivateSet to true to enable plotting of time series after activationDelay elapsed

Modelica definition

block TimeSeries "Block that plots one or multiple time series" extends Buildings.Utilities.Plotters.BaseClasses.PartialPlotter; parameter Buildings.Utilities.Plotters.Types.TimeUnit timeUnit= plotConfiguration.timeUnit "Time unit for plot"; protected final parameter String timeUnitString= if timeUnit == Types.TimeUnit.seconds then "s" elseif timeUnit == Types.TimeUnit.minutes then "min" elseif timeUnit == Types.TimeUnit.hours then "h" else "d" "String for time unit that is used in the plotter"; Real timeConverted "Time converted to display unit"; initial algorithm timeConverted := 0; for i in 1:n loop Buildings.Utilities.Plotters.BaseClasses.sendTerminalString( plt=plt, string=" const struct_" + insNam + String(i) + " = { x: " + insNam + "[0], y: " + insNam + "[" + String(i) + "], type: 'scatter', " + plotMode + " name: '" + legend[i] + "' };"); end for; Buildings.Utilities.Plotters.BaseClasses.sendTerminalString( plt=plt, string=" var data_" + insNam + " = ["); // Loop over all variables, and print them to the C implementation. // We print frequently as Dymola truncates the string if it becomes // too long. for i in 1:n loop Buildings.Utilities.Plotters.BaseClasses.sendTerminalString( plt=plt, string="struct_" + insNam + String(i)); Buildings.Utilities.Plotters.BaseClasses.sendTerminalString( plt=plt, string= if (i < n) then "," else "];"); end for; // Plot layout Buildings.Utilities.Plotters.BaseClasses.sendTerminalString( plt=plt, string=" var layout_" + insNam + " = { xaxis: { title: 'time [" + timeUnitString + "]'} }; Plotly.newPlot('" + insNam + "', data_" + insNam + ", layout_" + insNam + "); </script> "); equation when sampleTrigger then if timeUnit == Buildings.Utilities.Plotters.Types.TimeUnit.seconds then timeConverted = time; elseif timeUnit == Buildings.Utilities.Plotters.Types.TimeUnit.minutes then timeConverted = time/60.; elseif timeUnit == Buildings.Utilities.Plotters.Types.TimeUnit.hours then timeConverted = time/3600.; else timeConverted = time/86400.; end if; Buildings.Utilities.Plotters.BaseClasses.sendReal( plt=plt, x = cat(1, {timeConverted}, y)); end when; end TimeSeries;