Validating the model for blind behaviors. This example validates

Buildings.Occupants.Office.Blinds.Newsham1994BlindsSolarIntensity
by examing how the blinds state corresponds
to the solar intensity.

within Buildings.Occupants.Office.Blinds.Validation;
model Newsham1994BlindsSolarIntensity
    "Validating the model for blind behaviors"
    extends Modelica.Icons.Example;

    Modelica.Blocks.Sources.BooleanStep occ(startTime=1800)
                                            "True for occupied"
  Modelica.Blocks.Sources.Sine H(
    amplitude=250,
    offset=300,
    f=0.001,
    y(unit="W/m2")) "Solar intensity at the window"
    Buildings.Occupants.Office.Blinds.Newsham1994BlindsSolarIntensity bli "Tested blinds model"
equation
    connect(occ.y, bli.occ)
    connect(H.y, bli.H)
end Newsham1994BlindsSolarIntensity;


within Buildings.Occupants.Office.Blinds;
package Validation "Package with examples to validate models in the Blinds package"
  extends Modelica.Icons.ExamplesPackage;
end Validation;


Validating the model for blind behaviors. This example validates

Buildings.Occupants.Office.Blinds.Zhang2012BlindsSolarAltitude
by examing how the blinds state corresponds
to the solar altitude.

within Buildings.Occupants.Office.Blinds.Validation;
model Zhang2012BlindsSolarAltitude
  "Validating the model for blind behaviors"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.BooleanStep occ(startTime=1800)
    "True for occupied"
  Modelica.Blocks.Sources.Sine SA(
    amplitude=30*3.14159/180,
    offset=35*3.14159/180,
    f=0.001,
    y(unit="1")) "Solar altitude"
  Buildings.Occupants.Office.Blinds.Zhang2012BlindsSolarAltitude bli "Tested blinds model"
equation
  connect(occ.y, bli.occ)
  connect(SA.y, bli.solarAltitude)
end Zhang2012BlindsSolarAltitude;


Validating the model for blind behaviors. This example validates

Buildings.Occupants.Office.Blinds.Zhang2012BlindsSolarIntensity
by examing how the blinds state corresponds
to the solar intensity.

within Buildings.Occupants.Office.Blinds.Validation;
model Zhang2012BlindsSolarIntensity
    "Validating the model for blind behaviors"
    extends Modelica.Icons.Example;

    Modelica.Blocks.Sources.BooleanStep occ(startTime=1800)
                                            "True for occupied"
  Modelica.Blocks.Sources.Sine H(
    amplitude=250,
    offset=300,
    f=0.001,
    y(unit="W/m2")) "Solar intensity at the window"
    Buildings.Occupants.Office.Blinds.Zhang2012BlindsSolarIntensity bli "Tested blinds model"
equation
    connect(occ.y, bli.occ)
    connect(H.y, bli.H)
end Zhang2012BlindsSolarIntensity;


A model to predict occupants' lighting behavior with illuminance. Model predicting the state of the lighting with the illuminance on the working plane
and occupancy.

within Buildings.Occupants.Office.Lighting;
model Gunay2016Light "A model to predict occupants' lighting behavior with illuminance"
  extends Modelica.Blocks.Icons.DiscreteBlock;
  parameter Real AArriv = -0.009 "Slope of logistic regression arrival";
  parameter Real BArriv = 1.6 "Intercept of logistic regression arrival";
  parameter Real AInter = -0.002 "Slope of logistic regression intermediate";
  parameter Real BInter = -3.9 "Intercept of logistic regression intermediate";
  parameter Integer seed = 30 "Seed for the random number generator";
  parameter Modelica.Units.SI.Time samplePeriod=120 "Sample period";

  Modelica.Blocks.Interfaces.RealInput ill
    "Illuminance on the working planein units of lux"
  Modelica.Blocks.Interfaces.BooleanInput occ
    "Indoor occupancy, true for occupied"
  Modelica.Blocks.Interfaces.BooleanOutput on "State of lighting"

  Real pArriv(
    final unit="1",
    final min=0,
    final max=1) "Probability of switch on the lighting upon arrival";
  Real pInter(
    final unit="1",
    final min=0,
    final max=1) "Intermediate robability of switch on the lighting";

protected
  parameter Modelica.Units.SI.Time t0(final fixed=false)
    "First sample time instant";
  output Boolean sampleTrigger "True, if sample time instant";
  Real curSeed "Current value for seed as a real-valued variable";

initial equation
  t0 = time;
  curSeed = t0*seed;
  on = false;

equation
  pArriv = Modelica.Math.exp(AArriv*ill + BArriv)/(1+Modelica.Math.exp(AArriv*ill + BArriv));
  pInter = Modelica.Math.exp(AInter*ill + BInter)/(1+Modelica.Math.exp(AInter*ill + BInter));
  sampleTrigger = sample(t0,samplePeriod);
  when {occ, sampleTrigger} then
    curSeed = seed*time;
    if sampleTrigger then
      if occ then
        if not pre(on) then
          on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=pInter, globalSeed=integer(curSeed));
        else
          on = true;
        end if;
      else
        on = false;
      end if;
    else
      on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=pArriv, globalSeed=integer(curSeed));
    end if;
  end when;
end Gunay2016Light;


A model to predict occupants' lighting behavior with illuminance.

within Buildings.Occupants.Office.Lighting;
model Hunt1979Light "A model to predict occupants' lighting behavior with illuminance"
 extends Modelica.Blocks.Icons.DiscreteBlock;
 parameter Real AArriv = -0.0175 "Upon arrival";
 parameter Real BArriv = -4.0835 "Upon arrival";
 parameter Real CArriv = 1.0361 "Upon arrival";
 parameter Real MArriv = 1.8223 "Upon arrival";
 parameter Integer seed = 30 "Seed for the random number generator";
  parameter Modelica.Units.SI.Time samplePeriod=120 "Sample period";

 Modelica.Blocks.Interfaces.RealInput ill "Illuminance on the working planein units of lux"
 Modelica.Blocks.Interfaces.BooleanInput occ
   "Indoor occupancy, true for occupied"
 Modelica.Blocks.Interfaces.BooleanOutput on "State of lighting"

 Real pArriv(
   unit="1",
   min=0,
   max=1) "Probability of switch on the lighting upon arrival";

protected
  parameter Modelica.Units.SI.Time t0(final fixed=false)
    "First sample time instant";
 output Boolean sampleTrigger "True, if sample time instant";
 Real curSeed "Current value for seed as a real-valued variable";

initial equation
 t0 = time;
 curSeed = t0*seed;
 on = false;
equation
 if ill > 657.7 then
   pArriv =0;
 elseif ill < 7.0 then
   pArriv =1;
 else
   pArriv =AArriv + CArriv/(1 + Modelica.Math.exp(-BArriv*(
     Modelica.Math.log10(ill) - MArriv)));
 end if;
 sampleTrigger = sample(t0, samplePeriod);
 when {occ, sampleTrigger} then
   curSeed = seed*time;
   if sampleTrigger then
     if occ then
       on = pre(on);
     else
       on = false;
     end if;
   else
     on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(pArriv, globalSeed=integer(curSeed));
   end if;
 end when;
end Hunt1979Light;


A model to predict occupants' lighting behavior with illuminance. Model predicting the state of the lighting with the daylight illuminance level on the desk
and occupancy.

within Buildings.Occupants.Office.Lighting;
model Love1998Light1 "A model to predict occupants' lighting behavior with illuminance"
  extends Modelica.Blocks.Icons.DiscreteBlock;
  parameter Real B = 5.85 "Intercept for logistic regression";
  parameter Real M = -11.9 "Slope for logistic regression";
  parameter Integer seed = 30 "Seed for the random number generator";
  parameter Modelica.Units.SI.Time samplePeriod=120 "Sample period";

  Modelica.Blocks.Interfaces.RealInput ill "Daylight illuminance level on the deskin units of lux"
  Modelica.Blocks.Interfaces.BooleanInput occ
    "Indoor occupancy, true for occupied"
  Modelica.Blocks.Interfaces.BooleanOutput on "State of lighting"

  Real p(
    final unit="1",
    final min=0,
    final max=1) "Probability of switch on the lighting";

protected
  parameter Modelica.Units.SI.Time t0(final fixed=false)
    "First sample time instant";
  output Boolean sampleTrigger "True, if sample time instant";
  Real curSeed "Current value for seed as a real-valued variable";

initial equation
  t0 = time;
  curSeed = t0*seed;
  on = false;

equation
  p = Modelica.Math.exp(B+M*Modelica.Math.log10(ill))/(1 - Modelica.Math.exp(B+M*Modelica.Math.log10(ill)))*100;
  sampleTrigger = sample(t0, samplePeriod);
  when {occ, sampleTrigger} then
    curSeed = seed*time;
    if sampleTrigger then
      if occ then
        on = pre(on);
      else
        on = false;
      end if;
    else
      on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));
    end if;
  end when;
end Love1998Light1;


within Buildings.Occupants.Office.Lighting;
model Love1998Light2 "A model to predict occupants' lighting behavior with illuminance"
  extends Modelica.Blocks.Icons.DiscreteBlock;
  parameter Real B = 7.19 "Intercept for logistic regression";
  parameter Real M = -17.06 "Slope for logistic regression";
  parameter Integer seed = 30 "Seed for the random number generator";
  parameter Modelica.Units.SI.Time samplePeriod=120 "Sample period";

  Modelica.Blocks.Interfaces.RealInput ill "Daylight illuminance level on the deskin units of lux"
  Modelica.Blocks.Interfaces.BooleanInput occ
    "Indoor occupancy, true for occupied"
  Modelica.Blocks.Interfaces.BooleanOutput on "State of lighting"

  Real p(
    final unit="1",
    final min=0,
    final max=1) "Probability of switch on the lighting";

protected
  parameter Modelica.Units.SI.Time t0(final fixed=false)
    "First sample time instant";
  output Boolean sampleTrigger "True, if sample time instant";
  Real curSeed "Current value for seed as a real-valued variable";

initial equation
  t0 = time;
  curSeed = t0*seed;
  on = false;

equation
  p = Modelica.Math.exp(B+M*Modelica.Math.log10(ill))
    /(1 - Modelica.Math.exp(B+M*Modelica.Math.log10(ill)))*100;
  sampleTrigger = sample(t0, samplePeriod);
  when {occ, sampleTrigger} then
    curSeed = seed*time;
    if sampleTrigger then
      if occ then
        on = pre(on);
      else
        on = false;
      end if;
    else
      on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(
        p=p,
        globalSeed=integer(curSeed));
    end if;
  end when;
end Love1998Light2;


within Buildings.Occupants.Office;
package Lighting "Package with models to simulate lighting behaviors in office buildings"
  extends Modelica.Icons.VariantsPackage;
end Lighting;


within Buildings.Occupants.Office.Lighting;
model Reinhart2003Light "A model to predict occupants' lighting behavior with illuminance"
  extends Modelica.Blocks.Icons.DiscreteBlock;
  parameter Real AArriv = -0.00238 "Upon arrival";
  parameter Real BArriv = -3.0965 "Upon arrival";
  parameter Real CArriv = 1.0157 "Upon arrival";
  parameter Real MArriv = 1.8536 "Upon arrival";
  parameter Real AInter = 0.0027 "intermediate";
  parameter Real BInter = -64.19 "intermediate";
  parameter Real CInter = 0.017 "intermediate";
  parameter Real MInter = 2.41 "intermediate";
  parameter Integer seed = 30 "Seed for the random number generator";
  parameter Modelica.Units.SI.Time samplePeriod=120 "Sample period";

  Modelica.Blocks.Interfaces.RealInput ill "Illuminance on the working planein units of lux"
  Modelica.Blocks.Interfaces.BooleanInput occ
    "Indoor occupancy, true for occupied"
  Modelica.Blocks.Interfaces.BooleanOutput on "State of lighting"

  Real pArriv(
    final unit="1",
    final min=0,
    final max=1) "Probability of switch on the lighting upon arrival";
  Real pInter(
    final unit="1",
    final min=0,
    final max=1) "Intermediate robability of switch on the lighting";

protected
  parameter Modelica.Units.SI.Time t0(final fixed=false)
    "First sample time instant";
  output Boolean sampleTrigger "True, if sample time instant";
  Real curSeed "Current value for seed as a real-valued variable";

initial equation
  t0 = time;
  curSeed = t0*seed;
  on = false;

equation
  pArriv = AArriv + CArriv/(1+Modelica.Math.exp(-BArriv*(Modelica.Math.log10(ill)-MArriv)));
  pInter = AInter + CInter/(1+Modelica.Math.exp(-BInter*(Modelica.Math.log10(ill)-MInter)));
  sampleTrigger = sample(t0,samplePeriod);
  when {occ, sampleTrigger} then
    curSeed = seed*time;
    if sampleTrigger then
      if occ then
        if not pre(on) then
          on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=pInter, globalSeed=integer(curSeed));
        else
          on = true;
        end if;
      else
        on = false;
      end if;
    else
      on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=pArriv, globalSeed=integer(curSeed));
    end if;
  end when;
end Reinhart2003Light;


Validating the model for light behaviors. This example validates

Buildings.Occupants.Office.Lighting.Gunay2016Light
by examing how the lighting state corresponds
to the minimum illuminance level on the working plane.

within Buildings.Occupants.Office.Lighting.Validation;
model Gunay2016Light "Validating the model for light behaviors"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.Sine ill(
    amplitude=200,
    offset=250,
    f=0.001) "Illuminance at working planein units of lux"
  Buildings.Occupants.Office.Lighting.Gunay2016Light lig "Tested lighting model"
  Modelica.Blocks.Sources.BooleanPulse booleanPulse(period=400)
equation
  connect(lig.ill, ill.y)
  connect(booleanPulse.y, lig.occ)
end Gunay2016Light;


Validating the model for light behaviors. This example validates

Buildings.Occupants.Office.Lighting.Hunt1979Light
by examing how the lighting state corresponds
to the minimum illuminance level on the working plane.

within Buildings.Occupants.Office.Lighting.Validation;
model Hunt1979Light "Validating the model for light behaviors"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.Sine ill(
    amplitude=200,
    offset=250,
    f=0.001) "Minimum illuminance at working plane"
  Buildings.Occupants.Office.Lighting.Hunt1979Light lig "Tested lighting model"
  Modelica.Blocks.Sources.BooleanPulse occ(period=400)
equation
  connect(lig.ill, ill.y)
  connect(occ.y, lig.occ)
end Hunt1979Light;


Validating the model for light behaviors. This example validates

Buildings.Occupants.Office.Lighting.Love1998Light1
by examing how the lighting state corresponds
to the daylight illuminance level on the desk.

within Buildings.Occupants.Office.Lighting.Validation;
model Love1998Light1 "Validating the model for light behaviors"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.Sine ill(
    offset=250,
    f=0.001,
    amplitude=200) "Daylight illuminance level on the deskin units of lux"
  Buildings.Occupants.Office.Lighting.Love1998Light1 lig "Tested lighting model"
  Modelica.Blocks.Sources.BooleanPulse occ(period=400)
equation
  connect(lig.ill, ill.y)
  connect(occ.y, lig.occ)
end Love1998Light1;


Validating the model for light behaviors. This example validates

Buildings.Occupants.Office.Lighting.Love1998Light2
by examing how the lighting state corresponds
to the daylight illuminance level on the desk.

within Buildings.Occupants.Office.Lighting.Validation;
model Love1998Light2 "Validating the model for light behaviors"
    extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.Sine ill(
    amplitude=200,
    offset=250,
    f=0.001) "Daylight illuminance level on the deskin units of lux"
    Buildings.Occupants.Office.Lighting.Love1998Light2 lig "Tested lighting model"
    Modelica.Blocks.Sources.BooleanPulse occ(period=400)
equation
    connect(lig.ill, ill.y)
    connect(occ.y, lig.occ)
end Love1998Light2;


within Buildings.Occupants.Office.Lighting;
package Validation "Package with examples to validate models in Lighting package"
  extends Modelica.Icons.ExamplesPackage;
end Validation;


Validating the model for light behaviors. This example validates

Buildings.Occupants.Office.Lighting.Reinhart2003Light
by examing how the lighting state corresponds
to the minimum illuminance level on the working plane.

within Buildings.Occupants.Office.Lighting.Validation;
model Reinhart2003Light "Validating the model for light behaviors"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.Sine ill(
    amplitude=200,
    offset=250,
    f=0.001) "Minimum illuminance at working plane"
  Buildings.Occupants.Office.Lighting.Reinhart2003Light lig "Tested lighting model"
  Modelica.Blocks.Sources.BooleanPulse booleanPulse(period=400)
equation
  connect(lig.ill, ill.y)
  connect(booleanPulse.y, lig.occ)
end Reinhart2003Light;


within Buildings.Occupants.Office;
package Occupancy "Package with models to simulate occupancy in office buildings"
  extends Modelica.Icons.VariantsPackage;
end Occupancy;


A model to predict Occupancy of a single person office. Model predicting the occupancy of a single person office.

within Buildings.Occupants.Office.Occupancy;
model Wang2005Occupancy
  "A model to predict Occupancy of a single person office"
  extends Modelica.Blocks.Icons.DiscreteBlock;

  parameter Modelica.Units.SI.Time one_mu(displayUnit="min") = 4368
    "Mean occupancy duration";
  parameter Modelica.Units.SI.Time zero_mu(displayUnit="min") = 2556
    "Mean vacancy duration";
  parameter Integer seed = 10 "Seed for the random number generator";

  Modelica.Blocks.Interfaces.BooleanOutput occ(start=true, fixed=true)
    "The State of occupancy, true for occupied"

protected
  discrete Real mu;
  discrete Real tNext(start=0, fixed=true);
  discrete Real hold_time;
  Real r(min=0, max=1) "Generated random number";
  Integer state[Modelica.Math.Random.Generators.Xorshift1024star.nState](
    each start=0,
    each fixed=true);

algorithm
  when initial() then
    (r, state) := Modelica.Math.Random.Generators.Xorshift1024star.random(
      Modelica.Math.Random.Generators.Xorshift1024star.initialState(seed, seed));
    occ :=false;
    mu :=if occ then one_mu else zero_mu;
    hold_time :=-mu*Modelica.Math.log(1 - r);
    tNext :=time + hold_time;
   elsewhen time >= pre(tNext) then
    (r, state) :=Modelica.Math.Random.Generators.Xorshift1024star.random(pre(state));
    occ :=not pre(occ);
    mu :=if occ then one_mu else zero_mu;
    hold_time :=-mu*Modelica.Math.log(1 - r);
    tNext :=time + hold_time;
  end when;
end Wang2005Occupancy;


within Buildings.Occupants.Office.Occupancy;
package Validation "Package with examples to validate models in Occupancy package"
  extends Modelica.Icons.ExamplesPackage;
end Validation;


Validating the model for occupancy. This example validates

Buildings.Occupants.Office.Occupancy.Wang2005Occupancy
by examing output of occupancy state.

within Buildings.Occupants.Office.Occupancy.Validation;
model Wang2005Occupancy "Validating the model for occupancy"
  extends Modelica.Icons.Example;

  Buildings.Occupants.Office.Occupancy.Wang2005Occupancy occ "Tested Occupancy model"
end Wang2005Occupancy;


A model to predict occupants' window behavior with indoor temperature. Model predicting the state of the window with the indoor air temperature
and occupancy.

within Buildings.Occupants.Office.Windows;
model Haldi2008WindowsTIn "A model to predict occupants' window behavior with indoor temperature"
  extends Modelica.Blocks.Icons.DiscreteBlock;
  parameter Real A = 0.22 "Slope of the logistic relation";
  parameter Real B = -5.64 "Intercept of the logistic relation";
  parameter Integer seed = 30 "Seed for the random number generator";
  parameter Modelica.Units.SI.Time samplePeriod=120 "Sample period";

  Modelica.Blocks.Interfaces.RealInput TIn(
    final unit="K",
    displayUnit="degC") "Indoor air temperature"
  Modelica.Blocks.Interfaces.BooleanInput occ
    "Indoor occupancy, true for occupied"
  Modelica.Blocks.Interfaces.BooleanOutput on "State of window, true for open"

  Real p(
    unit="1",
    min=0,
    max=1) "Probability of window opened";

protected
  parameter Modelica.Units.SI.Time t0(final fixed=false)
    "First sample time instant";
  output Boolean sampleTrigger "True, if sample time instant";
  Real curSeed "Current value for seed as a real-valued variable";

initial equation
  t0 = time;
  curSeed = t0*seed;
  p = Modelica.Math.exp(A*(TIn - 273.15)+B)/(Modelica.Math.exp(A*(TIn - 273.15)+B) + 1);
  on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(seed*time));
equation
  sampleTrigger = sample(t0,samplePeriod);
  when sampleTrigger then
    curSeed = seed*time;
    if occ then
      p = Modelica.Math.exp(A*(TIn - 273.15)+B)/(Modelica.Math.exp(A*(TIn - 273.15)+B) + 1);
      on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));
    else
      p = 0;
      on = false;
    end if;
  end when;
end Haldi2008WindowsTIn;


A model to predict occupants' window behavior with outdoor temperature. Model predicting the state of the window with the outdoor air temperature
and occupancy.

within Buildings.Occupants.Office.Windows;
model Haldi2008WindowsTOut "A model to predict occupants' window behavior with outdoor temperature"
  extends Modelica.Blocks.Icons.DiscreteBlock;
  parameter Real A = 0.049 "Slope of the logistic relation";
  parameter Real B = -1.12 "Intercept of the logistic relation";
  parameter Integer seed = 30 "Seed for the random number generator";
  parameter Modelica.Units.SI.Time samplePeriod=120 "Sample period";

  Modelica.Blocks.Interfaces.RealInput TOut(
    final unit="K",
    displayUnit="degC") "Outdoor air temperature"
  Modelica.Blocks.Interfaces.BooleanInput occ
    "Indoor occupancy, true for occupied"
  Modelica.Blocks.Interfaces.BooleanOutput on "State of window, true for open"

  Real p(
    unit="1",
    min=0,
    max=1) "Probability of window opened";

protected
  parameter Modelica.Units.SI.Time t0(final fixed=false)
    "First sample time instant";
  output Boolean sampleTrigger "True, if sample time instant";
  Real curSeed "Current value for seed as a real-valued variable";
initial equation
  t0 = time;
  curSeed = t0*seed;
  p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
  on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));
equation
  sampleTrigger = sample(t0,samplePeriod);
  when sampleTrigger then
    curSeed = seed*time;
    if occ then
      p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
      on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));
    else
      p = 0;
      on = false;
    end if;
  end when;
end Haldi2008WindowsTOut;


A model to predict occupants' window behavior with indoor and outdoor temperature. Model predicting the state of the window with the indoor, outdoor air temperature
and occupancy.

within Buildings.Occupants.Office.Windows;
model Haldi2009WindowsTInTout "A model to predict occupants' window behavior with indoor and outdoor temperature"
  extends Modelica.Blocks.Icons.DiscreteBlock;
  parameter Real AOpenIn = 0.263 "Slope of indoor temp of the logistic relation for the opening probability";
  parameter Real AOpenOut = 0.039 "Slope of outdoor temp of the logistic relation for the opening probability";
  parameter Real BOpen = -11.78 "Intercept of the logistic relation for the opening probability";
  parameter Real ACloseIn = 0.026 "Slope of indoor temp of the logistic relation for the closing probability";
  parameter Real ACloseOut = -0.065 "Slope of outdoor temp of the logistic relation for the closing probability";
  parameter Real BClose = -4.14 "Intercept of the logistic relation for the closing probability";
  parameter Integer seed = 10 "Seed for the random number generator";
  parameter Modelica.Units.SI.Time samplePeriod=120 "Sample period";

  Modelica.Blocks.Interfaces.RealInput TIn(
    final unit="K",
    displayUnit="degC") "Indoor air temperature"
  Modelica.Blocks.Interfaces.RealInput TOut(
    final unit="K",
    displayUnit="degC") "Outdoor air temperature"
  Modelica.Blocks.Interfaces.BooleanInput occ
    "Indoor occupancy, true for occupied"
  Modelica.Blocks.Interfaces.BooleanOutput on "State of window, true for open"

  Real pOpen(
    unit="1",
    min=0,
    max=1) "Probability of opening windows";
  Real pClose(
    unit="1",
    min=0,
    max=1) "Probability of closing windows";

protected
  parameter Modelica.Units.SI.Time t0(final fixed=false)
    "First sample time instant";
  output Boolean sampleTrigger "True, if sample time instant";
  Real curSeed "Current value for seed as a real-valued variable";

initial equation
  t0 = time;
  curSeed = t0*seed;
  on = false;
  pOpen = Modelica.Math.exp(AOpenIn*(TIn - 273.15)+AOpenOut*(TOut - 273.15)+BOpen)/(Modelica.Math.exp(AOpenIn*(TIn - 273.15)+AOpenOut*(TOut - 273.15)+BOpen) + 1);
  pClose = Modelica.Math.exp(ACloseIn*(TIn - 273.15)+ACloseOut*(TOut - 273.15)+BClose)/(Modelica.Math.exp(ACloseIn*(TIn - 273.15)+ACloseOut*(TOut - 273.15)+BClose) + 1);

equation
  sampleTrigger = sample(t0,samplePeriod);
  when sampleTrigger then
    curSeed = seed*time;
    if occ then
      pOpen = Modelica.Math.exp(AOpenIn*(TIn - 273.15)+AOpenOut*(TOut - 273.15)+BOpen)/(Modelica.Math.exp(AOpenIn*(TIn - 273.15)+AOpenOut*(TOut - 273.15)+BOpen) + 1);
      pClose = Modelica.Math.exp(ACloseIn*(TIn - 273.15)+ACloseOut*(TOut - 273.15)+BClose)/(Modelica.Math.exp(ACloseIn*(TIn - 273.15)+ACloseOut*(TOut - 273.15)+BClose) + 1);
      if pre(on) then
        on = not Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=pClose, globalSeed=integer(curSeed));
      else
        on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=pOpen, globalSeed=integer(curSeed));
      end if;
    else
      pOpen = 0;
      pClose = 0;
      on = false;
    end if;
  end when;
end Haldi2009WindowsTInTout;


A model to predict occupants' window behavior with outdoor temperature for completely-open
large windows. Model predicting the state of the small window with the outdoor air temperature
and occupancy. The definition of large windows was not clearly presented in the
original paper.

within Buildings.Occupants.Office.Windows;
model Herkel2008WindowsCompletelyOpen "A model to predict occupants' window behavior with outdoor temperature for completely-open
large windows"
  extends Modelica.Blocks.Icons.DiscreteBlock;
  parameter Real A = 0.08 "Slope of the logistic relation";
  parameter Real B = -4.05 "Intercept of the logistic relation";
  parameter Integer seed = 3 "Seed for the random number generator";
  parameter Modelica.Units.SI.Time samplePeriod=120 "Sample period";

  Modelica.Blocks.Interfaces.RealInput TOut(
    final unit="K",
    displayUnit="degC") "Outdoor air temperature"
  Modelica.Blocks.Interfaces.BooleanInput occ
    "Indoor occupancy, true for occupied"
  Modelica.Blocks.Interfaces.BooleanOutput on "State of window, true for open"

  Real p(
    unit="1",
    min=0,
    max=1) "Probability of window opened";

protected
  parameter Modelica.Units.SI.Time t0(final fixed=false)
    "First sample time instant";
  output Boolean sampleTrigger "True, if sample time instant";
  Real curSeed "Current value for seed as a real-valued variable";
initial equation
  t0 = time;
  curSeed = t0*seed;
  p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
  on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));
equation
  sampleTrigger = sample(t0,samplePeriod);
  when sampleTrigger then
    curSeed = seed*time;
    if occ then
      p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
      on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));
    else
      p = 0;
      on = false;
    end if;
  end when;
end Herkel2008WindowsCompletelyOpen;


A model to predict occupants' window behavior with outdoor temperature for small windows. Model predicting the state of the small window with the outdoor air temperature
and occupancy. The definition of small windows was not clearly presented in the
original paper.

within Buildings.Occupants.Office.Windows;
model Herkel2008WindowsSmall "A model to predict occupants' window behavior with outdoor temperature for small windows"
  extends Modelica.Blocks.Icons.DiscreteBlock;
  parameter Real A = 0.16 "Slope of the logistic relation";
  parameter Real B = -2.99 "Intercept of the logistic relation";
  parameter Integer seed = 30 "Seed for the random number generator";
  parameter Modelica.Units.SI.Time samplePeriod=120 "Sample period";

  Modelica.Blocks.Interfaces.RealInput TOut(
    final unit="K",
    displayUnit="degC") "Outdoor air temperature"
  Modelica.Blocks.Interfaces.BooleanInput occ
    "Indoor occupancy, true for occupied"
  Modelica.Blocks.Interfaces.BooleanOutput on "State of window, true for open"

  Real p(
    unit="1",
    min=0,
    max=1) "Probability of window opened";

protected
  parameter Modelica.Units.SI.Time t0(final fixed=false)
    "First sample time instant";
  output Boolean sampleTrigger "True, if sample time instant";
  Real curSeed "Current value for seed as a real-valued variable";
initial equation
  t0 = time;
  curSeed = t0*seed;
  p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
  on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));
equation
  sampleTrigger = sample(t0,samplePeriod);
  when sampleTrigger then
    curSeed = seed*time;
    if occ then
      p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
      on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));
    else
      p = 0;
      on = false;
    end if;
  end when;
end Herkel2008WindowsSmall;


A model to predict occupants' window behavior with outdoor temperature for tilted-open
large windows. Model predicting the state of the small window with the outdoor air temperature
and occupancy. The definition of large windows was not clearly presented in the
original paper.

within Buildings.Occupants.Office.Windows;
model Herkel2008WindowsTiltedOpen "A model to predict occupants' window behavior with outdoor temperature for tilted-open
large windows"
  extends Modelica.Blocks.Icons.DiscreteBlock;
  parameter Real A = 0.08 "Slope of the logistic relation";
  parameter Real B = -3.13 "Intercept of the logistic relation";
  parameter Integer seed = 30 "Seed for the random number generator";
  parameter Modelica.Units.SI.Time samplePeriod=120 "Sample period";

  Modelica.Blocks.Interfaces.RealInput TOut(
    final unit="K",
    displayUnit="degC") "Outdoor air temperature"
  Modelica.Blocks.Interfaces.BooleanInput occ
    "Indoor occupancy, true for occupied"
  Modelica.Blocks.Interfaces.BooleanOutput on "State of window, true for open"

  Real p(
    unit="1",
    min=0,
    max=1) "Probability of window opened";

protected
  parameter Modelica.Units.SI.Time t0(final fixed=false)
    "First sample time instant";
  output Boolean sampleTrigger "True, if sample time instant";
  Real curSeed "Current value for seed as a real-valued variable";
initial equation
  t0 = time;
  curSeed = t0*seed;
  p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
  on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));
equation
  sampleTrigger = sample(t0,samplePeriod);
  when sampleTrigger then
    curSeed = seed*time;
    if occ then
      p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
      on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));
    else
      p = 0;
      on = false;
    end if;
  end when;
end Herkel2008WindowsTiltedOpen;


within Buildings.Occupants.Office;
package Windows "Package with models to simulate window behaviors in office buildings"
  extends Modelica.Icons.VariantsPackage;
end Windows;


A model to predict occupants' window behavior with indoor, outdoor and comfort temperature. Model predicting the state of the window with the indoor, outdoor and comfort temperature
and occupancy.

within Buildings.Occupants.Office.Windows;
model Rijal2007WindowsTInTOutTComf "A model to predict occupants' window behavior with indoor, outdoor and comfort temperature"
  extends Modelica.Blocks.Icons.DiscreteBlock;
  parameter Real AIn = 0.171 "Slope of the indoor temperature in the logistic relation";
  parameter Real AOut = 0.166 "Slope of the outdoor temperature in the logistic relation";
  parameter Real B = -6.4 "Intercept of the logistic relation";
  parameter Integer seed = 3 "Seed for the random number generator";
  parameter Modelica.Units.SI.Time samplePeriod=120 "Sample period";

  Modelica.Blocks.Interfaces.RealInput TIn(
    final unit="K",
    displayUnit="degC") "Indoor air temperature"
  Modelica.Blocks.Interfaces.RealInput TOut(
    final unit="K",
    displayUnit="degC") "Outdoor air temperature"
  Modelica.Blocks.Interfaces.RealInput TComf(
    final unit="K",
    displayUnit="degC") "Comfort temperature"
  Modelica.Blocks.Interfaces.BooleanInput occ
    "Indoor occupancy, true for occupied"
  Modelica.Blocks.Interfaces.BooleanOutput on "State of window, true for open"

  Real p(
    unit="1",
    min=0,
    max=1) "Probability of window opened";

protected
  parameter Modelica.Units.SI.Time t0(final fixed=false)
    "First sample time instant";
  output Boolean sampleTrigger "True, if sample time instant";
  Real curSeed "Current value for seed as a real-valued variable";

initial equation
  t0 = time;
  curSeed = t0*seed;
  p = Modelica.Math.exp(AIn*(TIn - 273.15)+AOut*(TOut - 273.15)+B)/(Modelica.Math.exp(AIn*(TIn - 273.15)+AOut*(TOut - 273.15)+B) + 1);
  on = false;

equation
  sampleTrigger = sample(t0,samplePeriod);
  when sampleTrigger then
    curSeed = seed*time;
    if occ then
      if TIn > TComf+2 then
        if not pre(on) then
          p = Modelica.Math.exp(AIn*(TIn - 273.15)+AOut*(TOut - 273.15)+B)/(Modelica.Math.exp(AIn*(TIn - 273.15)+AOut*(TOut - 273.15)+B) + 1);
          on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));
        else
          p = -0.3;
          on = true;
        end if;
      elseif TIn < TComf-2 then
        if pre(on) then
          p = Modelica.Math.exp(AIn*(TIn - 273.15)+AOut*(TOut - 273.15)+B)/(Modelica.Math.exp(AIn*(TIn - 273.15)+AOut*(TOut - 273.15)+B) + 1);
          on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));
        else
          p = -0.5;
          on = false;
        end if;
      else
        p = -0.1;
        on = pre(on);
      end if;
    else
      p = 0;
      on = false;
    end if;
  end when;
end Rijal2007WindowsTInTOutTComf;


A model to predict occupants' window behavior with indoor temperature. Model predicting the state of the window with the indoor air temperature
and occupancy through Markov approach.

within Buildings.Occupants.Office.Windows;
model Yun2008WindowsTIn "A model to predict occupants' window behavior with indoor temperature"
  extends Modelica.Blocks.Icons.DiscreteBlock;
  parameter Real AOpen = 0.030 "Slope of the logistic relation for opening the window";
  parameter Real BOpen = -0.629 "Intercept of the logistic relation for opening the window";
  parameter Real AClose = -0.007 "Slope of the logistic relation for closing the window";
  parameter Real BClose = -0.209 "Intercept of the logistic relation for closing the window";
  parameter Integer seed = 30 "Seed for the random number generator";
  parameter Modelica.Units.SI.Time samplePeriod=120 "Sample period";

  Modelica.Blocks.Interfaces.RealInput TIn(
    final unit="K",
    displayUnit="degC") "Indoor air temperature"
  Modelica.Blocks.Interfaces.BooleanInput occ
    "Indoor occupancy, true for occupied"
  Modelica.Blocks.Interfaces.BooleanOutput on "State of window, true for open"

  Real pOpen(
    unit="1",
    min=0,
    max=1) "Probability of opening the window";
  Real pClose(
    unit="1",
    min=0,
    max=1) "Probability of closing the window";

protected
  parameter Modelica.Units.SI.Time t0(final fixed=false)
    "First sample time instant";
  output Boolean sampleTrigger "True, if sample time instant";
  Real curSeed "Current value for seed as a real-valued variable";

initial equation
  t0 = time;
  curSeed = t0*seed;
  on = false;
  pOpen = Modelica.Math.exp(AOpen*(TIn - 273.15)+BOpen)/(Modelica.Math.exp(AOpen*(TIn - 273.15)+BOpen) + 1);
  pClose = Modelica.Math.exp(AClose*(TIn - 273.15)+BClose)/(Modelica.Math.exp(AClose*(TIn - 273.15)+BClose) + 1);

equation
  sampleTrigger = sample(t0,samplePeriod);
  when sampleTrigger then
    curSeed = seed*time;
    if occ then
      pOpen = Modelica.Math.exp(AOpen*(TIn - 273.15)+BOpen)/(Modelica.Math.exp(AOpen*(TIn - 273.15)+BOpen) + 1);
      pClose = Modelica.Math.exp(AClose*(TIn - 273.15)+BClose)/(Modelica.Math.exp(AClose*(TIn - 273.15)+BClose) + 1);
      if pre(on) == true and TIn < 303.15 then
        on = not Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=pClose, globalSeed=integer(curSeed));
      elseif pre(on) == false and TIn > 293.15 then
        on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=pOpen, globalSeed=integer(curSeed));
      else
        on = pre(on);
      end if;
    else
      pOpen = 0;
      pClose = 0;
      on = false;
    end if;
  end when;
end Yun2008WindowsTIn;


A model to predict occupants' window behavior with outdoor temperature. Model predicting the state of the window with the outdoor air temperature
and occupancy through Markov approach.

within Buildings.Occupants.Office.Windows;
model Yun2008WindowsTOut "A model to predict occupants' window behavior with outdoor temperature"
  extends Modelica.Blocks.Icons.DiscreteBlock;
  parameter Real AOpen = 0.009 "Slope of the logistic relation for opening the window";
  parameter Real BOpen = -0.115 "Intercept of the logistic relation for opening the window";
  parameter Real AClose = 0 "Slope of the logistic relation for closing the window";
  parameter Real BClose = -0.040 "Intercept of the logistic relation for closing the window";
  parameter Integer seed = 30 "Seed for the random number generator";
  parameter Modelica.Units.SI.Time samplePeriod=120 "Sample period";

  Modelica.Blocks.Interfaces.RealInput TOut(
    final unit="K",
    displayUnit="degC") "Outdoor air temperature"
  Modelica.Blocks.Interfaces.BooleanInput occ
    "Indoor occupancy, true for occupied"
  Modelica.Blocks.Interfaces.BooleanOutput on "State of window, true for open"

  Real pOpen(
    unit="1",
    min=0,
    max=1) "Probability of opening the window";
  Real pClose(
    unit="1",
    min=0,
    max=1) "Probability of closing the window";

protected
  parameter Modelica.Units.SI.Time t0(final fixed=false)
    "First sample time instant";
  output Boolean sampleTrigger "True, if sample time instant";
  Real curSeed "Current value for seed as a real-valued variable";
initial equation
  t0 = time;
  curSeed = t0*seed;
  on = false;
  pOpen = Modelica.Math.exp(AOpen*(TOut - 273.15)+BOpen)/(Modelica.Math.exp(AOpen*(TOut - 273.15)+BOpen) + 1);
  pClose = Modelica.Math.exp(AClose*(TOut - 273.15)+BClose)/(Modelica.Math.exp(AClose*(TOut - 273.15)+BClose) + 1);

equation
  sampleTrigger = sample(t0,samplePeriod);
  when sampleTrigger then
    curSeed = seed*time;
    if occ then
      pOpen = Modelica.Math.exp(AOpen*(TOut - 273.15)+BOpen)/(Modelica.Math.exp(AOpen*(TOut - 273.15)+BOpen) + 1);
      pClose = Modelica.Math.exp(AClose*(TOut - 273.15)+BClose)/(Modelica.Math.exp(AClose*(TOut - 273.15)+BClose) + 1);
      if pre(on) then
        on = not Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=pClose, globalSeed=integer(curSeed));
      elseif pre(on) == false and TOut > 288.15 then
        on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=pOpen, globalSeed=integer(curSeed));
      else
        on = pre(on);
      end if;
    else
      pOpen = 0;
      pClose = 0;
      on = false;
    end if;
  end when;
end Yun2008WindowsTOut;


within Buildings.Occupants.Office.Windows;
model Zhang2012WindowsAll "A model to predict occupants' window behavior with outdoor temperature"
  extends Modelica.Blocks.Icons.DiscreteBlock;
  parameter Real A = 0.10 "Slope of the logistic relation";
  parameter Real B = -4.01 "Intercept of the logistic relation";
  parameter Integer seed = 30 "Seed for the random number generator";
  parameter Modelica.Units.SI.Time samplePeriod=120 "Sample period";

  Modelica.Blocks.Interfaces.RealInput TOut(
    final unit="K",
    displayUnit="degC") "Outdoor air temperature"
  Modelica.Blocks.Interfaces.BooleanInput occ
    "Indoor occupancy, true for occupied"
  Modelica.Blocks.Interfaces.BooleanOutput on "State of window, true for open"

  Real p(
    unit="1",
    min=0,
    max=1) "Probability of window opened";

protected
  parameter Modelica.Units.SI.Time t0(final fixed=false)
    "First sample time instant";
  output Boolean sampleTrigger "True, if sample time instant";
  Real curSeed "Current value for seed as a real-valued variable";

initial equation
  t0 = time;
  curSeed = t0*seed;
  p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
  on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));

equation
  sampleTrigger = sample(t0,samplePeriod);
  when sampleTrigger then
    curSeed = seed*time;
    if occ then
      p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
      on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));
    else
      p = 0;
      on = false;
    end if;
  end when;
end Zhang2012WindowsAll;


A model to predict occupants' window behavior with outdoor temperature for East-oriented Windows. Model predicting the state of the East-oriented windows with the outdoor air temperature
and occupancy.

within Buildings.Occupants.Office.Windows;
model Zhang2012WindowsEast "A model to predict occupants' window behavior with outdoor temperature for East-oriented Windows"
  extends Modelica.Blocks.Icons.DiscreteBlock;
  parameter Real A = 0.09 "Slope of the logistic relation";
  parameter Real B = -3.72 "Intercept of the logistic relation";
  parameter Integer seed = 50 "Seed for the random number generator";
  parameter Modelica.Units.SI.Time samplePeriod=120 "Sample period";

  Modelica.Blocks.Interfaces.RealInput TOut(
    final unit="K",
    displayUnit="degC") "Outdoor air temperature"
  Modelica.Blocks.Interfaces.BooleanInput occ
    "Indoor occupancy, true for occupied"
  Modelica.Blocks.Interfaces.BooleanOutput on "State of East-oriented window, true for open"

  Real p(
    unit="1",
    min=0,
    max=1) "Probability of window opened";

protected
  parameter Modelica.Units.SI.Time t0(final fixed=false)
    "First sample time instant";
  output Boolean sampleTrigger "True, if sample time instant";
  Real curSeed "Current value for seed as a real-valued variable";

initial equation
  t0 = time;
  curSeed = t0*seed;
  p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
  on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));

equation
  sampleTrigger = sample(t0,samplePeriod);
  when sampleTrigger then
    curSeed = seed*time;
    if occ then
      p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
      on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));
    else
      p = 0;
      on = false;
    end if;
  end when;
end Zhang2012WindowsEast;


A model to predict occupants' window behavior with outdoor temperature for North-oriented windows. Model predicting the state of the North-oriented window with the outdoor air temperature
and occupancy.

within Buildings.Occupants.Office.Windows;
model Zhang2012WindowsNorth "A model to predict occupants' window behavior with outdoor temperature for North-oriented windows"
  extends Modelica.Blocks.Icons.DiscreteBlock;
  parameter Real A = 0.12 "Slope of the logistic relation";
  parameter Real B = -4.38 "Intercept of the logistic relation";
  parameter Integer seed = 30 "Seed for the random number generator";
  parameter Modelica.Units.SI.Time samplePeriod=120 "Sample period";

  Modelica.Blocks.Interfaces.RealInput TOut(
    final unit="K",
    displayUnit="degC") "Outdoor air temperature"
  Modelica.Blocks.Interfaces.BooleanInput occ
    "Indoor occupancy, true for occupied"
  Modelica.Blocks.Interfaces.BooleanOutput on "State of North-oriented window, true for open"

  Real p(
    unit="1",
    min=0,
    max=1) "Probability of window opened";

protected
  parameter Modelica.Units.SI.Time t0(final fixed=false)
    "First sample time instant";
  output Boolean sampleTrigger "True, if sample time instant";
  Real curSeed "Current value for seed as a real-valued variable";
initial equation
  t0 = time;
  curSeed = t0*seed;
  p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
  on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));
equation
  sampleTrigger = sample(t0,samplePeriod);
  when sampleTrigger then
    curSeed = seed*time;
    if occ then
      p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
      on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));
    else
      p = 0;
      on = false;
    end if;
  end when;
end Zhang2012WindowsNorth;


A model to predict occupants' window behavior with outdoor temperature for South-oriented windows. Model predicting the state of the South-oriented window with the outdoor air temperature
and occupancy.

within Buildings.Occupants.Office.Windows;
model Zhang2012WindowsSouth "A model to predict occupants' window behavior with outdoor temperature for South-oriented windows"
  extends Modelica.Blocks.Icons.DiscreteBlock;
  parameter Real A = 0.10 "Slope of the logistic relation";
  parameter Real B = -3.64 "Intercept of the logistic relation";
  parameter Integer seed = 30 "Seed for the random number generator";
  parameter Modelica.Units.SI.Time samplePeriod=120 "Sample period";

  Modelica.Blocks.Interfaces.RealInput TOut(
    final unit="K",
    displayUnit="degC") "Outdoor air temperature"
  Modelica.Blocks.Interfaces.BooleanInput occ
    "Indoor occupancy, true for occupied"
  Modelica.Blocks.Interfaces.BooleanOutput on "State of South-oriented window, true for open"

  Real p(
    unit="1",
    min=0,
    max=1) "Probability of window opened";

protected
  parameter Modelica.Units.SI.Time t0(final fixed=false)
    "First sample time instant";
  output Boolean sampleTrigger "True, if sample time instant";
  Real curSeed "Current value for seed as a real-valued variable";

initial equation
  t0 = time;
  curSeed = t0*seed;
  p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
  on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));

equation
  sampleTrigger = sample(t0,samplePeriod);
  when sampleTrigger then
    curSeed = seed*time;
    if occ then
      p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
      on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));
    else
      p = 0;
      on = false;
    end if;
  end when;
end Zhang2012WindowsSouth;


A model to predict occupants' window behavior with outdoor temperature for West-oriented windows. Model predicting the state of the West-oriented window with the outdoor air temperature
and occupancy.

within Buildings.Occupants.Office.Windows;
model Zhang2012WindowsWest "A model to predict occupants' window behavior with outdoor temperature for West-oriented windows"
  extends Modelica.Blocks.Icons.DiscreteBlock;
  parameter Real A = 0.12 "Slope of the logistic relation";
  parameter Real B = -4.77 "Intercept of the logistic relation";
  parameter Integer seed = 50 "Seed for the random number generator";
  parameter Modelica.Units.SI.Time samplePeriod=120 "Sample period";

  Modelica.Blocks.Interfaces.RealInput TOut(
    final unit="K",
    displayUnit="degC") "Outdoor air temperature"
  Modelica.Blocks.Interfaces.BooleanInput occ
    "Indoor occupancy, true for occupied"
  Modelica.Blocks.Interfaces.BooleanOutput on "State of West-oriented window, true for open"

  Real p(
    unit="1",
    min=0,
    max=1) "Probability of window opened";

protected
  parameter Modelica.Units.SI.Time t0(final fixed=false)
    "First sample time instant";
  output Boolean sampleTrigger "True, if sample time instant";
  Real curSeed "Current value for seed as a real-valued variable";
initial equation
  t0 = time;
  curSeed = t0*seed;
  p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
  on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));
equation
  sampleTrigger = sample(t0,samplePeriod);
  when sampleTrigger then
    curSeed = seed*time;
    if occ then
      p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
      on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));
    else
      p = 0;
      on = false;
    end if;
  end when;
end Zhang2012WindowsWest;


Validating the model for window behaviors. This example validates

Buildings.Occupants.Office.Windows.Haldi2008WindowsTIn
by examing how the window state corresponds
to the indoor temperature.

within Buildings.Occupants.Office.Windows.Validation;
model Haldi2008WindowsTIn "Validating the model for window behaviors"
    extends Modelica.Icons.Example;

    Modelica.Blocks.Sources.BooleanStep occ(startTime=1800)
                                            "True for occupied"
  Modelica.Blocks.Sources.Sine TIn(
    amplitude=15,
    offset=288,
    f=0.001,
    y(unit="K", displayUnit="degC")) "Indoor air temperature"
    Buildings.Occupants.Office.Windows.Haldi2008WindowsTIn win
equation
    connect(occ.y, win.occ)
    connect(TIn.y, win.TIn)
end Haldi2008WindowsTIn;


Validating the model for window behaviors. This example validates

Buildings.Occupants.Office.Windows.Haldi2008WindowsTOut
by examing how the window state corresponds
to the outdoor temperature.

within Buildings.Occupants.Office.Windows.Validation;
model Haldi2008WindowsTOut "Validating the model for window behaviors"
    extends Modelica.Icons.Example;

    Modelica.Blocks.Sources.BooleanStep occ(startTime=1800)
                                            "True for occupied"
  Modelica.Blocks.Sources.Sine TOut(
    amplitude=15,
    offset=288,
    f=0.001,
    y(unit="K", displayUnit="degC")) "Outdoor air temperature"
    Buildings.Occupants.Office.Windows.Haldi2008WindowsTOut win "Tested windows model"
equation
    connect(win.occ, occ.y)
    connect(win.TOut, TOut.y)
end Haldi2008WindowsTOut;


Validating the model for window behaviors. This example validates

Buildings.Occupants.Office.Windows.Haldi2009WindowsTInTout
by examing how the window state corresponds
to the indoor, outdoor temperature.

within Buildings.Occupants.Office.Windows.Validation;
model Haldi2009WindowsTInTout "Validating the model for window behaviors"
    extends Modelica.Icons.Example;

    Modelica.Blocks.Sources.BooleanStep occ(startTime=900)
                                            "True for occupied"
  Modelica.Blocks.Sources.Sine TIn(
    amplitude=10,
    f=0.0007,
    y(unit="K", displayUnit="degC"),
    offset=298) "Indoor air temperature"
  Modelica.Blocks.Sources.Sine TOut(
    f=0.001,
    y(unit="K", displayUnit="degC"),
    offset=298,
    amplitude=12) "Outdoor air temperature"
    Buildings.Occupants.Office.Windows.Haldi2009WindowsTInTout win "Tested windows model"
equation
    connect(win.occ, occ.y)
    connect(win.TOut, TOut.y)
    connect(win.TIn, TIn.y)
end Haldi2009WindowsTInTout;


Validating the model for window behaviors. This example validates

Buildings.Occupants.Office.Windows.Herkel2008WindowsCompletelyOpen
by examing how the window state corresponds
to the outdoor temperature.

within Buildings.Occupants.Office.Windows.Validation;
model Herkel2008WindowsCompletelyOpen "Validating the model for window behaviors"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.BooleanStep occ(startTime=1800)
                                          "True for occupied"
  Modelica.Blocks.Sources.Sine TOut(
    amplitude=15,
    offset=288,
    f=0.001,
    y(unit="K", displayUnit="degC")) "Outdoor air temperature"
  Buildings.Occupants.Office.Windows.Herkel2008WindowsCompletelyOpen win "Tested windows model"
equation
  connect(win.occ, occ.y)
  connect(win.TOut, TOut.y)
end Herkel2008WindowsCompletelyOpen;


Validating the model for window behaviors. This example validates

Buildings.Occupants.Office.Windows.Herkel2008WindowsSmall
by examing how the window state corresponds
to the outdoor temperature.

within Buildings.Occupants.Office.Windows.Validation;
model Herkel2008WindowsSmall "Validating the model for window behaviors"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.BooleanStep occ(startTime=1800)
                                          "True for occupied"
  Modelica.Blocks.Sources.Sine TOut(
    amplitude=15,
    offset=288,
    f=0.001,
    y(unit="K", displayUnit="degC")) "Outdoor air temperature"
  Buildings.Occupants.Office.Windows.Herkel2008WindowsSmall win "Tested windows model"
equation
  connect(win.occ, occ.y)
  connect(win.TOut, TOut.y)
end Herkel2008WindowsSmall;


Validating the model for window behaviors. This example validates

Buildings.Occupants.Office.Windows.Herkel2008WindowsTiltedOpen
by examing how the window state corresponds
to the outdoor temperature.

within Buildings.Occupants.Office.Windows.Validation;
model Herkel2008WindowsTiltedOpen "Validating the model for window behaviors"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.BooleanStep occ(startTime=1800)
                                          "True for occupied"
  Modelica.Blocks.Sources.Sine TOut(
    amplitude=15,
    offset=288,
    f=0.001,
    y(unit="K", displayUnit="degC")) "Outdoor air temperature"
  Buildings.Occupants.Office.Windows.Herkel2008WindowsTiltedOpen win "Tested windows model"
equation
  connect(win.occ, occ.y)
  connect(win.TOut, TOut.y)
end Herkel2008WindowsTiltedOpen;


within Buildings.Occupants.Office.Windows;
package Validation "Package with examples to validate models in Windows package"
  extends Modelica.Icons.ExamplesPackage;
end Validation;


Validating the model for window behaviors. This example validates

Buildings.Occupants.Office.Windows.Rijal2007WindowsTInTOutTComf
by examing how the window state corresponds
to the indoor, outdoor and comfort temperature.

within Buildings.Occupants.Office.Windows.Validation;
model Rijal2007WindowsTInTOutTComf "Validating the model for window behaviors"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.BooleanStep occ(startTime=900)
                                          "True for occupied"
  Modelica.Blocks.Sources.Sine TIn(
    amplitude=10,
    f=0.0007,
    y(unit="K", displayUnit="degC"),
    offset=298) "Indoor air temperature"
  Modelica.Blocks.Sources.Sine TOut(
    f=0.001,
    y(unit="K", displayUnit="degC"),
    offset=298,
    amplitude=12) "Outdoor air temperature"
  Modelica.Blocks.Sources.Sine TComf(
    amplitude=2,
    offset=298,
    f=0.0005,
    y(unit="K", displayUnit="degC")) "Comfort air temperature"
  Buildings.Occupants.Office.Windows.Rijal2007WindowsTInTOutTComf win "Tested windows model"
equation
  connect(win.occ, occ.y)
  connect(win.TOut, TOut.y)
  connect(win.TIn, TIn.y)
  connect(win.TComf, TComf.y)
end Rijal2007WindowsTInTOutTComf;


Validating the model for window behaviors. This example validates

Buildings.Occupants.Office.Windows.Yun2008WindowsTIn
by examing how the window state corresponds
to the indoor temperature.

within Buildings.Occupants.Office.Windows.Validation;
model Yun2008WindowsTIn "Validating the model for window behaviors"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.BooleanStep occ(startTime=1800)
                                          "True for occupied"
  Modelica.Blocks.Sources.Sine TIn(
    amplitude=15,
    offset=288,
    f=0.001,
    y(unit="K", displayUnit="degC")) "Indoor air temperature"
  Buildings.Occupants.Office.Windows.Yun2008WindowsTIn win
equation
  connect(occ.y, win.occ)
  connect(TIn.y, win.TIn)
end Yun2008WindowsTIn;


Validating the model for window behaviors. This example validates

Buildings.Occupants.Office.Windows.Yun2008WindowsTOut
by examing how the window state corresponds
to the outdoor temperature.

within Buildings.Occupants.Office.Windows.Validation;
model Yun2008WindowsTOut "Validating the model for window behaviors"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.BooleanStep occ(startTime=1800)
                                          "True for occupied"
  Modelica.Blocks.Sources.Sine TOut(
    amplitude=15,
    offset=288,
    f=0.001,
    y(unit="K", displayUnit="degC")) "Outdoor air temperature"
  Buildings.Occupants.Office.Windows.Yun2008WindowsTOut win
equation
  connect(occ.y, win.occ)
  connect(TOut.y, win.TOut)
end Yun2008WindowsTOut;


Validating the model for window behaviors. This example validates

Buildings.Occupants.Office.Windows.Zhang2012WindowsAll
by examing how the window state corresponds
to the outdoor temperature.

within Buildings.Occupants.Office.Windows.Validation;
model Zhang2012WindowsAll "Validating the model for window behaviors"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.BooleanStep occ(startTime=1800)
                                          "True for occupied"
  Modelica.Blocks.Sources.Sine TOut(
    amplitude=15,
    offset=288,
    f=0.001,
    y(unit="K", displayUnit="degC")) "Outdoor air temperature"
  Buildings.Occupants.Office.Windows.Zhang2012WindowsAll win "Tested windows model"
equation
  connect(win.occ, occ.y)
  connect(win.TOut, TOut.y)
end Zhang2012WindowsAll;


Validating the model for window behaviors. This example validates

Buildings.Occupants.Office.Windows.Zhang2012WindowsEast
by examing how the window state corresponds
to the outdoor temperature.

within Buildings.Occupants.Office.Windows.Validation;
model Zhang2012WindowsEast "Validating the model for window behaviors"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.BooleanStep occ(startTime=1800)
                                          "True for occupied"
  Modelica.Blocks.Sources.Sine TOut(
    amplitude=15,
    offset=288,
    f=0.001,
    y(unit="K", displayUnit="degC")) "Outdoor air temperature"
  Buildings.Occupants.Office.Windows.Zhang2012WindowsEast win "Tested windows model"
equation
  connect(win.occ, occ.y)
  connect(win.TOut, TOut.y)
end Zhang2012WindowsEast;


Validating the model for window behaviors. This example validates

Buildings.Occupants.Office.Windows.Zhang2012WindowsNorth
by examing how the window state corresponds
to the outdoor temperature.

within Buildings.Occupants.Office.Windows.Validation;
model Zhang2012WindowsNorth "Validating the model for window behaviors"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.BooleanStep occ(startTime=1800)
                                          "True for occupied"
  Modelica.Blocks.Sources.Sine TOut(
    amplitude=15,
    offset=288,
    f=0.001,
    y(unit="K", displayUnit="degC")) "Outdoor air temperature"
  Buildings.Occupants.Office.Windows.Zhang2012WindowsNorth win "Tested windows model"
equation
  connect(win.occ, occ.y)
  connect(win.TOut, TOut.y)
end Zhang2012WindowsNorth;


Validating the model for window behaviors. This example validates

Buildings.Occupants.Office.Windows.Zhang2012WindowsSouth
by examing how the window state corresponds
to the outdoor temperature.

within Buildings.Occupants.Office.Windows.Validation;
model Zhang2012WindowsSouth "Validating the model for window behaviors"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.BooleanStep occ(startTime=1800)
                                          "True for occupied"
  Modelica.Blocks.Sources.Sine TOut(
    amplitude=15,
    offset=288,
    f=0.001,
    y(unit="K", displayUnit="degC")) "Outdoor air temperature"
  Buildings.Occupants.Office.Windows.Zhang2012WindowsSouth win "Tested windows model"
equation
  connect(win.occ, occ.y)
  connect(win.TOut, TOut.y)
end Zhang2012WindowsSouth;


Validating the model for window behaviors. This example validates

Buildings.Occupants.Office.Windows.Zhang2012WindowsWest
by examing how the window state corresponds
to the outdoor temperature.

within Buildings.Occupants.Office.Windows.Validation;
model Zhang2012WindowsWest "Validating the model for window behaviors"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.BooleanStep occ(startTime=1800)
                                          "True for occupied"
  Modelica.Blocks.Sources.Sine TOut(
    amplitude=15,
    offset=288,
    f=0.001,
    y(unit="K", displayUnit="degC")) "Outdoor air temperature"
  Buildings.Occupants.Office.Windows.Zhang2012WindowsWest win "Tested windows model"
equation
  connect(win.occ, occ.y)
  connect(win.TOut, TOut.y)
end Zhang2012WindowsWest;


within Buildings.Occupants;
package Residential "Package with models to simulate occupant behaviors in resident buildings"
    extends Modelica.Icons.Package;
end Residential;


within Buildings.Occupants.Residential;
package AirConditioning "Package with models to simulate air conditioning behaviors in resident buildings"
    extends Modelica.Icons.VariantsPackage;
end AirConditioning;


A model to predict occupants' AC behavior in bedroom with indoor temperature. Model predicting the state of the AC with the indoor temperature
and occupancy.

within Buildings.Occupants.Residential.AirConditioning;
model Ren2014ACBedroom
  "A model to predict occupants' AC behavior in bedroom with indoor temperature"
  extends Modelica.Blocks.Icons.DiscreteBlock;
  parameter Real u1 = 304.40 "Threshold for turning off the AC of the Weibull Distribution";
  parameter Real u2 = 301.90 "Threshold for turning on the AC of the Weibull Distribution";
  parameter Real L1 = 13.34 "Normalization factor for turning off the AC of the Weibull Distribution";
  parameter Real L2 = 42.86 "Normalization factor for turning on the AC of the Weibull Distribution";
  parameter Real k1 = 1.73 "Shape factor for turning off the AC of the Weibull Distribution";
  parameter Real k2 = 1.80 "Shape factor for turning on the AC of the Weibull Distribution";
  parameter Modelica.Units.SI.Time samplePeriod=120 "Sample period";
  parameter Integer seed = 10 "Seed for random number generator";

  Modelica.Blocks.Interfaces.RealInput TIn(
    final unit="K",
    displayUnit="degC") "Indoor air temperature"
  Modelica.Blocks.Interfaces.BooleanInput occ
    "Indoor occupancy, true for occupied"

  Modelica.Blocks.Interfaces.BooleanOutput on "State of AC"

  Real pOn(
    final unit="1",
    final min=0,
    final max=1) "Probability of turning on the AC";
  Real pOff(
    final unit="1",
    final min=0,
    final max=1) "Probability of turning off the AC";

protected
  parameter Modelica.Units.SI.Time t0(final fixed=false)
    "First sample time instant";
  output Boolean sampleTrigger "True, if sample time instant";
  Real curSeed "Current value for seed as a real-valued variable";

initial equation
  t0 = time;
  curSeed = t0*seed;
  on = false "The initial state of AC is off";
  pOn = 0;
  pOff = 0;

equation
  sampleTrigger = sample(t0,samplePeriod);
  when sampleTrigger then
    curSeed = seed*time;
    pOff = if TIn <= u1 then 1 - Modelica.Math.exp(-((u1-TIn)/L1)^k1*samplePeriod) else 0;
    pOn = if TIn >= u2 then 1 - Modelica.Math.exp(-((TIn-u2)/L2)^k2*samplePeriod) else 0;
    if occ then
      if pre(on) then
        on = not Buildings.Occupants.BaseClasses.weibull1DOFF(
          x=TIn,
          u=u1,
          L=L1,
          k=k1,
          dt=samplePeriod,
          globalSeed=integer(curSeed));
      else
        on = Buildings.Occupants.BaseClasses.weibull1DON(
          x=TIn,
          u=u2,
          L=L2,
          k=k2,
          dt=samplePeriod,
          globalSeed=integer(curSeed));
      end if;
    else
      on = false;
    end if;
  end when;
end Ren2014ACBedroom;


A model to predict occupants' AC behavior in Livingroom with indoor temperature. Model predicting the state of the AC with the indoor temperature
and occupancy.

within Buildings.Occupants.Residential.AirConditioning;
model Ren2014ACLivingroom
  "A model to predict occupants' AC behavior in Livingroom with indoor temperature"
  extends Modelica.Blocks.Icons.DiscreteBlock;
  parameter Real u1 = 303.40 "Threshold for turning off the AC of the Weibull Distribution";
  parameter Real u2 = 300.90 "Threshold for turning on the AC of the Weibull Distribution";
  parameter Real L1 = 152.88 "Normalization factor for turning off the AC of the Weibull Distribution";
  parameter Real L2 = 15.87 "Normalization factor for turning on the AC of the Weibull Distribution";
  parameter Real k1 = 1.30 "Shape factor for turning off the AC of the Weibull Distribution";
  parameter Real k2 = 2.22 "Shape factor for turning on the AC of the Weibull Distribution";
  parameter Modelica.Units.SI.Time samplePeriod=120 "Sample period";
  parameter Integer seed = 10 "Seed for random number generator";

  Modelica.Blocks.Interfaces.RealInput TIn(
    final unit="K",
    displayUnit="degC") "Indoor air temperature"
  Modelica.Blocks.Interfaces.BooleanInput occ
    "Indoor occupancy, true for occupied"

  Modelica.Blocks.Interfaces.BooleanOutput on "State of AC"

  Real pOn(
    unit="1",
    min=0,
    max=1) "Probability of turning on the AC";
  Real pOff(
    unit="1",
    min=0,
    max=1) "Probability of turning off the AC";

protected
  parameter Modelica.Units.SI.Time t0(final fixed=false)
    "First sample time instant";
  output Boolean sampleTrigger "True, if sample time instant";
  Real curSeed "Current value for seed as a real-valued variable";

initial equation
  t0 = time;
  curSeed = t0*seed;
  on = false "The initial state of AC is off";
  pOn = 0;
  pOff = 0;

equation
  sampleTrigger = sample(t0,samplePeriod);
  when sampleTrigger then
    curSeed = seed*time;
    pOff = if TIn <= u1 then 1 - Modelica.Math.exp(-((u1-TIn)/L1)^k1*samplePeriod) else 0;
    pOn = if TIn >= u2 then 1 - Modelica.Math.exp(-((TIn-u2)/L2)^k2*samplePeriod) else 0;
    if occ then
      if pre(on) then
        on = not Buildings.Occupants.BaseClasses.weibull1DOFF(
          x=TIn,
          u=u1,
          L=L1,
          k=k1,
          dt=samplePeriod,
          globalSeed=integer(curSeed));
      else
        on = Buildings.Occupants.BaseClasses.weibull1DON(
          x=TIn,
          u=u2,
          L=L2,
          k=k2,
          dt=samplePeriod,
          globalSeed=integer(curSeed));
      end if;
    else
      on = false;
    end if;
  end when;
end Ren2014ACLivingroom;


within Buildings.Occupants.Residential.AirConditioning;
package Validation "Package with examples to validate models in AC package"
  extends Modelica.Icons.ExamplesPackage;
end Validation;


Validating the model for AC behaviors. This example validates

Buildings.Occupants.Residential.AirConditioning.Ren2014ACBedroom
by examing how the AC state corresponds
to the indoor temperature.

within Buildings.Occupants.Residential.AirConditioning.Validation;
model Ren2014ACBedroom "Validating the model for AC behaviors"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.BooleanStep occ(startTime=600)
                                          "True for occupied"
  Modelica.Blocks.Sources.Sine Tin(
    amplitude=10,
    offset=303,
    f=0.001,
    y(unit="K", displayUnit="degC")) "Indoor air temperature"
  Buildings.Occupants.Residential.AirConditioning.Ren2014ACBedroom ac "Tested AC model"

equation
  connect(occ.y, ac.occ)
  connect(Tin.y, ac.TIn)
end Ren2014ACBedroom;


Validating the model for AC behaviors. This example validates

Buildings.Occupants.Residential.AirConditioning.Ren2014ACLivingroom
by examing how the AC state corresponds
to the indoor temperature.

within Buildings.Occupants.Residential.AirConditioning.Validation;
model Ren2014ACLivingroom "Validating the model for AC behaviors"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.BooleanStep occ(startTime=1800)
                                          "True for occupied"
  Modelica.Blocks.Sources.Sine Tin(
    amplitude=10,
    offset=303,
    f=0.001,
    y(unit="K", displayUnit="degC")) "Indoor air temperature"
  Buildings.Occupants.Residential.AirConditioning.Ren2014ACLivingroom ac "Tested AC model"

equation
  connect(occ.y, ac.occ)
  connect(Tin.y, ac.TIn)
end Ren2014ACLivingroom;


A model to predict occupants' heating behavior with outdoor temperature. Model predicting the state of the heater with the outdoor temperature
and occupancy.

within Buildings.Occupants.Residential.Heating;
model Nicol2001HeatingEU "A model to predict occupants' heating behavior with outdoor temperature"
  extends Modelica.Blocks.Icons.DiscreteBlock;
  parameter Real A(final unit="1/K") = -0.32 "Slope of the logistic relation";
  parameter Real B(final unit="1") = 2.72 "Intercept of the logistic relation";
  parameter Integer seed = 10 "Seed for the random number generator";
  parameter Modelica.Units.SI.Time samplePeriod=120 "Sample period";

  Modelica.Blocks.Interfaces.RealInput TOut(
    final unit="K",
    displayUnit="degC") "Outdoor air temperature"
  Modelica.Blocks.Interfaces.BooleanInput occ
    "Indoor occupancy, true for occupied"
  Modelica.Blocks.Interfaces.BooleanOutput on "State of heater"

  Real p(
    final unit="1",
    final min=0,
    final max=1) "Probability of heating being on";

protected
  parameter Modelica.Units.SI.Time t0(final fixed=false)
    "First sample time instant";
  output Boolean sampleTrigger "True, if sample time instant";
  Real curSeed "Current value for seed as a real-valued variable";

initial equation
  t0 = time;
  curSeed = t0*seed;
  p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
  on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));

equation
  sampleTrigger = sample(t0,samplePeriod);
  when sampleTrigger then
    curSeed = seed*time;
    if occ then
      p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
      on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));
    else
      p = 0;
      on = false;
    end if;
  end when;
end Nicol2001HeatingEU;


within Buildings.Occupants.Residential.Heating;
model Nicol2001HeatingPakistan "A model to predict occupants' heating behavior with outdoor temperature"
  extends Modelica.Blocks.Icons.DiscreteBlock;
  parameter Real A(final unit="1/K") = -0.345 "Slope of the logistic relation";
  parameter Real B(final unit="1") = 2.73 "Intercept of the logistic relation";
  parameter Integer seed = 10 "Seed for the random number generator";
  parameter Modelica.Units.SI.Time samplePeriod=120 "Sample period";

  Modelica.Blocks.Interfaces.RealInput TOut(
    final unit="K",
    displayUnit="degC") "Outdoor air temperature"
  Modelica.Blocks.Interfaces.BooleanInput occ
    "Indoor occupancy, true for occupied"

  Modelica.Blocks.Interfaces.BooleanOutput on "State of heater"

  Real p(
    final unit="1",
    final min=0,
    final max=1) "Probability of heating being on";

protected
  parameter Modelica.Units.SI.Time t0(final fixed=false)
    "First sample time instant";
  output Boolean sampleTrigger "True, if sample time instant";
  Real curSeed "Current value for seed as a real-valued variable";

initial equation
  t0 = time;
  curSeed = t0*seed;
  p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
  on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));

equation
  sampleTrigger = sample(t0,samplePeriod);
  when sampleTrigger then
    curSeed = seed*time;
    if occ then
      p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
      on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));
    else
      p = 0;
      on = false;
    end if;
  end when;
end Nicol2001HeatingPakistan;


within Buildings.Occupants.Residential.Heating;
model Nicol2001HeatingUK "A model to predict occupants' heating behavior with outdoor temperature"
  extends Modelica.Blocks.Icons.DiscreteBlock;
  parameter Real A(final unit="1/K") = -0.514 "Slope of the logistic relation";
  parameter Real B(final unit="1") = 5.28 "Intercept of the logistic relation";
  parameter Integer seed = 10 "Seed for the random number generator";
  parameter Modelica.Units.SI.Time samplePeriod=120 "Sample period";

  Modelica.Blocks.Interfaces.RealInput TOut(
    final unit="K",
    displayUnit="degC") "Outdoor air temperature"
  Modelica.Blocks.Interfaces.BooleanInput occ
    "Indoor occupancy, true for occupied"

  Modelica.Blocks.Interfaces.BooleanOutput on "State of heater"

  Real p(
    final unit="1",
    final min=0,
    final max=1) "Probability of heating being on";

protected
  parameter Modelica.Units.SI.Time t0(final fixed=false)
    "First sample time instant";
  output Boolean sampleTrigger "True, if sample time instant";
  Real curSeed "Current value for seed as a real-valued variable";

initial equation
  t0 = time;
  curSeed = t0*seed;
  p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
  on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));

equation
  sampleTrigger = sample(t0,samplePeriod);
  when sampleTrigger then
    curSeed = seed*time;
    if occ then
      p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*( TOut - 273.15)+B) + 1);
      on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));
    else
      p = 0;
      on = false;
    end if;
  end when;
end Nicol2001HeatingUK;


within Buildings.Occupants.Residential;
package Heating "Package with models to simulate heating behaviors in resident buildings"
    extends Modelica.Icons.VariantsPackage;
end Heating;


Validating the model for heating behaviors. This example validates

Buildings.Occupants.Residential.Heating.Nicol2001HeatingEU
by examing how the heater state corresponds
to the outdoor temperature.

within Buildings.Occupants.Residential.Heating.Validation;
model Nicol2001HeatingEU "Validating the model for heating behaviors"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.BooleanStep occ(startTime=1800)
                                          "True for occupied"
  Modelica.Blocks.Sources.Sine TOut(
    amplitude=15,
    offset=288,
    f=0.001,
    y(unit="K", displayUnit="degC")) "Outdoor air temperature"
  Buildings.Occupants.Residential.Heating.Nicol2001HeatingEU hea "Occupancy model"
equation
  connect(hea.occ, occ.y)
  connect(hea.TOut, TOut.y)
end Nicol2001HeatingEU;


Validating the model for heating behaviors. This example validates

Buildings.Occupants.Residential.Heating.Nicol2001HeatingPakistan
by examing how the heater state corresponds
to the outdoor temperature.

within Buildings.Occupants.Residential.Heating.Validation;
model Nicol2001HeatingPakistan "Validating the model for heating behaviors"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.BooleanStep occ(startTime=1800)
                                          "True for occupied"
  Modelica.Blocks.Sources.Sine TOut(
    amplitude=15,
    offset=288,
    f=0.001,
    y(unit="K", displayUnit="degC")) "Outdoor air temperature"
  Buildings.Occupants.Residential.Heating.Nicol2001HeatingPakistan hea "Occupancy model"
equation
  connect(hea.occ, occ.y)
  connect(hea.TOut, TOut.y)
end Nicol2001HeatingPakistan;


Validating the model for heating behaviors. This example validates

Buildings.Occupants.Residential.Heating.Nicol2001HeatingUK
by examing how the heater state corresponds
to the outdoor temperature.

within Buildings.Occupants.Residential.Heating.Validation;
model Nicol2001HeatingUK "Validating the model for heating behaviors"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.BooleanStep occ(startTime=1800)
                                          "True for occupied"
  Modelica.Blocks.Sources.Sine TOut(
    amplitude=15,
    offset=288,
    f=0.001,
    y(unit="K", displayUnit="degC")) "Outdoor air temperature"
  Buildings.Occupants.Residential.Heating.Nicol2001HeatingUK hea "Tested heating model"
equation
  connect(hea.occ, occ.y)
  connect(hea.TOut, TOut.y)
end Nicol2001HeatingUK;


within Buildings.Occupants.Residential.Heating;
package Validation "Package with examples to validate models in Heating package"
    extends Modelica.Icons.ExamplesPackage;
end Validation;


A model to predict occupants' window behavior with outdoor temperature. Model predicting the state of the window with the outdoor air temperature
and occupancy.

within Buildings.Occupants.Residential.Windows;
model Nicol2001WindowsEU "A model to predict occupants' window behavior with outdoor temperature"
  extends Modelica.Blocks.Icons.DiscreteBlock;
  parameter Real A(final unit="1/K") = 0.104 "Slope of the logistic relation";
  parameter Real B(final unit="1") = -2.31 "Intercept of the logistic relation";
  parameter Integer seed = 30 "Seed for the random number generator";
  parameter Modelica.Units.SI.Time samplePeriod=120 "Sample period";

  Modelica.Blocks.Interfaces.RealInput TOut(
    final unit="K",
    displayUnit="degC") "Outdoor air temperature"
  Modelica.Blocks.Interfaces.BooleanInput occ
    "Indoor occupancy, true for occupied"
  Modelica.Blocks.Interfaces.BooleanOutput on "State of window"

  Real p(
    unit="1",
    min=0,
    max=1) "Probability of window opened";

protected
  parameter Modelica.Units.SI.Time t0(final fixed=false)
    "First sample time instant";
  output Boolean sampleTrigger "True, if sample time instant";
  Real curSeed "Current value for seed as a real-valued variable";
initial equation
  t0 = time;
  curSeed = t0*seed;
  p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
  on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p, globalSeed=integer(curSeed));
equation
  sampleTrigger = sample(t0,samplePeriod);
  when sampleTrigger then
    curSeed = seed*time;
    if occ then
      p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
      on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p, globalSeed=integer(curSeed));
    else
      p = 0;
      on = false;
    end if;
  end when;
end Nicol2001WindowsEU;


within Buildings.Occupants.Residential.Windows;
model Nicol2001WindowsPakistan "A model to predict occupants' window behavior with outdoor temperature"
  extends Modelica.Blocks.Icons.DiscreteBlock;
  parameter Real A(final unit="1/K") = 0.118 "Slope of the logistic relation";
  parameter Real B(final unit="1") = -3.73 "Intercept of the logistic relation";
  parameter Integer seed = 5 "Seed for the random number generator";
  parameter Modelica.Units.SI.Time samplePeriod=120 "Sample period";

  Modelica.Blocks.Interfaces.RealInput TOut(
    final unit="K",
    displayUnit="degC") "Outdoor air temperature"
  Modelica.Blocks.Interfaces.BooleanInput occ
    "Indoor occupancy, true for occupied"
  Modelica.Blocks.Interfaces.BooleanOutput on "State of window"

  Real p(
    unit="1",
    min=0,
    max=1) "Probability of window opened";

protected
  parameter Modelica.Units.SI.Time t0(final fixed=false)
    "First sample time instant";
  output Boolean sampleTrigger "True, if sample time instant";
  Real curSeed "Current value for seed as a real-valued variable";
initial equation
  t0 = time;
  curSeed = t0*seed;
  p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
  on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p, globalSeed=integer(curSeed));
equation
  sampleTrigger = sample(t0,samplePeriod);
  when sampleTrigger then
    curSeed = seed*time;
    if occ then
      p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
      on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p, globalSeed=integer(curSeed));
    else
      p = 0;
      on = false;
    end if;
  end when;
end Nicol2001WindowsPakistan;


within Buildings.Occupants.Residential.Windows;
model Nicol2001WindowsUK "A model to predict occupants' window behavior with outdoor temperature"
  extends Modelica.Blocks.Icons.DiscreteBlock;
  parameter Real A(final unit="1/K") = 0.169 "Slope of the logistic relation";
  parameter Real B(final unit="1") = -2.65 "Intercept of the logistic relation";
  parameter Integer seed = 30 "Seed for the random number generator";
  parameter Modelica.Units.SI.Time samplePeriod=120 "Sample period";

  Modelica.Blocks.Interfaces.RealInput TOut(
    final unit="K",
    displayUnit="degC") "Outdoor air temperature"
  Modelica.Blocks.Interfaces.BooleanInput occ
    "Indoor occupancy, true for occupied"
  Modelica.Blocks.Interfaces.BooleanOutput on "State of window"

  Real p(
    unit="1",
    min=0,
    max=1) "Probability of window opened";

protected
  parameter Modelica.Units.SI.Time t0(final fixed=false)
    "First sample time instant";
  output Boolean sampleTrigger "True, if sample time instant";
  Real curSeed "Current value for seed as a real-valued variable";
initial equation
  t0 = time;
  curSeed = t0*seed;
  p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
  on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));
equation
  sampleTrigger = sample(t0,samplePeriod);
  when sampleTrigger then
    curSeed = seed*time;
    if occ then
      p = Modelica.Math.exp(A*(TOut - 273.15)+B)/(Modelica.Math.exp(A*(TOut - 273.15)+B) + 1);
      on = Buildings.Occupants.BaseClasses.binaryVariableGeneration(p=p, globalSeed=integer(curSeed));
    else
      p = 0;
      on = false;
    end if;
  end when;
end Nicol2001WindowsUK;


within Buildings.Occupants.Residential;
package Windows "Package with models to simulate windows behaviors in resident buildings"
    extends Modelica.Icons.VariantsPackage;
end Windows;


Validating the model for window behaviors. This example validates

Buildings.Occupants.Residential.Windows.Nicol2001WindowsEU
by examing how the window state corresponds
to the outdoor temperature.

within Buildings.Occupants.Residential.Windows.Validation;
model Nicol2001WindowsEU "Validating the model for window behaviors"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.BooleanStep occ(startTime=1800)
    "True for occupied"
  Modelica.Blocks.Sources.Sine TOut(
    amplitude=15,
    offset=288,
    f=0.001,
    y(unit="K", displayUnit="degC")) "Outdoor air temperature"
  Buildings.Occupants.Residential.Windows.Nicol2001WindowsEU win "Tested windows model"
equation
  connect(win.occ, occ.y)
  connect(win.TOut, TOut.y)
end Nicol2001WindowsEU;


Validating the model for window behaviors. This example validates

Buildings.Occupants.Residential.Windows.Nicol2001WindowsPakistan
by examing how the window state corresponds
to the outdoor temperature.

within Buildings.Occupants.Residential.Windows.Validation;
model Nicol2001WindowsPakistan "Validating the model for window behaviors"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.BooleanStep occ(startTime=1800)
                                          "True for occupied"
  Modelica.Blocks.Sources.Sine TOut(
    amplitude=15,
    offset=288,
    f=0.001,
    y(unit="K", displayUnit="degC")) "Outdoor air temperature"
  Buildings.Occupants.Residential.Windows.Nicol2001WindowsPakistan win "Tested windows model"
equation
  connect(win.occ, occ.y)
  connect(win.TOut, TOut.y)
end Nicol2001WindowsPakistan;


Validating the model for window behaviors. This example validates

Buildings.Occupants.Residential.Windows.Nicol2001WindowsUK
by examing how the window state corresponds
to the outdoor temperature.

within Buildings.Occupants.Residential.Windows.Validation;
model Nicol2001WindowsUK "Validating the model for window behaviors"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.BooleanStep occ(startTime=1800)
                                          "True for occupied"
  Modelica.Blocks.Sources.Sine TOut(
    amplitude=15,
    offset=288,
    f=0.001,
    y(unit="K", displayUnit="degC")) "Outdoor air temperature"
  Buildings.Occupants.Residential.Windows.Nicol2001WindowsUK win "Tested windows model"
equation
  connect(win.occ, occ.y)
  connect(win.TOut, TOut.y)
end Nicol2001WindowsUK;


within Buildings.Occupants.Residential.Windows;
package Validation "Package with examples to validate models in Windows package"
    extends Modelica.Icons.ExamplesPackage;
end Validation;


within Buildings;
package Templates "Package with templates for various HVAC systems"
  extends Modelica.Icons.Package;
end Templates;


Package with type definitions

within Buildings.Templates;
package Types "Package with type definitions"
  extends Modelica.Icons.TypesPackage;

  type Buildings = enumeration(
      Education "Buildings used for academic or technical classroom instruction",
      FoodSales "Buildings used for retail or wholesale of food",
      FoodServices "Buildings used for preparation and sale of food and beverages for consumption",
      HealthCare "Buildings used as diagnostic and treatment facilities for inpatient care",
      Lodging  "Buildings used to offer multiple accommodations for short-term or long-term residents",
      MercantileRetail "Buildings used for the sale and display of goods other than food",
      MercantileMall "Shopping malls comprised of multiple connected establishments",
      Office "Buildings used for general office space, professional office, or administrative offices",
      PublicAssembly "Buildings in which people gather for social or recreational activities",
      PublicOrderSafety "Buildings used for the preservation of law and order or public safety",
      ReligiousWorkshop "Buildings in which people gather for religious activities",
      Service "Buildings in which some types of services is provided",
      WarehouseStorage "Buildings used to store goods, manufactured products, merchandise, raw materials, or personal belongings",
      Other "All other miscellaneous buildings that do not fit into any other category",
      Vacant "Buildings in which more floor space was vacant than was used for any single commercial activity")
    "Enumeration to specify the building type";
  type Units = enumeration(
      SI
      "SI - International units",
      IP
      "IP - Imperial units")
    "Enumeration to specify the system of units";
end Types;


Templates user guide

within Buildings.Templates;
package UsersGuide "Templates user guide"
  extends Modelica.Icons.Information;
  class Conventions
    "Conventions"
    extends Modelica.Icons.Information;
  end Conventions;

end UsersGuide;


Air handlers and fans

within Buildings.Templates;
package AirHandlersFans "Air handlers and fans"
  extends Modelica.Icons.Package;
end AirHandlersFans;


Package with type definitions

within Buildings.Templates.AirHandlersFans;
package Types "Package with type definitions"
  extends Modelica.Icons.TypesPackage;
  type Configuration = enumeration(
      SupplyOnly
      "Supply only system",
      ExhaustOnly
      "Exhaust only system",
      DualDuct
      "Dual duct system with supply and return",
      SingleDuct
      "Single duct system with supply and return")
    "Enumeration to configure the AHU";
  type Controller = enumeration(
      G36VAVMultiZone
      "Guideline 36 controller for multiple-zone VAV",
      OpenLoop
      "Open loop controller")
    "Enumeration to configure the AHU controller";
  type ControlFanReturn = enumeration(
      AirflowMeasured
      "Airflow tracking with airflow measurement stations",
      BuildingPressure
      "Building pressure (via discharge static pressure)")
    "Enumeration to configure the return fan control";
  // RFE: Add support for heat recovery.
  type HeatRecovery = enumeration(
      None
      "No heat recovery",
      FlatPlate
      "Flat plate heat exchanger",
      EnthalpyWheel
      "Enthalpy wheel",
      RunAroundCoil
      "Run-around coil")
    "Enumeration to configure the heat recovery";
  type OutdoorReliefReturnSection = enumeration(
      HundredPctOutdoorAir
      "100 % outdoor air system",
      MixedAirWithDamper
      "Mixed air system with return air damper - Optional economizer function",
      MixedAirNoDamper
      "Mixed air system without return air damper - No economizer function",
      MixedAirNoRelief
      "Mixed air system without relief branch - Optional economizer function")
    "Enumeration to configure the outdoor/relief/return air section";
  /* RFE: Add support for the following configurations.
      Barometric
        "Barometric relief damper without fan",
  */
  type ReliefReturnSection = enumeration(
      NoRelief
      "No relief branch",
      NoReturn
      "No return branch",
      ReliefDamper
      "Modulating relief damper without fan",
      ReliefFan
      "Relief fan with two-position relief damper",
      ReturnFan
      "Return fan with modulating relief damper")
    "Enumeration to configure the relief/return air section";
end Types;