Transmitted radiation through window. The model calculates the solar radiation through the window.
The calculations follow the description in Wetter (2004), Appendix A.4.3.

within Buildings.HeatTransfer.Windows.BaseClasses;
block TransmittedRadiation "Transmitted radiation through window"
  extends Buildings.HeatTransfer.Windows.BaseClasses.PartialRadiation;
  Modelica.Blocks.Interfaces.RealOutput QTraDif_flow[NSta](
    each final quantity="Power",
    each final unit="W")
    "Transmitted exterior diffuse radiation through the window. (1: no shade; 2: shade)"
  Modelica.Blocks.Interfaces.RealOutput QTraDir_flow[NSta](
    each final quantity="Power",
    each final unit="W")
    "Transmitted exterior direct radiation through the window. (1: no shade; 2: shade)"

  final parameter Real traCoeRoo[NSta](each fixed=false)
    "Transmitivity of the window glass for interior radiation without shading";

  output Modelica.Units.SI.Power QTraDifUns_flow[NSta]
    "Transmitted diffuse solar radiation through unshaded part of window";
  output Modelica.Units.SI.Power QTraDirUns_flow[NSta]
    "Transmitted direct solar radiation through unshaded part of window";
  output Modelica.Units.SI.Power QTraDifSha_flow[NSta]
    "Transmitted diffuse solar radiation through shaded part of window";
  output Modelica.Units.SI.Power QTraDirSha_flow[NSta]
    "Transmitted direct solar radiation through shaded part of window";

protected
  Real x "Intermediate variable";
  final parameter Integer NDIR=radDat.NDIR;
  final parameter Integer HEM=radDat.HEM;
  constant Integer NoShade=1;
  constant Integer Shade=2;
  constant Integer Interior=1;
  constant Integer Exterior=2;
  final parameter Real coeTraWinExtIrr[2, radDat.HEM + 2, NSta](each fixed=false);
  Real incAng2 "=min(incAng, 0.5*Modelica.Constants.pi)";

initial equation
  //**************************************************************
  // Assign coefficients.
  // Data dimension from Original ([1 : HEM]) to New ([2 : HEM+1])
  // with 2 dummy variable for interpolation.
  //**************************************************************
  // Glass
  for j in 1:HEM loop
    // Properties for glass without shading
    coeTraWinExtIrr[NoShade, j + 1, 1:NSta] =  radDat.traRef[1, 1, N, j, 1:NSta];
    // Properties for glass with shading
    if haveInteriorShade then
      coeTraWinExtIrr[Shade, j + 1, 1:NSta] =  radDat.winTraExtIrrIntSha[j, 1:NSta];
    elseif haveExteriorShade then
      coeTraWinExtIrr[Shade, j + 1, 1:NSta] =  radDat.winTraExtIrrExtSha[j, 1:NSta];
    else
      // No Shade
      coeTraWinExtIrr[Shade, j + 1, 1:NSta] =  zeros(NSta);
    end if;
  end for;
  // Dummy variables at 1 and HEM+2
  for k in NoShade:Shade loop
    coeTraWinExtIrr[k, 1, 1:NSta] =  coeTraWinExtIrr[k, 2, 1:NSta];
    coeTraWinExtIrr[k, HEM + 2, 1:NSta] =  coeTraWinExtIrr[k, HEM + 1, 1:NSta];
  end for;

  //**************************************************************
  // Glass: transmissivity for interior irradiation
  //**************************************************************
  traCoeRoo =  radDat.traRef[1, N, 1, HEM, 1:NSta];

equation
  //**************************************************************
  // Glass, Device: add absorbed radiation (angular part) from exterior sources
  //**************************************************************
  // Use min() instead of if() to avoid event
  incAng2 = min(incAng, 0.5*Modelica.Constants.pi);
  x = (2*(NDIR - 1)*abs(incAng2)/Modelica.Constants.pi)+2
    "x=(index-1)*incAng/(0.5pi)+2, 0<=x<=NDIR-1";

  // Window unshaded parts: add transmitted radiation for angular radiation
  for iSta in 1:NSta loop
    QTraDifUns_flow[iSta] = AWin*HDif*(1 - uSha_internal)*coeTraWinExtIrr[NoShade, HEM + 1, iSta];
    QTraDirUns_flow[iSta] = AWin*HDir*(1 - uSha_internal)*
                 Buildings.HeatTransfer.Windows.BaseClasses.smoothInterpolation({
                    coeTraWinExtIrr[NoShade, k, iSta] for k in 1:(HEM + 2)}, x);
  end for;

  // Window shaded parts: add transmitted radiation for angular radiation
  for iSta in 1:NSta loop
    QTraDifSha_flow[iSta] = AWin*HDif*uSha_internal*coeTraWinExtIrr[Shade, HEM + 1, iSta];
    QTraDirSha_flow[iSta] = AWin*HDir*uSha_internal*
               Buildings.HeatTransfer.Windows.BaseClasses.smoothInterpolation(
                 {coeTraWinExtIrr[Shade, k, iSta] for k in 1:(HEM + 2)}, x);
  end for;

  // Assign quantities to output connectors
  QTraDif_flow = QTraDifUns_flow + QTraDifSha_flow;
  QTraDir_flow = QTraDirUns_flow + QTraDirSha_flow;

The outputs are QTraDif_flow = Part1 + Part3 and
QTraDir_flow = Part2 + Part4.

References

Michael Wetter.

Simulation-based Building Energy Optimization.

Dissertation. University of California at Berkeley. 2004.

", revisions="

June 7, 2016, by Michael Wetter:

Removed output QTra_flow and introduced instead
QTraDif_flow and QTraDir_flow.
This is for
issue 451.

August 7, 2015, by Michael Wetter:

Revised model to allow modeling of electrochromic windows.
This is for
issue 445.

March 13, 2015, by Michael Wetter:

Changed initial algorithm
to initial equation section
to avoid a translation error in OpenModelica.

March 4, 2011, by Wangda Zuo:

Remove the if-statement and integer function that can trigger events.

February 2, 2010, by Michael Wetter:

Made connector uSha a conditional connector.

December 15, 2010, by Wangda Zuo:

Separate transmittance and absorbance models from the window radiation model.

December 12, 2010, by Michael Wetter:

Replaced record

Buildings.HeatTransfer.Data.GlazingSystems with the
parameters used by this model.
This was needed to integrate the radiation model into the room model.

December 10, 2010, by Wangda Zuo:

First implementation.

"),
    Icon(graphics={Text(
          extent={{-32,-80},{22,-96}},
          textColor={0,0,127},
          textString="uSha"), Text(
          extent={{56,28},{98,14}},
          textColor={0,0,127},
          textString="QTraDif"),
                              Text(
          extent={{54,-14},{96,-28}},
          textColor={0,0,127},
          textString="QTraDir")}));
end TransmittedRadiation;


Calculation radiation for window. The model calculates solar radiation through the window.
The calculations follow the description in Wetter (2004), Appendix A.4.3.
with the difference that this implementation allows a window to have
multiple states, thereby allowing to model electrochromic windows.

within Buildings.HeatTransfer.Windows.BaseClasses;
block WindowRadiation "Calculation radiation for window"

  extends Buildings.HeatTransfer.Windows.BaseClasses.PartialRadiation;

  Modelica.Blocks.Interfaces.RealInput uSta(min=0, max=1, unit="1")
    if NSta > 1 "Control signal for window state"

  Modelica.Blocks.Interfaces.RealInput HRoo(quantity="RadiantEnergyFluenceRate",
      unit="W/m2") "Diffussive radiation from room "
  Modelica.Blocks.Interfaces.RealOutput QTraDif_flow(
    final quantity="Power",
    final unit="W")
    "Transmitted diffuse exterior radiation through the window. (1: no shade; 2: shade)"
  Modelica.Blocks.Interfaces.RealOutput QTraDir_flow(
    final quantity="Power",
    final unit="W")
    "Transmitted direct exterior radiation through the window. (1: no shade; 2: shade)"

  Modelica.Blocks.Interfaces.RealOutput QAbsExtSha_flow(final quantity="Power",
      final unit="W")
    "Absorbed interior and exterior radiation by exterior shading device"
  Modelica.Blocks.Interfaces.RealOutput QAbsIntSha_flow(final quantity="Power",
      final unit="W")
    "Absorbed interior and exterior radiation by interior shading device"
  Modelica.Blocks.Interfaces.RealOutput QAbsGlaUns_flow[N](each quantity=
        "Power", each final unit="W")
    "Absorbed interior and exterior radiation by unshaded part of glass"
  Modelica.Blocks.Interfaces.RealOutput QAbsGlaSha_flow[N](each quantity=
        "Power", each final unit="W")
    "Absorbed interior and exterior radiation by shaded part of glass"

  Buildings.HeatTransfer.Windows.BaseClasses.TransmittedRadiation tra(
    final N=N,
    final tauGlaSol=tauGlaSol,
    final rhoGlaSol_a=rhoGlaSol_a,
    final rhoGlaSol_b=rhoGlaSol_b,
    final xGla=xGla,
    final tauShaSol_a=tauShaSol_a,
    final rhoShaSol_a=rhoShaSol_a,
    final rhoShaSol_b=rhoShaSol_b,
    final haveExteriorShade=haveExteriorShade,
    final haveInteriorShade=haveInteriorShade,
    final AWin=AWin,
    final tauShaSol_b=tauShaSol_b)
  Buildings.HeatTransfer.Windows.BaseClasses.AbsorbedRadiation abs(
    final N=N,
    final tauGlaSol=tauGlaSol,
    final rhoGlaSol_a=rhoGlaSol_a,
    final rhoGlaSol_b=rhoGlaSol_b,
    final xGla=xGla,
    final tauShaSol_a=tauShaSol_a,
    final tauShaSol_b=tauShaSol_b,
    final rhoShaSol_a=rhoShaSol_a,
    final rhoShaSol_b=rhoShaSol_b,
    final haveExteriorShade=haveExteriorShade,
    final haveInteriorShade=haveInteriorShade,
    final AWin=AWin)
protected
  final parameter Boolean noShade=not (haveExteriorShade or haveInteriorShade)
    "Flag, true if the window has a shade";

  StateInterpolator staIntQAbsExtSha_flow(
    final NSta=NSta) "Interpolator for the window state"
  StateInterpolator staIntQAbsGlaUns_flow[N](each final NSta=NSta)
    "Interpolator for the window state"
  StateInterpolator staIntQAbsGlaSha_flow[N](each final NSta=NSta)
    "Interpolator for the window state"
  StateInterpolator staIntQAbsIntSha_flow(
    final NSta=NSta) "Interpolator for the window state"
  StateInterpolator staIntQTraDif_flow(final NSta=NSta)
    "Interpolator for the window state"
  StateInterpolator staIntQTraDir_flow(final NSta=NSta)
    "Interpolator for the window state"

  Modelica.Blocks.Routing.Replicator replicator(final nout=N)
  if NSta > 1
    "Signal replicator for signals that have an element for each glass pane"
equation
  if noShade then
    assert(uSha_internal < 1E-6,
      "Window has no shade, but control signal is non-zero.\n" +
      "  Received uSha_internal = " + String(uSha_internal));
  end if;
  connect(HDif, tra.HDif)
  connect(HDif, abs.HDif)
  connect(HDir, tra.HDir)
  connect(HDir, abs.HDir)
  connect(incAng, tra.incAng)
  connect(incAng, abs.incAng)
  connect(HRoo, abs.HRoo)
  connect(tra.uSha, uSha)
  connect(abs.uSha, uSha)
  connect(abs.QAbsExtSha_flow, staIntQAbsExtSha_flow.HSta)
  connect(staIntQAbsExtSha_flow.H, QAbsExtSha_flow)
  connect(abs.QAbsGlaUns_flow, staIntQAbsGlaUns_flow.HSta)
  connect(staIntQAbsGlaUns_flow.H, QAbsGlaUns_flow)
  connect(staIntQAbsGlaSha_flow.HSta, abs.QAbsGlaSha_flow)
  connect(staIntQAbsGlaSha_flow.H, QAbsGlaSha_flow)
  connect(abs.QAbsIntSha_flow, staIntQAbsIntSha_flow.HSta)
  connect(staIntQAbsIntSha_flow.H, QAbsIntSha_flow)
  connect(staIntQTraDif_flow.H, QTraDif_flow)
  connect(uSta, staIntQAbsExtSha_flow.uSta)
  connect(staIntQTraDif_flow.uSta, uSta)
  connect(staIntQAbsIntSha_flow.uSta, uSta)

  connect(uSta, replicator.u)
  connect(replicator.y, staIntQAbsGlaUns_flow.uSta)
  connect(replicator.y, staIntQAbsGlaSha_flow.uSta)
  connect(uSta, staIntQTraDir_flow.uSta)
  connect(tra.QTraDif_flow, staIntQTraDif_flow.HSta)
  connect(tra.QTraDir_flow, staIntQTraDir_flow.HSta)
  connect(staIntQTraDir_flow.H, QTraDir_flow)

The outputs are QTraDif_flow = Part1 + Part3 and
QTraDir_flow = Part2 + Part4.

References

Michael Wetter.

Simulation-based Building Energy Optimization.

Dissertation. University of California at Berkeley. 2004.

", revisions="

June 7, 2016, by Michael Wetter:

Removed output QTra_flow and introduced instead
QTraDif_flow and QTraDir_flow.
This is for
issue 451.

August 7, 2015, by Michael Wetter:

Revised model to allow modeling of electrochromic windows.
This is for
issue 445.

March 13, 2015, by Michael Wetter:

Removed duplicate text annotation.

December 12, 2011, by Wangda Zuo:

Add glass thickness as a parameter for tra and abs. It is needed by the claculation of property for uncoated glass.

February 2, 2010, by Michael Wetter:

Made connector uSha a conditional connector.

January 4, 2011, by Michael Wetter:

Added assert statement to check that uSha=0 if no shade is present.
This is needed to avoid wrong results in the room model.

December 15, 2010, by Wangda Zuo:

Revise the model by separating transmittance and absorbance.

December 12, 2010, by Michael Wetter:

Replaced record

Buildings.HeatTransfer.Data.GlazingSystems with the
parameters used by this model.
This was needed to integrate the radiation model into the room model.

December 10, 2010, by Wangda Zuo:

First implementation.

"),
    Icon(graphics={
        Text(
          extent={{0,86},{90,72}},
          textColor={0,0,127},
          textString="QAbsExtSha"),
        Text(
          extent={{-4,-22},{92,-36}},
          textColor={0,0,127},
          textString="QAbsIntSha"),
        Text(
          extent={{2,58},{94,44}},
          textColor={0,0,127},
          textString="QAbsGlaUns"),
        Text(
          extent={{-2,20},{92,6}},
          textColor={0,0,127},
          textString="QAbsGlaSha"),
        Text(
          extent={{42,-52},{106,-66}},
          textColor={0,0,127},
          textString="QTraDif"),
        Text(
          extent={{-104,-70},{-50,-84}},
          textColor={0,0,127},
          textString="HRoo"),
        Text(
          extent={{8,-82},{62,-94}},
          textColor={0,0,127},
          textString="uSta"),
        Text(
          extent={{44,-80},{108,-94}},
          textColor={0,0,127},
          textString="QTraDir")}));
end WindowRadiation;


Test model for absorbed radiation by windows.

within Buildings.HeatTransfer.Windows.BaseClasses.Examples;
model AbsorbedRadiation "Test model for absorbed radiation by windows"
  extends Modelica.Icons.Example;
  parameter Modelica.Units.SI.Angle azi=0 "Surface azimuth";
  parameter Modelica.Units.SI.Angle til=1.5707963267949 "Surface tilt";

  replaceable parameter
    Buildings.HeatTransfer.Data.GlazingSystems.DoubleClearAir13Clear glaSys(
    shade=Buildings.HeatTransfer.Data.Shades.Gray(),
    UFra=2,
    haveExteriorShade=false,
    haveInteriorShade=true) constrainedby Data.GlazingSystems.Generic
    "Parameters for glazing system"

  BoundaryConditions.SolarIrradiation.DirectTiltedSurface HDirTil(
    til=til,
    azi=azi)
  BoundaryConditions.WeatherData.Bus weaBus
  BoundaryConditions.WeatherData.ReaderTMY3 weaDat(filNam=
        Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos"),
      computeWetBulbTemperature=false)

  BoundaryConditions.SolarIrradiation.DiffuseIsotropic HDifTilIso(
               til=til)
  Modelica.Blocks.Sources.Constant shaCon(k=if (glaSys.haveShade) then 0.5 else
              0)

  Buildings.HeatTransfer.Windows.BaseClasses.AbsorbedRadiation winAbs(
    AWin=1,
    N=size(glaSys.glass, 1),
    tauGlaSol = glaSys.glass.tauSol,
    rhoGlaSol_a=glaSys.glass.rhoSol_a,
    rhoGlaSol_b=glaSys.glass.rhoSol_b,
    xGla=glaSys.glass.x,
    tauShaSol_a=glaSys.shade.tauSol_a,
    tauShaSol_b=glaSys.shade.tauSol_b,
    rhoShaSol_a=glaSys.shade.rhoSol_a,
    rhoShaSol_b=glaSys.shade.rhoSol_b,
    haveExteriorShade=glaSys.haveExteriorShade,
    haveInteriorShade=glaSys.haveInteriorShade)

  Modelica.Blocks.Sources.Constant HRoo(k=10)
equation
  connect(weaDat.weaBus, weaBus)
  connect(HDirTil.weaBus, weaBus)
  connect(weaBus, HDifTilIso.weaBus)
  connect(shaCon.y,winAbs. uSha)
  connect(winAbs.HDir, HDirTil.H)
  connect(HDifTilIso.H,winAbs. HDif)
  connect(HDirTil.inc,winAbs. incAng)
  connect(HRoo.y,winAbs. HRoo)
end AbsorbedRadiation;


Test model for absorbed radiation for electrochromic window. This example tests the absorption of electrochromic glass.

within Buildings.HeatTransfer.Windows.BaseClasses.Examples;
model AbsorbedRadiationElectrochromic
  "Test model for absorbed radiation for electrochromic window"
  extends AbsorbedRadiation(redeclare
      Data.GlazingSystems.DoubleElectrochromicAir13Clear glaSys);
end AbsorbedRadiationElectrochromic;


Test model for center of glas heat transfer.

within Buildings.HeatTransfer.Windows.BaseClasses.Examples;
model CenterOfGlass "Test model for center of glas heat transfer"
  extends Modelica.Icons.Example;
  parameter Modelica.Units.SI.Area A=1 "Window surface area";
  parameter Boolean linearize = false "Set to true to linearize emissive power";

  Buildings.HeatTransfer.Windows.BaseClasses.CenterOfGlass sha(
    A=A,
    linearize=linearize,
    til=1.5707963267949,
    glaSys=glaSys) "Model for fraction of window that has a shade"
  Modelica.Blocks.Sources.Ramp uSha(
    height=0.9,
    duration=1,
    offset=0.05) "Control signal for shade"
  Buildings.HeatTransfer.Sources.PrescribedTemperature TAirOut
    "Outside air temperature"
  Modelica.Blocks.Sources.Constant TOut(k=273.15) "Outside temperature"
  Buildings.HeatTransfer.Sources.PrescribedTemperature TAirRoo
    "Room temperature"

  Buildings.HeatTransfer.Radiosity.OpaqueSurface radIn(A=A, absIR=0.8,
    linearize=false) "Model for inside radiosity"
  Modelica.Blocks.Sources.Constant TRoo(k=293.15) "Room temperature"
  Buildings.HeatTransfer.Sources.PrescribedTemperature TRadRoo
    "Room radiative temperature"
  Buildings.HeatTransfer.Radiosity.RadiositySplitter radShaInt
    "Radiosity that strikes shading device"

  Buildings.HeatTransfer.Windows.BaseClasses.CenterOfGlass nonSha(
    A=A,
    linearize=linearize,
    til=1.5707963267949,
    glaSys=glaSys) "Model for fraction of window that has no shade"
  Buildings.HeatTransfer.Radiosity.RadiositySplitter radShaOut
    "Radiosity that strikes shading device"

  parameter Buildings.HeatTransfer.Data.GlazingSystems.DoubleClearAir13Clear glaSys(
    shade=Buildings.HeatTransfer.Data.Shades.Gray(),
    haveExteriorShade=true,
    haveInteriorShade=true,
    UFra=2) "Parameters for glazing system"
  Buildings.HeatTransfer.Radiosity.OutdoorRadiosity radOut(A=A,
     vieFacSky=0.5) "Outdoor radiosity"

  Modelica.Thermal.HeatTransfer.Components.Convection conRooSha
    "Convection for room-facing surface of shaded part of window"
  Modelica.Thermal.HeatTransfer.Components.Convection conOutSha(dT(start=0))
    "Convection for outside-facing surface of shaded part of window"
  Modelica.Thermal.HeatTransfer.Components.Convection conOutNonSha1(dT(start=0))
    "Convection for outside-facing surface of non-shaded part of window"
  Modelica.Thermal.HeatTransfer.Components.Convection conRooNonSha
    "Convection for room-facing surface of non-shaded part of window"
  Modelica.Blocks.Sources.Constant hA(k=4*A)
    "Convection coefficient times total area"
  Modelica.Blocks.Math.Product hASha "Convection of shaded part of window"
  Modelica.Blocks.Math.Product hANonSha
    "Convection of non-shaded part of window"
  Buildings.HeatTransfer.Windows.BaseClasses.ShadingSignal shaCon(haveShade=
        glaSys.haveExteriorShade or glaSys.haveInteriorShade)
    "Bounds the shading signal"
  Modelica.Blocks.Sources.Constant QAbs[size(glaSys.glass, 1)](each k=0)
    "Solar radiation absorbed by glass"
  Modelica.Blocks.Math.MultiSum sumJ(nu=2)
    "Sum of radiosities from the two surfaces"
equation
  connect(TOut.y, TAirOut.T)
  connect(TRoo.y, TAirRoo.T)
  connect(TRadRoo.port, radIn.heatPort)
  connect(TRadRoo.T, TRoo.y)
  connect(radIn.JOut, radShaInt.JIn)
  connect(radOut.JOut, radShaOut.JIn)
  connect(hA.y, hANonSha.u1)
  connect(hASha.u1, hA.y)
  connect(hASha.y, conOutSha.Gc)
  connect(hASha.y, conRooSha.Gc)
  connect(hANonSha.y, conOutNonSha1.Gc)
  connect(hANonSha.y, conRooNonSha.Gc)
  connect(conOutSha.solid, sha.glass_a)
  connect(conOutSha.fluid, TAirOut.port)
  connect(nonSha.glass_a, conOutNonSha1.solid)
  connect(conOutNonSha1.fluid, TAirOut.port)
  connect(nonSha.glass_b, conRooNonSha.solid)
  connect(conRooNonSha.fluid, TAirRoo.port)
  connect(conRooSha.fluid, TAirRoo.port)
  connect(conRooSha.solid, sha.glass_b)

  connect(radShaOut.JOut_1, sha.JIn_a)
  connect(radShaOut.JOut_2, nonSha.JIn_a)
  connect(radShaInt.JOut_1, sha.JIn_b)
  connect(radShaInt.JOut_2, nonSha.JIn_b)
  connect(shaCon.yCom, hANonSha.u2)
  connect(shaCon.yCom, nonSha.u)
  connect(shaCon.y, radShaOut.u)
  connect(shaCon.y, radShaInt.u)
  connect(shaCon.y, sha.u)
  connect(uSha.y, shaCon.u)
  connect(shaCon.y, hASha.u2)
  connect(QAbs.y, nonSha.QAbs_flow)
  connect(QAbs.y, sha.QAbs_flow)
  connect(radOut.TOut, TOut.y)
  connect(TOut.y, radOut.TBlaSky)
  connect(radIn.JIn, sumJ.y)
  connect(sha.JOut_b, sumJ.u[1])
  connect(nonSha.JOut_b, sumJ.u[2])
end CenterOfGlass;


Test problem for convection in the gas layer.

within Buildings.HeatTransfer.Windows.BaseClasses.Examples;
model GasConvection "Test problem for convection in the gas layer"
  extends Modelica.Icons.Example;
  Buildings.HeatTransfer.Windows.BaseClasses.GasConvection conVer(
    A=1,
    linearize=false,
    gas=Buildings.HeatTransfer.Data.Gases.Air(x=0.1),
    til=Buildings.Types.Tilt.Wall) "Model for gas convection in vertical gap"
  Modelica.Blocks.Sources.Ramp TBC(
    duration=1,
    offset=283.15,
    height=20) "Boundary condition for temperature"
  Buildings.HeatTransfer.Sources.PrescribedTemperature T_a1
    "Exterior-side temperature"
  Buildings.HeatTransfer.Sources.FixedTemperature T_b1(T=293.15)
    "Room-side temperature"
  Modelica.Blocks.Sources.Constant u(k=1) "Shading control signal"
  Buildings.HeatTransfer.Windows.BaseClasses.GasConvection conCei(
    A=1,
    linearize=false,
    gas=Buildings.HeatTransfer.Data.Gases.Air(x=0.1),
    til=Buildings.Types.Tilt.Ceiling)
    "Model for gas convection in horizontal gap in a ceiling"
  Buildings.HeatTransfer.Sources.PrescribedTemperature T_a2
    "Exterior-side temperature"
  Buildings.HeatTransfer.Sources.FixedTemperature T_b2(T=293.15)
    "Room-side temperature"
  Buildings.HeatTransfer.Windows.BaseClasses.GasConvection conFlo(
    A=1,
    linearize=false,
    gas=Buildings.HeatTransfer.Data.Gases.Air(x=0.1),
    til=Buildings.Types.Tilt.Floor)
    "Model for gas convection in horizontal gap in a floor"
  Buildings.HeatTransfer.Sources.PrescribedTemperature T_a3
    "Exterior-side temperature"
  Buildings.HeatTransfer.Sources.FixedTemperature T_b3(T=293.15)
    "Room-side temperature"
equation
  connect(TBC.y, T_a1.T)
  connect(T_a1.port, conVer.port_a)
  connect(conVer.port_b, T_b1.port)
  connect(u.y, conVer.u)
  connect(TBC.y, T_a2.T)
  connect(T_a2.port, conCei.port_a)
  connect(conCei.port_b, T_b2.port)
  connect(u.y, conCei.u)
  connect(TBC.y, T_a3.T)
  connect(T_a3.port, conFlo.port_a)
  connect(conFlo.port_b, T_b3.port)
  connect(u.y, conFlo.u)
end GasConvection;


Test model for glass layer heat transfer.

within Buildings.HeatTransfer.Windows.BaseClasses.Examples;
model GlassLayer "Test model for glass layer heat transfer"
  extends Modelica.Icons.Example;
  parameter Modelica.Units.SI.Area A=1 "Window surface area";
  parameter Boolean linearize = false "Set to true to linearize emissive power";

  Buildings.HeatTransfer.Windows.BaseClasses.GlassLayer sha(
    A=A,
    absIR_a=0.5,
    tauIR=0.2,
    x=0.015,
    k=1,
    linearize=linearize,
    absIR_b=0.5) "Model for fraction of window that has a shade"
  Buildings.HeatTransfer.Sources.PrescribedTemperature TAirOut
    "Outside air temperature"
  Modelica.Blocks.Sources.Constant TOut(k=273.15) "Outside temperature"
  Buildings.HeatTransfer.Sources.PrescribedTemperature TAirRoo
    "Room temperature"
  Buildings.HeatTransfer.Radiosity.OpaqueSurface radOut(A=A, absIR=0.8,
    linearize=false) "Model for outside radiosity"
  Buildings.HeatTransfer.Sources.PrescribedTemperature TRadOut
    "Outside radiative temperature"

  Buildings.HeatTransfer.Radiosity.OpaqueSurface radIn(A=A, absIR=0.8,
    linearize=false) "Model for inside radiosity"
  Modelica.Blocks.Sources.Constant TRoo(k=293.15) "Room temperature"
  Buildings.HeatTransfer.Sources.PrescribedTemperature TRadRoo
    "Room radiative temperature"
  Modelica.Blocks.Sources.Constant QAbs_flow(k=0) "Absorbed solar heat flow"
  Buildings.HeatTransfer.Radiosity.RadiositySplitter radShaInt
    "Radiosity that strikes shading device"

  Buildings.HeatTransfer.Windows.BaseClasses.GlassLayer nonSha(
    A=A,
    absIR_a=0.5,
    tauIR=0.2,
    x=0.015,
    k=1,
    linearize=linearize,
    absIR_b=0.5) "Model for fraction of window that has no shade"
  Buildings.HeatTransfer.Radiosity.RadiositySplitter radShaOut
    "Radiosity that strikes shading device"

  Modelica.Thermal.HeatTransfer.Components.Convection conRooSha
    "Convection for room-facing surface of shaded part of window"
  Modelica.Thermal.HeatTransfer.Components.Convection conRooNonSha
    "Convection for room-facing surface of non-shaded part of window"
  Modelica.Blocks.Sources.Constant hA(k=4*A)
    "Convection coefficient times total area"
  Modelica.Blocks.Math.Product hASha "Convection of shaded part of window"
  Modelica.Blocks.Math.Product hANonSha
    "Convection of non-shaded part of window"
  Modelica.Thermal.HeatTransfer.Components.Convection conOutSha(
    dT(start=0))
    "Convection for outside-facing surface of shaded part of window"
  Modelica.Thermal.HeatTransfer.Components.Convection conOutNonSha1(
    dT(start=0))
    "Convection for outside-facing surface of non-shaded part of window"
  Modelica.Blocks.Sources.Ramp uSha(
    height=0.9,
    duration=1,
    offset=0.05) "Control signal for shade"
  Buildings.HeatTransfer.Windows.BaseClasses.ShadingSignal shaCon(haveShade=
        true) "Bounds the shading signal"
  Modelica.Blocks.Math.MultiSum sumJOut(nu=2)
    "Sum of radiosities at outer surface"
  Modelica.Blocks.Math.MultiSum sumJRoo(nu=2)
    "Sum of radiosities at room surface"
equation
  connect(TOut.y, TAirOut.T)
  connect(TRadOut.port, radOut.heatPort)
  connect(TRadOut.T, TOut.y)
  connect(TRoo.y, TAirRoo.T)
  connect(TRadRoo.port, radIn.heatPort)
  connect(TRadRoo.T, TRoo.y)
  connect(QAbs_flow.y, sha.QAbs_flow)
  connect(radShaOut.JIn, radOut.JOut)
  connect(radIn.JOut, radShaInt.JIn)
  connect(radShaOut.JOut_1, sha.JIn_a)
  connect(radShaOut.JOut_2, nonSha.JIn_a)
  connect(radShaInt.JOut_1, sha.JIn_b)
  connect(radShaInt.JOut_2, nonSha.JIn_b)
  connect(QAbs_flow.y, nonSha.QAbs_flow)
  connect(hA.y, hANonSha.u1)
  connect(hASha.u1, hA.y)
  connect(nonSha.port_a, conOutNonSha1.solid)
  connect(conOutNonSha1.fluid, TAirOut.port)
  connect(sha.port_a, conOutSha.solid)
  connect(conOutSha.fluid, TAirOut.port)
  connect(nonSha.port_b, conRooNonSha.solid)
  connect(sha.port_b, conRooSha.solid)
  connect(conRooSha.fluid, TAirRoo.port)
  connect(conRooNonSha.fluid, TAirRoo.port)
  connect(hASha.y, conOutSha.Gc)
  connect(hASha.y, conRooSha.Gc)
  connect(hANonSha.y, conOutNonSha1.Gc)
  connect(hANonSha.y, conRooNonSha.Gc)
  connect(shaCon.yCom, hANonSha.u2)
  connect(shaCon.yCom, nonSha.u)
  connect(shaCon.y, radShaOut.u)
  connect(shaCon.y, radShaInt.u)
  connect(shaCon.y, sha.u)
  connect(uSha.y,shaCon. u)
  connect(shaCon.y, hASha.u2)
  connect(radOut.JIn, sumJOut.y)
  connect(sha.JOut_a, sumJOut.u[1])
  connect(nonSha.JOut_a, sumJOut.u[2])
  connect(radIn.JIn, sumJRoo.y)
  connect(sha.JOut_b, sumJRoo.u[1])
  connect(nonSha.JOut_b, sumJRoo.u[2])
end GlassLayer;


Test model for the interior heat transfer due to convection. This is a test model for the interior side convective heat transfer.
During the simulation, the shading control signal is changed, which
causes a change in the convective heat flow rate.

within Buildings.HeatTransfer.Windows.BaseClasses.Examples;
model InteriorConvection
  "Test model for the interior heat transfer due to convection"
  extends Modelica.Icons.Example;

  Modelica.Blocks.Sources.Ramp uSha(
    duration=1,
    height=1,
    offset=0) "Control signal for shade"
  Buildings.HeatTransfer.Windows.BaseClasses.InteriorConvection con(til=
        Buildings.Types.Tilt.Wall, conMod=Buildings.HeatTransfer.Types.InteriorConvection.Temperature,
    A=1)
  Modelica.Thermal.HeatTransfer.Sensors.HeatFlowSensor heaFloSen
    "Heat flow sensor"
  Modelica.Thermal.HeatTransfer.Sources.FixedTemperature TGla(T=295.15)
    "Glass temperature"
  Modelica.Thermal.HeatTransfer.Sources.FixedTemperature TRoo(T=293.15)
    "Room air temperature"
equation
  connect(uSha.y, con.u)
  connect(TGla.port, con.solid)
  connect(con.fluid, heaFloSen.port_a)
  connect(heaFloSen.port_b, TRoo.port)
end InteriorConvection;


Test model for the overhang. This example uses the basic overhang model with solar angles as input and calculates the fraction of total window area that is exposed to the sun.
For a detail description of the solar angles used in the model, see
Buildings.BoundaryConditions.SolarGeometry.
For a detailed description of the overhang block, see
Buildings.HeatTransfer.Windows.BaseClasses.Overhang.
The required data for the solar angle calculations is obtained from weather data.

within Buildings.HeatTransfer.Windows.BaseClasses.Examples;
model Overhang "Test model for the overhang"
  extends Modelica.Icons.Example;
  Buildings.BoundaryConditions.SolarGeometry.IncidenceAngle incAng(
    azi=Buildings.Types.Azimuth.S,
    til=Buildings.Types.Tilt.Wall) "Solar incidence angle on a tilted surface"
  Buildings.BoundaryConditions.WeatherData.ReaderTMY3 weaDat(filNam=Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos"))
    "Weather data"
  Buildings.HeatTransfer.Windows.BaseClasses.Overhang ove(
    gap=0.1,
    azi=Buildings.Types.Azimuth.S,
    wL=0,
    wR=0.95,
    dep=0.5,
    hWin=2,
    wWin=0.1) "Calculates fraction of window area shaded by the overhang"

  Buildings.BoundaryConditions.SolarGeometry.BaseClasses.WallSolarAzimuth walSolAzi
    "Angle measured in horizontal plane between projection of sun's rays and normal to vertical surface"
  Buildings.BoundaryConditions.WeatherData.Bus weaBus
equation
  connect(weaDat.weaBus, incAng.weaBus)
  connect(incAng.y, walSolAzi.incAng)
  connect(walSolAzi.verAzi, ove.verAzi)
  connect(weaDat.weaBus, ove.weaBus)
  connect(weaDat.weaBus, weaBus)
  connect(weaBus.solAlt, walSolAzi.alt)
  connect(weaBus.solAlt, ove.alt)
end Overhang;


within Buildings.HeatTransfer.Windows.BaseClasses;
package Examples "Collection of models that illustrate model use and test models"
  extends Modelica.Icons.ExamplesPackage;
end Examples;


Test model for exterior shade heat transfer.

within Buildings.HeatTransfer.Windows.BaseClasses.Examples;
model Shade "Test model for exterior shade heat transfer"
  extends Modelica.Icons.Example;
  parameter Modelica.Units.SI.Area A=1 "Window surface area";
  parameter Boolean linearize = true "Set to true to linearize emissive power";

  Buildings.HeatTransfer.Windows.BaseClasses.ShadeRadiation extShaRad(
    A=A,
    linearize=false,
    absIR_air=0.3,
    absIR_glass=0.3,
    tauIR_air=0.3,
    tauIR_glass=0.3,
    thisSideHasShade=true) "Radiation model of exterior shade"
  Modelica.Blocks.Sources.Ramp uSha(
    height=0.9,
    duration=1,
    offset=0.05) "Control signal for shade"
  Modelica.Blocks.Sources.Constant TOut(k=273.15) "Outside temperature"
  Buildings.HeatTransfer.Radiosity.OpaqueSurface radOut(A=A, absIR=0.8,
    linearize=false) "Model for outside radiosity"
  Buildings.HeatTransfer.Sources.PrescribedTemperature TRadOut
    "Outside radiative temperature"

  Buildings.HeatTransfer.Radiosity.OpaqueSurface radIn(A=A, absIR=0.8,
    linearize=false) "Model for inside radiosity"
  Modelica.Blocks.Sources.Constant TRoo(k=293.15) "Room temperature"
  Buildings.HeatTransfer.Sources.PrescribedTemperature TRadRoo
    "Room radiative temperature"
  Modelica.Blocks.Sources.Constant QSol_shade(k=0)
    "Solar heat flow absorbed by shade"
  Buildings.HeatTransfer.Radiosity.RadiositySplitter radShaInt
    "Radiosity that strikes shading device"

  Buildings.HeatTransfer.Windows.BaseClasses.ShadeRadiation extNonShaRad(
    A=A,
    linearize=false,
    thisSideHasShade=false,
    absIR_air=0,
    absIR_glass=0,
    tauIR_air=0.3,
    tauIR_glass=0.3) "Radiation model for fraction of window that has no shade"
  Buildings.HeatTransfer.Radiosity.RadiositySplitter radShaOut
    "Radiosity that strikes shading device"
  Buildings.HeatTransfer.Sources.PrescribedTemperature TAirOut
    "Outside air temperature"
  Buildings.HeatTransfer.Sources.PrescribedTemperature TAirRoo
    "Room-side air temperature"
  Buildings.HeatTransfer.Windows.BaseClasses.ShadingSignal shaCon(haveShade=
        true)
  Modelica.Blocks.Math.Gain GConSha(k=10*A, y(unit="W/K"))
    "Convection coefficient for shade part of window"
  Modelica.Blocks.Math.Gain GConUns(k=10*A, y(unit="W/K"))
    "Convection coefficient for unshade part of window"
  Modelica.Blocks.Math.MultiSum sumJRoo(nu=2) "Sum of room side radiosity"
  Modelica.Blocks.Math.MultiSum sumJOut(nu=2) "Sum of outdoor side radiosity"
  Buildings.HeatTransfer.Windows.BaseClasses.ShadeConvection extShaCon(A=A,
      thisSideHasShade=true) "Convection model of exterior shade"
  Buildings.HeatTransfer.Windows.BaseClasses.ShadeConvection extNonShaCon(A=A,
      thisSideHasShade=false)
    "Convection model for fraction of window that has no shade"
equation
  connect(TRadOut.port, radOut.heatPort)
  connect(TRadOut.T, TOut.y)
  connect(TRadRoo.port, radIn.heatPort)
  connect(TRadRoo.T, TRoo.y)
  connect(radShaOut.JIn, radOut.JOut)
  connect(radIn.JOut, radShaInt.JIn)
  connect(radShaOut.JOut_1, extShaRad.JIn_air)
  connect(radShaOut.JOut_2, extNonShaRad.JIn_air)
  connect(radShaInt.JOut_1, extShaRad.JIn_glass)
  connect(radShaInt.JOut_2, extNonShaRad.JIn_glass)
  connect(TAirOut.T, TOut.y)
  connect(TAirRoo.T, TRoo.y)
  connect(shaCon.y, extShaRad.u)
  connect(shaCon.y, radShaOut.u)
  connect(uSha.y, shaCon.u)
  connect(shaCon.yCom, extNonShaRad.u)
  connect(GConSha.u, shaCon.y)
  connect(shaCon.yCom, GConUns.u)
  connect(shaCon.y, radShaInt.u)
  connect(radIn.JIn, sumJRoo.y)
  connect(radOut.JIn, sumJOut.y)
  connect(TAirRoo.port, extShaCon.glass)
  connect(TAirRoo.port, extNonShaCon.glass)
  connect(extShaCon.air, TAirOut.port)
  connect(extNonShaCon.air, TAirOut.port)
  connect(GConUns.y, extNonShaCon.Gc)
  connect(GConSha.y, extShaCon.Gc)
  connect(extShaCon.TSha, extShaRad.TSha)
  connect(extShaCon.QRadAbs_flow, extShaRad.QRadAbs_flow)
  connect(extNonShaRad.TSha, extNonShaCon.TSha)
  connect(extNonShaRad.QRadAbs_flow, extNonShaCon.QRadAbs_flow)
  connect(extShaRad.JOut_air, sumJOut.u[1])
  connect(extNonShaRad.JOut_air, sumJOut.u[2])
  connect(extShaRad.JOut_glass, sumJRoo.u[1])
  connect(extNonShaRad.JOut_glass, sumJRoo.u[2])
  connect(extShaRad.QSolAbs_flow, QSol_shade.y)
  connect(extNonShaRad.QSolAbs_flow, QSol_shade.y)
end Shade;


Test model for side fins. This example uses the basic side fins model with solar angles as input and calculates the fraction of total window area that is exposed to the sun.
For a detailed description of the solar angles used in the model,
see to documentation in the package
Buildings.BoundaryConditions.SolarGeometry.
For a detail description of side fin model, see

Buildings.HeatTransfer.Windows.BaseClasses.SideFins.
The required data for the solar angle calculations are obtained from the weather data.

within Buildings.HeatTransfer.Windows.BaseClasses.Examples;
model SideFins "Test model for side fins"
  extends Modelica.Icons.Example;
  Buildings.BoundaryConditions.SolarGeometry.ZenithAngle zen
    "Zenith angle: angle between the earth surface normal and the sun's beam"
  Buildings.BoundaryConditions.SolarGeometry.IncidenceAngle incAng(
    azi=0,
    til=1.5707963267949) "Solar incidence angle on a tilted surface"
  Buildings.BoundaryConditions.WeatherData.ReaderTMY3 weaDat(filNam=Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos"))
    "Weather data"
  Buildings.HeatTransfer.Windows.BaseClasses.SideFins fin(
    gap=0.1,
    h=0.7,
    dep=1.0,
    hWin=1.5,
    wWin=2.0) "Calculates fraction of window area shaded by the side fins"
  Buildings.BoundaryConditions.SolarGeometry.BaseClasses.AltitudeAngle
    altAng "Altitude angle: Angle between Sun ray and horizontal surface"
  Buildings.BoundaryConditions.SolarGeometry.BaseClasses.WallSolarAzimuth walSolAzi
    "Angle measured in horizontal plane between projection of sun's rays and normal to vertical surface"
equation
  connect(weaDat.weaBus, zen.weaBus)
  connect(weaDat.weaBus, incAng.weaBus)
  connect(zen.y, altAng.zen)
  connect(altAng.alt, fin.alt)
  connect(walSolAzi.verAzi, fin.verAzi)
  connect(altAng.alt, walSolAzi.alt)
  connect(incAng.y, walSolAzi.incAng)
end SideFins;


Test model for transmitted radiation through window.

within Buildings.HeatTransfer.Windows.BaseClasses.Examples;
model TransmittedRadiation
  "Test model for transmitted radiation through window"
  extends Modelica.Icons.Example;
  parameter Modelica.Units.SI.Angle azi=0 "Surface azimuth";
  parameter Modelica.Units.SI.Angle til=1.5707963267949 "Surface tilt";

  parameter Buildings.HeatTransfer.Data.GlazingSystems.DoubleClearAir13Clear glaSys(
    shade=Buildings.HeatTransfer.Data.Shades.Gray(),
    UFra=2,
    haveExteriorShade=false,
    haveInteriorShade=true) "Parameters for glazing system"

  BoundaryConditions.SolarIrradiation.DirectTiltedSurface HDirTil(
    til=til,
    azi=azi) "Direct irradiation on the tilted surface"
  BoundaryConditions.WeatherData.Bus weaBus "Weather data bus"
  BoundaryConditions.WeatherData.ReaderTMY3 weaDat(filNam=
        Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos"))
    "Weather data reader"

  BoundaryConditions.SolarIrradiation.DiffuseIsotropic HDifTilIso(
     til=til) "Diffuse isotropic irradiation"
  Modelica.Blocks.Sources.Constant shaCon(k=if (glaSys.haveShade) then 0.5 else
              0)
  Buildings.HeatTransfer.Windows.BaseClasses.TransmittedRadiation winTra(
    AWin=1,
    N=size(glaSys.glass, 1),
    tauGlaSol=glaSys.glass.tauSol,
    rhoGlaSol_a=glaSys.glass.rhoSol_a,
    rhoGlaSol_b=glaSys.glass.rhoSol_b,
    xGla=glaSys.glass.x,
    tauShaSol_a=glaSys.shade.tauSol_a,
    tauShaSol_b=glaSys.shade.tauSol_b,
    rhoShaSol_a=glaSys.shade.rhoSol_a,
    rhoShaSol_b=glaSys.shade.rhoSol_b,
    haveExteriorShade=glaSys.haveExteriorShade,
    haveInteriorShade=glaSys.haveInteriorShade)
equation
  connect(weaDat.weaBus, weaBus)
  connect(HDirTil.weaBus, weaBus)
  connect(weaBus, HDifTilIso.weaBus)
  connect(shaCon.y,winTra. uSha)
  connect(winTra.HDir, HDirTil.H)
  connect(HDifTilIso.H,winTra. HDif)
  connect(HDirTil.inc,winTra. incAng)
end TransmittedRadiation;


Test model for window radiation.

within Buildings.HeatTransfer.Windows.BaseClasses.Examples;
model WindowRadiation "Test model for window radiation"
  extends Modelica.Icons.Example;
  parameter Modelica.Units.SI.Angle azi=0 "Surface azimuth";
  parameter Modelica.Units.SI.Angle til=1.5707963267949 "Surface tilt";

  replaceable parameter
    Buildings.HeatTransfer.Data.GlazingSystems.DoubleClearAir13Clear glaSys(
    shade=Buildings.HeatTransfer.Data.Shades.Gray(),
    UFra=2,
    haveExteriorShade=false,
    haveInteriorShade=true) constrainedby Data.GlazingSystems.Generic
    "Parameters for glazing system"

  BoundaryConditions.SolarIrradiation.DirectTiltedSurface HDirTil(
    til=til,
    azi=azi) "Direct irradiation on the tilted surface"
  BoundaryConditions.WeatherData.Bus weaBus "Weather data bus"
  BoundaryConditions.WeatherData.ReaderTMY3 weaDat(filNam=
        Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos"))
    "Weather data reader"

  BoundaryConditions.SolarIrradiation.DiffuseIsotropic HDifTilIso(
    til=til) "Diffuse isotropic irradiation"
  Modelica.Blocks.Sources.Constant shaCon(k=if (glaSys.haveShade) then 0.5 else
              0)
  Modelica.Blocks.Math.Gain HRoo(k=0.1) "Solar irradiation from room"
  Buildings.HeatTransfer.Windows.BaseClasses.WindowRadiation winRad(
    AWin=1,
    N=size(glaSys.glass, 1),
    tauGlaSol=glaSys.glass.tauSol,
    rhoGlaSol_a=glaSys.glass.rhoSol_a,
    rhoGlaSol_b=glaSys.glass.rhoSol_b,
    xGla=glaSys.glass.x,
    tauShaSol_a=glaSys.shade.tauSol_a,
    tauShaSol_b=glaSys.shade.tauSol_b,
    rhoShaSol_a=glaSys.shade.rhoSol_a,
    rhoShaSol_b=glaSys.shade.rhoSol_b,
    haveExteriorShade=glaSys.haveExteriorShade,
    haveInteriorShade=glaSys.haveInteriorShade)
equation
  connect(weaDat.weaBus, weaBus)
  connect(HDirTil.weaBus, weaBus)
  connect(weaBus, HDifTilIso.weaBus)
  connect(HRoo.y, winRad.HRoo)
  connect(shaCon.y, winRad.uSha)
  connect(winRad.QTraDif_flow, HRoo.u)
  connect(winRad.HDir, HDirTil.H)
  connect(HDifTilIso.H, winRad.HDif)
  connect(HDirTil.inc, winRad.incAng)
end WindowRadiation;


Test model for window radiation for an electrochromic window. This example tests the implementation of the electrochromic window.

within Buildings.HeatTransfer.Windows.BaseClasses.Examples;
model WindowRadiationElectrochromic
  "Test model for window radiation for an electrochromic window"
  extends WindowRadiation(redeclare
      Data.GlazingSystems.DoubleElectrochromicAir13Clear glaSys);
  Modelica.Blocks.Sources.Ramp uSta(duration=86400, startTime=5*86400)
    "Window control signal"
equation
  connect(uSta.y, winRad.uSta)
end WindowRadiationElectrochromic;


Validation model for heat capacity with constant shade signal. This model validates the heat capacitor model for the window glass,
with and without a shade. For the case with shade, different
constant shade control signals are used to test
the correct energy storage of the system.
All temperatures need to decay at the same rates because
the area of heat transfer, and the heat capacity to which the
glass is connected, are scaled proportionally to the control signal.

within Buildings.HeatTransfer.Windows.BaseClasses.Validation;
model HeatCapacityConstantShade
  "Validation model for heat capacity with constant shade signal"
  extends Modelica.Icons.Example;
  parameter Modelica.Units.SI.Area AGla=2 "Glass area";

  parameter Data.Solids.Glass datGla(x=0.005)
    "Thermal properties for glass"

  HeatCapacity heaCapGla(
    haveShade=true,
    TUns(fixed=true),
    TSha(fixed=true),
    C=AGla*datGla.x*datGla.d*datGla.c)
    "Heat Capacity of glass"

  Modelica.Thermal.HeatTransfer.Components.HeatCapacitor heaCapSha1(
    C=0.5*1000,
    T(start=283.15, fixed=true))
    "Thermal capacity connected to shaded part of window"
  Modelica.Thermal.HeatTransfer.Components.HeatCapacitor heaCapUns1(
    C=0.5*1000,
    T(start=283.15, fixed=true))
    "Thermal capacity connected to unshaded part of window"
  Modelica.Blocks.Sources.Constant y05(k=0.5) "Shade control signal"
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor theConUns1(
    G=0.5*AGla*10)
    "Thermal conductor"
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor theConSha1(
    G=0.5*AGla*10)
    "Thermal conductor"
  HeatCapacity heaCapGla01(
    haveShade=true,
    TUns(fixed=true),
    TSha(fixed=true),
    C=AGla*datGla.x*datGla.d*datGla.c)
                      "Heat Capacity of glass"
  Modelica.Thermal.HeatTransfer.Components.HeatCapacitor heaCapSha2(
    C=0.1*1000,
    T(start=283.15, fixed=true))
    "Thermal capacity connected to shaded part of window"
  Modelica.Thermal.HeatTransfer.Components.HeatCapacitor heaCapUns2(
    C=0.9*1000,
    T(start=283.15, fixed=true))
    "Thermal capacity connected to unshaded part of window"
  Modelica.Blocks.Sources.Constant y1(k=0.1)  "Shade control signal"
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor theConUns2(
    G=0.9*AGla*10)
    "Thermal conductor"
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor theConSha2(
    G=0.1*AGla*10)
    "Thermal conductor"
  Modelica.Blocks.Sources.Constant y2(k=0.9)  "Shade control signal"
  HeatCapacity heaCapGlaNoSha(
    TUns(fixed=true),
    haveShade=false,
    C=AGla*datGla.x*datGla.d*datGla.c) "Heat Capacity of glass"
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor theConUns3(G=AGla*10)
    "Thermal conductor"
  Modelica.Thermal.HeatTransfer.Components.HeatCapacitor heaCapUns3(C=1000, T(
        start=283.15, fixed=true))
    "Thermal capacity connected to unshaded part of window"
equation
  connect(y05.y, heaCapGla.ySha)
  connect(y05.y, heaCapGla.yCom)
  connect(heaCapUns1.port, theConUns1.port_b)
  connect(theConUns1.port_a, heaCapGla.portUns)
  connect(heaCapGla.portSha, theConSha1.port_a)
  connect(theConSha1.port_b, heaCapSha1.port)
  connect(y1.y, heaCapGla01.ySha)
  connect(heaCapUns2.port,theConUns2. port_b)
  connect(theConUns2.port_a, heaCapGla01.portUns)
  connect(heaCapGla01.portSha, theConSha2.port_a)
  connect(theConSha2.port_b,heaCapSha2. port)
  connect(y2.y, heaCapGla01.yCom)
  connect(theConUns3.port_b,heaCapUns3. port)
  connect(heaCapGlaNoSha.portUns, theConUns3.port_a)
end HeatCapacityConstantShade;


Validation model for heat capacity with variable shade signal. This model validates the heat capacitor model for the window glass,
with varying control signal and heat conduction to a thermal capacity
that is a surrogate for the room model.
As the thermal capacity is at the same temperature, no heat is exchanged.

within Buildings.HeatTransfer.Windows.BaseClasses.Validation;
model HeatCapacityVariableShade
  "Validation model for heat capacity with variable shade signal"
  extends Modelica.Icons.Example;
  parameter Modelica.Units.SI.Area AGla=2 "Glass area";

  parameter Buildings.HeatTransfer.Data.Solids.Glass datGla(x=0.005)
    "Thermal properties for glass"

  HeatCapacity heaCapGla(
    haveShade=true,
    TUns(fixed=true),
    TSha(fixed=true),
    C=AGla*datGla.x*datGla.d*datGla.c)
    "Heat Capacity of glass"

  Modelica.Thermal.HeatTransfer.Components.HeatCapacitor heaCapSha(
    C=1000,
    T(start=293.15, fixed=true))
    "Thermal capacity connected to shaded part of window"
  Modelica.Blocks.Sources.Ramp yRamp(
    height=0.5,
    offset=0.25,
    duration=300,
    startTime=150) "Shade control signal"
  Modelica.Thermal.HeatTransfer.Components.Convection theConSha
    "Thermal conductor"
  Modelica.Thermal.HeatTransfer.Components.Convection theConUns
    "Thermal conductor"
  Modelica.Blocks.Sources.RealExpression yCom(y=1 - yRamp.y)
    "Complementary control signal"
  Modelica.Blocks.Math.Gain hASha(k=AGla*10)
    "hA value of shaded part of window"
  Modelica.Blocks.Math.Gain hAUns(k=AGla*10)
    "hA value of unshaded part of window"
equation
  connect(yRamp.y, heaCapGla.ySha)
  connect(heaCapGla.portSha, theConSha.solid)
  connect(theConSha.fluid, heaCapSha.port)
  connect(theConUns.fluid, heaCapSha.port)
  connect(heaCapGla.portUns, theConUns.solid)
  connect(yCom.y, heaCapGla.yCom)
  connect(yRamp.y, hASha.u)
  connect(hASha.y, theConSha.Gc)
  connect(hAUns.y, theConUns.Gc)
  connect(yCom.y, hAUns.u)
end HeatCapacityVariableShade;


Validation model for heat capacity with variable shade signal and different room temperature. This model validates the heat capacitor model for the window glass,
with varying control signal and heat conduction to a thermal capacity
that is a surrogate for the room model.
As the thermal capacity is at a different temperature, heat is exchanged.
The window area with the small control signal is smaller, and hence
a smaller amount of heat is exchanged.

within Buildings.HeatTransfer.Windows.BaseClasses.Validation;
model HeatCapacityVariableShadeDT
  "Validation model for heat capacity with variable shade signal and different room temperature"
  extends HeatCapacityVariableShade(heaCapSha(T(start=298.15)));
end HeatCapacityVariableShadeDT;


within Buildings.HeatTransfer.Windows.BaseClasses;
package Validation "Collection of models that validate the window base class models"
  extends Modelica.Icons.ExamplesPackage;
end Validation;


Test model for the depth of the solar beam in the room. This example computes how far from the wall, measured perpendicular to the wall,
hits the workplane.
The figure below shows this length for January 1 in Chicago
for windows with different orientations.
The spike at sunset is a numerical artifact that has no physical significance.

within Buildings.HeatTransfer.Windows.Examples;
model BeamDepthInRoom "Test model for the depth of the solar beam in the room"
  extends Modelica.Icons.Example;
  parameter Modelica.Units.SI.Length hApe=2.0
    "Upper height of aperature above ground";
  parameter Modelica.Units.SI.Length depOve=1.0
    "Depth of overhang, meausured from other exterior surface of aperature (set to 0 if no overhang)";
  parameter Modelica.Units.SI.Length gapOve=0.5
    "Gap between upper height of aperature and lower height of overhang (set to 0 if no overhang)";
  Buildings.HeatTransfer.Windows.BeamDepthInRoom winEas(
    azi=Buildings.Types.Azimuth.E,
    hApe=hApe,
    depOve=depOve,
    gapOve=gapOve,
    filNam=
        Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos"))
    "Beam depth at window in East wall"
  Buildings.HeatTransfer.Windows.BeamDepthInRoom winSou(
    azi=Buildings.Types.Azimuth.S,
    hApe=hApe,
    depOve=depOve,
    gapOve=gapOve,
    filNam=
        Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos"))
    "Beam depth at window in South wall"
  Buildings.HeatTransfer.Windows.BeamDepthInRoom winWes(
    azi=Buildings.Types.Azimuth.W,
    hApe=hApe,
    depOve=depOve,
    gapOve=gapOve,
    filNam=
        Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos"))
    "Beam depth at window in West wall"
  Buildings.HeatTransfer.Windows.BeamDepthInRoom winNor(
    azi=Buildings.Types.Azimuth.N,
    hApe=hApe,
    depOve=depOve,
    gapOve=gapOve,
    filNam=
        Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos"))
    "Beam depth at window in North wall"
end BeamDepthInRoom;


Test model for the heat transfer at the window boundary condition.

within Buildings.HeatTransfer.Windows.Examples;
model BoundaryHeatTransfer
  "Test model for the heat transfer at the window boundary condition"
  extends Modelica.Icons.Example;
  parameter Modelica.Units.SI.Area A=1 "Window surface area";
  parameter Real fFra=0.2
    "Fraction of frame, = frame area divided by total area";
  parameter
    Buildings.HeatTransfer.Data.GlazingSystems.TripleClearAir13ClearAir13Clear
    glaSys3(UFra=1) "Parameters for glazing system"
  parameter Buildings.HeatTransfer.Data.GlazingSystems.DoubleClearAir13Clear glaSys(
    shade=Buildings.HeatTransfer.Data.Shades.Gray(),
    UFra=1.5,
    haveExteriorShade=true,
    haveInteriorShade=false) "Parameters for glazing system"
  parameter Buildings.HeatTransfer.Data.GlazingSystems.SingleClear3 glaSys1(UFra=2)
    "Parameters for glazing system"
  parameter Buildings.HeatTransfer.Data.GlazingSystems.DoubleClearAir13Clear glaSys2(
    shade=Buildings.HeatTransfer.Data.Shades.Gray(),
    UFra=2,
    haveInteriorShade=false,
    haveExteriorShade=false) "Parameters for glazing system"
  parameter Boolean linearizeRadiation = false
    "Set to true to linearize emissive power";

  Buildings.HeatTransfer.Windows.ExteriorHeatTransfer extCon(A=A, fFra=fFra,
    linearizeRadiation=linearizeRadiation,
    absIRSha_air=glaSys.shade.absIR_a,
    absIRSha_glass=glaSys.shade.absIR_b,
    tauIRSha_air=glaSys.shade.tauIR_a,
    tauIRSha_glass=glaSys.shade.tauIR_b,
    haveExteriorShade=glaSys.haveExteriorShade,
    haveInteriorShade=glaSys.haveInteriorShade,
    vieFacSky=0.5) "Exterior convective heat transfer"
  Modelica.Blocks.Sources.Constant TOut(y(unit="K"), k=273.15)
    "Outside air temperature"
  Modelica.Blocks.Sources.Constant TRooAir(k=293.15, y(unit="K"))
    "Room air temperature"
  Modelica.Blocks.Sources.Ramp uSha(duration=1, startTime=0)
    "Shading control signal"
  Modelica.Blocks.Sources.Constant vWin(k=1) "Wind speed"
  Buildings.HeatTransfer.Sources.PrescribedTemperature TOuts
    "Outside air temperature"
  Buildings.HeatTransfer.Sources.PrescribedTemperature TRAir
    "Room air temperature"

 Buildings.HeatTransfer.Radiosity.IndoorRadiosity radIn(
    final linearize=linearizeRadiation, final A=A) "Indoor radiosity"
protected
  Buildings.HeatTransfer.Radiosity.RadiositySplitter radShaOut
    "Radiosity that strikes shading device"
public
  Buildings.HeatTransfer.Windows.BaseClasses.ShadingSignal shaSig(haveShade=true)
    "Conversion for shading signal"
  Buildings.HeatTransfer.Sources.PrescribedTemperature TRAir1
    "Room air temperature"
  Buildings.HeatTransfer.Sources.PrescribedTemperature TRAir2
    "Room air temperature"
  Buildings.HeatTransfer.Sources.PrescribedTemperature TRAir3
    "Room air temperature"
  Modelica.Blocks.Sources.Constant QAbsSW_flow(k=0) "Absorbed solar radiation"
  Modelica.Blocks.Math.MultiSum sumJ(nu=2)
    "Sum of radiosity from construction to room model"
equation
  connect(uSha.y, extCon.uSha)
  connect(TOuts.port, extCon.air)
  connect(TRooAir.y, TRAir.T)
  connect(extCon.vWin, vWin.y)
  connect(TOuts.T, TOut.y)
  connect(shaSig.y,radShaOut. u)
  connect(radIn.JOut, radShaOut.JIn)
  connect(shaSig.u, uSha.y)
  connect(radShaOut.JOut_2, extCon.JInUns)
  connect(radShaOut.JOut_1, extCon.JInSha)
  connect(radIn.heatPort, TRAir.port)
  connect(TRooAir.y, TRAir1.T)
  connect(TRooAir.y, TRAir2.T)
  connect(TRooAir.y, TRAir3.T)
  connect(TRAir1.port, extCon.glaUns)
  connect(TRAir2.port, extCon.glaSha)
  connect(TRAir3.port, extCon.frame)
  connect(TOut.y, extCon.TBlaSky)
  connect(TOut.y, extCon.TOut)
  connect(radIn.JIn, sumJ.y)
  connect(extCon.JOutUns, sumJ.u[1])
  connect(extCon.JOutSha, sumJ.u[2])
  connect(QAbsSW_flow.y, extCon.QSolAbs_flow)
end BoundaryHeatTransfer;


Electrochromic window. This model demonstrates the implementation of a window model.
On the left hand side is a model for the combined convective and radiative heat
transfer on the outside facing side of the window.
In the top middle is the window model, and below is a model that
computes the solar radiation balance of the window. Output of the solar
radiation balance model are the absorbed solar heat flow rates, which are
input to the heat balance models.
On the right hand side are models for the inside surface heat balance.
As opposed to the outside surface heat balance models, these models are
implemented using separate components for the radiative balance and for the convective
balance. This has been done to allow separating radiation from convection,
which is required when the room model is used with room air heat balance models
that use computational fluid dynamics.

within Buildings.HeatTransfer.Windows.Examples;
model ElectrochromicWindow "Electrochromic window"
  extends Window(
    redeclare Data.GlazingSystems.DoubleElectrochromicAir13Clear glaSys,
      uSha(
        height=0,
        duration=0,
        startTime=0));
  Modelica.Blocks.Sources.Ramp uWin(duration=0.5, startTime=0.25)
    "Window control signal"
equation
  connect(uWin.y, winRad.uSta)
end ElectrochromicWindow;


Test model for the fixed shade model. This model tests window overhang and side fins. There are four instances of sha.
The first instance models an overhang only, the second models side fins and
an overhang, the third models side fins only and the fourth has neither an overhang
nor a side fin.

within Buildings.HeatTransfer.Windows.Examples;
model FixedShade "Test model for the fixed shade model"
  extends Modelica.Icons.Example;

  Buildings.HeatTransfer.Windows.FixedShade sha[4](
    final conPar=conPar,
    azi=conPar.azi) "Shade model"
  Buildings.BoundaryConditions.WeatherData.ReaderTMY3 weaDat(
    filNam=Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos"))
  Buildings.BoundaryConditions.SolarIrradiation.DirectTiltedSurface HDirTil(
    til=Buildings.Types.Tilt.Wall,
    azi=Buildings.Types.Azimuth.S) "Direct solar irradiation"
  Modelica.Blocks.Routing.Replicator H(nout=4) "Replicator"
  Modelica.Blocks.Routing.Replicator incAng(nout=4) "Replicator"
  parameter Buildings.ThermalZones.Detailed.BaseClasses.ParameterConstructionWithWindow conPar[4](
    each til=Buildings.Types.Tilt.Wall,
    each azi=Buildings.Types.Azimuth.S,
    each A=20,
    each hWin=1.5,
    each wWin=2,
    each glaSys=glaSys,
    each layers=insCon,
    ove(
      wR = {0.1, 0.1,   0, 0},
      wL = {0.1, 0.1,   0, 0},
      gap= {0.1, 0.1,   0, 0},
      dep= {1,   1,     0, 0}),
    sidFin(
      dep= {0,   1,     1, 0},
      gap= {0,   0.1, 0.1, 0},
      h =  {0,   0.1, 0.1, 0})) "Construction parameters"

  parameter Buildings.HeatTransfer.Data.GlazingSystems.DoubleClearAir13Clear glaSys
    "Glazing system"
  parameter Data.OpaqueConstructions.Insulation100Concrete200 insCon
    "Insulation and concrete material"
equation
  connect(weaDat.weaBus, sha[1].weaBus)
  connect(weaDat.weaBus, sha[2].weaBus)
  connect(weaDat.weaBus, sha[3].weaBus)
  connect(HDirTil.weaBus, weaDat.weaBus)
  connect(HDirTil.H, H.u)
  connect(HDirTil.inc, incAng.u)
  connect(incAng.y,sha. incAng)
  connect(H.y,sha. HDirTilUns)
  connect(weaDat.weaBus, sha[4].weaBus)
end FixedShade;


This example tests the window overhang model. This example demonstrates the use of the overhang model.
It calculates the fraction of total window area that is exposed to the sun.

within Buildings.HeatTransfer.Windows.Examples;
model Overhang "This example tests the window overhang model"
  extends Modelica.Icons.Example;
  Buildings.BoundaryConditions.WeatherData.ReaderTMY3 weaDat(
    filNam=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos"))
    "Weather data"
  Buildings.HeatTransfer.Windows.Overhang ove(
    dep=1.2,
    gap=0.1,
    hWin=1.0,
    wWin=1.0,
    azi=Buildings.Types.Azimuth.S,
    wR=0.1,
    wL=0.1) "Calculates fraction of window area exposed to the sun"
  Buildings.BoundaryConditions.SolarIrradiation.DirectTiltedSurface HDirTil(
    til=Buildings.Types.Tilt.Wall,
    azi=Buildings.Types.Azimuth.S) "Direct solar irradiation"
equation
  connect(weaDat.weaBus, ove.weaBus)
  connect(HDirTil.weaBus, weaDat.weaBus)
  connect(HDirTil.inc, ove.incAng)
  connect(HDirTil.H, ove.HDirTilUns)
end Overhang;


within Buildings.HeatTransfer.Windows;
package Examples "Collection of models that illustrate model use and test models"
  extends Modelica.Icons.ExamplesPackage;
end Examples;


This example demonstrates the use of side fins for a window. This example uses the window sidefin model to calculate the fraction of total window area exposed to the sun.

within Buildings.HeatTransfer.Windows.Examples;
model SideFins "This example demonstrates the use of side fins for a window"
  extends Modelica.Icons.Example;
  Buildings.BoundaryConditions.WeatherData.ReaderTMY3 weaDat(
    filNam=Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos"))
    "Weather data"
  Buildings.HeatTransfer.Windows.SideFins fin(
    h=0.2,
    hWin=1.0,
    wWin=1.0,
    dep=0.5,
    gap=0.1) "Outputs fraction of window area exposed to the sun"
  Buildings.BoundaryConditions.SolarIrradiation.DirectTiltedSurface HDirTil(
    til=Buildings.Types.Tilt.Wall,
    azi=Buildings.Types.Azimuth.S) "Direct solar irradiation"
equation
  connect(weaDat.weaBus, fin.weaBus)
  connect(HDirTil.weaBus, weaDat.weaBus)
  connect(HDirTil.inc, fin.incAng)
  connect(HDirTil.H, fin.HDirTilUns)
end SideFins;


Test model for the window. This model demonstrates the implementation of a window model.
On the left hand side is a model for the combined convective and radiative heat
transfer on the outside facing side of the window.
In the top middle is the window model, and below is a model that
computes the solar radiation balance of the window. Output of the solar
radiation balance model are the absorbed solar heat flow rates, which are
input to the heat balance models.
On the right hand side are models for the inside surface heat balance.
As opposed to the outside surface heat balance models, these models are
implemented using separate components for the radiative balance and for the convective
balance. This has been done to allow separating radiation from convection,
which is required when the room model is used with room air heat balance models
that use computational fluid dynamics.

within Buildings.HeatTransfer.Windows.Examples;
model Window "Test model for the window"
  extends Modelica.Icons.Example;
  parameter Modelica.Units.SI.Area A=1 "Window surface area";
  parameter Real fFra=0.2
    "Fraction of frame, = frame area divided by total area";
  final parameter Modelica.Units.SI.Area AFra=fFra*A "Frame area";
  final parameter Modelica.Units.SI.Area AGla=A - AFra "Glass area";
  parameter Boolean linearize = false "Set to true to linearize emissive power";
  parameter Modelica.Units.SI.Angle azi=0 "Surface azimuth";
  parameter Modelica.Units.SI.Angle til=1.5707963267949 "Surface tilt";

  Buildings.HeatTransfer.Windows.Window window(
    A=A,
    fFra=fFra,
    glaSys=glaSys,
    linearize=linearize,
    til=til) "Window"
  Buildings.HeatTransfer.Windows.ExteriorHeatTransfer extCon(
    A=A,
    fFra=fFra,
    linearizeRadiation=linearize,
    absIRSha_air=glaSys.shade.absIR_a,
    absIRSha_glass=glaSys.shade.absIR_b,
    tauIRSha_air=glaSys.shade.tauIR_a,
    tauIRSha_glass=glaSys.shade.tauIR_b,
    haveExteriorShade=glaSys.haveExteriorShade,
    haveInteriorShade=glaSys.haveInteriorShade,
    vieFacSky=0.5) "Exterior convective heat transfer"
  Modelica.Blocks.Sources.Ramp uSha(duration=0.5, startTime=0.25)
    "Shading control signal"
  Buildings.HeatTransfer.Sources.PrescribedTemperature TOuts
    "Outside air temperature"
  Buildings.HeatTransfer.Sources.FixedTemperature TRAir(T=293.15)
    "Room air temperature"
  Buildings.HeatTransfer.Radiosity.IndoorRadiosity indRad(A=A)
    "Model for indoor radiosity"
  Buildings.HeatTransfer.Sources.FixedHeatFlow fixedHeatFlow(Q_flow=0)
  replaceable parameter
    Buildings.HeatTransfer.Data.GlazingSystems.DoubleClearAir13Clear glaSys(
    shade=Buildings.HeatTransfer.Data.Shades.Gray(),
    haveExteriorShade=false,
    haveInteriorShade=true) constrainedby Data.GlazingSystems.Generic
  Buildings.BoundaryConditions.SolarIrradiation.DirectTiltedSurface HDirTil(
    til=til,
    azi=azi)
  Buildings.BoundaryConditions.SolarIrradiation.DiffuseIsotropic HDifTilIso(
    til=til)
  Buildings.BoundaryConditions.WeatherData.ReaderTMY3 weaDat(
    filNam=Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos"))
  Modelica.Blocks.Math.Gain HRoo(k=0.1) "Solar irradiation from room"
  Buildings.HeatTransfer.Windows.BaseClasses.WindowRadiation winRad(
    AWin=1,
    N=size(glaSys.glass, 1),
    tauGlaSol=glaSys.glass.tauSol,
    rhoGlaSol_a=glaSys.glass.rhoSol_a,
    rhoGlaSol_b=glaSys.glass.rhoSol_b,
    xGla=glaSys.glass.x,
    tauShaSol_a=glaSys.shade.tauSol_a,
    tauShaSol_b=glaSys.shade.tauSol_b,
    rhoShaSol_a=glaSys.shade.rhoSol_a,
    rhoShaSol_b=glaSys.shade.rhoSol_b,
    haveExteriorShade=glaSys.haveExteriorShade,
    haveInteriorShade=glaSys.haveInteriorShade)

  Buildings.BoundaryConditions.WeatherData.Bus weaBus

  Buildings.HeatTransfer.Windows.BaseClasses.ShadeRadiation intShaRad(
    thisSideHasShade=glaSys.haveInteriorShade,
    linearize=linearize,
    absIR_air=glaSys.shade.absIR_a,
    absIR_glass=glaSys.shade.absIR_b,
    tauIR_air=glaSys.shade.tauIR_a,
    tauIR_glass=glaSys.shade.tauIR_b,
    A=AGla)
  if glaSys.haveShade "Interior shade radiation model"

  Buildings.HeatTransfer.Windows.BaseClasses.ShadingSignal shaSig(
    haveShade=glaSys.haveInteriorShade) "Conversion for shading signal"

  Buildings.HeatTransfer.Windows.InteriorHeatTransferConvective intShaCon(
    A=A,
    fFra=fFra,
    til=Buildings.Types.Tilt.Wall,
    haveExteriorShade=glaSys.haveExteriorShade,
    haveInteriorShade=glaSys.haveInteriorShade)
    "Model for interior shade heat transfer"
protected
  Modelica.Blocks.Math.Sum sumJ(
    nin=if glaSys.haveShade then 2 else 1,
    u(each start=0))
    "Sum of radiosity fom glass to outside"

  Buildings.HeatTransfer.Radiosity.RadiositySplitter radShaOut
    "Radiosity that strikes shading device"

equation
  connect(uSha.y, extCon.uSha)
  connect(uSha.y, window.uSha)
  connect(TOuts.port, extCon.air)
  connect(window.glaUns_a, extCon.glaUns)
  connect(window.glaSha_a, extCon.glaSha)
  connect(window.fra_a, extCon.frame)
  connect(extCon.JOutUns, window.JInUns_a)
  connect(extCon.JInUns, window.JOutUns_a)
  connect(extCon.JOutSha, window.JInSha_a)
  connect(extCon.JInSha, window.JOutSha_a)
  connect(fixedHeatFlow.port, indRad.heatPort)
  connect(winRad.QTraDif_flow, HRoo.u)
  connect(HRoo.y,winRad. HRoo)
  connect(HDifTilIso.H, winRad.HDif)
  connect(HDirTil.H, winRad.HDir)
  connect(HDirTil.inc, winRad.incAng)
  connect(winRad.QAbsGlaUns_flow, window.QAbsUns_flow)
  connect(winRad.QAbsGlaSha_flow, window.QAbsSha_flow)
  connect(weaDat.weaBus, weaBus)
  connect(weaBus, HDirTil.weaBus)
  connect(HDifTilIso.weaBus, weaBus)
  connect(TOuts.T, weaBus.TDryBul)
  connect(uSha.y, winRad.uSha)
  connect(weaBus.winSpe, extCon.vWin)
  connect(weaBus.TBlaSky, extCon.TBlaSky)
  connect(weaBus.TDryBul, extCon.TOut)
  connect(uSha.y, shaSig.u)
  connect(intShaRad.u, shaSig.y)
  connect(indRad.JOut, radShaOut.JIn)
  connect(radShaOut.JOut_1, intShaRad.JIn_air)
  connect(indRad.JIn, sumJ.y)
  connect(sumJ.u[2], intShaRad.JOut_air)
  connect(window.JOutUns_b, sumJ.u[1])
  connect(intShaRad.JOut_glass, window.JInSha_b)
  connect(window.JInUns_b, radShaOut.JOut_2)
  connect(radShaOut.u, shaSig.y)
  connect(intShaRad.JIn_glass, window.JOutSha_b)
  connect(TRAir.port, intShaCon.air)
  connect(uSha.y, intShaCon.uSha)
  connect(intShaCon.TSha, intShaRad.TSha)
  connect(window.fra_b, intShaCon.frame)
  connect(window.glaUns_b, intShaCon.glaUns)
  connect(intShaCon.glaSha, window.glaSha_b)
  connect(intShaCon.QRadAbs_flow, intShaRad.QRadAbs_flow)
  connect(winRad.QAbsIntSha_flow, intShaRad.QSolAbs_flow)
  connect(winRad.QAbsExtSha_flow, extCon.QSolAbs_flow)
end Window;


Angular and hemispherical absorptance of a shading device for exterior irradiation with interior shading. This function computes the angular and hemispherical absorptance of a shading device for exterior irradiation with interior shading.
Pane 1 is facing the outside and pane N is facing the room.

within Buildings.HeatTransfer.Windows.Functions;
function devAbsExteriorIrradiationInteriorShading
  "Angular and hemispherical absorptance of a shading device for exterior irradiation with interior shading"
  extends
    Buildings.HeatTransfer.Windows.Functions.BaseClasses.partialWindowShadingRadiation;

  output Real absExtIrrIntShaDev[HEM, NSta](each min=0, each max=1)
    "Absorptance of a shading device for exterior irradiation with interior shading";

algorithm
  for iSta in 1:NSta loop
    for iD in 1:HEM loop
      absExtIrrIntShaDev[iD, iSta] := traRef[TRA, 1, N, iD, iSta]*(1 - traIntShaDev -
        refIntShaDev)/(1 - refIntShaDev*traRef[Rb, N, 1, HEM, iSta])
        "Equation (A.4.91)";
    end for;
  end for;
end devAbsExteriorIrradiationInteriorShading;


Hemiperical absorptance of a shading device for interior irradiation with interior shading. This function computes the hemiperical absorbtance of a shading device for interior irradiation with interior shading.

within Buildings.HeatTransfer.Windows.Functions;
function devAbsInteriorIrradiationInteriorShading
  "Hemiperical absorptance of a shading device for interior irradiation with interior shading"
  extends
    Buildings.HeatTransfer.Windows.Functions.BaseClasses.partialWindowShadingRadiation;

  output Real absIntIrrIntShaDev[NSta](each min=0, each max=1)
    "Hemiperical absorbtance of a shading device for interior irradiation with interior shading";
protected
  Real rRho;
  Real rTau;
  Real c;

algorithm
  for iSta in 1:NSta loop
    rRho:=traRef[3, N, 1, HEM, iSta]*refIntShaDev "Part of equation (A.4.103)";
    rTau:=traRef[3, N, 1, HEM, iSta]*traIntShaDev "Part of equation (A.4.103)";
    c:=traIntShaDev*(1 - rRho/(1 - rRho)) "Equation (4.99)";

    absIntIrrIntShaDev[iSta] := (1 - traIntShaDev - refIntShaDev)*(1 + rTau/(1 - rRho))
      "Equation (4.103)";
  end for;
end devAbsInteriorIrradiationInteriorShading;


Transmittance and reflectance of glass. This function computes the angular variation of the transmittance and reflectance of each glass pane.
It accounts for the transmittance and reflectance among different panes.
Pane 1 is facing outside and pane N is facing the room.
For instance, traRef[TRA, 1, N, iD] means transmittance between layer 1 to N for exterior irradiation and
traRef[TRA, N, 1, iD] means the transmittance for interior irradiation.

within Buildings.HeatTransfer.Windows.Functions;
function getGlassTR "Transmittance and reflectance of glass"
  extends
    Buildings.HeatTransfer.Windows.Functions.BaseClasses.partialGlassRadiation;

  input Real layer[3, N, HEM, NSta] "Property of glass pane";
  output Real traRef[3, N, N, HEM, NSta](each min=0, each max=1)
    "Glass transmittance, front and back reflectance";

protected
  Real traRefIntIrr[3, N, N, HEM, NSta](each min=0, each max=1)
    "temporary array for glass transmittance, front and back reflectance for interior irradiation";

algorithm
  traRef :=
      Buildings.HeatTransfer.Windows.Functions.glassTRExteriorIrradiationNoShading(
      N=N,
      NSta=NSta,
      HEM=HEM,
      layer=layer) "property for exterior irradiation";
  traRefIntIrr :=
      Buildings.HeatTransfer.Windows.Functions.glassTRInteriorIrradiationNoShading(
      N=N,
      NSta=NSta,
      HEM=HEM,
      layer=layer) "property for interior irradiation";

  // Copy the property for interior irradiation to glass property
  for k in TRA:Rb loop
    for i in 1:N - 1 loop
      for j in i + 1:N loop
        for iD in 1:HEM loop
          traRef[k, N + 1 - i, N + 1 - j, iD, 1:NSta] :=
            traRefIntIrr[k, N + 1 - i, N + 1 - j, iD, 1:NSta];
        end for;
      end for;
    end for;
  end for;
end getGlassTR;


Angular and hemispherical absorptance of each glass pane for exterior irradiation with exterior shading. This function computes angular and hemispherical absorptance of each glass pane for exterior irradiation with exterior shading.
Pane 1 is facing outside and pane N is facing the room.

within Buildings.HeatTransfer.Windows.Functions;
function glassAbsExteriorIrradiationExteriorShading
  "Angular and hemispherical absorptance of each glass pane for exterior irradiation with exterior shading"
  input Real absExtIrrNoSha[N, HEM, NSta](each min=0, each max=1)
    "Angular and hemispherical absorptance of each glass pane for exterior irradiation without shading";
  extends
    Buildings.HeatTransfer.Windows.Functions.BaseClasses.partialWindowShadingRadiation;

  output Real absExtIrrExtSha[N, HEM, NSta](each min=0, each max=1)
    "Angular and hemispherical absorptance of each glass pane for exterior irradiation with exterior shading";

protected
  Real c "Intermediate variable";

algorithm
  for iSta in 1:NSta loop
    for iD in 1:HEM loop
      c := traExtShaDev*(1 + traRef[Ra, 1, N, iD, iSta]*refExtShaDev/
        (1 - traRef[Ra, 1, N, HEM, iSta]*refExtShaDev));
      for i in 1:N loop
        absExtIrrExtSha[i, iD, iSta] := c*absExtIrrNoSha[i, iD, iSta];
       end for;
    end for;
  end for;
end glassAbsExteriorIrradiationExteriorShading;


Angular and hemispherical absorptance of each glass pane for exterior irradiation with interior shading. This function computes angular and hemispherical absorptance of each glass pane for exterior irradiation with interior shading.
Pane 1 is facing the outside and pane N is facing the room.

within Buildings.HeatTransfer.Windows.Functions;
function glassAbsExteriorIrradiationInteriorShading
  "Angular and hemispherical absorptance of each glass pane for exterior irradiation with interior shading"
  input Real absExtIrrNoSha[N, HEM, NSta](each min=0, each max=1)
    "Absorptance for exterior irradiation without shading";
  extends
    Buildings.HeatTransfer.Windows.Functions.BaseClasses.partialWindowShadingRadiation;
  output Real absExtIrrNoShaIntSha[N, HEM, NSta](each min=0, each max=1)
    "Angular and hemispherical absorptance of each glass pane for exterior irradiation with interior shading";

protected
  Real fac;
  Real absFro "Front (outside-facing) absorptance";
  Real absBac "Back (room-facing) absorptance";
  Integer i "Index of glass pane";

algorithm
  for iSta in 1:NSta loop
    for iD in 1:HEM loop
      i := 1;
      fac := traRef[TRA, 1, N, iD, iSta]*refIntShaDev/(1 - traRef[Rb, N, 1, HEM, iSta]*
        refIntShaDev) "Equation (A.4.90)";
      absBac := 1 - traRef[TRA, i, i, iD, iSta] - traRef[Rb, i, i, iD, iSta]
        "Equation (A.4.81b)";

      if N >= 2 then
        absExtIrrNoShaIntSha[i, iD, iSta] := absExtIrrNoSha[i, iD, iSta] + fac*traRef[TRA, N,
          i + 1, HEM, iSta]*absBac "Equation (A.4.90)";

        for i in 2:N - 1 loop
          fac := traRef[TRA, 1, N, iD, iSta]*refIntShaDev/(1 - traRef[Rb, N, 1, HEM, iSta]*
            refIntShaDev) "Equation (A.4.90)";
          absFro := 1 - traRef[TRA, i, i, iD, iSta] - traRef[Ra, i, i, iD, iSta]
            "Equaiton (A.4.81a)";
          absBac := 1 - traRef[TRA, i, i, iD, iSta] - traRef[Rb, i, i, iD, iSta]
            "Equation (A.4.81b)";
          absExtIrrNoShaIntSha[i, iD, iSta] := absExtIrrNoSha[i, iD, iSta] + fac*(traRef[TRA,
              N, i, HEM, iSta]*traRef[Rb, i - 1, 1, HEM, iSta]*absFro + traRef[TRA, N, i + 1,
            HEM, iSta]*absBac) "Equation (A.4.90)";
        end for;

        i := N;
        fac := traRef[TRA, 1, N, iD, iSta]*refIntShaDev/(1 - traRef[Rb, N, 1, HEM, iSta]*
          refIntShaDev) "Equation (A.4.90)";
        absFro := 1 - traRef[TRA, i, i, iD, iSta] - traRef[Ra, i, i, iD, iSta]
          "Equaiton (A.4.81a)";
        absBac := 1 - traRef[TRA, i, i, iD, iSta] - traRef[Rb, i, i, iD, iSta]
          "Equation (A.4.81b)";
        absExtIrrNoShaIntSha[i, iD, iSta] := absExtIrrNoSha[i, iD, iSta] + fac*(traRef[TRA, N,
          i, HEM, iSta]*traRef[Rb, i - 1, 1, HEM, iSta]*absFro + absBac)
          "Equation (A.4.90)";

      else
        absExtIrrNoShaIntSha[i, iD, iSta] := absExtIrrNoSha[i, iD, iSta] + fac*absBac
          "Equation (A.4.90)";
      end if;
    end for;
  end for;
end glassAbsExteriorIrradiationInteriorShading;


Angular and hemispherical absorptance of each glass pane for exterior irradiation without shading. This function computes specular and hemispherical absorptance of each glass pane for exterior irradiation without shading.
It counts the transmittance and reflectance among different panes.
Pane 1 is facing the outside and pane N is facing the room.

within Buildings.HeatTransfer.Windows.Functions;
function glassAbsExteriorIrradiationNoShading
  "Angular and hemispherical absorptance of each glass pane for exterior irradiation without shading"
  extends
    Buildings.HeatTransfer.Windows.Functions.BaseClasses.partialWindowRadiation;
  output Real[N, HEM, NSta] abs(each min=0, each max=1) "Angular and hemispherical absorptance of each glass pane for exterior irradiation without shading.
     Indices: abs[1 to N : ] -> pane 1 to N;
     abs[ : 1 to HEM] -> angular (1:HEM-1) and hemispherical (HEM)";

protected
  Real af "Front (outside-facing side) absorptance of a pane";
  Real ab "Back (room-facing side) absorptance of a pane";
  Real deno1 "Denominantor";
  Real deno2 "Denominantor";
  Integer j;
  constant Real SMALL=Modelica.Constants.small "Small value";

algorithm
  if N == 1 then
    j := 1;
    for iSta in 1:NSta loop
      for iD in 1:HEM loop
        abs[j, iD, iSta] := 1 - traRef[TRA, j, j, iD, iSta] - traRef[Ra, j, j, iD, iSta]
          "Equation (A.4.79)";
      end for;
    end for;
  else
    for iSta in 1:NSta loop
      for iD in 1:HEM loop
        j := 1;
        af := 1 - traRef[TRA, j, j, iD, iSta] - traRef[Ra, j, j, iD, iSta]
          "Equation (A.4.81a)";
        ab := 1 - traRef[TRA, j, j, iD, iSta] - traRef[Rb, j, j, iD, iSta]
          "Equation (A.4.81b)";
        deno2 := 1 - traRef[Rb, j, 1, iD, iSta]*traRef[Ra, j + 1, N, iD, iSta];
        if deno2 < SMALL then
          abs[j, iD, iSta] := 0;
        else
          abs[j, iD, iSta] := af + ab*traRef[TRA, 1, j, iD, iSta]*traRef[Ra, j + 1, N, iD, iSta]/
            deno2 "Equation (A.4.82) and (A.4.83b)";
        end if;

        for j in 2:N - 1 loop
          af := 1 - traRef[TRA, j, j, iD, iSta] - traRef[Ra, j, j, iD, iSta]
            "Equation (A.4.81a)";
          ab := 1 - traRef[TRA, j, j, iD, iSta] - traRef[Rb, j, j, iD, iSta]
            "Equation (A.4.81b)";
          deno1 := 1 - traRef[Ra, j, N, iD, iSta]*traRef[Rb, j - 1, 1, iD, iSta];
          deno2 := 1 - traRef[Rb, j, 1, iD, iSta]*traRef[Ra, j + 1, N, iD, iSta];
          if deno1 < SMALL or deno2 < SMALL then
            abs[j, iD, iSta] := 0;
          else
            abs[j, iD, iSta] := af*traRef[TRA, 1, j - 1, iD, iSta]/deno1 + ab*traRef[TRA, 1,
              j, iD, iSta]*traRef[Ra, j + 1, N, iD, iSta]/deno2
              "Equation (A.4.83b)";
          end if;
        end for;

        j := N;
        af := 1 - traRef[TRA, j, j, iD, iSta] - traRef[Ra, j, j, iD, iSta]
          "Equation (A.4.81a)";
        deno1 := 1 - traRef[Ra, j, N, iD, iSta]*traRef[Rb, j - 1, 1, iD, iSta];
        if deno1 < SMALL then
          abs[j, iD, iSta] := 0;
        else
          abs[j, iD, iSta] := af*traRef[TRA, 1, j - 1, iD, iSta]/deno1;
        end if;
      end for;
    end for; // iSta in 1:NSta
  end if;
end glassAbsExteriorIrradiationNoShading;


Hemispherical absorptance of each glass pane for interior irradiation with exterior shading. This function computes the hemispherical absorptance of each glass pane for interior irradiation with exterior shading.
Pane 1 is facing the outside and pane N is facing the room.

within Buildings.HeatTransfer.Windows.Functions;
function glassAbsInteriorIrradiationExteriorShading
  "Hemispherical absorptance of each glass pane for interior irradiation with exterior shading"
  input Real absIntIrrNoSha[N, NSta]
    "Absorptance for interior irradiation without shading";
  extends
    Buildings.HeatTransfer.Windows.Functions.BaseClasses.partialWindowShadingRadiation;

  output Real absIntIrrExtSha[N, NSta](each min=0, each max=1)
    "Hemispherical absorptance of each glass pane for interior irradiation with exterior shading";

protected
  Real fac;
  Real absFro "Front absorptance";
  Real absBac "Back absorptance";
  Integer i "Pane index";

algorithm
  for iSta in 1:NSta loop
    fac := traRef[TRA, N, 1, HEM, iSta]*refExtShaDev/(1 - traRef[Ra, 1, N, HEM, iSta]*
      refExtShaDev);

    i := 1;
    absFro := 1 - traRef[TRA, i, i, HEM, iSta] - traRef[Ra, i, i, HEM, iSta]
      "Equaiton (A.4.81a)";
    absBac := 1 - traRef[TRA, i, i, HEM, iSta] - traRef[Rb, i, i, HEM, iSta]
      "Equation (A.4.81b)";

    if N >= 2 then
      absIntIrrExtSha[i, iSta] := absIntIrrNoSha[i, iSta] + fac*absFro + fac*traRef[TRA, 1, i,
        HEM, iSta]*traRef[Ra, i + 1, N, HEM, iSta]*absBac "Equation (A.4.94)";

      for i in 2:N - 1 loop
        absFro := 1 - traRef[TRA, i, i, HEM, iSta] - traRef[Ra, i, i, HEM, iSta]
          "Equaiton (A.4.81a)";
        absBac := 1 - traRef[TRA, i, i, HEM, iSta] - traRef[Rb, i, i, HEM, iSta]
          "Equation (A.4.81b)";
        absIntIrrExtSha[i, iSta] := absIntIrrNoSha[i, iSta] + fac*traRef[TRA, 1, i - 1, HEM, iSta]*
          absFro + fac*traRef[TRA, 1, i, HEM, iSta]*traRef[Ra, i + 1, N, HEM, iSta]*absBac
          "Equation (A.4.94)";
      end for;

      i := N;
      absFro := 1 - traRef[TRA, i, i, HEM, iSta] - traRef[Ra, i, i, HEM, iSta]
        "Equaiton (A.4.81a)";
      absIntIrrExtSha[i, iSta] := absIntIrrNoSha[i, iSta] + fac*traRef[TRA, 1, i - 1, HEM, iSta]*
        absFro "Equation (A.4.94)";
    else
      absIntIrrExtSha[i, iSta] := absIntIrrNoSha[i, iSta] + fac*absFro
        "Equation (A.4.94)";
    end if;
  end for;
end glassAbsInteriorIrradiationExteriorShading;


Hemispherical absorptance of each glass pane for interior irradiation with interior shading. This function computes the hemispherical absorbtance of each glass pane for interior irradiation with interior shading.
Pane 1 is facing the outside and pane N is facing the room.

within Buildings.HeatTransfer.Windows.Functions;
function glassAbsInteriorIrradiationInteriorShading
  "Hemispherical absorptance of each glass pane for interior irradiation with interior shading"
  input Real absIntIrrNoSha[N, NSta](each min=0, each max=1)
    "Hemispherical absorptance wfor interior irradiation without interior shading";
  extends
    Buildings.HeatTransfer.Windows.Functions.BaseClasses.partialWindowShadingRadiation;

  output Real absIntIrrIntSha[N, NSta](each min=0, each max=1)
    "Hemispherical absorbtance of each glass pane for interior irradiation with interior shading";

protected
  Real rRho;
  Real c;

algorithm
  for iSta in 1:NSta loop
    rRho :=traRef[Rb, N, 1, HEM, iSta]*refIntShaDev "Part of Equation (4.99)";
    c :=traIntShaDev*(1 + rRho/(1 - rRho)) "Equation (4.99)";
    for i in 1:N loop
      absIntIrrIntSha[i, iSta] := c*absIntIrrNoSha[i, iSta]
        "Equation (A4.100a)";
    end for;
  end for;
end glassAbsInteriorIrradiationInteriorShading;


Hemispherical absorptance of each glass pane for interior irradiation without shading. This function computes the hemispherical absorptance of each glass pane
for interior irradiation without no shading.
The angular irradiation is not considered since the interior irradiation (from the room)
is assumed to be diffusive.

within Buildings.HeatTransfer.Windows.Functions;
function glassAbsInteriorIrradiationNoShading
  "Hemispherical absorptance of each glass pane for interior irradiation without shading"

  extends
    Buildings.HeatTransfer.Windows.Functions.BaseClasses.partialWindowRadiation;

  output Real[N, NSta] absIntIrrNoSha(each min=0, each max=1)
    "Hemispherical absorptance of each glass layer for interior irradiation without shading";

protected
  Real dTraRef[3, N, N, HEM, NSta](each min=0, each max=1)
    "Dummy transmittance and reflectance with exterior irradiation without shading";
  Real dAbs[N, HEM, NSta](each min=0, each max=1)
    "Dummy absorptance with exterior irradiation and no shading";

algorithm
    // Reverse the data structure for exterior irradiation and no shading
  for i in 1:N loop
    for j in 1:N loop
      for iD in 1:HEM loop
        dTraRef[TRA, i, j, iD, 1:NSta] := traRef[TRA, N + 1 - i, N + 1 - j, iD, 1:NSta];
        dTraRef[Ra, i, j, iD, 1:NSta] := traRef[Rb, N + 1 - i, N + 1 - j, iD, 1:NSta];
        dTraRef[Rb, i, j, iD, 1:NSta] := traRef[Ra, N + 1 - i, N + 1 - j, iD, 1:NSta];
      end for;
    end for;
  end for;

  dAbs :=
    Buildings.HeatTransfer.Windows.Functions.glassAbsExteriorIrradiationNoShading(
    traRef=dTraRef,
    N=N,
    NSta=NSta,
    HEM=HEM) "Dummmy absorptance with exterior irradiation";

  // Only output hemispherical absorptance. Need to change order for interior irradiation.
  for i in 1:N loop
    absIntIrrNoSha[i, 1:NSta] := dAbs[N + 1 - i, HEM, 1:NSta];
  end for;
end glassAbsInteriorIrradiationNoShading;


Compute angular variation and hemispherical integration of the transmittance and reflectance for each glass pane without shading. This function computes the angular variation and the hemispherical integration of the transmittance and reflectance for each glass pane.
There are two schemes for the calculation. One is for coated glass and the other is for uncoated glass.
The function checks the difference between front and back reflectances.
If the difference is less than the tolerance (0.005), it uses the formula for uncoated glass.
Otherwise, the formula for coated glass will be used.

within Buildings.HeatTransfer.Windows.Functions;
function glassProperty
  "Compute angular variation and hemispherical integration of the transmittance and reflectance for each glass pane without shading"
  extends
    Buildings.HeatTransfer.Windows.Functions.BaseClasses.partialGlassRadiation;
  input Real glass[3, N, NSta] "Propertry of each glass pane";
  input Real xGla[N] "Thickness of each glass pane";
  input Modelica.Units.SI.Angle psi[HEM - 1] "Incident angles";

  output Real layer[3, N, HEM, NSta]
    "Transmittance, front and back reflectance";

protected
  parameter Real tol=0.005
    "Tolerance for difference between front and back reflectance to decide a glass is uncoated or coated";
  Real oneLay[3, HEM, NSta] "Temporary storage for glass property of one pane";
  Real oneGla[3, NSta];

algorithm
  // Compute specular value for angle 0 to 90 degree (psi[1] to psi[N]) and panes from 1 to N
  for i in 1:N loop
    // Copy data to temporary place
    for j in 1:3 loop
      oneGla[j, 1:NSta] := glass[j, i, 1:NSta];
    end for;

    for iSta in 1:NSta loop
      //uncoated galss
      if (abs(glass[Ra, i, iSta] - glass[Rb, i, iSta]) < tol) then
        oneLay[:,:,iSta] := Buildings.HeatTransfer.Windows.Functions.glassPropertyUncoated(
          HEM,
          oneGla[:,iSta],
          xGla[i],
          psi);

       else
        //coated glass
        oneLay[:,:,iSta] := Buildings.HeatTransfer.Windows.Functions.glassPropertyCoated(
          HEM,
          oneGla[:, iSta],
          psi);
       end if;
     end for; // iSta

    for j in 1:3 loop
      for k in 1:HEM loop
        layer[j, i, k, 1:NSta] := oneLay[j, k, 1:NSta];
      end for;
    end for;
  end for; // i in 1:N
end glassProperty;


Compute angular variation and hemispherical integration of the transmittance and reflectance for a uncoated glass pane without shading. This function computes the angular variation and the hemispherical integration of the transmittance and reflectance for one uncoated glass pane.
The equations are mainly based on Finlayson et al. (1990) and Fuler et al. (1991) with some modifications.

within Buildings.HeatTransfer.Windows.Functions;
function glassPropertyUncoated
  "Compute angular variation and hemispherical integration of the transmittance and reflectance for a uncoated glass pane without shading"
  extends
    Buildings.HeatTransfer.Windows.Functions.BaseClasses.partialSingleGlassRadiation;

  input Real glass[3] "Propertry of one glass pane";
  input Modelica.Units.SI.Length x "Thickness";
  input Modelica.Units.SI.Angle psi[HEM - 1] "Incident angles";
  output Real layer[3, HEM] "Transmittance, front and back reflectance";

protected
  Integer NDIR "Number of incident angles";
  Real psi_c "cos(psi), psi is incident angle in air";
  Real psi1_c "cos(psi1), psi1 is incident angle in glass";
  Real angT "Angular variation of transmittance";
  Real angR "Angular variation of reflectance";
  Real f[3, HEM-1]
    "Temporary variables for integration in hemispherical transmittance and reflectance";
  Real beta "Temporary coefficient defined in (7.2.1i)";
  Real rho0
    "Spectral reflectivity at incident angle of 0 degree at the interface";
  Real rho "Spectral reflectivity at the interface";
  Real rho1;
  Real rho2;
  Real tau "Spectral transmissivity at the interface";
  Real tau1;
  Real tau2;
  Real angT1;
  Real angT2;
  Real angR1;
  Real angR2;
  Real tmp;
  Real alpha "Spectral absorption coefficient defined in (7.2.1e)";
  Real n
    "Ratio of spectral index of refraction of glass to the index of refraction of air";
  Real psi1 "The angle od incident angle in glass";
  Real deltaX;

algorithm
  // Check the data
  assert(glass[TRA] >= 0,
    "Glass property is not correct with solar transmittance less than 0");
  assert(glass[Ra] >= 0,
    "Glass property is not correct with solar reflectance less than 0");
  assert(glass[TRA] + glass[Ra] <= 1,
    "Glass property is not correct since the summation of solar reflectance and transmittance is larger than 1");

  NDIR := HEM-1;
  deltaX := 0.5*Modelica.Constants.pi/(NDIR-1);
  // Compute specular value for angle 0 to 90 degree (psi[1] to psi[N])
  for k in TRA:Rb loop
    layer[k, 1] := glass[k] "Copy the data at 0 degree (normal incidence)";
  end for;

  beta := glass[TRA]^2 - glass[Ra]^2 + 2*glass[Ra] + 1 "(2)";

  tmp := beta^2 - 4*(2 - glass[Ra])*glass[Ra] "part of (1)";
  assert(tmp >= 0,
    "Glass property is wrong. It is not possible to calculate the spectral reflectivity at 0 degree for uncoated glass.");

  rho0 := 0.5*(beta - sqrt(tmp))/(2 - glass[Ra]) "(1)";
  assert(rho0 >= 0,
    "Glass property is wrong. The spectral reflectivity at 0 degree for uncoated glass is less than zero.");

  tmp := (glass[Ra] - rho0)/(rho0*glass[TRA]) "part of (3)";
  assert(tmp > 0,
    "Glass property is wrong. It is not possible to calculate the spectral extinction coefficient for uncoated glass.");

  alpha := -log(tmp)/x "(3)";
  tmp := sqrt(rho0);
  assert(tmp <> 1,
    "Glass property is wrong. It is not possible to calculate the spectral index of refraction for uncoated glass.");
  n := (1 + tmp)/(1 - tmp) "(4)";

  for j in 2:HEM-2 loop
    psi1 := asin(sin(psi[j])/n) "(5)";
    psi_c := cos(psi[j]);
    psi1_c := cos(psi1);

    rho1 := ((n*psi_c - psi1_c)/(n*psi_c + psi1_c))^2 "(6)";
    rho2 := ((n*psi1_c - psi_c)/(n*psi1_c + psi_c))^2 "(7)";

    tau1 := 1 - rho1 "(8)";
    tau2 := 1 - rho2 "(9)";

    tmp := exp(-alpha*x/psi1_c);

    angT1 := tau1^2*tmp/(1 - rho1^2*tmp^2) "(10)";
    angR1 := rho1*(1 + angT1*tmp) "(13)";
    angT2 := tau2^2*tmp/(1 - rho2^2*tmp^2) "(11)";
    angR2 := rho2*(1 + angT2*tmp) "(14)";

    layer[TRA, j] := 0.5*(angT1 + angT2) "Tansmittance in (12)";
    layer[Ra, j] := 0.5*(angR1 + angR2) "Front reflectance (15)";
    layer[Rb, j] := layer[Ra, j] "Back reflectance in (15)";
  end for;

  // When incident angle is equal to 90 degree
  layer[TRA, NDIR] := 0 "(16)";
  layer[Ra, NDIR] := 1.0 "(16)";
  layer[Rb, NDIR] := 1.0 "(16)";

  // Computer hemispherical value: HEM.
  for j in 1:HEM-1 loop
    for k in TRA:Rb loop
      f[k, j] := 2*layer[k, j]*Modelica.Math.cos(psi[j])*Modelica.Math.sin(psi[
        j]);
    end for;
  end for;

  for k in TRA:Rb loop
    layer[k, HEM] := Buildings.Utilities.Math.Functions.trapezoidalIntegration(
      NDIR,
      f[k, :],
      deltaX)
      "Equation (A.4.70a) and (A.4.70b) in M. Wetter 's Thesis or (7.3) in Finlayson 1993.";
  end for

end glassPropertyUncoated;


Transmittance and reflectance of glass panes for exterior irradiation without shading. This function computes the angular variation of the transmittance and reflectance of each glass pane for exteior irradiation without shading.
It accounts for the transmittance and reflectance among different panes.
Pane 1 is facing outside and pane N is facing the room.

within Buildings.HeatTransfer.Windows.Functions;
function glassTRExteriorIrradiationNoShading
  "Transmittance and reflectance of glass panes for exterior irradiation without shading"
  extends
    Buildings.HeatTransfer.Windows.Functions.BaseClasses.partialGlassRadiation;
  input Real layer[3, N, HEM, NSta] "Angular data of glass pane";
  output Real traRef[3, N, N, HEM, NSta](each min=0, each max=1)=fill(0,3, N, N, HEM, NSta)
    "Transmittance and reflectance of each glass pane for exterior irradiation without shading";

protected
  Real aij "Temporary variable";
  constant Real SMALL=Modelica.Constants.small "Small value";

algorithm
  // Property for single pane of glass or the first pane of multiple panes glass
  for iD in 1:HEM loop
    for k in TRA:Rb loop
      traRef[k, 1, 1, iD, 1:NSta] := layer[k, 1, iD, 1:NSta]
        "Equation (A.4.71)";
    end for;
  end for;

  // Property for multiple panes glass
  if N > 1 then
    for iD in 1:HEM loop
      for i in 1:N - 1 loop
        for j in i + 1:N loop
          for k in TRA:Rb loop
            traRef[k, j, j, iD, 1:NSta] := layer[k, j, iD, 1:NSta];
          end for;

          for iSta in 1:NSta loop
            aij := 1 - traRef[Ra, j, j, iD, iSta]*traRef[Rb, j - 1, i, iD, iSta]
              "Equation (A.4.77)";
            assert(aij > -SMALL,
              "Glass transmittance and reflectance data was not correct.\n");
            if aij < SMALL then
              traRef[TRA, i, j, iD, iSta] := 0;
              traRef[Ra, i, j, iD, iSta] := 1;
              traRef[Rb, j, i, iD, iSta] := 1;
            else
              aij := 1/aij;
              traRef[TRA, i, j, iD, iSta] := aij*traRef[TRA, i, j - 1, iD, iSta]*traRef[TRA,
                j, j, iD, iSta] "Equation (A.4.78a)";
              traRef[Ra, i, j, iD, iSta] := traRef[Ra, i, j - 1, iD, iSta] + aij*traRef[TRA,
                i, j - 1, iD, iSta]*traRef[TRA, i, j - 1, iD, iSta]*traRef[Ra, j, j, iD, iSta]
                "Equation (A.4.78b)";
              traRef[Rb, j, i, iD, iSta] := traRef[Rb, j, j, iD, iSta] + aij*traRef[TRA, j, j,
                iD, iSta]*traRef[TRA, j, j, iD, iSta]*traRef[Rb, j - 1, i, iD, iSta]
                "Equation (A.4.78c)";
            end if;
          end for; // iSta in 1:NSta
        end for;
      end for;
    end for;
  end if;
end glassTRExteriorIrradiationNoShading;


Transmittance and reflectance of each glass pane for interior irradiation without shading. This function computes the angular variation of the transmittance and reflectance of each glass pane for interior irradiation without shading.
It accounts for the transmittance and reflectance among different panes.
Pane 1 is facing outside and pane N is facing the room.

within Buildings.HeatTransfer.Windows.Functions;
function glassTRInteriorIrradiationNoShading
  "Transmittance and reflectance of each glass pane for interior irradiation without shading"
  extends
    Buildings.HeatTransfer.Windows.Functions.BaseClasses.partialGlassRadiation;
  input Real layer[3, N, HEM, NSta] "Angular data of glass pane";
  output Real traRef[3, N, N, HEM, NSta](each min=0, each max=1)=fill(0,3, N, N, HEM, NSta)
    "Glass transmittance, front and back reflectance";

protected
  Real dLayer[3, N, HEM, NSta]
    "Dummy glass property with Pane 1 facing inside and Pane N facing outside";
  Real dTraRef[3, N, N, HEM, NSta]
    "Dummy transmittance and reflectance for exterior irradiation";

algorithm
  // Copy the dummy glass property
  for iD in 1:HEM loop
    for j in 1:N loop
      dLayer[TRA, j, iD, 1:NSta] := layer[TRA, N + 1 - j, iD, 1:NSta];
      dLayer[Ra, j, iD, 1:NSta] := layer[Rb, N + 1 - j, iD, 1:NSta]
        "swap the front and back reflectance";
      dLayer[Rb, j, iD, 1:NSta] := layer[Ra, N + 1 - j, iD, 1:NSta]
        "swap the front and back reflectance";
    end for;
  end for;

  // Calculate transmittance and reflectance of dummy glass for exterior irradiation without shading
  dTraRef :=
    Buildings.HeatTransfer.Windows.Functions.glassTRExteriorIrradiationNoShading(
    N=N,
    NSta=NSta,
    HEM=HEM,
    layer=dLayer);

  // Convert the dummy data to real glass
  for iD in 1:HEM loop
    for i in 1:N - 1 loop
      for j in i + 1:N loop
        traRef[TRA, N + 1 - i, N + 1 - j, iD, 1:NSta] := dTraRef[TRA, i, j, iD, 1:NSta];
        traRef[Ra, N + 1 - i, N + 1 - j, iD, 1:NSta] := dTraRef[Rb, i, j, iD, 1:NSta]
          "swap the front and back reflectance";
        traRef[Rb, N + 1 - i, N + 1 - j, iD, 1:NSta] := dTraRef[Ra, i, j, iD, 1:NSta]
          "swap the front and back reflectance";
      end for;
    end for;
  end for;
end glassTRInteriorIrradiationNoShading;


within Buildings.HeatTransfer.Windows;
package Functions "Functions used in window radiation model"
  extends Modelica.Icons.Package;
end Functions;


Angular and hemispherical transmittance of a window system (glass and shading device) for exterior irradiation with interior shading. This function computes the angular and hemispherical transmittance of a window system (glass and shading device) for exterior irradiation with interior shading.
Pane 1 is facing outside and pane N is facing the room.

within Buildings.HeatTransfer.Windows.Functions;
function winTExteriorIrradiationInteriorShading
  "Angular and hemispherical transmittance of a window system (glass and shading device) for exterior irradiation with interior shading"
  extends
    Buildings.HeatTransfer.Windows.Functions.BaseClasses.partialWindowShadingRadiation;

  output Real traExtIrrIntSha[HEM, NSta](each min=0, each max=1)
    "Angular and hemispherical transmittance of a window system (glass and shading device) forh exterior irradiation with interior shading";

algorithm
  for iSta in 1:NSta loop
    for iD in 1:HEM loop
      traExtIrrIntSha[iD, iSta] := traRef[TRA, 1, N, iD, iSta]*traIntShaDev/(1 - refIntShaDev
        *traRef[Rb, N, 1, HEM, iSta]) "Equation (A.4.92)";
    end for;
  end for;
end winTExteriorIrradiationInteriorShading;


Angular and hemispherical transmittance of a window system (glass + shading device) for exterior irradiation with exterior shading. This function computes the angular and hemispherical transmittance of a window system (glass + shading device) for exterior irradiation with exterior shading.
Pane 1 is facing outside and pane N is facing the room.

within Buildings.HeatTransfer.Windows.Functions;
function winTExteriorIrradiatrionExteriorShading
  "Angular and hemispherical transmittance of a window system (glass + shading device) for exterior irradiation with exterior shading"
  extends
    Buildings.HeatTransfer.Windows.Functions.BaseClasses.partialWindowShadingRadiation;
  output Real traExtIrrExtSha[HEM, NSta](each min=0, each max=1)
    "Angular and hemispherical transmittance of a window system (glass + shading device) for exterior irradiation with exterior shading";

protected
  Real c;

algorithm
  for iSta in 1:NSta loop
    for iD in 1:HEM loop
      c := traExtShaDev*(1 + traRef[Ra, 1, N, iD, iSta]*refExtShaDev/
           (1 - traRef[Ra, 1, N, HEM, iSta]*refExtShaDev)) "Equation (A.4.88a)";
      traExtIrrExtSha[iD, iSta] := c*traRef[TRA, 1, N, iD, iSta]
        "Equation (A.4.88c)";
     end for;
  end for;
end winTExteriorIrradiatrionExteriorShading;


Hemispherical transmittance and back reflectance of a window system (glass and shading device) for interior irradiation with exterior shading.

within Buildings.HeatTransfer.Windows.Functions;
function winTRInteriorIrradiationExteriorShading
  "Hemispherical transmittance and back reflectance of a window system (glass and shading device) for interior irradiation with exterior shading"
  extends
    Buildings.HeatTransfer.Windows.Functions.BaseClasses.partialWindowShadingRadiation;
  output Real traRefIntIrrExtSha[3, NSta](each min=0, each max=1)
    "Hemispherical transmittance and back reflectance of a window system (glass and shading device) for interior irradiation with exterior shading";
algorithm
  for iSta in 1:NSta loop
    traRefIntIrrExtSha[TRA, iSta] := traRef[TRA, N, 1, HEM, iSta]*traExtShaDev/(1 -
      refExtShaDev*traRef[Ra, 1, N, HEM, iSta]) "Equation (A.4.95)";
    traRefIntIrrExtSha[Rb, iSta] := traRef[Rb, N, 1, HEM, iSta] + traRef[TRA, N, 1, HEM, iSta]*
      refExtShaDev*traRef[1, 1, N, HEM, iSta]/(1 - traRef[Ra, 1, N, HEM, iSta]*refExtShaDev)
      "Equation (A.4.97)";
    traRefIntIrrExtSha[Ra, iSta] := 0 "Dummy value";
  end for;
end winTRInteriorIrradiationExteriorShading;