|
1 |
| -""" |
2 |
| - abstract FieldArray{N, T, D} <: StaticArray{N, T, D} |
3 |
| -
|
4 |
| -Inheriting from this type will make it easy to create your own rank-D tensor types. A `FieldArray` |
5 |
| -will automatically define `getindex` and `setindex!` appropriately. An immutable |
6 |
| -`FieldArray` will be as performant as an `SArray` of similar length and element type, |
7 |
| -while a mutable `FieldArray` will behave similarly to an `MArray`. |
8 |
| -
|
9 |
| -Note that you must define the fields of any `FieldArray` subtype in column major order. If you |
10 |
| -want to use an alternative ordering you will need to pay special attention in providing your |
11 |
| -own definitions of `getindex`, `setindex!` and tuple conversion. |
12 |
| -
|
13 |
| -If you define a `FieldArray` which is parametric on the element type you should |
14 |
| -consider defining `similar_type` as in the `FieldVector` example. |
15 |
| -
|
16 |
| -
|
17 |
| -# Example |
18 |
| -
|
19 |
| - struct Stiffness <: FieldArray{Tuple{2,2,2,2}, Float64, 4} |
20 |
| - xxxx::Float64 |
21 |
| - yxxx::Float64 |
22 |
| - xyxx::Float64 |
23 |
| - yyxx::Float64 |
24 |
| - xxyx::Float64 |
25 |
| - yxyx::Float64 |
26 |
| - xyyx::Float64 |
27 |
| - yyyx::Float64 |
28 |
| - xxxy::Float64 |
29 |
| - yxxy::Float64 |
30 |
| - xyxy::Float64 |
31 |
| - yyxy::Float64 |
32 |
| - xxyy::Float64 |
33 |
| - yxyy::Float64 |
34 |
| - xyyy::Float64 |
35 |
| - yyyy::Float64 |
36 |
| - end |
37 |
| -""" |
38 |
| -abstract type FieldArray{N, T, D} <: StaticArray{N, T, D} end |
39 |
| - |
40 |
| -""" |
41 |
| - abstract FieldMatrix{N1, N2, T} <: FieldArray{Tuple{N1, N2}, 2} |
42 |
| -
|
43 |
| -Inheriting from this type will make it easy to create your own rank-two tensor types. A `FieldMatrix` |
44 |
| -will automatically define `getindex` and `setindex!` appropriately. An immutable |
45 |
| -`FieldMatrix` will be as performant as an `SMatrix` of similar length and element type, |
46 |
| -while a mutable `FieldMatrix` will behave similarly to an `MMatrix`. |
47 |
| -
|
48 |
| -Note that the fields of any subtype of `FieldMatrix` must be defined in column |
49 |
| -major order unless you are willing to implement your own `getindex`. |
50 |
| -
|
51 |
| -If you define a `FieldMatrix` which is parametric on the element type you |
52 |
| -should consider defining `similar_type` as in the `FieldVector` example. |
53 |
| -
|
54 |
| -# Example |
55 |
| -
|
56 |
| - struct Stress <: FieldMatrix{3, 3, Float64} |
57 |
| - xx::Float64 |
58 |
| - yx::Float64 |
59 |
| - zx::Float64 |
60 |
| - xy::Float64 |
61 |
| - yy::Float64 |
62 |
| - zy::Float64 |
63 |
| - xz::Float64 |
64 |
| - yz::Float64 |
65 |
| - zz::Float64 |
66 |
| - end |
67 |
| -
|
68 |
| - Note that the fields of any subtype of `FieldMatrix` must be defined in column major order. |
69 |
| - This means that formatting of constructors for literal `FieldMatrix` can be confusing. For example |
70 |
| -
|
71 |
| - sigma = Stress(1.0, 2.0, 3.0, |
72 |
| - 4.0, 5.0, 6.0, |
73 |
| - 7.0, 8.0, 9.0) |
74 |
| -
|
75 |
| - 3×3 Stress: |
76 |
| - 1.0 4.0 7.0 |
77 |
| - 2.0 5.0 8.0 |
78 |
| - 3.0 6.0 9.0 |
79 |
| -
|
80 |
| -will give you the transpose of what the multi-argument formatting suggests. For clarity, |
81 |
| -you may consider using the alternative |
82 |
| -
|
83 |
| - sigma = Stress(SA[1.0 2.0 3.0; |
84 |
| - 4.0 5.0 6.0; |
85 |
| - 7.0 8.0 9.0]) |
86 |
| -""" |
87 |
| -abstract type FieldMatrix{N1, N2, T} <: FieldArray{Tuple{N1, N2}, T, 2} end |
88 |
| - |
89 |
| -""" |
90 |
| - abstract FieldVector{N, T} <: FieldArray{Tuple{N}, 1} |
91 |
| -
|
92 |
| -Inheriting from this type will make it easy to create your own vector types. A `FieldVector` |
93 |
| -will automatically define `getindex` and `setindex!` appropriately. An immutable |
94 |
| -`FieldVector` will be as performant as an `SVector` of similar length and element type, |
95 |
| -while a mutable `FieldVector` will behave similarly to an `MVector`. |
96 |
| -
|
97 |
| -If you define a `FieldVector` which is parametric on the element type you |
98 |
| -should consider defining `similar_type` to preserve your array type through |
99 |
| -array operations as in the example below. |
100 |
| -
|
101 |
| -# Example |
102 |
| -
|
103 |
| - struct Vec3D{T} <: FieldVector{3, T} |
104 |
| - x::T |
105 |
| - y::T |
106 |
| - z::T |
107 |
| - end |
108 |
| -
|
109 |
| - StaticArrays.similar_type(::Type{<:Vec3D}, ::Type{T}, s::Size{(3,)}) where {T} = Vec3D{T} |
110 |
| -""" |
111 |
| -abstract type FieldVector{N, T} <: FieldArray{Tuple{N}, T, 1} end |
112 | 1 |
|
113 | 2 | @inline (::Type{FA})(x::Tuple) where {FA <: FieldArray} = construct_type(FA, x)(x...)
|
114 | 3 |
|
|
0 commit comments