/************************************************************************************************ * * * Ginz1D.c * * * * * * Solves the 1D Ginzburg-Landau-equation using a pseudospectral scheme in spatial domain * * and a exponential time-differencing scheme in temporal domain. * * The program displays its results as a space-time plot using dislin. * * * * * * Some parameter sets: * * (alpha, beta) = ( 1.0, 2.0) //plain waves * * = ( 2.0, -1.0) //phase turbulence * * = ( 2.0, -2.0) //defect turbulence * * = ( 0.5, -1.5) //intermittency * * = ( 0.0, -4.0) //intermittency * * = ( 0.0, 1.5) //coherent structures * * * * * * compile with * * gcc -std=c99 -O3 -Wall -o Ginz1D Ginz1D.c -I(FFTW3_PATH)/include * * -L(FFTW_PATH)/lib -lfftw3 -I(DISLIN_PATH) -L(DISLIN_PATH) -ldislin -lm * * * * * * author: Johannes Luelff (johannes.luelff@uni-muenster.de) * * * ************************************************************************************************/ #include #include //we want to use the C99 complex data type, so we need complex.h #include #include #include "fftw3.h" #include "dislin.h" //these two defines control whether we... //... want to use dislin (we surely want to, cause otherwise // this program wouldnt produce any output) #define USE_DISLIN //... want dislin to print its result into a PNG file or onto the screen #undef USE_PNG //constants etc. #define PI 3.14159265358979323846264338327950288419716939937510582097494459230781 const int N = 512; //Grid resolution const double L = 200; //Physical length const double alpha = 0.0; //coefficients of GL-equation const double beta = -4.0; // -"- const int MAX_ITER = 10000; //maximal number of iterations; const int EVERY_OUT = 5; //use every 'EVERY_OUT'-th timestep for display const int EVERY_DISLIN = 10; //display, once 'EVERY_DISLIN' timesteps are gathered //time(step) double t = 0; double dt = 0.05; //arrays etc. complex *A; //the 'main' field complex *Aedt_N1; //field for nonlinearity... complex *Aedt_N2; //... and backup field for nonlin. from previous timestep complex *Atmp; double *kabsvec; //vector that stores |k|**2 float *A_dislin_left, *A_dislin_right; //used for display with dislin complex *A_display; //2D field for the space-time plot fftw_plan planS2F, planF2S; //plan for spatial to fourier, fourier to spatial //multiplies array with scalar void smultArray(complex *arr, double s) { for(int i=0; imax_left) max_left = A_dislin_left[i]; } if(fabs(min_left-max_left)<1e-6) { min_left=-0.1; max_left= 0.1; } //prepare output array for dislin (right panel) double min_right = HUGE_VAL; double max_right = -HUGE_VAL; for(int i=0; imax_right) max_right = A_dislin_right[i]; } if(fabs(min_right-max_right)<1e-6) { min_right=-0.1; max_right= 0.1; } //plot with dislin #ifdef USE_PNG //init dislin metafl("PNG"); setfil("out.png"); scrmod("REVERS"); winsiz(1280,640); page(2970*2,2970); disini(); ax3len(2970*0.75, 2970*0.75, 2970*0.75); #endif //USE_PNG erase(); axspos(2970*0.1,2970*0.85); graf3(0,L,0,L/2, 0,L,0,L/2, min_left, max_left, min_left, (max_left-min_left)/2); crvmat(A_dislin_left, N, N, ((512/N)<=0)?1:(512/N), ((512/N)<=0)?1:(512/N)); titlin("Real(A)", 3); title(); endgrf(); axspos(2970*1.1,2970*0.85); graf3(0,L,0,L/2, 0,L,0,L/2, min_right, max_right, min_right, (max_right-min_right)/2); crvmat(A_dislin_right, N, N, ((512/N)<=0)?1:(512/N), ((512/N)<=0)?1:(512/N)); titlin("Abs(A)", 3); title(); endgrf(); #ifdef USE_PNG disfin(); #endif //USE_PNG } int main(int argc, char *argv[]) { //get memory A = fftw_malloc(sizeof(complex)*N); Atmp = fftw_malloc(sizeof(complex)*N); Aedt_N1 = fftw_malloc(sizeof(complex)*N); Aedt_N2 = fftw_malloc(sizeof(complex)*N); kabsvec = fftw_malloc(sizeof(double)*N); A_dislin_left = fftw_malloc(sizeof(float)*N*N); A_dislin_right = fftw_malloc(sizeof(float)*N*N); A_display = fftw_malloc(sizeof(complex)*N*N); //its a space-time plot that fills constantly, so we init it to 0 for(int i=0; i=1; j--) { A_display[i*N+j] = A_display[i*N+j-1]; } } assignArrays(Atmp, A); fftF2S(Atmp); for(int i=0; i