From ada900c4ab82655e1716be42239150ce6e072eee Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com>
Date: Mon, 8 Mar 2021 07:50:20 +0100
Subject: [PATCH] Improve output period management

---
 src/output/GnuplotWriter.cpp | 4 ++--
 src/output/WriterBase.cpp    | 5 +++--
 src/output/WriterBase.hpp    | 1 +
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/output/GnuplotWriter.cpp b/src/output/GnuplotWriter.cpp
index 436ae7ffa..f503c996c 100644
--- a/src/output/GnuplotWriter.cpp
+++ b/src/output/GnuplotWriter.cpp
@@ -102,8 +102,8 @@ GnuplotWriter::_writeCellValue(const CellValue<DataType>& cell_value, CellId cel
 template <typename DataType, ItemType item_type>
 void
 GnuplotWriter::_writeValue(const ItemValue<DataType, item_type>& item_value,
-                           CellId cell_id,
-                           NodeId node_id,
+                           [[maybe_unused]] CellId cell_id,
+                           [[maybe_unused]] NodeId node_id,
                            std::ostream& fout) const
 {
   if constexpr (item_type == ItemType::cell) {
diff --git a/src/output/WriterBase.cpp b/src/output/WriterBase.cpp
index 0359cf7b3..4a26605cd 100644
--- a/src/output/WriterBase.cpp
+++ b/src/output/WriterBase.cpp
@@ -172,7 +172,7 @@ WriterBase::getLastTime() const
 }
 
 WriterBase::WriterBase(const std::string& base_filename, const double& time_period)
-  : m_base_filename{base_filename}, m_time_period{time_period}
+  : m_base_filename{base_filename}, m_time_period{time_period}, m_next_time{0}
 {}
 
 void
@@ -183,7 +183,8 @@ WriterBase::writeIfNeeded(const std::vector<std::shared_ptr<const NamedDiscreteF
   if (time == last_time)
     return;   // output already performed
 
-  if (time >= last_time + m_time_period) {
+  if (time >= m_next_time) {
+    m_next_time += m_time_period;
     this->write(named_discrete_function_list, time);
     m_saved_times.push_back(time);
   }
diff --git a/src/output/WriterBase.hpp b/src/output/WriterBase.hpp
index 6e9a08ad1..babdec907 100644
--- a/src/output/WriterBase.hpp
+++ b/src/output/WriterBase.hpp
@@ -13,6 +13,7 @@ class WriterBase : public IWriter
  protected:
   const std::string m_base_filename;
   const double m_time_period;
+  mutable double m_next_time;
 
   mutable std::vector<double> m_saved_times;
 
-- 
GitLab