1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 """Module for the manipulation of alignment tensors."""
25
26
27 from numpy.linalg import eigvals
28
29
31 """The dAi/dAxx gradient.
32
33 This function will modify the A matrix to be equal to::
34
35 dAi | 1 0 0 |
36 ---- = | 0 0 0 |
37 dAxx | 0 0 -1 |
38
39
40 @param A: The alignment tensor object.
41 @type A: numpy rank-2 3D tensor
42 """
43
44
45 A[0, 0] = 1.0; A[0, 1] = 0.0; A[0, 2] = 0.0
46 A[1, 0] = 0.0; A[1, 1] = 0.0; A[1, 2] = 0.0
47 A[2, 0] = 0.0; A[2, 1] = 0.0; A[2, 2] = -1.0
48
49
51 """The dAi/dAyy gradient.
52
53 This function will modify the A matrix to be equal to::
54
55 dAi | 0 0 0 |
56 ---- = | 0 1 0 |
57 dAyy | 0 0 -1 |
58
59
60 @param A: The alignment tensor object.
61 @type A: numpy rank-2 3D tensor
62 """
63
64
65 A[0, 0] = 0.0; A[0, 1] = 0.0; A[0, 2] = 0.0
66 A[1, 0] = 0.0; A[1, 1] = 1.0; A[1, 2] = 0.0
67 A[2, 0] = 0.0; A[2, 1] = 0.0; A[2, 2] = -1.0
68
69
71 """The dAi/dAxy gradient.
72
73 This function will modify the A matrix to be equal to::
74
75 dAi | 0 1 0 |
76 ---- = | 1 0 0 |
77 dAxy | 0 0 0 |
78
79
80 @param A: The alignment tensor object.
81 @type A: numpy rank-2 3D tensor
82 """
83
84
85 A[0, 0] = 0.0; A[0, 1] = 1.0; A[0, 2] = 0.0
86 A[1, 0] = 1.0; A[1, 1] = 0.0; A[1, 2] = 0.0
87 A[2, 0] = 0.0; A[2, 1] = 0.0; A[2, 2] = 0.0
88
89
91 """The dAi/dAxz gradient.
92
93 This function will modify the A matrix to be equal to::
94
95 dAi | 0 0 1 |
96 ---- = | 0 0 0 |
97 dAxz | 1 0 0 |
98
99
100 @param A: The alignment tensor object.
101 @type A: numpy rank-2 3D tensor
102 """
103
104
105 A[0, 0] = 0.0; A[0, 1] = 0.0; A[0, 2] = 1.0
106 A[1, 0] = 0.0; A[1, 1] = 0.0; A[1, 2] = 0.0
107 A[2, 0] = 1.0; A[2, 1] = 0.0; A[2, 2] = 0.0
108
109
111 """The dAi/dAyz gradient.
112
113 This function will modify the A matrix to be equal to::
114
115 dAi | 0 0 0 |
116 ---- = | 0 0 1 |
117 dAyz | 0 1 0 |
118
119
120 @param A: The alignment tensor object.
121 @type A: numpy rank-2 3D tensor
122 """
123
124
125 A[0, 0] = 0.0; A[0, 1] = 0.0; A[0, 2] = 0.0
126 A[1, 0] = 0.0; A[1, 1] = 0.0; A[1, 2] = 1.0
127 A[2, 0] = 0.0; A[2, 1] = 1.0; A[2, 2] = 0.0
128
129
131 """Find the maximal alignment - the Azz component in the alignment frame.
132
133 @param tensor: The alignment tensor object.
134 @type tensor: numpy rank-2 3D tensor
135 @return: The Azz component in the alignment frame.
136 """
137
138
139 return max(abs(eigvals(tensor)))
140
141
142 -def to_5D(vector_5D, tensor):
143 """Convert the rank-2 3D alignment tensor matrix to the 5D vector format.
144
145 @param vector_5D: The 5D vector object to populate. The vector format is {Axx, Ayy, Axy, Axz,
146 Ayz}.
147 @type vector_5D: numpy 5D vector
148 @param tensor: The alignment tensor object.
149 @type tensor: numpy rank-2 3D tensor
150 """
151
152
153 vector_5D[0] = tensor[0, 0]
154 vector_5D[1] = tensor[1, 1]
155 vector_5D[2] = tensor[0, 1]
156 vector_5D[3] = tensor[0, 2]
157 vector_5D[4] = tensor[1, 2]
158
159
161 """Convert the 5D vector alignment tensor form to the rank-2 3D matrix from.
162
163 @param tensor: The alignment tensor object, in matrix format, to populate.
164 @type tensor: numpy rank-2 3D tensor
165 @param vector_5D: The 5D vector object. The vector format is {Axx, Ayy, Axy, Axz, Ayz}.
166 @type vector_5D: numpy 5D vector
167 """
168
169
170 tensor[0, 0] = vector_5D[0]
171 tensor[0, 1] = vector_5D[2]
172 tensor[0, 2] = vector_5D[3]
173 tensor[1, 0] = vector_5D[2]
174 tensor[1, 1] = vector_5D[1]
175 tensor[1, 2] = vector_5D[4]
176 tensor[2, 0] = vector_5D[3]
177 tensor[2, 1] = vector_5D[4]
178 tensor[2, 2] = -vector_5D[0] -vector_5D[1]
179