12#ifndef ARCANE_IMPL_INTERNAL_TIMEHISTORYMNGINTERNAL_H
13#define ARCANE_IMPL_INTERNAL_TIMEHISTORYMNGINTERNAL_H
17#include "arcane/utils/Iostream.h"
18#include "arcane/utils/Iterator.h"
19#include "arcane/utils/ScopedPtr.h"
20#include "arcane/utils/ITraceMng.h"
21#include "arcane/utils/PlatformUtils.h"
22#include "arcane/utils/OStringStream.h"
24#include "arcane/core/IIOMng.h"
25#include "arcane/core/CommonVariables.h"
26#include "arcane/core/Directory.h"
27#include "arcane/core/ObserverPool.h"
28#include "arcane/core/IVariableMng.h"
29#include "arcane/core/IParallelMng.h"
30#include "arcane/core/ITimeHistoryCurveWriter2.h"
31#include "arcane/core/ITimeHistoryTransformer.h"
32#include "arcane/core/XmlNode.h"
33#include "arcane/core/XmlNodeList.h"
34#include "arcane/core/IXmlDocumentHolder.h"
35#include "arcane/core/ServiceBuilder.h"
36#include "arcane/core/Properties.h"
37#include "arcane/core/IParallelReplication.h"
39#include "arcane/datatype/DataTypeTraits.h"
41#include "arcane/core/internal/ITimeHistoryMngInternal.h"
65 , m_sub_size(sub_size)
123 const String&
name()
const {
return m_thpi.timeHistoryAddValueArg().name(); }
131 Integer subSize()
const {
return m_sub_size; }
148 bool isLocal()
const {
return m_thpi.timeHistoryAddValueArg().isLocal(); }
179template <
typename DataType>
181:
public TimeHistoryValue
197 static const Integer COMPRESSED_TAG = -15;
218 , m_use_compression(false)
219 , m_shrink_history(shrink)
235 , m_use_compression(false)
236 , m_shrink_history(shrink)
246 if (ptr_old_values ==
nullptr || ptr_old_iterations ==
nullptr)
249 ValueList old_values(ptr_old_values);
250 IterationList old_iterations(ptr_old_iterations);
252 m_values.resize(old_values.
size());
253 m_values.copy(old_values);
255 m_iterations.resize(old_iterations.
size());
256 m_iterations.copy(old_iterations);
264 return m_iterations.size();
275 Integer nb_iteration = m_iterations.size();
276 Integer nb_value = m_values.size();
277 Integer sub_size = values.size();
278 if (nb_iteration != 0)
279 if (m_iterations[nb_iteration - 1] == iteration) {
281 for (
Integer i = 0; i < sub_size; ++i)
282 m_values[nb_value - sub_size + i] = values[i];
287 m_iterations.resizeWithReserve(nb_iteration + 1, add_nb_iter);
288 m_values.resizeWithReserve(nb_value + sub_size, add_nb_value);
289 m_iterations[nb_iteration] = iteration;
290 for (
Integer i = 0; i < sub_size; ++i)
291 m_values[nb_value + i] = values[i];
299 if (m_iterations[i] >= last_iteration) {
303 if (last_elem !=
size) {
304 m_iterations.resize(last_elem);
305 m_values.resize(last_elem * subSize());
317 if (m_shrink_history)
323 arrayToWrite(iterations_to_write, values_to_write, infos);
349 Integer nb_iteration = iterations.size();
350 Integer nb_value = values.size();
351 if (nb_iteration * sub_size != nb_value) {
352 msg->
warning() <<
"Bad size after history transformation";
356 m_iterations.resize(nb_iteration);
357 for (
Integer i = 0; i < nb_iteration; ++i)
358 m_iterations[i] = iterations[i];
360 m_values.resize(nb_value);
361 for (
Integer i = 0; i < nb_value; ++i)
362 m_values[i] = values[i];
370 Integer nb_iteration = m_iterations.size();
373 iterations.reserve(nb_iteration);
375 values.reserve(nb_iteration * sub_size);
376 for (
Integer i = 0, is = nb_iteration; i < is; ++i) {
377 Integer iter = m_iterations[i];
378 if (iter < max_iter) {
379 for (
Integer z = 0; z < sub_size; ++z) {
382 iterations.add(iter);
387 const ValueList& values()
const {
return m_values; }
388 const IterationList& iterations()
const {
return m_iterations; }
393 IterationList m_iterations;
394 bool m_use_compression;
395 bool m_shrink_history;
401class TimeHistoryMngInternal
408 , m_trace_mng(m_variable_mng->traceMng())
409 , m_parallel_mng(m_variable_mng->parallelMng())
410 , m_common_variables(m_variable_mng)
418 , m_properties(properties)
439 ~TimeHistoryMngInternal()
override
443 m_curve_writers2.clear();
447 typedef std::map<String, TimeHistoryValue*> HistoryList;
448 typedef std::set<Ref<ITimeHistoryCurveWriter2>> CurveWriter2List;
449 typedef HistoryList::value_type HistoryValueType;
522 template <
class DataType>
589 CurveWriter2List m_curve_writers2;
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
constexpr Integer size() const noexcept
Returns the size of the array.
Common variables of a case.
Constant view of an array of type T.
constexpr Integer size() const noexcept
Number of elements in the array.
Class managing a directory.
Interface of the parallelism manager for a subdomain.
Brief information on parallel subdomain replication.
virtual bool hasReplication() const =0
Indicates if replication is active.
virtual bool isMasterRank() const =0
Indicates if this replication rank is the master.
Interface of the property manager.
Interface for a curve writer.
virtual void writeCurve(const TimeHistoryCurveInfo &infos)=0
Write a curve.
Interface for the internal part of a value history manager.
Common info for each curve.
String name
Name of the curve.
Integer sub_size
Number of values per curve.
Int32SharedArray iterations
List of iterations.
Interface of an object transforming history curves.
virtual void transform(CommonInfo &infos, RealSharedArray values)=0
Applies the transformation for a curve with Real values.
virtual TraceMessage warning()=0
Stream for a warning message.
Variable manager interface.
virtual IVariable * findMeshVariable(IMesh *mesh, const String &name)=0
Returns the mesh variable named name or 0 if no such name exists.
@ PNoReplicaSync
Indicates that the variable does not necessarily have the same value across replicas.
@ PExecutionDepend
Indicates that the variable value is dependent on the execution.
@ PNoRestore
Indicates that the variable should not be restored.
Reference to an instance.
1D vector of data with reference semantics.
Unicode character string.
bool null() const
Returns true if the string is null.
Class extending the arguments when adding a value to a value history.
Information for writing a curve.
Information about writing curves.
RealConstArrayView times() const
List of times.
void setIOMasterWriteOnly(bool is_active) override
Method allowing to define if only the master process calls the writers.
bool isShrinkActive() const override
Returns a boolean indicating if the history is compressed.
void updateMetaData() override
Method allowing the curve metadata to be updated.
bool m_is_master_io
True if I am the IO manager.
bool m_is_shrink_active
Indicates if history compression is active.
void addNowInGlobalTime() override
Method allowing the current GlobalTime to be added to the GlobalTimes array.
bool isMasterIO() override
Method allowing to know if our process is the writer.
void addValue(const TimeHistoryAddValueArgInternal &thpi, Real value) override
Method allowing a value to be added to a history.
void _dumpSummaryOfCurves()
Method allowing a JSON file to be dumped with the name of each curve output in GNUPLOT format as well...
void addValue(const TimeHistoryAddValueArgInternal &thpi, Int32 value) override
Method allowing a value to be added to a history.
bool m_is_master_io_of_sd
True if I am the IO manager for my subdomain.
void _removeCurveWriter(const Ref< ITimeHistoryCurveWriter2 > &writer)
Method allowing removal of a writer.
void updateGlobalTimeCurve() override
Method allowing the GlobalTime array to be copied into the global GlobalTime variable.
void resizeArrayAfterRestore() override
Method allowing the value arrays to be resized after a restart.
void addObservers(IPropertyMng *prop_mng) override
Method allowing observers saving the history before a checkpoint to be added.
bool isMasterIOOfSubDomain() override
Method allowing to know if our process is the writer for our subdomain. In the case where replication...
bool isDumpActive() const override
Indicates the output activation status.
bool m_is_dump_active
Indicates if dumps are active.
void removeCurveWriter(const String &name) override
Method allowing a writer to be removed.
void readVariables(IMeshMng *mesh_mng, IMesh *default_mesh) override
Method allowing previously written curves to be retrieved during a restart.
void setDumpActive(bool is_active) override
Sets the output activation status.
void addValue(const TimeHistoryAddValueArgInternal &thpi, Int32ConstArrayView values) override
Method allowing values to be added to a history.
void dumpHistory() override
Method allowing all curves to be written using all registered writers.
void _dumpSummaryOfCurvesLegacy()
Method allowing an XML file to be dumped with the name of each curve output in GNUPLOT format.
void addValue(const TimeHistoryAddValueArgInternal &thpi, Int64ConstArrayView values) override
Method allowing values to be added to a history.
HistoryList m_history_list
List of histories.
void _addHistoryValue(const TimeHistoryAddValueArgInternal &thpi, ConstArrayView< DataType > values)
Method allowing values to be added to a value history.
VariableArrayReal m_th_global_time
Array of time instants.
bool isNonIOMasterCurvesEnabled() override
Method allowing to know if all processes can have a value history.
bool m_enable_non_io_master_curves
Indicates if curve writing by non-io_master procs is possible.
void _dumpCurvesAllWriters()
Method allowing all curves to be dumped with all writers.
void setActive(bool is_active) override
Sets the activation status.
void applyTransformation(ITimeHistoryTransformer *v) override
Applies the transformation v to all curves.
void iterationsAndValues(const TimeHistoryAddValueArgInternal &thpi, UniqueArray< Int32 > &iterations, UniqueArray< Real > &values) override
Method allowing the iterations and values of a history to be outputted.
void dumpCurves(ITimeHistoryCurveWriter2 *writer) override
Method allowing curves to be written using the provided writer.
bool m_io_master_write_only
Indicates if writers must be called by all processes.
bool isIOMasterWriteOnly() override
Method allowing to know if only the master process calls the writers.
bool active() const override
Indicates the activation status.
void addValue(const TimeHistoryAddValueArgInternal &thpi, RealConstArrayView values) override
Method allowing values to be added to a history.
void _saveProperties()
Method allowing saving the properties of the metadata.
void addValue(const TimeHistoryAddValueArgInternal &thpi, Int64 value) override
Method allowing a value to be added to a history.
void setShrinkActive(bool is_active) override
Sets the boolean indicating if the history is compressed.
VariableScalarString m_th_meta_data
History info.
void _fromLegacyFormat(IMesh *default_mesh)
Method allowing conversion from the old format to the new.
void editOutputPath(const Directory &directory) override
Method allowing the curve output directory to be changed.
void _destroyAll()
Destructor.
RealUniqueArray m_global_times
List of global times.
bool m_need_comm
Indicates if at least one curve is non-local (thus requiring communications).
bool m_is_active
Indicates if the service is active.
void addCurveWriter(Ref< ITimeHistoryCurveWriter2 > writer) override
Method allowing a writer to be added for curve output.
TimeHistoryValueT(const TimeHistoryAddValueArgInternal &thpi, Integer index, Integer nb_element, bool shrink)
Constructor for building a value history linked to a mesh.
void applyTransformation(ITraceMng *msg, ITimeHistoryTransformer *v) override
Method allowing the application of a transformation on the values of the value history.
Integer size() const override
Method allowing the retrieval of the number of recorded values.
void dumpValues(ITraceMng *msg, ITimeHistoryCurveWriter2 *writer, const TimeHistoryCurveWriterInfo &infos) const override
Prints the history values using the writer writer.
void addValue(ConstArrayView< DataType > values, Integer iteration)
Method allowing the addition of values to an iteration.
void removeAfterIteration(Integer last_iteration) override
Method allowing the removal of all values after a certain iteration.
void arrayToWrite(UniqueArray< Int32 > &iterations, UniqueArray< Real > &values, const TimeHistoryCurveWriterInfo &infos) const override
Method allowing the retrieval of iterations and values from a value history.
TimeHistoryValueT(IVariableMng *vm, const TimeHistoryAddValueArgInternal &thpi, Integer index, Integer nb_element, bool shrink)
Constructor for building a value history not linked to a mesh.
void fromOldToNewVariables(IVariableMng *vm, IMesh *default_mesh) override
Method allowing the conversion of variables from old saves to the new format.
Integer index() const
History index in the list.
virtual Integer size() const =0
Method allowing the retrieval of the number of recorded values.
const MeshHandle & meshHandle() const
Method allowing the retrieval of the registered MeshHandle.
virtual void removeAfterIteration(Integer last_iteration)=0
Method allowing the removal of all values after a certain iteration.
const String & name() const
History name.
eDataType dataType() const
History data type.
virtual void applyTransformation(ITraceMng *msg, ITimeHistoryTransformer *v)=0
Method allowing the application of a transformation on the values of the value history.
Integer m_index
History index in the list.
virtual void fromOldToNewVariables(IVariableMng *vm, IMesh *default_mesh)=0
Method allowing the conversion of variables from old saves to the new format.
virtual ~TimeHistoryValue()=default
Frees resources.
Integer localSubDomainId() const
Method allowing the retrieval of the subdomain ID to which this history belongs.
virtual void arrayToWrite(UniqueArray< Int32 > &iterations, UniqueArray< Real > &values, const TimeHistoryCurveWriterInfo &infos) const =0
Method allowing the retrieval of iterations and values from a value history.
bool isLocal() const
Method allowing determination if it is a global history or local to a subdomain.
eDataType m_data_type
Data type.
virtual void dumpValues(ITraceMng *msg, ITimeHistoryCurveWriter2 *writer, const TimeHistoryCurveWriterInfo &infos) const =0
Prints the history values using the writer writer.
1D data vector with value semantics (STL style).
Parameters necessary for building a variable.
virtual void resize(Integer new_size)
Resizes the array to contain new_size elements.
T max(const T &a, const T &b, const T &c)
Returns the maximum of three elements.
VariableRefArrayT< Real > VariableArrayReal
Array variable of real type.
VariableRefScalarT< String > VariableScalarString
Scalar variable of character string type.
Real toReal(Real r)
Converts r to a Real.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
ConstArrayView< Int64 > Int64ConstArrayView
C equivalent of a 1D array of 64-bit integers.
Integer arcaneCallFunctionAndCatchException(std::function< void()> function)
Calls the function function while catching potential exceptions.
UniqueArray< Real > RealUniqueArray
Dynamic 1D array of reals.
double Real
Type representing a real number.
std::int32_t Int32
Signed integer type of 32 bits.
ConstArrayView< Real > RealConstArrayView
C equivalent of a 1D array of reals.