I am using gridap for TO and like tutorial 18 i have defined o matrix but i am tackling with error that basis functions are not field which ∇ operate on that. evene in tutorial i couldnt find anywhere to define u as field.
this is the code in tutorial
function MatrixOf(fem_params)
x0 = VectorValue(0,300) # Position of the field to be optimized
δ = 1
return assemble_matrix(fem_params.U, fem_params.V) do u, v
∫((x->(1/(2*π)*exp(-norm(x - x0)^2 / 2 / δ^2))) * (∇(u) ⋅ ∇(v)) )fem_params.dΩ_c
end
end
and this is mine
function MatrixOf(fem_params)
return assemble_matrix(fem_params.U_Disp, fem_params.V0_Disp) do u, v
∫((0.5*C_mat)*(∇(u).∇(v)))fem_params.dΩ
end
end
and this is the error
type SingleFieldFEBasis has no field ∇
Stacktrace:
[1] getproperty(x::Gridap.FESpaces.SingleFieldFEBasis{Gridap.FESpaces.TrialBasis, ReferenceDomain}, sym::Symbol)
@ Gridap.CellData C:\Users\marya\.julia\packages\Gridap\971dU\src\CellData\CellFields.jl:674
[2] (::var"#155#156"{NamedTuple{(:V0_Disp, :U_Disp, :Q, :P, :Qf, :Pf, :np, :Ω, :dΩ, :dΓ_Load), Tuple{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{VectorValue{2, Int32}}}, TrialFESpace{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{VectorValue{2, Int32}}}}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Nothing}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Nothing}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{Int32}}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{Int32}}, Int64, BodyFittedTriangulation{2, 2, UnstructuredDiscreteModel{2, 2, Float64, Oriented}, UnstructuredGrid{2, 2, Float64, Oriented, Nothing}, Gridap.Arrays.IdentityVector{Int64}}, Gridap.CellData.GenericMeasure, Gridap.CellData.GenericMeasure}}})(u::Gridap.FESpaces.SingleFieldFEBasis{Gridap.FESpaces.TrialBasis, ReferenceDomain}, v::Gridap.FESpaces.SingleFieldFEBasis{Gridap.FESpaces.TestBasis, ReferenceDomain})
@ Main .\In[72]:4
[3] assemble_matrix(f::var"#155#156"{NamedTuple{(:V0_Disp, :U_Disp, :Q, :P, :Qf, :Pf, :np, :Ω, :dΩ, :dΓ_Load), Tuple{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{VectorValue{2, Int32}}}, TrialFESpace{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{VectorValue{2, Int32}}}}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Nothing}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Nothing}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{Int32}}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{Int32}}, Int64, BodyFittedTriangulation{2, 2, UnstructuredDiscreteModel{2, 2, Float64, Oriented}, UnstructuredGrid{2, 2, Float64, Oriented, Nothing}, Gridap.Arrays.IdentityVector{Int64}}, Gridap.CellData.GenericMeasure, Gridap.CellData.GenericMeasure}}}, a::Gridap.FESpaces.GenericSparseMatrixAssembler, U::TrialFESpace{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{VectorValue{2, Int32}}}}, V::Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{VectorValue{2, Int32}}})
@ Gridap.FESpaces C:\Users\marya\.julia\packages\Gridap\971dU\src\FESpaces\Assemblers.jl:285
[4] assemble_matrix(f::Function, U::TrialFESpace{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{VectorValue{2, Int32}}}}, V::Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{VectorValue{2, Int32}}})
@ Gridap.FESpaces C:\Users\marya\.julia\packages\Gridap\971dU\src\FESpaces\Assemblers.jl:342
[5] MatrixOf(fem_params::NamedTuple{(:V0_Disp, :U_Disp, :Q, :P, :Qf, :Pf, :np, :Ω, :dΩ, :dΓ_Load), Tuple{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{VectorValue{2, Int32}}}, TrialFESpace{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{VectorValue{2, Int32}}}}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Nothing}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Nothing}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{Int32}}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{Int32}}, Int64, BodyFittedTriangulation{2, 2, UnstructuredDiscreteModel{2, 2, Float64, Oriented}, UnstructuredGrid{2, 2, Float64, Oriented, Nothing}, Gridap.Arrays.IdentityVector{Int64}}, Gridap.CellData.GenericMeasure, Gridap.CellData.GenericMeasure}})
@ Main .\In[72]:3
[6] gf_pf(pf_vec::Vector{Float64}; β::Float64, η::Float64, fem_params::NamedTuple{(:V0_Disp, :U_Disp, :Q, :P, :Qf, :Pf, :np, :Ω, :dΩ, :dΓ_Load), Tuple{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{VectorValue{2, Int32}}}, TrialFESpace{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{VectorValue{2, Int32}}}}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Nothing}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Nothing}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{Int32}}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{Int32}}, Int64, BodyFittedTriangulation{2, 2, UnstructuredDiscreteModel{2, 2, Float64, Oriented}, UnstructuredGrid{2, 2, Float64, Oriented, Nothing}, Gridap.Arrays.IdentityVector{Int64}}, Gridap.CellData.GenericMeasure, Gridap.CellData.GenericMeasure}})
@ Main .\In[77]:7
[7] rrule(::typeof(gf_pf), pf_vec::Vector{Float64}; β::Float64, η::Float64, fem_params::NamedTuple{(:V0_Disp, :U_Disp, :Q, :P, :Qf, :Pf, :np, :Ω, :dΩ, :dΓ_Load), Tuple{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{VectorValue{2, Int32}}}, TrialFESpace{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{VectorValue{2, Int32}}}}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Nothing}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Nothing}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{Int32}}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{Int32}}, Int64, BodyFittedTriangulation{2, 2, UnstructuredDiscreteModel{2, 2, Float64, Oriented}, UnstructuredGrid{2, 2, Float64, Oriented, Nothing}, Gridap.Arrays.IdentityVector{Int64}}, Gridap.CellData.GenericMeasure, Gridap.CellData.GenericMeasure}})
@ Main .\In[77]:15
[8] chain_rrule_kw
@ C:\Users\marya\.julia\packages\Zygote\IoW2g\src\compiler\chainrules.jl:229 [inlined]
[9] macro expansion
@ C:\Users\marya\.julia\packages\Zygote\IoW2g\src\compiler\interface2.jl:0 [inlined]
[10] _pullback(::Zygote.Context, ::var"#gf_pf##kw", ::NamedTuple{(:β, :η, :fem_params), Tuple{Float64, Float64, NamedTuple{(:V0_Disp, :U_Disp, :Q, :P, :Qf, :Pf, :np, :Ω, :dΩ, :dΓ_Load), Tuple{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{VectorValue{2, Int32}}}, TrialFESpace{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{VectorValue{2, Int32}}}}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Nothing}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Nothing}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{Int32}}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{Int32}}, Int64, BodyFittedTriangulation{2, 2, UnstructuredDiscreteModel{2, 2, Float64, Oriented}, UnstructuredGrid{2, 2, Float64, Oriented, Nothing}, Gridap.Arrays.IdentityVector{Int64}}, Gridap.CellData.GenericMeasure, Gridap.CellData.GenericMeasure}}}}, ::typeof(gf_pf), ::Vector{Float64})
@ Zygote C:\Users\marya\.julia\packages\Zygote\IoW2g\src\compiler\interface2.jl:9
[11] _pullback
@ .\In[79]:3 [inlined]
[12] _pullback(::Zygote.Context, ::var"##gf_p#176", ::Float64, ::Float64, ::Float64, ::NamedTuple{(:V0_Disp, :U_Disp, :Q, :P, :Qf, :Pf, :np, :Ω, :dΩ, :dΓ_Load), Tuple{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{VectorValue{2, Int32}}}, TrialFESpace{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{VectorValue{2, Int32}}}}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Nothing}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Nothing}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{Int32}}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{Int32}}, Int64, BodyFittedTriangulation{2, 2, UnstructuredDiscreteModel{2, 2, Float64, Oriented}, UnstructuredGrid{2, 2, Float64, Oriented, Nothing}, Gridap.Arrays.IdentityVector{Int64}}, Gridap.CellData.GenericMeasure, Gridap.CellData.GenericMeasure}}, ::typeof(gf_p), ::Vector{Float64})
@ Zygote C:\Users\marya\.julia\packages\Zygote\IoW2g\src\compiler\interface2.jl:0
[13] _pullback
@ .\In[79]:1 [inlined]
[14] _pullback(::Zygote.Context, ::var"#gf_p##kw", ::NamedTuple{(:r, :β, :η, :fem_params), Tuple{Float64, Float64, Float64, NamedTuple{(:V0_Disp, :U_Disp, :Q, :P, :Qf, :Pf, :np, :Ω, :dΩ, :dΓ_Load), Tuple{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{VectorValue{2, Int32}}}, TrialFESpace{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{VectorValue{2, Int32}}}}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Nothing}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Nothing}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{Int32}}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{Int32}}, Int64, BodyFittedTriangulation{2, 2, UnstructuredDiscreteModel{2, 2, Float64, Oriented}, UnstructuredGrid{2, 2, Float64, Oriented, Nothing}, Gridap.Arrays.IdentityVector{Int64}}, Gridap.CellData.GenericMeasure, Gridap.CellData.GenericMeasure}}}}, ::typeof(gf_p), ::Vector{Float64})
@ Zygote C:\Users\marya\.julia\packages\Zygote\IoW2g\src\compiler\interface2.jl:0
[15] _pullback
@ .\In[79]:8 [inlined]
[16] _pullback(ctx::Zygote.Context, f::var"#178#180"{Float64, Float64, Float64, NamedTuple{(:V0_Disp, :U_Disp, :Q, :P, :Qf, :Pf, :np, :Ω, :dΩ, :dΓ_Load), Tuple{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{VectorValue{2, Int32}}}, TrialFESpace{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{VectorValue{2, Int32}}}}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Nothing}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Nothing}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{Int32}}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{Int32}}, Int64, BodyFittedTriangulation{2, 2, UnstructuredDiscreteModel{2, 2, Float64, Oriented}, UnstructuredGrid{2, 2, Float64, Oriented, Nothing}, Gridap.Arrays.IdentityVector{Int64}}, Gridap.CellData.GenericMeasure, Gridap.CellData.GenericMeasure}}}, args::Vector{Float64})
@ Zygote C:\Users\marya\.julia\packages\Zygote\IoW2g\src\compiler\interface2.jl:0
[17] _pullback(f::Function, args::Vector{Float64})
@ Zygote C:\Users\marya\.julia\packages\Zygote\IoW2g\src\compiler\interface.jl:34
[18] pullback(f::Function, args::Vector{Float64})
@ Zygote C:\Users\marya\.julia\packages\Zygote\IoW2g\src\compiler\interface.jl:40
[19] gradient(f::Function, args::Vector{Float64})
@ Zygote C:\Users\marya\.julia\packages\Zygote\IoW2g\src\compiler\interface.jl:75
[20] gf_p(p0::Vector{Float64}, grad::Vector{Float64}; r::Float64, β::Float64, η::Float64, fem_params::NamedTuple{(:V0_Disp, :U_Disp, :Q, :P, :Qf, :Pf, :np, :Ω, :dΩ, :dΓ_Load), Tuple{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{VectorValue{2, Int32}}}, TrialFESpace{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{VectorValue{2, Int32}}}}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Nothing}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Nothing}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{Int32}}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{Int32}}, Int64, BodyFittedTriangulation{2, 2, UnstructuredDiscreteModel{2, 2, Float64, Oriented}, UnstructuredGrid{2, 2, Float64, Oriented, Nothing}, Gridap.Arrays.IdentityVector{Int64}}, Gridap.CellData.GenericMeasure, Gridap.CellData.GenericMeasure}})
@ Main .\In[79]:8
[21] top-level scope
@ In[80]:5