Skip to content

Starting to draft primal HHO #20

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

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b672409
Starting to draft primal HHO
amartinhuertas Apr 3, 2022
8eb9119
First complete implementation of HHO gradient reconstruction operator
amartinhuertas Apr 6, 2022
df027d8
Modularizing LocalFEOperatorTests.jl for better readability
amartinhuertas Apr 7, 2022
3d3e076
Added the necessary logic to support the reduction operator
amartinhuertas Apr 7, 2022
70d2189
Potential reconstruction operator validated
amartinhuertas Apr 8, 2022
e433c8a
Difference operators working. All building blocks ready for HHO.
amartinhuertas Apr 8, 2022
492c420
Typo fix
amartinhuertas Apr 8, 2022
d5f6908
First complete implementation of HHO method for the Poisson problem.
amartinhuertas Apr 15, 2022
0d3737e
Primal HHO for Poisson problem working!
amartinhuertas Apr 16, 2022
cb54ef2
Cosmetic changes in the driver
amartinhuertas Apr 22, 2022
2f31f13
Adding @time to tests
amartinhuertas Apr 22, 2022
c53babb
* Added convergence analysis to HHO driver
amartinhuertas May 22, 2022
c80d9cc
Lowest order HHO convergence analysis
amartinhuertas May 22, 2022
c50f4b3
Project.toml and minor issues with PoissonHHOtests.jl
Jai-Tushar May 21, 2024
795d82f
fixed minor issues with PoissonHHOTests.jl
Jai-Tushar May 21, 2024
081e664
Fixes in LocalFEOperators + update to Julia 1.9
amartinhuertas Jun 16, 2024
9288e12
checkpoint. Not working
amartinhuertas Jul 1, 2024
40e0463
primal HHO + Poisson working for order=0, order=1 and order=3.
amartinhuertas Jul 1, 2024
da236e8
Splitting of LocalFEOperator into ReconstructionFEOperator and
amartinhuertas Jul 6, 2024
79a0d71
* Fixed a bug (a wrong sign) in the definition of the n(.,.) bilinear
amartinhuertas Jul 7, 2024
20255f3
* Tidying up reconstruction operator definition in PoissonHHoTests.
amartinhuertas Jul 8, 2024
d0cc27f
Removing unused template parameters from function definition statement
amartinhuertas Jul 9, 2024
8e1199c
Minor changes to PoissonHHO with performance in mind
amartinhuertas Jul 9, 2024
50ca221
Changes required to support latest version of Gridap (0.18)
amartinhuertas Jul 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 143 additions & 0 deletions draft_hho.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
using Gridap
using GridapHybrid

function Gridap.Arrays.return_cache(::typeof(\),a::AbstractArray{<:Number},b::AbstractArray{<:Number})
c = a\b
Gridap.Arrays.CachedArray(c)
end

function Gridap.Arrays.evaluate!(cache,::typeof(\),a::AbstractMatrix{<:Number},b::AbstractVector{<:Number})
m = size(a,1)
Gridap.Arrays.setsize!(cache,(m,))
c = cache.array
c .= a\b
c
end

function Gridap.Arrays.evaluate!(cache,::typeof(\),a::AbstractMatrix{<:Number},b::AbstractMatrix{<:Number})
m = size(a,1)
n = size(b,2)
Gridap.Arrays.setsize!(cache,(m,n))
c = cache.array
c .= a\b
c
end


# TO-THINK: Perhaps a better name??? E.g., Local FE problem???
struct LocalAffineFEOperator{T1,T2,T3,T4} <: GridapType
LHS_form :: T1
RHS_form :: T2
trial_space :: T3
test_space :: T4
LHS_contribs :: Gridap.CellData.DomainContribution

function LocalAffineFEOperator(weakform,
trial_space :: A,
test_space :: B) where {A,B}

us = get_trial_fe_basis(trial_space)
vs = get_fe_basis(test_space)

LHS_form, RHS_form = weakform
LHS_contribs = LHS_form(us,vs)

T1=typeof(LHS_form)
T2=typeof(RHS_form)
T3=typeof(trial_space)
T4=typeof(test_space)
new{T1,T2,T3,T4}(LHS_form,
RHS_form,
trial_space,
test_space,
LHS_contribs)
end
end

# TO-THINK: MultiFieldFEBasis are NOT of type <: FEBasis.
# They are of type MultiFieldCellField. Besides,
# I have the feeling the code below only works for
# SingleFieldFEBasis.

function (::LocalAffineFEOperator)(bases::Gridap.FESpaces.FEBasis...)
basis_style=Gridap.FESpaces.BasisStyle(first(bases))
Gridap.Helpers.@check all( [basis_style==Gridap.FESpaces.BasisStyle(basis) for basis in bases ] )

lhs_skeleton=GridapHybrid._find_skeleton(op.LHS_contribs)
if length(lhs_skeleton)==1
LHS_contribs = Gridap.Hybrid._merge_bulk_and_skeleton_contributions(op.LHS_contribs)
else
Gridap.Helpers.@check length(lhs_skeleton)==0
LHS_contribs = op.LHS_contribs
end

vs = get_fe_basis(op.test_space)
RHS_contribs = op.RHS_form(bases,vs)

rhs_skeleton=GridapHybrid._find_skeleton(RHS_contribs)
if length(rhs_skeleton)==1
RHS_contribs = GridapHybrid._merge_bulk_and_skeleton_matrix_contributions(RHS_contribs)
end
A_array = get_array(LHS_contribs)
B_array = get_array(RHS_contribs)
dofs = lazy_map(\,A_array,B_array)

# We get the test space so that we dont deal with
# the transpose underlying the trial basis
basis=get_fe_basis(op.test_space)

range_basis_data = lazy_map(Gridap.Fields.linear_combination,
dofs,
Gridap.CellData.get_data(basis))

if (basis_style==Gridap.FESpaces.TrialBasis())
range_basis_data = lazy_map(transpose,range_basis_data)
end

Gridap.FESpaces.similar_fe_basis(basis,
range_basis_data,
Gridap.CellData.get_domains(RHS_contribs)...,
basis_style,
DomainStyle(basis))
end


model=CartesianDiscreteModel((0,1,0,1),(2,2))

# Geometry
D = num_cell_dims(model)
Ω = Triangulation(ReferenceFE{D},model)
Γ = Triangulation(ReferenceFE{D-1},model)
∂K = GridapHybrid.Skeleton(model)

# Reference FEs
order = 1
refferecᵤ = ReferenceFE(lagrangian,Float64,order+1;space=:P)
reffeᵤ = ReferenceFE(lagrangian,Float64,order ;space=:P)

# Define test FESpaces
VKR = TestFESpace(Ω , refferecᵤ; conformity=:L2)
VK = TestFESpace(Ω , reffeᵤ ; conformity=:L2)
V∂K = TestFESpace(Γ , reffeᵤ ; conformity=:L2)


# Define trial FEspaces
UKR = TrialFESpace(VKR)
UK = TrialFESpace(VK)
U∂K = TrialFESpace(V∂K)

degree = 2*order+1
dΩ = Measure(Ω,degree)
nK = get_cell_normal_vector(∂K)
d∂K = Measure(∂K,degree)

v=get_fe_basis(VKR)
u∂K=get_trial_fe_basis(U∂K)
dc=∫((∇(v)⋅nK)*u∂K)d∂K


a(u,v)=∫(∇(v)⋅∇(u))dΩ
l( (uK,u∂K), v)=∫((∇(v)⋅nK)*u∂K)d∂K+∫(-Δ(v)*uK)dΩ

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# Stabilisation
# Method 1: Orthogonal basis using change of basis with M^{-1}

refferecᵤ = ReferenceFE(orthogonal,Float64,order+1;space=:P)
\mu_T = h^{-2} # k^4
m(u,v)=((v)(u))dΩ + \mu_T (vu)dΩ
l( (uK,u∂K), v)=(((v)nK)*u∂K)d∂K+(-Δ(v)*uK)dΩ + \mu_T (vu∂K)dΩ

# Optimisation
# \pi(k,u) that makes 0 dofs higher than k

# Method 2: Define subspaces of orthogonal spaces
# orthogonal basis from 1 to order+1 (excluding 0)
refferecᵤ = ReferenceFE(orthogonal,Float64,1:order+1;space=:P)
refferecᵤ_0 = ReferenceFE(orthogonal,Float64,0;space=:P)
VKR_1 = ...
VKR_0 = ...

VKR = MultiFieldFESpace([UKR_0,UKR_1])

# Define HHO local reconstruction operator
function m(u,v )
  v0, v1 = v
  m(u,v) = ∫∇(u)*(v1)dΩ +  (u*v0) dΩ
end

function l(u,v )
  v0, v1 = v
  l( (uK,u∂K), v)=(((v1)nK)*u∂K)d∂K+(-Δ(v1)*uK)dΩ + (uK*v0) dΩ
end

P=LocalProjector((m,l),UKR,VKR)


m(ur,v) = ∫u_mean*vdΩ
l(uK, v)=∫v*uKdΩ
\pi_0=LocalProjector((m,l),UKR,VKR)



# Global formulation
UK∂K = MultiFieldFESpace([UK, U∂K])
a(u,v)=((P(v))(P(u)))dΩ

function f(v)
   vK, v∂K = UK∂K
   f(v) = (f*vK)dΩ
end
# 


m(u,v)=((v)(u))dΩ 
l( (uK,u∂K), v)=(((v)nK)*u∂K)d∂K+(-Δ(v)*uK)dΩ 

(vu∂K)dΩ

op=LocalAffineFEOperator((a,l),UKR,VKR)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# Define HHO local reconstruction operator
m(ur,v) = ∫∇(ur)*(v)dΩ
l( (uK,u∂K), v)=(((v)nK)*u∂K)d∂K+(-Δ(v)*uK)dΩ
P=LocalProjector((m,l),UKR,VKR)

# Global formulation
UK∂K = MultiFieldFESpace([UK, U∂K])
a(u,v)=((P(v))(P(u)))dΩ

function f(v)
   vK, v∂K = UK∂K
   f(v) = (f*vK)dΩ
end

# as HDG

UKR_basis=op(get_trial_fe_basis.((UK,U∂K))...)
Copy link
Member

@santiagobadia santiagobadia Apr 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# Stab in Badia et al 2.11
# Define spaces for the projectors

# Cell term
m(ur,v) = ∫u*vdΩ
l( (uK,u∂K), v)=(P((uK,u∂K)) - uK)*vdΩ
\PiK =LocalProjector((m,l),UKR,VKR)

# Face term
m(ur,v) = ∫u*vd∂K
l( (uK,u∂K), v)=(P((uK,u∂K)) - u∂K)*vd∂K
\Pi∂K =LocalProjector((m,l),UKR,VKR)

# stab term in the global operator
a(u,v)=((P(v))(P(u)))dΩ +\Pi∂K(u)*\Pi∂K(v)d∂K +\PiK(u)*\PiK(v)dΩ