-
Notifications
You must be signed in to change notification settings - Fork 1
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
Embedded + Autodiff #67
Comments
Current state:
We have the code working for simplicial meshes. Moving to QUAD/HEX meshes, however, requires some modification of the cutting algorithm:
|
This comment will serve as a note regarding additional issues with comparability of GridapTopOpt and GridapEmbedded, and other issues that arrise in implementation of unfitted problems. We are actively investigating these. Distributed issues
Jordi: I have not solved this one yet, but here is an explanation and workaround:
This happens when there are touched ghost entries that do not belong to the local domain. Autodiff/analytic gradient issues
dJ_int_exact2(w) = ∫((-n_Γ⋅∇(g(fh)))*w/(norm ∘ (∇(φh))))dΓ +
∫(-n_S_Λ ⋅ (jump(g(fh)*m_k_Λ) * mean(w) / ∇ˢφ_Λ))dΛ +
∫(-n_S_Σ ⋅ (g(fh)*m_k_Σ * w / ∇ˢφ_Σ))dΣ
dJ_int_exact_vec2 = assemble_vector(dJ_int_exact2,V_φ) fails for
function Arrays.return_cache(
fg::Fields.FieldGradientArray{1,Polynomials.MonomialBasis{D,V}},
x::AbstractVector{<:Point}) where {D,V}
xi = testitem(x)
T = gradient_type(V,xi)
Polynomials._return_cache(fg,x,T,Val(false))
end
function Arrays.evaluate!(
cache,
fg::Fields.FieldGradientArray{1,Polynomials.MonomialBasis{D,V}},
x::AbstractVector{<:Point}) where {D,V}
Polynomials._evaluate!(cache,fg,x,Val(false))
end
Related error ERROR: MethodError: no method matching pos_neg_data(::Gridap.Arrays.LazyArray{…}, ::Gridap.Arrays.LazyArray{…})
Closest candidates are:
pos_neg_data(::AbstractArray{<:AbstractArray{<:Number}}, ::Gridap.Arrays.PosNegPartition)
@ Gridap C:\Users\n10915192\.julia\dev\Gridap\src\Geometry\Triangulations.jl:328
pos_neg_data(::AbstractArray, ::Gridap.Arrays.PosNegPartition)
@ Gridap C:\Users\n10915192\.julia\dev\Gridap\src\Geometry\Triangulations.jl:317
Stacktrace:
[1] lazy_map(k::Reindex{Gridap.Arrays.LazyArray{…}}, ids::Gridap.Arrays.LazyArray{FillArrays.Fill{…}, Int32, 1, Tuple{…}})
@ GridapTopOpt c:\Users\n10915192\.julia\dev\GridapTopOpt\src\GridapExtensions.jl:129
[2] autodiff_array_gradient(a::Gridap.FESpaces.var"#g#65"{…}, i_to_x::Gridap.Arrays.LazyArray{…}, j_to_i::Gridap.Arrays.LazyArray{…})
@ Gridap.Arrays C:\Users\n10915192\.julia\dev\Gridap\src\Arrays\Autodiff.jl:29
[3] _gradient(f::Function, uh::Gridap.FESpaces.SingleFieldFEFunction{GenericCellField{…}}, fuh::DomainContribution)
@ Gridap.FESpaces C:\Users\n10915192\.julia\dev\Gridap\src\FESpaces\FEAutodiff.jl:23
[4] gradient(f::GridapTopOpt.var"#_f#23"{…}, uh::Gridap.FESpaces.SingleFieldFEFunction{…})
@ Gridap.FESpaces C:\Users\n10915192\.julia\dev\Gridap\src\FESpaces\FEAutodiff.jl:5
[5] gradient(F::Function, uh::Vector{Gridap.FESpaces.SingleFieldFEFunction{GenericCellField{ReferenceDomain}}}, K::Int64)
@ GridapTopOpt c:\Users\n10915192\.julia\dev\GridapTopOpt\src\ChainRules.jl:20
[6] StateParamIntegrandWithMeasure(F::Function, U::TrialFESpace{…}, V_φ::Gridap.FESpaces.UnconstrainedFESpace{…}, U_reg::TrialFESpace{…}, assem_U::Gridap.FESpaces.GenericSparseMatrixAssembler, assem_deriv::Gridap.FESpaces.GenericSparseMatrixAssembler)
@ GridapTopOpt c:\Users\n10915192\.julia\dev\GridapTopOpt\src\ChainRules.jl:88
[7] StateParamIntegrandWithMeasure
@ c:\Users\n10915192\.julia\dev\GridapTopOpt\src\ChainRules.jl:344 [inlined]
[8] #326
@ c:\Users\n10915192\.julia\dev\GridapTopOpt\scripts\Embedded\Examples\2d_thermal_L.jl:92 [inlined]
[9] iterate
@ .\generator.jl:47 [inlined]
[10] _collect(c::Vector{…}, itr::Base.Generator{…}, ::Base.EltypeUnknown, isz::Base.HasShape{…})
@ Base .\array.jl:854
[11] collect_similar(cont::Vector{typeof(Vol)}, itr::Base.Generator{Vector{typeof(Vol)}, var"#326#328"{AffineFEStateMap{…}}})
@ Base .\array.jl:763
[12] map(f::Function, A::Vector{typeof(Vol)})
@ Base .\abstractarray.jl:3285
[13] (::var"#325#327")(::EmbeddedDiscretization{2, Float64})
@ Main c:\Users\n10915192\.julia\dev\GridapTopOpt\scripts\Embedded\Examples\2d_thermal_L.jl:89
[14] update_collection!(c::EmbeddedCollection, φh::Gridap.FESpaces.SingleFieldFEFunction{GenericCellField{ReferenceDomain}})
@ GridapTopOpt c:\Users\n10915192\.julia\dev\GridapTopOpt\src\Embedded\EmbeddedCollections.jl:50
[15] EmbeddedCollection(recipes::var"#325#327", bgmodel::UnstructuredDiscreteModel{…}, φ0::Gridap.FESpaces.SingleFieldFEFunction{…})
@ GridapTopOpt c:\Users\n10915192\.julia\dev\GridapTopOpt\src\Embedded\EmbeddedCollections.jl:41
[16] top-level scope
@ c:\Users\n10915192\.julia\dev\GridapTopOpt\scripts\Embedded\Examples\2d_thermal_L.jl:84
# Error 1
Γ = DifferentiableTriangulation(EmbeddedBoundary(cutgeo),V_φ)
dΓ = Measure(Γ,2get_order(V_φ))
dj(u,du,v) = jacobian(u->∫(u*v)dΓ,u)
dj(φh, get_trial_fe_basis(V_φ), get_fe_basis(V_φ))
# Error 2
Λ = SkeletonTriangulation(Triangulation(model))
dΛ = Measure(Λ,2*order)
dj(u,du,v) = jacobian(u->∫(jump(∇(u)) ⋅ jump(∇(v)))dΛ,u)
dj(φh, get_trial_fe_basis(V_φ), get_fe_basis(V_φ)) AgFEM issues
Related error ERROR: AssertionError: all_aggregated
Stacktrace:
[1] _aggregate_by_threshold_barrier(threshold::Float64, cell_to_unit_cut_meas::Gridap.Arrays.LazyArray{…}, facet_to_inoutcut::Vector{…}, cell_to_inoutcut::Vector{…}, loc::Int64, cell_to_coords::Gridap.Arrays.LazyArray{…}, cell_to_faces::Gridap.Arrays.Table{…}, face_to_cells::Gridap.Arrays.Table{…})
@ GridapEmbedded.AgFEM C:\Users\n10915192\.julia\dev\GridapEmbedded\src\AgFEM\CellAggregation.jl:178
[2] _aggregate_by_threshold(threshold::Float64, cut::EmbeddedDiscretization{…}, geo::DiscreteGeometry{…}, loc::Int64, facet_to_inoutcut::Vector{…})
@ GridapEmbedded.AgFEM C:\Users\n10915192\.julia\dev\GridapEmbedded\src\AgFEM\CellAggregation.jl:123
[3] aggregate(strategy::AggregateCutCellsByThreshold, cut::EmbeddedDiscretization{…}, geo::DiscreteGeometry{…}, in_or_out::Int64)
@ GridapEmbedded.AgFEM C:\Users\n10915192\.julia\dev\GridapEmbedded\src\AgFEM\CellAggregation.jl:80
[4] aggregate(strategy::AggregateCutCellsByThreshold, cut::EmbeddedDiscretization{…}, geo::DiscreteGeometry{…})
@ GridapEmbedded.AgFEM C:\Users\n10915192\.julia\dev\GridapEmbedded\src\AgFEM\CellAggregation.jl:7
[5] aggregate(strategy::AggregateCutCellsByThreshold, cut::EmbeddedDiscretization{2, Float64})
@ GridapEmbedded.AgFEM C:\Users\n10915192\.julia\dev\GridapEmbedded\src\AgFEM\CellAggregation.jl:3
[6] (::var"#333#335")(cutgeo::EmbeddedDiscretization{2, Float64})
@ Main c:\Users\n10915192\.julia\dev\GridapTopOpt\scripts\Embedded\Examples\2d_thermal_AgFEM.jl:79
[7] update_collection!(c::EmbeddedCollection, φh::Gridap.FESpaces.SingleFieldFEFunction{GenericCellField{ReferenceDomain}})
@ GridapTopOpt c:\Users\n10915192\.julia\dev\GridapTopOpt\src\Embedded\EmbeddedCollections.jl:50
[8] evaluate!(pcf::EmbeddedPDEConstrainedFunctionals{…}, φh::Gridap.FESpaces.SingleFieldFEFunction{…}; update_space::Bool)
@ GridapTopOpt c:\Users\n10915192\.julia\dev\GridapTopOpt\src\ChainRules.jl:1102
[9] evaluate!(pcf::EmbeddedPDEConstrainedFunctionals{…}, φh::Gridap.FESpaces.SingleFieldFEFunction{…})
@ GridapTopOpt c:\Users\n10915192\.julia\dev\GridapTopOpt\src\ChainRules.jl:1101
[10] iterate(m::AugmentedLagrangian, state::@NamedTuple{…})
@ GridapTopOpt c:\Users\n10915192\.julia\dev\GridapTopOpt\src\Optimisers\AugmentedLagrangian.jl:201
[11] top-level scope
@ c:\Users\n10915192\.julia\dev\GridapTopOpt\scripts\Embedded\Examples\2d_thermal_AgFEM.jl:122
Some type information was truncated. Use `show(err)` to see complete types. Other issues/TODOs
|
So here are some notes on the implementation of Autodiff for embedded triangulations. A similar discussion on this can be found in here.
Overview of the problem:
We distinguish two cases:
Case 1:
Case 2:
The text was updated successfully, but these errors were encountered: