Skip to content

Commit

Permalink
Issue4069 occupants (#4073)
Browse files Browse the repository at this point in the history
* Refactored Buildings.Occupants

For #4069
  • Loading branch information
mwetter authored Dec 9, 2024
1 parent 04215e9 commit 1e1f16d
Show file tree
Hide file tree
Showing 93 changed files with 1,368 additions and 557 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,32 @@ within Buildings.Occupants.BaseClasses.Validation;
model BinaryVariableGeneration "Test model for binary variable generation function"
extends Modelica.Icons.Example;

parameter Integer seed = 5 "Seed for the random number generator";
parameter Integer localSeed = 10
"Local seed to be used to generate the initial state of the random number generator";
parameter Integer globalSeed = 30129
"Global seed to be combined with the local seed";
Real p "Time-varying real number as input";
output Real y "Output";
protected
parameter Modelica.Units.SI.Time t0(final fixed=false)
"First sample time instant";
Real curSeed "Current value for seed as a real-valued variable";
Integer state[Modelica.Math.Random.Generators.Xorshift1024star.nState]
"State of the random number generator";
Boolean r "Return value of random number generator";

initial equation
y = 0;
t0 = time;
curSeed = t0*seed;
state = Modelica.Math.Random.Generators.Xorshift1024star.initialState(
localSeed = localSeed,
globalSeed = globalSeed);
r = false;

equation
p = time;
when sample(0, 0.1) then
curSeed = seed*1E6*time;
if Buildings.Occupants.BaseClasses.binaryVariableGeneration(p, globalSeed=integer(curSeed)) then
(r, state) = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p, pre(state));
if r then
y = 1;
else
y = 0;
Expand All @@ -37,6 +45,12 @@ Buildings.Occupants.BaseClasses.binaryVariableGeneration</a>.
</html>", revisions="<html>
<ul>
<li>
December 6, 2024, by Michael Wetter:<br/>
Refactored implementation of random number calculations, transfering the local state of
the random number generator from one call to the next.<br/>
This is for <a href=\"https://github.com/lbl-srg/modelica-buildings/issues/4069\">#4069</a>.
</li>
<li>
September 5, 2018 by Zhe Wang:<br/>
First implementation.
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,30 @@ within Buildings.Occupants.BaseClasses.Validation;
model ExponentialVariableGeneration "Test model for exponential variable generation function"
extends Modelica.Icons.Example;

parameter Integer seed = 5 "Seed for the random number generator";
parameter Integer localSeed = 10
"Local seed to be used to generate the initial state of the random number generator";
parameter Integer globalSeed = 30129
"Global seed to be combined with the local seed";
Real mu "Time-varying real number as input";
output Real y "Output";
protected
parameter Modelica.Units.SI.Time t0(final fixed=false)
"First sample time instant";
Real curSeed "Current value for seed as a real-valued variable";
Integer state[Modelica.Math.Random.Generators.Xorshift1024star.nState]
"State of the random number generator";

initial equation
y = 0;
t0 = time;
curSeed = t0*seed;
state = Modelica.Math.Random.Generators.Xorshift1024star.initialState(
localSeed = localSeed,
globalSeed = globalSeed);


equation
mu = 10*time;
when sample(0, 0.1) then
curSeed = seed*1E6*time;
y = Buildings.Occupants.BaseClasses.exponentialVariableGeneration(mu, globalSeed=integer(curSeed));
(y, state) = Buildings.Occupants.BaseClasses.exponentialVariableGeneration(mu, pre(state));
end when;

annotation ( experiment(Tolerance=1e-6, StopTime=1.0),
Expand All @@ -33,6 +39,12 @@ Buildings.Occupants.BaseClasses.exponentialVariableGeneration</a>.
</html>", revisions="<html>
<ul>
<li>
December 6, 2024, by Michael Wetter:<br/>
Refactored implementation of random number calculations, transfering the local state of
the random number generator from one call to the next.<br/>
This is for <a href=\"https://github.com/lbl-srg/modelica-buildings/issues/4069\">#4069</a>.
</li>
<li>
September 5, 2018 by Zhe Wang:<br/>
First implementation.
</li>
Expand Down
25 changes: 20 additions & 5 deletions Buildings/Occupants/BaseClasses/Validation/Linear1D.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,35 @@ within Buildings.Occupants.BaseClasses.Validation;
model Linear1D "Test model for 1D binary variable generation function"
extends Modelica.Icons.Example;

parameter Integer seed = 5 "Seed for the random number generator";
parameter Integer localSeed = 10
"Local seed to be used to generate the initial state of the random number generator";
parameter Integer globalSeed = 30129
"Global seed to be combined with the local seed";
parameter Real A = 0.9 "Parameter A";
parameter Real B = 0 "Parameter B";
Real x "Time-varying real number as input";
output Real y "Output";
protected
parameter Modelica.Units.SI.Time t0(final fixed=false)
"First sample time instant";
Real curSeed "Current value for seed as a real-valued variable";
Integer state[Modelica.Math.Random.Generators.Xorshift1024star.nState]
"State of the random number generator";
Boolean r "Return value of random number generator";

initial equation
y = 0;
t0 = time;
curSeed = t0*seed;
state = Modelica.Math.Random.Generators.Xorshift1024star.initialState(
localSeed = localSeed,
globalSeed = globalSeed);
r = false;


equation
x = time;
when sample(0, 0.1) then
curSeed = seed*1E6*time;
if Buildings.Occupants.BaseClasses.linear1D(x,A,B,globalSeed=integer(curSeed)) then
(r, state) = Buildings.Occupants.BaseClasses.linear1D(x, A, B, pre(state));
if r then
y = 1;
else
y = 0;
Expand All @@ -39,6 +48,12 @@ Buildings.Occupants.BaseClasses.linear1D</a>.
</html>", revisions="<html>
<ul>
<li>
December 6, 2024, by Michael Wetter:<br/>
Refactored implementation of random number calculations, transfering the local state of
the random number generator from one call to the next.<br/>
This is for <a href=\"https://github.com/lbl-srg/modelica-buildings/issues/4069\">#4069</a>.
</li>
<li>
September 5, 2018 by Zhe Wang:<br/>
First implementation.
</li>
Expand Down
24 changes: 19 additions & 5 deletions Buildings/Occupants/BaseClasses/Validation/Logit1D.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,34 @@ within Buildings.Occupants.BaseClasses.Validation;
model Logit1D "Test model for 1D binary variable generation function"
extends Modelica.Icons.Example;

parameter Integer seed = 5 "Seed for the random number generator";
parameter Integer localSeed = 10
"Local seed to be used to generate the initial state of the random number generator";
parameter Integer globalSeed = 30129
"Global seed to be combined with the local seed";
parameter Real A = 0.9 "Parameter A";
parameter Real B = 0 "Parameter B";
Real x "Time-varying real number as input";
output Real y "Output";
protected
parameter Modelica.Units.SI.Time t0(final fixed=false)
"First sample time instant";
Real curSeed "Current value for seed as a real-valued variable";
Integer state[Modelica.Math.Random.Generators.Xorshift1024star.nState]
"State of the random number generator";
Boolean r "Return value of random number generator";

initial equation
y = 0;
t0 = time;
curSeed = t0*seed;
state = Modelica.Math.Random.Generators.Xorshift1024star.initialState(
localSeed = localSeed,
globalSeed = globalSeed);
r = false;

equation
x = time;
when sample(0, 0.1) then
curSeed = seed*1E6*time;
if Buildings.Occupants.BaseClasses.logit1D(x,A,B,globalSeed=integer(curSeed)) then
(r, state) = Buildings.Occupants.BaseClasses.logit1D(x, A, B, pre(state));
if r then
y = 1;
else
y = 0;
Expand All @@ -39,6 +47,12 @@ Buildings.Occupants.BaseClasses.logit1D</a>.
</html>", revisions="<html>
<ul>
<li>
December 6, 2024, by Michael Wetter:<br/>
Refactored implementation of random number calculations, transfering the local state of
the random number generator from one call to the next.<br/>
This is for <a href=\"https://github.com/lbl-srg/modelica-buildings/issues/4069\">#4069</a>.
</li>
<li>
September 5, 2018 by Zhe Wang:<br/>
First implementation.
</li>
Expand Down
24 changes: 19 additions & 5 deletions Buildings/Occupants/BaseClasses/Validation/Logit1DQuadratic.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ within Buildings.Occupants.BaseClasses.Validation;
model Logit1DQuadratic "Test model for 1D binary variable generation function"
extends Modelica.Icons.Example;

parameter Integer seed = 5 "Seed for the random number generator";
parameter Integer localSeed = 10
"Local seed to be used to generate the initial state of the random number generator";
parameter Integer globalSeed = 30129
"Global seed to be combined with the local seed";
parameter Real A = 0.1 "Parameter A";
parameter Real B = 0.5 "Parameter B";
parameter Real C = 1.3 "Parameter A";
Expand All @@ -12,18 +15,23 @@ model Logit1DQuadratic "Test model for 1D binary variable generation function"
protected
parameter Modelica.Units.SI.Time t0(final fixed=false)
"First sample time instant";
Real curSeed "Current value for seed as a real-valued variable";
Integer state[Modelica.Math.Random.Generators.Xorshift1024star.nState]
"State of the random number generator";
Boolean r "Return value of random number generator";

initial equation
y = 0;
t0 = time;
curSeed = t0*seed;
state = Modelica.Math.Random.Generators.Xorshift1024star.initialState(
localSeed = localSeed,
globalSeed = globalSeed);
r = false;

equation
x = time+1;
when sample(0, 0.1) then
curSeed = seed*1E6*time;
if Buildings.Occupants.BaseClasses.logit1DQuadratic(x,A,B,C,D,globalSeed=integer(curSeed)) then
(r, state) = Buildings.Occupants.BaseClasses.logit1DQuadratic(x, A, B, C, D, pre(state));
if r then
y = 1;
else
y = 0;
Expand All @@ -41,6 +49,12 @@ Buildings.Occupants.BaseClasses.logit1DQuadratic</a>.
</html>", revisions="<html>
<ul>
<li>
December 6, 2024, by Michael Wetter:<br/>
Refactored implementation of random number calculations, transfering the local state of
the random number generator from one call to the next.<br/>
This is for <a href=\"https://github.com/lbl-srg/modelica-buildings/issues/4069\">#4069</a>.
</li>
<li>
September 5, 2018 by Zhe Wang:<br/>
First implementation.
</li>
Expand Down
25 changes: 20 additions & 5 deletions Buildings/Occupants/BaseClasses/Validation/Logit2D.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ within Buildings.Occupants.BaseClasses.Validation;
model Logit2D "Test model for 2D binary variable generation function"
extends Modelica.Icons.Example;

parameter Integer seed = 5 "Seed for the random number generator";
parameter Integer localSeed = 10
"Local seed to be used to generate the initial state of the random number generator";
parameter Integer globalSeed = 30129
"Global seed to be combined with the local seed";
parameter Real A = 0.9 "Parameter A";
parameter Real B = 1.3 "Parameter B";
parameter Real C = 0 "Parameter C";
Expand All @@ -12,19 +15,25 @@ model Logit2D "Test model for 2D binary variable generation function"
protected
parameter Modelica.Units.SI.Time t0(final fixed=false)
"First sample time instant";
Real curSeed "Current value for seed as a real-valued variable";
Integer state[Modelica.Math.Random.Generators.Xorshift1024star.nState]
"State of the random number generator";
Boolean r "Return value of random number generator";

initial equation
y = 0;
t0 = time;
curSeed = t0*seed;
state = Modelica.Math.Random.Generators.Xorshift1024star.initialState(
localSeed = localSeed,
globalSeed = globalSeed);
r = false;


equation
x1 = time;
x2 = 0.7*time;
when sample(0, 0.1) then
curSeed = seed*1E6*time;
if Buildings.Occupants.BaseClasses.logit2D(x1,x2,A,B,C,globalSeed=integer(curSeed)) then
(r, state) = Buildings.Occupants.BaseClasses.logit2D(x1, x2, A, B, C, pre(state));
if r then
y = 1;
else
y = 0;
Expand All @@ -42,6 +51,12 @@ Buildings.Occupants.BaseClasses.logit2D</a>.
</html>", revisions="<html>
<ul>
<li>
December 6, 2024, by Michael Wetter:<br/>
Refactored implementation of random number calculations, transfering the local state of
the random number generator from one call to the next.<br/>
This is for <a href=\"https://github.com/lbl-srg/modelica-buildings/issues/4069\">#4069</a>.
</li>
<li>
September 5, 2018 by Zhe Wang:<br/>
First implementation.
</li>
Expand Down
25 changes: 20 additions & 5 deletions Buildings/Occupants/BaseClasses/Validation/Weibull1DOFF.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ within Buildings.Occupants.BaseClasses.Validation;
model Weibull1DOFF "Test model for 1D binary variable generation function"
extends Modelica.Icons.Example;

parameter Integer seed = 5 "Seed for the random number generator";
parameter Integer localSeed = 10
"Local seed to be used to generate the initial state of the random number generator";
parameter Integer globalSeed = 30129
"Global seed to be combined with the local seed";
parameter Real u=1.0 "Parameter defining the Weibull distribution threshold";
parameter Real L=0.5 "Parameter defining the Weibull distribution normalization factor";
parameter Real k=1.0 "Parameter defining the Weibull distribution shape factor";
Expand All @@ -13,18 +16,24 @@ model Weibull1DOFF "Test model for 1D binary variable generation function"
protected
parameter Modelica.Units.SI.Time t0(final fixed=false)
"First sample time instant";
Real curSeed "Current value for seed as a real-valued variable";
Integer state[Modelica.Math.Random.Generators.Xorshift1024star.nState]
"State of the random number generator";
Boolean r "Return value of random number generator";

initial equation
y = 0;
t0 = time;
curSeed = t0*seed;
state = Modelica.Math.Random.Generators.Xorshift1024star.initialState(
localSeed = localSeed,
globalSeed = globalSeed);
r = false;


equation
x = time;
when sample(0, 0.1) then
curSeed = seed*1E6*time;
if Buildings.Occupants.BaseClasses.weibull1DOFF(x,u,L,k,dt,globalSeed=integer(curSeed)) then
(r, state) = Buildings.Occupants.BaseClasses.weibull1DOFF(x, u, L, k, dt, pre(state));
if r then
y = 1;
else
y = 0;
Expand All @@ -42,6 +51,12 @@ Buildings.Occupants.BaseClasses.weibull1DOFF</a>.
</html>", revisions="<html>
<ul>
<li>
December 6, 2024, by Michael Wetter:<br/>
Refactored implementation of random number calculations, transfering the local state of
the random number generator from one call to the next.<br/>
This is for <a href=\"https://github.com/lbl-srg/modelica-buildings/issues/4069\">#4069</a>.
</li>
<li>
September 5, 2018 by Zhe Wang:<br/>
First implementation.
</li>
Expand Down
Loading

0 comments on commit 1e1f16d

Please sign in to comment.