phetsims / greenhouse-effect

"Greenhouse Effect" is an educational simulation in HTML5, by PhET Interactive Simulations.
GNU General Public License v3.0
4 stars 4 forks source link

Investigate ways to make the equilibrium detection more "sticky" #378

Closed jbphet closed 5 months ago

jbphet commented 6 months ago

In #374 we are working on adding description for the Layer Model screen. There is an item in the Layer Model description spec where the layers, including the ground, dispatch an alert when they reach energy equilibrium (i.e. the amount of energy being absorbed equals the amount being radiated). However, the layers currently report going into and out of equilibrium several times before "settling in". I think this is because the amount of energy coming into the layers tends to oscillate a bit, which I think is due to the way the layers can suddenly appear and start sending energy back to the ground.

It would be better if there were a bit of hysteresis around detecting when the layers go into and come out of equilibrium. We may even need to parameterize the algorithm so that the behavior on the Layer Model screen can be adjust relative to that on the Waves and Photons screens.

jbphet commented 6 months ago

I wanted to quantify the problem a bit before changing any code. I tested the behavior on main using the a11y view. Using the Photons screen, I tried various combinations of gas concentration and cloud presence, and the temperature always stabilized and stayed that way. Here's an example of the readout from the a11y view:

image

On the Layer Model screen, I tried setting the solar intensity to the max and starting the sun, and it equilibrated. Then I added a layer, and the ground and the layer went into and out of equilibrium several times before staying there. This is what the readout looked like:

image

So, I basically need to fix up the behavior of the Layer Model screen without breaking the other screens. Sounds like some sort of options to the equilibrium detection algorithm may be what we need.

jbphet commented 6 months ago

Here's another test case that shows the behavior that we'd like to avoid. This is with max solar intensity, min albedo, max number of layers, all at 100% absorption. This is a screenshot of when the ground is reaching equilibrium, and it shows several messages from the ground and some from the layers:

image

Here it is a few seconds later, with several messages about layers becoming stable.

image

The goal will be to get to where there is only one message for each layer, including the ground, but that if things change we would then see a new set of "temperature stable" messages, but just one for each layer.

jbphet commented 6 months ago

I've added the ability to configure some aspects of the equilibrium detection algorithm, and things are a bit better, but not good enough yet. For example, with the configuration I committed, the test described in the previous comment behaves reasonably well in that there is only one alert for the stabilization of each layer, including the ground. However, if I get to this state and then suddenly remove all layers, there are no subsequent announcements about the ground cooling off.

I'm going to have to return to this later. I am considering making a full overhaul of the equilibrium detection algorithm and have it be based on the temperature change in a moving window. That will likely be a bit simpler, and since we can watch the temperatures on the ground and atmosphere layers, it may be a bit easier to tweak as well.

jbphet commented 6 months ago

I thought it would be helpful to graph the temperature of the ground over time on the 3rd screen when there is a single layer present, because I was seeing a stair-step-ish sort of behavior, and I wanted to be able to visualize it better. Here is what this looks like. The x axis is in seconds, the y axis is in Kelvin.

image

This illustrates why this problem is tricky. One could argue that it is going in and out of equilibrium all the time for short periods, but that's not the behavior we want, so we need to make sure that our criteria rule on the early "steps" that we are seeing in this data.

jbphet commented 6 months ago

I wasn't having any luck with the approach of adding hysteresis for the difference between the incoming and outgoing energy because adjusting the thresholds to make the algorithm more "sticky" made it too sticky in some situations, and there was no intuitive way to figure out how to adjust these thresholds. I decided to use a different approach altogether for the equilibrium detection where a history of the temperature values for the layer are kept in a moving window, and those values are evaluated at each step for whether the temperature has stayed within a given span. If it does, the layer is in equilibrium, if not, it's not. I used different values for this temperature span when transitioning from in to out or from out to in equilibrium. So far, this approach seems to work well in that it detects equilibrium of the layers reasonably quickly, recognizes when they layer goes out of equilibrium quickly, and doesn't bounce around between in and out of equilibrium.

jbphet commented 6 months ago

@arouinfar - assigning to you to test the current behavior on main and see if the alerts related to equilibrium are coming out when they should and not coming out when they shouldn't.

arouinfar commented 5 months ago

This is a nice improvement @jbphet, especially for the Layer Model screen. The repeated "temperature stable" statements negatively impacted the usability of that screen, and I'm glad that's no longer happening.

The behavior on the first two screens seems relatively undisturbed, but the "temperature stable" always triggers 0.1 degrees before reaching true equilibrium. However, I think this is an acceptable trade-off, as a 0.1-degree discrepancy is unlikely to cause pedagogical issues.

Overall, great work @jbphet! I'm happy with the results, closing.