Skip to content

Better operator evaluations + more operator tests#69

Open
chmerdon wants to merge 13 commits into
masterfrom
chmerdon/hdiv_grad_improved
Open

Better operator evaluations + more operator tests#69
chmerdon wants to merge 13 commits into
masterfrom
chmerdon/hdiv_grad_improved

Conversation

@chmerdon
Copy link
Copy Markdown
Member

@chmerdon chmerdon commented May 21, 2026

  • optimized loops in Gradient, Curl2, Curl3 computations of Hdiv finite elements
  • inner loops related to application of inverse transform to compute derivatives collapsed into dot products
  • added operators tests for Gradient (for H1 and Hdiv) and Divergence (for Hdiv) and Curl (for Hcurl)
  • fixed sign in Curl2 for Hcurl, now has the same sign as Curl2 for H1

@chmerdon chmerdon changed the title Better grad evaluation Hdiv + more operator tests Better operator evaluations Hdiv + more operator tests May 21, 2026
chmerdon added 2 commits May 22, 2026 13:35
…here for application of inverse trafo to compute derivatives; removed some type annotations from get_coefficient closure functions; item loops and citem properties of structs now use Ti type
@chmerdon chmerdon changed the title Better operator evaluations Hdiv + more operator tests Better operator evaluations H1, Hdiv + more operator tests May 22, 2026
@chmerdon chmerdon changed the title Better operator evaluations H1, Hdiv + more operator tests Better operator evaluations + more operator tests May 22, 2026
@chmerdon chmerdon requested a review from pjaap May 22, 2026 13:37
Copy link
Copy Markdown
Member

@pjaap pjaap left a comment

Choose a reason for hiding this comment

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

Nice work!

I think @views would really improve the code here.

But this is up to you. I'm not judging. Well, ok, a little :)

Comment thread src/feevaluator_h1.jl Outdated
for i in 1:size(cvals, 3), c in 1:length(offsets), k in 1:size(L2GAinv, 2), dof_i in 1:size(cvals, 2)
# compute duc/dxk
cvals[k + offsets[c], dof_i, i] += L2GAinv[k, j] * refbasisderivvals[subset[dof_i] + offsets2[c], j, i]
cvals[k + offsets[c], dof_i, i] = dot(view(L2GAinv, k, :), view(refbasisderivvals, subset[dof_i] + offsets2[c], :, i))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You know I'm a fan of @views and here, it really makes the code better + less brackets:

cvals[k + offsets[c], dof_i, i] = @views dot(L2GAinv[k, :], refbasisderivvals[subset[dof_i] + offsets2[c], :, i])

Comment thread src/feevaluator_h1.jl Outdated
cvals[3, dof_i, i] -= L2GAinv[2, k] * refbasisderivvals[subset[dof_i] + offsets2[1], k, i] # - du1/dx2
end
end
for i in 1:size(cvals, 3), dof_i in 1:size(cvals, 2)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

here you can put the @views even in front of the for.

Comment thread test/test_operators.jl Outdated

if fetype <: AbstractHcurlFiniteElement
return maximum([error_curl3])
else
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just for better code readability:

if cond
   return XXX
end

# no else, since this code branch is evaluated anyway

Comment thread test/test_operators.jl Outdated
println("EG = Tetrahedron3D | $fetype | operator = Gradient | error = $error_grad")
println("EG = Tetrahedron3D | $fetype | operator = Divergence | error = $error_div")

if fetype <: AbstractH1FiniteElement
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

and here

if !(fetype <: AbstractH1FiniteElemen)
 return ...
end
# no else

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants