tAdd output file writing and fix fluid command line argument - cngf-pf - contin… | |
git clone git://src.adamsgaard.dk/cngf-pf | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit a75692d10b150d7cae6f136737326033a8f40d0c | |
parent 750bf283e3904793069d4850c5faffdb74b37df9 | |
Author: Anders Damsgaard <[email protected]> | |
Date: Mon, 15 Apr 2019 15:22:55 +0200 | |
Add output file writing and fix fluid command line argument | |
Diffstat: | |
M arrays.c | 21 +++++++++++++++++++++ | |
M arrays.h | 11 +++++++++++ | |
M main.c | 56 ++++++++++++++++++++---------… | |
M parameter_defaults.h | 3 ++- | |
M simulation.c | 28 ++++++++++++++++++++++------ | |
M simulation.h | 2 ++ | |
6 files changed, 95 insertions(+), 26 deletions(-) | |
--- | |
diff --git a/arrays.c b/arrays.c | |
t@@ -135,6 +135,27 @@ void print_three_arrays( | |
printf("%.17g\t%.17g\t%.17g\n", a[i], b[i], c[i]); | |
} | |
+void fprint_arrays( | |
+ FILE* fp, | |
+ const double* a, | |
+ const double* b, | |
+ const int n) | |
+{ | |
+ for (int i=0; i<n; ++i) | |
+ fprintf(fp, "%.17g\t%.17g\n", a[i], b[i]); | |
+} | |
+ | |
+void fprint_three_arrays( | |
+ FILE* fp, | |
+ const double* a, | |
+ const double* b, | |
+ const double* c, | |
+ const int n) | |
+{ | |
+ for (int i=0; i<n; ++i) | |
+ fprintf(fp, "%.17g\t%.17g\t%.17g\n", a[i], b[i], c[i]); | |
+} | |
+ | |
void copy_values(const double* in, double* out, const int n) | |
{ | |
for (int i=0; i<n; ++i) | |
diff --git a/arrays.h b/arrays.h | |
t@@ -1,3 +1,5 @@ | |
+#include <stdio.h> | |
+ | |
#ifndef ARRAYS_ | |
#define ARRAYS_ | |
t@@ -35,6 +37,15 @@ void print_three_arrays( | |
const double* c, | |
const int n); | |
+void fprint_arrays(FILE* fp, const double* a, const double* b, const int n); | |
+ | |
+void fprint_three_arrays( | |
+ FILE* fp, | |
+ const double* a, | |
+ const double* b, | |
+ const double* c, | |
+ const int n); | |
+ | |
void copy_values(const double* in, double* out, const int n); | |
#endif | |
diff --git a/main.c b/main.c | |
t@@ -28,6 +28,7 @@ static void usage(void) | |
" -n, --resolution VAL number of cells in domain [-]\n" | |
" -o, --origo VAL coordinate system origo [m]\n" | |
" -L, --length VAL domain length [m]\n" | |
+ " -F, --fluid enable pore fluid computations\n" | |
" -v, --version show version information\n" | |
" -h, --help show this message\n" | |
, __func__, PROGNAME); | |
t@@ -51,7 +52,7 @@ int main(int argc, char* argv[]) | |
int normalize = 0; | |
int opt; | |
- const char* optstring = "hvNn:G:P:m:V:A:b:f:p:d:r:o:L:"; | |
+ const char* optstring = "hvNn:G:P:m:V:A:b:f:Fp:d:r:o:L:"; | |
const struct option longopts[] = { | |
{"help", no_argument, NULL, 'h'}, | |
{"version", no_argument, NULL, 'v'}, | |
t@@ -62,6 +63,7 @@ int main(int argc, char* argv[]) | |
{"nonlocal-amplitude", required_argument, NULL, 'A'}, | |
{"rate-dependence", required_argument, NULL, 'b'}, | |
{"friction-coefficient", required_argument, NULL, 'f'}, | |
+ {"fluid", no_argument, NULL, 'F'}, | |
{"porosity", required_argument, NULL, 'p'}, | |
{"grain-size", required_argument, NULL, 'd'}, | |
{"density", required_argument, NULL, 'r'}, | |
t@@ -126,6 +128,9 @@ int main(int argc, char* argv[]) | |
case 'L': | |
sim.L_z = atof(optarg); | |
break; | |
+ case 'F': | |
+ sim.fluid = 1; | |
+ break; | |
default: | |
fprintf(stderr, "%s: invalid option -- %c\n", argv[0], opt); | |
t@@ -141,31 +146,44 @@ int main(int argc, char* argv[]) | |
for (int i=0; i<sim.nz; ++i) | |
sim.phi[i] = new_phi; | |
- init_normal_stress(&sim); | |
- if (sim.fluid) | |
- init_water_pressure(&sim); | |
- compute_effective_stress(&sim); | |
- init_friction(&sim); | |
- compute_cooperativity_length(&sim); | |
+ double filetimeclock = 0.0; | |
+ while (sim.t <= sim.t_end) { | |
+ | |
+ init_normal_stress(&sim); | |
+ if (sim.fluid) | |
+ init_water_pressure(&sim); | |
+ compute_effective_stress(&sim); | |
+ init_friction(&sim); | |
+ compute_cooperativity_length(&sim); | |
- check_simulation_parameters(&sim); | |
+ check_simulation_parameters(&sim); | |
#ifdef DEBUG | |
- puts("\n## Before solver"); | |
- puts(".. sigma_n_eff:"); print_array(sim.sigma_n_eff, sim.nz); | |
- puts(".. mu:"); print_array(sim.mu, sim.nz); | |
+ puts("\n## Before solver"); | |
+ puts(".. sigma_n_eff:"); print_array(sim.sigma_n_eff, sim.nz); | |
+ puts(".. mu:"); print_array(sim.mu, sim.nz); | |
#endif | |
- if (implicit_1d_jacobian_poisson_solver(&sim, 10000, 1e-5)) | |
- exit(1); | |
+ if (implicit_1d_jacobian_poisson_solver(&sim, 10000, 1e-5)) | |
+ exit(1); | |
+ | |
+ compute_shear_strain_rate_plastic(&sim); | |
+ compute_shear_velocity(&sim); | |
+ | |
+ if (normalize) | |
+ print_arrays_2nd_normalized(sim.z, sim.v_x, sim.nz); | |
+ else | |
+ print_three_arrays(sim.z, sim.v_x, sim.sigma_n_eff, sim.nz); | |
- compute_shear_strain_rate_plastic(&sim); | |
- compute_shear_velocity(&sim); | |
+ sim.t += sim.dt; | |
+ filetimeclock += sim.dt; | |
- if (normalize) | |
- print_arrays_2nd_normalized(sim.z, sim.v_x, sim.nz); | |
- else | |
- print_three_arrays(sim.z, sim.v_x, sim.sigma_n_eff, sim.nz); | |
+ if (filetimeclock >= sim.file_dt) { | |
+ write_output_file(&sim); | |
+ filetimeclock = 0.0; | |
+ } | |
+ | |
+ } | |
free_arrays(&sim); | |
return 0; | |
diff --git a/parameter_defaults.h b/parameter_defaults.h | |
t@@ -47,7 +47,8 @@ struct simulation init_sim(void) | |
/* temporal settings */ | |
sim.t = 0.0; | |
- sim.t_end = 10.0; | |
+ sim.dt = 2.0; | |
+ sim.t_end = 1.0; | |
sim.file_dt = 0.1; | |
sim.n_file = 0; | |
diff --git a/simulation.c b/simulation.c | |
t@@ -96,11 +96,6 @@ void check_simulation_parameters(const struct simulation* s… | |
warn_parameter_value("sim.mu_s is negative", sim->mu_s, | |
&return_status); | |
- /* check_float("sim.phi", sim->phi, &return_status); */ | |
- /* if (sim->phi <= 0.0 || sim->phi > 1.0) */ | |
- /* warn_parameter_value("sim.phi is not in ]0;1]", sim->phi, */ | |
- /* &return_status); */ | |
- | |
check_float("sim.d", sim->d, &return_status); | |
if (sim->d <= 0.0) | |
warn_parameter_value("sim.d is not a positive number", sim->d, | |
t@@ -126,11 +121,15 @@ void check_simulation_parameters(const struct simulation… | |
&return_status); | |
check_float("sim.dz", sim->dz, &return_status); | |
- if (sim->dz <= 0) | |
+ if (sim->dz <= 0.0) | |
warn_parameter_value("sim.dz is not a positive number", sim->dz, | |
&return_status); | |
check_float("sim.t", sim->t, &return_status); | |
+ if (sim->t < 0.0) | |
+ warn_parameter_value("sim.t is a negative number", | |
+ sim->t, &return_status); | |
+ | |
check_float("sim.t_end", sim->t_end, &return_status); | |
if (sim->t > sim->t_end) | |
warn_parameter_value("sim.t_end is smaller than sim.t", | |
t@@ -142,12 +141,16 @@ void check_simulation_parameters(const struct simulation… | |
sim->dt, &return_status); | |
check_float("sim.file_dt", sim->file_dt, &return_status); | |
+ if (sim->file_dt < 0.0) | |
+ warn_parameter_value("sim.file_dt is a negative number", | |
+ sim->file_dt, &return_status); | |
if (sim->fluid != 0 && sim->fluid != 1) | |
warn_parameter_value("sim.fluid has an invalid value", | |
(double)sim->fluid, &return_status); | |
if (sim->fluid) { | |
+ | |
check_float("sim.p_f_mod_ampl", sim->p_f_mod_ampl, &return_status); | |
if (sim->p_f_mod_ampl < 0.0) | |
warn_parameter_value("sim.p_f_mod_ampl is not a zero or positive", | |
t@@ -371,3 +374,16 @@ int implicit_1d_jacobian_poisson_solver( | |
fprintf(stderr, ".. Residual normalized error: %f\n", r_norm_max); | |
return 1; | |
} | |
+ | |
+void write_output_file(struct simulation* sim) | |
+{ | |
+ | |
+ char outfile[200]; | |
+ FILE *fp; | |
+ sprintf(outfile, "%s.output%05d.txt", "testrun", sim->n_file++); | |
+ | |
+ fp = fopen(outfile, "w"); | |
+ fprint_three_arrays(fp, sim->z, sim->v_x, sim->sigma_n_eff, sim->nz); | |
+ | |
+ fclose(fp); | |
+} | |
diff --git a/simulation.h b/simulation.h | |
t@@ -112,4 +112,6 @@ int implicit_1d_jacobian_poisson_solver( | |
const int max_iter, | |
const double rel_tol); | |
+void write_output_file(struct simulation* sim); | |
+ | |
#endif |