@@ -407,7 +407,7 @@ RunStatus Simulation::steps( int n_steps )
407407 simulation_state = SimulationState ();
408408 simulation_state->t_run_start = std::chrono::high_resolution_clock::now ();
409409 }
410- auto common_lobe_dimensions = CommonLobeDimensions ( input );
410+ const auto common_lobe_dimensions = CommonLobeDimensions ( input );
411411
412412 // Define some aliases for convenience
413413 auto & lobes = simulation_state->lobes ;
@@ -421,10 +421,10 @@ RunStatus Simulation::steps( int n_steps )
421421
422422 for ( int step = step_initial; step < step_initial + n_steps; step++ )
423423 {
424- bool is_first_step_of_new_flow = {}; // TODO: figure this out
425- bool is_last_step_of_flow = {} ;
426- bool is_an_initial_lobe = {} ;
427- bool is_last_step = {} ;
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 ;
428428
429429 if ( is_first_step_of_new_flow )
430430 {
@@ -438,6 +438,9 @@ RunStatus Simulation::steps( int n_steps )
438438
439439 // set idx_lobe to zero, because we are at the beginning of a flow
440440 idx_lobe = 0 ;
441+
442+ // switch back the flag
443+ simulation_state->beginning_of_new_flow = false ;
441444 }
442445
443446 if ( is_an_initial_lobe )
@@ -451,7 +454,7 @@ RunStatus Simulation::steps( int n_steps )
451454 lobe_cur.thickness
452455 = MrLavaLoba::compute_current_lobe_thickness ( idx_lobe, n_lobes, input, common_lobe_dimensions );
453456
454- auto [height_lobe_center, slope] = topography.height_and_slope ( lobe_cur.center );
457+ const auto [height_lobe_center, slope] = topography.height_and_slope ( lobe_cur.center );
455458
456459 if ( height_lobe_center == topography.no_data_value )
457460 {
@@ -479,8 +482,8 @@ RunStatus Simulation::steps( int n_steps )
479482
480483 // Select which of the previously created lobes is the parent lobe
481484 // from which the new descendent lobe will bud
482- auto idx_parent = MrLavaLoba::select_parent_lobe ( idx_lobe, lobes, input, common_lobe_dimensions, gen );
483- Lobe & lobe_parent = lobes[idx_parent];
485+ const auto idx_parent = MrLavaLoba::select_parent_lobe ( idx_lobe, lobes, input, common_lobe_dimensions, gen );
486+ const Lobe & lobe_parent = lobes[idx_parent];
484487
485488 // stopping condition (parent lobe close the domain boundary or at a not defined z value)
486489 if ( stop_condition ( lobe_parent.center , lobe_parent.semi_axes [0 ] ) )
@@ -492,12 +495,12 @@ RunStatus Simulation::steps( int n_steps )
492495
493496 // Find the preliminary budding point on the perimeter of the parent lobe (npoints is the number of raster
494497 // points on the ellipse)
495- Flowy::Vector2 budding_point = topography.find_preliminary_budding_point ( lobe_parent, input.npoints );
498+ const Flowy::Vector2 budding_point = topography.find_preliminary_budding_point ( lobe_parent, input.npoints );
496499
497- auto [height_lobe_center, slope_parent] = topography.height_and_slope ( lobe_parent.center );
498- auto [height_bp, slope_bp] = topography.height_and_slope ( budding_point );
500+ const auto [height_lobe_center, slope_parent] = topography.height_and_slope ( lobe_parent.center );
501+ const auto [height_bp, slope_bp] = topography.height_and_slope ( budding_point );
499502
500- Vector2 diff = ( budding_point - lobe_parent.center );
503+ const Vector2 diff = ( budding_point - lobe_parent.center );
501504
502505 // Perturb the angle and set it (not on the parent anymore)
503506 lobe_cur.set_azimuthal_angle ( std::atan2 ( diff[1 ], diff[0 ] ) ); // Sets the angle prior to perturbation
@@ -509,8 +512,8 @@ RunStatus Simulation::steps( int n_steps )
509512
510513 // Compute the final budding point
511514 // It is defined by the point on the perimeter of the parent lobe closest to the center of the new lobe
512- auto angle_diff = lobe_parent.get_azimuthal_angle () - lobe_cur.get_azimuthal_angle ();
513- Vector2 final_budding_point = lobe_parent.point_at_angle ( -angle_diff );
515+ const auto angle_diff = lobe_parent.get_azimuthal_angle () - lobe_cur.get_azimuthal_angle ();
516+ const Vector2 final_budding_point = lobe_parent.point_at_angle ( -angle_diff );
514517
515518 // final_budding_point = budding_point;
516519 if ( stop_condition ( final_budding_point, lobe_parent.semi_axes [0 ] ) )
@@ -520,7 +523,7 @@ RunStatus Simulation::steps( int n_steps )
520523 break ;
521524 }
522525 // Get the slope at the final budding point
523- double slope_budding_point = topography.slope_between_points ( lobe_parent.center , final_budding_point );
526+ const double slope_budding_point = topography.slope_between_points ( lobe_parent.center , final_budding_point );
524527
525528 // compute the new lobe axes
526529 MrLavaLoba::compute_lobe_axes ( lobe_cur, slope_budding_point, input, common_lobe_dimensions );
@@ -549,6 +552,7 @@ RunStatus Simulation::steps( int n_steps )
549552 {
550553 // Increment idx_flow
551554 idx_flow++;
555+ simulation_state->beginning_of_new_flow = true ;
552556
553557 if ( input.save_hazard_data )
554558 {
@@ -563,8 +567,8 @@ RunStatus Simulation::steps( int n_steps )
563567
564568 if ( input.print_remaining_time )
565569 {
566- auto t_cur = std::chrono::high_resolution_clock::now ();
567- auto remaining_time = std::chrono::duration_cast<std::chrono::milliseconds>(
570+ const auto t_cur = std::chrono::high_resolution_clock::now ();
571+ const auto remaining_time = std::chrono::duration_cast<std::chrono::milliseconds>(
568572 ( input.n_flows - idx_flow - 1 ) * ( t_cur - simulation_state->t_run_start ) / ( idx_flow + 1 ) );
569573 fmt::print ( " remaining_time = {:%Hh %Mm %Ss}\n " , remaining_time );
570574 }
@@ -592,7 +596,7 @@ void Simulation::run()
592596 int n_lobes_processed = 0 ;
593597
594598 auto t_run_start = std::chrono::high_resolution_clock::now ();
595- auto common_lobe_dimensions = CommonLobeDimensions ( input );
599+ const auto common_lobe_dimensions = CommonLobeDimensions ( input );
596600
597601 for ( int idx_flow = 0 ; idx_flow < input.n_flows ; idx_flow++ )
598602 {
@@ -617,7 +621,7 @@ void Simulation::run()
617621 lobe_cur.thickness
618622 = MrLavaLoba::compute_current_lobe_thickness ( idx_lobe, n_lobes, input, common_lobe_dimensions );
619623
620- auto [height_lobe_center, slope] = topography.height_and_slope ( lobe_cur.center );
624+ const auto [height_lobe_center, slope] = topography.height_and_slope ( lobe_cur.center );
621625
622626 if ( height_lobe_center == topography.no_data_value )
623627 {
@@ -648,8 +652,8 @@ void Simulation::run()
648652
649653 // Select which of the previously created lobes is the parent lobe
650654 // from which the new descendent lobe will bud
651- auto idx_parent = MrLavaLoba::select_parent_lobe ( idx_lobe, lobes, input, common_lobe_dimensions, gen );
652- Lobe & lobe_parent = lobes[idx_parent];
655+ const auto idx_parent = MrLavaLoba::select_parent_lobe ( idx_lobe, lobes, input, common_lobe_dimensions, gen );
656+ const Lobe & lobe_parent = lobes[idx_parent];
653657
654658 // stopping condition (parent lobe close the domain boundary or at a not defined z value)
655659 if ( stop_condition ( lobe_parent.center , lobe_parent.semi_axes [0 ] ) )
@@ -662,10 +666,10 @@ void Simulation::run()
662666 // points on the ellipse)
663667 Flowy::Vector2 budding_point = topography.find_preliminary_budding_point ( lobe_parent, input.npoints );
664668
665- auto [height_lobe_center, slope_parent] = topography.height_and_slope ( lobe_parent.center );
666- auto [height_bp, slope_bp] = topography.height_and_slope ( budding_point );
669+ const auto [height_lobe_center, slope_parent] = topography.height_and_slope ( lobe_parent.center );
670+ const auto [height_bp, slope_bp] = topography.height_and_slope ( budding_point );
667671
668- Vector2 diff = ( budding_point - lobe_parent.center );
672+ const Vector2 diff = ( budding_point - lobe_parent.center );
669673
670674 // Perturb the angle and set it (not on the parent anymore)
671675 lobe_cur.set_azimuthal_angle ( std::atan2 ( diff[1 ], diff[0 ] ) ); // Sets the angle prior to perturbation
@@ -677,8 +681,8 @@ void Simulation::run()
677681
678682 // Compute the final budding point
679683 // It is defined by the point on the perimeter of the parent lobe closest to the center of the new lobe
680- auto angle_diff = lobe_parent.get_azimuthal_angle () - lobe_cur.get_azimuthal_angle ();
681- Vector2 final_budding_point = lobe_parent.point_at_angle ( -angle_diff );
684+ const auto angle_diff = lobe_parent.get_azimuthal_angle () - lobe_cur.get_azimuthal_angle ();
685+ const Vector2 final_budding_point = lobe_parent.point_at_angle ( -angle_diff );
682686
683687 // final_budding_point = budding_point;
684688 if ( stop_condition ( final_budding_point, lobe_parent.semi_axes [0 ] ) )
@@ -687,7 +691,7 @@ void Simulation::run()
687691 break ;
688692 }
689693 // Get the slope at the final budding point
690- double slope_budding_point = topography.slope_between_points ( lobe_parent.center , final_budding_point );
694+ const double slope_budding_point = topography.slope_between_points ( lobe_parent.center , final_budding_point );
691695
692696 // compute the new lobe axes
693697 MrLavaLoba::compute_lobe_axes ( lobe_cur, slope_budding_point, input, common_lobe_dimensions );
@@ -724,22 +728,22 @@ void Simulation::run()
724728
725729 if ( input.print_remaining_time )
726730 {
727- auto t_cur = std::chrono::high_resolution_clock::now ();
728- auto remaining_time = std::chrono::duration_cast<std::chrono::milliseconds>(
731+ const auto t_cur = std::chrono::high_resolution_clock::now ();
732+ const auto remaining_time = std::chrono::duration_cast<std::chrono::milliseconds>(
729733 ( input.n_flows - idx_flow - 1 ) * ( t_cur - t_run_start ) / ( idx_flow + 1 ) );
730734 fmt::print ( " remaining_time = {:%Hh %Mm %Ss}\n " , remaining_time );
731735 }
732736 }
733737
734- auto t_cur = std::chrono::high_resolution_clock::now ();
735- auto total_time = std::chrono::duration_cast<std::chrono::milliseconds>( ( t_cur - t_run_start ) );
738+ const auto t_cur = std::chrono::high_resolution_clock::now ();
739+ const auto total_time = std::chrono::duration_cast<std::chrono::milliseconds>( ( t_cur - t_run_start ) );
736740 fmt::print ( " total_time = {:%Hh %Mm %Ss}\n " , total_time );
737741
738742 fmt::print ( " Total number of processed lobes = {}\n " , n_lobes_processed );
739743
740744 if ( total_time.count () > 0 )
741745 {
742- auto lobes_per_ms = n_lobes_processed / total_time.count ();
746+ const auto lobes_per_ms = n_lobes_processed / total_time.count ();
743747 fmt::print ( " n_lobes/ms = {}\n " , lobes_per_ms );
744748 }
745749
0 commit comments