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 6 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 |
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.