commit 1d27bea446f7b34d61d3126d701dc9367a1b0ea6
parent e94f455468778b12e109147a3c3eb2732b554a9a
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Mon,  1 Jul 2019 13:11:58 +0200
Set fluid BCs in reusable function
Diffstat:
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/fluid.c b/fluid.c
@@ -60,6 +60,14 @@ sine_wave(const double time,
 	return amplitude*sin(2.0*PI*frequency*time + phase) + base_value;
 }
 
+static void
+set_fluid_bcs(struct simulation* sim, const double p_f_top)
+{
+	set_bc_dirichlet(sim->p_f_ghost, sim->nz, +1, p_f_top);
+	sim->p_f_ghost[idx1g(sim->nz-1)] = p_f_top; /* Include top node in BC */
+	set_bc_neumann(sim->p_f_ghost, sim->nz, -1);
+}
+
 static double
 darcy_pressure_change_1d(const int i,
                          const int nz,
@@ -129,9 +137,7 @@ darcy_solver_1d(struct simulation* sim,
 	                    sim->p_f_top);
 
 	/* set fluid BCs (1 of 2) */
-	set_bc_dirichlet(sim->p_f_ghost, sim->nz, +1, p_f_top);
-	sim->p_f_ghost[idx1g(sim->nz-1)] = p_f_top; /* Include top node in BC */
-	set_bc_neumann(sim->p_f_ghost, sim->nz, -1);
+	set_fluid_bcs(sim, p_f_top);
 
 	solved = 0;
 
@@ -154,18 +160,16 @@ darcy_solver_1d(struct simulation* sim,
 		dp_f_dt_impl = zeros(sim->nz);
 		p_f_ghost_out = zeros(sim->nz+2);
 		r_norm = zeros(sim->nz);
+
 		for (iter=0; iter<max_iter; ++iter) {
 
 			/* set fluid BCs (2 of 2) */
-			set_bc_dirichlet(sim->p_f_ghost, sim->nz, +1, p_f_top);
-			sim->p_f_ghost[idx1g(sim->nz-1)] = p_f_top;
-			set_bc_neumann(sim->p_f_ghost, sim->nz, -1);
+			set_fluid_bcs(sim, p_f_top);
 #ifdef DEBUG
 			puts(".. p_f_ghost after BC:");
 			print_array(sim->p_f_ghost, sim->nz+2);
 #endif
 
-			/* for (int i=0; i<sim->nz; ++i) */
 			for (i=0; i<sim->nz-1; ++i)
 				dp_f_dt_impl[i] = darcy_pressure_change_1d(i,
 				                                           sim->nz,