-
Notifications
You must be signed in to change notification settings - Fork 4
/
euc_k_form_SPB.py
1575 lines (1017 loc) · 68.1 KB
/
euc_k_form_SPB.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
#!!! We Define K_Forms in Euclidean Space to improve convergence
import numpy as np
import sph_func_SPB as sph_f
# Create Array of zeros to store vals at quad pts
def zero_quad_array(Q_val):
return np.zeros(( Q_val, 1 ))
# Return list of quad vals at each quad pt, given func
def Extract_Quad_Pt_Vals_From_Fn(Func, lbdv):
Extracted_Quad_vals = Func(lbdv.theta_pts, lbdv.phi_pts)
return Extracted_Quad_vals
# Return list of quad vals at each quad pt, given SPH_Func (CHART A order)
def Extract_Quad_Pt_Vals_From_SPH_Fn(SPH_Func, lbdv, Chart):
Extracted_Quad_vals = zero_quad_array(lbdv.lbdv_quad_pts)
quad_pts = range(lbdv.lbdv_quad_pts)
if(Chart == 'A'):
Extracted_Quad_vals = SPH_Func.Eval_SPH_Coef_Mat(quad_pts, lbdv)
if(Chart == 'B'): # The list needs to be in
Extracted_Quad_vals = SPH_Func.Eval_SPH_Coef_Mat(lbdv.Eval_Rot_Lbdv_Quad_vals(quad_pts), lbdv)
return Extracted_Quad_vals
# Return list of quad vals at each quad pt within Chart (CHART A order)
def Extract_dPhi_Quad_Pt_Vals_From_SPH_Fn(sph_func, lbdv, Chart):
Extracted_dPhi_Quad_Vals = zero_quad_array(lbdv.lbdv_quad_pts)
quad_pts = range(lbdv.lbdv_quad_pts)
if(Chart == 'A'):
return np.where(lbdv.Chart_of_Quad_Pts > 0, sph_func.Eval_SPH_Der_Phi_Coef(quad_pts, lbdv), 0)
if(Chart == 'B'):
quad_pts_rot = lbdv.Eval_Rot_Lbdv_Quad_vals(quad_pts)
return np.where(lbdv.Chart_of_Quad_Pts[quad_pts_rot] > 0, sph_func.Eval_SPH_Der_Phi_Coef(quad_pts_rot, lbdv), 0 )
# Return list of quad vals at each quad pt within Chart (CHART A order)
def Extract_dPhi_Phi_Quad_Pt_Vals_From_SPH_Fn(sph_func, lbdv, Chart):
Extracted_dPhi_Phi_Quad_Vals = zero_quad_array(lbdv.lbdv_quad_pts)
quad_pts = range(lbdv.lbdv_quad_pts)
if(Chart == 'A'):
return np.where(lbdv.Chart_of_Quad_Pts > 0, sph_func.Eval_SPH_Der_Phi_Phi_Coef(quad_pts, lbdv), 0)
if(Chart == 'B'):
quad_pts_rot = lbdv.Eval_Rot_Lbdv_Quad_vals(quad_pts)
return np.where(lbdv.Chart_of_Quad_Pts[quad_pts_rot] > 0, sph_func.Eval_SPH_Der_Phi_Phi_Coef(quad_pts_rot, lbdv), 0 )
# Combines info from each chart to give good vals at every point
def Combine_Chart_Quad_Vals(Quad_Vals_A, Quad_Vals_B, lbdv):
quad_pts = range(lbdv.lbdv_quad_pts)
return np.where(lbdv.Chart_of_Quad_Pts > 0, Quad_Vals_A, Quad_Vals_B[lbdv.Eval_Rot_Lbdv_Quad_vals(quad_pts)])
# Combines K_A and K_B into Chart A vector
def Combine_Manny_Gauss_Curvatures(Manny, lbdv, verbose=False):
K_cominbed_A_pts = Combine_Chart_Quad_Vals(Manny.K_A_pts, Manny.K_B_pts, lbdv)
if(verbose == True):
print("test of int on manny of K (in euc_kf) = "+str((Integral_on_Manny(K_cominbed_A_pts, Manny, lbdv)- 4*np.pi)/(4*np.pi)) + " (Rel Error)" )
return K_cominbed_A_pts
# Converts 1-form alpha, to vector field at quad pts:
def Sharp(dtheta_A_vals, dphi_A_vals, dtheta_B_vals, dphi_B_vals, p_deg, lbdv, Manny):
# alpha_i = (dtheta_vals_i)dtheta + (d_phi_vals_i)dphi
# Store x,y,z vals of sharped vector field at each quad_pt
sharped_x_vals_pts_A = zero_quad_array(lbdv.lbdv_quad_pts)
sharped_y_vals_pts_A = zero_quad_array(lbdv.lbdv_quad_pts)
sharped_z_vals_pts_A = zero_quad_array(lbdv.lbdv_quad_pts)
sharped_x_vals_pts_B = zero_quad_array(lbdv.lbdv_quad_pts)
sharped_y_vals_pts_B = zero_quad_array(lbdv.lbdv_quad_pts)
sharped_z_vals_pts_B = zero_quad_array(lbdv.lbdv_quad_pts)
# Use appropriate Chart for computing sharp
quad_pts = range(lbdv.lbdv_quad_pts)
# Values of 1-form:
d_theta_pts_A = np.where(lbdv.Chart_of_Quad_Pts > 0, dtheta_A_vals[quad_pts], 0)
d_phi_pts_A = np.where(lbdv.Chart_of_Quad_Pts > 0, dphi_A_vals[quad_pts], 0)
d_theta_pts_B = np.where(lbdv.Chart_of_Quad_Pts > 0, dtheta_B_vals[quad_pts], 0)
d_phi_pts_B = np.where(lbdv.Chart_of_Quad_Pts > 0, dphi_B_vals[quad_pts], 0)
# Manifold Data Needed:
#theta_pts = lbdv.theta_pts
#phi_pts = lbdv.phi_pts
g_inv_theta_theta_A_pts = Manny.g_Inv_Theta_Theta_A_Pts #Manny.g_inv_theta_theta(theta_pts, phi_pts, 'A')
g_inv_theta_phi_A_pts = Manny.g_Inv_Theta_Phi_A_Pts #Manny.g_inv_theta_phi(theta_pts, phi_pts, 'A')
g_inv_phi_phi_A_pts = Manny.g_Inv_Phi_Phi_A_Pts #Manny.g_inv_phi_phi(theta_pts, phi_pts, 'A')
g_inv_theta_theta_B_pts = Manny.g_Inv_Theta_Theta_B_Pts #Manny.g_inv_theta_theta(theta_pts, phi_pts, 'B')
g_inv_theta_phi_B_pts = Manny.g_Inv_Theta_Phi_B_Pts #Manny.g_inv_theta_phi(theta_pts, phi_pts, 'B')
g_inv_phi_phi_B_pts = Manny.g_Inv_Phi_Phi_B_Pts #Manny.g_inv_phi_phi(theta_pts, phi_pts, 'B')
sigma_theta_A_pts = Manny.Sigma_Theta_A_Pts #np.squeeze(Manny.sigma_theta(theta_pts, phi_pts, 'A'))
sigma_theta_B_pts = Manny.Sigma_Theta_B_Pts #np.squeeze(Manny.sigma_theta(theta_pts, phi_pts, 'B') )
sigma_phi_A_pts = Manny.Sigma_Phi_A_Pts #np.squeeze(Manny.sigma_phi(theta_pts, phi_pts, 'A'))
sigma_phi_B_pts = Manny.Sigma_Phi_B_Pts #np.squeeze(Manny.sigma_phi(theta_pts, phi_pts, 'B'))
# Sharp in (theta, phi) Coors:
alpha_sharp_theta_A_pts = np.multiply(d_theta_pts_A, g_inv_theta_theta_A_pts) + np.multiply(d_phi_pts_A, g_inv_theta_phi_A_pts)
alpha_sharp_phi_A_pts = np.multiply(d_theta_pts_A, g_inv_theta_phi_A_pts) + np.multiply(d_phi_pts_A, g_inv_phi_phi_A_pts)
alpha_sharp_theta_B_pts = np.multiply(d_theta_pts_B, g_inv_theta_theta_B_pts) + np.multiply(d_phi_pts_B, g_inv_theta_phi_B_pts)
alpha_sharp_phi_B_pts = np.multiply(d_theta_pts_B, g_inv_theta_phi_B_pts) + np.multiply(d_phi_pts_B, g_inv_phi_phi_B_pts)
# Convert Sharped Result to Euclidean Coors:
alpha_sharp_A_pts = np.multiply(alpha_sharp_theta_A_pts, sigma_theta_A_pts) + np.multiply(alpha_sharp_phi_A_pts, sigma_phi_A_pts)
alpha_sharp_B_pts = np.multiply(alpha_sharp_theta_B_pts, sigma_theta_B_pts) + np.multiply(alpha_sharp_phi_B_pts, sigma_phi_B_pts)
sharped_x_vals_pts_A, sharped_y_vals_pts_A, sharped_z_vals_pts_A = np.hsplit(alpha_sharp_A_pts, 3)
sharped_x_vals_pts_B, sharped_y_vals_pts_B, sharped_z_vals_pts_B = np.hsplit(alpha_sharp_B_pts, 3)
sharped_x_vals_pts_Used = Combine_Chart_Quad_Vals(sharped_x_vals_pts_A, sharped_x_vals_pts_B, lbdv)
sharped_y_vals_pts_Used = Combine_Chart_Quad_Vals(sharped_y_vals_pts_A, sharped_y_vals_pts_B, lbdv)
sharped_z_vals_pts_Used = Combine_Chart_Quad_Vals(sharped_z_vals_pts_A, sharped_z_vals_pts_B, lbdv)
# For 1-form constuction
Sharped_Quad_Vals = np.hstack(( sharped_x_vals_pts_Used, sharped_y_vals_pts_Used, sharped_z_vals_pts_Used ))
return euc_k_form(1, lbdv.lbdv_quad_pts, p_deg, Manny, Sharped_Quad_Vals)
# Converts 2-forms from Polar to Euclidean at a Quad Pt
def Two_Form_Conv_to_Euc_pt(quad_pt, lbdv, Chart, Manny):
# BJG: NEED TO CHANGE TO TO SPB FRAME:
'''
x_pt, y_pt, z_pt = Manny.Cart_Coor(quad_pt, lbdv, Chart)
r_sq_pt = Manny.R_Sq_Val(quad_pt, Chart)
if(Chart == 'A'):
denom_A = (r_pt**2)*np.sqrt(x_pt**2 + y_pt**2)
dx_dy_comp = -z_pt/denom_A
dx_dz_comp = y_pt/denom_A
dy_dz_comp = -x_pt/denom_A
return dx_dy_comp, dx_dz_comp, dy_dz_comp
if(Chart == 'B'):
denom_B = (r_pt**2)*np.sqrt(y_pt**2 + z_pt**2)
dx_dy_comp = -z_pt/denom_B
dx_dz_comp = y_pt/denom_B
dy_dz_comp = -x_pt/denom_B
return dx_dy_comp, dx_dz_comp, dy_dz_comp
'''
dx_dy_comp = Polar_Two_Form_to_Euc_dx_dy(quad_pt, Chart)
dx_dz_comp = Polar_Two_Form_to_Euc_dx_dz(quad_pt, Chart)
dy_dz_comp = Polar_Two_Form_to_Euc_dy_dz(quad_pt, Chart)
return dx_dy_comp, dx_dz_comp, dy_dz_comp
# Converts 2-forms from Euclidean to Polar at a Quad Pt
def Two_Form_Conv_to_Polar_pt(quad_pt, lbdv, Manny, Chart):
# BJG: DOES NOT NEED TO CHANGE FOR SPB FRAME:
theta_pt = lbdv.theta_pts[quad_pt]
phi_pt = lbdv.phi_pts[quad_pt]
dy_dz_comp = []
dx_dz_comp = []
dx_dy_comp = []
if(np.isscalar(quad_pt) == True):
theta_pt = np.asscalar(theta_pt)
phi_pt = np.asscalar(phi_pt)
#Cross_of_Basis = Manny.Normal_Dir(theta_pt, phi_pt, Chart)
# BJG: New Change:
Cross_of_Basis = Manny.Normal_Dir(quad_pt, Chart)
dy_dz_comp = Cross_of_Basis[0]
dx_dz_comp = -1*Cross_of_Basis[1]
dx_dy_comp = Cross_of_Basis[2]
else:
#Cross_of_Basis = Manny.Normal_Dir_Quad_Pts(lbdv, Chart) #Manny.Normal_Dir(theta_pt, phi_pt, Chart)
# BJG: New Change:
Cross_of_Basis = Manny.Normal_Dir(quad_pt, Chart)
#print("quad_pt = "+str(quad_pt)+", Cross_of_Basis.shape = "+str(Cross_of_Basis.shape)+", Cross_of_Basis = "+str(Cross_of_Basis))
dy_dz_comp, neg_dx_dz_comp, dx_dy_comp = np.hsplit(Cross_of_Basis, 3)
dx_dz_comp = -1.*neg_dx_dz_comp
#print("dy_dz_comp = "+str(dy_dz_comp)+"\n"+"dx_dz_comp = "+str(dx_dz_comp)+"\n"+"dx_dy_comp = "+str(dx_dy_comp)+"\n")
#dy_dz_comp = Cross_of_Basis[:, :, 0].T
#dx_dz_comp = -1*Cross_of_Basis[:, :, 1].T
#dx_dy_comp = Cross_of_Basis[:, :, 2].T
return dx_dy_comp, dx_dz_comp, dy_dz_comp
# computes (-*d) directly;
# Takes in 1-form (in LOCAL coordinates) -> 0-Form
def Gen_Curl_1(theta_C_A_vals, phi_C_A_vals, theta_C_B_vals, phi_C_B_vals, p_deg, lbdv, Manny):
# Project into SPH within Charts:
theta_C_A_SPH_Fn = sph_f.Faster_Double_Proj(theta_C_A_vals, p_deg, lbdv)
phi_C_A_SPH_Fn = sph_f.Faster_Double_Proj(phi_C_A_vals, p_deg, lbdv)
theta_C_B_SPH_Fn = sph_f.Faster_Double_Proj(theta_C_B_vals, p_deg, lbdv)
phi_C_B_SPH_Fn = sph_f.Faster_Double_Proj(phi_C_B_vals, p_deg, lbdv)
# take (local) theta derivative of (local) phi component
dTheta_phi_C_A_SPH_Fn = phi_C_A_SPH_Fn.Quick_Theta_Der()
dTheta_phi_C_B_SPH_Fn = phi_C_B_SPH_Fn.Quick_Theta_Der()
# project this azmuthal derivative into local chart ('A' because we dont rotate)
dTheta_phi_C_A_quad_pt_vals = Extract_Quad_Pt_Vals_From_SPH_Fn(dTheta_phi_C_A_SPH_Fn, lbdv, 'A')
dTheta_phi_C_B_quad_pt_vals = Extract_Quad_Pt_Vals_From_SPH_Fn(dTheta_phi_C_B_SPH_Fn, lbdv, 'A')
# Compute (local) phi derivative of (local) theta component:
dPhi_theta_C_A_quad_pt_vals = Extract_dPhi_Quad_Pt_Vals_From_SPH_Fn(theta_C_A_SPH_Fn, lbdv, 'A')
dPhi_theta_C_B_quad_pt_vals = Extract_dPhi_Quad_Pt_Vals_From_SPH_Fn(theta_C_B_SPH_Fn, lbdv, 'A')
# inv metric factor, at each point, within Chart:
q_val = lbdv.lbdv_quad_pts
quad_pts = range(q_val)
inv_met_fac_A_pts = np.where(lbdv.Chart_of_Quad_Pts > 0, 1./Manny.Metric_Factor_A_pts, 0)
inv_met_fac_B_pts = np.where(lbdv.Chart_of_Quad_Pts > 0, 1./Manny.Metric_Factor_B_pts, 0)
# Combine fields to produce gen_curl_1 in each chart:
gen_curl_1_A_pts = np.multiply(dPhi_theta_C_A_quad_pt_vals - dTheta_phi_C_A_quad_pt_vals, inv_met_fac_A_pts)
gen_curl_1_B_pts = np.multiply(dPhi_theta_C_B_quad_pt_vals - dTheta_phi_C_B_quad_pt_vals, inv_met_fac_B_pts)
gen_curl_1_Used_pts = Combine_Chart_Quad_Vals(gen_curl_1_A_pts, gen_curl_1_B_pts , lbdv)
return euc_k_form(0, q_val, p_deg, Manny, gen_curl_1_Used_pts)
# takes in quadrature points and weights them by metric:
def Integral_on_Manny_Eta_Z(vals_at_quad_pts, Manny, lbdv): #Orriginal Version
met_fac_over_sin_phi_pts_A = Manny.Metric_Factor_A_over_sin_phi_pts
met_fac_over_sin_phi_pts_B = Manny.Metric_Factor_B_over_sin_phi_bar_pts
num_quad_pts = lbdv.lbdv_quad_pts
# We integrate in local coordinates
eta_Z_Chart_A = np.zeros(( num_quad_pts, 1 ))
one_minus_eta_Z_Chart_B = np.zeros(( num_quad_pts, 1 ))
# We need to rotate integrand into chart B
rotated_vals_at_quad_pts = np.zeros(( num_quad_pts, 1 ))
for quad_pt in range(num_quad_pts):
eta_Z_pt = lbdv.eta_z(quad_pt)
eta_Z_Chart_A[quad_pt, 0] = eta_Z_pt
quad_pt_rot = lbdv.Eval_Rot_Lbdv_Quad_vals(quad_pt)
one_minus_eta_Z_Chart_B[quad_pt_rot, 0] = 1- eta_Z_pt
rotated_vals_at_quad_pts[quad_pt_rot, 0] = vals_at_quad_pts[quad_pt, 0]
Chart_A_integrand = np.multiply(np.multiply(met_fac_over_sin_phi_pts_A, eta_Z_Chart_A), vals_at_quad_pts)
Chart_B_integrand = np.multiply(np.multiply(met_fac_over_sin_phi_pts_B, one_minus_eta_Z_Chart_B), rotated_vals_at_quad_pts)
Int_On_Manny = sph_f.S2_Integral(Chart_A_integrand, lbdv) + sph_f.S2_Integral(Chart_B_integrand, lbdv)
return Int_On_Manny
def Integral_on_Manny(vals_at_quad_pts, Manny, lbdv): # New Version
vals_at_quad_pts = vals_at_quad_pts.reshape(len(vals_at_quad_pts),1) # ASSERT THIS IS THE RIGHT SIZE
met_fac_over_sin_phi_pts_A = Manny.Metric_Factor_A_over_sin_phi_pts
met_fac_over_sin_phi_pts_B = Manny.Metric_Factor_B_over_sin_phi_bar_pts
num_quad_pts = lbdv.lbdv_quad_pts
# We need to rotate integrand into chart B
rotated_vals_at_quad_pts = np.zeros(( num_quad_pts, 1 ))
quad_pts = range(num_quad_pts)
quad_pts_rot = lbdv.Eval_Rot_Lbdv_Quad_vals(quad_pts) #lbdv.Eval_Rot_Lbdv_Quad_vals(quad_pts)
rotated_vals_at_quad_pts = vals_at_quad_pts[quad_pts_rot]
Jacobian_Integrand = np.multiply(Combine_Chart_Quad_Vals(met_fac_over_sin_phi_pts_A, met_fac_over_sin_phi_pts_B, lbdv), vals_at_quad_pts) #Combine_Chart_Quad_Vals(np.multiply(met_fac_over_sin_phi_pts_A, vals_at_quad_pts), np.multiply(met_fac_over_sin_phi_pts_B, rotated_vals_at_quad_pts), lbdv)
Jacobian_Int_On_Manny = sph_f.S2_Integral(Jacobian_Integrand, lbdv)
return Jacobian_Int_On_Manny
# get metric factor scaling of weights from S2 to Manny:
def lebedev_quad_adj_Manny(Manny, lbdv):
met_fac_over_sin_phi_pts_A = Manny.Metric_Factor_A_over_sin_phi_pts
met_fac_over_sin_phi_pts_B = Manny.Metric_Factor_B_over_sin_phi_bar_pts
return Combine_Chart_Quad_Vals(met_fac_over_sin_phi_pts_A, met_fac_over_sin_phi_pts_B, lbdv)
# Inputs quad vals for f, f_approx, integrates on MANNY:
def Lp_Rel_Error_At_Quad_On_Manny(approx_f_vals, f_vals, lbdv, p, Manny): #Assumes f NOT 0
Lp_Err = 0 # ||self - f||_p
Lp_f = 0 # || f ||_p
pointwise_errs_to_the_p = abs((approx_f_vals - f_vals)**p)
Lp_Err_Manny = Integral_on_Manny(pointwise_errs_to_the_p, Manny, lbdv)
Lp_f_Manny = Integral_on_Manny(abs(f_vals)**p, Manny, lbdv)
return (Lp_Err_Manny/Lp_f_Manny)**(1./p) #||f_approx - f||_p / || f ||_p
# Get rid of normal components in a elegant way:
def Tangent_Projection(Vectors_at_Quad, lbdv, Manny):
num_quad_pts = lbdv.lbdv_quad_pts
Tangent_Vecs_at_Quad = np.zeros(( num_quad_pts, 3 ))
sigma_theta_A_pts = Manny.Sigma_Theta_A_Pts
sigma_theta_B_pts = Manny.Sigma_Theta_B_Pts
sigma_phi_A_pts = Manny.Sigma_Phi_A_Pts
sigma_phi_B_pts = Manny.Sigma_Phi_B_Pts
for quad_pt in range(num_quad_pts):
Vec_pt = Vectors_at_Quad[quad_pt, :].flatten()
Normal_Vec_pt = []
# Chart A:
if(lbdv.Chart_of_Quad_Pts[quad_pt] > 0):
Normal_Vec_pt = np.cross(sigma_theta_A_pts[quad_pt, :].flatten(), sigma_phi_A_pts[quad_pt, :].flatten())
dot_theta_A = np.dot(sigma_theta_A_pts[quad_pt, :].flatten(), Normal_Vec_pt)
dot_phi_A = np.dot(sigma_phi_A_pts[quad_pt, :].flatten(), Normal_Vec_pt)
if(dot_theta_A > 1e-12):
print("dot_theta_A = "+str(dot_theta_A))
if(dot_phi_A > 1e-12):
print("dot_phi_A = "+str(dot_phi_A))
# Chart B:
else:
quad_pt_rot = lbdv.Eval_Rot_Lbdv_Quad_vals(quad_pt)
Normal_Vec_pt = np.cross(sigma_theta_B_pts[quad_pt_rot, :].flatten(), sigma_phi_B_pts[quad_pt_rot, :].flatten())
dot_theta_B = np.dot(sigma_theta_B_pts[quad_pt_rot, :].flatten(), Normal_Vec_pt)
dot_phi_B = np.dot(sigma_phi_B_pts[quad_pt_rot, :].flatten(), Normal_Vec_pt)
if(dot_theta_B > 1e-12):
print("dot_theta_B = "+str(dot_theta_B))
if(dot_phi_B > 1e-12):
print("dot_phi_B = "+str(dot_phi_B))
Vec_pt_Tangent = Vec_pt - Normal_Vec_pt*(np.dot(Vec_pt, Normal_Vec_pt)/np.dot(Normal_Vec_pt, Normal_Vec_pt))
Tangent_Vecs_at_Quad[quad_pt, :] = Vec_pt_Tangent.reshape(1,3)
return Tangent_Vecs_at_Quad
'''
# Uses above code to get Normal direction in both charts:
def Normal_Dirs_Manny(lbdv, Manny):
num_quad_pts = lbdv.lbdv_quad_pts
Normal_Dirs_at_Quad = np.zeros(( num_quad_pts, 3 ))
sigma_theta_A_pts = Manny.Sigma_Theta_A_Pts
sigma_theta_B_pts = Manny.Sigma_Theta_B_Pts
sigma_phi_A_pts = Manny.Sigma_Phi_A_Pts
sigma_phi_B_pts = Manny.Sigma_Phi_B_Pts
for quad_pt in range(num_quad_pts):
Normal_Vec_pt = []
# Chart A:
if(lbdv.Chart_of_Quad_Pts[quad_pt] > 0):
Normal_Vec_pt = np.cross(sigma_theta_A_pts[quad_pt, :].flatten(), sigma_phi_A_pts[quad_pt, :].flatten())
# Chart B:
else:
quad_pt_rot = lbdv.Eval_Rot_Lbdv_Quad_vals(quad_pt)
Normal_Vec_pt = np.cross(sigma_theta_B_pts[quad_pt_rot, :].flatten(), sigma_phi_B_pts[quad_pt_rot, :].flatten())
Normal_Vec_pt_Mag = np.sqrt( np.dot(Normal_Vec_pt, Normal_Vec_pt) )
Normal_Dirs_at_Quad[quad_pt, :] = Normal_Vec_pt.reshape(1,3)/Normal_Vec_pt_Mag
return Normal_Dirs_at_Quad #np.hstack(( lbdv.X, lbdv.Y, lbdv.Z ))
'''
# Returns Riemannian Inner Product of 1-Forms input, returns Integral of
def Riemann_L2_Inner_Product_One_Form(One_Form_pts_1, One_Form_pts_2, lbdv, manny):
One_Form_1 = euc_k_form(1, lbdv.lbdv_quad_pts, manny.Man_SPH_Deg, manny, One_Form_pts_1)
One_Form_2 = euc_k_form(1, lbdv.lbdv_quad_pts, manny.Man_SPH_Deg, manny, One_Form_pts_2)
Inner_Prod_quad_pts = One_Form_1.Riemann_Inner_Prouct_One_Form(One_Form_2, lbdv)
return Integral_on_Manny(Inner_Prod_quad_pts, manny, lbdv)
# Return L2 norm of one form:
def Riemann_L2_Norm_One_Form(One_Form_pts, lbdv, manny):
return np.sqrt( Riemann_L2_Inner_Product_One_Form(One_Form_pts, One_Form_pts, lbdv, manny) )
# return L2 norm of scalar field:
def Riemann_L2_Norm_Zero_Form(Zero_Form_pts, lbdv, manny):
return np.sqrt( Integral_on_Manny( np.multiply(Zero_Form_pts, Zero_Form_pts) , manny, lbdv) )
# return L2 inner-product of scalar field:
def Riemann_L2_Inner_Product_Zero_Form(Zero_Form_pts_1, Zero_Form_pts_2, lbdv, manny):
return Integral_on_Manny( np.multiply(Zero_Form_pts_1, Zero_Form_pts_2) , manny, lbdv)
###############################################################################
class euc_k_form(object):
def __init__(self, k_val, Q_val, P_deg, Manny, array_of_quad_vals):
self.k_value = k_val # k = 0, 1, 2
self.Q_value = Q_val #lbdv.lbdv_quad_pts # Number of Quad Pts
self.P_degree = P_deg # Degree of Basis
#self.LBDV = Lbdv
self.Manifold = Manny
self.array_size = 0
if(self.k_value == 0):
self.array_size = 1
else:
self.array_size = 3 #{x,y,z} or {dx^dy, dx^dz, dy^dz}
self.quad_pt_array = array_of_quad_vals # col_i = comp_i, row_j = quad_pt_j
# K_form copy constuctor
def copy(self):
return euc_k_form(self.k_value, self.Q_value, self.P_degree, self.Manifold, self.quad_pt_array)
# Adds k_forms together (of same degree):
def linear_comb(self, euc_k_form_2, Const_1, Const_2):
return euc_k_form(self.k_value, self.Q_value, self.P_degree, self.Manifold, Const_1*self.quad_pt_array + Const_2*euc_k_form_2.quad_pt_array)
# Multiplies k_form by a constanct
def times_const(self, Const):
return euc_k_form(self.k_value, self.Q_value, self.P_degree, self.Manifold, Const*self.quad_pt_array)
# Multiplies k_form by a function
def times_fn(self, fn_vals_at_quad_pts):
num_cols = self.array_size
product_array = np.zeros(( self.Q_value, num_cols ))
product_array = np.einsum('i, ij -> ij', np.squeeze(fn_vals_at_quad_pts), self.quad_pt_array)
return euc_k_form(self.k_value, self.Q_value, self.P_degree, self.Manifold, product_array)
# Compute 1-form at a pt, given vector field
#def Flat(self, deriv, Matrix_Fn_Quad_pt, lbdv):
def Flat(self, G_deriv, A_inv_deriv, lbdv):
# Deriv = '', for G, 'theta' to use G_theta, 'phi' to use G_phi
# Matrix_Fn_Quad_pt is a 3x3 matrix function of the quad_pt, Chart (Could be eye(3))
# Store the value of one_form comps, before combining:
One_Form_Theta_Comp_A_vals = zero_quad_array(self.Q_value)
One_Form_Theta_Comp_B_vals = zero_quad_array(self.Q_value)
One_Form_Phi_Comp_A_vals = zero_quad_array(self.Q_value)
One_Form_Phi_Comp_B_vals = zero_quad_array(self.Q_value)
for quad_pt in range(self.Q_value):
# We use quad pts within each chart
if(lbdv.Chart_of_Quad_Pts[quad_pt] > 0):
quad_pt_rot = lbdv.Eval_Inv_Rot_Lbdv_Quad_vals(quad_pt)
alpha_sharp_X_A_pt = self.quad_pt_array[quad_pt, :].T
alpha_sharp_X_B_pt = self.quad_pt_array[quad_pt_rot, :].T
Flat_A_mat = []
Flat_B_mat = []
# Use G_theta
if(G_deriv == 'theta'):
Flat_A_mat = self.Manifold.rho_theta_A_Mats[:, :, quad_pt]
Flat_B_mat = self.Manifold.rho_theta_B_Mats[:, :, quad_pt]
# Use G_phi
elif(G_deriv == 'phi'):
Flat_A_mat = self.Manifold.rho_phi_A_Mats[:, :, quad_pt]
Flat_B_mat = self.Manifold.rho_phi_B_Mats[:, :, quad_pt]
# Use G
elif(G_deriv == ''):
if(A_inv_deriv == ''):
Flat_A_mat = self.Manifold.rho_A_Mats[:, :, quad_pt]
Flat_B_mat = self.Manifold.rho_B_Mats[:, :, quad_pt]
elif(A_inv_deriv == 'theta'):
Flat_A_mat = self.Manifold.xi_theta_A_Mats[:, :, quad_pt]
Flat_B_mat = self.Manifold.xi_theta_B_Mats[:, :, quad_pt]
elif(A_inv_deriv == 'phi'):
Flat_A_mat = self.Manifold.xi_phi_A_Mats[:, :, quad_pt]
Flat_B_mat = self.Manifold.xi_phi_B_Mats[:, :, quad_pt]
else:
print("Error in Flat A_inv_deriv")
# DONT use G: (regular flat)
elif(G_deriv == 'No_G'):
Flat_A_mat = self.Manifold.Change_Basis_Mat(quad_pt, 'A')
Flat_B_mat = self.Manifold.Change_Basis_Mat(quad_pt, 'B')
else:
print("Error in Flat G_deriv")
one_form_comps_A_pt = np.dot(Flat_A_mat, alpha_sharp_X_A_pt)
one_form_comps_B_pt = np.dot(Flat_B_mat, alpha_sharp_X_B_pt)
# we need to apply A^-1, but cant calc directly:
if(G_deriv == 'No_G'):
one_form_comps_A_pt = np.linalg.solve(Flat_A_mat, alpha_sharp_X_A_pt)
one_form_comps_B_pt = np.linalg.solve(Flat_B_mat, alpha_sharp_X_B_pt)
One_Form_Theta_Comp_A_vals[quad_pt] = one_form_comps_A_pt[0]
One_Form_Theta_Comp_B_vals[quad_pt] = one_form_comps_B_pt[0]
One_Form_Phi_Comp_A_vals[quad_pt] = one_form_comps_A_pt[1]
One_Form_Phi_Comp_B_vals[quad_pt] = one_form_comps_B_pt[1]
return One_Form_Theta_Comp_A_vals, One_Form_Theta_Comp_B_vals, One_Form_Phi_Comp_A_vals, One_Form_Phi_Comp_B_vals
# d: k_form -> (k+1)_form
def Ext_Der(self, lbdv):
if(self.k_value == 0):
#print("Doing Ext_Der on 0-Forms")
f_dtheta_A_quad_vals = zero_quad_array(lbdv.lbdv_quad_pts)
f_dphi_A_quad_vals = zero_quad_array(lbdv.lbdv_quad_pts)
f_dtheta_B_quad_vals = zero_quad_array(lbdv.lbdv_quad_pts)
f_dphi_B_quad_vals = zero_quad_array(lbdv.lbdv_quad_pts)
# Project function f into basis of each chart
f_SPH_A, f_SPH_B = sph_f.Proj_Into_SPH_Charts_At_Quad_Pts(self.quad_pt_array, self.P_degree, lbdv)
# Theta Ders Exact within basis
f_SPH_A_dtheta = f_SPH_A.Quick_Theta_Der()
f_SPH_B_dtheta = f_SPH_B.Quick_Theta_Bar_Der()
quad_pts = range(self.Q_value)
f_dtheta_A_quad_vals = np.where(lbdv.Chart_of_Quad_Pts[quad_pts] > 0, f_SPH_A_dtheta.Eval_SPH_Coef_Mat(quad_pts, lbdv), 0)
f_dphi_A_quad_vals = np.where(lbdv.Chart_of_Quad_Pts[quad_pts] > 0, f_SPH_A.Eval_SPH_Der_Phi_Coef(quad_pts, lbdv), 0)
f_dtheta_B_quad_vals = np.where(lbdv.Chart_of_Quad_Pts[quad_pts] > 0, f_SPH_B_dtheta.Eval_SPH_Coef_Mat(quad_pts, lbdv), 0)
f_dphi_B_quad_vals = np.where(lbdv.Chart_of_Quad_Pts[quad_pts] > 0, f_SPH_B.Eval_SPH_Der_Phi_Coef(quad_pts, lbdv), 0)
# Use sharp function above to convert 1-form components to euclidean vector field
return Sharp(f_dtheta_A_quad_vals, f_dphi_A_quad_vals, f_dtheta_B_quad_vals, f_dphi_B_quad_vals, self.P_degree, lbdv, self.Manifold)
if(self.k_value == 1):
#print("Doing Ext_Der on 1-Forms")
# Store values of Ext Det of (1-forms) alpha, at quad pts in each Chart
d_alpha_dx_dy_A_pts = zero_quad_array(self.Q_value)
d_alpha_dx_dz_A_pts = zero_quad_array(self.Q_value)
d_alpha_dy_dz_A_pts = zero_quad_array(self.Q_value)
d_alpha_dx_dy_B_pts = zero_quad_array(self.Q_value)
d_alpha_dx_dz_B_pts = zero_quad_array(self.Q_value)
d_alpha_dy_dz_B_pts = zero_quad_array(self.Q_value)
# Vals at quad pts needed for projection
alpha_sharp_x_quad_vals, alpha_sharp_y_quad_vals, alpha_sharp_z_quad_vals = np.hsplit(self.quad_pt_array, 3)
# Project euclidean comps of alpha_sharp into basis of each chart
alpha_sharp_x_SPH_A, alpha_sharp_x_SPH_B = sph_f.Proj_Into_SPH_Charts_At_Quad_Pts(alpha_sharp_x_quad_vals, self.P_degree, lbdv)
alpha_sharp_y_SPH_A, alpha_sharp_y_SPH_B = sph_f.Proj_Into_SPH_Charts_At_Quad_Pts(alpha_sharp_y_quad_vals, self.P_degree, lbdv)
alpha_sharp_z_SPH_A, alpha_sharp_z_SPH_B = sph_f.Proj_Into_SPH_Charts_At_Quad_Pts(alpha_sharp_z_quad_vals, self.P_degree, lbdv)
# SPH Theta Ders Exact within basis
alpha_sharp_x_SPH_A_dtheta = alpha_sharp_x_SPH_A.Quick_Theta_Der()
alpha_sharp_x_SPH_B_dtheta = alpha_sharp_x_SPH_B.Quick_Theta_Bar_Der()
alpha_sharp_y_SPH_A_dtheta = alpha_sharp_y_SPH_A.Quick_Theta_Der()
alpha_sharp_y_SPH_B_dtheta = alpha_sharp_y_SPH_B.Quick_Theta_Bar_Der()
alpha_sharp_z_SPH_A_dtheta = alpha_sharp_z_SPH_A.Quick_Theta_Der()
alpha_sharp_z_SPH_B_dtheta = alpha_sharp_z_SPH_B.Quick_Theta_Bar_Der()
#print("d_1: finished projections")
# Quad Vals of theta derivatives functions for alpha_sharp_X comps:
alpha_sharp_x_A_dtheta_vals = Extract_Quad_Pt_Vals_From_SPH_Fn(alpha_sharp_x_SPH_A_dtheta, lbdv, 'A')
alpha_sharp_x_B_dtheta_vals = Extract_Quad_Pt_Vals_From_SPH_Fn(alpha_sharp_x_SPH_B_dtheta, lbdv, 'B')
alpha_sharp_y_A_dtheta_vals = Extract_Quad_Pt_Vals_From_SPH_Fn(alpha_sharp_y_SPH_A_dtheta, lbdv, 'A')
alpha_sharp_y_B_dtheta_vals = Extract_Quad_Pt_Vals_From_SPH_Fn(alpha_sharp_y_SPH_B_dtheta, lbdv, 'B')
alpha_sharp_z_A_dtheta_vals = Extract_Quad_Pt_Vals_From_SPH_Fn(alpha_sharp_z_SPH_A_dtheta, lbdv, 'A')
alpha_sharp_z_B_dtheta_vals = Extract_Quad_Pt_Vals_From_SPH_Fn(alpha_sharp_z_SPH_B_dtheta, lbdv, 'B')
# Quad Vals of phi derivatives functions for alpha_sharp_X comps (within Charts):
alpha_sharp_x_A_dphi_vals = Extract_dPhi_Quad_Pt_Vals_From_SPH_Fn(alpha_sharp_x_SPH_A, lbdv, 'A')
alpha_sharp_x_B_dphi_vals = Extract_dPhi_Quad_Pt_Vals_From_SPH_Fn(alpha_sharp_x_SPH_B, lbdv, 'B')
alpha_sharp_y_A_dphi_vals = Extract_dPhi_Quad_Pt_Vals_From_SPH_Fn(alpha_sharp_y_SPH_A, lbdv, 'A')
alpha_sharp_y_B_dphi_vals = Extract_dPhi_Quad_Pt_Vals_From_SPH_Fn(alpha_sharp_y_SPH_B, lbdv, 'B')
alpha_sharp_z_A_dphi_vals = Extract_dPhi_Quad_Pt_Vals_From_SPH_Fn(alpha_sharp_z_SPH_A, lbdv, 'A')
alpha_sharp_z_B_dphi_vals = Extract_dPhi_Quad_Pt_Vals_From_SPH_Fn(alpha_sharp_z_SPH_B, lbdv, 'B')
# Create quad val vector Arrays:
alpha_sharp_dTheta_A_quad_array = np.hstack(( alpha_sharp_x_A_dtheta_vals, alpha_sharp_y_A_dtheta_vals, alpha_sharp_z_A_dtheta_vals ))
alpha_sharp_dPhi_A_quad_array = np.hstack(( alpha_sharp_x_A_dphi_vals, alpha_sharp_y_A_dphi_vals, alpha_sharp_z_A_dphi_vals ))
alpha_sharp_dTheta_B_quad_array = np.hstack(( alpha_sharp_x_B_dtheta_vals, alpha_sharp_y_B_dtheta_vals, alpha_sharp_z_B_dtheta_vals ))
alpha_sharp_dPhi_B_quad_array = np.hstack(( alpha_sharp_x_B_dphi_vals, alpha_sharp_y_B_dphi_vals, alpha_sharp_z_B_dphi_vals ))
alpha_vec_dTheta_A = euc_k_form(1, self.Q_value, self.P_degree, self.Manifold, alpha_sharp_dTheta_A_quad_array)
alpha_vec_dPhi_A = euc_k_form(1, self.Q_value, self.P_degree, self.Manifold, alpha_sharp_dPhi_A_quad_array)
alpha_vec_dTheta_B = euc_k_form(1, self.Q_value, self.P_degree, self.Manifold, alpha_sharp_dTheta_B_quad_array)
alpha_vec_dPhi_B = euc_k_form(1, self.Q_value, self.P_degree, self.Manifold, alpha_sharp_dPhi_B_quad_array)
# Compute Y = -dA_i * A^(-1)
def Y_mat(q_pt, Chart, deriv):
Basis_Mat = self.Manifold.Change_Basis_Mat(q_pt, Chart)
dBasis_Mat_deriv = []
if(deriv == 'theta'):
dBasis_Mat_deriv = self.Manifold.dChange_Basis_Mat_theta(q_pt, Chart)
if(deriv == 'phi'):
dBasis_Mat_deriv = self.Manifold.dChange_Basis_Mat_phi(q_pt, Chart)
return np.linalg.solve(Basis_Mat.T, -1*dBasis_Mat_deriv.T).T
# Values of components, in each chart:
# alpha_Sharp_X.Flat() gives us: (alpha_theta_comp_A_vals, alpha_theta_comp_B_vals, alpha_phi_comp_A_vals, alpha_phi_comp_B_vals)
#print("d_1: created needed 1-forms vecs")
# dG_i * A^(-1) * alpha^X
dG_theta_comps = self.Flat('theta', '', lbdv)
dG_phi_comps = self.Flat('phi', '', lbdv)
# G * A^(-1) * dalpha^X_i
d_alpha_sharp_X_theta_A_comps = alpha_vec_dTheta_A.Flat('', '', lbdv)
d_alpha_sharp_X_phi_A_comps = alpha_vec_dPhi_A.Flat('', '', lbdv)
d_alpha_sharp_X_theta_B_comps = alpha_vec_dTheta_B.Flat('', '', lbdv)
d_alpha_sharp_X_phi_B_comps = alpha_vec_dPhi_B.Flat('', '', lbdv)
# G * A^(-1) * dA_i * A^(-1) * alpha^X
d_Basis_mat_theta_comps = self.Flat('', 'theta', lbdv)
d_Basis_mat_phi_comps = self.Flat('', 'phi', lbdv)
#print("d_1: Flat operations done")
# Values we need to compute d:
d_theta_comp_A_dphi_vals = dG_phi_comps[0] + d_Basis_mat_phi_comps[0] + d_alpha_sharp_X_phi_A_comps[0]
d_phi_comp_A_dtheta_vals = dG_theta_comps[2] + d_Basis_mat_theta_comps[2] + d_alpha_sharp_X_theta_A_comps[2]
d_theta_comp_B_dphi_vals = dG_phi_comps[1] + d_Basis_mat_phi_comps[1] + d_alpha_sharp_X_phi_B_comps[1]
d_phi_comp_B_dtheta_vals = dG_theta_comps[3] + d_Basis_mat_theta_comps[3] + d_alpha_sharp_X_theta_B_comps[3]
# d_alpha polar vals
d_alpha_A_Polar_vals = d_phi_comp_A_dtheta_vals - d_theta_comp_A_dphi_vals
d_alpha_B_Polar_vals = d_phi_comp_B_dtheta_vals - d_theta_comp_B_dphi_vals
quad_pts = range(self.Q_value)
# Convert to Euclidean Coors:
dx_dy_A_pts = self.Manifold.dx_dy_A_Vals_From_Polar
dx_dz_A_pts = self.Manifold.dx_dz_A_Vals_From_Polar
dy_dz_A_pts = self.Manifold.dy_dz_A_Vals_From_Polar
dx_dy_B_pts = self.Manifold.dx_dy_B_Vals_From_Polar
dx_dz_B_pts = self.Manifold.dx_dz_B_Vals_From_Polar
dy_dz_B_pts = self.Manifold.dy_dz_B_Vals_From_Polar
# We use quad pts within each chart
d_alpha_A_Polar_pts = np.where(lbdv.Chart_of_Quad_Pts[quad_pts] > 0, d_alpha_A_Polar_vals, 0)
d_alpha_B_Polar_pts = np.where(lbdv.Chart_of_Quad_Pts[quad_pts] > 0, d_alpha_B_Polar_vals, 0)
d_alpha_dx_dy_A_pts = d_alpha_A_Polar_pts*dx_dy_A_pts
d_alpha_dx_dz_A_pts = d_alpha_A_Polar_pts*dx_dz_A_pts
d_alpha_dy_dz_A_pts = d_alpha_A_Polar_pts*dy_dz_A_pts
d_alpha_dx_dy_B_pts = d_alpha_B_Polar_pts*dx_dy_B_pts
d_alpha_dx_dz_B_pts = d_alpha_B_Polar_pts*dx_dz_B_pts
d_alpha_dy_dz_B_pts = d_alpha_B_Polar_pts*dy_dz_B_pts
#print("d_1: computed polar solutions in each chart")
# Combine Values from Charts
d_alpha_Used_dx_dy_pts = Combine_Chart_Quad_Vals(d_alpha_dx_dy_A_pts, d_alpha_dx_dy_B_pts, lbdv)
d_alpha_Used_dx_dz_pts = Combine_Chart_Quad_Vals(d_alpha_dx_dz_A_pts, d_alpha_dx_dz_B_pts, lbdv)
d_alpha_Used_dy_dz_pts = Combine_Chart_Quad_Vals(d_alpha_dy_dz_A_pts, d_alpha_dy_dz_B_pts, lbdv)
#print("d_1: combined into euc solution")
# Create array of 2-form values
New_Quad_Pt_Array = np.hstack(( d_alpha_Used_dx_dy_pts, d_alpha_Used_dx_dz_pts, d_alpha_Used_dy_dz_pts ))
return euc_k_form(2, self.Q_value, self.P_degree, self.Manifold, New_Quad_Pt_Array)
if(self.k_value == 2): # ext der of of 2-form is 0:
#print("Doing Ext_Der on 2-Forms")
return euc_k_form(0, self.Q_value, self.P_degree, self.Manifold, zero_quad_array(self.Q_value))
# Compute *: k_form -> (n-k)_form
def Hodge_Star(self, lbdv):
if(self.k_value == 0):
#print("Doing Hodge Star on 0-Forms")
# store values of Hodge star of fn (0-form) f, at quad pts in each Chart
star_f_A_dx_dy_pts = zero_quad_array(self.Q_value)
star_f_A_dx_dz_pts = zero_quad_array(self.Q_value)
star_f_A_dy_dz_pts = zero_quad_array(self.Q_value)
star_f_B_dx_dy_pts = zero_quad_array(self.Q_value)
star_f_B_dx_dz_pts = zero_quad_array(self.Q_value)
star_f_B_dy_dz_pts = zero_quad_array(self.Q_value)
# Corresponding quad_pts in chart B (in Chart A Coors)
quad_pts = range(self.Q_value)
quad_pts_inv_rot = lbdv.Eval_Inv_Rot_Lbdv_Quad_vals(quad_pts)
# values at (theta_C, phi_C) = (theta_i, phi_i), given q_i, Difffernt points on manifold!
f_A_pts = self.quad_pt_array[quad_pts]
f_B_pts = self.quad_pt_array[quad_pts_inv_rot]
# metric factor, at each point, within Chart
met_fac_A_pts = self.Manifold.Metric_Factor_A_pts #np.where(lbdv.Chart_of_Quad_Pts > 0, self.Manifold.Metric_Factor_Quad_Pt(quad_pts, lbdv, 'A'), 0)
met_fac_B_pts = self.Manifold.Metric_Factor_B_pts #np.where(lbdv.Chart_of_Quad_Pts > 0, self.Manifold.Metric_Factor_Quad_Pt(quad_pts, lbdv, 'B'), 0)
# Do Hodge Star:
star_f_dtheta_dphi_A_pts = np.multiply(f_A_pts, met_fac_A_pts)
star_f_dtheta_dphi_B_pts = np.multiply(f_B_pts, met_fac_B_pts)
# Convert to Euclidean Coors:
#dx_dy_A_vals, dx_dz_A_vals, dy_dz_A_vals = Two_Form_Conv_to_Euc_pt(quad_pts, lbdv, 'A', self.Manifold)
#dx_dy_B_vals, dx_dz_B_vals, dy_dz_B_vals = Two_Form_Conv_to_Euc_pt(quad_pts, lbdv, 'B', self.Manifold)
dx_dy_A_vals = self.Manifold.dx_dy_A_Vals_From_Polar
dx_dz_A_vals = self.Manifold.dx_dz_A_Vals_From_Polar
dy_dz_A_vals = self.Manifold.dy_dz_A_Vals_From_Polar
dx_dy_B_vals = self.Manifold.dx_dy_B_Vals_From_Polar
dx_dz_B_vals = self.Manifold.dx_dz_B_Vals_From_Polar
dy_dz_B_vals = self.Manifold.dy_dz_B_Vals_From_Polar
star_f_A_dx_dy_pts = np.multiply(star_f_dtheta_dphi_A_pts, dx_dy_A_vals)
star_f_A_dx_dz_pts = np.multiply(star_f_dtheta_dphi_A_pts, dx_dz_A_vals)
star_f_A_dy_dz_pts = np.multiply(star_f_dtheta_dphi_A_pts, dy_dz_A_vals)
star_f_B_dx_dy_pts = np.multiply(star_f_dtheta_dphi_B_pts, dx_dy_B_vals)
star_f_B_dx_dz_pts = np.multiply(star_f_dtheta_dphi_B_pts, dx_dz_B_vals)
star_f_B_dy_dz_pts = np.multiply(star_f_dtheta_dphi_B_pts, dy_dz_B_vals)
# Combine Values from Charts
star_f_Used_dx_dy_pts = Combine_Chart_Quad_Vals(star_f_A_dx_dy_pts, star_f_B_dx_dy_pts, lbdv)
star_f_Used_dx_dz_pts = Combine_Chart_Quad_Vals(star_f_A_dx_dz_pts, star_f_B_dx_dz_pts, lbdv)
star_f_Used_dy_dz_pts = Combine_Chart_Quad_Vals(star_f_A_dy_dz_pts, star_f_B_dy_dz_pts, lbdv)
# Create array of 2-form values
New_Quad_Pt_Array = np.hstack((star_f_Used_dx_dy_pts, star_f_Used_dx_dz_pts, star_f_Used_dy_dz_pts ))
return euc_k_form(2, self.Q_value, self.P_degree, self.Manifold, New_Quad_Pt_Array)
if(self.k_value == 1):
#print("Doing Hodge Star on 1-Forms")
# Store values of Hodge Star of (1-forms) alpha, at quad pts in each Chart
star_alpha_A_theta_pts = zero_quad_array(self.Q_value)
star_alpha_A_phi_pts = zero_quad_array(self.Q_value)
star_alpha_B_theta_pts = zero_quad_array(self.Q_value)
star_alpha_B_phi_pts = zero_quad_array(self.Q_value)
# Values of components, in each chart
alpha_theta_comp_A_vals, alpha_theta_comp_B_vals, alpha_phi_comp_A_vals, alpha_phi_comp_B_vals = self.Flat('', '', lbdv)
met_fac_A_pts = self.Manifold.Metric_Factor_A_pts
met_fac_B_pts = self.Manifold.Metric_Factor_B_pts
g_inv_theta_theta_A_pts = self.Manifold.g_Inv_Theta_Theta_A_Pts
g_inv_theta_phi_A_pts = self.Manifold.g_Inv_Theta_Phi_A_Pts
g_inv_phi_phi_A_pts = self.Manifold.g_Inv_Phi_Phi_A_Pts
g_inv_theta_theta_B_pts = self.Manifold.g_Inv_Theta_Theta_B_Pts
g_inv_theta_phi_B_pts = self.Manifold.g_Inv_Theta_Phi_B_Pts
g_inv_phi_phi_B_pts = self.Manifold.g_Inv_Phi_Phi_B_Pts
# Take Hodge-Star of 1-Form:
star_alpha_A_theta_pts = np.multiply(-1*met_fac_A_pts, (np.multiply(g_inv_theta_phi_A_pts, alpha_theta_comp_A_vals) + np.multiply(g_inv_phi_phi_A_pts, alpha_phi_comp_A_vals)))
star_alpha_A_phi_pts = np.multiply(met_fac_A_pts, (np.multiply(g_inv_theta_theta_A_pts, alpha_theta_comp_A_vals) + np.multiply(g_inv_theta_phi_A_pts, alpha_phi_comp_A_vals)))
star_alpha_B_theta_pts = np.multiply(-1*met_fac_B_pts, (np.multiply(g_inv_theta_phi_B_pts, alpha_theta_comp_B_vals) + np.multiply(g_inv_phi_phi_B_pts, alpha_phi_comp_B_vals)))
star_alpha_B_phi_pts = np.multiply(met_fac_B_pts, (np.multiply(g_inv_theta_theta_B_pts, alpha_theta_comp_B_vals) + np.multiply(g_inv_theta_phi_B_pts, alpha_phi_comp_B_vals)))
return Sharp(star_alpha_A_theta_pts, star_alpha_A_phi_pts, star_alpha_B_theta_pts, star_alpha_B_phi_pts, self.P_degree, lbdv, self.Manifold)
if(self.k_value == 2):
#print("Doing Hodge Star on 2-Forms")
# store values of Hodge star of fn (2-form) beta, at quad pts in each Chart
star_beta_from_A_pts = zero_quad_array(self.Q_value)
star_beta_from_B_pts = zero_quad_array(self.Q_value)
# Corresponding quad pt in chart B (in Chart A Coors)
quad_pts = range(self.Q_value)
quad_pts_inv_rot = lbdv.Eval_Inv_Rot_Lbdv_Quad_vals(quad_pts)
# inv metric factor, at each point, within Chart
#inv_met_fac_A_pts = np.where(lbdv.Chart_of_Quad_Pts > 0, 1/self.Manifold.Metric_Factor_Quad_Pt(quad_pts, lbdv, 'A'), 0)
#inv_met_fac_B_pts = np.where(lbdv.Chart_of_Quad_Pts > 0, 1/self.Manifold.Metric_Factor_Quad_Pt(quad_pts, lbdv, 'B'), 0)
#BJG: new change:
inv_met_fac_A_pts = np.where(lbdv.Chart_of_Quad_Pts > 0, 1./self.Manifold.Metric_Factor_A_pts, 0)
inv_met_fac_B_pts = np.where(lbdv.Chart_of_Quad_Pts > 0, 1./self.Manifold.Metric_Factor_B_pts, 0)
# values at (theta_C, phi_C) = (theta_i, phi_i), given q_i, Difffernt points on manifold!
beta_dx_dy_A_pts, beta_dx_dz_A_pts, beta_dy_dz_A_pts = np.hsplit(self.quad_pt_array[quad_pts], 3)
beta_dx_dy_B_pts, beta_dx_dz_B_pts, beta_dy_dz_B_pts = np.hsplit(self.quad_pt_array[quad_pts_inv_rot], 3)
# 2-forms to cartesian conversions:
dx_dy_to_dtheta_dphi_A_pts, dx_dz_to_dtheta_dphi_A_pts, dy_dz_to_dtheta_dphi_A_pts = Two_Form_Conv_to_Polar_pt(quad_pts, lbdv, self.Manifold, 'A')
dx_dy_to_dtheta_dphi_B_pts, dx_dz_to_dtheta_dphi_B_pts, dy_dz_to_dtheta_dphi_B_pts = Two_Form_Conv_to_Polar_pt(quad_pts, lbdv, self.Manifold, 'B')
# Do Hodge Star:
beta_dtheta_dphi_A_pts = np.multiply(beta_dx_dy_A_pts, dx_dy_to_dtheta_dphi_A_pts) + np.multiply(beta_dy_dz_A_pts, dy_dz_to_dtheta_dphi_A_pts) + np.multiply(beta_dx_dz_A_pts, dx_dz_to_dtheta_dphi_A_pts)
beta_dtheta_dphi_B_pts = np.multiply(beta_dx_dy_B_pts, dx_dy_to_dtheta_dphi_B_pts) + np.multiply(beta_dy_dz_B_pts, dy_dz_to_dtheta_dphi_B_pts) + np.multiply(beta_dx_dz_B_pts, dx_dz_to_dtheta_dphi_B_pts)
star_beta_from_A_pts = np.multiply(beta_dtheta_dphi_A_pts, inv_met_fac_A_pts)
star_beta_from_B_pts = np.multiply(beta_dtheta_dphi_B_pts, inv_met_fac_B_pts)
# Combine Values from Charts
star_beta_Used_pts = Combine_Chart_Quad_Vals(star_beta_from_A_pts , star_beta_from_B_pts , lbdv)
return euc_k_form(0, self.Q_value, self.P_degree, self.Manifold, star_beta_Used_pts)
# Computes -*d directly;
# Takes 0-Forms -> 1-Forms (in local chart)
def Gen_Curl_0(self, lbdv):
if(self.k_value == 0):
#print("Doing Ext_Der on 0-Forms")
f_dtheta_A_quad_vals = zero_quad_array(lbdv.lbdv_quad_pts)
f_dphi_A_quad_vals = zero_quad_array(lbdv.lbdv_quad_pts)
f_dtheta_B_quad_vals = zero_quad_array(lbdv.lbdv_quad_pts)
f_dphi_B_quad_vals = zero_quad_array(lbdv.lbdv_quad_pts)
# Project function f into basis of each chart
f_SPH_A, f_SPH_B = sph_f.Proj_Into_SPH_Charts_At_Quad_Pts(self.quad_pt_array, self.P_degree, lbdv)
# Theta Ders Exact within basis
f_SPH_A_dtheta = f_SPH_A.Quick_Theta_Der()
f_SPH_B_dtheta = f_SPH_B.Quick_Theta_Bar_Der()
quad_pts = range(self.Q_value)
f_dtheta_A_quad_vals = np.where(lbdv.Chart_of_Quad_Pts[quad_pts] > 0, f_SPH_A_dtheta.Eval_SPH_Coef_Mat(quad_pts, lbdv), 0)
f_dphi_A_quad_vals = np.where(lbdv.Chart_of_Quad_Pts[quad_pts] > 0, f_SPH_A.Eval_SPH_Der_Phi_Coef(quad_pts, lbdv), 0)
f_dtheta_B_quad_vals = np.where(lbdv.Chart_of_Quad_Pts[quad_pts] > 0, f_SPH_B_dtheta.Eval_SPH_Coef_Mat(quad_pts, lbdv), 0)
f_dphi_B_quad_vals = np.where(lbdv.Chart_of_Quad_Pts[quad_pts] > 0, f_SPH_B.Eval_SPH_Der_Phi_Coef(quad_pts, lbdv), 0)
# fields needed for *_1 :
met_fac_A_pts = self.Manifold.Metric_Factor_A_pts
met_fac_B_pts = self.Manifold.Metric_Factor_B_pts
g_inv_theta_theta_A_pts = self.Manifold.g_Inv_Theta_Theta_A_Pts
g_inv_theta_phi_A_pts = self.Manifold.g_Inv_Theta_Phi_A_Pts
g_inv_phi_phi_A_pts = self.Manifold.g_Inv_Phi_Phi_A_Pts
g_inv_theta_theta_B_pts = self.Manifold.g_Inv_Theta_Theta_B_Pts
g_inv_theta_phi_B_pts = self.Manifold.g_Inv_Theta_Phi_B_Pts
g_inv_phi_phi_B_pts = self.Manifold.g_Inv_Phi_Phi_B_Pts
# Take Hodge-Star of 1-Form:
neg_star_df_A_theta_pts = (-1)*np.multiply(-1*met_fac_A_pts, (np.multiply(g_inv_theta_phi_A_pts, f_dtheta_A_quad_vals) + np.multiply(g_inv_phi_phi_A_pts, f_dphi_A_quad_vals)))
neg_star_df_A_phi_pts = (-1)*np.multiply(met_fac_A_pts, (np.multiply(g_inv_theta_theta_A_pts, f_dtheta_A_quad_vals) + np.multiply(g_inv_theta_phi_A_pts, f_dphi_A_quad_vals)))
neg_star_df_B_theta_pts = (-1)*np.multiply(-1*met_fac_B_pts, (np.multiply(g_inv_theta_phi_B_pts, f_dtheta_B_quad_vals) + np.multiply(g_inv_phi_phi_B_pts, f_dphi_B_quad_vals)))
neg_star_df_B_phi_pts = (-1)*np.multiply(met_fac_B_pts, (np.multiply(g_inv_theta_theta_B_pts, f_dtheta_B_quad_vals) + np.multiply(g_inv_theta_phi_B_pts, f_dphi_B_quad_vals)))
return neg_star_df_A_theta_pts, neg_star_df_A_phi_pts, neg_star_df_B_theta_pts, neg_star_df_B_phi_pts
#Sharp(star_alpha_A_theta_pts, star_alpha_A_phi_pts, star_alpha_B_theta_pts, star_alpha_B_phi_pts, self.P_degree, lbdv, self.Manifold)
else:
print("Error: Zero Forms needed for this inner-product fn to work")