/** # Second order structure function The functions within this file aim to calculate a second-order longitudional structure function from a vector field. We can define a distance vector $\mathbf{l}$ separating two points in space $(\mathbf{x}_1,\ \mathbf{x}_1+\mathbf{l})$. Generally speaking, the vectors $\mathbf{u}$ at these points are different. The difference in the magnitude of their projections on the $\mathbf{l}$ vector may have some interesting properties. We define: $$\delta v_{\|}(\mathbf{x}_1,\mathbf{l})= \left( \mathbf{v}(\mathbf{x}_1)-\mathbf{v}(\mathbf{x}_1)\right) \cdot \frac{\mathbf{l}}{l},$$ where $l$ is $\|\mathbf{l}\|$. By definition, from a statistical perspective, within a homogeneous and isotropic region, one would expect $\|\delta v_{\|}(\mathbf{x_1,l})\|$ only to be dependend on $l$, i.e. the length of the separation vector. Therefore we can define a second order statistic related to a vector field ($\mathbf{u}$) according to: $$S_2(l)=\langle \delta v_{\|}(\mathbf{x}_1,\mathbf{l})^2 \rangle$$ where the variable $\langle x \rangle$ represents a region-averaged value of a dummy variable $x$. The code belows aims to evaluate some discretized version of $S_2(l)$ from a vector field on a three-dimensional-tree grid. There are many sub-functions so that maybe later, it may be modified/extended to e.g. 2D and 1D. First, a function is defined that selects j cells for analysis and stores the relevant data in an array. */ int obtain_a_cache(int j,double d[][6],int lev[],vector u){ #if _MPI MPI_Barrier(MPI_COMM_WORLD); #endif srand(time(NULL));// In order to obtain a smooth-ish pair distances distribution we add a stogastic component; int index[j]; int n=0; foreach() n++; double meaninc=(double)(n)/(double)(j); //The mean increment to obtain approx j cells. index[0]=0; int g=1; while (g0.&&l0.){ aa = dvarr[it][1]/dvarr[it][2]; dvarr[it][1] = aa; } dvarr[it][0]=it*Del; it++; } printdvarr(fp,dvarr,Len); #if _MPI } #endif return 1; } /** ## Usage * [Les of isotropic turbulence](isotropicLES.c) */