# Matrix assembly

**URL:** <https://discourse.julialang.org/t/matrix-assembly/111324>\
**Category:** New to Julia\
**Created:** [March 7, 2024, 8:51pm UTC](https://discourse.julialang.org/t/matrix-assembly/111324 "2024-03-07T20:51:31Z")\
**Posts on this page:** 6\
**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:** [March 7, 2024, 8:51pm UTC](https://discourse.julialang.org/t/matrix-assembly/111324/1 "2024-03-07T20:51:31Z")

</div>

Hi,  
I am trying to understand this equation and implementing it in julia.

![image](https://global.discourse-cdn.com/julialang/original/3X/5/9/594bf91ce9fcfcc0fb4ba96b3dfa802e47964411.png)

where sigma is second order tensor assuming dimension n1_n1. and Nd is shape function matric for scalar value so dimension is 1_n2. How this multiplication can be done? I think it would be a third order tensor and if it is right how can I assemble that matric in Julia. I tried to find some examples on that but I couldnt.  
Thank you

---

<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:** [March 7, 2024, 8:52pm UTC](https://discourse.julialang.org/t/matrix-assembly/111324/2 "2024-03-07T20:52:55Z")

</div>

I assembled before matrices in trial and test spaces with same dimensions. but now i have 2 different dimensions

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [March 7, 2024, 9:05pm UTC](https://discourse.julialang.org/t/matrix-assembly/111324/3 "2024-03-07T21:05:45Z")

</div>

\bar d is likely a vector of size `n2`. I can’t make sense of that expression otherwise.

Then the meaning is rather clear: I’ll write it for you with more indices and summation over repeated indices is implied (I also call N\_d just N so it’s clearer what the indices are):

\frac{\partial\sigma\_{i,j}}{\partial \bar d\_k} = -2(1- N\_l \bar d\_l) \sigma\_{i,j} N\_k

This object indeed has 3 indices and is thus a 3-tensor.

I am not sure what you mean with “implementing it in Julia” but Julia supports multi-dimensional arrays out of the box. So you could use just a 3 dimensional array to store all the values.

---

<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:** [March 7, 2024, 9:14pm UTC](https://discourse.julialang.org/t/matrix-assembly/111324/4 "2024-03-07T21:14:01Z")

</div>

thank you! perfect explanation. so what is the dimension of this 3rd order tensor? n1_n1_n2?  
also for coding part i used gridap FE package like below

```julia
function dσfun(ε, ε_in,s_in)
    σ_elas = C_mat⊙ε
    if tr(ε_in) >= 0
        dσ = (2 * s_in)*σ_elas
    elseif tr(ε_in) < 0
        dσ = (2 * s_in)*P_dev ⊙ σ_elas
    end
    return dσ
end
function MatrixdAs(pth,uh,sh;fem_params)
    dAs_Disp(u,pth,uh,sh,s) = ((p->Em(p))∘pth) * ((dσfun∘(ε(u), ε(uh), sh)) * s)
    dAs_mat = assemble_matrix(fem_params.V0_Disp, fem_params.U_PF) do u,s
        ∫(dAs_Disp(u,pth,uh,sh,s))fem_params.dΩ
    end
    return dAs_mat
end

```

but it can not assemble that matrix and getting this error

```julia
MethodError: no method matching Float64(::SymTensorValue{2, Float64, 3})
Closest candidates are:
  (::Type{T})(::T) where T<:Number at boot.jl:772
  (::Type{T})(::AbstractChar) where T<:Union{AbstractChar, Number} at char.jl:50
  (::Type{T})(::Base.TwicePrecision) where T<:Number at twiceprecision.jl:266
  ...

Stacktrace:
  [1] convert(#unused#::Type{Float64}, x::SymTensorValue{2, Float64, 3})
    @ Base .\number.jl:7
  [2] setindex!(A::Vector{Float64}, x::SymTensorValue{2, Float64, 3}, i1::Int64)
    @ Base .\array.jl:966
  [3] add_entry!(#unused#::typeof(+), a::Gridap.Algebra.InserterCSC{Float64, Int64}, v::SymTensorValue{2, Float64, 3}, i::Int32, j::Int32)
    @ Gridap.Algebra C:\Users\marya\.julia\packages\Gridap\971dU\src\Algebra\SparseMatrixCSC.jl:132
  [4] _add_entries!
    @ C:\Users\marya\.julia\packages\Gridap\971dU\src\Algebra\AlgebraInterfaces.jl:149 [inlined]
  [5] add_entries!
    @ C:\Users\marya\.julia\packages\Gridap\971dU\src\Algebra\AlgebraInterfaces.jl:127 [inlined]
  [6] evaluate!(cache::Nothing, k::Gridap.Arrays.AddEntriesMap{typeof(+)}, A::Gridap.Algebra.InserterCSC{Float64, Int64}, v::Matrix{SymTensorValue{2, Float64, 3}}, i::Vector{Int32}, j::Vector{Int32})
    @ Gridap.Arrays C:\Users\marya\.julia\packages\Gridap\971dU\src\Arrays\AlgebraMaps.jl:47
  [7] _numeric_loop_matrix!(mat::Gridap.Algebra.InserterCSC{Float64, Int64}, caches::Tuple{Nothing, Tuple{Tuple{Nothing, Tuple{Gridap.Arrays.CachedMatrix{SymTensorValue{2, Float64, 3}, Matrix{SymTensorValue{2, Float64, 3}}}, Gridap.Arrays.CachedVector{Float64, Vector{Float64}}}, Tuple{Tuple{Tuple{Nothing, Gridap.Arrays.CachedArray{SymTensorValue{2, Float64, 3}, 3, Array{SymTensorValue{2, Float64, 3}, 3}}, Tuple{Tuple{Tuple{Nothing, Gridap.Arrays.CachedVector{Float64, Vector{Float64}}, Tuple{Tuple{Tuple{Nothing, Gridap.Arrays.CachedVector{Float64, Vector{Float64}}, Tuple{Tuple{Tuple{Nothing, Gridap.Arrays.CachedVector{Float64, Vector{Float64}}, Tuple{Tuple{Tuple{Nothing, Gridap.Arrays.CachedVector{Float64, Vector{Float64}}, Tuple{Gridap.Arrays.CachedVector{Int32, Vector{Int32}}}}, Gridap.Arrays.IndexItemPair{Int64, Vector{Float64}}}, Nothing}}, Gridap.Arrays.IndexItemPair{Int64, Vector{Float64}}}}}, Gridap.Arrays.IndexItemPair{Int64, Vector{Float64}}}}}, Gridap.Arrays.IndexItemPair{Int64, Vector{Float64}}}, Tuple{Tuple{Nothing, Gridap.Arrays.CachedArray{SymTensorValue{2, Float64, 3}, 3, Array{SymTensorValue{2, Float64, 3}, 3}}, Tuple{Tuple{Tuple{Nothing, Gridap.Arrays.CachedArray{SymTensorValue{2, Float64, 3}, 3, Array{SymTensorValue{2, Float64, 3}, 3}}, Tuple{Tuple{Tuple{Nothing, Gridap.Arrays.CachedArray{SymTensorValue{2, Float64, 3}, 3, Array{SymTensorValue{2, Float64, 3}, 3}}, Tuple{Tuple{Tuple{Nothing, Nothing, Tuple{Tuple{Tuple{Nothing, Gridap.Arrays.CachedMatrix{TensorValue{2, 2, Float64, 4}, Matrix{TensorValue{2, 2, Float64, 4}}}, Tuple{Tuple{Tuple{Nothing, Gridap.Arrays.CachedVector{TensorValue{2, 2, Float64, 4}, Vector{TensorValue{2, 2, Float64, 4}}}, Tuple{Tuple{Tuple{Tuple{Tuple{Nothing, Nothing, Tuple{Tuple{Tuple{Nothing, Nothing, Tuple{Tuple{Tuple{Nothing, Gridap.Arrays.CachedVector{VectorValue{2, Float64}, Vector{VectorValue{2, Float64}}}, Tuple{Gridap.Arrays.CachedVector{Int64, Vector{Int64}}}}, Gridap.Arrays.IndexItemPair{Int64, Vector{VectorValue{2, Float64}}}}, Nothing}}, Gridap.Arrays.IndexItemPair{Int64, TensorValue{2, 2, Float64, 4}}}}}, Gridap.Arrays.IndexItemPair{Int64, ConstantField{TensorValue{2, 2, Float64, 4}}}}, Gridap.Arrays.CachedVector{TensorValue{2, 2, Float64, 4}, Vector{TensorValue{2, 2, Float64, 4}}}, Tuple{Nothing}}, Gridap.Arrays.IndexItemPair{Int64, Vector{TensorValue{2, 2, Float64, 4}}}}}}, Gridap.Arrays.IndexItemPair{Int64, Vector{TensorValue{2, 2, Float64, 4}}}}, Nothing}}, Gridap.Arrays.IndexItemPair{Int64, Matrix{TensorValue{2, 2, Float64, 4}}}}}}, Gridap.Arrays.IndexItemPair{Int64, Gridap.Fields.TransposeFieldIndices{Matrix{TensorValue{2, 2, Float64, 4}}, TensorValue{2, 2, Float64, 4}}}}}}, Gridap.Arrays.IndexItemPair{Int64, Array{SymTensorValue{2, Float64, 3}, 3}}}, Tuple{Tuple{Nothing, Gridap.Arrays.CachedVector{SymTensorValue{2, Float64, 3}, Vector{SymTensorValue{2, Float64, 3}}}, Tuple{Tuple{Tuple{Nothing, Gridap.Arrays.CachedVector{TensorValue{2, 2, Float64, 4}, Vector{TensorValue{2, 2, Float64, 4}}}, Tuple{Tuple{Tuple{Nothing, Gridap.Arrays.CachedVector{TensorValue{2, 2, Float64, 4}, Vector{TensorValue{2, 2, Float64, 4}}}, Tuple{Tuple{Tuple{Tuple{Tuple{Nothing, Nothing, Tuple{Tuple{Tuple{Nothing, Nothing, Tuple{Tuple{Tuple{Nothing, Gridap.Arrays.CachedVector{VectorValue{2, Float64}, Vector{VectorValue{2, Float64}}}, Tuple{Gridap.Arrays.CachedVector{Int64, Vector{Int64}}}}, Gridap.Arrays.IndexItemPair{Int64, Vector{VectorValue{2, Float64}}}}, Nothing}}, Gridap.Arrays.IndexItemPair{Int64, TensorValue{2, 2, Float64, 4}}}}}, Gridap.Arrays.IndexItemPair{Int64, ConstantField{TensorValue{2, 2, Float64, 4}}}}, Gridap.Arrays.CachedVector{TensorValue{2, 2, Float64, 4}, Vector{TensorValue{2, 2, Float64, 4}}}, Tuple{Nothing}}, Gridap.Arrays.IndexItemPair{Int64, Vector{TensorValue{2, 2, Float64, 4}}}}}}, Gridap.Arrays.IndexItemPair{Int64, Vector{TensorValue{2, 2, Float64, 4}}}}, Tuple{Tuple{Nothing, Gridap.Arrays.CachedVector{TensorValue{2, 2, Float64, 4}, Vector{TensorValue{2, 2, Float64, 4}}}, Tuple{Tuple{Tuple{Nothing, Gridap.Arrays.CachedVector{Float64, Vector{Float64}}, Tuple{Gridap.Arrays.CachedVector{Int32, Vector{Int32}}}}, Gridap.Arrays.IndexItemPair{Int64, Vector{Float64}}}, Nothing}}, Gridap.Arrays.IndexItemPair{Int64, Vector{TensorValue{2, 2, Float64, 4}}}}}}, Gridap.Arrays.IndexItemPair{Int64, Vector{TensorValue{2, 2, Float64, 4}}}}}}, Gridap.Arrays.IndexItemPair{Int64, Vector{SymTensorValue{2, Float64, 3}}}}, Tuple{Tuple{Nothing, Gridap.Arrays.CachedVector{Float64, Vector{Float64}}, Tuple{Tuple{Tuple{Nothing, Gridap.Arrays.CachedVector{Float64, Vector{Float64}}, Tuple{Gridap.Arrays.CachedVector{Int32, Vector{Int32}}}}, Gridap.Arrays.IndexItemPair{Int64, Vector{Float64}}}, Nothing}}, Gridap.Arrays.IndexItemPair{Int64, Vector{Float64}}}}}, Gridap.Arrays.IndexItemPair{Int64, Array{SymTensorValue{2, Float64, 3}, 3}}}, Nothing}}, Gridap.Arrays.IndexItemPair{Int64, Array{SymTensorValue{2, Float64, 3}, 3}}}}}, Gridap.Arrays.IndexItemPair{Int64, Array{SymTensorValue{2, Float64, 3}, 3}}}, Nothing, Tuple{Tuple{Tuple{Tuple{Nothing, Nothing, Tuple{Tuple{Tuple{Nothing, Nothing, Tuple{Tuple{Tuple{Nothing, Gridap.Arrays.CachedVector{VectorValue{2, Float64}, Vector{VectorValue{2, Float64}}}, Tuple{Gridap.Arrays.CachedVector{Int64, Vector{Int64}}}}, Gridap.Arrays.IndexItemPair{Int64, Vector{VectorValue{2, Float64}}}}, Nothing}}, Gridap.Arrays.IndexItemPair{Int64, TensorValue{2, 2, Float64, 4}}}}}, Gridap.Arrays.IndexItemPair{Int64, ConstantField{TensorValue{2, 2, Float64, 4}}}}, Gridap.Arrays.CachedVector{TensorValue{2, 2, Float64, 4}, Vector{TensorValue{2, 2, Float64, 4}}}, Tuple{Nothing}}, Gridap.Arrays.IndexItemPair{Int64, Vector{TensorValue{2, 2, Float64, 4}}}}}}, Gridap.Arrays.IndexItemPair{Int64, Matrix{SymTensorValue{2, Float64, 3}}}}, Gridap.Arrays.CachedVector{Int32, Vector{Int32}}, Gridap.Arrays.CachedVector{Int32, Vector{Int32}}}, cell_vals::Gridap.Arrays.LazyArray{FillArrays.Fill{IntegrationMap, 1, Tuple{Base.OneTo{Int64}}}, Matrix{SymTensorValue{2, Float64, 3}}, 1, Tuple{Gridap.Arrays.LazyArray{FillArrays.Fill{Gridap.Fields.BroadcastingFieldOpMap{typeof(*)}, 1, Tuple{Base.OneTo{Int64}}}, Array{SymTensorValue{2, Float64, 3}, 3}, 1, Tuple{Gridap.Arrays.LazyArray{FillArrays.Fill{Gridap.Fields.BroadcastingFieldOpMap{var"#78#81"}, 1, Tuple{Base.OneTo{Int64}}}, Vector{Float64}, 1, Tuple{Gridap.Arrays.LazyArray{FillArrays.Fill{Gridap.Fields.BroadcastingFieldOpMap{var"#31#32"}, 1, Tuple{Base.OneTo{Int64}}}, Vector{Float64}, 1, Tuple{Gridap.Arrays.LazyArray{FillArrays.Fill{Gridap.Fields.LinearCombinationMap{Colon}, 1, Tuple{Base.OneTo{Int64}}}, Vector{Float64}, 1, Tuple{Gridap.Arrays.LazyArray{FillArrays.Fill{Broadcasting{Gridap.Arrays.PosNegReindex{Vector{Float64}, Vector{Float64}}}, 1, Tuple{Base.OneTo{Int64}}}, Vector{Float64}, 1, Tuple{Gridap.Arrays.Table{Int32, Vector{Int32}, Vector{Int32}}}}, Gridap.Arrays.CompressedArray{Matrix{Float64}, 1, Vector{Matrix{Float64}}, Vector{Int8}}}}}}}}, Gridap.Arrays.LazyArray{FillArrays.Fill{Gridap.Fields.BroadcastingFieldOpMap{typeof(*)}, 1, Tuple{Base.OneTo{Int64}}}, Array{SymTensorValue{2, Float64, 3}, 3}, 1, Tuple{Gridap.Arrays.LazyArray{FillArrays.Fill{Gridap.Fields.BroadcastingFieldOpMap{typeof(dσfun)}, 1, Tuple{Base.OneTo{Int64}}}, Array{SymTensorValue{2, Float64, 3}, 3}, 1, Tuple{Gridap.Arrays.LazyArray{FillArrays.Fill{Gridap.Fields.BroadcastingFieldOpMap{typeof(symmetric_part)}, 1, Tuple{Base.OneTo{Int64}}}, Array{SymTensorValue{2, Float64, 3}, 3}, 1, Tuple{Gridap.Arrays.LazyArray{FillArrays.Fill{Gridap.Fields.TransposeMap, 1, Tuple{Base.OneTo{Int64}}}, Gridap.Fields.TransposeFieldIndices{Matrix{TensorValue{2, 2, Float64, 4}}, TensorValue{2, 2, Float64, 4}}, 1, Tuple{Gridap.Arrays.LazyArray{FillArrays.Fill{Gridap.Fields.BroadcastingFieldOpMap{typeof(dot)}, 1, Tuple{Base.OneTo{Int64}}}, Matrix{TensorValue{2, 2, Float64, 4}}, 1, Tuple{Gridap.Arrays.LazyArray{FillArrays.Fill{Broadcasting{typeof(pinvJt)}, 1, Tuple{Base.OneTo{Int64}}}, Vector{TensorValue{2, 2, Float64, 4}}, 1, Tuple{Gridap.Arrays.LazyArray{Gridap.Arrays.LazyArray{FillArrays.Fill{typeof(constant_field), 1, Tuple{Base.OneTo{Int64}}}, ConstantField{TensorValue{2, 2, Float64, 4}}, 1, Tuple{Gridap.Arrays.LazyArray{FillArrays.Fill{Gridap.Fields.LinearCombinationMap{Colon}, 1, Tuple{Base.OneTo{Int64}}}, TensorValue{2, 2, Float64, 4}, 1, Tuple{Gridap.Arrays.LazyArray{FillArrays.Fill{Broadcasting{Reindex{Vector{VectorValue{2, Float64}}}}, 1, Tuple{Base.OneTo{Int64}}}, Vector{VectorValue{2, Float64}}, 1, Tuple{Gridap.Arrays.Table{Int64, Vector{Int64}, Vector{Int32}}}}, Gridap.Arrays.CompressedArray{Vector{VectorValue{2, Float64}}, 1, Vector{Vector{VectorValue{2, Float64}}}, Vector{Int8}}}}}}, Vector{TensorValue{2, 2, Float64, 4}}, 1, Tuple{Gridap.Arrays.CompressedArray{Vector{VectorValue{2, Float64}}, 1, Vector{Vector{VectorValue{2, Float64}}}, Vector{Int8}}}}}}, Gridap.Arrays.CompressedArray{Matrix{TensorValue{2, 2, Float64, 4}}, 1, Vector{Matrix{TensorValue{2, 2, Float64, 4}}}, Vector{Int8}}}}}}}}, Gridap.Arrays.LazyArray{FillArrays.Fill{Gridap.Fields.BroadcastingFieldOpMap{typeof(symmetric_part)}, 1, Tuple{Base.OneTo{Int64}}}, Vector{SymTensorValue{2, Float64, 3}}, 1, Tuple{Gridap.Arrays.LazyArray{FillArrays.Fill{Gridap.Fields.BroadcastingFieldOpMap{typeof(dot)}, 1, Tuple{Base.OneTo{Int64}}}, Vector{TensorValue{2, 2, Float64, 4}}, 1, Tuple{Gridap.Arrays.LazyArray{FillArrays.Fill{Broadcasting{typeof(pinvJt)}, 1, Tuple{Base.OneTo{Int64}}}, Vector{TensorValue{2, 2, Float64, 4}}, 1, Tuple{Gridap.Arrays.LazyArray{Gridap.Arrays.LazyArray{FillArrays.Fill{typeof(constant_field), 1, Tuple{Base.OneTo{Int64}}}, ConstantField{TensorValue{2, 2, Float64, 4}}, 1, Tuple{Gridap.Arrays.LazyArray{FillArrays.Fill{Gridap.Fields.LinearCombinationMap{Colon}, 1, Tuple{Base.OneTo{Int64}}}, TensorValue{2, 2, Float64, 4}, 1, Tuple{Gridap.Arrays.LazyArray{FillArrays.Fill{Broadcasting{Reindex{Vector{VectorValue{2, Float64}}}}, 1, Tuple{Base.OneTo{Int64}}}, Vector{VectorValue{2, Float64}}, 1, Tuple{Gridap.Arrays.Table{Int64, Vector{Int64}, Vector{Int32}}}}, Gridap.Arrays.CompressedArray{Vector{VectorValue{2, Float64}}, 1, Vector{Vector{VectorValue{2, Float64}}}, Vector{Int8}}}}}}, Vector{TensorValue{2, 2, Float64, 4}}, 1, Tuple{Gridap.Arrays.CompressedArray{Vector{VectorValue{2, Float64}}, 1, Vector{Vector{VectorValue{2, Float64}}}, Vector{Int8}}}}}}, Gridap.Arrays.LazyArray{FillArrays.Fill{Gridap.Fields.LinearCombinationMap{Colon}, 1, Tuple{Base.OneTo{Int64}}}, Vector{TensorValue{2, 2, Float64, 4}}, 1, Tuple{Gridap.Arrays.LazyArray{FillArrays.Fill{Broadcasting{Gridap.Arrays.PosNegReindex{Vector{Float64}, Vector{Float64}}}, 1, Tuple{Base.OneTo{Int64}}}, Vector{Float64}, 1, Tuple{Gridap.Arrays.Table{Int32, Vector{Int32}, Vector{Int32}}}}, Gridap.Arrays.CompressedArray{Matrix{TensorValue{2, 2, Float64, 4}}, 1, Vector{Matrix{TensorValue{2, 2, Float64, 4}}}, Vector{Int8}}}}}}}}, Gridap.Arrays.LazyArray{FillArrays.Fill{Gridap.Fields.LinearCombinationMap{Colon}, 1, Tuple{Base.OneTo{Int64}}}, Vector{Float64}, 1, Tuple{Gridap.Arrays.LazyArray{FillArrays.Fill{Broadcasting{Gridap.Arrays.PosNegReindex{Vector{Float64}, Vector{Float64}}}, 1, Tuple{Base.OneTo{Int64}}}, Vector{Float64}, 1, Tuple{Gridap.Arrays.Table{Int32, Vector{Int32}, Vector{Int32}}}}, Gridap.Arrays.CompressedArray{Matrix{Float64}, 1, Vector{Matrix{Float64}}, Vector{Int8}}}}}}, Gridap.Arrays.CompressedArray{Matrix{Float64}, 1, Vector{Matrix{Float64}}, Vector{Int8}}}}}}, Gridap.Arrays.CompressedArray{Vector{Float64}, 1, Vector{Vector{Float64}}, Vector{Int8}}, Gridap.Arrays.LazyArray{Gridap.Arrays.LazyArray{FillArrays.Fill{typeof(constant_field), 1, Tuple{Base.OneTo{Int64}}}, ConstantField{TensorValue{2, 2, Float64, 4}}, 1, Tuple{Gridap.Arrays.LazyArray{FillArrays.Fill{Gridap.Fields.LinearCombinationMap{Colon}, 1, Tuple{Base.OneTo{Int64}}}, TensorValue{2, 2, Float64, 4}, 1, Tuple{Gridap.Arrays.LazyArray{FillArrays.Fill{Broadcasting{Reindex{Vector{VectorValue{2, Float64}}}}, 1, Tuple{Base.OneTo{Int64}}}, Vector{VectorValue{2, Float64}}, 1, Tuple{Gridap.Arrays.Table{Int64, Vector{Int64}, Vector{Int32}}}}, Gridap.Arrays.CompressedArray{Vector{VectorValue{2, Float64}}, 1, Vector{Vector{VectorValue{2, Float64}}}, Vector{Int8}}}}}}, Vector{TensorValue{2, 2, Float64, 4}}, 1, Tuple{Gridap.Arrays.CompressedArray{Vector{VectorValue{2, Float64}}, 1, Vector{Vector{VectorValue{2, Float64}}}, Vector{Int8}}}}}}, cell_rows::Gridap.Arrays.Table{Int32, Vector{Int32}, Vector{Int32}}, cell_cols::Gridap.Arrays.Table{Int32, Vector{Int32}, Vector{Int32}})
    @ Gridap.FESpaces C:\Users\marya\.julia\packages\Gridap\971dU\src\FESpaces\SparseMatrixAssemblers.jl:261
  [8] numeric_loop_matrix!(A::Gridap.Algebra.InserterCSC{Float64, Int64}, a::Gridap.FESpaces.GenericSparseMatrixAssembler, matdata::Tuple{Vector{Any}, Vector{Any}, Vector{Any}})
    @ Gridap.FESpaces C:\Users\marya\.julia\packages\Gridap\971dU\src\FESpaces\SparseMatrixAssemblers.jl:248
  [9] assemble_matrix(a::Gridap.FESpaces.GenericSparseMatrixAssembler, matdata::Tuple{Vector{Any}, Vector{Any}, Vector{Any}})
    @ Gridap.FESpaces C:\Users\marya\.julia\packages\Gridap\971dU\src\FESpaces\SparseMatrixAssemblers.jl:107
 [10] assemble_matrix(f::var"#79#82"{NamedTuple{(:V0_Disp, :U_PF, :V0_PF, :Q, :P, :Qf, :Pf, :np, :Ω, :dΩ, :n_Γ_Load, :dΓ_Load), Tuple{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{VectorValue{2, Int32}}}, TrialFESpace{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{Int32}}}, Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{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}}, Gridap.CellData.OperationCellField{ReferenceDomain}, Gridap.FESpaces.SingleFieldFEFunction{GenericCellField{ReferenceDomain}}, Gridap.FESpaces.SingleFieldFEFunction{GenericCellField{ReferenceDomain}}, var"#dAs_Disp#80"}, a::Gridap.FESpaces.GenericSparseMatrixAssembler, U::Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{VectorValue{2, Int32}}}, V::TrialFESpace{Gridap.FESpaces.UnconstrainedFESpace{Vector{Float64}, Gridap.FESpaces.NodeToDofGlue{Int32}}})
    @ Gridap.FESpaces C:\Users\marya\.julia\packages\Gridap\971dU\src\FESpaces\Assemblers.jl:285
 [11] assemble_matrix
    @ C:\Users\marya\.julia\packages\Gridap\971dU\src\FESpaces\Assemblers.jl:342 [inlined]
 [12] #MatrixdAs#77
    @ .\In[48]:9 [inlined]
 [13] top-level scope
    @ In[48]:14

```

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [March 7, 2024, 9:16pm UTC](https://discourse.julialang.org/t/matrix-assembly/111324/5 "2024-03-07T21:16:32Z")

</div>

> [@mary](#):
>
> thank you! perfect explanation. so what is the dimension of this 3rd order tensor? n1_n1_n2?

You can choose how you want to arrange the dimensions. Choose whatever will be practical in the following code.

> [@mary](#):
>
> also for coding part i used gridap FE package like below

I am sorry, but I am not familiar with this package. So someone else needs to chime in and comment on that 🙂

---

<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:** [March 7, 2024, 9:17pm UTC](https://discourse.julialang.org/t/matrix-assembly/111324/6 "2024-03-07T21:17:32Z")

</div>

thank you the indices notation helps a lot
