cngf-pf

continuum model for granular flows with pore-pressure dynamics (renamed from 1d_fd_simple_shear)
git clone git://src.adamsgaard.dk/cngf-pf # fast
git clone https://src.adamsgaard.dk/cngf-pf.git # slow
Log | Files | Refs | README | LICENSE Back to index

commit a715c6d8412ec46c3df15b56f94a8331d4717870
parent c95b1939d5e265279eea39af7c47dbb863c21c22
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Wed, 14 Jan 2026 21:12:12 +0100

refactor(simulation): fuse transient field computation loops for better cache locality

Diffstat:
Msimulation.c | 30++++++++++++++++++++++++------
1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/simulation.c b/simulation.c @@ -471,6 +471,28 @@ compute_tan_dilatancy_angle(struct simulation *sim) } static void +compute_transient_fields(struct simulation *sim) +{ + int i; + + /* Fused loop: compute I, phi_c, and tan_psi in single pass */ + for (i = 0; i < sim->nz; ++i) { + /* Eq. 1: Inertia number */ + sim->I[i] = inertia_number(sim->gamma_dot_p[i], + sim->d, + fmax(sim->sigma_n_eff[i], SIGMA_N_EFF_MIN), + sim->rho_s); + + /* Eq. 2: Critical state porosity */ + sim->phi_c[i] = sim->phi_min + + (sim->phi_max - sim->phi_min) * sim->I[i]; + + /* Eq. 5: Dilatancy angle */ + sim->tan_psi[i] = sim->dilatancy_constant * (sim->phi_c[i] - sim->phi[i]); + } +} + +static void compute_porosity_change(struct simulation *sim) { int i; @@ -811,12 +833,8 @@ coupled_shear_solver(struct simulation *sim, if (sim->transient) { copy_values(sim->phi_dot, sim->old_val, sim->nz); - /* step 1 */ - compute_inertia_number(sim); /* Eq. 1 */ - /* step 2 */ - compute_critical_state_porosity(sim); /* Eq. 2 */ - /* step 3 */ - compute_tan_dilatancy_angle(sim); /* Eq. 5 */ + /* steps 1-3: fused computation of I, phi_c, tan_psi */ + compute_transient_fields(sim); /* Eqs. 1, 2, 5 */ } compute_critical_state_friction(sim); /* Eq. 7 */