-
Notifications
You must be signed in to change notification settings - Fork 134
feat(FluidDynamics): Adding more fluid dynamics - continuation of PR #949 and #1112 , #1125
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
e6e290b
ed9ebc5
c2c135c
8696eec
2bebbc2
58b969a
d59db4c
7b35664
4119cf2
94cd05c
e0890ac
1324844
8f00c5e
9b6eb71
1df0fbf
5ab5fc4
99098ec
e5dcd53
ced67cb
e151a98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| /- | ||
| Copyright (c) 2026 Florian Wiesner. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Florian Wiesner, Michał Mogielnicki | ||
| -/ | ||
| module | ||
|
|
||
| public import Physlib.FluidDynamics.Momentum | ||
| public import Physlib.SpaceAndTime.Space.Derivatives.Grad | ||
| /-! | ||
|
|
||
| # Euler equation for fluid flows | ||
|
|
||
| ## i. Overview | ||
|
|
||
| This module defines the Euler momentum equation for inviscid fluid flow. The pressure gradient | ||
| and body force terms are kept explicit, while the conservative and convective left-hand sides | ||
| reuse the corresponding Navier-Stokes balance-law definitions. | ||
|
|
||
| ## ii. Key results | ||
|
|
||
| - `FluidInEulerBalance` : A fluid state with pressure and body force. | ||
| - `eulerMomentumRHS` : The pressure-gradient and body-force side of Euler momentum balance. | ||
| - `EulerMomentumEquation` : Euler momentum balance in conservative form. | ||
| - `ConvectiveEulerMomentumEquation` : Euler momentum balance in convective form. | ||
| - `Euler` : Classical continuity and conservative Euler momentum together. | ||
| - `ConvectiveEuler` : Classical continuity and convective Euler momentum together. | ||
| - `Euler_iff_ConvectiveEuler` : Equivalence of the conservative and convective forms when the | ||
| fields are differentiable. | ||
|
|
||
| ## iii. Table of contents | ||
|
|
||
| - A. Euler data | ||
| - B. Euler momentum equations | ||
| - C. Full Euler forms | ||
| - D. Equivalence of conservative and convective Euler forms | ||
|
|
||
| ## iv. References | ||
|
|
||
| -/ | ||
|
|
||
| @[expose] public section | ||
|
|
||
| open Space | ||
| open Time | ||
|
|
||
| namespace FluidDynamics | ||
|
|
||
| /-! | ||
|
|
||
| ## A. Euler data | ||
|
|
||
| -/ | ||
|
|
||
| /-- The fields needed for Euler momentum balance: fluid state, pressure, and body force. -/ | ||
| structure FluidInEulerBalance (d : ℕ) extends FluidState d where | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is ok for now - but I think we should have a think about how we name all of these things
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea would be to have some key data structures
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I am not happy with the naming of all the structures, except
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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would splitting based on kinematics vs dynamics work? Which of these quantities are actually derived and which define the system? |
||
| /-- The pressure field. -/ | ||
| pressure : ScalarField d | ||
| /-- The body-force field per unit mass. -/ | ||
| bodyForce : BodyForce d | ||
|
|
||
| /-! | ||
|
|
||
| ## B. Euler momentum equations | ||
|
|
||
| -/ | ||
|
|
||
| /-- The right-hand side of Euler momentum balance, `-grad p + rho f`. -/ | ||
| noncomputable def eulerMomentumRHS (d : ℕ) (data : FluidInEulerBalance d) : VectorField d := | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I now called it |
||
| fun t x => -(∇ (data.pressure t) x) + data.rho t x • data.bodyForce t x | ||
|
|
||
| /-- Euler momentum balance in conservative form, | ||
| `partial_t (rho u) + matrixDiv (rho u ⊗ u) = -grad p + rho f`. -/ | ||
| def EulerMomentumEquation (d : ℕ) (data : FluidInEulerBalance d) : Prop := | ||
| ∀ t x, conservativeMomentumLHS d data.toFluidState t x = | ||
| eulerMomentumRHS d data t x | ||
|
|
||
| /-- Euler momentum balance in convective form, | ||
| `rho (partial_t u + (u · grad)u) = -grad p + rho f`. -/ | ||
| def ConvectiveEulerMomentumEquation (d : ℕ) (data : FluidInEulerBalance d) : Prop := | ||
| ∀ t x, convectiveMomentumLHS d data.toFluidState t x = | ||
| eulerMomentumRHS d data t x | ||
|
jstoobysmith marked this conversation as resolved.
Outdated
|
||
|
|
||
| /-! | ||
|
|
||
| ## C. Full Euler forms | ||
|
|
||
| -/ | ||
|
|
||
| /-- The conservative Euler equations: classical continuity and conservative momentum balance. -/ | ||
| def Euler (d : ℕ) (data : FluidInEulerBalance d) : Prop := | ||
| ClassicalContinuityEquation d data.toFluidState ∧ | ||
| EulerMomentumEquation d data | ||
|
|
||
| /-- The convective Euler equations: classical continuity and convective momentum balance. -/ | ||
| def ConvectiveEuler (d : ℕ) (data : FluidInEulerBalance d) : Prop := | ||
|
jstoobysmith marked this conversation as resolved.
Outdated
|
||
| ClassicalContinuityEquation d data.toFluidState ∧ | ||
| ConvectiveEulerMomentumEquation d data | ||
|
|
||
| /-! | ||
|
|
||
| ## D. Equivalence of conservative and convective Euler forms | ||
|
|
||
| -/ | ||
|
|
||
| /-- The conservative and convective Euler forms are equivalent when the fields are | ||
| differentiable enough for the product rules. -/ | ||
| theorem Euler_iff_ConvectiveEuler | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be e.g.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. Btw, is there a way to bake these rules into the linter since I keep making the same mistake?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 |
||
| (d : ℕ) (data : FluidInEulerBalance d) | ||
| (hRhoTime : ∀ t x, DifferentiableAt ℝ (data.rho · x) t) | ||
| (hVelocityTime : ∀ t x, DifferentiableAt ℝ (data.velocity · x) t) | ||
| (hMomentumDensity : ∀ t, | ||
| Differentiable ℝ (momentumDensity d data.toFluidState t)) | ||
| (hVelocitySpace : ∀ t, Differentiable ℝ (data.velocity t)) : | ||
| Euler d data ↔ ConvectiveEuler d data := by | ||
| constructor | ||
| · intro hConservative | ||
| refine ⟨hConservative.1, ?_⟩ | ||
| intro t x | ||
| have hMassFluxSpace : | ||
| DifferentiableAt ℝ (fun x' => data.rho t x' • data.velocity t x') x := by | ||
| simpa [momentumDensity] using (hMomentumDensity t).differentiableAt | ||
| have hResidual : continuityResidual d data.toFluidState t x = 0 := by | ||
| simpa [continuityResidual] using | ||
| hConservative.1 t x (by simpa using hRhoTime t x) hMassFluxSpace | ||
| have hLhs := | ||
| conservativeMomentumLHS_eq_convectiveMomentumLHS_add_continuityResidual_smul | ||
| d data.toFluidState t x (hRhoTime t x) (hVelocityTime t x) | ||
| (hMomentumDensity t) (hVelocitySpace t) | ||
| have hLhs' : | ||
| conservativeMomentumLHS d data.toFluidState t x = | ||
| convectiveMomentumLHS d data.toFluidState t x := by | ||
| rw [hLhs, hResidual, zero_smul, add_zero] | ||
| rw [← hLhs'] | ||
| exact hConservative.2 t x | ||
| · intro hConvective | ||
| refine ⟨hConvective.1, ?_⟩ | ||
| intro t x | ||
| have hMassFluxSpace : | ||
| DifferentiableAt ℝ (fun x' => data.rho t x' • data.velocity t x') x := by | ||
| simpa [momentumDensity] using (hMomentumDensity t).differentiableAt | ||
| have hResidual : continuityResidual d data.toFluidState t x = 0 := by | ||
| simpa [continuityResidual] using | ||
| hConvective.1 t x (by simpa using hRhoTime t x) hMassFluxSpace | ||
| have hLhs := | ||
| conservativeMomentumLHS_eq_convectiveMomentumLHS_add_continuityResidual_smul | ||
| d data.toFluidState t x (hRhoTime t x) (hVelocityTime t x) | ||
| (hMomentumDensity t) (hVelocitySpace t) | ||
| have hLhs' : | ||
| conservativeMomentumLHS d data.toFluidState t x = | ||
| convectiveMomentumLHS d data.toFluidState t x := by | ||
| rw [hLhs, hResidual, zero_smul, add_zero] | ||
| rw [hLhs'] | ||
| exact hConvective.2 t x | ||
|
|
||
| end FluidDynamics | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| /- | ||
| Copyright (c) 2026 Florian Wiesner. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Florian Wiesner, Michał Mogielnicki | ||
| -/ | ||
| module | ||
|
|
||
| public import Physlib.FluidDynamics.Euler.Basic | ||
| /-! | ||
|
|
||
| # Bernoulli theory for Euler flows | ||
|
|
||
| ## i. Overview | ||
|
|
||
| This module is reserved for Bernoulli definitions and results derived from Euler-flow | ||
| assumptions. The intended development includes the Bernoulli function associated with | ||
| velocity, enthalpy, and an external potential, together with assumptions under which it is | ||
| conserved. | ||
|
|
||
| ## ii. Key results | ||
|
|
||
| - `FluidInBernoulliFlow` : Euler-flow data with enthalpy and potential fields. | ||
| - `HasConservativeBodyForce` : Predicate encoding the convention `bodyForce = -grad Phi`. | ||
| - `isSteady` : Predicate saying the velocity field has no time dependence. | ||
| - `materialDerivative` : Material derivative of a scalar field along a fluid velocity field. | ||
| - `isIsentropic` : Predicate saying the entropy is materially conserved. | ||
| - `specificKineticEnergy` : The specific kinetic energy `|u|^2 / 2`. | ||
| - `bernoulliFunction` : The Bernoulli function `|u|^2 / 2 + h + Phi`. | ||
| - `LocalBernoulliLaw` : Vanishing spatial gradient of the Bernoulli function. | ||
| - `BernoulliLaw` : Spatial constancy of the Bernoulli function at each time. | ||
|
|
||
| ## iii. Table of contents | ||
|
|
||
| - A. Bernoulli data | ||
| - B. Conservative-force convention | ||
| - C. Flow-state predicates | ||
| - D. Bernoulli function | ||
| - E. Bernoulli-law predicates | ||
|
|
||
| ## iv. References | ||
|
|
||
| -/ | ||
|
|
||
| @[expose] public section | ||
|
|
||
| open scoped InnerProductSpace | ||
| open Space | ||
| open Time | ||
|
|
||
| namespace FluidDynamics | ||
|
|
||
| /-! | ||
|
|
||
| ## A. Bernoulli data | ||
|
|
||
| -/ | ||
|
|
||
| /-- The fields needed for Bernoulli theory: Euler data, entropy, enthalpy, and an external | ||
| potential. | ||
|
|
||
| The potential is the potential energy per unit mass. In the conservative-force convention used | ||
| below, it satisfies `bodyForce = -grad Phi`. This relation is not imposed by the data structure. | ||
| -/ | ||
| structure FluidInBernoulliFlow (d : ℕ) extends FluidInEulerBalance d where | ||
| /-- The specific entropy field. -/ | ||
| entropy : ScalarField d | ||
| /-- The specific enthalpy field. -/ | ||
| enthalpy : ScalarField d | ||
| /-- The external potential field. -/ | ||
| potential : Space d → ℝ | ||
|
|
||
| /-! | ||
|
|
||
| ## B. Conservative-force convention | ||
|
|
||
| -/ | ||
|
|
||
| /-- A Bernoulli flow has conservative body force when its body force is minus the gradient of | ||
| the potential energy per unit mass. -/ | ||
| def HasConservativeBodyForce (d : ℕ) (data : FluidInBernoulliFlow d) : Prop := | ||
| ∀ t x, data.bodyForce t x = -(∇ data.potential x) | ||
|
|
||
| /-! | ||
|
|
||
| ## C. Flow-state predicates | ||
|
|
||
| -/ | ||
|
|
||
| /-- A fluid state is steady when the velocity has zero time derivative everywhere. -/ | ||
| def isSteady (d : ℕ) (fluid : FluidState d) : Prop := | ||
|
FloWsnr marked this conversation as resolved.
Outdated
|
||
| ∀ t x, ∂ₜ (fluid.velocity · x) t = 0 | ||
|
|
||
| /-- The material derivative `D_t f = partial_t f + u · grad f` of a scalar field. -/ | ||
| noncomputable def materialDerivative (d : ℕ) (fluid : FluidState d) | ||
| (field : ScalarField d) : ScalarField d := | ||
| fun t x => ∂ₜ (field · x) t + ⟪fluid.velocity t x, ∇ (field t) x⟫_ℝ | ||
|
|
||
| /-- A Bernoulli flow is isentropic when the entropy is materially conserved. -/ | ||
| def isIsentropic (d : ℕ) (data : FluidInBernoulliFlow d) : Prop := | ||
|
FloWsnr marked this conversation as resolved.
Outdated
|
||
| ∀ t x, materialDerivative d data.toFluidState data.entropy t x = 0 | ||
|
|
||
| /-! | ||
|
|
||
| ## D. Bernoulli function | ||
|
|
||
| -/ | ||
|
|
||
| /-- The specific kinetic energy `|u|^2 / 2` of a fluid state. -/ | ||
| noncomputable def specificKineticEnergy (d : ℕ) (fluid : FluidState d) : ScalarField d := | ||
| fun t x => (1 / 2 : ℝ) * ⟪fluid.velocity t x, fluid.velocity t x⟫_ℝ | ||
|
|
||
| /-- The Bernoulli function `|u|^2 / 2 + h + Phi`. -/ | ||
| noncomputable def bernoulliFunction (d : ℕ) (data : FluidInBernoulliFlow d) : ScalarField d := | ||
| fun t x => specificKineticEnergy d data.toFluidState t x + data.enthalpy t x + | ||
| data.potential x | ||
|
|
||
| /-! | ||
|
|
||
| ## E. Bernoulli-law predicates | ||
|
|
||
| -/ | ||
|
|
||
| /-- A local Bernoulli law: the Bernoulli function has zero spatial gradient. -/ | ||
| def LocalBernoulliLaw (d : ℕ) (data : FluidInBernoulliFlow d) : Prop := | ||
| ∀ t x, (∇ (bernoulliFunction d data t)) x = 0 | ||
|
|
||
| /-- A global Bernoulli law: the Bernoulli function is spatially constant at each time. -/ | ||
| def BernoulliLaw (d : ℕ) (data : FluidInBernoulliFlow d) : Prop := | ||
| ∀ t x y, bernoulliFunction d data t x = bernoulliFunction d data t y | ||
|
|
||
| end FluidDynamics | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would think about wether it makes sense to have folders