commit b2f8d047df70db4aa5593bfafe9bd594312e1481
parent 4a6213835f491e0753ed1a3f864380a75a0d30cd
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Tue, 25 Jun 2019 17:11:38 +0200
Also normalize output files during the simulation
Diffstat:
3 files changed, 41 insertions(+), 33 deletions(-)
diff --git a/main.c b/main.c
@@ -47,33 +47,33 @@ static void usage(void)
" -I, --file-interval VAL interval between output files [s] (default %g)\n"
" -v, --version show version information\n"
" -h, --help show this message\n",
- __func__, PROGNAME,
- sim.name,
- sim.G,
- sim.P_wall,
- sim.mu_wall,
- sim.v_x_bot,
- sim.A,
- sim.b,
- sim.mu_s,
- sim.phi[0],
- sim.d,
- sim.rho_s,
- sim.nz,
- sim.origo_z,
- sim.L_z,
- sim.beta_f,
- sim.mu_f,
- sim.rho_f,
- sim.k[0],
- sim.p_f_top,
- sim.p_f_mod_ampl,
- sim.p_f_mod_freq,
- sim.p_f_mod_phase,
- sim.t,
- sim.t_end,
- sim.dt,
- sim.file_dt);
+ __func__, PROGNAME,
+ sim.name,
+ sim.G,
+ sim.P_wall,
+ sim.mu_wall,
+ sim.v_x_bot,
+ sim.A,
+ sim.b,
+ sim.mu_s,
+ sim.phi[0],
+ sim.d,
+ sim.rho_s,
+ sim.nz,
+ sim.origo_z,
+ sim.L_z,
+ sim.beta_f,
+ sim.mu_f,
+ sim.rho_f,
+ sim.k[0],
+ sim.p_f_top,
+ sim.p_f_mod_ampl,
+ sim.p_f_mod_freq,
+ sim.p_f_mod_phase,
+ sim.t,
+ sim.t_end,
+ sim.dt,
+ sim.file_dt);
free(sim.phi);
free(sim.k);
}
@@ -304,7 +304,7 @@ int main(int argc, char* argv[])
iter++;
if (filetimeclock >= sim.file_dt || iter == 0) {
- write_output_file(&sim);
+ write_output_file(&sim, normalize);
filetimeclock = 0.0;
}
}
diff --git a/simulation.c b/simulation.c
@@ -403,24 +403,32 @@ int implicit_1d_jacobian_poisson_solver(struct simulation* sim,
return 1;
}
-void write_output_file(struct simulation* sim)
+void write_output_file(struct simulation* sim, const int normalize)
{
-
char outfile[200];
FILE *fp;
sprintf(outfile, "%s.output%05d.txt", sim->name, sim->n_file++);
+ double *v_x_out = malloc(sim->nz*sizeof(double));
+ copy_values(sim->v_x, v_x_out, sim->nz);
+ if (normalize) {
+ double max_v_x = max(v_x_out, sim->nz);
+ for (int i=0; i<sim->nz; ++i)
+ v_x_out[i] /= max_v_x;
+ }
+
fp = fopen(outfile, "w");
if (sim->fluid)
for (int i=0; i<sim->nz; ++i)
fprintf(fp, "%.17g\t%.17g\t%.17g\t%.17g\t%.17g\n",
sim->z[i],
- sim->v_x[i],
+ v_x_out[i],
sim->sigma_n_eff[i],
sim->p_f_ghost[idx1g(i)],
sim->mu[i]);
else
- fprint_three_arrays(fp, sim->z, sim->v_x, sim->sigma_n_eff, sim->nz);
+ fprint_three_arrays(fp, sim->z, v_x_out, sim->sigma_n_eff, sim->nz);
+ free(v_x_out);
fclose(fp);
}
diff --git a/simulation.h b/simulation.h
@@ -122,6 +122,6 @@ int implicit_1d_jacobian_poisson_solver(
const int max_iter,
const double rel_tol);
-void write_output_file(struct simulation* sim);
+void write_output_file(struct simulation* sim, const int normalize);
#endif