an_01.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. //This is a hybrid lattice-Boltzmann code for nematic hydrodynamics
  2. //Create folder data!!
  3. //Compile with "gcc -O3 -o prog an_01.c -lm -lpthread -march=native -std=gnu99 -fopenmp -Wall -Wno-unused-variable -Wno-unused-but-set-variable"
  4. //Compile with "gcc -O3 -o prog an_01.c -lm -lpthread -march=native -std=gnu99 -fopenmp -Wall -Wno-unused-variable -Wno-unused-but-set-variable -Wno-format-overflow"
  5. //ActiveDroplet
  6. //Compile with "gcc -O3 -o prog2 an_01.c diff_eq_system.c -lm -lpthread -march=native -std=gnu99 -fopenmp -Wall -Wno-unused-variable -Wno-unused-but-set-variable -Wno-format-overflow"
  7. //gcc -O3 -o prog2 -g an_01.c diff_eq_system.c -lm -lpthread -march=native -std=gnu99 -fopenmp -Wall -Wno-unused-variable -Wno-unused-but-set-variable -Wno-format-overflow
  8. #include <math.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <time.h>
  12. #include <omp.h>
  13. #include <string.h>
  14. int I; //Number of points in each direction
  15. int J;
  16. int K;
  17. #define NMAX (I*J*K) //NMAX is no longer defined as (I+1)*(J+1)*(K+1)
  18. #define ST_HITROSTI 19 //Number of velocity vectors within the model -- in this case 3DQ19 -- 19 velocities To change the model, one needs to set new values of ST_HITROSTI, new vectors E and also set FEQ, P, and bounce-back
  19. #define STCASKOR 5000000
  20. #define STCASKORINIT 0
  21. #define STCASKORQ 1 //How many steps in Q are performed for each step in LB
  22. #define STKONV 100 //On how many steps the fields are written to a file
  23. #define STKONVV 10000 //On how many steps the fields are written to a file
  24. #define STKONG 100 //On how many steps the defect grad and config are written to a file
  25. #define TWRITEU 1 //Writes velocity
  26. #define TWRITEDEN 1 //Writes density
  27. #define TWRITEDIR 1 //Writes director field
  28. #define TWRITEOP 1 //Writes order parameter field
  29. #define TWRITEQ 1 //Writes Q-tensor field
  30. #define STDVF 100 //On how many steps the defect volume fraction is written to a file
  31. #define TWRITEDVF 1 //Writes defect volume fraction
  32. #define STFE 500 //On how many steps the free energy is written to a file
  33. #define TWRITEFE 1 //Writes free energy
  34. #define TWRITELOC 1 //Writes location of defects
  35. #define TWRITEgrad 1 //Writes defet gradients
  36. // #define STU 300 //Change the initial condition
  37. // #define initialU 1
  38. #define STCOPY 10000 //On how many steps the copy of DATA.bin is written to a file
  39. #define TWRITECOPY 1 //Writes copy of DATA.bin
  40. #define ZAPISF 1 //Write all necessary functions to a file at the end of the computation
  41. #define BERIF 0 //Read initialisation from the file
  42. #define READINITIAL 0
  43. // #define ZETAchange 70 //change zeta value
  44. //
  45. // #define ZETAstart 50 //change zeta value (start)
  46. // #define ZETAend 80 //change zeta value (end)
  47. //
  48. int STPROC=64; //Number of CPU cores for the paralelisation
  49. float **U, **F, **FEQ, **FNEW, **P; //Allocation of global matrices
  50. float **Q, **QNIC, **QNEW;
  51. float *WKONST;
  52. int **E;
  53. char *LMARK;
  54. float **UNIC;
  55. float **H;
  56. float **FORCE;
  57. float **TAU;
  58. char* QMARK;
  59. // number of surface data points
  60. int Qmax;
  61. float* QNC;
  62. float **gradU;
  63. float **gradU_defect;
  64. char Izpis[] = "droplet";
  65. char imeIzpis[100];
  66. #include "acn_funk_head.h" //function headers
  67. #include "diff_eq_system.h"
  68. #include "konstante.c"
  69. #include "num_rec.c" //All needed function from numerical recipes in a single file
  70. #include "acn_utils.c" //Useful functions -- utility
  71. #include "acn_active_droplet.c" //defects on shell
  72. #include "acn_funk_lb.c" //Lattice-Boltzmann part of the code
  73. #include"acn_funk_op.c"
  74. #include "acn_funk_zapis.c"
  75. int main(int argc, char** args){
  76. ZETA=(float) atof(args[1]);
  77. I=(int) atoi(args[2]);
  78. J=(int) atoi(args[3]);
  79. K=(int) atoi(args[4]);
  80. sprintf(imeIzpis, "%s-%dx%dx%d_%f", Izpis, I, J, K, ZETA);
  81. long Seed=12345; //Seed for random initial conditions
  82. char buf[256];
  83. int l,m;
  84. U=matrix(1,4,0,NMAX-1); // velocity field; 4th component is density
  85. F=matrix(0,ST_HITROSTI-1,0,NMAX-1); // Lattice Boltzmann scalar distribution functions to calculate velocity U
  86. FNEW=matrix(0,ST_HITROSTI-1,0,NMAX-1); // matrix field to temporarily store currently calculated F
  87. FEQ=matrix(0,ST_HITROSTI-1,0,NMAX-1); // Lattice Boltzmann scalar distribution functions to calculate velocity U - equilibrium; nedded in colloision operators
  88. P=matrix(0,ST_HITROSTI-1,0,NMAX-1); // Lattice Boltzmann scalar distribution functions to calculate velocity U - forcing term; needed in colloision operators
  89. TAU=matrix(1,9,0,NMAX-1);
  90. Q=matrix(1,6,0,NMAX-1); //Q-tensor
  91. QNEW=matrix(1,6,0,NMAX-1);
  92. QNIC=matrix(1,6,0,NMAX-1); //Qnic include info about the normal, prefered surface orientation and possibly also surface velocity
  93. WKONST=vector(0,18);
  94. LMARK=malloc(NMAX*sizeof(char));
  95. UNIC=matrix(1,3,0,NMAX-1); //Surface velocity (usually commented out to save time and RAM)
  96. gradU=matrix(1,3,0,NMAX-1);
  97. gradU_defect=matrix(1,3,0,NMAX-1);
  98. H=matrix(1,6,0,NMAX-1); //H tensor -- molecular field
  99. FORCE=matrix(1,3,0,NMAX-1); //FORCE = divergence of a total stress tensor -- needed to correct the velocity due to discrete effects
  100. E=imatrix(0,ST_HITROSTI-1,1,3); // matrix of all LB characteristic velocity lattice vectors
  101. initialiseE(); //Characteristic lattice vectors for the chosen LB model
  102. // if(BERIF){ sprintf(buf, "droplet-200x200x200_0.010000-DATA.bin", imeIzpis); beriDATA(buf); //Reads F
  103. if(BERIF){ sprintf(buf, "%s-DATA.bin", imeIzpis); beriDATA(buf); //Reads F
  104. for(l=0;l<NMAX;l++){
  105. for(m=0;m<ST_HITROSTI;m++) FNEW[m][l]=F[m][l]; //Transcribe F to FNEW
  106. FORCE[1][l]=0; FORCE[2][l]=0; FORCE[3][l]=0; calcF2Ul(l,F); //Compute U
  107. }
  108. }
  109. else{
  110. zacPriblQ(Seed);
  111. zacPriblUF(Seed); // initial condition for U and F
  112. }
  113. //read initial conditions (janus core)
  114. // if(READINITIAL) {sprintf(buf,"dim_par_eightL_relax_E01.raw"); beriDROPLETDATA(buf);}
  115. // if(READINITIAL) {sprintf(buf,"dim_par_satrn_relax_E01.raw"); beriDROPLETDATA(buf);}
  116. // ActiveDroplet sphere1;
  117. // ActiveDroplet* sphere1_ptr = &sphere1;
  118. // init_droplet(sphere1_ptr);
  119. // printf("Len after init: %d\n", sphere1.num_points);
  120. //printf("%d\n", sphere1.num_points);
  121. izrQU(); //Main computational loop
  122. //Calculates the upper estimates for the Reynolds and Ericksen number
  123. float umax=0;
  124. for(l=0;l<NMAX;l++) if(LMARK[l]&LMARK1){
  125. float delovni=fsqr(U[1][l]) + fsqr(U[2][l]) + fsqr(U[3][l]);
  126. if(delovni>umax) umax=delovni;
  127. }
  128. printf("reynolds: %e\nericksen: %e\n gostota: %f\n", 3*sqrt(umax)*I/(TAUF/DT-0.5f), 1.f/3.f*(TAUF/DT-0.5f)*DENSITYINIT*sqrt(umax)*I, DENSITYINIT);
  129. //Write the desired variables in .raw files
  130. //Write the desired variables in .vtk files
  131. sprintf(buf,"./data/%s_u.vtk",imeIzpis);
  132. zapisUraw(buf); // write velocity profile
  133. sprintf(buf,"./data/%s_den.vtk",imeIzpis);
  134. zapisDENraw(buf); // write density profile
  135. sprintf(buf,"./data/%s_dir.vtk",imeIzpis);
  136. zapisQ2DIRraw(buf);
  137. sprintf(buf,"./data/%s_op.vtk",imeIzpis);
  138. zapisQ2OPraw(buf);
  139. //sprintf(buf,"./data/%s_u.dat",imeIzpis); //velocity profile for gnuplot
  140. //za_profilU(buf,K/2,I/2);
  141. // zapisDVF(buf);
  142. //Write all the variables in a .bin file
  143. if(ZAPISF){ sprintf(buf, "%s-DATA.bin", imeIzpis); zapisDATA(buf);}
  144. //free all matrices
  145. free_matrix(U,1,4,0,NMAX-1); free_matrix(F,0,ST_HITROSTI-1,0,NMAX-1); free_matrix(FNEW,0,ST_HITROSTI-1,0,NMAX-1); free_matrix(FEQ,0,ST_HITROSTI-1,0,NMAX-1); free_matrix(P,0,ST_HITROSTI-1,0,NMAX-1); free_imatrix(E,0,ST_HITROSTI-1,1,3); free_matrix(Q,1,6,0,NMAX-1); free_matrix(QNEW,1,6,0,NMAX-1);
  146. free_matrix(QNIC,1,6,0,NMAX-1); free_vector(WKONST,0,18); free(LMARK); free_matrix(UNIC,1,3,0,NMAX-1);
  147. free_matrix(TAU,1,9,0,NMAX-1);
  148. free_matrix(H,1,6,0,NMAX-1); free_matrix(FORCE,1,3,0,NMAX-1); free_matrix(gradU,1,3,0,NMAX-1); free_matrix(gradU_defect,1,3,0,NMAX-1);
  149. return 0;
  150. }