/** # Equidistant averaging in time Testing the equidistant averaging functions for convergence in time. First we define a function, cubed in space and squared in time. Moving at a speed of 1/tau. De time integration of this function is define afterwards. The choice for a more general function would be better, but this is just to see if the functions actually do what they say. Convergence in space and time will be very specific to the problem in question. */ #define func(s,d,f) (cube(s-sq(t/tau)) + cube(d) + cube(f)) #define Ifunc(s,d,f) (cube(d) + cube(f) + cube(s) - sq(s)*sq(t)/sq(tau) + 3*s*pow(t, 4)/5./pow(tau,4) - pow(t,6)/(7*pow(tau,6))) double tau; double ave_err; // Diagnosing total error #include "grid/octree.h" // 3D #include "run.h" int diagi = 0; int diaglvl = 4; // Level at which we want equidistant diagnostisation int minlevel = 4; int maxlevel = 4; // set equal to diag level such that spacial error = 0 scalar b[]; double *equifield = NULL; // The diagnostics field /** Used functions which are define at the end of the document */ int equi_diag (scalar s, int lvl, int diagii); void equi_output (scalar s, FILE * fp, int lvl, int diagii); int main(){ FILE * fp3 = fopen("output_time", "w"); // Specify te error output file L0=1.; int pp = 0; /** Loop over different DT to see if average converges */ for(DT = 0.1; DT > 0.001; DT = DT/2.){ init_grid(1< minlevel-1); } /** Set values of scalar b based on defined function */ event update(i++) { dt = dtnext(DT); foreach() { b[] = func(x, y, z); } boundary({b}); } /** Keeping track of the field b (averaging), here we cheat a bit since the error determination is defined in the function itself. */ event diag(i++){ fprintf(stderr, "time=%g\n",t); diagi = equi_diag(b, diaglvl, diagi); } /** Write away output of the averaging function */ event end(t=1){ FILE * fp2 = fopen("output", "w"); equi_output(b, fp2, diaglvl, diagi); fclose(fp2); } /** ## Results The average error seems to nicely converge in a linear fasion. ~~~gnuplot set xr [0.:0.11] set yr [0.:0.3] set xlabel 'DT' set ylabel 'Error plot 'output_time' using 2:1 title 'DT vs err' ~~~ */ /** ## Used functions NOTE: Very much in progress. These functions are geared towards equidistant diagnostics. The level for which diagnostics are done can be specified. Values will be linearly interpolated if necesarry. So far this function works with MPI and only works in 3D. Short description of what they do: //void equi_diag(scalar s){ adds values to the equifield array } //void equi_output(scalar s, FILE * fp){ outputs equifield to file fp in the format: place = x*n*n + y*n + z*n } TODO implement 2D TODO walking average since values in equifield get big, or divide before summing? */ int equi_diag (scalar s, int lvl, int diagii){ int len = 1; // TODO implement multiple scalar field averaging int n = 1<