Buildings.Occupants.BaseClasses

Package with base classes for Buildings.Occupants

Information

This package contains base functions which will be used in the Modelica Building Occupancy simulation module. The functions included in this package would map the inputs, for instance the indoor/output temperature, to two kinds of outputs: on/off state or the duration of a specific state.

Extends from Modelica.Icons.BasesPackage (Icon for packages containing base classes).

Package Content

Name Description
Buildings.Occupants.BaseClasses.binaryVariableGeneration binaryVariableGeneration Binary variables random generator
Buildings.Occupants.BaseClasses.exponentialVariableGeneration exponentialVariableGeneration Random variable generator from the exponential distribution
Buildings.Occupants.BaseClasses.linear1D linear1D Mapping a continuous input to a binary output through a linear relation
Buildings.Occupants.BaseClasses.logit1D logit1D Mapping a continuous input to a binary output through a logistic relation
Buildings.Occupants.BaseClasses.logit1DQuadratic logit1DQuadratic Mapping a continuous input to a binary output through a quadratic logistic relation
Buildings.Occupants.BaseClasses.logit2D logit2D Mapping two continuous inputs to a binary output through a 2-dimension logistic relation
Buildings.Occupants.BaseClasses.weibull1DOFF weibull1DOFF Mapping a continuous input to a binary output through a Weibull Distribution Relation
Buildings.Occupants.BaseClasses.weibull1DON weibull1DON Mapping a continuous input to a binary output through a Weibull Distribution Relation
Buildings.Occupants.BaseClasses.weibullVariableGeneration weibullVariableGeneration Random variable generator from the Weibull distribution
Buildings.Occupants.BaseClasses.Validation Validation Package with examples to validate functions in BaseClasses package

Buildings.Occupants.BaseClasses.binaryVariableGeneration

Binary variables random generator

Information

Function that generates a random binary variable with the input of probability p.

The input p denotes the probability of being true. Higher p indicates a higher chance of generating true.

Inputs

TypeNameDefaultDescription
Realpp(min=0, max=1)Probaility of 1
IntegerglobalSeed Seed for the random number generator

Outputs

TypeNameDescription
BooleanyRandom number

Modelica definition

function binaryVariableGeneration "Binary variables random generator" input Real p(min=0, max=1) "Probaility of 1"; input Integer globalSeed "Seed for the random number generator"; output Boolean y "Random number"; protected Integer localSeed "Local seed"; Integer state[Modelica.Math.Random.Generators.Xorshift1024star.nState]; Real r(min=0, max=1) "Generated random number"; algorithm state := Modelica.Math.Random.Generators.Xorshift1024star.initialState(localSeed, globalSeed); (r, state) := Modelica.Math.Random.Generators.Xorshift1024star.random(state); y := r < p; end binaryVariableGeneration;

Buildings.Occupants.BaseClasses.exponentialVariableGeneration

Random variable generator from the exponential distribution

Information

This function generates a random variable, from a exponentuial distribution with the input of mean mu. The random variable might be the duration of a specific event, for instance the time to keep the HVAC on.

The input mu denotes the mean value of the exponential distribution. Higher mu indicates a higher chance to generate a larger output y.

Inputs

TypeNameDefaultDescription
Realmu Mean exponential distribution
IntegerglobalSeed Seed for the random number generator

Outputs

TypeNameDescription
Realyduration of event

Modelica definition

function exponentialVariableGeneration "Random variable generator from the exponential distribution" input Real mu "Mean exponential distribution"; input Integer globalSeed "Seed for the random number generator"; output Real y "duration of event"; protected Integer localSeed; Integer state[Modelica.Math.Random.Generators.Xorshift1024star.nState]; Real r "Generated random numberin the range 0 < random ≤ 1"; algorithm state := Modelica.Math.Random.Generators.Xorshift1024star.initialState(localSeed, globalSeed); (r, state) := Modelica.Math.Random.Generators.Xorshift1024star.random(state); y := -mu * Modelica.Math.log(1 - r); end exponentialVariableGeneration;

Buildings.Occupants.BaseClasses.linear1D

Mapping a continuous input to a binary output through a linear relation

Information

This function generates a random binary variable with the input of a continuous variable x from a linear relation.

The probability of being 1 is calculated from the input x with the slope A and the intercept B. Then a random generator generates the output, which should be a binary variable.

Inputs

TypeNameDefaultDescription
Realx Continuous variable
RealA1Slope of the linear function
RealB0Intercept of the linear function
IntegerglobalSeed Seed for the random number generator

Outputs

TypeNameDescription
BooleanyBinary variable

Modelica definition

function linear1D "Mapping a continuous input to a binary output through a linear relation" input Real x "Continuous variable"; input Real A=1 "Slope of the linear function"; input Real B=0 "Intercept of the linear function"; input Integer globalSeed "Seed for the random number generator"; output Boolean y "Binary variable"; algorithm y := Buildings.Occupants.BaseClasses.binaryVariableGeneration(max(0, min(1, A*x+B)), globalSeed); end linear1D;

Buildings.Occupants.BaseClasses.logit1D

Mapping a continuous input to a binary output through a logistic relation

Information

This function generates a random binary variable with the input of a continuous variable x from a logistic relation.

The probability of being 1 is calculated from the input x from a logistic relation with the slope A and the intercept B. Then a random generator generates the output, which should be a binary variable.

Inputs

TypeNameDefaultDescription
Realx Continuous variable
RealA1.0Logistic relation: Slope
RealB1.0Logistic relation: Intercept
IntegerglobalSeed Seed for the random number generator

Outputs

TypeNameDescription
BooleanyBinary variable

Modelica definition

function logit1D "Mapping a continuous input to a binary output through a logistic relation" input Real x "Continuous variable"; input Real A=1.0 "Logistic relation: Slope"; input Real B=1.0 "Logistic relation: Intercept"; input Integer globalSeed "Seed for the random number generator"; output Boolean y "Binary variable"; algorithm y := Buildings.Occupants.BaseClasses.binaryVariableGeneration( Modelica.Math.exp(A*x+B)/(Modelica.Math.exp(A*x+B)+1), globalSeed); end logit1D;

Buildings.Occupants.BaseClasses.logit1DQuadratic

Mapping a continuous input to a binary output through a quadratic logistic relation

Information

This function generates a random binary variable with the input of a continuous variable x from a quadratic logistic relation.

The probability of being 1 is calculated from the input x from a quadratic logistic relation with four predefined parameters A, B, C and D. Then a random generator generates the output, which should be a binary variable.

Inputs

TypeNameDefaultDescription
Realx Continous variable
RealA1.0Parameter defining the quadratic logistic relation
RealB1.0Parameter defining the quadratic logistic relation
RealC1.0Parameter defining the quadratic logistic relation
RealD1.0Parameter defining the quadratic logistic relation
IntegerglobalSeed Seed for the random number generator

Outputs

TypeNameDescription
BooleanyBinary variable

Modelica definition

function logit1DQuadratic "Mapping a continuous input to a binary output through a quadratic logistic relation" input Real x "Continous variable"; input Real A=1.0 "Parameter defining the quadratic logistic relation"; input Real B=1.0 "Parameter defining the quadratic logistic relation"; input Real C=1.0 "Parameter defining the quadratic logistic relation"; input Real D=1.0 "Parameter defining the quadratic logistic relation"; input Integer globalSeed "Seed for the random number generator"; output Boolean y "Binary variable"; algorithm y := Buildings.Occupants.BaseClasses.binaryVariableGeneration( A + C/(1+ Modelica.Math.exp(-B*(Modelica.Math.log10(x)-D))), globalSeed); end logit1DQuadratic;

Buildings.Occupants.BaseClasses.logit2D

Mapping two continuous inputs to a binary output through a 2-dimension logistic relation

Information

This function generates a random binary variable with two inputs x1 and x2 from a 2-dimension logistic relation.

The probability of being 1 is calculated from the inputs x1 and x2 from a 2D logistic relation with three predefined parameters A (mutiplier for x1), B (mutiplier for x2) and C (intercept). Then a random generator generates the output, which should be a binary variable.

Inputs

TypeNameDefaultDescription
Realx1 The first input variable
Realx2 The second input variable
RealA1.0Parameter defining the 2D logistic relation: mutiplier for the first input
RealB1.0Parameter defining the 2D logistic relation: mutiplier for the second input
RealC1.0Parameter defining the 2D logistic relation: intercept
IntegerglobalSeed Seed for the random number generator

Outputs

TypeNameDescription
BooleanyBinary variable

Modelica definition

function logit2D "Mapping two continuous inputs to a binary output through a 2-dimension logistic relation" input Real x1 "The first input variable"; input Real x2 "The second input variable"; input Real A=1.0 "Parameter defining the 2D logistic relation: mutiplier for the first input"; input Real B=1.0 "Parameter defining the 2D logistic relation: mutiplier for the second input"; input Real C=1.0 "Parameter defining the 2D logistic relation: intercept"; input Integer globalSeed "Seed for the random number generator"; output Boolean y "Binary variable"; algorithm y := Buildings.Occupants.BaseClasses.binaryVariableGeneration( Modelica.Math.exp(A*x1+B*x2+C)/(Modelica.Math.exp(A*x1+B*x2+C)+1), globalSeed); end logit2D;

Buildings.Occupants.BaseClasses.weibull1DOFF

Mapping a continuous input to a binary output through a Weibull Distribution Relation

Information

This function generates a random binary variable with a continuous inputs x from a Weibull Distribution relation.

The probability of being 1 is calculated from the input x from a Weibull Distribution relation with three predefined parameters u (threshold, the output would be 0 if x is bigger than u), L (normalization faction) and k (shape factor). Then a random generator generates the output, which should be a binary variable.

Inputs

TypeNameDefaultDescription
Realx Continous variable
Realu1.0Parameter defining the Weibull distribution threshold
RealL1.0Parameter defining the Weibull distribution normalization factor
Realk1.0Parameter defining the Weibull distribution shape factor
Realdt60Time step length
IntegerglobalSeed Seed for the random number generator

Outputs

TypeNameDescription
BooleanyBinary variable 0/1

Modelica definition

function weibull1DOFF "Mapping a continuous input to a binary output through a Weibull Distribution Relation" input Real x "Continous variable"; input Real u=1.0 "Parameter defining the Weibull distribution threshold"; input Real L=1.0 "Parameter defining the Weibull distribution normalization factor"; input Real k=1.0 "Parameter defining the Weibull distribution shape factor"; input Real dt=60 "Time step length"; input Integer globalSeed "Seed for the random number generator"; output Boolean y "Binary variable 0/1"; algorithm y := Buildings.Occupants.BaseClasses.binaryVariableGeneration( p = if x <= u then 1 - Modelica.Math.exp(-((u-x)/L)^k*dt) else 0, globalSeed = globalSeed); end weibull1DOFF;

Buildings.Occupants.BaseClasses.weibull1DON

Mapping a continuous input to a binary output through a Weibull Distribution Relation

Information

This function generates a random binary variable with a continuous inputs x from a Weibull Distribution relation.

The probability of being 1 is calculated from the input x from a Weibull Distribution relation with three predefined parameters u (threshold, the output would be 0 if x is less than u), L (normalization faction) and k (shape factor). Then a random generator generates the output, which should be a binary variable.

Inputs

TypeNameDefaultDescription
Realx Continous variable
Realu1.0Parameter defining the Weibull distribution threshold
RealL1.0Parameter defining the Weibull distribution normalization factor
Realk1.0Parameter defining the Weibull distribution shape factor
Realdt60Time step length
IntegerglobalSeed Seed for the random number generator

Outputs

TypeNameDescription
BooleanyBinary variable 0/1

Modelica definition

function weibull1DON "Mapping a continuous input to a binary output through a Weibull Distribution Relation" input Real x "Continous variable"; input Real u=1.0 "Parameter defining the Weibull distribution threshold"; input Real L=1.0 "Parameter defining the Weibull distribution normalization factor"; input Real k=1.0 "Parameter defining the Weibull distribution shape factor"; input Real dt=60 "Time step length"; input Integer globalSeed "Seed for the random number generator"; output Boolean y "Binary variable 0/1"; algorithm y := Buildings.Occupants.BaseClasses.binaryVariableGeneration( p = if x >= u then 1- Modelica.Math.exp(-((x-u)/L)^k*dt) else 0, globalSeed = globalSeed); end weibull1DON;

Buildings.Occupants.BaseClasses.weibullVariableGeneration

Random variable generator from the Weibull distribution

Information

This function generates a random variable, from a Weibull distribution with the inputs of lambda and k. The random variable might be the duration of a specific event, for instance the time to keep the HVAC on.

The inputs lambda and k defines the probability density function. lambda is similar to the mean value of exponential distribution, and k defines the shape. A value of k = 1 means the Weibull distribution reduces to an exponential distribution. Genrally speaking, higher lambda and higher k indicate a higher chance to generate a higher output.

Inputs

TypeNameDefaultDescription
Reallambda Parameter defining the Weibull distribution scale factor
Realk Parameter defining the Weibull distribution shape factor
IntegerglobalSeed Seed for the random number generator

Outputs

TypeNameDescription
RealyRandom variable generated from Weibull Distribution

Modelica definition

function weibullVariableGeneration "Random variable generator from the Weibull distribution" input Real lambda "Parameter defining the Weibull distribution scale factor"; input Real k "Parameter defining the Weibull distribution shape factor"; input Integer globalSeed "Seed for the random number generator"; output Real y "Random variable generated from Weibull Distribution"; protected Integer localSeed; Integer state[Modelica.Math.Random.Generators.Xorshift1024star.nState]; Real r "Generated random numberin the range 0 < random ≤ 1"; algorithm state := Modelica.Math.Random.Generators.Xorshift1024star.initialState(localSeed, globalSeed); (r, state) := Modelica.Math.Random.Generators.Xorshift1024star.random(state); y := lambda*(Modelica.Math.log((1 - r)^(-1)))^(1/k); end weibullVariableGeneration;