/** # Equidistant averaging in time Testing the equidistant averaging functions for convergence in space. 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 = 6; // make minlvl = maxlvl, such that spacial error can be speciified int maxlevel = 6; 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_space", "w"); // Specify te error output file L0=1.; DT = 0.01; // Putting DT sufficiently low (error domination by space) int pp = 0; /** Loop over different DT to see if average converges */ for(diaglvl = 2; diaglvl < 7; diaglvl += 1){ init_grid(1< minlevel-1); // such that we have multiple resolutions present } /** 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 solution converges more then linearly. This is probably do to the behaviour of the cubic in space function. Overall the error at diag level 4 already falls way below 1 percent, which is a good sign. ~~~gnuplot set xr [1.:7.] set yr [0.:10] set xlabel 'diaglvl' set ylabel 'Mean Error percentage' set size square plot 'output_space' using 3:(100*$1) title "diaglvl vs error" ~~~ */ /** ## Used functions IMPORTANT: for the most recent version look [here](averaging.h) 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<