-
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 6 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,138 @@ | ||
| /- | ||
| 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. | ||
| - `eulerForceDensity` : The pressure-gradient and body-force density in Euler momentum balance. | ||
| - `Euler` : Classical continuity and conservative Euler momentum together. | ||
| - `euler_iff_convective_euler` : Equivalence of the conservative and convective forms when the | ||
| fields are differentiable. | ||
|
|
||
| ## iii. Table of contents | ||
|
|
||
| - A. Euler data | ||
| - B. Euler force density | ||
| - C. Euler equation | ||
| - 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 force density | ||
|
|
||
| -/ | ||
|
|
||
| /-- The force density in Euler momentum balance, `-grad p + rho f`. -/ | ||
| noncomputable def eulerForceDensity (d : ℕ) (data : FluidInEulerBalance d) : VectorField d := | ||
| fun t x => -(∇ (data.pressure t) x) + data.rho t x • data.bodyForce t x | ||
|
|
||
| /-! | ||
|
|
||
| ## C. Euler equation | ||
|
|
||
| -/ | ||
|
|
||
| /-- The conservative Euler equations: classical continuity and conservative momentum balance. -/ | ||
| def Euler (d : ℕ) (data : FluidInEulerBalance d) : Prop := | ||
| ClassicalContinuityEquation d data.toFluidState ∧ | ||
| ∀ t x, conservativeMomentumLHS d data.toFluidState t x = eulerForceDensity d data t x | ||
|
|
||
| /-! | ||
|
|
||
| ## 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_convective_euler | ||
|
FloWsnr marked this conversation as resolved.
Outdated
|
||
| (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 ↔ | ||
| ClassicalContinuityEquation d data.toFluidState ∧ | ||
| ∀ t x, convectiveMomentumLHS d data.toFluidState t x = eulerForceDensity d data t x := 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 := | ||
| ∀ 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 := | ||
| ∀ 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /- | ||
| 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.FluidState | ||
| public import Physlib.SpaceAndTime.Space.Derivatives.Div | ||
| public import Physlib.SpaceAndTime.Time.Derivatives | ||
| /-! | ||
|
|
||
| # Incompressible fluid flows | ||
|
|
||
| ## i. Overview | ||
|
|
||
| This module defines general incompressibility predicates for fluid flows. These predicates are | ||
| not tied to a particular equation of motion, so they can be reused later by incompressible | ||
| Navier-Stokes, incompressible Euler, and Bernoulli-style developments. | ||
|
|
||
| ## ii. Key results | ||
|
|
||
| - `incompressibilityResidual` : The divergence of the velocity field. | ||
| - `ClassicalIncompressible` : Incompressibility guarded by velocity differentiability. | ||
| - `SmoothIncompressible` : Incompressibility with globally differentiable velocity. | ||
| - `SmoothIncompressible.toClassical` : Smooth incompressibility implies classical | ||
| incompressibility. | ||
| - `DensityTimeIndependent` : A fluid flow whose density has zero time derivative. | ||
|
|
||
| ## iii. Table of contents | ||
|
|
||
| - A. Incompressibility predicates | ||
|
|
||
| ## iv. References | ||
|
|
||
| -/ | ||
|
|
||
| @[expose] public section | ||
|
|
||
| open Space | ||
| open Time | ||
|
|
||
| namespace FluidDynamics | ||
|
|
||
| /-! | ||
|
|
||
| ## A. Incompressibility predicates | ||
|
|
||
| -/ | ||
|
|
||
| /-- The incompressibility residual, given by the divergence of the velocity field. -/ | ||
| noncomputable def incompressibilityResidual (d : ℕ) (fluid : FluidState d) : | ||
| Time → Space d → ℝ := | ||
| fun t x => (∇ ⬝ fluid.velocity t) x | ||
|
|
||
| /-- A classical incompressible flow has divergence-free velocity at points where the velocity | ||
| field is differentiable. -/ | ||
| def ClassicalIncompressible (d : ℕ) (fluid : FluidState d) : Prop := | ||
| ∀ t x, DifferentiableAt ℝ (fluid.velocity t) x → | ||
| incompressibilityResidual d fluid t x = 0 | ||
|
|
||
| /-- A smooth incompressible flow has globally differentiable velocity and vanishing | ||
| incompressibility residual everywhere. -/ | ||
| def SmoothIncompressible (d : ℕ) (fluid : FluidState d) : Prop := | ||
| (∀ t, Differentiable ℝ (fluid.velocity t)) ∧ | ||
| ∀ t x, incompressibilityResidual d fluid t x = 0 | ||
|
|
||
| /-- A smooth incompressible flow is classically incompressible. -/ | ||
| lemma SmoothIncompressible.toClassical (d : ℕ) (fluid : FluidState d) : | ||
| SmoothIncompressible d fluid → ClassicalIncompressible d fluid := by | ||
| intro hSmooth t x _ | ||
| simpa [incompressibilityResidual] using hSmooth.2 t x | ||
|
|
||
| /-- A fluid flow has time-independent density when the density has zero time derivative at | ||
| each spatial point. -/ | ||
| def DensityTimeIndependent (d : ℕ) (fluid : FluidState d) : Prop := | ||
| ∀ t x, ∂ₜ (fluid.rho · x) t = 0 | ||
|
|
||
| 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