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