-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmovemart.c
executable file
·1652 lines (1604 loc) · 36.6 KB
/
movemart.c
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
/* LEFT+Right Side or Err for X-Stokes Equation */
/* Stokes equation initial form */
/* dSIGxx/dX + dSIGxy/dY - dP/dX = - RO*Gx */
double xstokserr(long int m1, long int m2, int ynerr)
/* m1,m2 - node X,Y number */
/* ynerr - Err Calc Y(1)/N(0) */
{
/* Counters */
int n1,n2;
long int v[4];
/* Err Buf */
double leftx,rightx,nueff;
/* Distances */
double xkf=(gx[m1+1]-gx[m1-1])/2.0,ykf=gy[m2+1]-gy[m2];
double GXKOEFX=GXKOEF;
/**/
/**/
/**/
/* Staggered Nodes num */
/* [0] [2] */
/* Ro0,Sxy0,Nu0 */
/* */
/* Pr1,Sxx1 <Vx0> Pr3,Sxx3 */
/* */
/* [1] [3] */
/* RO1,Sxy1,Nu1 */
/* */
v[0]=m1*ynumy+m2;v[1]=v[0]+1;
v[2]=v[0]+ynumy;v[3]=v[2]+1;
/**/
/**/
/**/
/* Spherical Gravity acceleration from gravity potential */
if(0==0)
{
GXKOEFX=-(gp[v[3]]-gp[v[1]])/xkf;
/*
printf("GX %ld %ld %e %e %e %e %e ",m1,m2,gp[v[3]],gp[v[1]],GXKOEFX,gp[v[3]],GXKOEF);getchar();
*/
}
/**/
/**/
/**/
/* RIGHT parts of X-Stokes */
/* dSIGik/dXk - dP/dXi = - Gi*RO */
rightx = -GXKOEFX*(ro[v[0]]+ro[v[1]])/2.0;
/**/
/**/
/**/
/* Return val for LSQ err ----------------------------*/
if(ynerr==1)
{
/* LEFT part of X-Stokes */
/* dSIGxx/dX + dSIGxy/dY - dP/dX = - RO*Gx */
/**/
/* dSIGxx/dX */
leftx =(sxx[v[3]]-sxx[v[1]])/xkf;
/* dSIGxy/dY */
leftx+=(sxy[v[1]]-sxy[v[0]])/ykf;
/* -dP/dX */
leftx-=(pr[v[3]]-pr[v[1]])/xkf;
/**/
/* FD stabilization mechanism included [T. Duretz et al., Geochem. Geophys. Geosyst., 12, Q07004, 2011] */
/* -gx/dt/2*(vx*dRHO/dx+vy*dRHO/dy) */
leftx-=timestep/2.0*GXKOEFX*(vx[v[0]]*(ro[v[2]]+ro[v[3]]-ro[v[0]-ynumy]-ro[v[1]-ynumy])/(gx[m1+1]-gx[m1-1])/2.0+((vy[v[0]]+vy[v[1]])*(gx[m1]-gx[m1-1])+(vy[v[0]-ynumy]+vy[v[1]-ynumy])*(gx[m1+1]-gx[m1]))/(gx[m1+1]-gx[m1-1])/2.0*(ro[v[1]]-ro[v[0]])/(gy[m2+1]-gy[m2]));
/**/
/**/
/* Effective NU calc */
nueff=(nu[v[0]]+nu[v[1]])/2.0;
/**/
/* X-STOKES Error */
leftx=(leftx-rightx)/nueff;
/**/
/* Min,Max Value of Nu Save */
errbuf[9]=nueff;
/* Min,Max Value of P Save */
errbuf[10]=MAXV(pr[v[1]],pr[v[3]]);
errbuf[11]=MINV(pr[v[1]],pr[v[3]]);
/**/
return leftx;
}
/**/
/**/
/**/
/* Set Initial Num of lines -------------------------------------- */
wn[0]=2;
/* Save Right part Save for X-Stokes ---------------------*/
wi[0]=rightx;
/**/
/* Add Coefficients for left parts of X-Stokes ----------------*/
/* Staggered Nodes num */
/* [0] [2] */
/* Ro0,Sxy0,Nu0 */
/* */
/* Pr1,Sxx1 <Vx0> Pr3,Sxx3 */
/* */
/* [1] [3] */
/* RO1,Sxy1,Nu1 */
/* */
/* 0(P) 1(Vx) 2(Vy) */
/* -dP/dX */
wn[1]=v[1]*3+0;
wi[1]=+1.0/xkf;
wn[2]=v[3]*3+0;
wi[2]=-1.0/xkf;
/* dSIGxx/dX */
sxxcalc(m1,m2+1,-1.0/xkf);
sxxcalc(m1+1,m2+1,1.0/xkf);
/* dSIGxy/dY */
sxycalc(m1,m2,-1.0/ykf);
sxycalc(m1,m2+1,1.0/ykf);
/**/
/**/
/* FD stabilization mechanism included [T. Duretz et al., Geochem. Geophys. Geosyst., 12, Q07004, 2011] */
/* -gx/dt/2*(vx*dRHO/dx+vy*dRHO/dy) */
wn[wn[0]+1]=v[0]*3+1;
wi[wn[0]+1]=-timestep/2.0*GXKOEFX*(ro[v[2]]+ro[v[3]]-ro[v[0]-ynumy]-ro[v[1]-ynumy])/(gx[m1+1]-gx[m1-1])/2.0;
wn[wn[0]+2]=v[0]*3+2;
wi[wn[0]+2]=-timestep/2.0*GXKOEFX*(gx[m1]-gx[m1-1])/(gx[m1+1]-gx[m1-1])/2.0*(ro[v[1]]-ro[v[0]])/(gy[m2+1]-gy[m2]);
wn[wn[0]+3]=v[1]*3+2;
wi[wn[0]+3]=-timestep/2.0*GXKOEFX*(gx[m1]-gx[m1-1])/(gx[m1+1]-gx[m1-1])/2.0*(ro[v[1]]-ro[v[0]])/(gy[m2+1]-gy[m2]);
wn[wn[0]+4]=(v[0]-ynumy)*3+2;
wi[wn[0]+4]=-timestep/2.0*GXKOEFX*(gx[m1+1]-gx[m1])/(gx[m1+1]-gx[m1-1])/2.0*(ro[v[1]]-ro[v[0]])/(gy[m2+1]-gy[m2]);
wn[wn[0]+5]=(v[1]-ynumy)*3+2;
wi[wn[0]+5]=-timestep/2.0*GXKOEFX*(gx[m1+1]-gx[m1])/(gx[m1+1]-gx[m1-1])/2.0*(ro[v[1]]-ro[v[0]])/(gy[m2+1]-gy[m2]);
wn[0]+=5;
/**/
/**/
/**/
/*
for(n1=0;n1<=vn[0];n1++)printf("Vx %e %ld \n",wi[n1],wn[n1]);getchar();
*/
return 0;
}
/* Left+Right Side or Err for X-Stokes Equation */
/* LEFT+Right Side or Err for Y-Stokes Equation */
/* Stokes equation initial form */
/* dSIGyy/dY + dSIGxy/dX - dP/dY = - RO*Gy */
double ystokserr(long int m1, long int m2, int ynerr)
/* m1,m2 - node X,Y number */
/* ynerr - Err Calc Y(1)/N(0) */
{
/* Counters */
int n1;
long int v[4];
/* Err Buf */
double lefty,righty,nueff;
/* Distances */
double xkf=gx[m1+1]-gx[m1],ykf=(gy[m2+1]-gy[m2-1])/2.0;
double GYKOEFY=GYKOEF;
/**/
/**/
/**/
/* Staggered Nodes num */
/* */
/* Pr2,Syy2 */
/* */
/* [0] [2] */
/* Ro0,Sxy0,Nu0 <Vy0> Ro2,Sxy2,Nu2 */
/* */
/* Pr3,Syy3 */
/* */
/* [1] [3] */
/* */
v[0]=m1*ynumy+m2;v[1]=v[0]+1;
v[2]=v[0]+ynumy;v[3]=v[2]+1;
/**/
/**/
/**/
/* Spherical Gravity */
if(0==0)
{
GYKOEFY=-(gp[v[3]]-gp[v[2]])/ykf;
/*
printf("GY %ld %ld %e %e %e %e %e ",m1,m2,gp[v[3]],gp[v[1]],GYKOEFY,gp[v[3]],GXKOEF);getchar();
*/
}
/**/
/**/
/**/
/* RIGHT part of Y-Stokes */
/* dSIGik/dXk - dP/dXi = - Gi*RO */
righty = -GYKOEFY*(ro[v[0]]+ro[v[2]])/2.0;
/**/
/**/
/**/
/**/
/* Return val for LSQ err ----------------------------*/
if(ynerr==1)
{
/* LEFT part of Y-Stokes */
/* dSIGyy/dY + dSIGxy/dX - dP/dY = - RO*Gy */
/**/
/* dSIGyy/dY */
lefty =(syy[v[3]]-syy[v[2]])/ykf;
/* dSIGxy/dX */
lefty+=(sxy[v[2]]-sxy[v[0]])/xkf;
/* -dP/dY */
lefty-=(pr[v[3]]-pr[v[2]])/ykf;
/**/
/**/
/* FD stabilization mechanism included [T. Duretz et al., Geochem. Geophys. Geosyst., 12, Q07004, 2011] */
/* -gy/dt/2*(vy*dRHO/dy+vx*dRHO/dx) */
lefty-=timestep/2.0*GYKOEFY*(vy[v[0]]*(ro[v[1]]+ro[v[3]]-ro[v[0]-1]-ro[v[2]-1])/(gy[m2+1]-gy[m2-1])/2.0+((vx[v[0]]+vx[v[2]])*(gy[m2]-gy[m2-1])+(vx[v[0]-1]+vx[v[2]-1])*(gy[m2+1]-gy[m2]))/(gy[m2+1]-gy[m2-1])/2.0*(ro[v[2]]-ro[v[0]])/(gx[m1+1]-gx[m1]));
/**/
/**/
/* Effective NU calc */
nueff=(nu[v[0]]+nu[v[2]])/2.0;
/**/
/* Y-STOKES Error */
lefty=(lefty-righty)/nueff;
/**/
/* Min,Max Value of Nu Save */
errbuf[9]=nueff;
/* Min,Max Value of P Save */
errbuf[10]=MAXV(pr[v[2]],pr[v[3]]);
errbuf[11]=MINV(pr[v[2]],pr[v[3]]);
/**/
return lefty;
}
/**/
/**/
/**/
/* Set Initial Num of lines -------------------------------------- */
wn[0]=2;
/* Save Right parts Save for Y-Stokes ---------------------*/
wi[0]=righty;
/**/
/* Add Coefficients for left parts of Y-Stokes ----------------*/
/* Staggered Nodes num */
/* */
/* Pr2,Syy2 */
/* */
/* [0] [2] */
/* Ro0,Sxy0,Nu0 <Vy0> Ro2,Sxy2,Nu2 */
/* */
/* Pr3,Syy3 */
/* */
/* [1] [3] */
/* */
/* 0(P) 1(Vx) 2(Vy) */
/* -dP/dY */
wn[1]=v[2]*3+0;
wi[1]=+1.0/ykf;
wn[2]=v[3]*3+0;
wi[2]=-1.0/ykf;
/* dSIGyy/dY */
syycalc(m1+1,m2,-1.0/ykf);
syycalc(m1+1,m2+1,1.0/ykf);
/* dSIGxy/dX */
sxycalc(m1,m2,-1.0/xkf);
sxycalc(m1+1,m2,1.0/xkf);
/**/
/**/
/* FD stabilization mechanism included [T. Duretz et al., Geochem. Geophys. Geosyst., 12, Q07004, 2011] */
/* -gy/dt/2*(vy*dRHO/dy+vx*dRHO/dx) */
wn[wn[0]+1]=v[0]*3+2;
wi[wn[0]+1]=-timestep/2.0*GYKOEFY*(ro[v[1]]+ro[v[3]]-ro[v[0]-1]-ro[v[2]-1])/(gy[m2+1]-gy[m2-1])/2.0;
wn[wn[0]+2]=v[0]*3+1;
wi[wn[0]+2]=-timestep/2.0*GYKOEFY*(gy[m2]-gy[m2-1])/(gy[m2+1]-gy[m2-1])/2.0*(ro[v[2]]-ro[v[0]])/(gx[m1+1]-gx[m1]);
wn[wn[0]+3]=v[2]*3+1;
wi[wn[0]+3]=-timestep/2.0*GYKOEFY*(gy[m2]-gy[m2-1])/(gy[m2+1]-gy[m2-1])/2.0*(ro[v[2]]-ro[v[0]])/(gx[m1+1]-gx[m1]);
wn[wn[0]+4]=(v[0]-1)*3+1;
wi[wn[0]+4]=-timestep/2.0*GYKOEFY*(gy[m2+1]-gy[m2])/(gy[m2+1]-gy[m2-1])/2.0*(ro[v[2]]-ro[v[0]])/(gx[m1+1]-gx[m1]);
wn[wn[0]+5]=(v[2]-1)*3+1;
wi[wn[0]+5]=-timestep/2.0*GYKOEFY*(gy[m2+1]-gy[m2])/(gy[m2+1]-gy[m2-1])/2.0*(ro[v[2]]-ro[v[0]])/(gx[m1+1]-gx[m1]);
wn[0]+=5;
/**/
/**/
/**/
/*
for(n1=0;n1<=vn[0];n1++)printf("Vy %e %ld \n",wi[n1],wn[n1]);getchar();
*/
return 0;
}
/* Left+Right Side or Err for Y-Stokes Equation */
/* Left side or Err for Continuity Equation */
/* dVx/dX+dVy/dY = 0 */
double conterr(long int m1, long int m2, int ynerr)
/* m1,m2 - node X,Y number */
/* ynerr - Err Calc Y(1)/N(0) */
{
/* Counter */
long int v[4],m1min,m1max,m2min,m2max,m3;
/* Val Buffer */
double divv=0,xi;
int n1,nx,ny;
/**/
/* Staggered Nodes num */
/* [0] Vy0 [2] */
/* */
/* Vx0 <P3> Vx2 */
/* Exx3,Eyy3 */
/* */
/* [1] Vy1 [3] */
v[0]=(m1-1)*ynumy+(m2-1);v[1]=v[0]+1;
v[2]=v[0]+ynumy;v[3]=v[2]+1;
/**/
/**/
/**/
/* Calc, Check Fd limits for dVx/dX */
m1min=m1-1-stoksfd; if(m1min<0) m1min=0;
m1max=m1+stoksfd; if(m1max>xnumx-1) m1max=xnumx-1;
/**/
/* Current X position */
xi=(gx[m1-1]+gx[m1])/2.0;
/**/
/* Load distances to xn[] */
for (m3=m1min;m3<=m1max;m3++)
{
xn[m3-m1min]=gx[m3];
}
/**/
/* Calc maximal position in xn[] */
nx=(int)(m1max-m1min);
/**/
/* Calc Vx coefficients for EPSxx */
fdweight(nx,1,xi);
/* Reload coefficients to cn[] */
for (m3=0;m3<=nx;m3++)
{
cn[m3][2]=cn[m3][1];
}
/**/
/**/
/**/
/* Calc, Check Fd limits dVy/dY */
m2min=m2-1-stoksfd; if(m2min<0) m2min=0;
m2max=m2+stoksfd; if(m2max>ynumy-1) m2max=ynumy-1;
/**/
/* Current Y position */
xi=(gy[m2-1]+gy[m2])/2.0;
/**/
/* Load distances to xn[] */
for (m3=m2min;m3<=m2max;m3++)
{
xn[m3-m2min]=gy[m3];
}
/**/
/* Calc maximal position in xn[] */
ny=(int)(m2max-m2min);
/**/
/* Calc Vy coefficients for EPSyy */
fdweight(ny,1,xi);
/**/
/* Return dVx/dX+dVy/dY err ----------------------------*/
if(ynerr==1)
{
/* dVx/dX */
/* Add Vx with koefficients */
for (m3=m1min;m3<=m1max;m3++)
{
divv+=vx[m3*ynumy+(m2-1)]*cn[m3-m1min][2];
}
/**/
/* dVy/dY */
/* Add Vy with koefficients */
for (m3=m2min;m3<=m2max;m3++)
{
divv+=vy[(m1-1)*ynumy+m3]*cn[m3-m2min][1];
}
/**/
return divv;
}
/**/
/**/
/**/
/* Add continuity equation */
/* Set Initial Num of lines -------------------------------------- */
wn[0]=0;
/**/
/* Save Right part for Contin ---------------------*/
wi[0]=0;
/**/
/**/
/**/
/* Add Coefficients for left parts of dVx/dX ----------------*/
/* 0(P) 1(Vx) 2(Vy) */
/* Sxx=2Nu*Exx, Exx=dVx/dX */
/* Add Vx with koefficients */
for (m3=m1min;m3<=m1max;m3++)
{
wn[wn[0]+1+m3-m1min]=(m3*ynumy+(m2-1))*3+1;
wi[wn[0]+1+m3-m1min]=cn[m3-m1min][2];
}
/**/
/* Add total Num of lines */
wn[0]+=nx+1;
/**/
/**/
/**/
/* Add Coefficients for left parts of Syy ----------------*/
/* 0(P) 1(Vx) 2(Vy) */
/* Sxx=2Nu*Exx, Exx=dVx/dX */
/* Add Vy with koefficients */
for (m3=m2min;m3<=m2max;m3++)
{
wn[wn[0]+1+m3-m2min]=((m1-1)*ynumy+m3)*3+2;
wi[wn[0]+1+m3-m2min]=cn[m3-m2min][1];
}
/**/
/* Add total Num of lines */
wn[0]+=ny+1;
/**/
/**/
/**/
/* Check Boundary conditions around Cell */
divv=1.0;
if (!bondm[v[0]*3+1]) divv=0;
if (!bondm[v[0]*3+2]) divv=0;
if (!bondm[v[1]*3+2]) divv=0;
if (!bondm[v[2]*3+1]) divv=0;
/**/
/*
for(n1=0;n1<3;n1++)printf("Cont %e %d \n",wi[n1],wn[n1]);getchar();
*/
return divv;
}
/* Left side or Err for Continuity Equation */
/* Left side or Err for vX Boundary Condition Equation */
/* V=CONST+KOEF*Vn */
double xbonderr(long int mcmax, int ynerr)
/* mcmax - numer of cur Vx in sol[] */
/* ynerr - Err Calc Y(1)/N(0) */
{
/* Val Buffer */
double leftx=0;
int n1;
/**/
/**/
/**/
/* Error Calc */
if (ynerr)
{
/* Add Const */
leftx=x[mcmax]-bondv[bondm[mcmax]][0];
/* Add Koef */
for (n1=0;n1<3;n1++)
{
if(bondn[bondm[mcmax]][n1])
{
leftx-=bondv[bondm[mcmax]][n1+1]*x[bondn[bondm[mcmax]][n1]-1];
}
}
/**/
return leftx;
}
/**/
/**/
/**/
/* Add X CONST */
wn[0]=1;
wi[0]=bondv[bondm[mcmax]][0];
wn[1]=mcmax;
wi[1]=1.0;
/* Add X PAR1,PAR2,PAR3 */
for (n1=0;n1<3;n1++)
{
if(bondn[bondm[mcmax]][n1])
{
wn[0]+=1;
wn[wn[0]]=bondn[bondm[mcmax]][n1]-1;
wi[wn[0]]=-bondv[bondm[mcmax]][n1+1];
}
}
/**/
/*
for(n1=0;n1<3;n1++)printf("%e %ld \n",wi[n1],wn[n1]);getchar();
*/
return 0;
}
/* Left side or Err for vX Boundary Condition Equation */
/* Left side or Err for vY Boundary Condition Equation */
/* V=CONST+KOEF*Vn */
double ybonderr(long int mcmax, int ynerr)
/* mcmax - numer of cur Vx in sol[] */
/* ynerr - Err Calc Y(1)/N(0) */
{
/* Val Buffer */
double lefty=0;
int n1;
/**/
/**/
/**/
/* Error Calc */
if (ynerr)
{
/* Add Const */
lefty=x[mcmax]-bondv[bondm[mcmax]][0];
/* Add Koef */
for (n1=0;n1<3;n1++)
{
if(bondn[bondm[mcmax]][n1])
{
lefty-=bondv[bondm[mcmax]][n1+1]*x[bondn[bondm[mcmax]][n1]-1];
}
}
/**/
return lefty;
}
/**/
/**/
/**/
/* Add Y CONST */
wn[0]=1;
wi[0]=bondv[bondm[mcmax]][0];
wn[1]=mcmax;
wi[1]=1.0;
/* Add Y PAR1,PAR2,PAR3 */
for (n1=0;n1<3;n1++)
{
if(bondn[bondm[mcmax]][n1])
{
wn[0]+=1;
wn[wn[0]]=bondn[bondm[mcmax]][n1]-1;
wi[wn[0]]=-bondv[bondm[mcmax]][n1+1];
}
}
/*
for(n1=0;n1<3;n1++)printf("%e %d \n",wi[n1],wn[n1]);getchar();
*/
return 0;
}
/* Left side or Err for vY Boundary Condition Equation */
/* Left side or Err for P Boundary Condition Equation */
/* P=CONST+KOEF*Pn */
double pbonderr(long int mcmax, int ynerr)
/* mcmax - numer of cur P in sol[] */
/* ynerr - Err Calc Y(1)/N(0) */
{
/* Val Buffer */
double leftp;
int n1;
/**/
/**/
/**/
/* Error Calc */
if (ynerr)
{
/* Add Const */
leftp=x[mcmax]-bondv[bondm[mcmax]][0];
/* Add Koef */
for (n1=0;n1<3;n1++)
{
if(bondn[bondm[mcmax]][n1])
{
leftp-=bondv[bondm[mcmax]][n1+1]*x[bondn[bondm[mcmax]][n1]-1];
}
}
/**/
return leftp*leftp;
}
/**/
/**/
/**/
/* Add P CONST */
wn[0]=1;
wi[0]=bondv[bondm[mcmax]][0];
wn[1]=mcmax;
wi[1]=1.0;
/* Add P PAR1,PAR2,PAR3 */
for (n1=0;n1<3;n1++)
{
if(bondn[bondm[mcmax]][n1])
{
wn[0]+=1;
wn[wn[0]]=bondn[bondm[mcmax]][n1]-1;
wi[wn[0]]=-bondv[bondm[mcmax]][n1+1];
}
}
/*
for(n1=0;n1<3;n1++)printf("%e %d \n",wi[n1],wn[n1]);getchar();
*/
return 0;
}
/* Left side or Err for P Boundary Condition Equation */
/* Solve XY-Stokes+Continuity equations by vX,vY,P mixed arbitrary order Finite Diff method */
void viterate(int m0)
{
/* Counters */
long int m1,m2,m3,mcmax,mcmax0,mcmax1,dm1,dm2,ccc=0,n1;
double vxmin,vxmax,vymin,vymax,minvx=1e+30,maxvx=-1e+30,minvy=1e+30,maxvy=-1e+30,mindx,pmpa,minnu=1e+50,maxnu=-1e+50,minpr=1e+50,maxpr=-1e+50;
int printyn=printmod;
/**/
/* Val buffer */
double ival,ival1,mukoef;
/* Err koef */
double bondsum=0,bondnum=0;
double stoksum=0,stoknum=0;
double contsum=0,contnum=0;
double gamma=6.67384e-11,dx02,dx24,dy12,dy23;
double pival,rosum,ronum,dx,dy;
pival=2.0*asin(1.0);
/**/
/**/
/**/
/* Gravity field compute */
if(0==0)
{
/* Compute average density of the planet */
rosum=ronum=0;
/* Node Cycle */
for (m1=1;m1<xnumx;m1++)
for (m2=1;m2<ynumy;m2++)
{
/* Pos GP in sol0[] */
mcmax=m1*ynumy+m2;
/**/
/* Calc Distace */
dx=(gx[m1-1]+gx[m1]-xsize)/2.0;
dy=(gy[m2-1]+gy[m2]-ysize)/2.0;
ival=pow(dx*dx+dy*dy,0.5);
/* Compose boundary condition equations */
if(ival<GYKOEF)
{
ival1=(gx[m1]-gx[m1-1])*(gy[m2]-gy[m2-1]);
rosum+=ival1*(ro[mcmax-1-ynumy]+ro[mcmax-ynumy]+ro[mcmax-1]+ro[mcmax])/4.0;
ronum+=ival1;
}
}
/* Compute mass and gravity of the planet */
if(ronum>0)
{
rosum/=ronum;
GXKOEF=4.0/3.0*pival*GYKOEF*rosum*gamma;
/*
printf("%e %e",rosum,GXKOEF);getchar();
printf("%e %e %e",rosum,GYKOEF,GXKOEF);getchar();
printf("%e %e %e",rosum,rosum*4.0/3.0*pival*GYKOEF*GYKOEF*GYKOEF,GXKOEF);getchar();
*/
}
/**/
/* Clear New Solution */
/* P, Vx,Vy */
pos0cur=0;
/*
mukoef=1e-1;
*/
mukoef=2.0/xstpx/xstpx+2/ystpy/ystpy;
/**/
/**/
/* Add Matrix by gravity potential equation */
/* Node Cycle */
for (m1=0;m1<xnumx;m1++)
for (m2=0;m2<ynumy;m2++)
{
/* Pos GP in sol0[] */
mcmax=m1*ynumy+m2;
/**/
if(m1>0 && m2>0)
{
/* Calc Distace */
dx=(gx[m1-1]+gx[m1]-xsize)/2.0;
dy=(gy[m2-1]+gy[m2]-ysize)/2.0;
ival=pow(dx*dx+dy*dy,0.5);
/* Compose boundary condition equations */
/*
if(m1==1 || m1==xnumx-1 || m2==1 || m2==ynumy-1 || ival>GYKOEF)
*/
if(m1==1 || m1==xnumx-1 || m2==1 || m2==ynumy-1)
{
wn[0]=1;
wn[1]=mcmax;
/* Gravity potential for constant concentric acceleration */
wi[0]=-GXKOEF*GYKOEF*GYKOEF/ival*mukoef;
/*
wi[0]=0;
*/
wi[1]=1.0*mukoef;
gausmat4(1,mcmax,0);
}
/* Gravity potential per unit mass equation */
else
{
wn[0]=8;
wi[0]=4.0/1.5*pival*gamma*(ro[mcmax-1-ynumy]+ro[mcmax-ynumy]+ro[mcmax-1]+ro[mcmax])/4.0;
/* Cross */
/* m1-1 m1 m1+1 */
/* m2-1 G1 */
/* m2 G0 G2 G4 */
/* m2+1 G3 */
/* d(dG/dX)/dX = ((G4-G2)/dX24-(G2-G0)/dX02)/(dX02/2+dX24/2) */
dx02=(gx[m1]-gx[m1-2])/2.0;
dx24=(gx[m1+1]-gx[m1-1])/2.0;
wn[1]=mcmax-ynumy;
wi[1]= 2.0/dx02/(dx02+dx24);
wn[2]=mcmax;
wi[2]=-2.0/dx02/(dx02+dx24);
wn[3]=mcmax+ynumy;
wi[3]= 2.0/dx24/(dx02+dx24);
wn[4]=mcmax;
wi[4]=-2.0/dx24/(dx02+dx24);
/* d(dG/dY)/dY = ((G3-G2)/dY23-(G2-G1)/dY12)/(dY12/2+dY23/2) */
dy12=(gy[m2]-gy[m2-2])/2.0;
dy23=(gy[m2+1]-gy[m2-1])/2.0;
wn[5]=mcmax-1;
wi[5]= 2.0/dy12/(dy12+dy23);
wn[6]=mcmax;
wi[6]=-2.0/dy12/(dy12+dy23);
wn[7]=mcmax+1;
wi[7]= 2.0/dy23/(dy12+dy23);
wn[8]=mcmax;
wi[8]=-2.0/dy23/(dy12+dy23);
if(ival>GYKOEF)
{
wn[0]=9;
wi[0]-=GXKOEF*GYKOEF*GYKOEF/ival*mukoef*1e+18;
wn[9]=mcmax;
wi[9]=1.0*mukoef*1e+18;
}
gausmat4(1,mcmax,0);
}
}
/* Add ghost parameters */
else
{
wn[0]=1;
wi[0]=0;
wn[1]=mcmax;
wi[1]=1.0*mukoef;
gausmat4(1,mcmax,0);
}
/**/
}
/* Solve Matrix ==================================================== */
if (printmod) printf("Number of positions in global matrix = %ld Number of unknown = %ld \n",pos0cur,nodenum);
gausmat4(0,nodenum,0);
/*
gausmat3(0,nodenum-1,0);
gausmat4(0,nodenum,0);
*/
/* End Solve Matrix ==================================================== */
/**/
/* Reload GRAVITY POTENTIAL */
for (m1=0;m1<nodenum;m1++)
{
gp[m1]=x[m1];
}
/**/
/* New function included by Taras Gerya, compute magnitude of gravity acceleration */
/* Node Cycle */
for (m1=1;m1<xnumx-1;m1++)
for (m2=1;m2<ynumy-1;m2++)
{
/* Pos GP in sol0[] */
mcmax=m1*ynumy+m2;
{
/**/
/* gx-component */
ival=(gp[mcmax+ynumy]+gp[mcmax+ynumy+1]-gp[mcmax]-gp[mcmax+1])/(gx[m1+1]-gx[m1-1]);
/**/
/* gy-component */
ival1=(gp[mcmax+1]+gp[mcmax+ynumy+1]-gp[mcmax]-gp[mcmax+1])/(gy[m2+1]-gy[m2-1]);
/**/
/* Calculate magnitude of gravity acceleration for each node [m/s^2] */
ga[mcmax]=pow(ival*ival+ival1*ival1,0.500);
}
}
/* End upgrade */
}
/**/
/**/
/**/
/* Clear New Solution */
/* P, Vx,Vy */
pos0cur=0;
mukoef=nubeg*strmin;
/**/
/* Add Matrix by vX-vY-Stokes, Continuity, Boundary, EPS, SIG, Equations */
/* Node Cycle */
for (m1=0;m1<xnumx;m1++)
for (m2=0;m2<ynumy;m2++)
{
/* Pos P,Vx,Vy in sol0[] */
mcmax=(m1*ynumy+m2)*3;
/*
printf("P-Vx-Vy Cycle %ld %ld %ld",m1,m2,mcmax); getchar();
*/
/**/
/**/
/**/
/* Add Continuity equation for Cells ------------------------------------------------ */
if(m1 && m2)
{
/*
printf("Pr %ld %ld %ld",m1,m2,bondm[mcmax+0]); getchar();
*/
if(!bondm[mcmax+0])
{
/* Check Pressure in Cell calculation Y/N */
conterr(m1,m2,0);
/* Rescale coefficients */
for (n1=0;n1<=wn[0];n1++) wi[n1]*=mukoef;
gausmat4(1,mcmax+0,0);
}
else
{
/* Add P-Boundary */
pbonderr(mcmax+0,0);
/* Rescale coefficients */
for (n1=0;n1<=wn[0];n1++) wi[n1]*=mukoef;
gausmat4(1,mcmax+0,0);
}
}
/* Add ghost parameters */
else
{
wn[0]=1;
wi[0]=0;
wn[1]=mcmax+0;
wi[1]=mukoef;
gausmat4(1,mcmax+0,0);
}
/**/
/**/
/**/
/* Add vX-Equations --------------------------------------------------- */
if(m2<ynumy-1)
{
/*
printf("Vx %ld %ld %ld",m1,m2,bondm[mcmax+1]); getchar();
*/
if(!bondm[mcmax+1])
{
/* Add vX-Stokes */
xstokserr(m1,m2,0);
/**/
/* Add matrix */
/* vX */
gausmat4(1,mcmax+1,0);
/*
printf("Vx %ld %ld %ld",m1,m2,bondm[mcmax+1]); getchar();
*/
}
else
{
/* Continuity Equation Vx boundary condition */
if(bondv[bondm[mcmax+1]][1]>1e+30)
{
/* m1 m2 increment definition */
m3=(bondn[bondm[mcmax+1]][0]-1-(mcmax+1))/3;
dm1=dm2=0;
if(m3>=ynumy) dm1=1;
if(m3==1 || m3>ynumy) dm2=1;
/*
printf("Vx(%ld) P(%ld) boundary conditions for X=%ld Y=%ld Node",mcmax+1,bondn[bondm[mcmax+1]][0]-2,m1,m2); getchar();
*/
if(m3<0 || m3>ynumy+1 || !(m1+dm1) || !(m2+dm2) || !bondm[bondn[bondm[mcmax+1]][0]-2])
{
printf("EXIT PROGRAM Inconsistent Vx(%ld) P(%ld) boundary conditions for X=%ld Y=%ld Node",mcmax+1,bondn[bondm[mcmax+1]][0]-2,m1,m2);
exit(0);
}
conterr(m1+dm1,m2+dm2,0);
}
else
{
/* Add vX Simple Boundary */
xbonderr(mcmax+1,0);
}
/**/
/* Vx boundary condition Add */
/* Rescale coefficients */
for (n1=0;n1<=wn[0];n1++) wi[n1]*=mukoef;
gausmat4(1,mcmax+1,0);
}
}
/* Add ghost parameters */
else
{
wn[0]=1;
wi[0]=0;
wn[1]=mcmax+1;
wi[1]=mukoef;
gausmat4(1,mcmax+1,0);
}
/**/
/**/
/**/
/* Add vY-Equations --------------------------------------------------- */
if(m1<xnumx-1)
{
/*
printf("Vy %ld %ld %ld",m1,m2,bondm[mcmax+2]); getchar();
*/
if(!bondm[mcmax+2])
{
/* Add vX-Stokes */
ystokserr(m1,m2,0);
/**/
/* Add matrix */
/* vY */
gausmat4(1,mcmax+2,0);
/*
printf("Vy2 %ld %ld %ld",m1,m2,bondm[mcmax+8]); getchar();
*/
}
else
{
/* Continuity Equation Vy boundary condition */
if(bondv[bondm[mcmax+2]][1]>1e+30)
{
/* m1 m2 increment definition */
m3=(bondn[bondm[mcmax+2]][0]-1-(mcmax+2))/3;
dm1=dm2=0;
if(m3>=ynumy) dm1=1;
if(m3==1 || m3>ynumy) dm2=1;
if(m3<0 || m3>ynumy+1 || !(m1+dm1) || !(m2+dm2) || !bondm[bondn[bondm[mcmax+2]][0]-3])
/*
printf("Vy(%ld) P(%ld) boundary conditions for X=%ld Y=%ld Node",mcmax+2,bondn[bondm[mcmax+2]][0]-3,m1,m2); getchar();
*/
{
printf("EXIT PROGRAM Inconsistent Vy(%ld) P(%ld) boundary conditions for X=%ld Y=%ld Node",mcmax+2,bondn[bondm[mcmax+2]][0]-3,m1,m2);
exit(0);
}
conterr(m1+dm1,m2+dm2,0);
}
/* Simple Vy boundary condition */
else
{
/* Add vY Simple Boundary */
ybonderr(mcmax+2,0);
}
/**/
/* Vy boundary condition Add */
/* Rescale coefficients */
for (n1=0;n1<=wn[0];n1++) wi[n1]*=mukoef;
gausmat4(1,mcmax+2,0);
}
}
/* Add ghost parameters */
else
{
wn[0]=1;
wi[0]=0;
wn[1]=mcmax+2;
wi[1]=mukoef;
gausmat4(1,mcmax+2,0);
}
/**/
/**/
/**/
}
/* End Add Matrix By vX-vY-Stokes, Continuity Equations */
/**/
/**/
/**/
/* Solve Matrix ================================================ */
if (printmod) printf("Number of positions in global matrix = %ld Number of unknown = %ld \n",pos0cur,nodenum3);
gausmat4(0,nodenum3,0);
/* Solve Matrix ================================================ */
/**/
/**/
/**/
/* Reload P, Vx, Vy Results */
/* Node Cycle */
for (m1=0;m1<xnumx;m1++)
{
for (m2=0;m2<ynumy;m2++)
{
/* Pos P,Vx,Vy in sol0[] */
mcmax0=(m1*ynumy+m2)*3;
/* Pos in vx[], vy[], pr[], etc. */
mcmax1=m1*ynumy+m2;
/**/
/**/
/**/
/* Reload/Recalc P */
if(m1 && m2)
{
/* Reload P */
pr[mcmax1]=x[mcmax0+0];
}
/**/
/**/
/**/