@@ -296,13 +296,13 @@ void Simulation::write_avg_thickness_file()
296296 xt::filter ( topography_masked.hazard , topography_thickness.height_data < threshold_thickness ) = 0.0 ;
297297
298298 // Write the masked thickness and the masked hazard maps
299- auto file_thick = get_file_handle ( topography_masked, OutputQuantitiy ::Height );
299+ auto file_thick = get_file_handle ( topography_masked, OutputQuantity ::Height );
300300 file_thick->save (
301301 input.output_folder / fmt::format ( " {}_thickness_masked_{:.2f}" , input.run_name , threshold ) );
302302
303303 if ( input.save_hazard_data )
304304 {
305- auto file_hazard = get_file_handle ( topography_masked, OutputQuantitiy ::Hazard );
305+ auto file_hazard = get_file_handle ( topography_masked, OutputQuantity ::Hazard );
306306 file_hazard->save (
307307 input.output_folder / fmt::format ( " {}_hazard_masked_{:.2f}" , input.run_name , threshold ) );
308308 }
@@ -311,7 +311,7 @@ void Simulation::write_avg_thickness_file()
311311}
312312
313313std::unique_ptr<TopographyFile>
314- Simulation::get_file_handle ( const Topography & topography, OutputQuantitiy output_quantity ) const
314+ Simulation::get_file_handle ( const Topography & topography, OutputQuantity output_quantity ) const
315315{
316316 std::unique_ptr<TopographyFile> res{};
317317
@@ -343,6 +343,33 @@ Simulation::get_file_handle( const Topography & topography, OutputQuantitiy outp
343343 return res;
344344}
345345
346+ void Simulation::compute_topography_thickness ()
347+ {
348+ // Compute the thickness by substracting the initial topography and correcting for the thickening parametr
349+ topography_thickness = topography;
350+ topography_thickness.no_data_value = DEFAULT_NO_DATA_VALUE_THICKNESS;
351+ topography_thickness.height_data -= topography_initial.height_data ;
352+ topography_thickness.height_data /= ( 1.0 - input.thickening_parameter );
353+ }
354+
355+ void Simulation::write_thickness_if_necessary ( int n_lobes_processed )
356+ {
357+ // If the optional does not have a value, we simply return without doing anything
358+ if ( !input.write_thickness_every_n_lobes .has_value () )
359+ {
360+ return ;
361+ }
362+
363+ // Else we check if we have to write a dem file according to our setting
364+ if ( n_lobes_processed % input.write_thickness_every_n_lobes .value () == 0 )
365+ {
366+ compute_topography_thickness ();
367+ auto file_thick = get_file_handle ( topography_thickness, OutputQuantity::Height );
368+ file_thick->save (
369+ input.output_folder / fmt::format ( " {}_thickness_after_{}_lobes" , input.run_name , n_lobes_processed ) );
370+ }
371+ }
372+
346373void Simulation::run ()
347374{
348375 // Initialize MrLavaLoba method
@@ -394,6 +421,7 @@ void Simulation::run()
394421 // Add rasterized lobe
395422 topography.add_lobe ( lobe_cur, input.volume_correction , idx_lobe );
396423 n_lobes_processed++;
424+ write_thickness_if_necessary ( n_lobes_processed );
397425 }
398426
399427 // Loop over the rest of the lobes (skipping the initial ones).
@@ -464,6 +492,7 @@ void Simulation::run()
464492 // Add rasterized lobe
465493 topography.add_lobe ( lobe_cur, input.volume_correction , idx_lobe );
466494 n_lobes_processed++;
495+ write_thickness_if_necessary ( n_lobes_processed );
467496 }
468497
469498 if ( input.save_hazard_data )
@@ -501,29 +530,25 @@ void Simulation::run()
501530 fmt::print ( " Used RNG seed: {}\n " , rng_seed );
502531
503532 // Save initial topography to asc file
504- auto file_initial = get_file_handle ( topography_initial, OutputQuantitiy ::Height );
533+ auto file_initial = get_file_handle ( topography_initial, OutputQuantity ::Height );
505534 file_initial->save ( input.output_folder / fmt::format ( " {}_DEM" , input.run_name ) );
506535
507536 // Save final topography to asc file
508537 if ( input.save_final_dem )
509538 {
510- auto file_final = get_file_handle ( topography, OutputQuantitiy ::Height );
539+ auto file_final = get_file_handle ( topography, OutputQuantity ::Height );
511540 file_final->save ( input.output_folder / fmt::format ( " {}_DEM_final" , input.run_name ) );
512541 }
513542
514543 // Save full thickness to asc file
515- topography_thickness = topography;
516- topography_thickness.no_data_value = DEFAULT_NO_DATA_VALUE_THICKNESS;
517- topography_thickness.height_data -= topography_initial.height_data ;
518- topography_thickness.height_data /= ( 1.0 - input.thickening_parameter );
519-
520- auto file_thick = get_file_handle ( topography_thickness, OutputQuantitiy::Height );
544+ compute_topography_thickness ();
545+ auto file_thick = get_file_handle ( topography_thickness, OutputQuantity::Height );
521546 file_thick->save ( input.output_folder / fmt::format ( " {}_thickness_full" , input.run_name ) );
522547
523548 // Save the full hazard map
524549 if ( input.save_hazard_data )
525550 {
526- auto file_hazard = get_file_handle ( topography, OutputQuantitiy ::Hazard );
551+ auto file_hazard = get_file_handle ( topography, OutputQuantity ::Hazard );
527552 file_hazard->save ( input.output_folder / fmt::format ( " {}_hazard_full" , input.run_name ) );
528553 }
529554
0 commit comments