Skip to content

Commit

Permalink
improve support for shared showTemperatureProperty and the migration …
Browse files Browse the repository at this point in the history
…for it, see #374 and #376
  • Loading branch information
jbphet committed Dec 19, 2023
1 parent 50995d9 commit da2f107
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 34 deletions.
34 changes: 23 additions & 11 deletions js/common/model/EnergyAbsorbingEmittingLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import EMEnergyPacket from './EMEnergyPacket.js';
import EnergyDirection from './EnergyDirection.js';
import WithRequired from '../../../../phet-core/js/types/WithRequired.js';
import energyPacketCrossedAltitude from './energyPacketCrossedAltitude.js';
import Property from '../../../../axon/js/Property.js';

// constants

Expand Down Expand Up @@ -73,8 +74,17 @@ const VOLUME = SURFACE_DIMENSIONS.width * SURFACE_DIMENSIONS.height * LAYER_THIC

type SelfOptions = {
substance?: Substance;

// initial setting for the absorption proportion, must be from 0 to 1 inclusive
initialEnergyAbsorptionProportion?: number;

// The minimum temperature that this layer can get to, in Kelvin. This will also be the temperature at
// which it is originally set to. When at this temperature, the layer will radiate no energy. This is a bit of
// a violation of the actual physics, since anything that is above absolute zero radiates some energy, but was a
// necessary simplification to have the Earth at a stable initial temperature that is reasonable (i.e. not
// absolute zero).
minimumTemperature?: number;
supportsShowTemperature?: boolean;
};
export type EnergyAbsorbingEmittingLayerOptions = SelfOptions & WithRequired<PhetioObjectOptions, 'tandem'>;

Expand All @@ -93,7 +103,7 @@ class EnergyAbsorbingEmittingLayer extends PhetioObject {
public readonly energyAbsorptionProportionProperty: NumberProperty;

// tracks whether the temperature should be shown in the view
public readonly showTemperatureProperty: BooleanProperty;
public readonly showTemperatureProperty: Property<boolean>;

// Other fields whose meaning should be reasonably obvious.
private readonly substance: Substance;
Expand All @@ -110,16 +120,12 @@ class EnergyAbsorbingEmittingLayer extends PhetioObject {
// default to glass
substance: Substance.GLASS,

// initial setting for the absorption proportion, must be from 0 to 1 inclusive
initialEnergyAbsorptionProportion: 1,

// The minimum temperature that this layer can get to, in degrees Kelvin. This will also be the temperature at
// which it is originally set to. When at this temperature, the layer will radiate no energy. This is a bit of
// a violation of the actual physics, since anything that is above absolute zero radiates some energy, but was a
// necessary simplification to have the Earth at a stable initial temperature that is reasonable (i.e. not
// absolute zero).
minimumTemperature: 0,

supportsShowTemperature: false,

// phet-io
phetioReadOnly: true,
phetioState: false,
Expand Down Expand Up @@ -148,10 +154,15 @@ class EnergyAbsorbingEmittingLayer extends PhetioObject {
phetioDocumentation: 'Proportion, from 0 to 1, of light energy absorbed for interacting wavelengths.'
} );

this.showTemperatureProperty = new BooleanProperty( true, {
tandem: options.tandem.createTandem( 'showTemperatureProperty' ),
phetioFeatured: true
} );
// Create the Property that controls whether the temperature of this layer will be depicted in the view. If this
// instance does not support showing the temperature a dummy property is created that is not instrumented and should
// not be used.
this.showTemperatureProperty = options.supportsShowTemperature ?
new BooleanProperty( true, {
tandem: options.tandem.createTandem( 'showTemperatureProperty' ),
phetioFeatured: true
} ) :
new BooleanProperty( true );

// A property that is true when this layer is in equilibrium, meaning that the amount of energy coming in is equal
// to or at least very close to the amount of energy going out.
Expand Down Expand Up @@ -279,6 +290,7 @@ class EnergyAbsorbingEmittingLayer extends PhetioObject {
public reset(): void {
this.temperatureProperty.reset();
this.atEquilibriumProperty.reset();
this.showTemperatureProperty.value = true;
}

// statics
Expand Down
1 change: 1 addition & 0 deletions js/common/model/GroundLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class GroundLayer extends EnergyAbsorbingEmittingLayer {

substance: EnergyAbsorbingEmittingLayer.Substance.EARTH,
initialEnergyAbsorptionProportion: 1,
supportsShowTemperature: true,

// Set the minimum temperature to a value that is reasonable for surface of the Earth.
minimumTemperature: MINIMUM_EARTH_AT_NIGHT_TEMPERATURE,
Expand Down
16 changes: 6 additions & 10 deletions js/common/model/LayersModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ type SelfOptions = {
// proportion of energy that crosses an atmosphere layer that is absorbed, 0 for none, 1 for 100%
initialAtmosphereLayerAbsorptionProportion?: number;

// whether to support showing the temperature of the atmosphere layers, only used if these layers are shown in view
supportShowTemperatureInAtmosphereLayers?: boolean;

// whether a flux meter should be present in this model
fluxMeterPresent?: boolean;

Expand Down Expand Up @@ -111,9 +114,6 @@ class LayersModel extends GreenhouseEffectModel {
// model of a meter that can measure the energy flux moving through the atmosphere
public readonly fluxMeter: FluxMeter | null;

// whether the thermometer measuring surface temperature is visible
public readonly surfaceThermometerVisibleProperty: BooleanProperty;

// whether the "Energy Balance" display is visible
public readonly energyBalanceVisibleProperty: BooleanProperty;

Expand All @@ -136,6 +136,7 @@ class LayersModel extends GreenhouseEffectModel {
numberOfAtmosphereLayers: DEFAULT_NUMBER_OF_ATMOSPHERE_LAYERS,
initialAtmosphereLayerAbsorptionProportion: 0,
atmosphereLayersInitiallyActive: true,
supportShowTemperatureInAtmosphereLayers: false,
fluxMeterPresent: false,
groundLayerOptions: {
tandem: providedOptions.tandem.createTandem( 'groundLayer' )
Expand Down Expand Up @@ -169,11 +170,6 @@ class LayersModel extends GreenhouseEffectModel {
}
} );

this.surfaceThermometerVisibleProperty = new BooleanProperty( true, {
tandem: surfaceTemperatureTandem.createTandem( 'surfaceThermometerVisibleProperty' ),
phetioFeatured: true
} );

this.surfaceTemperatureVisibleProperty = new BooleanProperty( false, {
tandem: surfaceTemperatureTandem.createTandem( 'surfaceTemperatureVisibleProperty' ),
phetioFeatured: true
Expand Down Expand Up @@ -282,7 +278,8 @@ class LayersModel extends GreenhouseEffectModel {
{
tandem: this.atmosphereLayersTandem.createTandem( `layer${index + 1}` ),
initiallyActive: options.atmosphereLayersInitiallyActive,
initialEnergyAbsorptionProportion: options.initialAtmosphereLayerAbsorptionProportion
initialEnergyAbsorptionProportion: options.initialAtmosphereLayerAbsorptionProportion,
supportsShowTemperature: options.supportShowTemperatureInAtmosphereLayers
}
);
this.atmosphereLayers.push( atmosphereLayer );
Expand Down Expand Up @@ -382,7 +379,6 @@ class LayersModel extends GreenhouseEffectModel {
this.netInflowOfEnergyProperty.reset();
this.fluxMeterVisibleProperty.reset();
this.energyBalanceVisibleProperty.reset();
this.surfaceThermometerVisibleProperty.reset();
this.temperatureUnitsProperty.set( DEFAULT_TEMPERATURE_UNITS_PROPERTY.value );
this.sunEnergySource.reset();
this.groundLayer.reset();
Expand Down
2 changes: 1 addition & 1 deletion js/common/view/GreenhouseEffectObservationWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class GreenhouseEffectObservationWindow extends Node {
// Create a derived property that is true when either of the visual surface temperature indicators are enabled.
const surfaceTemperatureIndicatorEnabledProperty = new DerivedProperty(
[
model.surfaceThermometerVisibleProperty,
model.groundLayer.showTemperatureProperty,
model.surfaceTemperatureVisibleProperty
],
( thermometerVisible, temperatureVisible ) => thermometerVisible || temperatureVisible
Expand Down
2 changes: 1 addition & 1 deletion js/common/view/LandscapeObservationWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class LandscapeObservationWindow extends GreenhouseEffectObservationWindow {
model.surfaceTemperatureFahrenheitProperty,
model.temperatureUnitsProperty,
{
visibleProperty: model.surfaceThermometerVisibleProperty,
visibleProperty: model.groundLayer.showTemperatureProperty,
minTemperature: model.groundLayer.minimumTemperature - 5,

// phet-io
Expand Down
2 changes: 1 addition & 1 deletion js/common/view/LandscapeObservationWindowPDOMNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class LandscapeObservationWindowPDOMNode extends ObservationWindo

Multilink.multilink( [
model.surfaceTemperatureKelvinProperty,
model.surfaceThermometerVisibleProperty,
model.groundLayer.showTemperatureProperty,
model.surfaceTemperatureVisibleProperty,
model.temperatureUnitsProperty,
model.concentrationControlModeProperty
Expand Down
2 changes: 1 addition & 1 deletion js/common/view/LandscapeScreenSummaryContentNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class LandscapeScreenSummaryContentNode extends GreenhouseEffectS
model.surfaceTemperatureKelvinProperty,
model.concentrationControlModeProperty,
model.surfaceTemperatureVisibleProperty,
model.surfaceThermometerVisibleProperty,
model.groundLayer.showTemperatureProperty,
model.temperatureUnitsProperty,
model.cloudEnabledInManualConcentrationModeProperty
],
Expand Down
4 changes: 2 additions & 2 deletions js/common/view/LayersModelAlerter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class LayersModelAlerter extends Alerter {
if ( atEquilibrium ) {
this.alert( TemperatureDescriber.getSurfaceTemperatureStableString(
model.surfaceTemperatureKelvinProperty.value,
model.surfaceThermometerVisibleProperty.value,
model.groundLayer.showTemperatureProperty.value,
model.surfaceTemperatureVisibleProperty.value,
model.temperatureUnitsProperty.value,
options.useHistoricalAlertsProperty.value
Expand Down Expand Up @@ -235,7 +235,7 @@ class LayersModelAlerter extends Alerter {

// To reduce verbosity the temperature value is included only every NUMBER_OF_TERSE_TEMPERATURE_ALERTS that
// this response is created. Temperature must also be visible in the view.
const includeTemperatureValue = this.model.surfaceThermometerVisibleProperty.value &&
const includeTemperatureValue = this.model.groundLayer.showTemperatureProperty.value &&
this.temperatureChangeAlertCount === 0;

const currentTemperature = this.getCurrentTemperature();
Expand Down
1 change: 1 addition & 0 deletions js/layer-model/model/LayerModelModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class LayerModelModel extends LayersModel {
numberOfAtmosphereLayers: 3,
initialAtmosphereLayerAbsorptionProportion: INITIAL_ABSORPTION_PROPORTION,
atmosphereLayersInitiallyActive: false,
supportShowTemperatureInAtmosphereLayers: true,
groundLayerOptions: {
initialAlbedo: 0.3,
minimumTemperature: MINIMUM_GROUND_TEMPERATURE,
Expand Down
4 changes: 2 additions & 2 deletions js/layer-model/view/LayerModelObservationWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class LayerModelObservationWindow extends GreenhouseEffectObservationWindow {
new BooleanProperty( true ) // The ground layer always has a temperature.
);

this.showThermometerCheckbox = new ShowTemperatureCheckbox( model.surfaceThermometerVisibleProperty, {
this.showThermometerCheckbox = new ShowTemperatureCheckbox( model.groundLayer.showTemperatureProperty, {
left: this.atmosphereLayerNodes[ 0 ].temperatureDisplay.left,
bottom: GreenhouseEffectObservationWindow.SIZE.height -
GreenhouseEffectObservationWindow.CONTROL_AND_INSTRUMENT_INSET,
Expand Down Expand Up @@ -193,7 +193,7 @@ class LayerModelObservationWindow extends GreenhouseEffectObservationWindow {
model.temperatureUnitsProperty,
{

visibleProperty: model.surfaceThermometerVisibleProperty,
visibleProperty: model.groundLayer.showTemperatureProperty,
minTemperature: model.groundLayer.minimumTemperature - 5,
maxTemperature: 475, // empirically determined

Expand Down
2 changes: 1 addition & 1 deletion js/layer-model/view/LayerModelObservationWindowPDOMNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class LayerModelObservationWindowPDOMNode extends ObservationWindowPDOMNode {
);

// Only show the surface temperature description when the surface thermometer is visible.
model.surfaceThermometerVisibleProperty.link( surfaceThermometerVisible => {
model.groundLayer.showTemperatureProperty.link( surfaceThermometerVisible => {
surfaceTemperatureListItemNode.pdomVisible = surfaceThermometerVisible;
} );

Expand Down
2 changes: 1 addition & 1 deletion js/layer-model/view/LayerModelScreenSummaryContentNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class LayerModelScreenSummaryContentNode extends GreenhouseEffect
[
model.isPlayingProperty,
model.sunEnergySource.isShiningProperty,
model.surfaceThermometerVisibleProperty,
model.groundLayer.showTemperatureProperty,
infraredAbsorbingLayersPhraseProperty,
surfaceTemperaturePhraseProperty
],
Expand Down
2 changes: 1 addition & 1 deletion js/layer-model/view/ShowTemperatureCheckbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
*/

import NumberProperty from '../../../../axon/js/NumberProperty.js';
import Property from '../../../../axon/js/Property.js';
import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';
import ThermometerNode from '../../../../scenery-phet/js/ThermometerNode.js';
import { Color, NodeTranslationOptions, ParallelDOMOptions } from '../../../../scenery/js/imports.js';
import Checkbox, { CheckboxOptions } from '../../../../sun/js/Checkbox.js';
import greenhouseEffect from '../../greenhouseEffect.js';
import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
import Property from '../../../../axon/js/Property.js';

type SelfOptions = EmptySelfOptions;
export type ShowTemperatureCheckboxOptions = SelfOptions & NodeTranslationOptions & ParallelDOMOptions &
Expand Down
2 changes: 1 addition & 1 deletion js/photons/view/PhotonsScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class PhotonsScreenView extends GreenhouseEffectScreenView {
} );

const surfaceThermometerCheckbox = new SurfaceThermometerCheckbox(
model.surfaceThermometerVisibleProperty,
model.groundLayer.showTemperatureProperty,
model.surfaceTemperatureKelvinProperty,
model.temperatureUnitsProperty,
tandem.createTandem( 'surfaceThermometerCheckbox' )
Expand Down
2 changes: 1 addition & 1 deletion js/waves/view/WavesScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class WavesScreenView extends GreenhouseEffectScreenView {
} );

const surfaceThermometerCheckbox = new SurfaceThermometerCheckbox(
model.surfaceThermometerVisibleProperty,
model.groundLayer.showTemperatureProperty,
model.surfaceTemperatureKelvinProperty,
model.temperatureUnitsProperty,
tandem.createTandem( 'surfaceThermometerCheckbox' )
Expand Down

0 comments on commit da2f107

Please sign in to comment.