xref: /libCEED/julia/LibCEED.jl/docs/src/Misc.md (revision dc8efd83546faf0200bf0bfcfb1678fae1874cc5)
1# Linear Algebra
2
3User Q-functions often perform small (1x1, 2x2, or 3x3) linear algebra
4operations (determinant, matrix-vector product, etc.) at every Q-point. For good
5performance, it is important to use specialized versions of these operations for
6the given size.
7
8If the matrix or vector is given in a statically sized container (e.g. using
9[StaticArrays.jl](https://github.com/JuliaArrays/StaticArrays.jl/)) then this
10happens automatically. However, if the matrix is not statically sized, and
11instead is given as, for example, a view into a larger array, then LibCEED.jl
12provides some convenient specialized functions.
13
14In order to allow for generic code, the [`CeedDim`](@ref) struct is used for
15dispatch. An object `D = CeedDim(dim)` can be created, and passed as a second
16argument to functions like `det` to choose the specialized implementations. In
17this case, `dim` should be known as a compile-time constant, otherwise it will
18result in a type instability, and give poor performance.
19
20For example:
21```@repl
22using LibCEED, LinearAlgebra
23
24dim = 3;
25J = rand(dim, dim);
26
27det(J) # Slow!
28det(J, CeedDim(dim)) # Fast!
29```
30
31```@docs
32CeedDim
33det(J, ::CeedDim{1})
34setvoigt
35getvoigt
36```
37