lbl-srg / modelica-buildings

Modelica Buildings library
257 stars 159 forks source link

Fix TrueFalseHold with unit impulse input signal #3967

Closed AntoineGautier closed 2 months ago

AntoineGautier commented 2 months ago

This addresses #3966.

AntoineGautier commented 2 months ago

Unit tests failing with 9bb0c29

Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice

This is due to the following sequence within Buildings.Controls.OBC.ASHRAE.G36.ZoneGroups.OperationMode.

image

The following plot compares the variables that cause the differences between the master branch //1 and the feature branch //2 for Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice.Guideline36Winter.

image

We can verify that the feature branch yields the expected results.

[EDIT] Not really: see https://github.com/lbl-srg/modelica-buildings/pull/3967#issuecomment-2311927171

Buildings.Air.Systems.SingleZone.VAV.Examples.OptimalStart

This is due to the following sequence within Buildings.Controls.OBC.Utilities.BaseClasses.OptimalStartCalculation.

image

The following plot compares the variables that cause the differences between the master branch //1 and the feature branch //2 for Buildings.Air.Systems.SingleZone.VAV.Examples.OptimalStart.ConventionalSpring.

image

We can verify that the feature branch yields the expected results.

[EDIT] Not really: see https://github.com/lbl-srg/modelica-buildings/pull/3967#issuecomment-2311927171

Buildings.Obsolete.Air.Systems.SingleZone.VAV.Examples.OptimalStart

Same as above.

Updated results

Results are updated in 72c45d30b0266cc2cffef788c1f9f73eb4d2ba1b.

AntoineGautier commented 2 months ago

There is still an issue with the implementation in 72c45d3 that is visible in the plots for Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice.Guideline36Winter in https://github.com/lbl-srg/modelica-buildings/pull/3967#issuecomment-2310093495. The condition time >= pre(entryTimeFalse) + falseHoldDuration and time >= pre(entryTimeTrue) + trueHoldDuration does not fire the when clause as expected based on https://specification.modelica.org/maint/3.6/equations.html#when-equations:

The equations within a when-equation are activated only at the instant when the scalar expression or any of the elements of the vector expression becomes true.

This seems related to the CVODE solver and Dymola (OCT with CVODE yields the expected results). The plot below compares the trajectories of the same variables between DASSL (diagram 1) and CVODE (diagram 2).

image

As a workaround for CVODE, the vector expression is split into two separate elsewhen clauses in e793841, which yields the following results with CVODE.

image

A ticket has been open at DS #SR01251824.

AntoineGautier commented 2 months ago

@JayHuLBL This is ready for your review. (Another PR more complicated than anticipated: 2 tickets open at DS, 1 at Modelon)

AntoineGautier commented 2 months ago

@mwetter This is ready to merge.

mwetter commented 2 months ago

Thanks, that was indeed a hard one...