import NavierStokes.CorrectionState import NavierStokes.LinearWaveResidual import NavierStokes.CorrectionStepCovariance /-! # Exact full residual and its increment The 166-page Navier–Stokes paper uses cylindrical transport with frame terms in §9.1, equation (9.2) and Lemma 9.2. This module supplies the addition laws for those differential operators and their exact expansion under an update. It assembles the velocity and pressure corrections of §9.3, equation (9.7), and separates the angular mean, nonconstant angular part and stored errors as in the residual decomposition of §9.2, equations (9.3)–(9.4). It keeps both old/new transport terms and the square of the increment. The angular covariance uses the full oscillation as in §8.1, equation (8.1). Its exact update gives the cross terms and square used in the split in §9.3, equation (9.13). -/ noncomputable section namespace NavierStokes.CorrectionStep open Set WeightedClasses MeanIncrementBounds open scoped ContDiff BigOperators variable {D : Type} [NormedAddCommGroup D] [NormedSpace ℝ D] /-! ## The full differential residual, before angular averaging -/ section FullCalculus open HarmonicCalculus LinearWaveResidual theorem angularGenerator_add (a b : ComplexVector) : angularGenerator (a + b) = angularGenerator a + angularGenerator b := by ext i fin_cases i <;> simp [angularGenerator] abel theorem transport_add_left (R : D → ℝ) (Vr Vθ Vz : D → D) (a b v : D → ComplexVector) (x : D) : transport R Vr Vθ Vz (a + b) v x = transport R Vr Vθ Vz a v x + transport R Vr Vθ Vz b v x := by ext i simp only [transport, Pi.add_apply] ring theorem transport_add_right (R : D → ℝ) (Vr Vθ Vz : D → D) (u a b : D → ComplexVector) {x : D} (ha : ∀ i, DifferentiableAt ℝ (fun y => a y i) x) (hb : ∀ i, DifferentiableAt ℝ (fun y => b y i) x) : transport R Vr Vθ Vz u (a + b) x = transport R Vr Vθ Vz u a x + transport R Vr Vθ Vz u b x := by ext i simp only [transport, Pi.add_apply, angularGenerator_add, along_add _ (ha i) (hb i)] ring theorem twiceAlong_add {U : Set D} (hU : IsOpen U) {V : D → D} (hV : ContDiffOn ℝ ∞ V U) {f g : D → ℂ} (hf : ContDiffOn ℝ ∞ f U) (hg : ContDiffOn ℝ ∞ g U) {x : D} (hx : x ∈ U) : along V (along V (f + g)) x = along V (along V f) x + along V (along V g) x := by have heq : EqOn (along V (f + g)) (along V f + along V g) U := by intro y hy exact along_add V ((hf.contDiffAt (hU.mem_nhds hy)).differentiableAt (by simp)) ((hg.contDiffAt (hU.mem_nhds hy)).differentiableAt (by simp)) rw [along_congr hU heq hx] exact along_add V (((contDiffOn_along hU hV hf).contDiffAt (hU.mem_nhds hx)).differentiableAt (by simp)) (((contDiffOn_along hU hV hg).contDiffAt (hU.mem_nhds hx)).differentiableAt (by simp)) theorem cylindricalLaplacian_add {U : Set D} (hU : IsOpen U) (R : D → ℝ) {Vr Vθ Vz : D → D} (hr : ContDiffOn ℝ ∞ Vr U) (hθ : ContDiffOn ℝ ∞ Vθ U) (hz : ContDiffOn ℝ ∞ Vz U) {f g : D → ℂ} (hf : ContDiffOn ℝ ∞ f U) (hg : ContDiffOn ℝ ∞ g U) {x : D} (hx : x ∈ U) : cylindricalLaplacian R Vr Vθ Vz (f + g) x = cylindricalLaplacian R Vr Vθ Vz f x + cylindricalLaplacian R Vr Vθ Vz g x := by have df := (hf.contDiffAt (hU.mem_nhds hx)).differentiableAt (by simp) have dg := (hg.contDiffAt (hU.mem_nhds hx)).differentiableAt (by simp) have hfirst : along Vr (f + g) x = along Vr f x + along Vr g x := along_add Vr df dg simp only [cylindricalLaplacian, twiceAlong_add hU hr hf hg hx, twiceAlong_add hU hθ hf hg hx, twiceAlong_add hU hz hf hg hx, hfirst, smul_add] abel theorem cylindricalVectorLaplacian_add {U : Set D} (hU : IsOpen U) (R : D → ℝ) {Vr Vθ Vz : D → D} (hr : ContDiffOn ℝ ∞ Vr U) (hθ : ContDiffOn ℝ ∞ Vθ U) (hz : ContDiffOn ℝ ∞ Vz U) {a b : D → ComplexVector} (ha : ∀ i, ContDiffOn ℝ ∞ (fun y => a y i) U) (hb : ∀ i, ContDiffOn ℝ ∞ (fun y => b y i) U) {x : D} (hx : x ∈ U) : cylindricalVectorLaplacian R Vr Vθ Vz (a + b) x = cylindricalVectorLaplacian R Vr Vθ Vz a x + cylindricalVectorLaplacian R Vr Vθ Vz b x := by have hL i : cylindricalLaplacian R Vr Vθ Vz (fun y => a y i + b y i) x = cylindricalLaplacian R Vr Vθ Vz (fun y => a y i) x + cylindricalLaplacian R Vr Vθ Vz (fun y => b y i) x := cylindricalLaplacian_add hU R hr hθ hz (ha i) (hb i) hx have hD i := along_add Vθ (((ha i).contDiffAt (hU.mem_nhds hx)).differentiableAt (by simp)) (((hb i).contDiffAt (hU.mem_nhds hx)).differentiableAt (by simp)) ext i fin_cases i <;> simp [cylindricalVectorLaplacian, angularGenerator, hL 0, hL 1, hL 2, hD 0, hD 1, Complex.real_smul] <;> ring theorem gradient_add (R : D → ℝ) (Vr Vθ Vz : D → D) {p q : D → ℂ} {x : D} (hp : DifferentiableAt ℝ p x) (hq : DifferentiableAt ℝ q x) : gradient R Vr Vθ Vz (p + q) x = gradient R Vr Vθ Vz p x + gradient R Vr Vθ Vz q x := by have hd (V : D → D) : along V (p + q) x = along V p x + along V q x := along_add V hp hq ext i fin_cases i <;> simp [gradient, hd, smul_add] theorem linearResidual_add {U : Set D} (hU : IsOpen U) (ε : ℝ) (R : D → ℝ) {Vr Vθ Vz : D → D} (Vt : D → D) (hr : ContDiffOn ℝ ∞ Vr U) (hθ : ContDiffOn ℝ ∞ Vθ U) (hz : ContDiffOn ℝ ∞ Vz U) (B a b : D → ComplexVector) (p q : D → ℂ) (ha : ∀ i, ContDiffOn ℝ ∞ (fun y => a y i) U) (hb : ∀ i, ContDiffOn ℝ ∞ (fun y => b y i) U) (hp : ContDiffOn ℝ ∞ p U) (hq : ContDiffOn ℝ ∞ q U) {x : D} (hx : x ∈ U) : linearResidual ε R Vr Vθ Vz Vt B (a + b) (p + q) x = linearResidual ε R Vr Vθ Vz Vt B a p x + linearResidual ε R Vr Vθ Vz Vt B b q x := by have da i := ((ha i).contDiffAt (hU.mem_nhds hx)).differentiableAt (by simp) have db i := ((hb i).contDiffAt (hU.mem_nhds hx)).differentiableAt (by simp) have dp := (hp.contDiffAt (hU.mem_nhds hx)).differentiableAt (by simp) have dq := (hq.contDiffAt (hU.mem_nhds hx)).differentiableAt (by simp) have hL := cylindricalVectorLaplacian_add hU R hr hθ hz ha hb hx ext i simp only [linearResidual, Pi.add_apply, along_add _ (da i) (db i), transport_add_left, transport_add_right R Vr Vθ Vz B a b da db, gradient_add R Vr Vθ Vz dp dq, hL] ring /-- Exact residual of a perturbation of a fixed base, before the virtual stress and the separately retained base residual are added. -/ noncomputable def nonlinearResidual (ε : ℝ) (R : D → ℝ) (Vr Vθ Vz Vt : D → D) (B a : D → ComplexVector) (p : D → ℂ) (x : D) : ComplexVector := linearResidual ε R Vr Vθ Vz Vt B a p x + transport R Vr Vθ Vz a a x theorem nonlinearResidual_add_sub {U : Set D} (hU : IsOpen U) (ε : ℝ) (R : D → ℝ) {Vr Vθ Vz : D → D} (Vt : D → D) (hr : ContDiffOn ℝ ∞ Vr U) (hθ : ContDiffOn ℝ ∞ Vθ U) (hz : ContDiffOn ℝ ∞ Vz U) (B a b : D → ComplexVector) (p q : D → ℂ) (ha : ∀ i, ContDiffOn ℝ ∞ (fun y => a y i) U) (hb : ∀ i, ContDiffOn ℝ ∞ (fun y => b y i) U) (hp : ContDiffOn ℝ ∞ p U) (hq : ContDiffOn ℝ ∞ q U) {x : D} (hx : x ∈ U) : nonlinearResidual ε R Vr Vθ Vz Vt B (a + b) (p + q) x - nonlinearResidual ε R Vr Vθ Vz Vt B a p x = linearResidual ε R Vr Vθ Vz Vt B b q x + transport R Vr Vθ Vz a b x + transport R Vr Vθ Vz b a x + transport R Vr Vθ Vz b b x := by have da i := ((ha i).contDiffAt (hU.mem_nhds hx)).differentiableAt (by simp) have db i := ((hb i).contDiffAt (hU.mem_nhds hx)).differentiableAt (by simp) rw [nonlinearResidual, linearResidual_add hU ε R Vt hr hθ hz B a b p q ha hb hp hq hx, transport_add_left, transport_add_right R Vr Vθ Vz a a b da db, transport_add_right R Vr Vθ Vz b a b da db, nonlinearResidual] abel end FullCalculus section FullFields open CorrectionState HarmonicCalculus noncomputable def radialDirection (c : Context D) (n : ℕ) (x : D × ℝ) : D × ℝ := (c.operators.eR + (c.operators.radialFrequency n * c.operators.radialProfile x.1) • c.operators.vR, 0) noncomputable def axialDirection (c : Context D) (n : ℕ) (_x : D × ℝ) : D × ℝ := (c.operators.epsilon n • c.operators.eZ, 0) noncomputable def angularDirection (_x : D × ℝ) : D × ℝ := (0, 1) noncomputable def timeDirection (c : Context D) (n : ℕ) (_x : D × ℝ) : D × ℝ := (c.operators.fastCoefficient n • c.operators.vT - c.operators.epsilon n • c.operators.eT, 0) noncomputable def complexBase (c : Context D) (n : ℕ) (x : D × ℝ) : ComplexVector := ![(c.base.radial n x.1 : ℂ), (c.base.angular n x.1 : ℂ), (c.base.axial n x.1 : ℂ)] noncomputable def complexPerturbation (u : State D) (n : ℕ) (x : D × ℝ) : ComplexVector := ![(u.mean.radial n x.1 + u.oscillation n x 0 : ℝ), (u.mean.angular n x.1 + u.oscillation n x 1 : ℝ), (u.mean.axial n x.1 + u.oscillation n x 2 : ℝ)] noncomputable def complexPressure (u : State D) (n : ℕ) (x : D × ℝ) : ℂ := (u.totalPressureIncrement n x : ℝ) noncomputable def virtualDivergence (c : Context D) (n : ℕ) (x : D × ℝ) : Fin 3 → ℝ := ![0, -(c.operators.radialDiv 2 c.virtualTheta n x.1), -(c.operators.radialDiv 1 c.virtualAxial n x.1)] /-- This field uses actual Fréchet derivatives. The base flat error is restored once, alongside the negative virtual-stress divergence. -/ noncomputable def fullResidual (c : Context D) (u : State D) : Oscillation D := fun n x i => (nonlinearResidual (c.operators.epsilon n) (fun y : D × ℝ => c.operators.radius y.1) (radialDirection c n) angularDirection (axialDirection c n) (timeDirection c n) (complexBase c n) (complexPerturbation u n) (complexPressure u n) x i).re + virtualDivergence c n x i + u.errors.base n x i noncomputable def fullGoodResidual (c : Context D) (u : State D) : Oscillation D := fullResidual c u - u.errors.total noncomputable def angularMeanVector (f : Oscillation D) : MeanVector D := fun n x i => angularAverage (fun k p => f k p i) n x noncomputable def angularNonconstant (f : Oscillation D) : Oscillation D := fun n x i => f n x i - angularMeanVector f n x.1 i noncomputable def fullGoodWaveResidual (c : Context D) (u : State D) : Oscillation D := angularNonconstant (fullGoodResidual c u) theorem fullResidual_eq_good_add_excluded (c : Context D) (u : State D) : fullResidual c u = fullGoodResidual c u + u.errors.total := by simp [fullGoodResidual] theorem fullResidual_decomposition (c : Context D) (u : State D) : fullResidual c u = fun n x i => fullGoodWaveResidual c u n x i + angularMeanVector (fullGoodResidual c u) n x.1 i + u.errors.total n x i := by funext n x i simp only [fullGoodWaveResidual, angularNonconstant, fullGoodResidual, Pi.sub_apply] ring end FullFields section ActualCovariance open CorrectionState MeasureTheory def AngularContinuous (u : Oscillation D) : Prop := ∀ n x i, Continuous (fun θ : ℝ => u n (x, θ) i) omit [NormedAddCommGroup D] [NormedSpace ℝ D] in theorem AngularContinuous.add {u v : Oscillation D} (hu : AngularContinuous u) (hv : AngularContinuous v) : AngularContinuous (u + v) := fun n x i => (hu n x i).add (hv n x i) omit [NormedAddCommGroup D] [NormedSpace ℝ D] in theorem bilinearCovariance_add_left {u v w : Oscillation D} (hu : AngularContinuous u) (hv : AngularContinuous v) (hw : AngularContinuous w) : bilinearCovariance (u + v) w = bilinearCovariance u w + bilinearCovariance v w := by funext i j n x have he : (fun θ : ℝ => (u + v) n (x, θ) i * w n (x, θ) j) = (fun θ => u n (x, θ) i * w n (x, θ) j + v n (x, θ) i * w n (x, θ) j) := by funext θ simp only [Pi.add_apply] ring change (∫ θ in (0 : ℝ)..2 * Real.pi, (u + v) n (x, θ) i * w n (x, θ) j) / (2 * Real.pi) = _ rw [he, intervalIntegral.integral_add (((hu n x i).fun_mul (hw n x j)).intervalIntegrable _ _) (((hv n x i).fun_mul (hw n x j)).intervalIntegrable _ _), add_div] rfl omit [NormedAddCommGroup D] [NormedSpace ℝ D] in theorem bilinearCovariance_add_right {u v w : Oscillation D} (hu : AngularContinuous u) (hv : AngularContinuous v) (hw : AngularContinuous w) : bilinearCovariance u (v + w) = bilinearCovariance u v + bilinearCovariance u w := by funext i j rw [bilinearCovariance_comm u (v + w) i j, congrFun (congrFun (bilinearCovariance_add_left hv hw hu) j) i] simp only [Pi.add_apply, bilinearCovariance_comm v u j i, bilinearCovariance_comm w u j i] /-- The actual covariance increment contains both cross terms and the entire square of the exact increment. -/ noncomputable def covarianceIncrement (u v : Oscillation D) : Tensor D := bilinearCovariance u v + bilinearCovariance v u + bilinearCovariance v v omit [NormedAddCommGroup D] [NormedSpace ℝ D] in theorem covariance_add {u v : Oscillation D} (hu : AngularContinuous u) (hv : AngularContinuous v) : bilinearCovariance (u + v) (u + v) = bilinearCovariance u u + covarianceIncrement u v := by rw [bilinearCovariance_add_left hu hv (hu.add hv), bilinearCovariance_add_right hu hu hv, bilinearCovariance_add_right hv hu hv] unfold covarianceIncrement abel omit [NormedAddCommGroup D] [NormedSpace ℝ D] in theorem covariance_actual_update (s : State D) (m : Triple D) (p : ScalarField D) (v : Oscillation D) (q : OscillatoryScalar D) (e : ExcludedErrors D) (hu : AngularContinuous s.oscillation) (hv : AngularContinuous v) : (s.addIncrement m p v q e).covariance = s.covariance + covarianceIncrement s.oscillation v := covariance_add hu hv end ActualCovariance section ActualFullUpdate open CorrectionState HarmonicCalculus noncomputable def complexIncrement (m : Triple D) (v : Oscillation D) (n : ℕ) (x : D × ℝ) : ComplexVector := ![(m.radial n x.1 + v n x 0 : ℝ), (m.angular n x.1 + v n x 1 : ℝ), (m.axial n x.1 + v n x 2 : ℝ)] noncomputable def complexPressureIncrement (p : ScalarField D) (q : OscillatoryScalar D) (n : ℕ) (x : D × ℝ) : ℂ := (p n x.1 + q n x : ℝ) omit [NormedAddCommGroup D] [NormedSpace ℝ D] in theorem complexPerturbation_actual_update (s : State D) (m : Triple D) (p : ScalarField D) (v : Oscillation D) (q : OscillatoryScalar D) (e : ExcludedErrors D) (n : ℕ) : complexPerturbation (s.addIncrement m p v q e) n = complexPerturbation s n + complexIncrement m v n := by funext x i fin_cases i <;> simp [complexPerturbation, complexIncrement, State.addIncrement, updated] <;> ring omit [NormedAddCommGroup D] [NormedSpace ℝ D] in theorem complexPressure_actual_update (s : State D) (m : Triple D) (p : ScalarField D) (v : Oscillation D) (q : OscillatoryScalar D) (e : ExcludedErrors D) (n : ℕ) : complexPressure (s.addIncrement m p v q e) n = complexPressure s n + complexPressureIncrement p q n := by funext x simp [complexPressure, complexPressureIncrement, State.totalPressureIncrement, State.addIncrement] ring /-- The differential increment uses the old *exact* perturbation in both cross terms. The stored excluded residual is not multiplied into the PDE. -/ noncomputable def fullDifferentialIncrement (c : Context D) (s : State D) (m : Triple D) (p : ScalarField D) (v : Oscillation D) (q : OscillatoryScalar D) : ℕ → D × ℝ → ComplexVector := fun n x => let R : D × ℝ → ℝ := fun y => c.operators.radius y.1 let a := complexPerturbation s n let b := complexIncrement m v n LinearWaveResidual.linearResidual (c.operators.epsilon n) R (radialDirection c n) angularDirection (axialDirection c n) (timeDirection c n) (complexBase c n) b (complexPressureIncrement p q n) x + LinearWaveResidual.transport R (radialDirection c n) angularDirection (axialDirection c n) a b x + LinearWaveResidual.transport R (radialDirection c n) angularDirection (axialDirection c n) b a x + LinearWaveResidual.transport R (radialDirection c n) angularDirection (axialDirection c n) b b x theorem fullResidual_actual_update {U : Set (D × ℝ)} (hU : IsOpen U) (c : Context D) (s : State D) (m : Triple D) (p : ScalarField D) (v : Oscillation D) (q : OscillatoryScalar D) (e : ExcludedErrors D) (n : ℕ) (hr : ContDiffOn ℝ ∞ (radialDirection c n) U) (ha : ∀ i, ContDiffOn ℝ ∞ (fun x => complexPerturbation s n x i) U) (hb : ∀ i, ContDiffOn ℝ ∞ (fun x => complexIncrement m v n x i) U) (hp : ContDiffOn ℝ ∞ (complexPressure s n) U) (hq : ContDiffOn ℝ ∞ (complexPressureIncrement p q n) U) {x : D × ℝ} (hx : x ∈ U) (i : Fin 3) : fullResidual c (s.addIncrement m p v q e) n x i - fullResidual c s n x i = (fullDifferentialIncrement c s m p v q n x i).re + e.base n x i := by have hd := nonlinearResidual_add_sub hU (c.operators.epsilon n) (fun y : D × ℝ => c.operators.radius y.1) (timeDirection c n) hr (show ContDiffOn ℝ ∞ (angularDirection : D × ℝ → D × ℝ) U from contDiffOn_const) (show ContDiffOn ℝ ∞ (axialDirection c n) U from contDiffOn_const) (complexBase c n) (complexPerturbation s n) (complexIncrement m v n) (complexPressure s n) (complexPressureIncrement p q n) ha hb hp hq hx have hdreal := congrArg Complex.re (congrFun hd i) simp only [Pi.sub_apply, Pi.add_apply, Complex.sub_re, Complex.add_re] at hdreal simp only [fullResidual] rw [complexPerturbation_actual_update, complexPressure_actual_update] simp only [State.addIncrement, ExcludedErrors.add, Pi.add_apply] change _ = (fullDifferentialIncrement c s m p v q n x i).re + _ unfold fullDifferentialIncrement simp only [Pi.add_apply, Complex.add_re] linarith theorem fullGoodResidual_actual_update {U : Set (D × ℝ)} (hU : IsOpen U) (c : Context D) (s : State D) (m : Triple D) (p : ScalarField D) (v : Oscillation D) (q : OscillatoryScalar D) (e : ExcludedErrors D) (n : ℕ) (hr : ContDiffOn ℝ ∞ (radialDirection c n) U) (ha : ∀ i, ContDiffOn ℝ ∞ (fun x => complexPerturbation s n x i) U) (hb : ∀ i, ContDiffOn ℝ ∞ (fun x => complexIncrement m v n x i) U) (hp : ContDiffOn ℝ ∞ (complexPressure s n) U) (hq : ContDiffOn ℝ ∞ (complexPressureIncrement p q n) U) {x : D × ℝ} (hx : x ∈ U) (i : Fin 3) : fullGoodResidual c (s.addIncrement m p v q e) n x i - fullGoodResidual c s n x i = (fullDifferentialIncrement c s m p v q n x i).re - e.gaussian n x i - e.aliasError n x i := by have hd := fullResidual_actual_update hU c s m p v q e n hr ha hb hp hq hx i simp only [fullGoodResidual, State.addIncrement, ExcludedErrors.total, ExcludedErrors.add, Pi.sub_apply, Pi.add_apply] at * linarith end ActualFullUpdate end NavierStokes.CorrectionStep