Skip to content

Commit

Permalink
Add output time interval (#1120)
Browse files Browse the repository at this point in the history
Description of the problem
Only needed the last 30% of my simulations and they are quite heavy.

Description of the solution
Added a new parameter in the parameter file -> output_time_interval. If the user specifies an output time interval, the .vtu files are only written if the simulation time is within that time window. This has been implemented for output control = iteration and output control = time.

How Has This Been Tested?
new simulation_control_06.cc test. Makes sure information is written at the appropriated time steps.

Documentation
Modified the simulation_control.rst file to consider the new parameter.
  • Loading branch information
mivaia committed May 8, 2024
1 parent 0b5a46f commit e4530ec
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
All notable changes to the Lethe project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/).

## [Master] - 2024-05-09

### Added

- MINOR Added a condition to the generation of .vtu and .pvd files in addition to the output generation frequency. If specified in the parameter file, only the results within the specified simulation time interval will be generated. [#1120] (https://github.com/chaos-polymtl/lethe/pull/1120)


## [Master] - 2024-05-02

### Fixed
Expand Down
5 changes: 5 additions & 0 deletions doc/source/parameters/cfd/simulation_control.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ This subsection contains the general information of the simulation, including th
# Output time
set output time = 1
# Output time interval
set output time interval = 1, 1.7e308
# Maximum number of vtu output files
set group files = 1
Expand Down Expand Up @@ -152,6 +155,8 @@ This subsection contains the general information of the simulation, including th

* ``output time``: controls the time when the ``.pvd`` / ``.vtu`` results are written. This parameter is only used when ``set output control = time``.

* ``output time interval``: Only writes the ``.pvd`` / ``.vtu`` files when the simulation time is within the closed interval defined by the ``output time interval``. Default values are 0s and 1.7e308s.

* ``group files``: number of ``.vtu`` files generated in a parallel simulation

.. tip::
Expand Down
3 changes: 3 additions & 0 deletions include/core/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ namespace Parameters
// Frequency of the output
double output_time;

// Time window for file output
std::vector<double> output_time_interval;

// Enable output of the boundaries
bool output_boundaries;

Expand Down
6 changes: 6 additions & 0 deletions include/core/simulation_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ class SimulationControl
// by the time
double output_time_frequency;

// Adds a condition to the generation of .vtu and .pvd files in addition to
// the output generation frequency. If specified in the parameter file, only
// the results within the specified simulation time interval will be
// generated.
std::vector<double> output_time_interval;

// Log iteration frequency
// Controls the frequency at which status of the simulation is written to
// the terminal
Expand Down
11 changes: 9 additions & 2 deletions source/core/parameters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ namespace Parameters
"The control for the output of the simulation results"
"Results can be either outputted at constant iteration frequency or at constant time");

prm.declare_entry("output time interval",
"0, 1.7976931348623157e308", // 0, Maximum double
Patterns::List(Patterns::Double()),
"Output files for a desired time interval");

prm.declare_entry("subdivision",
"1",
Patterns::Integer(),
Expand Down Expand Up @@ -233,8 +238,10 @@ namespace Parameters
output_name.end(),
'/'),
output_name.end());
output_frequency = prm.get_integer("output frequency");
output_time = prm.get_double("output time");
output_frequency = prm.get_integer("output frequency");
output_time = prm.get_double("output time");
output_time_interval =
convert_string_to_vector<double>(prm, "output time interval");
output_boundaries = prm.get_bool("output boundaries");

subdivision = prm.get_integer("subdivision");
Expand Down
15 changes: 12 additions & 3 deletions source/core/simulation_control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ SimulationControl::SimulationControl(const Parameters::SimulationControl param)
, stop_tolerance(param.stop_tolerance)
, output_frequency(param.output_frequency)
, output_time_frequency(param.output_time)
, output_time_interval(param.output_time_interval)
, log_frequency(param.log_frequency)
, log_precision(param.log_precision)
, subdivision(param.subdivision)
Expand Down Expand Up @@ -61,7 +62,11 @@ SimulationControl::is_output_iteration()
return false;
else
{
return (get_step_number() % output_frequency == 0);
// Check if the current step number matches the output frequency and falls
// within the user-specified time window.
return (get_step_number() % output_frequency == 0 &&
get_current_time() >= output_time_interval[0] &&
get_current_time() <= output_time_interval[1]);
}
}

Expand Down Expand Up @@ -316,9 +321,13 @@ SimulationControlTransientDynamicOutput::calculate_time_step()
bool
SimulationControlTransientDynamicOutput::is_output_iteration()
{
// Check if the current step number matches the output time frequency and
// falls within the user-specified time window.
bool is_output_time =
(current_time - last_output_time) - output_time_frequency >
-1e-12 * output_time_frequency;
((current_time - last_output_time) - output_time_frequency >
-1e-12 * output_time_frequency &&
get_current_time() >= output_time_interval[0] &&
get_current_time() <= output_time_interval[1]);
if (is_output_time)
last_output_time = current_time;

Expand Down
1 change: 1 addition & 0 deletions tests/core/simulation_control_02.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ test()
simulationControlParameters.subdivision = 7;
simulationControlParameters.output_folder = "canard";
simulationControlParameters.output_frequency = 8;
simulationControlParameters.output_time_interval = {0, 1000000000};

SimulationControlSteady simulation_control(simulationControlParameters);

Expand Down
1 change: 1 addition & 0 deletions tests/core/simulation_control_03.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ test()
simulation_control_parameters.subdivision = 7;
simulation_control_parameters.output_folder = "canard";
simulation_control_parameters.output_frequency = 8;
simulation_control_parameters.output_time_interval = {0, 1000000000};

{
SimulationControlTransient simulation_control(
Expand Down
97 changes: 97 additions & 0 deletions tests/core/simulation_control_06.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/* ---------------------------------------------------------------------
*
* Copyright (C) 2020 - by the Lethe authors
*
* This file is part of the Lethe library
*
* The Lethe library is free software; you can use it, redistribute
* it, and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation; either
* version 3.1 of the License, or (at your option) any later version.
* The full text of the license can be found in the file LICENSE at
* the top level of the Lethe distribution.
*
* ---------------------------------------------------------------------
/**
* @brief This test checks if files are only generated within the output time interval
*/

// Lethe
#include <core/parameters.h>
#include <core/simulation_control.h>

// Tests (with common definitions)
#include <../tests/tests.h>

void
test()
{
Parameters::SimulationControl simulationControlParameters;

simulationControlParameters.dt = 0.01;
simulationControlParameters.adapt = false;
simulationControlParameters.maxCFL = 99;
simulationControlParameters.method =
Parameters::SimulationControl::TimeSteppingMethod::bdf1;

simulationControlParameters.timeEnd = 999;
simulationControlParameters.number_mesh_adaptation = 9;
simulationControlParameters.output_name = "test";
simulationControlParameters.subdivision = 7;
simulationControlParameters.output_folder = "canard";
simulationControlParameters.output_frequency = 1;
simulationControlParameters.output_time_interval = {1, 2};

SimulationControlSteady simulation_control(simulationControlParameters);

deallog << "Iteration : " << simulation_control.get_step_number()
<< std::endl;

while (simulation_control.integrate())
{
deallog << "Iteration : " << simulation_control.get_step_number()
<< " Time : " << simulation_control.get_current_time()
<< std::endl;
if (simulation_control.is_at_start())
deallog << "This is the first iteration" << std::endl;

if (simulation_control.is_output_iteration())
deallog << "This is an output iteration" << std::endl;
}
}

int
main()
{
try
{
initlog();
test();
}
catch (std::exception &exc)
{
std::cerr << std::endl
<< std::endl
<< "----------------------------------------------------"
<< std::endl;
std::cerr << "Exception on processing: " << std::endl
<< exc.what() << std::endl
<< "Aborting!" << std::endl
<< "----------------------------------------------------"
<< std::endl;
return 1;
}
catch (...)
{
std::cerr << std::endl
<< std::endl
<< "----------------------------------------------------"
<< std::endl;
std::cerr << "Unknown exception!" << std::endl
<< "Aborting!" << std::endl
<< "----------------------------------------------------"
<< std::endl;
return 1;
}
}
15 changes: 15 additions & 0 deletions tests/core/simulation_control_06.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

DEAL::Iteration : 0
DEAL::Iteration : 1 Time : 1.00000
DEAL::This is the first iteration
DEAL::This is an output iteration
DEAL::Iteration : 2 Time : 2.00000
DEAL::This is an output iteration
DEAL::Iteration : 3 Time : 3.00000
DEAL::Iteration : 4 Time : 4.00000
DEAL::Iteration : 5 Time : 5.00000
DEAL::Iteration : 6 Time : 6.00000
DEAL::Iteration : 7 Time : 7.00000
DEAL::Iteration : 8 Time : 8.00000
DEAL::Iteration : 9 Time : 9.00000
DEAL::Iteration : 10 Time : 10.0000

0 comments on commit e4530ec

Please sign in to comment.