14#include "arcane/utils/ArcanePrecomp.h"
16#include "arcane/utils/ScopedPtr.h"
17#include "arcane/utils/Array.h"
18#include "arcane/utils/StringBuilder.h"
19#include "arcane/utils/NotImplementedException.h"
20#include "arcane/utils/StringBuilder.h"
22#include "arcane/core/AbstractService.h"
23#include "arcane/core/IRessourceMng.h"
24#include "arcane/core/BasicTimeLoopService.h"
25#include "arcane/core/IVariableWriter.h"
26#include "arcane/core/IXmlDocumentHolder.h"
27#include "arcane/core/IIOMng.h"
28#include "arcane/core/IMesh.h"
29#include "arcane/core/PostProcessorWriterBase.h"
30#include "arcane/core/IDataWriter.h"
31#include "arcane/core/IParallelMng.h"
32#include "arcane/core/Directory.h"
33#include "arcane/core/VariableCollection.h"
34#include "arcane/core/IMeshMng.h"
36#include "arcane/utils/Collection.h"
38#include "arcane/hdf5/Hdf5VariableWriter_axl.h"
39#include "arcane/hdf5/Hdf5VariableInfoBase.h"
57class Hdf5VariableWriterHelper
65 , m_xml_file_name(xml_filename)
68 virtual ~Hdf5VariableWriterHelper() {}
73 virtual void notifyRestore() {}
74 virtual void writeOnExit();
90void Hdf5VariableWriterHelper::
94 m_xml_document_holder = io_mng->
parseXmlFile(m_xml_file_name);
95 if (!m_xml_document_holder.get())
96 fatal() <<
"Can not read file '" << m_xml_file_name <<
"'";
98 XmlNode root_element = m_xml_document_holder->documentNode().documentElement();
99 m_hdf5_file_name = root_element.
attrValue(
"file-name",
true);
104 for (
XmlNode elem : variables_elem) {
105 String var_name = elem.attrValue(
"name",
true);
106 String var_family = elem.attrValue(
"family",
true);
107 String var_path = elem.attrValue(
"path",
true);
108 info() <<
"VARIABLE: name=" << var_name <<
" path=" << var_path
109 <<
" family=" << var_family;
112 m_exit_variables.add(var_info);
120void Hdf5VariableWriterHelper::
126 if (m_mesh->parallelMng()->isMasterIO()) {
127 hfile.openTruncate(m_hdf5_file_name);
130 std::set<ItemGroup> groups_to_write;
131 for (
Integer iz = 0, izs = m_exit_variables.size(); iz < izs; ++iz) {
132 Hdf5VariableInfoBase* vi = m_exit_variables[iz];
133 groups_to_write.insert(vi->variable()->itemGroup());
134 vi->writeVariable(hfile, m_types);
143class Hdf5VariableWriter
149 ~Hdf5VariableWriter();
154 void onTimeLoopStartInit()
override
160 info() <<
"Hdf5VariableWriter: FILE_INFO: mesh=" << mesh_name <<
" file_name=" << file_name;
167 info() <<
"Hdf5VariableWriter: Nb writer =" << m_writers.size();
168 for (
Integer i = 0, is = m_writers.size(); i < is; ++i) {
169 m_writers[i]->open();
172 void onTimeLoopExit()
override
174 info() <<
"Hdf5VariableWriter: End loop";
175 for (
Integer i = 0, is = m_writers.size(); i < is; ++i) {
176 m_writers[i]->writeOnExit();
179 void onTimeLoopRestore()
override
181 for (
Integer i = 0, is = m_writers.size(); i < is; ++i) {
182 m_writers[i]->notifyRestore();
185 void onTimeLoopBeginLoop()
override {}
189 UniqueArray<Hdf5VariableWriterHelper*> m_writers;
207 for (
Integer i = 0, is = m_writers.size(); i < is; ++i)
215class ManualHdf5DataWriter
219 typedef std::set<ItemGroup> ItemGroupSet;
228 , m_directory_name(directory_name)
229 , m_file_name(file_name)
237 info(4) <<
"BEGIN WRITE N=" << vars.count() <<
" INDEX=" << m_index <<
" directory=" << m_directory_name;
239 String full_filename = out_dir.
file(m_file_name);
240 info(4) <<
"OUT FILE_NAME=" << full_filename;
241 if (m_parallel_mng->isMasterIO()) {
243 m_hdf_file.openTruncate(full_filename);
246 m_hdf_file.openAppend(full_filename);
248 m_saved_groups.clear();
250 virtual void endWrite()
255 ARCANE_UNUSED(meta_data);
263 path +=
"/Variables/";
267 var_info->setPath(path);
268 var_info->writeVariable(m_hdf_file, m_hdf5_types);
273 if (!group.
null() && m_saved_groups.find(group) == m_saved_groups.end()) {
274 Integer save_type = Hdf5VariableInfoBase::SAVE_IDS + Hdf5VariableInfoBase::SAVE_COORDS;
275 String group_path = index_path +
"/Groups/" + group.
name();
276 var_info->writeGroup(m_hdf_file, m_hdf5_types, group_path, save_type);
278 m_saved_groups.insert(group);
285 v.write(m_hdf5_types, bytes);
290 Hdf5Utils::StandardTypes m_hdf5_types;
291 IParallelMng* m_parallel_mng;
293 String m_directory_name;
296 std::set<ItemGroup> m_saved_groups;
304class ManualHdf5VariableWriter
305:
public PostProcessorWriterBase
310 ~ManualHdf5VariableWriter();
327 info() <<
"Hdf5VariableWriter: nb_vars=" <<
variables.count() <<
" index=" << index;
335 bool is_master = subDomain()->parallelMng()->isMasterIO();
339 XmlNode doc = info_doc->documentNode();
344 for (VariableCollection::Enumerator ivar(
variables); ++ivar;) {
349 XmlNode x = root_element.createAndAppendElement(
"time-variable");
352 for (
Integer i = 0, n = my_times.
size(); i < n; ++i) {
353 XmlNode tx = x.createAndAppendElement(
"time-value");
354 String index_path = String::format(
"Index{0}/Variables/{1}", i + 1, var->
fullName());
356 tx.
setAttrValue(
"global-time", String::fromNumber(my_times[i]));
360 info_doc->save(xml_bytes);
362 m_writer->writeInfos(xml_bytes);
383 if (base_file_name.
null())
384 base_file_name =
"data";
385 m_file_name = base_file_name +
".h5";
392ManualHdf5VariableWriter::
402ManualHdf5VariableWriter::
403~ManualHdf5VariableWriter()
#define ARCANE_REGISTER_SUB_DOMAIN_FACTORY(aclass, ainterface, aname)
Registers a factory service for the class aclass.
Generation de la classe de base du Service.
CaseOptionsHdf5VariableWriter * options() const
Options du jeu de données du service.
ArcaneHdf5VariableWriterObject(const Arcane::ServiceBuildInfo &sbi)
Constructeur.
constexpr Integer size() const noexcept
Number of elements in the array.
Class managing a directory.
String file(const String &file_name) const override
Returns the full path of the file file_name in the directory.
Encapsulates a hid_t for a file.
Encapsulates a simple dataset from an HDF5 file that represents an array.
Definition of standard Arcane types for hdf5.
Base class for reading or writing a variable.
void setPath(const String &path)
Sets the path in the Hdf5 file containing the variable value.
HFile m_file_id
HDF file identifier.
Writing variables in HDF5 format.
void build() override
Build-level construction of the service.
virtual IIOMng * ioMng()=0
Input/output manager.
virtual IRessourceMng * ressourceMng() const =0
Resource manager.
Interface for writing variable data.
Interface of a data item.
Interface of the input/output manager.
virtual bool writeXmlFile(IXmlDocumentHolder *doc, const String &filename, const bool indented=false)=0
Writes the XML tree of the document doc to the file filename.
virtual IXmlDocumentHolder * parseXmlFile(const String &filename, const String &schemaname=String{})=0
Reads and parses the XML file filename.
virtual MeshHandle * findMeshHandle(const String &name, bool throw_exception)=0
Searches for the mesh with name name.
virtual IParallelMng * parallelMng()=0
Parallelism manager.
Interface of the parallelism manager for a subdomain.
virtual ITraceMng * traceMng() const =0
Trace manager.
virtual IIOMng * ioMng() const =0
I/O manager.
Interface for a writer for post-processing information.
virtual IXmlDocumentHolder * createXmlDocument()=0
Creates an XML document node.
virtual IMeshMng * meshMng() const =0
Returns the mesh manager.
virtual String itemFamilyName() const =0
Name of the associated family (null if none).
virtual String fullName() const =0
Full variable name (with family prefix).
virtual eItemKind itemKind() const =0
Kind of mesh entities on which the variable is based.
virtual ItemGroup itemGroup() const =0
Associated mesh group.
virtual String name() const =0
Variable name.
const String & name() const
Group name.
bool null() const
true means the group is the null group
virtual void setMetaData(const String &meta_data)
Sets the metadata information.
virtual void write(IVariable *var, IData *data)
Writes the data data of the variable var.
Writing variables in HDF5 format.
virtual void notifyEndWrite()
Notifies that an output has just been performed.
virtual void close()
Closes the writer. After closing, it can no longer be used.
virtual void notifyBeginWrite()
Notifies that an output will be performed with the current parameters.
virtual void build()
Build-level construction of the service.
virtual IDataWriter * dataWriter()
Returns the writer associated with this post-processor.
IMesh * mesh() const
Associated mesh.
Base class for a writer service for post-processing information.
VariableCollection variables() override
List of variables to save.
ConstArrayView< Real > times() override
List of saved times.
const String & baseDirectoryName() override
Name of the output directory for files.
const String & baseFileName() override
Name of the file containing the outputs.
T * get() const
Returns the object referenced by the instance.
Encapsulation of an automatically destructing pointer.
Structure containing the information to create a service.
Unicode character string constructor.
Unicode character string.
bool null() const
Returns true if the string is null.
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
TraceMessage fatal() const
Flow for a fatal error message.
TraceMessage info() const
Flow for an information message.
1D data vector with value semantics (STL style).
List of nodes of a DOM tree.
String attrValue(const String &name, bool throw_exception=false) const
Value of attribute name.
XmlNodeList children(const String &name) const
Set of child nodes of this node having the name name.
void setAttrValue(const String &name, const String &value)
Sets the attribute name to the value value.
Utility functions for Hdf5.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
UniqueArray< Byte > ByteUniqueArray
Dynamic 1D array of characters.
@ IK_Unknown
Unknown or uninitialized mesh entity.
ConstArrayView< Byte > ByteConstArrayView
C equivalent of a 1D array of characters.
ConstArrayView< Real > RealConstArrayView
C equivalent of a 1D array of reals.