Skip to content
Snippets Groups Projects
Unverified Commit 600d6d98 authored by Dmitri Naumov's avatar Dmitri Naumov Committed by GitHub
Browse files

Merge pull request #3000 from endJunction/DontSkipOutputOfRepeatedFixedTimeStep

Dont skip output of repeated fixed time step
parents 3c4d56a8 c418dfa4
No related branches found
No related tags found
No related merge requests found
......@@ -45,12 +45,9 @@ std::unique_ptr<TimeStepAlgorithm> createEvolutionaryPIDcontroller(
auto fixed_output_times =
//! \ogs_file_param{prj__time_loop__processes__process__time_stepping__EvolutionaryPIDcontroller__fixed_output_times}
config.getConfigParameter<std::vector<double>>("fixed_output_times",
std::vector<double>{});
if (!fixed_output_times.empty())
{
// Remove possible duplicated elements and sort in descending order.
BaseLib::makeVectorUnique(fixed_output_times, std::greater<>());
}
{});
// Remove possible duplicated elements and sort.
BaseLib::makeVectorUnique(fixed_output_times);
//! \ogs_file_param{prj__time_loop__processes__process__time_stepping__EvolutionaryPIDcontroller__tol}
auto const tol = config.getConfigParameter<double>("tol");
......
......@@ -46,12 +46,9 @@ std::unique_ptr<TimeStepAlgorithm> createIterationNumberBasedTimeStepping(
auto fixed_output_times =
//! \ogs_file_param{prj__time_loop__processes__process__time_stepping__IterationNumberBasedTimeStepping__fixed_output_times}
config.getConfigParameter<std::vector<double>>("fixed_output_times",
std::vector<double>{});
if (!fixed_output_times.empty())
{
// Remove possible duplicated elements and sort in descending order.
BaseLib::makeVectorUnique(fixed_output_times, std::greater<>());
}
{});
// Remove possible duplicated elements and sort.
BaseLib::makeVectorUnique(fixed_output_times);
return std::make_unique<IterationNumberBasedTimeStepping>(
t_initial, t_end, minimum_dt, maximum_dt, initial_dt,
......
......@@ -36,8 +36,12 @@ EvolutionaryPIDcontroller::EvolutionaryPIDcontroller(
_e_n_minus2(0.),
_is_accepted(true)
{
// Remove possible duplicated elements. Result will be sorted.
BaseLib::makeVectorUnique(_fixed_output_times);
if (!std::is_sorted(cbegin(_fixed_output_times), cend(_fixed_output_times)))
{
OGS_FATAL(
"Vector of fixed time steps passed to the "
"EvolutionaryPIDcontroller constructor must be sorted");
}
}
bool EvolutionaryPIDcontroller::next(double const solution_error,
......
......@@ -53,8 +53,12 @@ IterationNumberBasedTimeStepping::IterationNumberBasedTimeStepping(
OGS_FATAL("Vector of iteration numbers must be sorted.");
}
// Remove possible duplicated elements. Result will be sorted.
BaseLib::makeVectorUnique(_fixed_output_times);
if (!std::is_sorted(cbegin(_fixed_output_times), cend(_fixed_output_times)))
{
OGS_FATAL(
"Vector of fixed time steps passed to the "
"IterationNumberBasedTimeStepping constructor must be sorted");
}
}
bool IterationNumberBasedTimeStepping::next(double const /*solution_error*/,
......
......@@ -55,8 +55,6 @@ std::unique_ptr<Output> createOutput(
// Construction of output times
std::vector<Output::PairRepeatEachSteps> repeats_each_steps;
std::vector<double> fixed_output_times;
//! \ogs_file_param{prj__time_loop__output__timesteps}
if (auto const timesteps = config.getConfigSubtreeOptional("timesteps"))
{
......@@ -133,16 +131,12 @@ std::unique_ptr<Output> createOutput(
}
}
auto fixed_output_times_ptr =
std::vector<double> fixed_output_times =
//! \ogs_file_param{prj__time_loop__output__fixed_output_times}
config.getConfigParameterOptional<std::vector<double>>(
"fixed_output_times");
if (fixed_output_times_ptr)
{
fixed_output_times = std::move(*fixed_output_times_ptr);
// Remove possible duplicated elements and sort in descending order.
BaseLib::makeVectorUnique(fixed_output_times, std::greater<>());
}
config.getConfigParameter<std::vector<double>>("fixed_output_times",
{});
// Remove possible duplicated elements and sort.
BaseLib::makeVectorUnique(fixed_output_times);
bool const output_iteration_results =
//! \ogs_file_param{prj__time_loop__output__output_iteration_results}
......
......@@ -78,22 +78,20 @@ bool Output::shallDoOutput(int timestep, double const t)
}
}
bool make_output = timestep % each_steps == 0;
if (_fixed_output_times.empty())
if (timestep % each_steps == 0)
{
return make_output;
return true;
}
const double specific_time = _fixed_output_times.back();
const double zero_threshold = std::numeric_limits<double>::min();
if (std::fabs(specific_time - t) < zero_threshold)
auto const fixed_output_time = std::lower_bound(
cbegin(_fixed_output_times), cend(_fixed_output_times), t);
if (fixed_output_time == cend(_fixed_output_times))
{
_fixed_output_times.pop_back();
make_output = true;
return false;
}
return make_output;
return std::fabs(*fixed_output_time - t) <
std::numeric_limits<double>::min();
}
Output::Output(std::string output_directory, std::string output_file_prefix,
......@@ -117,6 +115,12 @@ Output::Output(std::string output_directory, std::string output_file_prefix,
_mesh_names_for_output(mesh_names_for_output),
_meshes(meshes)
{
if (!std::is_sorted(cbegin(_fixed_output_times), cend(_fixed_output_times)))
{
OGS_FATAL(
"Vector of fixed output time steps passed to the Output "
"constructor must be sorted");
}
}
void Output::addProcess(ProcessLib::Process const& process,
......
......@@ -104,7 +104,7 @@ private:
std::vector<PairRepeatEachSteps> _repeats_each_steps;
//! Given times that steps have to reach.
std::vector<double> _fixed_output_times;
std::vector<double> const _fixed_output_times;
std::multimap<Process const*, MeshLib::IO::PVDFile> _process_to_pvd_file;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment