-
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
Open
FloWsnr
wants to merge
20
commits into
leanprover-community:master
Choose a base branch
from
FloWsnr:feat/fluid_dynamics_2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e6e290b
feat(FluidDynamics): add incompressibility predicates
FloWsnr ed9ebc5
refactor(FluidDynamics): extract shared continuity and momentum
FloWsnr c2c135c
feat(FluidDynamics): add Euler Bernoulli setup
FloWsnr 8696eec
feat(FluidDynamics): record Bernoulli force convention
FloWsnr 2bebbc2
refactor(FluidDynamics): inline Euler convective form
FloWsnr 58b969a
refactor(FluidDynamics): rename Euler predicates
FloWsnr d59db4c
refactor(FluidDynamics): introduce Cauchy flow data
FloWsnr 7b35664
refactor(FluidDynamics): rename fluid flow carrier
FloWsnr 4119cf2
refactor(FluidDynamics): add shared Cauchy momentum
FloWsnr 94cd05c
refactor(FluidDynamics): use Cauchy flows in Euler theory
FloWsnr e0890ac
refactor(FluidDynamics): express Navier-Stokes via Cauchy momentum
FloWsnr 1324844
refactor(FluidDynamics): clarify force and viscosity names
FloWsnr 8f00c5e
feat(FluidDynamics): relate inviscid stress to pressure gradient
FloWsnr 9b6eb71
refactor(FluidDynamics): move flow time-independence predicates
FloWsnr 1df0fbf
refactor(FluidDynamics): namespace flow-derived APIs
FloWsnr 5ab5fc4
refactor(FluidDynamics): address review naming and docs
FloWsnr 99098ec
refactor(FluidDynamics): move flow-derived scalar APIs
FloWsnr e5dcd53
refactor(FluidDynamics): rename flow core module
FloWsnr ced67cb
refactor(FluidDynamics): organize flow APIs by structure
FloWsnr e151a98
Merge remote-tracking branch 'upstream/master' into feat/fluid_dynami…
FloWsnr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| /- | ||
| Copyright (c) 2026 Florian Wiesner. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Florian Wiesner | ||
| -/ | ||
| module | ||
|
|
||
| public import Physlib.FluidDynamics.Momentum | ||
| /-! | ||
|
|
||
| # Cauchy momentum equations | ||
|
|
||
| ## i. Overview | ||
|
|
||
| This module defines the conservative and convective Cauchy momentum equations for a fluid flow | ||
| with stress and specific body-force fields. The stress tensor is left as an input field, so this | ||
| is the balance-law layer before specializing to a constitutive law, such as Euler or | ||
| Navier-Stokes. | ||
|
|
||
| ## ii. Key results | ||
|
|
||
| - `CauchyFlow.CauchyMomentumEquation` : Conservation of momentum using `Space.matrixDiv`. | ||
| - `CauchyFlow.ConvectiveCauchyMomentumEquation` : The Cauchy momentum equation in convective | ||
| form. | ||
| - `CauchyFlow.cauchy_momentum_iff_convective_cauchy_momentum` : Equivalence of the two Cauchy | ||
| momentum equations when continuity holds and the fields are differentiable. | ||
|
|
||
| ## iii. Table of contents | ||
|
|
||
| - A. Cauchy momentum equations | ||
| - B. Equivalence of conservative and convective Cauchy momentum | ||
|
|
||
| ## iv. References | ||
|
|
||
| -/ | ||
|
|
||
| @[expose] public section | ||
|
|
||
| open Space | ||
|
|
||
| namespace FluidDynamics | ||
|
|
||
| namespace CauchyFlow | ||
|
|
||
| /-! | ||
|
|
||
| ## A. Cauchy momentum equations | ||
|
|
||
| -/ | ||
|
|
||
| /-- Conservation of momentum in conservative matrix-divergence form. | ||
|
|
||
| The equation is | ||
|
|
||
| `partial_t (rho u) + matrixDiv (rho u ⊗ u) = matrixDiv sigma + rho f`. | ||
|
|
||
| Here `stress` is intentionally not yet specialized to a constitutive law. | ||
| -/ | ||
| def CauchyMomentumEquation (d : ℕ) (flow : CauchyFlow d) : Prop := | ||
| ∀ t x, | ||
| FluidFlow.conservativeMomentumLHS d flow.toFluidFlow t x = | ||
| matrixDiv d (flow.stress t) x + flow.rho t x • flow.specificBodyForce t x | ||
|
|
||
| /-- Conservation of momentum in convective form. | ||
|
|
||
| The equation is | ||
|
|
||
| `rho (partial_t u + (u · ∇)u) = matrixDiv sigma + rho f`. | ||
|
|
||
| Here `stress` is intentionally not yet specialized to a constitutive law. | ||
| -/ | ||
| def ConvectiveCauchyMomentumEquation (d : ℕ) (flow : CauchyFlow d) : Prop := | ||
| ∀ t x, | ||
| flow.rho t x • FluidFlow.materialAcceleration d flow.toFluidFlow t x = | ||
| matrixDiv d (flow.stress t) x + flow.rho t x • flow.specificBodyForce t x | ||
|
|
||
| /-! | ||
|
|
||
| ## B. Equivalence of conservative and convective Cauchy momentum | ||
|
|
||
| -/ | ||
|
|
||
| /-- The conservative and convective Cauchy momentum equations are equivalent when the classical | ||
| continuity equation holds. | ||
|
|
||
| The differentiability assumptions are exactly the product-rule assumptions used to rewrite | ||
| `partial_t (rho u)` and `matrixDiv (rho u ⊗ u)`. | ||
| -/ | ||
| theorem cauchy_momentum_iff_convective_cauchy_momentum | ||
| (d : ℕ) (flow : CauchyFlow d) | ||
| (hContinuity : FluidFlow.ClassicalContinuityEquation d flow.toFluidFlow) | ||
| (hRhoTime : ∀ t x, DifferentiableAt ℝ (flow.rho · x) t) | ||
| (hVelocityTime : ∀ t x, DifferentiableAt ℝ (flow.velocity · x) t) | ||
| (hMomentumDensity : ∀ t, Differentiable ℝ (FluidFlow.momentumDensity d flow.toFluidFlow t)) | ||
| (hVelocitySpace : ∀ t, Differentiable ℝ (flow.velocity t)) : | ||
| CauchyMomentumEquation d flow ↔ ConvectiveCauchyMomentumEquation d flow := by | ||
| constructor | ||
| · intro hConservative t x | ||
| have hMassFluxSpace : | ||
| DifferentiableAt ℝ (fun x' => flow.rho t x' • flow.velocity t x') x := by | ||
| simpa [FluidFlow.momentumDensity] using (hMomentumDensity t).differentiableAt | ||
| have hResidual : FluidFlow.continuityResidual d flow.toFluidFlow t x = 0 := by | ||
| simpa [FluidFlow.continuityResidual] using | ||
| hContinuity t x (by simpa using hRhoTime t x) hMassFluxSpace | ||
| have hLhs := | ||
| FluidFlow.conservativeMomentumLHS_eq_convectiveMomentumLHS_add_continuityResidual_smul | ||
| d flow.toFluidFlow t x (hRhoTime t x) (hVelocityTime t x) | ||
| (hMomentumDensity t) (hVelocitySpace t) | ||
| have hLhs' : | ||
| FluidFlow.conservativeMomentumLHS d flow.toFluidFlow t x = | ||
| FluidFlow.convectiveMomentumLHS d flow.toFluidFlow t x := by | ||
| rw [hLhs, hResidual, zero_smul, add_zero] | ||
| change FluidFlow.convectiveMomentumLHS d flow.toFluidFlow t x = | ||
| matrixDiv d (flow.stress t) x + flow.rho t x • flow.specificBodyForce t x | ||
| rw [← hLhs'] | ||
| exact hConservative t x | ||
| · intro hConvective t x | ||
| have hMassFluxSpace : | ||
| DifferentiableAt ℝ (fun x' => flow.rho t x' • flow.velocity t x') x := by | ||
| simpa [FluidFlow.momentumDensity] using (hMomentumDensity t).differentiableAt | ||
| have hResidual : FluidFlow.continuityResidual d flow.toFluidFlow t x = 0 := by | ||
| simpa [FluidFlow.continuityResidual] using | ||
| hContinuity t x (by simpa using hRhoTime t x) hMassFluxSpace | ||
| have hLhs := | ||
| FluidFlow.conservativeMomentumLHS_eq_convectiveMomentumLHS_add_continuityResidual_smul | ||
| d flow.toFluidFlow t x (hRhoTime t x) (hVelocityTime t x) | ||
| (hMomentumDensity t) (hVelocitySpace t) | ||
| have hLhs' : | ||
| FluidFlow.conservativeMomentumLHS d flow.toFluidFlow t x = | ||
| FluidFlow.convectiveMomentumLHS d flow.toFluidFlow t x := by | ||
| rw [hLhs, hResidual, zero_smul, add_zero] | ||
| change FluidFlow.conservativeMomentumLHS d flow.toFluidFlow t x = | ||
| matrixDiv d (flow.stress t) x + flow.rho t x • flow.specificBodyForce t x | ||
| rw [hLhs'] | ||
| exact hConvective t x | ||
|
|
||
| end CauchyFlow | ||
|
|
||
| end FluidDynamics | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
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. I would think about wether it makes sense to have folders |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| /- | ||
| 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.CauchyMomentum | ||
| public import Physlib.SpaceAndTime.Space.Derivatives.Grad | ||
| /-! | ||
|
|
||
| # Euler equation for fluid flows | ||
|
|
||
| ## i. Overview | ||
|
|
||
| This module defines the Euler equations for inviscid fluid flow as continuity, Cauchy momentum, | ||
| and an inviscid stress law. The pressure field appears through the constitutive relation for | ||
| the Cauchy stress tensor rather than as a field of the flow data. | ||
|
|
||
| ## ii. Key results | ||
|
|
||
| - `CauchyFlow.IsInviscid` : Predicate saying the Cauchy stress is the inviscid pressure stress. | ||
| - `CauchyFlow.matrixDiv_stress_eq_neg_grad_pressure_of_is_inviscid` : The inviscid stress | ||
| contributes the usual pressure-gradient force term. | ||
| - `Euler` : Classical continuity, Cauchy momentum, and inviscid stress together. | ||
| - `ConvectiveEuler` : Classical continuity, convective Cauchy momentum, and inviscid stress. | ||
| - `euler_iff_convective_euler` : Equivalence of the conservative and convective forms when the | ||
| fields are differentiable. | ||
|
|
||
| ## iii. Table of contents | ||
|
|
||
| - A. Inviscid stress law | ||
| - B. Euler equations | ||
| - C. Equivalence of conservative and convective Euler forms | ||
|
|
||
| ## iv. References | ||
|
|
||
| -/ | ||
|
|
||
| @[expose] public section | ||
|
|
||
| open Space | ||
|
|
||
| namespace FluidDynamics | ||
|
|
||
| namespace CauchyFlow | ||
|
|
||
| /-! | ||
|
|
||
| ## A. Inviscid stress law | ||
|
|
||
| -/ | ||
|
|
||
| /-- A Cauchy flow is inviscid with pressure `p` when its stress is `-p I`. -/ | ||
| def IsInviscid (d : ℕ) (flow : CauchyFlow d) (pressure : ScalarField d) : Prop := | ||
|
FloWsnr marked this conversation as resolved.
Outdated
|
||
| ∀ t x, flow.stress t x = (-(pressure t x)) • (1 : Matrix (Fin d) (Fin d) ℝ) | ||
|
|
||
| /-- The matrix divergence of the inviscid pressure stress `-p I` is `-grad p`. -/ | ||
| lemma matrixDiv_inviscid_pressure_stress (d : ℕ) (pressureAtTime : Space d → ℝ) : | ||
| matrixDiv d (fun x => (-(pressureAtTime x)) • (1 : Matrix (Fin d) (Fin d) ℝ)) = | ||
| -∇ pressureAtTime := by | ||
| ext x i | ||
| rw [matrixDiv_apply] | ||
| rw [Finset.sum_eq_single i] | ||
| · simp [grad, Space.deriv_eq] | ||
| · intro j _ hji | ||
| have hij : i ≠ j := fun h => hji h.symm | ||
| simp [hij] | ||
| · intro hi | ||
| simp at hi | ||
|
|
||
| /-- In an inviscid Cauchy flow, the stress-divergence force is the usual | ||
| negative pressure-gradient term. -/ | ||
| theorem matrixDiv_stress_eq_neg_grad_pressure_of_is_inviscid | ||
| (d : ℕ) (flow : CauchyFlow d) (pressure : ScalarField d) | ||
| (hInviscid : IsInviscid d flow pressure) : | ||
| ∀ t, matrixDiv d (flow.stress t) = -∇ (pressure t) := by | ||
| intro t | ||
| rw [show flow.stress t = | ||
| fun x => (-(pressure t x)) • (1 : Matrix (Fin d) (Fin d) ℝ) by | ||
| funext x | ||
| exact hInviscid t x] | ||
| exact matrixDiv_inviscid_pressure_stress d (pressure t) | ||
|
|
||
| end CauchyFlow | ||
|
|
||
| /-! | ||
|
|
||
| ## B. Euler equations | ||
|
|
||
| -/ | ||
|
|
||
| /-- The conservative Euler equations: continuity, Cauchy momentum, and inviscid stress. -/ | ||
| def Euler (d : ℕ) (flow : CauchyFlow d) (pressure : ScalarField d) : Prop := | ||
| FluidFlow.ClassicalContinuityEquation d flow.toFluidFlow ∧ | ||
| CauchyFlow.CauchyMomentumEquation d flow ∧ CauchyFlow.IsInviscid d flow pressure | ||
|
|
||
| /-- The convective Euler equations: continuity, convective Cauchy momentum, and inviscid | ||
| stress. -/ | ||
| def ConvectiveEuler (d : ℕ) (flow : CauchyFlow d) (pressure : ScalarField d) : Prop := | ||
| FluidFlow.ClassicalContinuityEquation d flow.toFluidFlow ∧ | ||
| CauchyFlow.ConvectiveCauchyMomentumEquation d flow ∧ CauchyFlow.IsInviscid d flow pressure | ||
|
|
||
| /-! | ||
|
|
||
| ## C. 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 : ℕ) (flow : CauchyFlow d) (pressure : ScalarField d) | ||
| (hRhoTime : ∀ t x, DifferentiableAt ℝ (flow.rho · x) t) | ||
| (hVelocityTime : ∀ t x, DifferentiableAt ℝ (flow.velocity · x) t) | ||
| (hMomentumDensity : ∀ t, | ||
| Differentiable ℝ (FluidFlow.momentumDensity d flow.toFluidFlow t)) | ||
| (hVelocitySpace : ∀ t, Differentiable ℝ (flow.velocity t)) : | ||
| Euler d flow pressure ↔ ConvectiveEuler d flow pressure := by | ||
| constructor | ||
| · intro hConservative | ||
| refine ⟨hConservative.1, ?_, hConservative.2.2⟩ | ||
| exact (CauchyFlow.cauchy_momentum_iff_convective_cauchy_momentum d flow hConservative.1 | ||
| hRhoTime hVelocityTime hMomentumDensity hVelocitySpace).mp hConservative.2.1 | ||
| · intro hConvective | ||
| refine ⟨hConvective.1, ?_, hConvective.2.2⟩ | ||
| exact (CauchyFlow.cauchy_momentum_iff_convective_cauchy_momentum d flow hConvective.1 | ||
| hRhoTime hVelocityTime hMomentumDensity hVelocitySpace).mpr hConvective.2.1 | ||
|
|
||
| end FluidDynamics | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.