import NavierStokes.AxisymmetricFields import Mathlib.Tactic.Ring /-! # Cartesian Navier--Stokes residual in regular axisymmetric coordinates Every derivative below is an ordinary Fréchet derivative. The coordinate is `s=(x₀²+x₁²)/2`, so none of the formulas divide by the cylindrical radius. -/ noncomputable section namespace NavierStokes.AxisymmetricResidual open ProblemStatement AxisymmetricFields open scoped BigOperators ContDiff def pack (a b c : ℝ) : Space := a • coordinateVector 0 + b • coordinateVector 1 + c • coordinateVector 2 @[simp] theorem pack_zero (a b c : ℝ) : pack a b c 0 = a := by simp [pack, coordinateVector] @[simp] theorem pack_one (a b c : ℝ) : pack a b c 1 = b := by simp [pack, coordinateVector] @[simp] theorem pack_two (a b c : ℝ) : pack a b c 2 = c := by simp [pack, coordinateVector] def packDerivative {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] (a b c : E →L[ℝ] ℝ) : E →L[ℝ] Space := a.smulRight (coordinateVector 0) + b.smulRight (coordinateVector 1) + c.smulRight (coordinateVector 2) @[simp] theorem packDerivative_apply {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] (a b c : E →L[ℝ] ℝ) (v : E) : packDerivative a b c v = pack (a v) (b v) (c v) := rfl theorem hasFDerivAt_pack {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {a b c : E → ℝ} {da db dc : E →L[ℝ] ℝ} {x : E} (ha : HasFDerivAt a da x) (hb : HasFDerivAt b db x) (hc : HasFDerivAt c dc x) : HasFDerivAt (fun y => pack (a y) (b y) (c y)) (packDerivative da db dc) x := ((ha.smul_const _).add (hb.smul_const _)).add (hc.smul_const _) theorem fderiv_pack_apply {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {a b c : E → ℝ} {x : E} (ha : DifferentiableAt ℝ a x) (hb : DifferentiableAt ℝ b x) (hc : DifferentiableAt ℝ c x) (v : E) : fderiv ℝ (fun y => pack (a y) (b y) (c y)) x v = pack (fderiv ℝ a x v) (fderiv ℝ b x v) (fderiv ℝ c x v) := by rw [(hasFDerivAt_pack ha.hasFDerivAt hb.hasFDerivAt hc.hasFDerivAt).fderiv] rfl def direction (g : Space → ℝ) (i : Fin 3) (x : Space) : ℝ := fderiv ℝ g x (coordinateVector i) def scalarLaplacian (g : Space → ℝ) (x : Space) : ℝ := ∑ i : Fin 3, direction (fun y => direction g i y) i x def vectorLaplacian (g : Space → Space) (x : Space) : Space := ∑ i : Fin 3, fderiv ℝ (fun y => fderiv ℝ g y (coordinateVector i)) x (coordinateVector i) theorem direction_add {a b : Space → ℝ} (ha : Differentiable ℝ a) (hb : Differentiable ℝ b) (i : Fin 3) (x : Space) : direction (fun y => a y + b y) i x = direction a i x + direction b i x := by unfold direction rw [fderiv_fun_add (ha x) (hb x)] rfl theorem direction_neg (a : Space → ℝ) (i : Fin 3) (x : Space) : direction (fun y => -a y) i x = -direction a i x := by simp [direction] theorem scalarLaplacian_neg (a : Space → ℝ) (x : Space) : scalarLaplacian (fun y => -a y) x = -scalarLaplacian a x := by simp only [scalarLaplacian, direction_neg, Finset.sum_neg_distrib] def lift (G : Profile) (t : ℝ) (x : Space) : ℝ := G (profilePoint t x) /-- Joint differentiability is needed only along the spatial slice being evaluated. -/ def SliceDifferentiable (G : Profile) (t : ℝ) : Prop := ∀ x : Space, DifferentiableAt ℝ G (profilePoint t x) /-- No smooth extension across the singular time is required by this hypothesis. -/ def SliceC2 (G : Profile) (t : ℝ) : Prop := ∀ x : Space, ContDiffAt ℝ 2 G (profilePoint t x) theorem SliceC2.differentiable {G : Profile} {t : ℝ} (hG : SliceC2 G t) : SliceDifferentiable G t := fun x => (hG x).differentiableAt (by norm_num) def partialT (G : Profile) (p : ProfilePoint) : ℝ := fderiv ℝ G p (1, (0, 0)) def laplaceScalar (G : Profile) (p : ProfilePoint) : ℝ := 2 * p.2.1 * partialS (partialS G) p + 2 * partialS G p + partialZ (partialZ G) p def laplaceWeighted (G : Profile) (p : ProfilePoint) : ℝ := 2 * p.2.1 * partialS (partialS G) p + 4 * partialS G p + partialZ (partialZ G) p def componentX (B F : Profile) (t : ℝ) (x : Space) : ℝ := -(x 0 * lift B t x + x 1 * lift F t x) def componentY (B F : Profile) (t : ℝ) (x : Space) : ℝ := x 0 * lift F t x - x 1 * lift B t x /-- Convention: radial velocity `-r B`, angular velocity `r F`, axial velocity `U`. -/ def velocity (B F U : Profile) : VelocityField := fun w => pack (componentX B F w.1 w.2) (componentY B F w.1 w.2) (lift U w.1 w.2) def pressure (P : Profile) : PressureField := fun w => lift P w.1 w.2 def velocityJacobian (B F U : Profile) (t : ℝ) (x : Space) : Space →L[ℝ] Space := packDerivative (-(x 0 • profileDerivative B t x + lift B t x • projection 0 + (x 1 • profileDerivative F t x + lift F t x • projection 1))) ((x 0 • profileDerivative F t x + lift F t x • projection 0) - (x 1 • profileDerivative B t x + lift B t x • projection 1)) (profileDerivative U t x) def advectionRadial (B F U : Profile) (p : ProfilePoint) : ℝ := (B p) ^ 2 - (F p) ^ 2 + 2 * p.2.1 * B p * partialS B p - U p * partialZ B p def advectionAngular (B F U : Profile) (p : ProfilePoint) : ℝ := 2 * B p * F p + 2 * p.2.1 * B p * partialS F p - U p * partialZ F p def advectionAxial (B U : Profile) (p : ProfilePoint) : ℝ := -2 * p.2.1 * B p * partialS U p + U p * partialZ U p def timeProfileJacobian : ℝ →L[ℝ] ProfilePoint := (ContinuousLinearMap.id ℝ ℝ).prod (0 : ℝ →L[ℝ] ℝ × ℝ) def timeProfileDerivative (G : Profile) (p : ProfilePoint) : ℝ →L[ℝ] ℝ := (fderiv ℝ G p).comp timeProfileJacobian @[simp] theorem timeProfileDerivative_one (G : Profile) (p : ProfilePoint) : timeProfileDerivative G p 1 = partialT G p := rfl def residualRadial (B F U P : Profile) (p : ProfilePoint) : ℝ := -partialT B p + advectionRadial B F U p + laplaceWeighted B p + partialS P p def residualAngular (B F U : Profile) (p : ProfilePoint) : ℝ := -partialT F p + advectionAngular B F U p + laplaceWeighted F p def residualAxial (B U P : Profile) (p : ProfilePoint) : ℝ := partialT U p + advectionAxial B U p - laplaceScalar U p + partialZ P p def fromPotentialB (H : Profile) (p : ProfilePoint) : ℝ := partialZ H p / 2 def fromPotentialF (K : Profile) (p : ProfilePoint) : ℝ := -partialS K p def fromPotentialU (H : Profile) (p : ProfilePoint) : ℝ := H p + p.2.1 * partialS H p /-- Connect the residual convention to the already constructed curl field. -/ theorem velocity_from_potential_at (H K : Profile) (t : ℝ) (x : Space) (hH : DifferentiableAt ℝ H (profilePoint t x)) (hK : DifferentiableAt ℝ K (profilePoint t x)) : AxisymmetricFields.velocity H K (t, x) = velocity (fromPotentialB H) (fromPotentialF K) (fromPotentialU H) (t, x) := by ext i fin_cases i · change AxisymmetricFields.velocity H K (t, x) 0 = _ rw [AxisymmetricFields.velocity_zero H K t x hH hK] simp [velocity, componentX, lift, fromPotentialB, fromPotentialF] ring · change AxisymmetricFields.velocity H K (t, x) 1 = _ rw [AxisymmetricFields.velocity_one H K t x hH hK] simp [velocity, componentY, lift, fromPotentialB, fromPotentialF] ring · change AxisymmetricFields.velocity H K (t, x) 2 = _ rw [AxisymmetricFields.velocity_two H K t x hH hK] simp [velocity, lift, fromPotentialU, profilePoint] end NavierStokes.AxisymmetricResidual