Library NumAnalysis.FEM.FE_LagP

This file is part of the Rocq Numerical Analysis library
Copyright (C) Boldo, Clément, Martin, Mayero, Mouhcine
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the COPYING file for more details.

Bibliography

[ErnGuermond] Alexandre Ern and Jean-Luc Guermond, Finite Elements I. Approximation and Interpolation, Texts in Applied Mathematics, vol. 72, Springer Cham, 2021, https://doi.org/10.1007/978-3-030-56341-7,
https://inria.hal.science/hal-03226049 (with different page numbers).
[RR9557v1] François Clément and Vincent Martin, Finite element method. Detailed proofs to be formalized in Coq, RR-9557, first version, Inria Paris, 2024, https://inria.hal.science/hal-04713897v1.

From NumAnalysis Require Import stdlib_wR ssr_wMC.

From Coquelicot Require Import Hierarchy.
Close Scope R_scope.

From NumAnalysis Require Import Algebra_wDep.
From NumAnalysis Require Import multi_index poly_Pdk.
From NumAnalysis Require Import poly_LagP1k poly_LagPd1_ref.
From NumAnalysis Require Import geom_transf_affine poly_LagPd1.
From NumAnalysis Require Import LagP_node_ref LagP_node FE FE_transf.

Local Open Scope Monoid_scope.
Local Open Scope Group_scope.
Local Open Scope Ring_scope.

Section LagP_P_approx.

Lagrange approximation space.

Definition nnode_LagPdk (d k : nat) : nat := (pbinom d k).+1.

Lemma Pdk_has_dim : ∀ d k, has_dim (Pdk d k) (nnode_LagPdk d k).
Proof. intros; apply Pdk_has_dim. Qed.

End LagP_P_approx.

Section LagP1k_S_dof.

Lagrange degrees of freedom from nodes for d=1 and any k.

Context {k : nat}.
Variable node_1k : [0..nnode_LagPdk 1 k) → 'R^1.

Definition FE_LagP1k_S_dof : [0..nnode_LagPdk 1 k) → FRd 1 → R :=
  fun i1k p ⇒ p (node_1k i1k).

Lemma FE_LagP1k_S_dof_lm : ∀ i1k, lin_map (FE_LagP1k_S_dof i1k).
Proof. intros; apply pt_eval_lm. Qed.

End LagP1k_S_dof.

Section LagPdk_S_dof.

Lagrange degrees of freedom from vertices for any d,k.

Context {d : nat}.
Variable k : nat.
Variable vtx : [0..d] → 'R^d.

[RR9557v1] Def 1608, p. 102.
For k=0.
Definition FE_LagPd0_S_dof : [0..nnode_LagPdk d 0) → FRd d → R :=
  fun _ p ⇒ p (node_d0 vtx).

Lemma FE_LagPd0_S_dof_lm : ∀ id0, lin_map (FE_LagPd0_S_dof id0).
Proof. intros; apply pt_eval_lm. Qed.

[RR9557v1] Def 1608, p. 102.
For k<>0.
Definition FE_LagPSdSk_S_dof : [0..nnode_LagPdk d k) → FRd d → R :=
  fun idk p ⇒ p (node vtx idk).

Lemma FE_LagPSdSk_S_dof_lm : ∀ idk, lin_map (FE_LagPSdSk_S_dof idk).
Proof. intros; apply pt_eval_lm. Qed.

End LagPdk_S_dof.

Section FE_LagP0k_Def.

Build Lagrange FE for d=0 and any k.
Build Lagrange FE for d=1 and any k.

Lemma FE_LagP1k_unisolvence_inj :
  ∀ {k} {node_1k : [0..nnode_LagPdk 1 k) → 'R^1}, injective node_1k →
    KerS0 (Pdk 1 k) (gather (FE_LagP1k_S_dof node_1k)).
Proof.
unfold FE_LagP1k_S_dof; move=>> Hnode.
rewrite KerS0_gather_equiv; intros p Hp1 Hp2.
rewrite (LagP1k_decomp Hnode Hp1); apply: lc_zero_compat_l.
apply extF; easy.
Qed.

Context {k : nat}.
Context {node_1k : [0..nnode_LagPdk 1 k) → 'R^1}.
Hypothesis Hnode : injective node_1k.
Variable vtx : 'R^{2,1}.

Definition FE_LagP1k : FE 1 :=
  mk_FE Simplex vtx (Pdk_has_dim 1 k)
    (FE_LagP1k_S_dof_lm node_1k) (FE_LagP1k_unisolvence_inj Hnode).

End FE_LagP1k_Def.

Section FE_LagPd0_Def.

Build Lagrange FE for any d and k=0.

Context {d : nat}.

[RR9557v1] Lem 1615, p. 103.
Lemma FE_LagPd0_unisolvence_inj :
  ∀ vtx, KerS0 (Pdk d 0) (gather (FE_LagPd0_S_dof vtx)).
Proof.
unfold FE_LagPd0_S_dof; intros;
    apply KerS0_gather_equiv; move⇒ p /Pd0_eq → Hp; rewrite (Hp ord0); easy.
Qed.

Variable vtx : [0..d] → 'R^d.

[RR9557v1] Th 1629, p. 108.
For k=0.
Build Lagrange FE for d,k<>0.

Let UP d k :=
  ∀ vtx, aff_indep_ms vtx →
    KerS0 (Pdk d k) (gather (FE_LagPSdSk_S_dof k vtx)).

Base case: unisolvence result for d=1 and k<>0.
[RR9557v1] Lem 1476, p. 63.
Lemma FE_LagP1Sk_unisolvence_inj : ∀ {k}, k ≠ 0 → UP 1 k.
Proof.
intros k Hk vtx Hvtx; apply FE_LagP1k_unisolvence_inj, node_inj; easy.
Qed.

Base case: unisolvence result for d<>0 and k=1.
[RR9557v1] Lem 1619, p. 104.
Lemma FE_LagPSd1_unisolvence_inj : ∀ {d}, d ≠ 0 → UP d 1.
Proof.
intros [| d1] Hd vtx Hvtx; [easy |]; unfold UP, FE_LagPSdSk_S_dof.
rewrite KerS0_gather_equiv; intros p Hp1 Hp2.
rewrite (LagPd1_decomp_node Hvtx Hp1); apply: lc_zero_compat_l.
apply extF; easy.
Qed.

Induction step: unisolvence result for d,k>1.

Lemma unisolvence_inj_Hface :
  ∀ {d k}, d ≠ 0 → k ≠ 0 → UP d k →
    ∀ i {vtx p}, aff_indep_ms vtx → Pdk d.+1 k p →
      (∀ (idk : [0..pbinom d.+1 k]),
        Hface vtx i (node vtx idk) → p (node vtx idk) = 0) →
      ∀ x, Hface vtx i x → p x = 0.
Proof.
intros d [| k1] Hd Hk; [easy |]; intros H i vtx p Hvtx Hp1 Hp2 x Hx.
rewrite -(f_invS_canS_r (inj_Hface_bijS Hvtx i) x)//.
fold (inj_Hface_invS Hvtx i x).
pose (pi := fun y ⇒ p (inj_Hface vtx i y));
  fold (pi (inj_Hface_invS Hvtx i x)).
rewrite (H _ vtx_ref_aff_indep pi)//; [apply inj_Hface_comp; easy |].
extF idk; rewrite gather_eq;
    unfold FE_LagPSdSk_S_dof, pi; rewrite -node_ref_node.
rewrite inj_Hface_node//; apply Hp2; apply node_Hface; [easy.. |].
apply inj_ASdki_correct.
Qed.

Lemma FE_LagPSdSk_unisolvence_inj_ind :
  ∀ {d k}, d ≠ 0 → k ≠ 0 → UP d.+1 k → UP d k.+1 → UP d.+1 k.+1.
Proof.
unfold UP, FE_LagPSdSk_S_dof; intros d k Hd0 Hk0 IH2 IH1 vtx Hvtx.
assert (HSd0 : d.+1 ≠ 0) by easy.
assert (HSk0 : k.+1 ≠ 0) by easy.
assert (HSk1 : (1 < k.+1)%coq_nat) by now apply nat_neq_0_lt_S.
apply KerS0_gather_equiv; intros p Hp1 Hp2.
destruct (factor_zero_on_Hface HSd0 Hvtx ord0 Hp1) as [q [Hq1 Hq2]].
apply (unisolvence_inj_Hface Hd0 HSk0); easy.
specialize (IH2 _ (sub_vtx_aff_indep HSk1 Hvtx));
    rewrite KerS0_gather_equiv in IH2.
rewrite Hq2 (IH2 q)//; [apply: mult_zero_r |]; intros iSdk.
apply mult_reg_l with (LagPd1 Hvtx ord0 (sub_node k.+1 vtx iSdk)).
apply invertible_equiv_R; rewrite -Hface_equiv;
    apply sub_node_out_Hface_0; easy.
rewrite -(sub_node_node HSk1)
    -fct_mult_eq -Hq2 sub_node_eq// Hp2 mult_zero_r//.
Qed.

Unisolvence result for d,k<>0.
[RR9557v1] Lem 1625, pp. 105-107.
Theorem FE_LagPSdSk_unisolvence_inj : ∀ {d k}, d ≠ 0 → k ≠ 0 → UP d k.
Proof.
apply nat_ind2_alt_11.
intros d; apply: FE_LagPSd1_unisolvence_inj.
intros k; apply: FE_LagP1Sk_unisolvence_inj.
intros d k; apply: FE_LagPSdSk_unisolvence_inj_ind.
Qed.

Context {d k : nat}.
Hypothesis Hd : d ≠ 0.
Hypothesis Hk : k ≠ 0.
Context {vtx : [0..d] → 'R^d}.
Hypothesis Hvtx : aff_indep_ms vtx.

[RR9557v1] Th 1629, p. 108.
For k<>0.
Shape functions in the case k=1. They are the Lagrange polynomials

Context {d : nat}.
Hypothesis Hd : d ≠ 0.
Context {vtx : [0..d] → 'R^d}.
Hypothesis Hvtx : aff_indep_ms vtx.

Lemma Hndof : ndof (FE_LagPSdSk Hd neq_1_0 Hvtx) = d.+1.
Proof. simpl; unfold nnode_LagPdk; f_equal; apply pbinom_1_r. Qed.

Lemma shape_fun_LagPSd1_correct :
  shape_fun (FE_LagPSdSk Hd neq_1_0 Hvtx) = castF (eq_sym Hndof) (LagPd1 Hvtx).
Proof.
apply is_predual_dof_uniq; [apply shape_fun_correct | split; simpl].
intro; unfold castF; apply LagPd1_is_Pd1.
intros i; unfold FE_LagPSdSk_S_dof; apply fun_ext_rev, (castF_inj Hndof).
apply trans_eq with (fun j : [0..d] ⇒ kron (cast_ord Hndof i) j); [| easy].
rewrite -(LagPd1_kron_vtx Hvtx) fct_castF_eq castF_can; fun_ext j; f_equal.
rewrite node_vtx_d1; unfold castF; f_equal; apply ord_inj; easy.
Qed.

End FE_LagPSd1_shape_fun.

Section FE_LagPSdk_from_ref.

Check that FE_LagPSdSk Hd Hk Hvtx = FE_ref_to_cur (FE_LagPSdSk Hd Hk vtx_ref_aff_indep), ie that the generic simplicial Lagrange FE is equal to the transformation of the reference simplicial Lagrange FE.
[RR9557v1] Lem 1604 (for k<>0), p. 101.
It is actually directly on the linear forms, rather than on the nodes.
Lemma FE_LagPSdSk_S_dof_eq_from_ref :
  ∀ {d} k (vtx : [0..d] → 'R^d) i p,
    FE_LagPSdSk_S_dof k vtx i p =
      FE_LagPSdSk_S_dof k vtx_ref i (p \o (T_geom vtx)).
Proof.
intros; unfold FE_LagPSdSk_S_dof.
rewrite comp_correct -node_ref_node; easy.
Qed.

Context {d k : nat}.
Hypothesis Hd : d ≠ 0.
Hypothesis Hk : k ≠ 0.
Context {vtx : [0..d] → 'R^d}.
Hypothesis Hvtx : aff_indep_ms vtx.

Definition FE_LagPSdSk_ref := FE_LagPSdSk Hd Hk (@vtx_ref_aff_indep d).

Lemma FE_LagPSdSk_eq_from_ref :
  FE_LagPSdSk Hd Hk Hvtx = TFE_vtx_from_ref FE_LagPSdSk_ref Hvtx.
Proof.
apply: FE_ext; simpl;
    [unfold TFE_K_vertices | unfold TFE_P_approx | unfold TFE_S_dof]; simpl.
rewrite castF_id T_geom_vtxF; easy.
apply eq_sym, transf_am_Pdk; [apply T_geom_bij; easy | apply T_geom_am].
rewrite !castF_id; fun_ext2; apply FE_LagPSdSk_S_dof_eq_from_ref.
Qed.

Let Hndof := f_equal ndof FE_LagPSdSk_eq_from_ref.

Lemma shape_fun_LagPSdSk_eq_from_ref :
  shape_fun (FE_LagPSdSk Hd Hk Hvtx) =
    castF (eq_sym Hndof)
      (shape_fun (TFE_vtx_from_ref FE_LagPSdSk_ref Hvtx)).
Proof. apply shape_fun_ext. Qed.

Lemma local_interp_LagPSdSk_comp :
  ∀ f,
    local_interp FE_LagPSdSk_ref (f \o (T_geom vtx)) =
      (local_interp (FE_LagPSdSk Hd Hk Hvtx) f) \o (T_geom vtx).
Proof.
intros; rewrite (TFE_local_interp (T_geom_bij Hvtx))
    FE_LagPSdSk_eq_from_ref; easy.
Qed.

End FE_LagPSdk_from_ref.

Section FE_LagPd0_from_ref.

Check that FE_LagPd0 vtx = FE_ref_to_cur (FE_LagPd0 vtx_ref), ie that the generic simplicial Lagrange FE is equal to the transformation of the reference simplicial Lagrange FE.
[RR9557v1] Lem 1604 (for k=0), p. 101.
It is actually directly on the linear forms, rather than on the nodes.
Lemma FE_LagPd0_S_dof_eq_from_ref :
  ∀ {d} (vtx : [0..d] → 'R^d) id0 p,
    FE_LagPd0_S_dof vtx id0 p =
      FE_LagPd0_S_dof vtx_ref id0 (p \o (T_geom vtx)).
Proof.
intros; unfold FE_LagPd0_S_dof, node_d0;
    rewrite comp_correct (am_isobaryc_Rms (T_geom_am _))// T_geom_vtxF; easy.
Qed.

Context {d : nat}.
Context {vtx : [0..d] → 'R^d}.
Hypothesis Hvtx : aff_indep_ms vtx.

Definition FE_LagPd0_ref := FE_LagPd0 (@vtx_ref d).

Lemma FE_LagPd0_eq_from_ref :
  FE_LagPd0 vtx = TFE_vtx_from_ref FE_LagPd0_ref Hvtx.
Proof.
apply: FE_ext; simpl;
    [unfold TFE_K_vertices | unfold TFE_P_approx | unfold TFE_S_dof]; simpl.
rewrite castF_id T_geom_vtxF; easy.
apply eq_sym, transf_am_Pdk; [apply T_geom_bij; easy | apply T_geom_am].
rewrite !castF_id; fun_ext2; apply FE_LagPd0_S_dof_eq_from_ref.
Qed.

Let Hndof := f_equal ndof FE_LagPd0_eq_from_ref.

Lemma shape_fun_LagPd0_eq_from_ref :
  shape_fun (FE_LagPd0 vtx) =
    castF (eq_sym Hndof) (shape_fun (TFE_vtx_from_ref FE_LagPd0_ref Hvtx)).
Proof. apply shape_fun_ext. Qed.

Lemma local_interp_LagPdk_comp :
  ∀ f,
    local_interp FE_LagPd0_ref (f \o (T_geom vtx)) =
      (local_interp (FE_LagPd0 vtx) f) \o (T_geom vtx).
Proof.
intros; rewrite (TFE_local_interp (T_geom_bij Hvtx))
    FE_LagPd0_eq_from_ref; easy.
Qed.

End FE_LagPd0_from_ref.

Section Face_unisolvence.

Face unisolvence for d>1 and k<>0.

Context {d k : nat}.
Hypothesis Hd : (1 < d)%coq_nat.
Hypothesis Hk : k ≠ 0.
Context {vtx : [0..d] → 'R^d}.
Hypothesis Hvtx : aff_indep_ms vtx.

[RR9557v1] Lem 1628, p. 107.
Lemma Hface_unisolvence :
  ∀ {i} p, Pdk d k p →
    (∀ (idk : [0..pbinom d k]),
      Hface vtx i (node vtx idk) → p (node vtx idk) = 0) ↔
    (∀ x, Hface vtx i x → p x = 0).
Proof.
intros i p Hp; split; [| move⇒ H idk Hidk; apply H; easy].
destruct d as [| d1]; [easy |].
assert (Hd0 : d1 ≠ 0) by now apply nat_neq_0_lt_S.
apply: (unisolvence_inj_Hface _ _ (FE_LagPSdSk_unisolvence_inj _ _)); easy.
Qed.

End Face_unisolvence.