-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sim doesn't launch with correct avg temperature if mass is changed on Diffusion Screen #284
Comments
Reproduced in main. Very weird. Tavg should be the same as the Initial Temperature setting. In the launched sim, if I change Initial Temperature to 250, then back to 300, then Tavg is correct. I'm guessing there's an ordering issue with how state is restored that is resulting in a different result. Tavg is the value of protected override stepModelTime( dt: number ): void {
...
this.updateData();
}
/**
* Updates the Data displayed for the left and right sides of the container.
*/
private updateData(): void {
this.leftData.update();
this.rightData.update();
} |
(cherry picked from commit 023cf87)
(cherry picked from commit 023cf87)
In the above commits, I tightened up the API for DiffusionData, which is where |
If I omit step 4 (Change the Mass to 30) then Tavg is correct. If I add this to DiffusionModel, the problem goes away. But this should not be necessary, because if ( assert && Tandem.PHET_IO_ENABLED ) {
phet.phetio.phetioEngine.phetioStateEngine.stateSetEmitter.addListener( () => this.updateData() );
} |
Inspecting |
DiffusionParticle extends Particle, and adds Verified with this addition to DiffusionData else {
assert && assert( totalKE !== 0, 'totalKE should not be zero when the container is not empty' );
+ console.log( `totalKE=${totalKE} mass=${this.particleSystem.particles2[ 0 ].mass}` ); So we need DiffusionParticleIO. Ugh... This will be a big change. |
Looking more closely at ParticleStateObject, I see that it does include export type ParticleStateObject = {
mass: number;
radius: number;
x: number;
y: number;
_previousX: number;
_previousY: number;
vx: number;
vy: number;
}; The difference with DiffusionParticle is that mass and radius are mutable. So something is apparently not setting mass (and radius?) when restoring the state of DiffusionParticle instances. |
The problem is in DiffusionParticleSystem, where there's some overly-zealous uses of Multilink.multilink(
[ this.particle2Settings.massProperty, this.particle2Settings.initialTemperatureProperty ],
( mass, initialTemperature ) => {
if ( !isSettingPhetioStateProperty.value ) {
updateMassAndSpeed( mass, initialTemperature, this.particles2 );
}
} );
// Update radii of existing particles.
this.particle1Settings.radiusProperty.link( radius => {
if ( !isSettingPhetioStateProperty.value ) {
updateRadius( radius, this.particles1, container.leftBounds, isPlayingProperty.value );
}
} );
this.particle2Settings.radiusProperty.link( radius => {
if ( !isSettingPhetioStateProperty.value ) {
updateRadius( radius, this.particles2, container.rightBounds, isPlayingProperty.value );
}
} ); |
The fix is 470663f, the other commits are patches for the 3 sim branches. @Nancy-Salpepi please test in main. Leave open for verification in 1.1.0-rc.2. |
In the State wrapper when I follow similar steps to #284 (comment), the downstream sim will launch with the correct average temperature after pressing Set State Now. Steps:
|
Reproduced in main using the steps in #284 (comment). Noting that this workaround (first mentioned in #284 (comment)) does NOT address this new problem. if ( assert && Tandem.PHET_IO_ENABLED ) {
phet.phetio.phetioEngine.phetioStateEngine.stateSetEmitter.addListener( () => this.updateData() );
} |
I previously noted:
ParticleIO does not exist; we have LightParticleIO and HeavyParticleIO, DiffusionParticle1IO and DiffusionParticle2IO. I suspect that there's a serialization problem with DiffusionParticle1IO and DiffusionParticle1IO. |
This was indeed a serialization bug in DiffusionParticle1IO and DiffusionParticle2IO. While mass and radius were serialized correctly, there were not deserialized correctly. The mass and radius values that were saved were not being used to create the particle instance during deserialization. For example, here's the fix for DiffusionParticle1: /**
* Deserializes an instance of DiffusionParticle1.
*/
private static fromStateObject( stateObject: DiffusionParticle1StateObject ): DiffusionParticle1 {
return new DiffusionParticle1( {
x: stateObject.x,
y: stateObject.y,
previousX: stateObject._previousX,
previousY: stateObject._previousY,
vx: stateObject.vx,
- vy: stateObject.vy
+ vy: stateObject.vy,
+ mass: stateObject.mass,
+ radius: stateObject.radius
} );
} The primary commit is cab2dc5, the others are related to patching release branches for the 3 sims. I tested both the original problem (#284 (comment)) and the more recent problem (#284 (comment)). |
@Nancy-Salpepi please test in main. Leave open for verification in 1.1.0-rc.2. |
This looks good now on main! |
Please verify for phetsims/qa#1123 and phetsims/qa#1125. (This issue is irrelevant for the Gases Intro sim.) To verify: If everything looks OK, please close this issue. |
looks good in rc.2 for Gas Properties and Diffusion sims. |
Test device
MacBook Air M1 chip
Operating System
14.5
Browser
Safari 17.5
Problem description
For phetsims/qa#1107, in the Studio and State wrappers on the Diffusion Screen changing the Mass of either particle type will result in an incorrect Tavg in the Data Panel when the sim is launched.
Steps to reproduce
Visuals
The text was updated successfully, but these errors were encountered: