Ian Jauslin
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Jauslin <ian@jauslin.org>2022-05-19 18:35:33 +0200
committerIan Jauslin <ian@jauslin.org>2022-05-19 18:35:33 +0200
commit6fbcb8665824b0c1edbbe8cb18d509ca7e006e49 (patch)
tree8030efad7b1fa951a543fc544adfcf78da2c1b8c /src/navier-stokes.c
parent146903265abcfb0dce8ee6075b1cd355cab3ab94 (diff)
Compute energy
Diffstat (limited to 'src/navier-stokes.c')
-rw-r--r--src/navier-stokes.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/navier-stokes.c b/src/navier-stokes.c
index 18c2fc5..0a2842c 100644
--- a/src/navier-stokes.c
+++ b/src/navier-stokes.c
@@ -68,6 +68,55 @@ int uk(
return(0);
}
+// compute the energy as a function of time
+int energy(
+ int K1,
+ int K2,
+ int N1,
+ int N2,
+ unsigned int nsteps,
+ double nu,
+ double delta,
+ _Complex double (*g)(int,int),
+ unsigned int print_freq,
+ unsigned int nthreads
+){
+ _Complex double* u;
+ _Complex double* tmp1;
+ _Complex double* tmp2;
+ _Complex double* tmp3;
+ unsigned int t;
+ fft_vect fft1;
+ fft_vect fft2;
+ fft_vect ifft;
+ int kx,ky;
+ double energy;
+
+ ns_init_tmps(&u, &tmp1, &tmp2, &tmp3, &fft1, &fft2, &ifft, K1, K2, N1, N2, nthreads);
+ ns_init_u(u, K1, K2);
+
+ // iterate
+ for(t=0;t<nsteps;t++){
+ ins_step(u, K1, K2, N1, N2, nu, delta, g, fft1, fft2, ifft, tmp1, tmp2, tmp3);
+
+ if(t%print_freq==0){
+
+ energy=0.;
+ for(kx=-K1;kx<=K1;kx++){
+ for (ky=-K2;ky<=K2;ky++){
+ energy+=__real__ (u[klookup(kx,ky,2*K1+1,2*K2+1)]*conj(u[klookup(kx,ky,2*K1+1,2*K2+1)]));
+ }
+ }
+
+ fprintf(stderr,"%d % .8e % .8e\n",t,t*delta, energy);
+ printf("%8d % .15e % .15e\n",t,t*delta,energy);
+ }
+ }
+
+ ns_free_tmps(u, tmp1, tmp2, tmp3, fft1, fft2, ifft);
+ return(0);
+}
+
// compute enstrophy as a function of time in the I-NS equation
int enstrophy(
int K1,