-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFENE_effdiff.cpp
More file actions
2145 lines (1702 loc) · 54.5 KB
/
Copy pathFENE_effdiff.cpp
File metadata and controls
2145 lines (1702 loc) · 54.5 KB
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
// added flag -turnfivept_on which will read in tr_t.dat and spit out tr_fivept_t.dat
// and will also turn on flag fivept_on
// working on flag -rand_tr which when activated
// will randomize the initial tracer points
// added flag -fivept_on which will create a 5pt stencil around
// tracer points and update them for estimating lyap exponents
//
//
// added flag m and default falseod_off to turn off the mod in the tracer points
// use -mod_off to run tracer points without mod
//
// update trace with bicubic interpolation using FFT to get derivatives at corners
// 2/27/07 take away 2/3 de-alias replace with Hou filter
// modify 1/31/07 to limit modes of u used
// 5/23/06 modify to have time dependent f
// 4/28/06
// fixed de-aliasing 4/28/06
// modified 4/25/06 to have dynamic filenames!
// agrees with matlab code (n=128, 1000 iterations differs O(10^-15) for S and O(10^-16) for U
// VERSION 5 updates Shat with ABCN with 2/3 de-aliasing
// VERSION 4 does all of below but updates Shat rather than S
// still with Runge Kutta
// VERSION 3 does 2/3 versus doubling for de-aliasing
// This is the fully working fftw C code as of 2/24/06
// for 2 d Oldroyd-B
// modified for ibm fftw by estarose 1/26/06
// modified by becca 1/3/06
// rearranged the order to save after compute u,
// now writing files with 20.16e precision
// updating u in RK step!!
// Two dimension of Oldroyd-B.
#include "ConfigFile/ConfigFile.h"
#include <math.h>
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <fftw.h>
//#include "FENETiming.h"
#include "Interscale/Interscale.h"
#include "MacroscaleObjects.h"
using namespace CFD::Interscale;
using namespace std;
#define EPS .0000001
// Fill in the following parameters: N, dt (optional), Total_iterations, Wi, NU, start_w_zero, pertid, timedep_F,
// lastsaved, time_lastsaved
int N;
double dt;
//double Wi;
double NU;
int N2;
int KK;
//double reciprocal_Wi;
//double Beta;
int start_w_zero;
int pertid;
int timedep_F;
int tracer;
int restart_tr;
int mod_off;
int fivept_on;
int fivept;
int turnfivept_on;
int rand_tr;
// FENE Parameters
double deltaX, h, offset, D, H, Q0, lambda;
double lastsaved;
double finalTime;
double saveTime;
int dtOn;
int betaOn;
int tr_pts;
string configStr, dirStr;
// Claims of sub-functions.
void Hou_filter(double *Ahat_re, double *Ahat_im, int k_dim);
void Add_Shat(double *mid_Shat_Re, double *mid_shat_Im, double *S_hat_Re,
double *S_hat_Im);
void Get_Frequency(int Freq[]);
void initialization_S(double *S);
void initialization_tr(double *tr);
void init_tr_rand(double *tr);
void initialization_Spert(double *S);
void Get_F_hat(double *F_hat_Re, double *F_hat_Im);
void Get_F_hat_t(double *F_hat_Re, double *F_hat_Im, double time,
int iterations);
void Get_hat(double *A, double *A_hat_Re, double *A_hat_Im, int k_dim);
void Get_P_U_hat(double *P_hat_Re, double *P_hat_Im, double *U_hat_Re,
double *U_hat_Im, double *S_hat_Re, double *S_hat_Im, double *F_hat_Re,
double *F_hat_Im, int Freq[]);
void Get_gradUS_convolution(double *Re_gradUS_hat, double *Im_gradUS_hat,
double *S_hat_Re, double *S_hat_Im, double *U_hat_Re, double *U_hat_Im,
int Freq[]);
void Get_UgradS_convolution(double *Re_UgradS_hat, double *Im_UgradS_hat,
double *S_hat_Re, double *S_hat_Im, double *U_hat_Re, double *U_hat_Im,
int Freq[]);
void Get_U_S(double *U, double *U_hat_Re, double *U_hat_Im, int k_dim);
void update_S_hat(double *New_Shat_Re, double *New_Shat_Im, double *S_hat_Re,
double *S_hat_Im, double *U_hat_Re, double *U_hat_Im, int Freq[]);
void Save_U_S(double *U, char filename[], int k_dim);
void Save_tr(double *tr, char filename[], int fivept);
void zeroboundary_hat(double *A_hat_Re, double *A_hat_Im, int k_dim);
void Readin_S(double *S, char filename[], int k_dim);
void Readin_tr(double *tr, char filename[], int fivept);
void Euler_Step(double *S_hat_Re, double *S_hat_Im, double *RHS_Re,
double *RHS_Im, double nu, double ddt, int Freq[]);
void ABCN_Step(double *S_hat_Re, double *S_hat_Im, double *RHS_Re,
double *RHS_Im, double *old_RHS_Re, double *old_RHS_Im, double nu,
double ddt, int Freq[]);
void Euler_tr(double *tr, double *update, int fivept);
void AB_tr(double *tr, double *update, double *old_update, int fivept);
void get_fivept_tr(double *tr, double *tr_fivept);
void Get_update(double *tr, double *U, double *U_hat_Re, double *U_hat_Im,
double *update, int Freq[], int fivept);
void bcuint(double *y, double *y1, double *y2, double *y12, double x1l,
double x1u, double x2l, double x2u, double x1, double x2, double *ansy);
void readConfigFile();
void readParameters(int argc, char **argv);
void Get_mixd2U(double *gradU_hat_re, double *gradU_hat_im, double *mixd2U,
int Freq[]);
void Get_grad_hat(double *A_hat_re, double *A_hat_im, double *gradA_hat_re,
double *gradA_hat_im, int Freq[], int k_dim);
// END OF CLAIMS.
// define plans for fftw so that they are reusable
fftwnd_plan planN;
double PI2, kB;
//#define BECCA_DEBUG
#ifdef BECCA_DEBUG
#define UXY(kx,ky) \
({ \
cerr << "kx=" << kx << " ky=" << ky << " " << 2*(kx*N+ky) << endl; \
2*(kx*N+ky); \
})
#else
#define UXY(kx,ky) 2*(kx*N+ky)
#endif
////////////////////////////////////////////////////////////////////////////
////////////////////////////---Main Part---/////////////////////////////////
////////////////////////////////////////////////////////////////////////////
int main(int argc, char *argv[]) {
int Total_iterations;
int Record_iterations;
double *tr;
double *update;
double *old_update;
double *tr_fivept;
double *update_fivept;
double *old_update_fivept;
// double *tr_new;
// default parameters
PI2 = 8. * atan((double) 1.);
N = 512;
NU = 0.;
start_w_zero = true;
pertid = false;
timedep_F = false;
tracer = false;
lastsaved = 1.;
dtOn = true;
betaOn = true;
finalTime = 4.;
saveTime = 1.;
tr_pts = 64;
restart_tr = false;
mod_off = false;
fivept_on = false;
turnfivept_on = false;
rand_tr = false;
// ****************************************** //
// FENE PARAMETERS
Q0 = PI2 / 100.0;
h = Q0 * (2.0 / 30.0);
offset = h / 2;
D = 1;
H = 1;
lambda = 1;
deltaX = PI2 / N;
// END FENE PARAMETERS
// ****************************************** //
readParameters(argc, argv);
readConfigFile();
if (dtOn)
dt = .01 / (pow(2, (log2(N) - 6)));
cout << "deltaT should really equal " << dt << endl;
FokkerPlanckSolver fps(N, deltaX, dt, h, offset, D, H, Q0, lambda);
UniformAdvector advect(N, deltaX, deltaX, fps.getGrid());
Total_iterations = int(finalTime / dt + EPS);
Record_iterations = int(saveTime / dt + EPS);
// Total_iterations = int(finalTime *100 + EPS);
// Record_iterations = int(saveTime * 50 + EPS);
N2 = N * N;
KK = N / 2;
if (turnfivept_on)
fivept_on = true;
if (fivept_on)
fivept = 5;
else
fivept = 1;
// Allocate the matrices.
// tracer
if (tracer) {
tr = (double*) calloc((tr_pts * tr_pts * 2 * fivept), sizeof(double));
update = (double*) calloc((tr_pts * tr_pts * 2 * fivept),
sizeof(double));
old_update = (double*) calloc((tr_pts * tr_pts * 2 * fivept),
sizeof(double));
if (fivept_on) {
tr_fivept = (double*) calloc((tr_pts * tr_pts * 2 * fivept),
sizeof(double));
update_fivept = (double*) calloc((tr_pts * tr_pts * 2 * fivept),
sizeof(double));
old_update_fivept = (double*) calloc(
(tr_pts * tr_pts * 2 * fivept), sizeof(double));
}
}
// Pressure.
double *P = (double*) calloc(N2, sizeof(double));
double *P_hat_Re = (double*) calloc(N2, sizeof(double));
double *P_hat_Im = (double*) calloc(N2, sizeof(double));
// Velocity U=(u1, u2).
double *U = (double*) calloc(N2 * 2, sizeof(double));
CFD::VelocityArrayOrder<3> uOrder;
Array<double,3> Uarray(U,shape(N,N,2),neverDeleteData,uOrder);
double *U_hat_Re = (double*) calloc(N2 * 2, sizeof(double));
double *U_hat_Im = (double*) calloc(N2 * 2, sizeof(double));
// Stress tensor S=(S1, S2; S2, S3);
double *S = (double*) calloc(N2 * 3, sizeof(double));
CFD::SymmetricTensorArrayOrder<3> sOrder;
Array<double,3> Sarray(S,shape(N,N,3),neverDeleteData,sOrder);
double *S_hat_Re = (double*) calloc(N2 * 3, sizeof(double));
double *S_hat_Im = (double*) calloc(N2 * 3, sizeof(double));
double *RHS_Re = (double*) calloc(N2 * 3, sizeof(double));
double *RHS_Im = (double*) calloc(N2 * 3, sizeof(double));
double *old_RHS_Re = (double*) calloc(N2 * 3, sizeof(double));
double *old_RHS_Im = (double*) calloc(N2 * 3, sizeof(double));
// External force F=(f1, f2).
double *F = (double*) calloc(N2 * 2, sizeof(double));
double *F_hat_Re = (double*) calloc(N2 * 2, sizeof(double));
double *F_hat_Im = (double*) calloc(N2 * 2, sizeof(double));
// Frequency.
int *Freq = (int *) calloc(N, sizeof(int));
int i;
// General variables.
int iterations;
double time;
// Define data files.
char filename[132];
char dirname[80];
char command[132];
/////////////////////////////////////////////////////////////////////////
///////////////////--- STEP 1. Initialization ---////////////////////////
/////////////////////////////////////////////////////////////////////////
cout << " N = " << N << endl;
cout << " nu = " << NU << endl;
cout << " dt = " << dt << endl;
cout << " tracer = " << tracer << endl;
cout << " pert id = " << pertid << endl;
cout << " time dep f = " << timedep_F << endl;
cout << " save time = " << saveTime << endl;
cout << " final time = " << finalTime << endl;
cout << " restart tr = " << restart_tr << endl;
cout << " mod_off = " << mod_off << endl;
cout << " fivept_on = " << fivept_on << endl;
cout << " rand_tr = " << rand_tr << endl;
cout << " D = " << D << endl;
cout << " H = " << H << endl;
cout << " Q0 = " << Q0 << endl;
cout << " lambda = " << lambda << endl;
iterations = 0;
planN = fftw2d_create_plan(N, N, FFTW_FORWARD, FFTW_ESTIMATE
| FFTW_IN_PLACE);
/*sprintf(dirname, "./wi%.2f_n%d_nu%.6f_pi%d_td%d", Wi, N, NU, pertid,
timedep_F);*/
if(dirStr.empty()){
sprintf(dirname, "./data");
}
else{
sprintf(dirname, dirStr.c_str());
}
if (access(dirname, F_OK)) { /* data directory not present */
sprintf(command, "mkdir %s", dirname);
system(command);
}
/* If starting a new simulation, call this */
if (start_w_zero) {
time = 0;
if (pertid){
initialization_Spert(S);
}
else{
initialization_S(S);
Sarray = 0;
}
if (tracer) {
if (rand_tr)
init_tr_rand(tr);
else
initialization_tr(tr);
if (fivept_on)
get_fivept_tr(tr, tr_fivept);
}
}
/* If restarting a simulation, load from files */
else {
time = lastsaved;
sprintf(filename, "%s/S%3.15f.dat", dirname, lastsaved);
Readin_S(S, filename, 3);
sprintf(filename, "%s/RHS_re%3.15f.dat", dirname, lastsaved);
Readin_S(RHS_Re, filename, 3);
sprintf(filename, "%s/RHS_im%3.15f.dat", dirname, lastsaved);
Readin_S(RHS_Im, filename, 3);
if (tracer && !restart_tr) {
if (turnfivept_on) {
sprintf(filename, "%s/tr_%3.15f.dat", dirname, lastsaved);
Readin_tr(tr, filename, 1);
sprintf(filename, "%s/update%3.15f.dat", dirname, lastsaved);
Readin_tr(update, filename, 1);
get_fivept_tr(tr, tr_fivept);
}
else
if (fivept_on && !turnfivept_on) {
sprintf(filename, "%s/tr_fivept_%3.15f.dat", dirname,
lastsaved);
Readin_tr(tr_fivept, filename, fivept);
sprintf(filename, "%s/update_fivept_%3.15f.dat", dirname,
lastsaved);
Readin_tr(update_fivept, filename, fivept);
}
else {
sprintf(filename, "%s/tr_%3.15f.dat", dirname, lastsaved);
Readin_tr(tr, filename, fivept);
sprintf(filename, "%s/update%3.15f.dat", dirname, lastsaved);
Readin_tr(update, filename, fivept);
}
}
else {
if (rand_tr)
init_tr_rand(tr);
else
initialization_tr(tr);
if (fivept_on)
get_fivept_tr(tr, tr_fivept);
}
}
/* Compute Fourier transform of S, store the
* real and imaginary parts in S_hat_Re and S_hat_Im.
*/
Get_hat(S, S_hat_Re, S_hat_Im, 3);
zeroboundary_hat(S_hat_Re, S_hat_Im, 3);
/* Set frequency modes in Freq */
Get_Frequency(Freq);
/* Get the fourier transform of the forcing function,
* and store it in F_hat_Re and F_hat_Im
*/
if (timedep_F)
Get_F_hat_t(F_hat_Re, F_hat_Im, time, iterations);
else
Get_F_hat(F_hat_Re, F_hat_Im);
/////////////////////////////////////////////////////////////////////////
///////////////////--- STEP 2. Updating S, U ---/////////////////////////
/////////////////////////////////////////////////////////////////////////
// for saving data.
while (iterations <= Total_iterations) {
/*
* Order of solver:
*
* 1. Solve Stokes equations with current polymeric stress tensor S
* 2. Solve the configuration space portion of the Fokker-Planck equation
* for the pdf f(x,q,t) of polymer configurations
* 3. Use the current fluid velocity to solve the physical space portion
* of the Fokker-Planck equation, which advects it with the fluid velocity.
* 4. Calculate the polymeric stress tensor S from the current pdf of
* the polymer configuration
*/
/*
* 1. Solve Stokes equations with current polymeric stress tensor S
*/
// Compute Fourier Transform of S
Get_hat(S, S_hat_Re, S_hat_Im, 3);
// Solve for P_hat and U_hat in Fourier space
Get_P_U_hat(P_hat_Re, P_hat_Im, U_hat_Re, U_hat_Im, S_hat_Re, S_hat_Im,
F_hat_Re, F_hat_Im, Freq);
// Take the inverse Fourier transform to get U in physical space
Get_U_S(U, U_hat_Re, U_hat_Im, 2);
/*
* 2. Solve the configuration space portion of the Fokker-Planck equation
* for the pdf f(x,q,t) of polymer configurations
*/
fps.solveFokkerPlanck(Uarray);
/*
* 3. Use the current fluid velocity to solve the physical space portion
* of the Fokker-Planck equation, which advects it with the fluid velocity.
*/
advect.advectFromFlat(dt,Uarray,fps.f);
// advect.advect(dt,Uarray,fps.f);
/*
* 4. Calculate the polymeric stress tensor S from the current pdf of
* the polymer configuration
*/
fps.calculateStress(Sarray);
//cout << "Max of S: " << max(Sarray) << endl;
/* Save the current iteration if it is a savetime */
if ((iterations % Record_iterations) == 0) {
sprintf(filename, "%s/U%3.15f.dat", dirname, time);
//Get_U_S(U, U_hat_Re, U_hat_Im, 2);
Save_U_S(U, filename, 2);
sprintf(filename, "%s/S%3.15f.dat", dirname, time);
//Get_U_S(S, S_hat_Re, S_hat_Im, 3);
Save_U_S(S, filename, 3);
//cout << "bef if tracer " << endl;
if (tracer) {
if (fivept_on) {
sprintf(filename, "%s/tr_fivept_%3.15f.dat", dirname, time);
Save_tr(tr_fivept, filename, fivept);
}
else {
sprintf(filename, "%s/tr_%3.15f.dat", dirname, time);
Save_tr(tr, filename, fivept);
}
}
if (iterations > 0 || start_w_zero == false) {
sprintf(filename, "%s/RHS_re%3.15f.dat", dirname, time);
Save_U_S(RHS_Re, filename, 3);
sprintf(filename, "%s/RHS_im%3.15f.dat", dirname, time);
Save_U_S(RHS_Im, filename, 3);
if (tracer) {
if (fivept_on) {
sprintf(filename, "%s/update_fivept_%3.15f.dat",
dirname, time);
Save_tr(update_fivept, filename, fivept);
}
else {
sprintf(filename, "%s/update%3.15f.dat", dirname, time);
Save_tr(update, filename, fivept);
}
}
}
}
/*
* Solve the Fokker-Planck equation for f, and use f to get S.
* Then compute S_hat from S.
*/
/* bool doFENE = true;
if(doFENE && false){
cout << "Started updatePolymers()" << endl;
fps.updatePolymersAndCalculateStressTensor(U,S);
cout << "Finished updatePolymers()" << endl;
#ifdef FeneTiming
cout << "Ran updatePolymersAndCalculateStressTensor" << endl;
cout << "Calls to solver: " << CFD::Timing::callSolver;
cout << ". Total time in method: " << CFD::Timing::callSolverTime << endl;
cout << "Calls to stressAtPoint: " << CFD::Timing::stressAtPoint;
cout << ". Total time in method: " << CFD::Timing::stressAtPointTime << endl;
cout << "Total calls to updatePolymersAndCalculateStressTensor: " << CFD::Timing::callUpdatePolymers;
cout << ". Total time in method: " << CFD::Timing::callUpdatePolymersTime << endl;
#endif
Get_hat(S, S_hat_Re, S_hat_Im, 3);
//zeroboundary_hat(S_hat_Re, S_hat_Im, 3);
}
else if(false){
if (iterations == 0 && start_w_zero) {
update_S_hat(RHS_Re, RHS_Im, S_hat_Re, S_hat_Im, U_hat_Re,
U_hat_Im, Freq);
Euler_Step(S_hat_Re, S_hat_Im, RHS_Re, RHS_Im, NU, dt, Freq);
if (tracer && !fivept_on) {
Get_U_S(U, U_hat_Re, U_hat_Im, 2);
Get_update(tr, U, U_hat_Re, U_hat_Im, update, Freq, fivept);
Euler_tr(tr, update, fivept);
}
if (tracer && fivept_on) {
Get_U_S(U, U_hat_Re, U_hat_Im, 2);
Get_update(tr_fivept, U, U_hat_Re, U_hat_Im, update, Freq,
fivept);
Euler_tr(tr_fivept, update_fivept, fivept);
}
}
else {
for (i = 0; i < 3 * N2; i++) {
old_RHS_Re[i] = RHS_Re[i];
old_RHS_Im[i] = RHS_Im[i];
}
update_S_hat(RHS_Re, RHS_Im, S_hat_Re, S_hat_Im, U_hat_Re,
U_hat_Im, Freq);
ABCN_Step(S_hat_Re, S_hat_Im, RHS_Re, RHS_Im, old_RHS_Re,
old_RHS_Im, NU, dt, Freq);
if (tracer) {
if (restart_tr) {
if (fivept_on) {
Get_U_S(U, U_hat_Re, U_hat_Im, 2);
Get_update(tr_fivept, U, U_hat_Re, U_hat_Im, update,
Freq, fivept);
Euler_tr(tr_fivept, update_fivept, fivept);
}
else {
Get_U_S(U, U_hat_Re, U_hat_Im, 2);
Get_update(tr, U, U_hat_Re, U_hat_Im, update, Freq,
fivept);
Euler_tr(tr, update, fivept);
}
restart_tr = false;
}
else {
if (fivept_on) {
Get_U_S(U, U_hat_Re, U_hat_Im, 2);
for (i = 0; i < (2 * tr_pts * tr_pts * fivept); i++) {
old_update_fivept[i] = update_fivept[i];
}
Get_update(tr_fivept, U, U_hat_Re, U_hat_Im,
update_fivept, Freq, fivept);
AB_tr(tr_fivept, update_fivept, old_update_fivept,
fivept);
}
else {
Get_U_S(U, U_hat_Re, U_hat_Im, 2);
for (i = 0; i < (2 * tr_pts * tr_pts * fivept); i++) {
old_update[i] = update[i];
}
Get_update(tr, U, U_hat_Re, U_hat_Im, update, Freq,
fivept);
AB_tr(tr, update, old_update, fivept);
}
}
}
}
}*/
//cout << "Max velocity value is: " << max(Uarray) << endl;
// Advect Fokker-Planck solutions with fluid
/* if(time >= 10){
advect.advect(dt,Uarray,fps.f);
}*/
//cout << "bef if tracer3a " << endl;
iterations += 1;
time = time + dt;
if (timedep_F)
Get_F_hat_t(F_hat_Re, F_hat_Im, time, iterations);
if ((iterations % 100) == 0)
cout << " iterations === " << iterations << endl;
}
cout << "end reached" << endl;
/////////////////////////////////////////////////////////////////////////
///////////////////--- STEP 3. Saving U ---/////////////////////////
//////////////////////////////////////////////////////////////////////////
// FREE the assigned matrices.
free(P);
free(P_hat_Re);
free(P_hat_Im);
free(U);
free(U_hat_Re);
free(U_hat_Im);
free(S);
free(S_hat_Re);
free(S_hat_Im);
free(RHS_Re);
free(RHS_Im);
free(old_RHS_Re);
free(old_RHS_Im);
free(F);
free(F_hat_Re);
free(F_hat_Im);
if (tracer) {
free(tr);
free(old_update);
//free(tr_new);
free(update);
}
fftwnd_destroy_plan(planN);
}
////////////////////////////////////////////////////////////////////////////
void Readin_S(double *S, char filename[], int k_dim) {
FILE *fp;
int i, j, k, index;
double s;
fp = fopen(filename, "r");
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
index = (i * N + j) * k_dim;
for (k = 0; k < k_dim; k++) {
fscanf(fp, "%lf", &s);
//fscanf(fp, " ");
S[index + k] = s;
}
}
fscanf(fp, "\n");
}
fclose(fp);
}
void Readin_tr(double *tr, char filename[], int fivept) {
FILE *fp;
int i;
double s;
fp = fopen(filename, "r");
for (i = 0; i < (tr_pts * tr_pts * 2 * fivept); i++) {
fscanf(fp, "%lf", &s);
tr[i] = s;
}
fscanf(fp, "\n");
fclose(fp);
}
void initialization_S(double *S) {
double mesh_size = PI2 / N;
int i, j, index;
double x, y;
index = 0;
for (i = 0; i < N; i++)
for (j = 0; j < N; j++) {
x = i * mesh_size;
y = j * mesh_size;
S[index] = 1.0;
S[index + 1] = 0.0;
S[index + 2] = 1.0;
index += 3;
}
}
//void initialization_Spert( double *S )
//{
//
// double mesh_size = PI2/N;
//
// int i, j, index;
//
// double x, y;
//
// index = 0;
//
// for( i = 0; i < N; i ++ )
// for( j = 0; j < N; j ++ )
// {
//
// x = i*mesh_size;
// y = j*mesh_size;
//
//
// S[index] = 1. -(.05)*cos(y)*(-2*sin(x)-(3/2)*sin(2*x));
//
// S[index+1] = (.02)*cos(2*y)*sin(x);
//
// S[index+2] = 1. +(.06)*cos(x)*(-2*sin(y)-(3/2)*sin(2*y));
//
// index += 3;
// }
//}
void initialization_Spert(double *S) {
double mesh_size = PI2 / N;
int t, i, j, index, index1;
int start_val;
double wi_mult; // add a stronger perturbation if Wi is large because beta gets tiny so the effect on the
// velocity gets smaller
double x, y, rand_locx, rand_locy, nn1, nn2, scale, rr;
fftw_complex *g1 = (fftw_complex *) calloc(N2, sizeof(fftw_complex));
fftw_complex *g2 = (fftw_complex *) calloc(N2, sizeof(fftw_complex));
fftw_complex *g3 = (fftw_complex *) calloc(N2, sizeof(fftw_complex));
/* if (Wi < 10)
wi_mult = 1;
else
wi_mult = Wi / 10.;
*/
start_val = 60;
cout << "start_val = " << start_val << endl;
srand(start_val);
for (t = 1; t < 21; t++) {
rand_locx = PI2 * ((double) rand() / ((double) (RAND_MAX)
+ (double) (1)));
rand_locy = PI2 * ((double) rand() / ((double) (RAND_MAX)
+ (double) (1)));
nn1 = 100. * ((double) rand() / ((double) (RAND_MAX) + (double) (1)));
nn2 = 100. * ((double) rand() / ((double) (RAND_MAX) + (double) (1)));
scale = wi_mult * 1. / (pow((nn1 + nn2), .5)) * (1 / (pow(2., (nn1
+ nn2))));
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
index1 = i * N + j;
x = (N + i) * mesh_size;
y = j * mesh_size;
g1[index1].re = g1[index1].re + scale * (pow((1. + sin(x
- rand_locx)), nn1)) * (pow((1. + sin(y - rand_locy)),
nn2));
g1[index1].im = 0;
}
}
}
srand(start_val + 1);
for (t = 1; t < 21; t++) {
rand_locx = PI2 * ((double) rand() / ((double) (RAND_MAX)
+ (double) (1)));
rand_locy = PI2 * ((double) rand() / ((double) (RAND_MAX)
+ (double) (1)));
nn1 = 100. * ((double) rand() / ((double) (RAND_MAX) + (double) (1)));
nn2 = 100. * ((double) rand() / ((double) (RAND_MAX) + (double) (1)));
scale = wi_mult * 1. / (pow((nn1 + nn2), .5)) * (1 / (pow(2., (nn1
+ nn2))));
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
index1 = i * N + j;
x = (N + i) * mesh_size;
y = j * mesh_size;
g2[index1].re = g2[index1].re + scale * (pow((1. + sin(x
- rand_locx)), nn1)) * (pow((1. + sin(y - rand_locy)),
nn2));
g2[index1].im = 0;
}
}
}
srand(start_val + 2);
for (t = 1; t < 21; t++) {
rand_locx = PI2 * ((double) rand() / ((double) (RAND_MAX)
+ (double) (1)));
rand_locy = PI2 * ((double) rand() / ((double) (RAND_MAX)
+ (double) (1)));
nn1 = 100. * ((double) rand() / ((double) (RAND_MAX) + (double) (1)));
nn2 = 100. * ((double) rand() / ((double) (RAND_MAX) + (double) (1)));
scale = wi_mult * 1. / (pow((nn1 + nn2), .5)) * (1 / (pow(2., (nn1
+ nn2))));
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
index1 = i * N + j;
x = (N + i) * mesh_size;
y = j * mesh_size;
g3[index1].re = g3[index1].re + scale * (pow((1. + sin(x
- rand_locx)), nn1)) * (pow((1. + sin(y - rand_locy)),
nn2));
g3[index1].im = 0;
}
}
}
index = 0;
for (i = 0; i < N; i++)
for (j = 0; j < N; j++) {
x = (N + i) * mesh_size;
y = j * mesh_size;
index1 = i * N + j;
S[index] = 1. + g1[index1].re; //-(.05)*cos(y)*(-2*sin(x)-(3/2)*sin(2*x));
S[index + 1] = g2[index1].re; //(.02)*cos(2*y)*sin(x);
S[index + 2] = 1. + g3[index1].re; //+(.06)*cos(x)*(-2*sin(y)-(3/2)*sin(2*y));
index += 3;
}
// free the assigned arrays.
free(g1);
free(g2);
free(g3);
}
void initialization_tr(double *tr) {
double mesh_size = PI2 / tr_pts;
int i, j, index;
double x, y;
index = 0;
for (i = 0; i < tr_pts / 2; i++)
for (j = 0; j < tr_pts / 2; j++) {
x = i * mesh_size;
y = j * mesh_size;
tr[index] = x;
tr[index + 1] = y;
index += 2;
}
for (i = 0; i < tr_pts / 2; i++)
for (j = tr_pts / 2; j < tr_pts; j++) {
x = i * mesh_size;
y = j * mesh_size;
tr[index] = x;
tr[index + 1] = y;
index += 2;
}
for (i = tr_pts / 2; i < tr_pts; i++)
for (j = tr_pts / 2; j < tr_pts; j++) {
x = i * mesh_size;
y = j * mesh_size;
tr[index] = x;
tr[index + 1] = y;
index += 2;
}
for (i = tr_pts / 2; i < tr_pts; i++)
for (j = 0; j < tr_pts / 2; j++) {
x = i * mesh_size;
y = j * mesh_size;
tr[index] = x;
tr[index + 1] = y;
index += 2;
}
}
void init_tr_rand(double *tr) {
int i, j, index;
double XMin, XMax, YMin, YMax;
index = 0;
srand(11);
XMin = 1.;