@@ -231,7 +231,8 @@ void Simulation::write_avg_thickness_file()
231231
232232 // This lambda performs bisection search to find the threshold thickness at which a
233233 // relative volume proportion of `thresh` is contained within cells with greater thickness than the threshold thickness
234- auto bisection_search = [&]( double thresh, double tol, int max_iter ) {
234+ auto bisection_search = [&]( double thresh, double tol, int max_iter )
235+ {
235236 int idx_lo = 0 ;
236237 int idx_hi = n_cells - 1 ;
237238
@@ -417,32 +418,43 @@ RunStatus Simulation::steps( int n_steps )
417418 auto & n_lobes = simulation_state->n_lobes ;
418419
419420 // Now we have to figure out the value of idx_flow and if we are past n_init or not
420- const int step_initial = simulation_state->step ;
421-
422- for ( int step = step_initial; step < step_initial + n_steps; step++ )
421+ for ( int step = 0 ; step < n_steps; step++ )
423422 {
424- const bool is_last_step_of_flow = idx_lobe == n_lobes - 1 ;
425- const bool is_first_step_of_new_flow = simulation_state->beginning_of_new_flow ;
426- const bool is_an_initial_lobe = idx_lobe < input.n_init ;
427- const bool is_last_step = ( idx_flow == input.n_flows ) && is_last_step_of_flow;
423+ std::cout << " step " << step << " \n " ;
424+ std::cout << " idx_flow " << idx_flow << " \n " ;
425+ std::cout << " idx_lobe " << idx_lobe << " \n " ;
426+ std::cout << " n_lobes " << n_lobes << " \n " ;
427+ std::cout << " n_lobes_processed " << n_lobes_processed << " \n " ;
428+
429+ const bool is_last_step_of_flow = idx_lobe == n_lobes - 1 ;
430+ const bool is_an_initial_lobe = idx_lobe < input.n_init ;
431+ const bool is_last_step = ( idx_flow == input.n_flows - 1 ) && is_last_step_of_flow;
428432
429- if ( is_first_step_of_new_flow )
433+ std::cout << " is_last_step_of_flow " << is_last_step_of_flow << " \n " ;
434+ std::cout << " is_an_initial_lobe " << is_an_initial_lobe << " \n " ;
435+ std::cout << " is_last_step " << is_last_step << " \n ===== \n\n " ;
436+
437+ if ( simulation_state->beginning_of_new_flow )
430438 {
431- // simulation_state->idx_flow++;
432- simulation_state->n_lobes_current_flow
433- = MrLavaLoba::compute_n_lobes ( simulation_state->idx_flow , input, gen );
434- simulation_state->lobes = std::vector<Lobe>{};
435- simulation_state->lobes .reserve ( simulation_state->n_lobes_current_flow );
439+ simulation_state->n_lobes = MrLavaLoba::compute_n_lobes ( simulation_state->idx_flow , input, gen );
440+ simulation_state->lobes = std::vector<Lobe>{};
441+ simulation_state->lobes .reserve ( simulation_state->n_lobes );
436442 // set the intersection cache
437- topography.reset_intersection_cache ( simulation_state->n_lobes_current_flow );
443+ topography.reset_intersection_cache ( simulation_state->n_lobes );
438444
439445 // set idx_lobe to zero, because we are at the beginning of a flow
440446 idx_lobe = 0 ;
441447
442- // switch back the flag
448+ // switch back the flag
443449 simulation_state->beginning_of_new_flow = false ;
444450 }
445451
452+ if ( idx_lobe >= n_lobes || idx_flow >= input.n_flows )
453+ {
454+ run_status = RunStatus::Finished;
455+ break ;
456+ }
457+
446458 if ( is_an_initial_lobe )
447459 {
448460 lobes.emplace_back ();
@@ -472,7 +484,6 @@ RunStatus Simulation::steps( int n_steps )
472484
473485 // Add rasterized lobe
474486 topography.add_lobe ( lobe_cur, input.volume_correction , idx_lobe );
475- n_lobes_processed++;
476487 write_thickness_if_necessary ( n_lobes_processed );
477488 }
478489 else
@@ -482,7 +493,8 @@ RunStatus Simulation::steps( int n_steps )
482493
483494 // Select which of the previously created lobes is the parent lobe
484495 // from which the new descendent lobe will bud
485- const auto idx_parent = MrLavaLoba::select_parent_lobe ( idx_lobe, lobes, input, common_lobe_dimensions, gen );
496+ const auto idx_parent
497+ = MrLavaLoba::select_parent_lobe ( idx_lobe, lobes, input, common_lobe_dimensions, gen );
486498 const Lobe & lobe_parent = lobes[idx_parent];
487499
488500 // stopping condition (parent lobe close the domain boundary or at a not defined z value)
@@ -495,7 +507,8 @@ RunStatus Simulation::steps( int n_steps )
495507
496508 // Find the preliminary budding point on the perimeter of the parent lobe (npoints is the number of raster
497509 // points on the ellipse)
498- const Flowy::Vector2 budding_point = topography.find_preliminary_budding_point ( lobe_parent, input.npoints );
510+ const Flowy::Vector2 budding_point
511+ = topography.find_preliminary_budding_point ( lobe_parent, input.npoints );
499512
500513 const auto [height_lobe_center, slope_parent] = topography.height_and_slope ( lobe_parent.center );
501514 const auto [height_bp, slope_bp] = topography.height_and_slope ( budding_point );
@@ -523,7 +536,8 @@ RunStatus Simulation::steps( int n_steps )
523536 break ;
524537 }
525538 // Get the slope at the final budding point
526- const double slope_budding_point = topography.slope_between_points ( lobe_parent.center , final_budding_point );
539+ const double slope_budding_point
540+ = topography.slope_between_points ( lobe_parent.center , final_budding_point );
527541
528542 // compute the new lobe axes
529543 MrLavaLoba::compute_lobe_axes ( lobe_cur, slope_budding_point, input, common_lobe_dimensions );
@@ -544,14 +558,14 @@ RunStatus Simulation::steps( int n_steps )
544558
545559 // Add rasterized lobe
546560 topography.add_lobe ( lobe_cur, input.volume_correction , idx_lobe );
547- n_lobes_processed++;
548561 write_thickness_if_necessary ( n_lobes_processed );
549562 }
550563
564+ n_lobes_processed++;
565+ idx_lobe++;
566+
551567 if ( is_last_step_of_flow )
552568 {
553- // Increment idx_flow
554- idx_flow++;
555569 simulation_state->beginning_of_new_flow = true ;
556570
557571 if ( input.save_hazard_data )
@@ -572,15 +586,14 @@ RunStatus Simulation::steps( int n_steps )
572586 ( input.n_flows - idx_flow - 1 ) * ( t_cur - simulation_state->t_run_start ) / ( idx_flow + 1 ) );
573587 fmt::print ( " remaining_time = {:%Hh %Mm %Ss}\n " , remaining_time );
574588 }
589+ idx_flow++;
590+ idx_lobe = 0 ;
575591 }
576592
577593 if ( is_last_step )
578594 {
579595 run_status = RunStatus::Finished;
580596 }
581-
582- n_lobes_processed++;
583- idx_lobe++;
584597 }
585598
586599 if ( run_status == RunStatus::Finished )
@@ -595,7 +608,7 @@ void Simulation::run()
595608{
596609 int n_lobes_processed = 0 ;
597610
598- auto t_run_start = std::chrono::high_resolution_clock::now ();
611+ auto t_run_start = std::chrono::high_resolution_clock::now ();
599612 const auto common_lobe_dimensions = CommonLobeDimensions ( input );
600613
601614 for ( int idx_flow = 0 ; idx_flow < input.n_flows ; idx_flow++ )
@@ -652,7 +665,8 @@ void Simulation::run()
652665
653666 // Select which of the previously created lobes is the parent lobe
654667 // from which the new descendent lobe will bud
655- const auto idx_parent = MrLavaLoba::select_parent_lobe ( idx_lobe, lobes, input, common_lobe_dimensions, gen );
668+ const auto idx_parent
669+ = MrLavaLoba::select_parent_lobe ( idx_lobe, lobes, input, common_lobe_dimensions, gen );
656670 const Lobe & lobe_parent = lobes[idx_parent];
657671
658672 // stopping condition (parent lobe close the domain boundary or at a not defined z value)
@@ -691,7 +705,8 @@ void Simulation::run()
691705 break ;
692706 }
693707 // Get the slope at the final budding point
694- const double slope_budding_point = topography.slope_between_points ( lobe_parent.center , final_budding_point );
708+ const double slope_budding_point
709+ = topography.slope_between_points ( lobe_parent.center , final_budding_point );
695710
696711 // compute the new lobe axes
697712 MrLavaLoba::compute_lobe_axes ( lobe_cur, slope_budding_point, input, common_lobe_dimensions );
0 commit comments