-
Notifications
You must be signed in to change notification settings - Fork 98
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
AutoDiff on sub-domains #661
Comments
Hi @ConnorMallon I can reproduce this in the ERROR: LoadError: AssertionError: A check failed
Stacktrace:
[1] macro expansion
@ ~/Code/jl/Gridap.jl/src/Helpers/Macros.jl:60 [inlined]
[2] get_triangulation(f::Gridap.MultiField.MultiFieldCellField{Gridap.CellData.ReferenceDomain})
@ Gridap.MultiField ~/Code/jl/Gridap.jl/src/MultiField/MultiFieldCellFields.jl:34
[3] get_triangulation
@ ~/Code/jl/Gridap.jl/src/MultiField/MultiFieldFEFunctions.jl:30 [inlined]
[4] _gradient(f::Function, uh::Gridap.MultiField.MultiFieldFEFunction{Gridap.MultiField.MultiFieldCellField{Gridap.CellData.ReferenceDomain}}, fuh::Gridap.CellData.DomainContribution)
@ Gridap.FESpaces ~/Code/jl/Gridap.jl/src/FESpaces/FEAutodiff.jl:22
[5] gradient(f::typeof(Main.Issue661.j), uh::Gridap.MultiField.MultiFieldFEFunction{Gridap.MultiField.MultiFieldCellField{Gridap.CellData.ReferenceDomain}})
@ Gridap.FESpaces ~/Code/jl/Gridap.jl/src/FESpaces/FEAutodiff.jl:5
[6] (::Gridap.Fields.var"#_gradient#83"{typeof(Main.Issue661.j)})(x::Gridap.MultiField.MultiFieldFEFunction{Gridap.MultiField.MultiFieldCellField{Gridap.CellData.ReferenceDomain}})
@ Gridap.Fields ~/Code/jl/Gridap.jl/src/Fields/AutoDiff.jl:20
[7] top-level scope
@ ~/Code/jl/Gridap.jl/issue_661.jl:49
[8] include(fname::String)
@ Base.MainInclude ./client.jl:444
[9] top-level scope
@ REPL[2]:1
in expression starting at /home/fverdugo/Code/jl/Gridap.jl/issue_661.jl:1 automatic differentiation for multi-field is not fully implemented now. |
Unfortunately this is not a dummy bug that can be solved easily. It is a whole functionality still not implemented in the library. To implement this one needs to understand:
On top of this, we first want to solve issue #584 since the solution of this issue can affect on how AD is implemented for multi-field |
Hey @amartinhuertas @fverdugo, seeing as multifield autodiff is fixed it would be nice to also have this functionality. The first problem I am having is in the function FESpaces._change_argument(
op::typeof(gradient),f,trian,uh::MultiFieldFEFunction)
U = get_fe_space(uh)
function g(cell_u)
single_fields = GenericCellField[]
nfields = length(U.spaces)
cell_dofs_field_offsets=_get_cell_dofs_field_offsets(uh)
for i in 1:nfields
view_range=cell_dofs_field_offsets[i]:cell_dofs_field_offsets[i+1]-1
cell_values_field = lazy_map(a->view(a,view_range),cell_u)
cf = CellField(U.spaces[i],cell_values_field)
push!(single_fields,cf)
end
xh = MultiFieldCellField(single_fields)
cell_grad = f(xh)
get_contribution(cell_grad,trian)
end
g
end The context is when we call the function in a specific sub-domain (trian). The Please see a5fd715 for what I have done in my forked repo and the target functionality test to reproduce the error. |
Hi @ConnorMallon , @amartinhuertas , @fverdugo, I'm getting the following error when trying to use autodiff for a problem with mixed-dimensional PDEs (a variable defined in a 2D domain and another defined on one of the boundaries):
Is this error related to this issue? If not, is it easier to solve? |
Hey @oriolcg, that problem can be solved by adding the triangulation that you are looping over at that point as an argument to the |
@oriolcg @ConnorMallon I will take a look at it whenever I have some time. Thanks for reporting |
@oriolcg do you have a mwe? |
I'll prepare one reproducer and post it here |
hey @amartinhuertas, have you had a chance to take a look at this? |
Hi @oriolcg ... could you please help us and prepare one reproducer of this issue? I want to work with both @ConnorMallon reproducers and yours, so that I can be sure that I am finding a solution that considers both cases (if they are diferent) |
Hi @amartinhuertas , yes I forgot about this issue. Here I attach a reproducer: module tmp
using Gridap
domain = (0.0, 1.0, 0.0, 1.0)
partition = (3,3)
model_Ω = CartesianDiscreteModel(domain,partition)
labels = get_face_labeling(model_Ω)
add_tag_from_tags!(labels,"surface",[3,4,6])
Ω = Interior(model_Ω)
Γ = Boundary(model_Ω,tags="surface")
order = 1
degree = 2*order
dΩ = Measure(Ω,degree)
dΓ = Measure(Γ,degree)
reffe = ReferenceFE(lagrangian,Float64,order)
V_Ω = TestFESpace(Ω,reffe,conformity=:H1)
V_Γ = TestFESpace(Γ,reffe,conformity=:H1)
U_Ω = TrialFESpace(V_Ω)
U_Γ = TrialFESpace(V_Γ)
Y = MultiFieldFESpace([V_Ω,V_Γ])
X = MultiFieldFESpace([U_Ω,U_Γ])
res((ϕ,η),(w,v)) = ∫(∇(ϕ)⋅∇(w) )dΩ + ∫( η*v )dΓ
op = FEOperator(res,X,Y)
(ϕₕ,ηₕ) = solve(op)
println(∑(∫(ϕₕ*ϕₕ)dΩ))
println(∑(∫(ηₕ*ηₕ)dΓ))
end |
Thanks! |
Hi @ConnorMallon @amartinhuertas , what's the status of this issue. I am still facing problems using autodiff in multifield problems defined in different domains. Do you have any work-around for this? |
Hey @oriolcg, I ended up not needing this functionality so I don't have a work-around. I am still happy however to help this get implemented. |
There are some cases when using Gridap and Gridap's Autodiff machinery together does not work. Here we have a problem where a FEFunction only exists in certain parts of the domain. It means that if we do something like get_cell_dof_values we get back an array for which some of the entries are empty. We have problems then using Autodiff in the multifield case where one field is empty and the other isnt at a given point. The following MWE gives the target functionality:
The text was updated successfully, but these errors were encountered: