You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use Gridap to invert the Laplace problem to determine Dirichlet data on the boundaries given some point measurements on the interior. The idea is to minimize the squared residual between simulated and measured data. However, I am having trouble using ForwardDiff (finite differencing works, but I really want AD to speed up the optimization process).
Here is my program:
# Finite element method
using Gridap
using GridapGmsh, Gridap.Io
model = DiscreteModelFromFile("model03-1e4.json")
order = 2
reffe = ReferenceFE(lagrangian,Float64,order)
# define the test space
V0 = TestFESpace(model,reffe;conformity=:H1,
dirichlet_tags=[
"westFace",
"eastFace",
"southFace",
"northFace",
"westBase",
"eastBase",
"southBase",
"northBase",
"upFace",
"bottom"]
)
degree = 2
Ω = Triangulation(model)
dΩ = Measure(Ω,degree) # approximation of Lebesgue measure
function laplacesolve(α)
"""
laplacesolve solves the Laplace equation with Dirichlet data given by the vector α.
"""
# add boundary data (here: fixed data for boundary regions 1:10)
g_wf(x) = α[1] # west face
g_ef(x) = α[2] # east face
g_sf(x) = α[3] # south face
g_nf(x) = α[4] # north face
g_wb(x) = α[5] # west base
g_eb(x) = α[6] # east base
g_sb(x) = α[7] # south base
g_nb(x) = α[8] # north base
g_uf(x) = α[9] # up face
g_bo(x) = α[10] # bottom
# define the trial space
Ug = TrialFESpace(V0,[g_wf,g_ef,g_sf,g_nf,g_wb,g_eb,g_sb,g_nb,g_uf,g_bo])
# define the weak problem
f(x) = 0.0 # ⇒ Laplace
a(u,v) =∫( ∇(u)⋅∇(v) )*dΩ # Dirichlet terms are built into the TrialFESpace, not here
b(v) = ∫( f*v )*dΩ #+ ∫( v*h )*dΓ #for a neumann term
# define the problem through the abstract type FEOperator
op = AffineFEOperator(a,b,Ug,V0)
ls = LUSolver()
solver = LinearFESolver(ls)
uh = solve(solver,op) # solve
# extract node values at pts
return uh
end
function tempout(bcs::T, pts) where T
uh = laplacesolve(bcs)
# extract node values at pts
return uh.(Point.(pts))
end
I'm trying to differentiate a function (bcs)->f(bcs,data,pts), where f is defined as f(bcs,data,pts) = norm(tempout(bcs,pts) .- data, 2)^2/length(data)
The error I receive is
ERROR: MethodError: no method matching
Float64(::ForwardDiff.Dual{ForwardDiff.Tag{var"#377#378", Float64}, Float64, 10})
Closest candidates are:
(::Type{T})(::Real, ::RoundingMode) where T<:AbstractFloat
@ Base rounding.jl:207
(::Type{T})(::T) where T<:Number
@ Core boot.jl:792
(::Type{T})(::AbstractChar) where T<:Union{AbstractChar, Number}
@ Base char.jl:50`
Clearly at some point the Dirichlet data is being defined as Float64, but I hope you might know where and how to resolve this issue. I'm using Optim.jl to solve this optimization problem, but if you know a way to solve this problem within the Gridap.jl ecosystem, I'm all ears.
The text was updated successfully, but these errors were encountered:
Hi all, happy holidays-
I'm trying to use Gridap to invert the Laplace problem to determine Dirichlet data on the boundaries given some point measurements on the interior. The idea is to minimize the squared residual between simulated and measured data. However, I am having trouble using ForwardDiff (finite differencing works, but I really want AD to speed up the optimization process).
Here is my program:
I'm trying to differentiate a function (bcs)->f(bcs,data,pts), where f is defined as
f(bcs,data,pts) = norm(tempout(bcs,pts) .- data, 2)^2/length(data)
The error I receive is
Clearly at some point the Dirichlet data is being defined as Float64, but I hope you might know where and how to resolve this issue. I'm using Optim.jl to solve this optimization problem, but if you know a way to solve this problem within the Gridap.jl ecosystem, I'm all ears.
The text was updated successfully, but these errors were encountered: