# Assemble dirac delta in all nodes

**URL:** <https://discourse.julialang.org/t/assemble-dirac-delta-in-all-nodes/101063>\
**Category:** New to Julia\
**Tags:** question, package\
**Created:** [July 1, 2023, 8:33pm UTC](https://discourse.julialang.org/t/assemble-dirac-delta-in-all-nodes/101063 "2023-07-01T20:33:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mary/32/53139_2.png) [@mary](https://discourse.julialang.org/u/mary)\
**Post date:** [July 1, 2023, 8:33pm UTC](https://discourse.julialang.org/t/assemble-dirac-delta-in-all-nodes/101063/1 "2023-07-01T20:33:50Z")

</div>

Hi, I have a problem in assembling matrix of o in all nodes. can anyone help me? below is s sample which assemble o in domain for one point

```julia
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

```

i want to do this for all nodes not just x0. i write the code as below

```julia
co=Gridap.ReferenceFEs.get_node_coordinates(Ω)
function MatrixOf(fem_params)
δ = 1
    return assemble_matrix(fem_params.U0_Disp, fem_params.V0_Disp) do u, v
              0.5*sum(∫((x->(1/(2*π)*exp(-norm(x-x_i)^2 / 2 / δ^2))) * (∇(u))' ⊙ (C_mat ⊙ ∇(v))) for x_i in fem_params.co)fem_params.dΩ
    end
end
and the error is 

```

MethodError: no method matching +(::Integrand, ::Integrand)  
Closest candidates are:  
+(::Any, ::Any, ::Any, ::Any…) at operators.jl:591  
+(::Union{MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}}, ::T) where T at C:\Users\marya.julia\packages\MathOptInterface\goW8i\src\Utilities\functions.jl:1783  
+(::Tangent{P}, ::P) where P at C:\Users\marya.julia\packages\ChainRulesCore\0t04l\src\tangent\_arithmetic.jl:146  
…

Stacktrace:  
[1] add\_sum(x::Integrand, y::Integrand)  
@ Base .\reduce.jl:24  
[2] BottomRF  
@ .\reduce.jl:81 [inlined]  
[3] MappingRF  
@ .\reduce.jl:95 [inlined]  
[4] \_foldl\_impl  
@ .\reduce.jl:62 [inlined]  
[5] foldl\_impl  
@ .\reduce.jl:48 [inlined]  
[6] mapfoldl\_impl  
@ .\reduce.jl:44 [inlined]  
[7] #mapfoldl#259  
@ .\reduce.jl:170 [inlined]  
[8] mapfoldl  
@ .\reduce.jl:170 [inlined]  
[9] #mapreduce#263  
@ .\reduce.jl:302 [inlined]  
[10] mapreduce  
@ .\reduce.jl:302 [inlined]  
[11] #sum#266  
@ .\reduce.jl:528 [inlined]  
[12] sum  
@ .\reduce.jl:528 [inlined]  
[13] #sum#267  
@ .\reduce.jl:557 [inlined]  
[14] sum  
@ .\reduce.jl:557 [inlined]  
[15] (::var"#784#787"{NamedTuple{(:V0\_Disp, :U0\_Disp, :Q, :P, :Qf, :Pf, :np, :Ω, :dΩ, :n\_Γ\_Load, :dΓ\_Load, :co), 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}, TrialFESpace{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Nothing}}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{Int32}}, TrialFESpace{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, GenericCellField{ReferenceDomain}, Gridap.CellData.GenericMeasure, Vector{VectorValue{2, Float64}}}}, Int64})(u::Gridap.FESpaces.SingleFieldFEBasis{Gridap.FESpaces.TrialBasis, ReferenceDomain}, v::Gridap.FESpaces.SingleFieldFEBasis{Gridap.FESpaces.TestBasis, ReferenceDomain})  
@ Main .\In[228]:4  
[16] assemble\_matrix(f::var"#784#787"{NamedTuple{(:V0\_Disp, :U0\_Disp, :Q, :P, :Qf, :Pf, :np, :Ω, :dΩ, :n\_Γ\_Load, :dΓ\_Load, :co), 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}, TrialFESpace{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Nothing}}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{Int32}}, TrialFESpace{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, GenericCellField{ReferenceDomain}, Gridap.CellData.GenericMeasure, Vector{VectorValue{2, Float64}}}}, Int64}, 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  
[17] assemble\_matrix  
@ C:\Users\marya.julia\packages\Gridap\971dU\src\FESpaces\Assemblers.jl:342 [inlined]  
[18] MatrixOf(fem\_params::NamedTuple{(:V0\_Disp, :U0\_Disp, :Q, :P, :Qf, :Pf, :np, :Ω, :dΩ, :n\_Γ\_Load, :dΓ\_Load, :co), 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}, TrialFESpace{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Nothing}}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{Int32}}, TrialFESpace{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, GenericCellField{ReferenceDomain}, Gridap.CellData.GenericMeasure, Vector{VectorValue{2, Float64}}}})  
@ Main .\In[228]:3  
[19] top-level scope  
@ show.jl:1047

```julia
to be more clear i want to do optimization at each node not just one specified point
thank you
```
