Skip to content

Commit fa50560

Browse files
ENH: save_post_run_output function
a bit more concise Co-authored-by: Amrita Goswami <amrita16thaug646@gmail.com>
1 parent 108952d commit fa50560

3 files changed

Lines changed: 35 additions & 28 deletions

File tree

flowy/include/models/mr_lava_loba.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "flowy/include/config.hpp"
66
#include "flowy/include/definitions.hpp"
77
#include "flowy/include/lobe.hpp"
8-
#include "flowy/include/simulation.hpp"
98
#include "flowy/include/vent_flags.hpp"
109
#include "pdf_cpplib/include/probability_dist.hpp"
1110
#include <algorithm>

flowy/include/simulation.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,18 @@ class Simulation
3737

3838
void write_avg_thickness_file();
3939

40-
// Check if the dem has to be written (because of the input.write_dem_every_n_lobes_setting) and, if yes, writes the topography
41-
void write_thickness_if_necessary(int n_lobes_processed);
40+
// Check if the dem has to be written (because of the input.write_dem_every_n_lobes_setting) and, if yes, writes the
41+
// topography
42+
void write_thickness_if_necessary( int n_lobes_processed );
4243

4344
// Computes the topography_thickness field by subtracting the initial topography and dividing by (1.0 - filling_parameter)
4445
void compute_topography_thickness();
4546

4647
std::unique_ptr<TopographyFile>
4748
get_file_handle( const Topography & topography, OutputQuantity output_quantity ) const;
4849

50+
void save_post_run_output();
51+
4952
void run();
5053

5154
private:

src/simulation.cpp

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ Simulation::get_file_handle( const Topography & topography, OutputQuantity outpu
344344

345345
void Simulation::compute_topography_thickness()
346346
{
347-
// Compute the thickness by substracting the initial topography and correcting for the thickening parametr
347+
// Compute the thickness by subtracting the initial topography and correcting for the thickening parametr
348348
topography_thickness = topography;
349349
topography_thickness.no_data_value = DEFAULT_NO_DATA_VALUE_THICKNESS;
350350
topography_thickness.height_data -= topography_initial.height_data;
@@ -369,6 +369,34 @@ void Simulation::write_thickness_if_necessary( int n_lobes_processed )
369369
}
370370
}
371371

372+
void Simulation::save_post_run_output()
373+
{
374+
// Save initial topography to asc file
375+
auto file_initial = get_file_handle( topography_initial, OutputQuantity::Height );
376+
file_initial->save( input.output_folder / fmt::format( "{}_DEM", input.run_name ) );
377+
378+
// Save final topography to asc file
379+
if( input.save_final_dem )
380+
{
381+
auto file_final = get_file_handle( topography, OutputQuantity::Height );
382+
file_final->save( input.output_folder / fmt::format( "{}_DEM_final", input.run_name ) );
383+
}
384+
385+
// Save full thickness to asc file
386+
compute_topography_thickness();
387+
auto file_thick = get_file_handle( topography_thickness, OutputQuantity::Height );
388+
file_thick->save( input.output_folder / fmt::format( "{}_thickness_full", input.run_name ) );
389+
390+
// Save the full hazard map
391+
if( input.save_hazard_data )
392+
{
393+
auto file_hazard = get_file_handle( topography, OutputQuantity::Hazard );
394+
file_hazard->save( input.output_folder / fmt::format( "{}_hazard_full", input.run_name ) );
395+
}
396+
397+
write_avg_thickness_file();
398+
}
399+
372400
void Simulation::run()
373401
{
374402
int n_lobes_processed = 0;
@@ -527,30 +555,7 @@ void Simulation::run()
527555

528556
fmt::print( "Used RNG seed: {}\n", rng_seed );
529557

530-
// Save initial topography to asc file
531-
auto file_initial = get_file_handle( topography_initial, OutputQuantity::Height );
532-
file_initial->save( input.output_folder / fmt::format( "{}_DEM", input.run_name ) );
533-
534-
// Save final topography to asc file
535-
if( input.save_final_dem )
536-
{
537-
auto file_final = get_file_handle( topography, OutputQuantity::Height );
538-
file_final->save( input.output_folder / fmt::format( "{}_DEM_final", input.run_name ) );
539-
}
540-
541-
// Save full thickness to asc file
542-
compute_topography_thickness();
543-
auto file_thick = get_file_handle( topography_thickness, OutputQuantity::Height );
544-
file_thick->save( input.output_folder / fmt::format( "{}_thickness_full", input.run_name ) );
545-
546-
// Save the full hazard map
547-
if( input.save_hazard_data )
548-
{
549-
auto file_hazard = get_file_handle( topography, OutputQuantity::Hazard );
550-
file_hazard->save( input.output_folder / fmt::format( "{}_hazard_full", input.run_name ) );
551-
}
552-
553-
write_avg_thickness_file();
558+
save_post_run_output();
554559
}
555560

556561
} // namespace Flowy

0 commit comments

Comments
 (0)