14#include "arcane/utils/Iostream.h"
15#include "arcane/utils/ApplicationInfo.h"
16#include "arcane/utils/ScopedPtr.h"
17#include "arcane/utils/ITraceMng.h"
18#include "arcane/utils/PlatformUtils.h"
20#include "arcane/core/ITimeHistoryMng.h"
21#include "arcane/core/IIOMng.h"
22#include "arcane/core/CommonVariables.h"
23#include "arcane/core/ISubDomain.h"
24#include "arcane/core/Directory.h"
25#include "arcane/core/AbstractModule.h"
26#include "arcane/core/EntryPoint.h"
27#include "arcane/core/ObserverPool.h"
28#include "arcane/core/IVariableMng.h"
29#include "arcane/core/CaseOptionsMain.h"
30#include "arcane/core/IParallelMng.h"
31#include "arcane/core/ITimeHistoryCurveWriter2.h"
32#include "arcane/core/ITimeHistoryTransformer.h"
33#include "arcane/core/XmlNode.h"
34#include "arcane/core/XmlNodeList.h"
35#include "arcane/core/IXmlDocumentHolder.h"
36#include "arcane/core/ServiceFinder2.h"
37#include "arcane/core/ServiceBuilder.h"
38#include "arcane/core/IMeshMng.h"
40#include "arcane/datatype/DataTypeTraits.h"
42#include "arcane/impl/internal/TimeHistoryMngInternal.h"
43#include "arcane/core/GlobalTimeHistoryAdder.h"
59class GnuplotTimeHistoryCurveWriter2
65 GnuplotTimeHistoryCurveWriter2(
ITraceMng* tm)
72 void build()
override {}
75 m_times = infos.
times();
78 if (m_output_path.empty())
83 if (m_gnuplot_path.createDirectory()) {
84 warning() <<
"Can not create gnuplot curve directory '"
85 << m_gnuplot_path.path() <<
"'";
92 if (infos.subDomain() != NULL_SUB_DOMAIN_ID) {
93 name =
"SD" + String::fromNumber(infos.subDomain()) +
"_" +
name;
95 if (infos.hasSupport()) {
100 FILE* ofile = fopen(sname.
localstr(),
"w");
102 warning() <<
"Can not open gnuplot curve file '" << sname <<
"'";
109 for (
Integer i = 0; i < nb_val; ++i) {
111 for (
Integer z = 0; z < sub_size; ++z)
113 fprintf(ofile,
"\n");
124 m_output_path = path;
128 return m_output_path;
156 TimeHistoryMng2(
const ModuleBuildInfo& cb,
bool add_entry_points =
true);
157 ~TimeHistoryMng2()
override =
default;
192 void timeHistoryBegin()
override;
193 void timeHistoryEnd()
override;
194 void timeHistoryInit()
override;
195 void timeHistoryStartInit()
override;
196 void timeHistoryContinueInit()
override;
197 void timeHistoryRestore()
override;
198 void timeHistoryStartInitEnd();
215 bool active()
const override {
return m_internal->active(); }
216 void setActive(
bool is_active)
override { m_internal->setActive(is_active); }
218 bool isDumpActive()
const override {
return m_internal->isDumpActive(); }
219 void setDumpActive(
bool is_active)
override { m_internal->setDumpActive(is_active); }
222 void setShrinkActive(
bool is_active)
override { m_internal->setShrinkActive(is_active); }
238TimeHistoryMng2(
const ModuleBuildInfo& mb,
bool add_entry_points)
240, CommonVariables(this)
241, m_internal(
makeRef(new TimeHistoryMngInternal(subDomain()->variableMng(),
242 makeRef(new Properties(subDomain()->propertyMng(),
"ArcaneTimeHistoryProperties")))))
245 if (add_entry_points) {
246 addEntryPoint(
this,
"ArcaneTimeHistoryBegin", &TimeHistoryMng2::timeHistoryBegin,
248 addEntryPoint(
this,
"ArcaneTimeHistoryEnd", &TimeHistoryMng2::timeHistoryEnd,
250 addEntryPoint(
this,
"ArcaneTimeHistoryInit", &TimeHistoryMng2::timeHistoryInit,
252 addEntryPoint(
this,
"ArcaneTimeHistoryStartInit", &TimeHistoryMng2::timeHistoryStartInit,
254 addEntryPoint(
this,
"ArcaneTimeHistoryContinueInit", &TimeHistoryMng2::timeHistoryContinueInit,
256 addEntryPoint(
this,
"ArcaneTimeHistoryStartInitEnd", &TimeHistoryMng2::timeHistoryStartInitEnd,
258 addEntryPoint(
this,
"ArcaneTimeHistoryRestore", &TimeHistoryMng2::timeHistoryRestore,
266void TimeHistoryMng2::
267timeHistoryStartInit()
269 m_internal->addNowInGlobalTime();
274void TimeHistoryMng2::
275timeHistoryStartInitEnd()
277 m_internal->updateGlobalTimeCurve();
283void TimeHistoryMng2::
293 m_internal->addNowInGlobalTime();
298 bool force_print_thm =
false;
302 if (
parallelMng()->isMasterIO() || (m_internal->isNonIOMasterCurvesEnabled() && m_internal->isMasterIOOfSubDomain()))
303 force_print_thm =
true;
305 if (
subDomain()->applicationInfo().isDebug())
306 force_print_thm =
true;
308 m_internal->dumpHistory();
315void TimeHistoryMng2::
318 m_internal->updateGlobalTimeCurve();
324void TimeHistoryMng2::
329 info(4) <<
"TimeHistory is MasterIO ? " << m_internal->isMasterIO();
330 if (!m_internal->isMasterIO() && (!m_internal->isNonIOMasterCurvesEnabled() || !m_internal->isMasterIOOfSubDomain()))
333 m_internal->editOutputPath(Directory(
subDomain()->exportDirectory(),
"courbes"));
334 m_internal->addObservers(
subDomain()->propertyMng());
337 ITimeHistoryCurveWriter2* gnuplot_curve_writer =
new GnuplotTimeHistoryCurveWriter2(
traceMng());
338 m_internal->addCurveWriter(
makeRef(gnuplot_curve_writer));
341 ServiceBuilder<ITimeHistoryCurveWriter2> builder(
subDomain());
342 auto writers = builder.createAllInstances();
343 for (
auto& wr_ref : writers) {
344 ITimeHistoryCurveWriter2* cw = wr_ref.get();
346 info() <<
"FOUND CURVE SERVICE (V2)!";
347 m_internal->addCurveWriter(wr_ref);
358 m_internal->addCurveWriter(
makeRef(writer));
364void TimeHistoryMng2::
365timeHistoryContinueInit()
367 if (m_internal->isMasterIO() || (m_internal->isNonIOMasterCurvesEnabled() && m_internal->isMasterIOOfSubDomain()))
374void TimeHistoryMng2::
377 m_internal->resizeArrayAfterRestore();
386 ARCANE_UNUSED(is_verbose);
387 m_internal->dumpHistory();
396 m_internal->dumpCurves(writer);
405 m_internal->applyTransformation(v);
414 m_internal->removeCurveWriter(
name);
428extern "C++" ARCANE_IMPL_EXPORT ITimeHistoryMng*
429arcaneCreateTimeHistoryMng2(ISubDomain* mng,
bool add_entry_points)
431 return new TimeHistoryMng2(ModuleBuildInfo(mng,
"TimeHistoryMng"), add_entry_points);
#define ARCANE_CHECK_POINTER(ptr)
Macro returning the pointer ptr if it is not null or throwing an exception if it is null.
String name() const override
Module name.
ITraceMng * traceMng() const override
Trace manager.
ISubDomain * subDomain() const override
Sub-domain associated with the module.
IMesh * defaultMesh() const override
Default mesh for this module.
AbstractModule(const ModuleBuildInfo &)
Constructor from a ModuleBuildInfo.
IParallelMng * parallelMng() const override
Message passing parallelism manager.
Int32 globalIteration() const
Current iteration number.
CommonVariables(IModule *c)
Constructs the references of the common variables for the module c.
constexpr Integer size() const noexcept
Number of elements in the array.
Class managing a directory.
void beginWrite(const TimeHistoryCurveWriterInfo &infos) override
Notify the start of writing.
void setOutputPath(const String &path) override
Base directory where curves will be written.
String outputPath() const override
Base directory where curves will be written.
void writeCurve(const TimeHistoryCurveInfo &infos) override
Write a curve.
void endWrite() override
Notify the end of writing.
String name() const override
Writer name.
static const char *const WComputeLoop
called during the calculation loop
static const char *const WStartInit
called during new case initialization
static const char *const WRestore
called to restore variables during a rollback
@ PAutoLoadEnd
Automatically loaded at the end. This means that a module possessing an entry point with this propert...
@ PAutoLoadBegin
Automatically loaded at the beginning. This means that a module possessing an entry point with this p...
static const char *const WContinueInit
called during continuation initialization
static const char *const WInit
called during initialization
Interface of the subdomain manager.
virtual const CaseOptionsMain * caseOptionsMain() const =0
General dataset options.
Interface for a curve writer.
virtual String name() const =0
Writer name.
Interface for the internal part of a value history manager.
Class managing a history of values.
Interface of an object transforming history curves.
Information for building a module.
Reference to an instance.
Unicode character string.
String clone() const
Clones this string.
const char * localstr() const
Returns the conversion of the instance into UTF-8 encoding.
Class extending the arguments when adding a value to a value history.
Information for writing a curve.
Int32ConstArrayView iterations() const
List of iterations.
const String & name() const
Curve name.
RealConstArrayView values() const
List of curve values.
Integer subSize() const
Number of values per time step.
Information about writing curves.
String path() const
Path to write the data (unless specifically overridden by the service via ITimeHistoryCurveWriter2::s...
RealConstArrayView times() const
List of times.
Manager of a history of values.
void applyTransformation(ITimeHistoryTransformer *v) override
Applies the transformation v to all curves.
void setDumpActive(bool is_active) override
Sets the output activation status.
void dumpCurves(ITimeHistoryCurveWriter2 *writer) override
Uses the writer writer to output all curves.
ITimeHistoryMngInternal * _internalApi() override
Internal Arcane API.
void removeCurveWriter(ITimeHistoryCurveWriter2 *writer) override
Removes a writer.
void addValue(const String &name, Real value, bool end_time, bool is_local) override
Adds the value value to the history name.
void setActive(bool is_active) override
Sets the activation status.
void addValue(const String &name, Int64 value, bool end_time, bool is_local) override
void dumpHistory(bool is_verbose) override
Saves the history.
bool active() const override
Indicates the activation status.
void addValue(const String &name, Int64ConstArrayView values, bool end_time, bool is_local) override
void setShrinkActive(bool is_active) override
Sets the boolean indicating if the history is compressed.
void addValue(const String &name, RealConstArrayView values, bool end_time, bool is_local) override
Adds the value value to the history name.
VersionInfo versionInfo() const override
Module version.
void addValue(const String &name, Int32 value, bool end_time, bool is_local) override
Adds the value value to the history name.
bool isDumpActive() const override
Indicates the output activation status.
void addValue(const String &name, Int32ConstArrayView values, bool end_time, bool is_local) override
Adds the value value to the history name.
void addCurveWriter(ITimeHistoryCurveWriter2 *writer) override
Adds a writer.
bool isShrinkActive() const override
Returns a boolean indicating if the history is compressed.
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
TraceMessage info() const
Flow for an information message.
TraceMessage warning() const
Flow for a warning message.
1D data vector with value semantics (STL style).
Information about a version.
double toDouble(Real r)
Converts a Real to double.
-- 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.
double Real
Type representing a real number.
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Creates a reference on a pointer.
void addEntryPoint(ModuleType *module, const char *name, void(ModuleType::*func)(), const String &where=IEntryPoint::WComputeLoop, int property=IEntryPoint::PNone)
Template routine allowing an entry point to be referenced in a module.
std::int32_t Int32
Signed integer type of 32 bits.
ConstArrayView< Real > RealConstArrayView
C equivalent of a 1D array of reals.