Skip to content
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

Fix 3d case #83

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 10 additions & 1 deletion src/domain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -992,14 +992,23 @@ function align_field(a::AbstractQuantity,glue::BoundaryGlue)
end

function inverse_map_impl(f,x0)
function pseudo_inverse_if_not_square(J)
m,n = size(J)
if m != n
pinv(J)
else
inv(J)
end
end
function invf(fx)
x = x0
tol = 1.0e-12
J = nothing
niters = 100
for _ in 1:niters
J = ForwardDiff.jacobian(f,x)
dx = pinv(J)*(fx-f(x))
Jinv = pseudo_inverse_if_not_square(J)
dx = Jinv*(fx-f(x))
x += dx
if norm(dx) < tol
return x
Expand Down
17 changes: 17 additions & 0 deletions test/assembly_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,21 @@ el2 = ∫( q->abs2(eh(q)), dΩ) |> sum |> sqrt
eh1 = ∫( q->∇eh(q)⋅∇eh(q), dΩ) |> sum |> sqrt
@test el2 < tol

# 3d case

n = 2
domain = (0,1,0,1,0,1)
cells = (n,n,n)
mesh = GT.cartesian_mesh(domain,cells)
Ω = GT.interior(mesh)
k = 1
V = GT.lagrange_space(Ω,k)
dΩ = GT.measure(Ω,2*k)
gradient(u) = x->ForwardDiff.gradient(u,x)
∇(u,x) = GT.call(gradient,u)(x)
a(u,v) = GT.∫( x->∇(u,x)⋅∇(v,x), dΩ)
l(v) = 0
x,A,b = GT.linear_problem(Float64,V,a,l)
A |> display

end # module
Loading