Skip to content

Commit

Permalink
Viscosity query parameters, see phetsims/density#67
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Jul 27, 2021
1 parent b70b7e2 commit b61a7c3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
19 changes: 19 additions & 0 deletions js/common/DensityBuoyancyCommonQueryParameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,25 @@ const DensityBuoyancyCommonQueryParameters = QueryStringMachine.getAll( {
p2DynamicRelaxation: {
type: 'number',
defaultValue: 4
},

// Controls the proportional amount of overall result viscosity forces applied
viscosityMultiplier: {
type: 'number',
defaultValue: 1
},

// A mix between 0: Full viscosity is applied when any part of a mass is in the liquid, 1: The viscosity effect is
// multiplied times the proportion of the mass submerged (lowering viscosity when partially submerged).
viscositySubmergedRatio: {
type: 'number',
defaultValue: 0
},

// Viscosity for masses larger than this will be reduced to the force for this viscosity (somewhat of a hacK)
viscosityMassCutoff: {
type: 'number',
defaultValue: 2
}
} );

Expand Down
6 changes: 5 additions & 1 deletion js/common/model/DensityBuoyancyModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,12 @@ class DensityBuoyancyModel {
}

// Increase the generally-visible viscosity effect
const ratioSubmerged =
( 1 - DensityBuoyancyCommonQueryParameters.viscositySubmergedRatio ) +
DensityBuoyancyCommonQueryParameters.viscositySubmergedRatio * submergedVolume / mass.volumeProperty.value;
const hackedViscosity = this.liquidViscosityProperty.value ? 0.03 * Math.pow( this.liquidViscosityProperty.value / 0.03, 0.8 ) : 0;
const viscousForce = velocity.times( -hackedViscosity * Math.max( 2, mass.massProperty.value ) * 3000 );
const viscosityMass = Math.max( DensityBuoyancyCommonQueryParameters.viscosityMassCutoff, mass.massProperty.value );
const viscousForce = velocity.times( -hackedViscosity * viscosityMass * ratioSubmerged * 3000 * DensityBuoyancyCommonQueryParameters.viscosityMultiplier );
this.engine.bodyApplyForce( mass.body, viscousForce );
}
else {
Expand Down

0 comments on commit b61a7c3

Please sign in to comment.