-
Notifications
You must be signed in to change notification settings - Fork 306
/
nullpoint.py
1564 lines (1345 loc) · 49 KB
/
nullpoint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
Functionality to find and analyze 3D magnetic null points.
.. note::
This module is still under development and the API may change in
future releases.
"""
__all__ = [
"MultipleNullPointWarning",
"NonZeroDivergence",
"NullPoint",
"NullPointError",
"NullPointWarning",
"Point",
"null_point_find",
"trilinear_approx",
"uniform_null_point_find",
]
import numpy as np
import warnings
from typing import Callable
# Declare Constants & global variables
_EQUALITY_ATOL = 1e-10
_MAX_RECURSION_LEVEL = 10
global _recursion_level
_recursion_level = 0
class NullPointError(Exception):
"""
A class for handling the exceptions of the null point finder functionality.
.. note::
This functionality is still under development and the API may
change in future releases.
"""
pass
class NullPointWarning(UserWarning):
"""
A class for handling the warnings of the null point finder functionality.
.. note::
This functionality is still under development and the API may
change in future releases.
"""
pass
class NonZeroDivergence(NullPointError):
"""
A class for handling the exception raised by passing in a magnetic field
that violates the zero divergence constraint.
.. note::
This functionality is still under development and the API may
change in future releases.
"""
def __init__(self):
super().__init__(
"The divergence constraint does not hold for the provided magnetic field."
)
class MultipleNullPointWarning(NullPointWarning):
"""
A class for handling the warning raised by passing in a magnetic field
grid that may contain multiple null points in close proximity due to low
resolution.
.. note::
This functionality is still under development and the API may
change in future releases.
"""
pass
class Point:
"""
Abstract class for defining a point in 3D space.
.. note::
This functionality is still under development and the API may
change in future releases.
"""
def __init__(self, loc):
self._loc = loc
def get_loc(self):
r"""
Returns the coordinates of the point object.
"""
return self._loc
loc = property(get_loc)
class NullPoint(Point):
"""
A class for defining a null point in 3D space.
.. note::
This functionality is still under development and the API may
change in future releases.
"""
def __init__(self, null_loc, classification):
super().__init__(null_loc)
self._classification = classification
def get_classification(self):
r"""
Returns the type of the null point object.
"""
return self._classification
def __eq__(self, point):
r"""
Returns True if two null point objects have the same coordinates.
False otherwise.
"""
d = np.sqrt(
(self.loc[0] - point.loc[0]) ** 2
+ (self.loc[1] - point.loc[1]) ** 2
+ (self.loc[2] - point.loc[2]) ** 2
)
return np.isclose(d, 0, atol=_EQUALITY_ATOL)
classification = property(get_classification)
def _vector_space(
x_arr=None,
y_arr=None,
z_arr=None,
x_range=[0, 1],
y_range=[0, 1],
z_range=[0, 1],
u_arr=None,
v_arr=None,
w_arr=None,
func=(lambda x, y, z: [x, y, z]),
precision=[0.05, 0.05, 0.05],
):
r"""
Returns a vector space in the form of a multi-dimensional array.
Parameters
----------
x_arr : |array_like|
The array representing the coordinates in the x-dimension.
If not given, then range values are used to construct a
uniform array on that interval.
y_arr : |array_like|
The array representing the coordinates in the y-dimension.
If not given, then range values are used to construct a
uniform array on that interval.
z_arr : |array_like|
The array representing the coordinates in the z-dimension.
If not given, then range values are used to construct a
uniform array on that interval.
x_range : |array_like|
A 1 by 2 array containing the range of x-values for the vector spaces.
If not given, the default interval [0,1] is assumed.
y_range : |array_like|
A 1 by 2 array containing the range of y-values for the vector spaces.
If not given, the default interval [0,1] is assumed.
z_range : |array_like|
A 1 by 2 array containing the range of z-values for the vector spaces.
If not given, the default interval [0,1] is assumed.
u_arr : |array_like|
A 3D array containing the x-component of the vector values for the vector
space. If not given, the vector values are generated over the vector space
using the function func.
v_arr : |array_like|
A 3D array containing the y-component of the vector values for the vector
space. If not given, the vector values are generated over the vector space
using the function func.
w_arr : |array_like|
A 3D array containing the z-component of the vector values for the vector
space. If not given, the vector values are generated over the vector space
using the function func.
func : function
A function that takes in 3 arguments, respectively representing a x, y, and z
coordinate of a point and returns the vector value for that point in the form
of a 1 by 3 array.
precision : |array_like|
A 1 by 3 array containing the approximate precision values for each dimension,
in the case where uniform arrays are being used.
The default value is [0.05, 0.05, 0.05].
Returns
-------
ndarray
A 1 by 3 array with
the first element containing the coordinates.
the second element containing the vector values.
and the third element containing the delta values for each dimension.
"""
# Constructing the Meshgrid
if x_arr is not None and y_arr is not None and z_arr is not None:
x, y, z = np.meshgrid(
x_arr,
y_arr,
z_arr,
indexing="ij",
)
dx = np.diff(x_arr)
dy = np.diff(y_arr)
dz = np.diff(z_arr)
else:
x_den = int(np.around((x_range[1] - x_range[0]) / precision[0]) + 1)
y_den = int(np.around((y_range[1] - y_range[0]) / precision[1]) + 1)
z_den = int(np.around((z_range[1] - z_range[0]) / precision[2]) + 1)
dx = np.diff(np.linspace(x_range[0], x_range[1], x_den))
dy = np.diff(np.linspace(y_range[0], y_range[1], y_den))
dz = np.diff(np.linspace(z_range[0], z_range[1], z_den))
x, y, z = np.meshgrid(
np.linspace(x_range[0], x_range[1], x_den),
np.linspace(y_range[0], y_range[1], y_den),
np.linspace(z_range[0], z_range[1], z_den),
indexing="ij",
)
# Calculating the vector values
if u_arr is not None and v_arr is not None and w_arr is not None:
u = u_arr
v = v_arr
w = w_arr
else:
u, v, w = func(x, y, z)
return np.array([x, y, z]), np.array([u, v, w]), np.array([dx, dy, dz])
def _trilinear_coeff_cal(vspace, cell):
r"""
Return the coefficients for the trilinear approximation function
on a given grid cell in a given vector space.
Parameters
----------
vspace: |array_like|
The vector space as constructed by the vector_space function which is
A 1 by 3 array with the first element containing the coordinates,
the second element containing the vector values,
and the third element containing the delta values for each dimension.
cell: |array_like| of integers
A grid cell, represented by a 1 by 3 array
of integers, which correspond to a grid cell
in the vector space.
Returns
-------
ndarray
Returns a 1 by 3 array with
the first element containing the coefficients for the trilinear approximation function
for the x-component of the vector space,
the second element containing the coefficients for the trilinear approximation function
for the y-component of the vector space, and
the third element containing the coefficients for the trilinear approximation function
for the z-component of the vector space.
"""
u, v, w = vspace[1]
deltax, deltay, deltaz = vspace[2]
f000 = cell
f001 = [cell[0], cell[1], cell[2] + 1]
f010 = [cell[0], cell[1] + 1, cell[2]]
f011 = [cell[0], cell[1] + 1, cell[2] + 1]
f100 = [cell[0] + 1, cell[1], cell[2]]
f101 = [cell[0] + 1, cell[1], cell[2] + 1]
f110 = [cell[0] + 1, cell[1] + 1, cell[2]]
f111 = [cell[0] + 1, cell[1] + 1, cell[2] + 1]
x0 = float(vspace[0][0][f000[0]][f000[1]][f000[2]])
x1 = float(x0 + deltax[cell[0]])
y0 = float(vspace[0][1][f000[0]][f000[1]][f000[2]])
y1 = float(y0 + deltay[cell[1]])
z0 = float(vspace[0][2][f000[0]][f000[1]][f000[2]])
z1 = float(z0 + deltaz[cell[2]])
A = np.array(
[
[1, x0, y0, z0, x0 * y0, x0 * z0, y0 * z0, x0 * y0 * z0],
[1, x1, y0, z0, x1 * y0, x1 * z0, y0 * z0, x1 * y0 * z0],
[1, x0, y1, z0, x0 * y1, x0 * z0, y1 * z0, x0 * y1 * z0],
[1, x1, y1, z0, x1 * y1, x1 * z0, y1 * z0, x1 * y1 * z0],
[1, x0, y0, z1, x0 * y0, x0 * z1, y0 * z1, x0 * y0 * z1],
[1, x1, y0, z1, x1 * y0, x1 * z1, y0 * z1, x1 * y0 * z1],
[1, x0, y1, z1, x0 * y1, x0 * z1, y1 * z1, x0 * y1 * z1],
[1, x1, y1, z1, x1 * y1, x1 * z1, y1 * z1, x1 * y1 * z1],
]
)
sx = np.array(
[
[u[f000[0]][f000[1]][f000[2]]],
[u[f100[0]][f100[1]][f100[2]]],
[u[f010[0]][f010[1]][f010[2]]],
[u[f110[0]][f110[1]][f110[2]]],
[u[f001[0]][f001[1]][f001[2]]],
[u[f101[0]][f101[1]][f101[2]]],
[u[f011[0]][f011[1]][f011[2]]],
[u[f111[0]][f111[1]][f111[2]]],
]
)
sy = np.array(
[
[v[f000[0]][f000[1]][f000[2]]],
[v[f100[0]][f100[1]][f100[2]]],
[v[f010[0]][f010[1]][f010[2]]],
[v[f110[0]][f110[1]][f110[2]]],
[v[f001[0]][f001[1]][f001[2]]],
[v[f101[0]][f101[1]][f101[2]]],
[v[f011[0]][f011[1]][f011[2]]],
[v[f111[0]][f111[1]][f111[2]]],
]
)
sz = np.array(
[
[w[f000[0]][f000[1]][f000[2]]],
[w[f100[0]][f100[1]][f100[2]]],
[w[f010[0]][f010[1]][f010[2]]],
[w[f110[0]][f110[1]][f110[2]]],
[w[f001[0]][f001[1]][f001[2]]],
[w[f101[0]][f101[1]][f101[2]]],
[w[f011[0]][f011[1]][f011[2]]],
[w[f111[0]][f111[1]][f111[2]]],
]
)
ax, bx, cx, dx, ex, fx, gx, hx = np.linalg.solve(A, sx).reshape(1, 8)[0]
ay, by, cy, dy, ey, fy, gy, hy = np.linalg.solve(A, sy).reshape(1, 8)[0]
az, bz, cz, dz, ez, fz, gz, hz = np.linalg.solve(A, sz).reshape(1, 8)[0]
return np.array(
[
[ax, bx, cx, dx, ex, fx, gx, hx],
[ay, by, cy, dy, ey, fy, gy, hy],
[az, bz, cz, dz, ez, fz, gz, hz],
]
)
def trilinear_approx(vspace, cell):
r"""
Return a function whose input is a coordinate within a given grid cell
and returns the trilinearly approximated vector value at that particular
coordinate in that grid cell.
.. note::
This functionality is still under development and the API may
change in future releases.
Parameters
----------
vspace: |array_like|
The vector space as constructed by the vector_space function which is
A 1 by 3 array with the first element containing the coordinates,
the second element containing the vector values,
and the third element containing the delta values for each dimension.
cell: |array_like| of integers
A grid cell, represented by a 1 by 3 array
of integers, which correspond to a grid cell
in the vector space.
Returns
-------
function
A function whose input is a coordinate within a given grid cell
and returns the trilinearly approximated vector value at that particular
coordinate in that grid cell.
"""
# Calculating coefficients
ax, bx, cx, dx, ex, fx, gx, hx = _trilinear_coeff_cal(vspace, cell)[0]
ay, by, cy, dy, ey, fy, gy, hy = _trilinear_coeff_cal(vspace, cell)[1]
az, bz, cz, dz, ez, fz, gz, hz = _trilinear_coeff_cal(vspace, cell)[2]
def approx_func(xInput, yInput, zInput):
Bx = (
ax
+ bx * xInput
+ cx * yInput
+ dx * zInput
+ ex * xInput * yInput
+ fx * xInput * zInput
+ gx * yInput * zInput
+ hx * xInput * yInput * zInput
)
By = (
ay
+ by * xInput
+ cy * yInput
+ dy * zInput
+ ey * xInput * yInput
+ fy * xInput * zInput
+ gy * yInput * zInput
+ hy * xInput * yInput * zInput
)
Bz = (
az
+ bz * xInput
+ cz * yInput
+ dz * zInput
+ ez * xInput * yInput
+ fz * xInput * zInput
+ gz * yInput * zInput
+ hz * xInput * yInput * zInput
)
return np.array([Bx, By, Bz])
return approx_func
def _trilinear_jacobian(vspace, cell):
r"""
Returns a function whose input is a coordinate within a given grid cell
and returns the trilinearly approximated jacobian matrix for that particular
coordinate in that grid cell.
Parameters
----------
vspace: |array_like|
The vector space as constructed by the vector_space function which is
A 1 by 3 array with the first element containing the coordinates,
the second element containing the vector values,
and the third element containing the delta values for each dimension.
cell: |array_like| of integers
A grid cell, represented by a 1 by 3 array
of integers, which correspond to a grid cell
in the vector space.
Returns
-------
A function whose input is a coordinate within a given grid cell
and returns the trilinearly approximated jacobian matrix for that particular
coordinate in that grid cell.
"""
# Calculating coefficients
ax, bx, cx, dx, ex, fx, gx, hx = _trilinear_coeff_cal(vspace, cell)[0]
ay, by, cy, dy, ey, fy, gy, hy = _trilinear_coeff_cal(vspace, cell)[1]
az, bz, cz, dz, ez, fz, gz, hz = _trilinear_coeff_cal(vspace, cell)[2]
def jacobian_func(xInput, yInput, zInput):
dBxdx = bx + ex * yInput + fx * zInput + hx * yInput * zInput
dBxdy = cx + ex * xInput + gx * zInput + hx * xInput * yInput
dBxdz = dx + fx * xInput + gx * yInput + hx * xInput * yInput
dBydx = by + ey * yInput + fy * zInput + hy * yInput * zInput
dBydy = cy + ey * xInput + gy * zInput + hy * xInput * yInput
dBydz = dy + fy * xInput + gy * yInput + hy * xInput * yInput
dBzdx = bz + ez * yInput + fz * zInput + hz * yInput * zInput
dBzdy = cz + ez * xInput + gz * zInput + hz * xInput * yInput
dBzdz = dz + fz * xInput + gz * yInput + hz * xInput * yInput
jmatrix = np.array(
[
float(dBxdx),
float(dBxdy),
float(dBxdz),
float(dBydx),
float(dBydy),
float(dBydz),
float(dBzdx),
float(dBzdy),
float(dBzdz),
]
).reshape(3, 3)
return jmatrix
return jacobian_func
def _reduction(vspace, cell):
r"""
Return a true or false based on weather
a grid cell passes the reduction phase,
meaning that they potentially contain a null point.
Parameters
----------
vspace: |array_like|
The vector space as constructed by the vector_space function which is
A 1 by 3 array with the first element containing the coordinates,
the second element containing the vector values,
and the third element containing the delta values for each dimension.
cell: |array_like| of integers
A grid cell, represented by a 1 by 3 array
of integers, which correspond to a grid cell
in the vector space.
Returns
-------
bool
True if a grid cell passes the reduction phase.
False, otherwise.
Notes
-----
Depending on the grid resolution, a cell containing more than
one null point may not pass reduction, so it would not be detected.
"""
u, v, w = vspace[1]
f000 = cell
f001 = [cell[0], cell[1], cell[2] + 1]
f010 = [cell[0], cell[1] + 1, cell[2]]
f011 = [cell[0], cell[1] + 1, cell[2] + 1]
f100 = [cell[0] + 1, cell[1], cell[2]]
f101 = [cell[0] + 1, cell[1], cell[2] + 1]
f110 = [cell[0] + 1, cell[1] + 1, cell[2]]
f111 = [cell[0] + 1, cell[1] + 1, cell[2] + 1]
corners = [f000, f001, f010, f011, f100, f101, f110, f111]
passX = False
passY = False
passZ = False
# Check reduction criteria
sign_x = np.sign(u[cell[0]][cell[1]][cell[2]])
sign_y = np.sign(v[cell[0]][cell[1]][cell[2]])
sign_z = np.sign(w[cell[0]][cell[1]][cell[2]])
for point in corners:
if (
u[point[0]][point[1]][point[2]] == 0
or np.sign(u[point[0]][point[1]][point[2]]) != sign_x
):
passX = True
if (
v[point[0]][point[1]][point[2]] == 0
or np.sign(v[point[0]][point[1]][point[2]]) != sign_y
):
passY = True
if (
w[point[0]][point[1]][point[2]] == 0
or np.sign(w[point[0]][point[1]][point[2]]) != sign_z
):
passZ = True
doesPassReduction = passX and passY and passZ
return doesPassReduction
def _bilinear_root(a1, b1, c1, d1, a2, b2, c2, d2):
r"""
Return the roots of a pair of bilinear equations of the following format.
.. math::
a_1 + b_1 x + c_1 y + d_1 x y = 0 \\
a_2 + b_2 x + c_2 y + d_2 x y = 0
Parameters
----------
a1: float
b1: float
c1: float
d1: float
a2: float
b2: float
c2: float
d2: float
Returns
-------
roots : |array_like| of floats
A 1 by 2 array containing the two roots
"""
m1 = np.array([[a1, a2], [c1, c2]])
m2 = np.array([[a1, a2], [d1, d2]])
m3 = np.array([[b1, b2], [c1, c2]])
m4 = np.array([[b1, b2], [d1, d2]])
a = np.linalg.det(m4)
b = np.linalg.det(m2) + np.linalg.det(m3)
c = np.linalg.det(m1)
if np.isclose(a, 0, atol=_EQUALITY_ATOL):
if np.isclose(b, 0, atol=_EQUALITY_ATOL):
return np.array([])
else:
x1 = (-1.0 * c) / b
x2 = (-1.0 * c) / b
else:
if (b**2 - 4.0 * a * c) < 0:
return np.array([])
else:
x1 = (-1.0 * b + (b**2 - 4.0 * a * c) ** 0.5) / (2.0 * a)
x2 = (-1.0 * b - (b**2 - 4.0 * a * c) ** 0.5) / (2.0 * a)
y1 = None
y2 = None
if not (np.isclose((c1 + d1 * x1), 0, atol=_EQUALITY_ATOL)):
y1 = (-a1 - b1 * x1) / (c1 + d1 * x1)
elif not (np.isclose((c2 + d2 * x1), 0, atol=_EQUALITY_ATOL)):
y1 = (-a2 - b2 * x1) / (c2 + d2 * x1)
if not (np.isclose((c1 + d1 * x2), 0, atol=_EQUALITY_ATOL)):
y2 = (-a1 - b1 * x2) / (c1 + d1 * x2)
elif not (np.isclose((c2 + d2 * x2), 0, atol=_EQUALITY_ATOL)):
y2 = (-a2 - b2 * x2) / (c2 + d2 * x2)
if y1 is None and y2 is None:
return np.array([])
elif y1 is None:
return np.array([(x2, y2)])
elif y2 is None:
return np.array([(x1, y1)])
else:
d = np.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
if np.isclose(d, 0, atol=_EQUALITY_ATOL):
return np.array([(x1, y1)])
else:
return np.array([(x1, y1), (x2, y2)])
def _trilinear_analysis(vspace, cell):
r"""
Return a true or false value based on whether
a grid cell which has passed the reduction step,
contains a null point, using trilinear analysis.
Parameters
----------
vspace: |array_like|
The vector space as constructed by the vector_space function which is
A 1 by 3 array with the first element containing the coordinates,
the second element containing the vector values,
and the third element containing the delta values for each dimension.
cell: |array_like| of integers
A grid cell, represented by a 1 by 3 array
of integers, which correspond to a grid cell
in the vector space.
Returns
-------
bool
True if a grid cell contains a null point using trilinear analysis.
False, otherwise.
Raises
------
This function does not raise any exceptions.
Warns
-----
:`UserWarning`
If there is a possible lack of grid resolution, so
that a grid cell may contain more than one null point.
"""
# Critical Cell Corners
f000 = cell
f111 = [cell[0] + 1, cell[1] + 1, cell[2] + 1]
# Calculating coefficients
ax, bx, cx, dx, ex, fx, gx, hx = _trilinear_coeff_cal(vspace, cell)[0]
ay, by, cy, dy, ey, fy, gy, hy = _trilinear_coeff_cal(vspace, cell)[1]
az, bz, cz, dz, ez, fz, gz, hz = _trilinear_coeff_cal(vspace, cell)[2]
# Initial Position of the cell corner
initial = np.array(
[
vspace[0][0][f000[0]][f000[1]][f000[2]],
vspace[0][1][f000[0]][f000[1]][f000[2]],
vspace[0][2][f000[0]][f000[1]][f000[2]],
]
)
# Arrays holding the endpoints
BxByEndpoints = []
BxBzEndpoints = []
ByBzEndpoints = []
# Check if the null point already exists in root list
def is_root_in_list(root, arr):
for r in arr:
x_close = np.isclose(root[0], r[0], atol=_EQUALITY_ATOL)
y_close = np.isclose(root[1], r[1], atol=_EQUALITY_ATOL)
z_close = np.isclose(root[2], r[2], atol=_EQUALITY_ATOL)
if x_close and y_close and z_close:
return True
return False
# Front Surface
yConst1 = vspace[0][1][f000[0]][f000[1]][
f000[2]
] # y-coordinate of the front surface
# Bx=By=0 Curve Endpoint
root_list = _bilinear_root(
ax + cx * yConst1,
bx + ex * yConst1,
dx + gx * yConst1,
fx + hx * yConst1,
ay + cy * yConst1,
by + ey * yConst1,
dy + gy * yConst1,
fy + hy * yConst1,
)
for root in root_list:
if not is_root_in_list((root[0], yConst1, root[1]), BxByEndpoints):
BxByEndpoints.append((root[0], yConst1, root[1]))
# Bx=Bz=0 Curve Endpoint
root_list = _bilinear_root(
ax + cx * yConst1,
bx + ex * yConst1,
dx + gx * yConst1,
fx + hx * yConst1,
az + cz * yConst1,
bz + ez * yConst1,
dz + gz * yConst1,
fz + hz * yConst1,
)
for root in root_list:
if not is_root_in_list((root[0], yConst1, root[1]), BxBzEndpoints):
BxBzEndpoints.append((root[0], yConst1, root[1]))
# By=Bz=0 Curve Endpoint
root_list = _bilinear_root(
ay + cy * yConst1,
by + ey * yConst1,
dy + gy * yConst1,
fy + hy * yConst1,
az + cz * yConst1,
bz + ez * yConst1,
dz + gz * yConst1,
fz + hz * yConst1,
)
for root in root_list:
if not is_root_in_list((root[0], yConst1, root[1]), ByBzEndpoints):
ByBzEndpoints.append((root[0], yConst1, root[1]))
# Back Surface
yConst2 = vspace[0][1][f111[0]][f111[1]][
f111[2]
] # y-coordinate of the front surface
# Bx=By=0 Curve Endpoint
root_list = _bilinear_root(
ax + cx * yConst2,
bx + ex * yConst2,
dx + gx * yConst2,
fx + hx * yConst2,
ay + cy * yConst2,
by + ey * yConst2,
dy + gy * yConst2,
fy + hy * yConst2,
)
for root in root_list:
if not is_root_in_list((root[0], yConst2, root[1]), BxByEndpoints):
BxByEndpoints.append((root[0], yConst2, root[1]))
# Bx=Bz=0 Curve Endpoint
root_list = _bilinear_root(
ax + cx * yConst2,
bx + ex * yConst2,
dx + gx * yConst2,
fx + hx * yConst2,
az + cz * yConst2,
bz + ez * yConst2,
dz + gz * yConst2,
fz + hz * yConst2,
)
for root in root_list:
if not is_root_in_list((root[0], yConst2, root[1]), BxBzEndpoints):
BxBzEndpoints.append((root[0], yConst2, root[1]))
# By=Bz=0 Curve Endpoint
root_list = _bilinear_root(
ay + cy * yConst2,
by + ey * yConst2,
dy + gy * yConst2,
fy + hy * yConst2,
az + cz * yConst2,
bz + ez * yConst2,
dz + gz * yConst2,
fz + hz * yConst2,
)
for root in root_list:
if not is_root_in_list((root[0], yConst2, root[1]), ByBzEndpoints):
ByBzEndpoints.append((root[0], yConst2, root[1]))
# Right Surface
xConst1 = vspace[0][0][f111[0]][f111[1]][f111[2]]
# Bx=By=0 Curve Endpoint
root_list = _bilinear_root(
ax + bx * xConst1,
cx + ex * xConst1,
dx + fx * xConst1,
gx + hx * xConst1,
ay + by * xConst1,
cy + ey * xConst1,
dy + fy * xConst1,
gy + hy * xConst1,
)
for root in root_list:
if not is_root_in_list((xConst1, root[0], root[1]), BxByEndpoints):
BxByEndpoints.append((xConst1, root[0], root[1]))
# Bx=BZ=0 Curve Endpoint
root_list = _bilinear_root(
ax + bx * xConst1,
cx + ex * xConst1,
dx + fx * xConst1,
gx + hx * xConst1,
az + bz * xConst1,
cz + ez * xConst1,
dz + fz * xConst1,
gz + hz * xConst1,
)
for root in root_list:
if not is_root_in_list((xConst1, root[0], root[1]), BxBzEndpoints):
BxBzEndpoints.append((xConst1, root[0], root[1]))
# By=Bz=0 Curve Endpoint
root_list = _bilinear_root(
ay + by * xConst1,
cy + ey * xConst1,
dy + fy * xConst1,
gy + hy * xConst1,
az + bz * xConst1,
cz + ez * xConst1,
dz + fz * xConst1,
gz + hz * xConst1,
)
for root in root_list:
if not is_root_in_list((xConst1, root[0], root[1]), ByBzEndpoints):
ByBzEndpoints.append((xConst1, root[0], root[1]))
# Left Surface
xConst2 = vspace[0][0][f000[0]][f000[1]][f000[2]]
# Bx=By=0 Curve Endpoint
root_list = _bilinear_root(
ax + bx * xConst2,
cx + ex * xConst2,
dx + fx * xConst2,
gx + hx * xConst2,
ay + by * xConst2,
cy + ey * xConst2,
dy + fy * xConst2,
gy + hy * xConst2,
)
for root in root_list:
if not is_root_in_list((xConst2, root[0], root[1]), BxByEndpoints):
BxByEndpoints.append((xConst2, root[0], root[1]))
# Bx=BZ=0 Curve Endpoint
root_list = _bilinear_root(
ax + bx * xConst2,
cx + ex * xConst2,
dx + fx * xConst2,
gx + hx * xConst2,
az + bz * xConst2,
cz + ez * xConst2,
dz + fz * xConst2,
gz + hz * xConst2,
)
for root in root_list:
if not is_root_in_list((xConst2, root[0], root[1]), BxBzEndpoints):
BxBzEndpoints.append((xConst2, root[0], root[1]))
# By=Bz=0 Curve Endpoint
root_list = _bilinear_root(
ay + by * xConst2,
cy + ey * xConst2,
dy + fy * xConst2,
gy + hy * xConst2,
az + bz * xConst2,
cz + ez * xConst2,
dz + fz * xConst2,
gz + hz * xConst2,
)
for root in root_list:
if not is_root_in_list((xConst2, root[0], root[1]), ByBzEndpoints):
ByBzEndpoints.append((xConst2, root[0], root[1]))
# Up Surface
zConst1 = vspace[0][2][f111[0]][f111[1]][f111[2]]
# Bx=By=0 Curve Endpoint
root_list = _bilinear_root(
ax + dx * zConst1,
bx + fx * zConst1,
cx + gx * zConst1,
ex + hx * zConst1,
ay + dy * zConst1,
by + fy * zConst1,
cy + gy * zConst1,
ey + hy * zConst1,
)
for root in root_list:
if not is_root_in_list((root[0], root[1], zConst1), BxByEndpoints):
BxByEndpoints.append((root[0], root[1], zConst1))
# Bx=Bz=0 Curve Endpoint
root_list = _bilinear_root(
ax + dx * zConst1,
bx + fx * zConst1,
cx + gx * zConst1,
ex + hx * zConst1,
az + dz * zConst1,
bz + fz * zConst1,
cz + gz * zConst1,
ez + hz * zConst1,
)
for root in root_list:
if not is_root_in_list((root[0], root[1], zConst1), BxBzEndpoints):
BxBzEndpoints.append((root[0], root[1], zConst1))
# By=Bz=0 Curve Endpoint
root_list = _bilinear_root(
ay + dy * zConst1,
by + fy * zConst1,
cy + gy * zConst1,
ey + hy * zConst1,
az + dz * zConst1,
bz + fz * zConst1,
cz + gz * zConst1,
ez + hz * zConst1,
)
for root in root_list:
if not is_root_in_list((root[0], root[1], zConst1), ByBzEndpoints):
ByBzEndpoints.append((root[0], root[1], zConst1))
# Down Surface
zConst2 = vspace[0][2][f000[0]][f000[1]][f000[2]]
# Bx=By=0 Curve Endpoint
root_list = _bilinear_root(
ax + dx * zConst2,
bx + fx * zConst2,
cx + gx * zConst2,
ex + hx * zConst2,
ay + dy * zConst2,
by + fy * zConst2,
cy + gy * zConst2,
ey + hy * zConst2,
)
for root in root_list:
if not is_root_in_list((root[0], root[1], zConst2), BxByEndpoints):
BxByEndpoints.append((root[0], root[1], zConst2))
# Bx=Bz=0 Curve Endpoint
root_list = _bilinear_root(
ax + dx * zConst2,
bx + fx * zConst2,
cx + gx * zConst2,
ex + hx * zConst2,
az + dz * zConst2,
bz + fz * zConst2,
cz + gz * zConst2,
ez + hz * zConst2,
)
for root in root_list: