Skip to content

Commit

Permalink
Adding code optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanPham committed May 24, 2024
1 parent c96c721 commit 19d7595
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/solve/Solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,26 @@ void Solver::run() {

int num_time_pts_in_two_cycles;
std::vector<State> states_last_two_cycles;
int last_two_cycles_time_pt_counter = 1;
int last_two_cycles_time_pt_counter = 0;
if (simparams.use_cycle_to_cycle_error) {
num_time_pts_in_two_cycles = 2 * (simparams.sim_pts_per_cycle - 1) + 1;
states_last_two_cycles =
std::vector<State>(num_time_pts_in_two_cycles, state);
}
for (int i = 1; i < simparams.sim_num_time_steps; i++) {
state = integrator.step(state, time);
if (simparams.use_cycle_to_cycle_error) {
if (last_two_cycles_time_pt_counter == num_time_pts_in_two_cycles - 1) {
std::rotate(states_last_two_cycles.begin(),
states_last_two_cycles.begin() + 1,
states_last_two_cycles.end());
if (i == simparams.sim_num_time_steps - num_time_pts_in_two_cycles + 1) {
// add first state
states_last_two_cycles[last_two_cycles_time_pt_counter] = state;
last_two_cycles_time_pt_counter +=
1; // last_two_cycles_time_pt_counter becomes 1
}
}
state = integrator.step(state, time);
if (simparams.use_cycle_to_cycle_error &&
last_two_cycles_time_pt_counter > 0) {
states_last_two_cycles[last_two_cycles_time_pt_counter] = state;
if (last_two_cycles_time_pt_counter < num_time_pts_in_two_cycles - 1) {
last_two_cycles_time_pt_counter += 1;
}
last_two_cycles_time_pt_counter += 1;
}
interval_counter += 1;
time = simparams.sim_time_step_size * double(i);
Expand All @@ -131,18 +133,21 @@ void Solver::run() {
get_vessel_caps_dof_indices();

if (!(this->model->get_has_windkessel_bc())) {
assert(last_two_cycles_time_pt_counter == num_time_pts_in_two_cycles - 1);
assert(last_two_cycles_time_pt_counter == num_time_pts_in_two_cycles);
double converged = check_vessel_cap_convergence(states_last_two_cycles,
vessel_caps_dof_indices);
int extra_num_cycles = 0;

while (!converged) {
std::rotate(
states_last_two_cycles.begin(),
states_last_two_cycles.begin() + simparams.sim_pts_per_cycle - 1,
states_last_two_cycles.end());
last_two_cycles_time_pt_counter = simparams.sim_pts_per_cycle;
for (size_t i = 1; i < simparams.sim_pts_per_cycle; i++) {
state = integrator.step(state, time);
std::rotate(states_last_two_cycles.begin(),
states_last_two_cycles.begin() + 1,
states_last_two_cycles.end());
states_last_two_cycles[last_two_cycles_time_pt_counter] = state;
last_two_cycles_time_pt_counter += 1;
interval_counter += 1;
time = simparams.sim_time_step_size * double(i);

Expand All @@ -158,6 +163,7 @@ void Solver::run() {
extra_num_cycles++;
converged = check_vessel_cap_convergence(states_last_two_cycles,
vessel_caps_dof_indices);
assert(last_two_cycles_time_pt_counter == num_time_pts_in_two_cycles);
}
std::cout << "Ran simulation for " << extra_num_cycles
<< " more cycles to converge flow and pressures at caps"
Expand Down

0 comments on commit 19d7595

Please sign in to comment.