-
Notifications
You must be signed in to change notification settings - Fork 2
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
amartinhuertas
wants to merge
24
commits into
main
Choose a base branch
from
exploring_primal_hho
base: main
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.
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 8eb9119
First complete implementation of HHO gradient reconstruction operator
amartinhuertas df027d8
Modularizing LocalFEOperatorTests.jl for better readability
amartinhuertas 3d3e076
Added the necessary logic to support the reduction operator
amartinhuertas 70d2189
Potential reconstruction operator validated
amartinhuertas e433c8a
Difference operators working. All building blocks ready for HHO.
amartinhuertas 492c420
Typo fix
amartinhuertas d5f6908
First complete implementation of HHO method for the Poisson problem.
amartinhuertas 0d3737e
Primal HHO for Poisson problem working!
amartinhuertas cb54ef2
Cosmetic changes in the driver
amartinhuertas 2f31f13
Adding @time to tests
amartinhuertas c53babb
* Added convergence analysis to HHO driver
amartinhuertas c80d9cc
Lowest order HHO convergence analysis
amartinhuertas c50f4b3
Project.toml and minor issues with PoissonHHOtests.jl
Jai-Tushar 795d82f
fixed minor issues with PoissonHHOTests.jl
Jai-Tushar 081e664
Fixes in LocalFEOperators + update to Julia 1.9
amartinhuertas 9288e12
checkpoint. Not working
amartinhuertas 40e0463
primal HHO + Poisson working for order=0, order=1 and order=3.
amartinhuertas da236e8
Splitting of LocalFEOperator into ReconstructionFEOperator and
amartinhuertas 79a0d71
* Fixed a bug (a wrong sign) in the definition of the n(.,.) bilinear
amartinhuertas 20255f3
* Tidying up reconstruction operator definition in PoissonHHoTests.
amartinhuertas d0cc27f
Removing unused template parameters from function definition statement
amartinhuertas 8e1199c
Minor changes to PoissonHHO with performance in mind
amartinhuertas 50ca221
Changes required to support latest version of Gridap (0.18)
amartinhuertas 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
There are no files selected for viewing
This file contains 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,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Ω | ||
|
||
op=LocalAffineFEOperator((a,l),UKR,VKR) | ||
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. # 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))...) | ||
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. # 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Ω |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.