feat(FluidDynamics): Adding more fluid dynamics - continuation of PR #949 and #1112 ,#1125
feat(FluidDynamics): Adding more fluid dynamics - continuation of PR #949 and #1112 ,#1125FloWsnr wants to merge 20 commits into
Conversation
|
|
||
| /-- The conservative and convective Euler forms are equivalent when the fields are | ||
| differentiable enough for the product rules. -/ | ||
| theorem Euler_iff_ConvectiveEuler |
There was a problem hiding this comment.
should be e.g. euler_iff_convectiveEuler
There was a problem hiding this comment.
done. Btw, is there a way to bake these rules into the linter since I keep making the same mistake?
There was a problem hiding this comment.
This should be possible. If you make a comment here about this, someone might pick it up as something to do: https://leanprover.zulipchat.com/#narrow/channel/479953-Physlib/topic/Infrastructure.20ideas/with/597860431
| -/ | ||
|
|
||
| /-- The fields needed for Euler momentum balance: fluid state, pressure, and body force. -/ | ||
| structure FluidInEulerBalance (d : ℕ) extends FluidState d where |
There was a problem hiding this comment.
This is ok for now - but I think we should have a think about how we name all of these things
There was a problem hiding this comment.
The idea would be to have some key data structures FluidState, FluidInEulerBalance, etc. with which we organize the folders around.
There was a problem hiding this comment.
Yes, I am not happy with the naming of all the structures, except FluidState which is fine.
I don't have a great idea tho.
Perhaps it's better to define a few overarching structures like
- FluidState
- ThermodynamicFluidState
which provide "all" parameters we might need. The functions (NavierStokes, Euler, Bernoulli) would then all use these even though some fields are not needed for this.
But again, not super convinced yet
There was a problem hiding this comment.
Would splitting based on kinematics vs dynamics work? Which of these quantities are actually derived and which define the system?
| -/ | ||
|
|
||
| /-- The right-hand side of Euler momentum balance, `-grad p + rho f`. -/ | ||
| noncomputable def eulerMomentumRHS (d : ℕ) (data : FluidInEulerBalance d) : VectorField d := |
There was a problem hiding this comment.
Is there a better name for this which gives across the physical meaning? If not, maybe we should not define it explicitly. Similarly with other definitions like this.
There was a problem hiding this comment.
I now called it eulerForceDensity which is accurate but not really great. We can also inline twice, for both Euler equations. It really depends on whether future lemma will be using this. I don't know...
| -/ | ||
|
|
||
| /-- The momentum density `rho u`. -/ | ||
| def momentumDensity (d : ℕ) (fluid : FluidState d) : MomentumDensityField d := |
There was a problem hiding this comment.
All these should be in the FluidState namespac
|
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.
There was a problem hiding this comment.
I would think about wether it makes sense to have folders
./CaucyFlow
./FluidState
./ThermodynamicFluid
|
@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! |
…cs_2 # Conflicts: # Physlib/FluidDynamics/FluidFlow/Momentum.lean
|
|
||
| /-- A smooth continuity equation satisfies the guarded classical continuity equation. -/ | ||
| lemma SmoothContinuityEquation.toClassical (d : ℕ) (fluid : FluidState d) : | ||
| lemma SmoothContinuityEquation.toClassical (d : ℕ) (fluid : FluidFlow d) : |
There was a problem hiding this comment.
this should be called something along the lines classicalContinuityEquation_of_smoothContinuityEquation.
| ∀ t x, incompressibilityResidual d fluid t x = 0 | ||
|
|
||
| /-- A smooth incompressible flow is classically incompressible. -/ | ||
| lemma SmoothIncompressible.toClassical (d : ℕ) (fluid : FluidFlow d) : |
There was a problem hiding this comment.
Similar here with the naming.
|
|
||
| /-- A fluid flow has time-independent density when the density has zero time derivative at | ||
| each spatial point. -/ | ||
| def DensityTimeIndependent (d : ℕ) (fluid : FluidFlow d) : Prop := | ||
| ∀ t x, ∂ₜ (fluid.rho · x) t = 0 | ||
|
|
||
| /-- A fluid flow has time-independent velocity when the velocity has zero time derivative at | ||
| each spatial point. -/ | ||
| def VelocityTimeIndependent (d : ℕ) (fluid : FluidFlow d) : Prop := | ||
| ∀ t x, ∂ₜ (fluid.velocity · x) t = 0 |
There was a problem hiding this comment.
Not sure how needed these will be, maybe we could just use e.g. ∀ t x, ∂ₜ (fluid.velocity · x) t = 0 explicitly.
|
|
||
| /-- The left-hand side of the conservative momentum equation. -/ | ||
| noncomputable def conservativeMomentumLHS (d : ℕ) (fluid : FluidState d) : VectorField d := | ||
| noncomputable def conservativeMomentumLHS (d : ℕ) (fluid : FluidFlow d) : VectorField d := |
There was a problem hiding this comment.
Still not sure about these definitions, if they only appear in a given lemma, then we should write it out explicitly in that lemma or prop.
There was a problem hiding this comment.
Would move to the CauchyFlow file.
| -/ | ||
|
|
||
| /-- The spatial velocity-gradient matrix, with entries `partial_j u_i`. -/ | ||
| noncomputable def velocityGradient (d : ℕ) (flow : FluidFlow d) : |
There was a problem hiding this comment.
This should be in FluidFlow, no need to redefine it here.
| `-p I + mu (grad u + grad u^T) + lambda (div u) I`. | ||
|
|
||
| The scalar fields are pressure, shear viscosity, and second viscosity. | ||
| -/ |
There was a problem hiding this comment.
Likewise, should be in FluidFlow
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.