feat(FluidDynamics): Adding more fluid dynamics - continuation of PR #949 and #1112 ,#1125
Conversation
|
I think it might be best to sort this |
|
I spent some time thinking about this and this is my current favorite: Two main fluid data structures: The generic kinematic fluid data structure FluidFlow (d : ℕ) where
massDensity : MassDensity d
velocity : VelocityField dand the generic dynamic fluid data, based on the generic Cauchy momentum equation. structure CauchyFlow (d : ℕ) extends FluidFlow d where
stress : CauchyStress d
bodyForce : SpecificBodyForce dWe can then use definitions/predicates for the physical cases. def IsUnforced (d : ℕ) (flow : CauchyFlow d) : Prop :=
∀ t x, flow.bodyForce t x = 0
def HasConservativeBodyForce
(d : ℕ) (flow : CauchyFlow d) (potential : Space d → ℝ) : Prop :=
∀ t x, flow.bodyForce t x = -(∇ potential x)
def IsInviscid
(d : ℕ) (flow : CauchyFlow d) (pressure : ScalarField d) : Prop :=
∀ t x, flow.stress t x = -pressure t x • 1
def IsNewtonian
(d : ℕ) (flow : CauchyFlow d)
(pressure shearViscosity bulkViscosity : ScalarField d) : Prop :=And define force-density helpers: noncomputable def bodyForceDensity (d : ℕ) (flow : CauchyFlow d) : VectorField d :=
fun t x => flow.massDensity t x • flow.bodyForce t x
noncomputable def stressForceDensity (d : ℕ) (flow : CauchyFlow d) : VectorField d :=
fun t x => matrixDiv d (flow.stress t) x
noncomputable def totalForceDensity (d : ℕ) (flow : CauchyFlow d) : VectorField d :=
fun t x => stressForceDensity d flow t x + bodyForceDensity d flow t xThen the aforementioned Cauchy momentum equation is the generic: def CauchyMomentumEquation (d : ℕ) (flow : CauchyFlow d) : Prop :=
∀ t x, conservativeMomentumLHS d flow.toFluidFlow t x = totalForceDensity d flow t xEuler becomes: def Euler (d : ℕ) (flow : CauchyFlow d) (pressure : ScalarField d) : Prop :=
ClassicalContinuityEquation d flow.toFluidFlow ∧
CauchyMomentumEquation d flow ∧
IsInviscid d flow pressureNavier-Stokes becomes: def NavierStokes
(d : ℕ) (flow : CauchyFlow d)
(pressure shearViscosity bulkViscosity : ScalarField d) : Prop :=
ClassicalContinuityEquation d flow.toFluidFlow ∧
CauchyMomentumEquation d flow ∧
IsNewtonian d flow pressure shearViscosity bulkViscosityIf we want to work with thermodynamic equations (Bernoulli, energy balances etc), we should introduce a single new structure with combines flow with thermodynamics. structure ThermodynamicCauchyFlow (d : ℕ) extends CauchyFlow d where
entropy : ScalarField d
enthalpy : ScalarField d
-- perhaps also
temperature : ScalarField d
heatFlux : VectorField dWith this, we can basically describe all fluid flow situations. |
|
It is unclear why something like |
|
I also think something like |
|
yes exactly, you get it from the stress: In my idea, FluidFlow is meant to be the minimal kinematic/mass-transport object, not the full dynamic fluid model. Pressure is not needed for continuity, incompressibility, material derivatives, or kinetic quantities. Once we move to momentum balance, I think the more invariant field is the Cauchy stress tensor; pressure then appears through stress laws, e.g. inviscid stress σ = -p I or Newtonian stress σ = -p I + τ. |
|
How does viscosity come into this all? |
|
Viscosity is just another form of stress in the Cauchy version. σ = -p I + viscousStressThe total stress is |
|
Ok great! This looks good then. I wonder if FluidKinematics and FluidDynamics would be better names, but I’m also happy with what you have callled them. Would you be able to restructure the API around these? |
|
Great! I will get right onto it and refactor... |
|
Yeah - ok let’s keep names as they are |
|
okay, check out the new structure and let me know what you think: Main changes
Side changes
|
jstoobysmith
left a comment
There was a problem hiding this comment.
Sorry for my delay here - have been travelling.
|
@FloWsnr Regarding this, if you don't think you have time to address the reviews, we could put it in the new PhyslibAlpha directory for now. See: https://leanprover.zulipchat.com/#narrow/channel/479953-Physlib/topic/PhyslibAlpha/with/601570535 |
|
Hey, I'm sorry, had some travel & new job. Still plan to do the final fixes asap. I'll try this weekend! |
|
I think I addressed all comments now except for the larger rename / restructure into subdirs
Not sure if this split up the code too much, but if you want I can quickly do that |
|
@FloWsnr Sorry I think I missed this comment. I think the larger restructure would be good here, as it will make it easier to see what is related to what structure. |
|
@jstoobysmith No problem! I just attempted the restructure. Let me know what you think! |
|
@jstoobysmith Sorry for the long cycles. I applied your comments. |
|
Would it be possible to include the motivation behind the different data structures within the files: e.g. for |
|
@jstoobysmith Added documentation and removed the LHS stuff |
|
I think we are getting there :). Would you mind fixing the merge-conflicts. |
Co-authored-by: Claude Opus 4.8 <no-reply+claude-opus-4-8@anthropic.com>
Co-authored-by: Claude Opus 4.8 <no-reply+claude-opus-4-8@anthropic.com>
2d7a4bf to
be4b145
Compare
jstoobysmith
left a comment
There was a problem hiding this comment.
Approved - will merge shortly. Thanks for iterating with me on this.
Summary
This PR extends the fluid dynamics API with reusable foundations for incompressibility, continuity, momentum balance, Euler flow, and Bernoulli flow based. It copies PR #949 ideas refactored based on the structure agreed upon in #1112 .
Changes
Structure
I realized that we previously placed general equations into the Navier-Stokes namespace which instead should be general FluidDynamics, since they will be reused by systems other than Navier-Stokes.
NavierStokes/into reusableFluidDynamics/Continuity.lean.FluidDynamics/Momentum.lean.Additions
FluidDynamics/Incompressible.lean. This can be reused in Navier-Stokes, Euler and other fluid systems.Notes
This branch intentionally keeps the new fluid definitions dimension-generic and avoids recreating the older
IdealFluidwrapper from PR #949.