Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
Hdf5VariableReader.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* Hdf5VariableReader.cc (C) 2000-2023 */
9/* */
10/* Reading variables in HDF5 format. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/ScopedPtr.h"
15#include "arcane/utils/StringBuilder.h"
16#include "arcane/utils/ITraceMng.h"
17#include "arcane/utils/HashTableMap.h"
18#include "arcane/utils/PlatformUtils.h"
19#include "arcane/utils/NotSupportedException.h"
20
21#include "arcane/core/AbstractService.h"
22#include "arcane/core/IVariableReader.h"
23#include "arcane/core/BasicTimeLoopService.h"
24#include "arcane/core/IXmlDocumentHolder.h"
25#include "arcane/core/IIOMng.h"
26#include "arcane/core/IMesh.h"
27#include "arcane/core/IItemFamily.h"
28#include "arcane/core/IParallelMng.h"
29#include "arcane/core/ISubDomain.h"
30#include "arcane/core/CommonVariables.h"
31#include "arcane/core/IVariableAccessor.h"
32#include "arcane/core/Directory.h"
33#include "arcane/core/VariableCollection.h"
34#include "arcane/core/IMeshMng.h"
35
36#include "arcane/hdf5/Hdf5VariableReader_axl.h"
37#include "arcane/hdf5/Hdf5Utils.h"
38#include "arcane/hdf5/Hdf5VariableInfoBase.h"
39
40#include <map>
41
42/*---------------------------------------------------------------------------*/
43/*---------------------------------------------------------------------------*/
44
45namespace Arcane
46{
47
48/*---------------------------------------------------------------------------*/
49/*---------------------------------------------------------------------------*/
50
51using namespace Hdf5Utils;
52
53/*---------------------------------------------------------------------------*/
54/*---------------------------------------------------------------------------*/
55
56class Hdf5VariableReaderHelperBase
57: public TraceAccessor
58{
59 protected:
60
61 class TimePathPair
62 {
63 public:
64
65 TimePathPair()
66 : m_time(0.0)
67 {}
68 TimePathPair(Real vtime, const String& path)
69 : m_time(vtime)
70 , m_path(path)
71 {}
72
73 public:
74
75 Real timeValue() const { return m_time; }
76 const String& path() const { return m_path; }
77
78 private:
79
80 Real m_time;
81 String m_path;
82 };
83
84 public:
85
86 Hdf5VariableReaderHelperBase(IMesh* mesh)
88 , m_mesh(mesh)
89 , m_is_verbose(false)
90 {
91 if (!platform::getEnvironmentVariable("ARCANE_DEBUG_HDF5VARIABLE").null())
92 m_is_verbose = true;
93 }
94
95 protected:
96
97 IMesh* m_mesh;
99 String m_hdf5_file_name;
100 bool m_is_verbose;
101
102 protected:
103
104 void _readStandardArray(IVariable* var, RealArray& buffer, hid_t file_id, const String& path);
105 void _readVariable(IVariable* var, RealArray& buffer, HFile& hfile, const String& path);
106 void _checkValidVariable(IVariable* var);
107};
108
109/*---------------------------------------------------------------------------*/
110/*---------------------------------------------------------------------------*/
111
112void Hdf5VariableReaderHelperBase::
113_readStandardArray(IVariable* var, RealArray& buffer, hid_t file_id, const String& path)
114{
115 Hdf5Utils::StandardArrayT<Real> values(file_id, path);
116 values.readDim();
117 Int64ConstArrayView dims(values.dimensions());
118 Integer nb_dim = dims.size();
119 if (nb_dim != 1)
120 fatal() << "Only one-dimension array are allowed "
121 << " dim=" << nb_dim << " var_name=" << var->fullName() << " path=" << path;
122 Integer nb_item = arcaneCheckArraySize(dims[0]);
123 info(4) << "NB_ITEM: nb_item=" << nb_item;
124#if 0
125 if (nb_item!=family->nbItem())
126 fatal() << "Bad number of items in file n=" << nb_item
127 << " expected=" << family->nbItem()
128 << " var_name=" << var_name << " path=" << var_path
129 << " family=" << var_family;
130#endif
131 buffer.resize(nb_item);
132 values.read(m_types, buffer);
133#if 0
134 {
135 Integer index=0;
136 for( Integer i=0; i<nb_item; ++i ){
137 if (buffer[i]>0.0){
138 ++index;
139 info() << " VAR_VAL i=" << i << " value=" << buffer[i];
140 }
141 if (index>20)
142 break;
143 }
144 }
145#endif
146}
147
148/*---------------------------------------------------------------------------*/
149/*---------------------------------------------------------------------------*/
150
151void Hdf5VariableReaderHelperBase::
152_readVariable(IVariable* var, RealArray& buffer, HFile& hfile, const String& path)
153{
154 IParallelMng* pm = m_mesh->parallelMng();
155 bool is_master = pm->isMasterIO();
156 //Integer rank = pm->commRank();
157 Integer master_rank = pm->masterIORank();
158 Integer buf_size = 0;
159
160 if (is_master) {
161 if (hfile.id() < 0) {
162 info() << "Hdf5VariableReaderHelper::OPEN FILE " << m_hdf5_file_name;
163 hfile.openRead(m_hdf5_file_name);
164 }
165 _readStandardArray(var, buffer, hfile.id(), path);
166 buf_size = buffer.size();
167 IntegerArrayView iav(1, &buf_size);
168 pm->broadcast(iav, master_rank);
169 pm->broadcast(buffer, master_rank);
170 }
171 else {
172 IntegerArrayView iav(1, &buf_size);
173 pm->broadcast(iav, master_rank);
174 buffer.resize(buf_size);
175 pm->broadcast(buffer, master_rank);
176 }
177
178 Int64UniqueArray unique_ids(buf_size);
179 Int32UniqueArray local_ids(buf_size);
180 IData* var_data = var->data();
181 auto* var_true_data = dynamic_cast<IArrayDataT<Real>*>(var_data);
182 if (!var_true_data)
183 throw FatalErrorException(A_FUNCINFO, "Variable is not an array of Real");
184 RealArrayView var_value(var_true_data->view());
185 Integer nb_var_value = var_value.size();
186 for (Integer z = 0; z < buf_size; ++z)
187 unique_ids[z] = z;
188 var->itemFamily()->itemsUniqueIdToLocalId(local_ids, unique_ids, false);
189 for (Integer z = 0; z < buf_size; ++z) {
190 Integer lid = local_ids[z];
191 if (lid == NULL_ITEM_LOCAL_ID)
192 continue;
193 if (lid > nb_var_value)
194 throw FatalErrorException(A_FUNCINFO, "Bad variable");
195 var_value[lid] = buffer[z];
196 }
197 info(4) << "End of read for variable '" << var->fullName()
198 << "' path=" << path;
199}
200
201/*---------------------------------------------------------------------------*/
202/*---------------------------------------------------------------------------*/
203
204void Hdf5VariableReaderHelperBase::
205_checkValidVariable(IVariable* var)
206{
207 if (var->dataType() == DT_Real && (var->dimension() == 1) && var->itemFamily())
208 return;
209 throw FatalErrorException(A_FUNCINFO,
210 String::format("Bad variable '{0}'. Variable must be an item variable,"
211 " have datatype 'Real' and dimension '1'",
212 var->fullName()));
213}
214
215/*---------------------------------------------------------------------------*/
216/*---------------------------------------------------------------------------*/
217
218/*---------------------------------------------------------------------------*/
219/*---------------------------------------------------------------------------*/
223class Hdf5VariableReaderHelper
224: public Hdf5VariableReaderHelperBase
225{
226 public:
227
231 class TimeVariableInfoBase
232 {
233 public:
234
235 TimeVariableInfoBase(const VariableItemReal& var)
236 : m_variable(var)
237 , m_begin_variable(VariableBuildInfo(var.itemGroup().mesh(), String("Hdf5TimeVariableBegin") + var.name(),
239 var.itemGroup().itemKind())
240 , m_end_variable(VariableBuildInfo(var.itemGroup().mesh(), String("Hdf5TimeVariableEnd") + var.name(),
242 var.itemGroup().itemKind())
243 , m_current_index(-1)
244 , m_mesh_timestamp(-1)
245 {
246 }
247
248 public:
249
250 VariableItemReal& variable() { return m_variable; }
251
252 private:
253
254 VariableItemReal m_variable;
255
256 public:
257
258 UniqueArray<TimePathPair> m_time_path_values;
259 VariableItemReal m_begin_variable;
260 VariableItemReal m_end_variable;
261
270 };
271
272 public:
273
274 Hdf5VariableReaderHelper(IMesh* mesh, const String& xml_file_name);
275 ~Hdf5VariableReaderHelper();
276
277 public:
278
285 void open(bool is_start);
286
288 void readInit();
289
291 void readAndUpdateTimeVariables(Real wanted_time);
292
294 void notifyRestore();
295
296 private:
297
298 String m_xml_file_name;
299
300 ScopedPtrT<IXmlDocumentHolder> m_xml_document_holder;
301 UniqueArray<Hdf5VariableInfoBase*> m_init_variables;
302 UniqueArray<TimeVariableInfoBase*> m_time_variables;
303
304 private:
305
306 //void _checkValidVariable(IVariable* var);
307 //void _readVariable(IVariable* var,RealUniqueArray buffer,HFile& hfile,const String& path);
308 void _readAndUpdateVariable(TimeVariableInfoBase* vi, Real wanted_time, HFile& hfile);
309
310 private:
311};
312
313/*---------------------------------------------------------------------------*/
314/*---------------------------------------------------------------------------*/
315
316Hdf5VariableReaderHelper::
317Hdf5VariableReaderHelper(IMesh* mesh, const String& xml_file_name)
319, m_xml_file_name(xml_file_name)
320{
321}
322
323/*---------------------------------------------------------------------------*/
324/*---------------------------------------------------------------------------*/
325
326Hdf5VariableReaderHelper::
327~Hdf5VariableReaderHelper()
328{
329 for (Integer i = 0, n = m_init_variables.size(); i < n; ++i)
330 delete m_init_variables[i];
331 m_init_variables.clear();
332 for (Integer i = 0, n = m_time_variables.size(); i < n; ++i)
333 delete m_time_variables[i];
334 m_time_variables.clear();
335}
336
337/*---------------------------------------------------------------------------*/
338/*---------------------------------------------------------------------------*/
339
341open(bool is_start)
342{
343 if (m_xml_file_name.null())
344 ARCANE_FATAL("No xml file specified");
345 IIOMng* io_mng = m_mesh->parallelMng()->ioMng();
346 m_xml_document_holder = io_mng->parseXmlFile(m_xml_file_name);
347 if (!m_xml_document_holder.get())
348 ARCANE_FATAL("Can not read file '{0}'", m_xml_file_name);
349
350 XmlNode root_element = m_xml_document_holder->documentNode().documentElement();
351 m_hdf5_file_name = root_element.attrValue("file-name", true);
352
353 // Reading variables for initialization
354 if (is_start) {
355 XmlNodeList variables_elem = root_element.children("init-variable");
356 for (XmlNode elem : variables_elem) {
357 String var_name = elem.attrValue("name", true);
358 String var_family = elem.attrValue("family", true);
359 String var_path = elem.attrValue("path", true);
360 info() << "INIT_VARIABLE: name=" << var_name << " path=" << var_path
361 << " family=" << var_family;
362 Hdf5VariableInfoBase* var_info = Hdf5VariableInfoBase::create(m_mesh, var_name, var_family);
363 var_info->setPath(var_path);
364 m_init_variables.add(var_info);
365 }
366 }
367
368 XmlNodeList variables_elem = root_element.children("time-variable");
369 for (XmlNode elem : variables_elem) {
370 String var_name = elem.attrValue("name", true);
371 String var_family = elem.attrValue("family", true);
372 info() << "TIME_VARIABLE: name=" << var_name << " family=" << var_family;
373 IItemFamily* family = m_mesh->findItemFamily(var_family, true);
374 IVariable* var = family->findVariable(var_name, false);
375 if (!var) {
376 warning() << "TEMPORARY: Create variable from hdf5 file";
377 VariableCellReal* vcr = new VariableCellReal(VariableBuildInfo(m_mesh, var_name));
378 var = vcr->variable();
379 }
380 _checkValidVariable(var);
381 VariableItemReal vir(VariableBuildInfo(m_mesh, var->name(), var->itemFamily()->name()), var->itemKind());
382 TimeVariableInfoBase* var_info = new TimeVariableInfoBase(vir);
383
384 XmlNodeList times_elem = elem.children("time-value");
385 Real last_var_time = -1.0;
386 for (XmlNode time_elem : times_elem) {
387 String var_path = time_elem.attrValue("path", true);
388 XmlNode var_time_node = time_elem.attr("global-time", true);
389 Real var_time = var_time_node.valueAsReal(true);
390 if (var_time <= last_var_time) {
391 fatal() << "Bad value for " << var_time_node.xpathFullName()
392 << " current=" << var_time << " previous=" << last_var_time
393 << ". current value should be greater than previous time.";
394 }
395 last_var_time = var_time;
396 var_info->m_time_path_values.add(TimePathPair(var_time, var_path));
397 }
398
399 m_time_variables.add(var_info);
400 }
401}
402
403/*---------------------------------------------------------------------------*/
404/*---------------------------------------------------------------------------*/
405
407readInit()
408{
409 //TODO throw exception in case of error.
410 HFile hfile;
411
412 for (Integer iz = 0, izs = m_init_variables.size(); iz < izs; ++iz) {
413 Hdf5VariableInfoBase* vi = m_init_variables[iz];
414 IVariable* var = vi->variable();
415 info() << "Hdf5VariableReader: init for variable name=" << var->fullName();
416 vi->readVariable(hfile, m_hdf5_file_name, m_types, String(), var->data());
417 }
418}
419
420/*---------------------------------------------------------------------------*/
421/*---------------------------------------------------------------------------*/
422
423void Hdf5VariableReaderHelper::
424_readAndUpdateVariable(TimeVariableInfoBase* vi, Real wanted_time, HFile& hfile)
425{
426 VariableItemReal& var = vi->variable();
427
428 ConstArrayView<TimePathPair> time_path_values(vi->m_time_path_values.view());
429 Integer current_index = -1;
430 Real begin_time = 0.0;
431 Real end_time = 0.0;
432 Integer nb_value = time_path_values.size();
433 for (Integer i = 0; i < nb_value; ++i) {
434 begin_time = time_path_values[i].timeValue();
435 if (wanted_time < begin_time) {
436 break;
437 }
438 current_index = i;
439 if ((i + 1) == nb_value) {
440 break;
441 }
442 if (math::isEqual(begin_time, wanted_time)) {
443 break;
444 }
445 end_time = time_path_values[i + 1].timeValue();
446 if (wanted_time > begin_time && wanted_time < end_time) {
447 break;
448 }
449 }
450 // Do nothing if not in the table
451 if (current_index < 0)
452 return;
453 info(4) << " FIND TIME: var=" << var.variable()->fullName() << " current=" << wanted_time
454 << " begin=" << begin_time << " end=" << end_time
455 << " index=" << current_index;
456 Int64 mesh_timestamp = var.variable()->meshHandle().mesh()->timestamp();
457 bool need_read = current_index != vi->m_current_index || vi->m_mesh_timestamp != mesh_timestamp;
458 if (nb_value == 1 || (current_index + 1) == nb_value) {
459 // We are at the end of the table.
460 // In this case, take the value corresponding to the last index without performing
461 // interpolation.
462 if (need_read) {
463 RealUniqueArray buffer;
464 String begin_path = vi->m_time_path_values[current_index].path();
465 info() << "Hdf5VariableReaderHelper:: PATH=" << begin_path;
466 _readVariable(vi->m_begin_variable.variable(), buffer, hfile, begin_path);
467 vi->m_current_index = current_index;
468 vi->m_mesh_timestamp = mesh_timestamp;
469 }
470
471 begin_time = vi->m_time_path_values[current_index].timeValue();
472 VariableItemReal& begin_variable = vi->m_begin_variable;
473
474 ENUMERATE_ITEM (iitem, var.itemGroup()) {
475 Real begin_value = begin_variable[iitem];
476 var[iitem] = begin_value;
477 if (m_is_verbose)
478 info() << "Value for cell=" << (*iitem).uniqueId() << " var_value=" << var[iitem];
479 }
480 }
481 else {
482 if (need_read) {
483 RealUniqueArray buffer;
484 String begin_path = vi->m_time_path_values[current_index].path();
485 String end_path = vi->m_time_path_values[current_index + 1].path();
486 info(4) << "Hdf5VariableReaderHelper:: BEGIN_PATH=" << begin_path << " END_PATH=" << end_path;
487 _readVariable(vi->m_begin_variable.variable(), buffer, hfile, begin_path);
488 _readVariable(vi->m_end_variable.variable(), buffer, hfile, end_path);
489 vi->m_current_index = current_index;
490 vi->m_mesh_timestamp = mesh_timestamp;
491 }
492
493 begin_time = vi->m_time_path_values[current_index].timeValue();
494 end_time = vi->m_time_path_values[current_index + 1].timeValue();
495 if (math::isEqual(begin_time, end_time))
496 fatal() << "Hdf5VariableReaderHelper::_readAndUpdateVariable() "
497 << " same value for begin and end time (value=" << begin_time << ")";
498 Real ratio = (wanted_time - begin_time) / (end_time - begin_time);
499 info(4) << " RATIO = " << ratio;
500 VariableItemReal& begin_variable = vi->m_begin_variable;
501 VariableItemReal& end_variable = vi->m_end_variable;
502
503 ENUMERATE_ITEM (iitem, var.itemGroup()) {
504 Real begin_value = begin_variable[iitem];
505 Real end_value = end_variable[iitem];
506 var[iitem] = (end_value - begin_value) * ratio + begin_value;
507 if (m_is_verbose) {
508 info() << "Value for cell=" << (*iitem).uniqueId()
509 << " begin=" << begin_value << " end_value=" << end_value
510 << " var_value=" << var[iitem];
511 }
512 }
513 }
514}
515
516/*---------------------------------------------------------------------------*/
517/*---------------------------------------------------------------------------*/
518
521{
522 HFile hfile;
523
524 for (Integer iz = 0, izs = m_time_variables.size(); iz < izs; ++iz) {
525 TimeVariableInfoBase* vi = m_time_variables[iz];
526 _readAndUpdateVariable(vi, wanted_time, hfile);
527 }
528}
529
530/*---------------------------------------------------------------------------*/
531/*---------------------------------------------------------------------------*/
532
535{
536 // For variables that depend on time, indicates that the current time
537 // is invalid and must be reloaded
538 for (Integer iz = 0, izs = m_time_variables.size(); iz < izs; ++iz) {
539 TimeVariableInfoBase* vi = m_time_variables[iz];
540 vi->m_current_index = -1;
541 }
542}
543
544/*---------------------------------------------------------------------------*/
545/*---------------------------------------------------------------------------*/
546
547/*---------------------------------------------------------------------------*/
548/*---------------------------------------------------------------------------*/
552class Hdf5VariableReaderHelper2
553: public Hdf5VariableReaderHelperBase
554{
555 public:
556
562 class TimeVariableInfoBase
563 {
564 public:
565
566 TimeVariableInfoBase(Hdf5VariableInfoBase* var)
567 : m_hdf5_var_info(var)
568 , m_current_index(-1)
569 , m_mesh_timestamp(-1)
570 {
571 }
572 ~TimeVariableInfoBase()
573 {
574 }
575
576 public:
577
578 IVariable* variable() { return m_hdf5_var_info->variable(); }
579 Hdf5VariableInfoBase* hdf5Info() { return m_hdf5_var_info; }
580 Real2 timeInterval() const
581 {
582 Integer n = m_time_path_values.size();
583 if (n == 0)
584 return Real2(0.0, 0.0);
585 Real x = m_time_path_values[0].timeValue();
586 Real y = m_time_path_values[n - 1].timeValue();
587 return Real2(x, y);
588 }
589 void rebuildData()
590 {
591 IVariable* v = variable();
592 m_begin_data = v->data()->cloneRef();
593 m_end_data = v->data()->cloneRef();
594 }
595
596 private:
597
598 Hdf5VariableInfoBase* m_hdf5_var_info;
599
600 public:
601
602 UniqueArray<TimePathPair> m_time_path_values;
603 Ref<IData> m_begin_data;
604 Ref<IData> m_end_data;
605
614 };
615
620 class CorrespondanceInfo : public Hdf5VariableInfoBase::ICorrespondanceFunctor
621 {
622 public:
623
624 CorrespondanceInfo(const ItemGroup& group)
625 : m_group(group)
626 , m_corresponding_uids(VariableBuildInfo(group.mesh(), String("CorrespondingUids_") + group.fullName(), IVariable::PNoRestore))
627 , m_corresponding_hash(512, true)
628 {
629 }
630
631 public:
632
633 virtual Int64 getOldUniqueId(Int64 uid, Integer index)
634 {
635 ARCANE_UNUSED(index);
636 HashTableMapT<Int64, Int64>::Data* uid_data = m_corresponding_hash.lookup(uid);
637 if (!uid_data)
638 throw FatalErrorException(A_FUNCINFO,
639 String::format("Can not find corresponding uid item='{0}' group={1}",
640 uid, m_group.fullName()));
641 Int64 old_uid = uid_data->value();
642 return old_uid;
643 }
644
645 public:
646
647 void updateHashMap()
648 {
649 m_corresponding_hash.clear();
650 Integer nb_pair = m_corresponding_uids.size() / 2;
651 for (Integer z = 0; z < nb_pair; ++z)
652 m_corresponding_hash.add(m_corresponding_uids[z * 2], m_corresponding_uids[(z * 2) + 1]);
653 }
654
655 public:
656
657 ItemGroup m_group;
658 VariableArrayInt64 m_corresponding_uids;
659 HashTableMapT<Int64, Int64> m_corresponding_hash;
660 };
661
662 public:
663
664 Hdf5VariableReaderHelper2(IMesh* mesh, const String& hdf5_file_name);
665 ~Hdf5VariableReaderHelper2();
666
667 public:
668
676 {
677 m_wanted_vars = vars;
678 }
679
686 void open(bool is_start);
687
689 void readAndUpdateTimeVariables(Real wanted_time);
690
692 void notifyRestore();
693
694 Real2 timeInterval(IVariable* var)
695 {
696 for (Integer i = 0, n = m_time_variables.size(); i < n; ++i) {
697 TimeVariableInfoBase* vinfo = m_time_variables[i];
698 if (vinfo->variable() == var)
699 return vinfo->timeInterval();
700 }
701 return Real2(0.0, 0.0);
702 }
703
704 protected:
705 private:
706
707 UniqueArray<IVariable*> m_wanted_vars;
708 ScopedPtrT<IXmlDocumentHolder> m_xml_document_holder;
709 UniqueArray<TimeVariableInfoBase*> m_time_variables;
710 std::map<String, CorrespondanceInfo*> m_correspondance_map;
711
712 private:
713
714 template <typename DataType>
715 void _readAndUpdateVariable(TimeVariableInfoBase* vi, Real wanted_time, HFile& hfile);
716 bool _isWanted(const String& var_name, const String& var_family);
717 void _checkCreateCorrespondance(Hdf5VariableInfoBase* var, HFile& file_id, const String& group_path, bool is_start);
718 void _createCorrespondance(IVariable* var, CorrespondanceInfo* ci, Int64ConstArrayView saved_uids, Real3ConstArrayView saved_centers);
719
720 private:
721};
722
723/*---------------------------------------------------------------------------*/
724/*---------------------------------------------------------------------------*/
725
726Hdf5VariableReaderHelper2::
727Hdf5VariableReaderHelper2(IMesh* mesh, const String& hdf5_file_name)
728: Hdf5VariableReaderHelperBase(mesh)
729{
730 m_hdf5_file_name = hdf5_file_name;
731}
732
733/*---------------------------------------------------------------------------*/
734/*---------------------------------------------------------------------------*/
735
736Hdf5VariableReaderHelper2::
737~Hdf5VariableReaderHelper2()
738{
739 for (Integer i = 0, n = m_time_variables.size(); i < n; ++i)
740 delete m_time_variables[i];
741 m_time_variables.clear();
742}
743
744/*---------------------------------------------------------------------------*/
745/*---------------------------------------------------------------------------*/
746
748open(bool is_start)
749{
750 if (m_hdf5_file_name.null())
751 throw FatalErrorException(A_FUNCINFO, "No hdf5 file specified");
752
753 HFile file_id;
754 IParallelMng* pm = m_mesh->parallelMng();
755 bool is_master = pm->isMasterIO();
756 ByteUniqueArray xml_bytes;
757 if (is_master) {
758 file_id.openRead(m_hdf5_file_name);
759 Hdf5Utils::StandardArrayT<Byte> v(file_id.id(), "Infos");
760 v.directRead(m_types, xml_bytes);
761 }
762 info(5) << "XML_DATA len=" << xml_bytes.size() << " data=" << xml_bytes << "__EOF";
763 pm->broadcastMemoryBuffer(xml_bytes, pm->masterIORank());
764
765 IIOMng* io_mng = m_mesh->parallelMng()->ioMng();
766 m_xml_document_holder = io_mng->parseXmlBuffer(xml_bytes, m_hdf5_file_name);
767 if (!m_xml_document_holder.get())
768 ARCANE_FATAL("Can not XML data from file '{0}'", m_hdf5_file_name);
769
770 XmlNode root_element = m_xml_document_holder->documentNode().documentElement();
771 //m_hdf5_file_name = root_element.attrValue("file-name",true);
772
773 XmlNodeList variables_elem = root_element.children("time-variable");
774 for (const auto& elem : variables_elem) {
775 String var_name = elem.attrValue("name", true);
776 String var_family = elem.attrValue("family", true);
777 info(4) << "TIME_VARIABLE: name=" << var_name << " family=" << var_family;
778 if (!_isWanted(var_name, var_family))
779 continue;
780 //TODO: create the variable if it doesn't exist or do something (exception...)
781 Hdf5VariableInfoBase* var_info = Hdf5VariableInfoBase::create(m_mesh, var_name, var_family);
782 //TODO: tmp
783 String group_name = var_info->variable()->itemGroupName();
784 String index_path = String("Index") + 1;
785 String group_path = index_path + "/Groups/" + group_name;
786 _checkCreateCorrespondance(var_info, file_id, group_path, is_start);
787
788 TimeVariableInfoBase* time_var_info = new TimeVariableInfoBase(var_info);
789
790 XmlNodeList times_elem = elem.children("time-value");
791 Real last_var_time = -1.0;
792 for (const auto& time_elem : times_elem) {
793 String var_path = time_elem.attrValue("path", true);
794 XmlNode var_time_node = time_elem.attr("global-time", true);
795 Real var_time = var_time_node.valueAsReal(true);
796 if (var_time <= last_var_time) {
797 fatal() << "Bad value for " << var_time_node.xpathFullName()
798 << " current=" << var_time << " previous=" << last_var_time
799 << ". current value should be greater than previous time.";
800 }
801 last_var_time = var_time;
802 time_var_info->m_time_path_values.add(TimePathPair(var_time, var_path));
803 }
804
805 m_time_variables.add(time_var_info);
806 }
807}
808
809/*---------------------------------------------------------------------------*/
810/*---------------------------------------------------------------------------*/
811
812void Hdf5VariableReaderHelper2::
813_checkCreateCorrespondance(Hdf5VariableInfoBase* var_info, HFile& file_id, const String& group_path, bool is_start)
814{
815 IVariable* var = var_info->variable();
816 // Checks if the correspondence already exists.
817 ItemGroup group = var->itemGroup();
818 CorrespondanceInfo* ci = 0;
819 std::map<String, CorrespondanceInfo*>::const_iterator iter = m_correspondance_map.find(group.fullName());
820 if (iter == m_correspondance_map.end()) {
821 ci = new CorrespondanceInfo(group);
822 if (is_start) {
823 Int64UniqueArray saved_uids;
824 Real3UniqueArray saved_centers;
825 var_info->readGroupInfo(file_id, m_types, group_path, saved_uids, saved_centers);
826 _createCorrespondance(var, ci, saved_uids, saved_centers);
827 }
828 ci->updateHashMap();
829 m_correspondance_map.insert(std::make_pair(group.fullName(), ci));
830 }
831 else
832 ci = iter->second;
833 var_info->setCorrespondanceFunctor(ci);
834}
835
836/*---------------------------------------------------------------------------*/
837/*---------------------------------------------------------------------------*/
853 Real3ConstArrayView saved_centers)
854{
855 IMesh* mesh = var->meshHandle().mesh();
856 ItemGroup group = var->itemGroup();
857 IParallelMng* pm = mesh->parallelMng();
858
859 Int64UniqueArray corresponding_uids;
860 Integer nb_orig_item = saved_uids.size();
861 VariableNodeReal3& nodes_coords(mesh->nodesCoordinates());
862 ENUMERATE_ITEM (iitem, group) {
863 Real3 item_center;
864 ItemUniqueId item_uid = (*iitem).uniqueId();
865 if ((*iitem).isItemWithNodes()) {
866 ItemWithNodes item = (*iitem).toItemWithNodes();
867 if (!item.isOwn())
868 continue;
869 Integer nb_node = item.nbNode();
870 for (NodeLocalId inode : item.nodeIds()) {
871 item_center += nodes_coords[inode];
872 }
873 item_center /= nb_node;
874 }
875 else {
876 Node node = (*iitem).toNode();
877 item_center = nodes_coords[node];
878 }
879
880 // Search for the closest entity.
881 Real min_dist = FloatInfo<Real>::maxValue();
882 Integer min_index = -1;
883 for (Integer z = 0; z < nb_orig_item; ++z) {
884 Real d = (item_center - saved_centers[z]).squareNormL2();
885 if (d < min_dist) {
886 min_dist = d;
887 min_index = z;
888 }
889 }
890 if (min_index == (-1))
891 throw FatalErrorException(A_FUNCINFO, "Can not find old unique id");
892 info() << "FIND NEAREST my_uid=" << item_uid << " orig_uid=" << saved_uids[min_index]
893 << " d^2=" << min_dist;
894 corresponding_uids.add(item_uid);
895 corresponding_uids.add(saved_uids[min_index]);
896 }
897
898 // For now, and to simplify things in case of mesh redistribution
899 // of the mesh, we retrieve all information from other subdomains.
900 // This is not ideal because it duplicates information everywhere,
901 // but it avoids having to manage the redistribution.
902 // Eventually, this information should be distributed to each process
903 // and grouped when updating the hash table during a mesh change.
904 Int64UniqueArray global_uids;
905 pm->allGatherVariable(corresponding_uids, global_uids);
906 ci->m_corresponding_uids.resize(global_uids.size());
907 ci->m_corresponding_uids.copy(global_uids);
908}
909
910/*---------------------------------------------------------------------------*/
911/*---------------------------------------------------------------------------*/
912
913bool Hdf5VariableReaderHelper2::
914_isWanted(const String& var_name, const String& var_family)
915{
916 Integer nb_var = m_wanted_vars.size();
917 if (nb_var == 0)
918 return true;
919 for (Integer i = 0, n = m_wanted_vars.size(); i < n; ++i) {
920 IVariable* v = m_wanted_vars[i];
921 if (v->name() == var_name && v->itemFamilyName() == var_family)
922 return true;
923 }
924 return false;
925}
926
927/*---------------------------------------------------------------------------*/
928/*---------------------------------------------------------------------------*/
929
930template <typename DataType>
931void Hdf5VariableReaderHelper2::
932_readAndUpdateVariable(TimeVariableInfoBase* vi, Real wanted_time, HFile& hfile)
933{
934 //VariableItemReal& var = vi->variable();
935
936 ConstArrayView<TimePathPair> time_path_values(vi->m_time_path_values.view());
937 Integer current_index = -1;
938 Real begin_time = 0.0;
939 Real end_time = 0.0;
940 Integer nb_value = time_path_values.size();
941 for (Integer i = 0; i < nb_value; ++i) {
942 begin_time = time_path_values[i].timeValue();
943 if (wanted_time < begin_time) {
944 break;
945 }
946 current_index = i;
947 if ((i + 1) == nb_value) {
948 // Reached the end of the table. Does nothing.
949 current_index = -1;
950 break;
951 }
952 if (math::isEqual(begin_time, wanted_time)) {
953 break;
954 }
955 end_time = time_path_values[i + 1].timeValue();
956 if (wanted_time > begin_time && wanted_time < end_time) {
957 break;
958 }
959 }
960 // Does nothing if we are not in the table
961 if (current_index < 0)
962 return;
963
964 //TODO use the modifiedTime of the variable group instead of the mesh
965 IVariable* variable = vi->variable();
966 Int64 mesh_timestamp = variable->meshHandle().mesh()->timestamp();
967
968 // We must reread the info if we change the index in the table
969 // or if the mesh changes
970 bool need_read = current_index != vi->m_current_index || vi->m_mesh_timestamp != mesh_timestamp;
971 if (need_read)
972 vi->rebuildData();
973
974 String ids_hpath = String("Index1/Groups/") + variable->itemGroupName() + "_Ids";
975 info(4) << " FIND TIME: current=" << wanted_time << " begin=" << begin_time << " end=" << end_time
976 << " index=" << current_index << "ids_path=" << ids_hpath << " var=" << variable->fullName();
977 Hdf5VariableInfoBase* var_info = vi->hdf5Info();
978 IArrayDataT<DataType>* true_begin_data = dynamic_cast<IArrayDataT<DataType>*>(vi->m_begin_data.get());
979 IArrayDataT<DataType>* true_end_data = dynamic_cast<IArrayDataT<DataType>*>(vi->m_end_data.get());
980 IArrayDataT<DataType>* true_data = dynamic_cast<IArrayDataT<DataType>*>(variable->data());
981 info(4) << "DATA: begin=" << vi->m_begin_data.get() << " end=" << vi->m_end_data.get() << " current=" << variable->data();
982 info(4) << "TRUEDATA: begin=" << true_begin_data << " end=" << true_end_data << " current=" << true_data;
983 if (!true_data || !true_end_data || !true_begin_data) {
984 throw FatalErrorException(A_FUNCINFO, "variable data can not be cast to type IArrayDataT");
985 }
986 bool is_partial = variable->isPartial();
987
988 if (need_read) {
989 String begin_path = vi->m_time_path_values[current_index].path();
990 String end_path = vi->m_time_path_values[current_index + 1].path();
991 info(4) << "Hdf5VariableReaderHelper2:: Reading new index BEGIN_PATH=" << begin_path << " END_PATH=" << end_path;
992 var_info->setPath(begin_path);
993 var_info->readVariable(hfile, m_hdf5_file_name, m_types, ids_hpath, vi->m_begin_data.get());
994 var_info->setPath(end_path);
995 var_info->readVariable(hfile, m_hdf5_file_name, m_types, ids_hpath, vi->m_end_data.get());
996 }
997
998 vi->m_current_index = current_index;
999 vi->m_mesh_timestamp = mesh_timestamp;
1000
1001 begin_time = vi->m_time_path_values[current_index].timeValue();
1002 end_time = vi->m_time_path_values[current_index + 1].timeValue();
1003 if (math::isEqual(begin_time, end_time))
1004 throw FatalErrorException(A_FUNCINFO,
1005 String::format("same value for begin and end time (value={0})",
1006 begin_time));
1007 Real ratio = (wanted_time - begin_time) / (end_time - begin_time);
1008 info(4) << " BeginTime=" << begin_time << " wanted=" << wanted_time << " end_time=" << end_time
1009 << " ratio = " << ratio;
1010 {
1011 ConstArrayView<DataType> begin_values_view = true_begin_data->view();
1012 ConstArrayView<DataType> end_values_view = true_end_data->view();
1013 ArrayView<DataType> values_view = true_data->view();
1014 ENUMERATE_ITEM (iitem, variable->itemGroup()) {
1015 Int32 lid = (is_partial) ? iitem.index() : iitem.itemLocalId();
1016 DataType begin_value = begin_values_view[lid];
1017 DataType end_value = end_values_view[lid];
1018 values_view[lid] = (end_value - begin_value) * ratio + begin_value;
1019 if (m_is_verbose) {
1020 info() << "Value for cell=" << (*iitem).uniqueId()
1021 << " begin=" << begin_value << " end_value=" << end_value
1022 << " var_value=" << values_view[lid];
1023 }
1024 }
1025 }
1026}
1027
1028/*---------------------------------------------------------------------------*/
1029/*---------------------------------------------------------------------------*/
1030
1033{
1034 HFile hfile;
1035
1036 for (Integer iz = 0, izs = m_time_variables.size(); iz < izs; ++iz) {
1037 TimeVariableInfoBase* vi = m_time_variables[iz];
1038 IVariable* variable = vi->variable();
1039 switch (variable->dataType()) {
1040 case DT_Real:
1041 _readAndUpdateVariable<Real>(vi, wanted_time, hfile);
1042 break;
1043 case DT_Real3:
1044 _readAndUpdateVariable<Real3>(vi, wanted_time, hfile);
1045 break;
1046 default:
1047 throw NotSupportedException(A_FUNCINFO, "Bad variable datatype (only Real and Real3 are supported)");
1048 }
1049 }
1050}
1051
1052/*---------------------------------------------------------------------------*/
1053/*---------------------------------------------------------------------------*/
1054
1057{
1058 // For variables that depend on time, indicates that the time
1059 // current is invalid and must be reloaded
1060 for (Integer iz = 0, izs = m_time_variables.size(); iz < izs; ++iz) {
1061 TimeVariableInfoBase* vi = m_time_variables[iz];
1062 vi->m_current_index = -1;
1063 }
1064}
1065
1066/*---------------------------------------------------------------------------*/
1067/*---------------------------------------------------------------------------*/
1068
1069/*---------------------------------------------------------------------------*/
1070/*---------------------------------------------------------------------------*/
1074class Hdf5VariableReader
1076{
1077 public:
1078
1079 explicit Hdf5VariableReader(const ServiceBuildInfo& sbi);
1080 ~Hdf5VariableReader() override;
1081
1082 public:
1083
1084 void build() override
1085 {
1086 }
1087
1088 void onTimeLoopStartInit() override
1089 {
1090 _load(true);
1091 for (Integer i = 0, is = m_readers.size(); i < is; ++i) {
1092 m_readers[i]->readInit();
1093 }
1094 }
1095 void onTimeLoopContinueInit() override
1096 {
1097 // On resume, variables must be loaded but not reread
1098 _load(false);
1099 }
1100 void onTimeLoopEndLoop() override {}
1101 void onTimeLoopRestore() override
1102 {
1103 for (Integer i = 0, is = m_readers.size(); i < is; ++i) {
1104 m_readers[i]->notifyRestore();
1105 }
1106 }
1107 void onTimeLoopBeginLoop() override
1108 {
1109 Real current_time = subDomain()->commonVariables().globalTime();
1110 for (Integer i = 0, is = m_readers.size(); i < is; ++i) {
1111 m_readers[i]->readAndUpdateTimeVariables(current_time);
1112 }
1113 }
1114
1115 private:
1116
1117 void _load(bool is_start)
1118 {
1119 IMeshMng* mm = subDomain()->meshMng();
1120 for (Integer i = 0, is = options()->read.size(); i < is; ++i) {
1121 String file_name = options()->read[i]->fileName();
1122 String mesh_name = options()->read[i]->meshName();
1123 info() << "Hdf5VariableReader: FILE_INFO: mesh=" << mesh_name << " file_name=" << file_name;
1124 {
1125 IMesh* mesh = mm->findMeshHandle(mesh_name).mesh();
1126 Hdf5VariableReaderHelper* sd = new Hdf5VariableReaderHelper(mesh, file_name);
1127 m_readers.add(sd);
1128 }
1129 }
1130 info() << "Hdf5VariableReader: Nb reader =" << m_readers.size();
1131 for (Integer i = 0, is = m_readers.size(); i < is; ++i) {
1132 m_readers[i]->open(is_start);
1133 }
1134 }
1135
1136 private:
1137
1138 UniqueArray<Hdf5VariableReaderHelper*> m_readers;
1139};
1140
1141/*---------------------------------------------------------------------------*/
1142/*---------------------------------------------------------------------------*/
1143
1144Hdf5VariableReader::
1145Hdf5VariableReader(const ServiceBuildInfo& sbi)
1147{
1148}
1149
1150/*---------------------------------------------------------------------------*/
1151/*---------------------------------------------------------------------------*/
1152
1153Hdf5VariableReader::
1154~Hdf5VariableReader()
1155{
1156 for (Integer i = 0, is = m_readers.size(); i < is; ++i)
1157 delete m_readers[i];
1158 m_readers.clear();
1159}
1160
1161/*---------------------------------------------------------------------------*/
1162/*---------------------------------------------------------------------------*/
1163
1164/*---------------------------------------------------------------------------*/
1165/*---------------------------------------------------------------------------*/
1169class ManualHdf5VariableReader
1170: public BasicService
1171, public IVariableReader
1172{
1173 public:
1174
1175 ManualHdf5VariableReader(const ServiceBuildInfo& sbi);
1176 ~ManualHdf5VariableReader();
1177
1178 public:
1179
1180 virtual void build()
1181 {
1182 }
1183
1184 virtual void read(IVariable* var)
1185 {
1186 ARCANE_UNUSED(var);
1187 }
1188
1189 virtual void initialize(bool is_start)
1190 {
1191 pwarning() << "Reading variable from HDF5 file does not work with mesh load balancing";
1192 if (m_base_file_name.null())
1193 m_base_file_name = "data";
1194 String file_name = m_base_file_name + ".h5";
1195 Directory dir(m_directory_name);
1196 String full_file_name = dir.file(file_name);
1197 m_helper = new Hdf5VariableReaderHelper2(mesh(), full_file_name);
1198 m_helper->setVariables(m_variables);
1199 m_helper->open(is_start);
1200 }
1201
1202 virtual void updateVariables(Real wanted_time)
1203 {
1204 m_helper->readAndUpdateTimeVariables(wanted_time);
1205 }
1206
1207 virtual void setBaseDirectoryName(const String& path)
1208 {
1209 m_directory_name = path;
1210 }
1211
1212 virtual void setBaseFileName(const String& path)
1213 {
1214 m_base_file_name = path;
1215 }
1216
1218 {
1219 for (VariableCollection::Enumerator ivar(vars); ++ivar;)
1220 m_variables.add(*ivar);
1221 }
1223 {
1224 arcaneCheckNull(m_helper);
1225 arcaneCheckNull(var);
1226 return m_helper->timeInterval(var);
1227 }
1228
1229 public:
1230
1231 Hdf5VariableReaderHelper2* m_helper;
1232 String m_directory_name;
1233 String m_base_file_name;
1234 UniqueArray<IVariable*> m_variables;
1235};
1236
1237/*---------------------------------------------------------------------------*/
1238/*---------------------------------------------------------------------------*/
1239
1240ManualHdf5VariableReader::
1241ManualHdf5VariableReader(const ServiceBuildInfo& sbi)
1242: BasicService(sbi)
1243, m_helper(0)
1244, m_directory_name(".")
1245, m_base_file_name("data")
1246{
1247}
1248
1249/*---------------------------------------------------------------------------*/
1250/*---------------------------------------------------------------------------*/
1251
1252ManualHdf5VariableReader::
1253~ManualHdf5VariableReader()
1254{
1255 delete m_helper;
1256}
1257
1258/*---------------------------------------------------------------------------*/
1259/*---------------------------------------------------------------------------*/
1263class OldManualHdf5VariableReader
1264: public BasicService
1265, public IVariableReader
1266{
1267 public:
1268
1269 OldManualHdf5VariableReader(const ServiceBuildInfo& sbi)
1270 : BasicService(sbi)
1271 , m_reader(nullptr)
1272 {}
1273 ~OldManualHdf5VariableReader()
1274 {
1275 delete m_reader;
1276 }
1277
1278 public:
1279
1280 virtual void build()
1281 {
1282 }
1283
1284 public:
1285
1286 virtual void read(IVariable* var)
1287 {
1288 ARCANE_UNUSED(var);
1289 throw NotSupportedException(A_FUNCINFO);
1290 }
1291
1292 virtual void initialize(bool is_start)
1293 {
1294 _load(is_start);
1295 }
1296
1297 virtual void updateVariables(Real wanted_time)
1298 {
1299 m_reader->readAndUpdateTimeVariables(wanted_time);
1300 }
1301
1302 virtual void setBaseDirectoryName(const String& path)
1303 {
1304 m_directory_name = path;
1305 }
1306
1307 virtual void setBaseFileName(const String& path)
1308 {
1309 m_base_file_name = path;
1310 }
1311
1313 {
1314 ARCANE_UNUSED(vars);
1315 throw NotSupportedException(A_FUNCINFO);
1316 }
1317
1319 {
1320 ARCANE_UNUSED(var);
1321 throw NotSupportedException(A_FUNCINFO);
1322 }
1323
1324 private:
1325
1326 void _load(bool is_start)
1327 {
1328 ARCANE_UNUSED(is_start);
1329
1330 Directory dir(m_directory_name);
1331 String file_name = dir.file(m_base_file_name);
1332
1333 info() << "OldManualHdf5VariableReader: FILE_INFO: file_name=" << file_name;
1334 IMesh* mesh = subDomain()->defaultMesh();
1336 m_reader = sd;
1337 }
1338
1339 private:
1340
1341 Hdf5VariableReaderHelper* m_reader;
1342 String m_directory_name;
1343 String m_base_file_name;
1344};
1345
1346/*---------------------------------------------------------------------------*/
1347/*---------------------------------------------------------------------------*/
1348
1349ARCANE_REGISTER_SERVICE_HDF5VARIABLEREADER(Hdf5VariableReader,
1351
1353 ServiceProperty("Hdf5VariableReader", ST_SubDomain),
1355
1357 ServiceProperty("OldManualHdf5VariableReader", ST_SubDomain),
1359
1360/*---------------------------------------------------------------------------*/
1361/*---------------------------------------------------------------------------*/
1362
1363} // End namespace Arcane
1364
1365/*---------------------------------------------------------------------------*/
1366/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
#define ENUMERATE_ITEM(name, group)
Generic enumerator for a node group.
#define ARCANE_SERVICE_INTERFACE(ainterface)
Macro to declare an interface when registering a service.
Integer size() const
Number of elements in the vector.
Generation de la classe de base du Service.
ArcaneHdf5VariableReaderObject(const Arcane::ServiceBuildInfo &sbi)
Constructeur.
CaseOptionsHdf5VariableReader * options() const
Options du jeu de données du service.
void copy(const U &copy_array)
Copies the array copy_array into the instance.
void add(ConstReferenceType val)
Adds element val to the end of the array.
Constant view of an array of type T.
constexpr Integer size() const noexcept
Number of elements in the array.
Class managing a directory.
Definition Directory.h:36
String file(const String &file_name) const override
Returns the full path of the file file_name in the directory.
Definition Directory.cc:120
Information about the floating-point type.
Definition Limits.h:49
Hash table for associative arrays.
Encapsulates a hid_t for a file.
Encapsulates a simple dataset from an HDF5 file that represents an array.
void directRead(StandardTypes &st, Array< DataType > &buffer)
Reads the dataset of a 1D array.
Definition of standard Arcane types for hdf5.
Functor to establish the correspondence between a entity of the current mesh and that of the saved me...
Base class for reading or writing a variable.
void setPath(const String &path)
Sets the path in the Hdf5 file containing the variable value.
Correspondence information between saved uids and those of the current mesh for the group group.
Int64 m_mesh_timestamp
Mesh timestamp when this index was read.
Integer m_current_index
Contains the index in the time array of the currently read time.
Reading variables in HDF5 format.
void _createCorrespondance(IVariable *var, CorrespondanceInfo *ci, Int64ConstArrayView saved_uids, Real3ConstArrayView saved_centers)
Finds which saved mesh entity corresponds to a current mesh entity.
void readAndUpdateTimeVariables(Real wanted_time)
Reading and updating variables.
void setVariables(ConstArrayView< IVariable * > vars)
Specifies the variables that we want to reread.
void notifyRestore()
Notification of a rollback.
void open(bool is_start)
Opens the file containing the reading information.
Integer m_current_index
Contains the index in the time array of the currently read time.
Int64 m_mesh_timestamp
Mesh timestamp at which this index was read.
Reading variables in HDF5 format.
void notifyRestore()
Notification of a rollback.
void readInit()
Reads the information.
void open(bool is_start)
Opens the file containing the reading information.
void readAndUpdateTimeVariables(Real wanted_time)
Reads and updates time variables.
Reading variables in HDF5 format.
void build() override
Build-level construction of the service.
virtual Ref< IData > cloneRef()=0
Clone the data.
Interface of the input/output manager.
Definition IIOMng.h:37
virtual IXmlDocumentHolder * parseXmlFile(const String &filename, const String &schemaname=String{})=0
Reads and parses the XML file filename.
virtual IXmlDocumentHolder * parseXmlBuffer(Span< const Byte > buffer, const String &name)=0
Reads and parses the XML file contained in the buffer buffer.
Interface of an entity family.
Definition IItemFamily.h:83
virtual String name() const =0
Family name.
virtual IVariable * findVariable(const String &name, bool throw_exception=false)=0
Searches for the variable name name associated with this family.
virtual Int64 timestamp()=0
Counter indicating the time of the last mesh modification.
Interface of the parallelism manager for a subdomain.
virtual void broadcastMemoryBuffer(ByteArray &bytes, Int32 rank)=0
Performs a broadcast of a memory region.
virtual void allGatherVariable(ConstArrayView< char > send_buf, Array< char > &recv_buf)=0
Performs an all-gather operation across all processors.
virtual bool isMasterIO() const =0
true if the instance is a master I/O manager.
virtual Integer masterIORank() const =0
Rank of the instance managing I/O (for which isMasterIO() is true).
virtual IMesh * defaultMesh()=0
Default mesh.
Brief reading of variables during calculation.
Interface of a variable.
Definition IVariable.h:40
virtual eDataType dataType() const =0
Data type managed by the variable (Real, Integer, ...).
virtual String itemFamilyName() const =0
Name of the associated family (null if none).
virtual String fullName() const =0
Full variable name (with family prefix).
@ PNoRestore
Indicates that the variable should not be restored.
Definition IVariable.h:120
@ PNoDump
Indicates that the variable should not be saved.
Definition IVariable.h:62
virtual eItemKind itemKind() const =0
Kind of mesh entities on which the variable is based.
virtual IData * data()=0
Data associated with the variable.
virtual ItemGroup itemGroup() const =0
Associated mesh group.
virtual IItemFamily * itemFamily() const =0
Associated entity family.
virtual String itemGroupName() const =0
Name of the associated entity group.
virtual MeshHandle meshHandle() const =0
Mesh associated with the variable.
virtual String name() const =0
Variable name.
Mesh entity group.
Definition ItemGroup.h:51
const String & fullName() const
Group name.
Definition ItemGroup.h:87
eItemKind itemKind() const
Group kind. This is the kind of its elements.
Definition ItemGroup.h:114
IMesh * mesh() const
Mesh to which this group belongs (0 for the null group).
Definition ItemGroup.h:131
Unique identifier of an entity.
Mesh element based on nodes (Edge,Face,Cell).
Definition Item.h:773
Int32 nbNode() const
Number of nodes of the entity.
Definition Item.h:837
NodeLocalIdView nodeIds() const
List of nodes of the entity.
Definition Item.h:846
ItemWithNodes toItemWithNodes() const
Converts the entity to the ItemWithNodes kind.
Definition Item.h:1802
constexpr bool isOwn() const
true if the entity belongs to the subdomain
Definition Item.h:267
Node toNode() const
Converts the entity to the Node kind.
Definition Item.h:1809
Reading variables in HDF5 format.
virtual void updateVariables(Real wanted_time)
Updates the variables for the time wanted_time.
virtual void setBaseFileName(const String &path)
Sets the name of the file containing the data.
virtual void setBaseDirectoryName(const String &path)
Sets the path of the directory containing the data.
virtual void setVariables(VariableCollection vars)
Sets the list of variables that we wish to reread. This call must happen before initialize().
virtual void initialize(bool is_start)
Initializes the reader.
virtual Real2 timeInterval(IVariable *var)
Time interval of values for the variable var. The data for the variable var exists for the times incl...
virtual void build()
Build-level construction of the service.
IMesh * mesh() const
Associated mesh.
Node of a mesh.
Definition Item.h:598
Reading variables in HDF5 format via an XML descriptor.
virtual void build()
Build-level construction of the service.
virtual void setBaseDirectoryName(const String &path)
Sets the path of the directory containing the data.
virtual void setVariables(VariableCollection vars)
Sets the list of variables that we wish to reread. This call must happen before initialize().
virtual void updateVariables(Real wanted_time)
Updates the variables for the time wanted_time.
virtual void setBaseFileName(const String &path)
Sets the name of the file containing the data.
virtual void initialize(bool is_start)
Initializes the reader.
virtual Real2 timeInterval(IVariable *var)
Time interval of values for the variable var. The data for the variable var exists for the times incl...
Class managing a 2-dimensional real vector.
Definition Real2.h:122
Class managing a 3-dimensional real vector.
Definition Real3.h:132
Reference to an instance.
Encapsulation of an automatically destructing pointer.
Definition ScopedPtr.h:44
Structure containing the information to create a service.
Service creation properties.
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.
TraceMessage warning() const
Flow for a warning message.
ITraceMng * traceMng() const
Trace manager.
TraceMessage pwarning() const
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.
IVariable * variable() const
Associated variable.
String name() const
Variable name.
List of nodes of a DOM tree.
Definition XmlNodeList.h:36
Node of a DOM tree.
Definition XmlNode.h:51
XmlNode attr(const String &name, bool throw_exception=false) const
Returns the attribute of name name.
Definition XmlNode.cc:257
String xpathFullName() const
XPath name of the node with its ancestors.
Definition XmlNode.cc:152
XmlNode documentElement() const
Returns the document element.
Definition XmlNode.cc:565
String attrValue(const String &name, bool throw_exception=false) const
Value of attribute name.
Definition XmlNode.cc:234
Real valueAsReal(bool throw_exception=false) const
Node value converted to real number. If conversion fails, if throw_exception is false returns 0....
Definition XmlNode.cc:473
XmlNodeList children(const String &name) const
Set of child nodes of this node having the name name.
Definition XmlNode.cc:102
void add(ConstReferenceType val)
Adds element val to the end of the array.
#define ARCANE_REGISTER_SERVICE(aclass, a_service_property,...)
Macro for registering a service.
MeshVariableScalarRefT< Cell, Real > VariableCellReal
Real type quantity at cell center.
VariableRefArrayT< Int64 > VariableArrayInt64
Array variable of 64-bit integer type.
ItemVariableScalarRefT< Real > VariableItemReal
Real type quantity.
MeshVariableScalarRefT< Node, Real3 > VariableNodeReal3
Coordinate type quantity at node.
Utility functions for Hdf5.
Definition Hdf5Utils.cc:34
constexpr __host__ __device__ bool isEqual(const _Type &a, const _Type &b)
Tests the bit-by-bit equality between two values.
Definition Numeric.h:260
String getEnvironmentVariable(const String &name)
Environment variable named name.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Integer arcaneCheckArraySize(unsigned long long size)
Checks that size can be converted into an 'Integer' to serve as the size of an array....
ConstArrayView< Real3 > Real3ConstArrayView
C equivalent of a 1D array of Real3.
Definition UtilsTypes.h:496
UniqueArray< Int64 > Int64UniqueArray
Dynamic 1D array of 64-bit integers.
Definition UtilsTypes.h:339
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
UniqueArray< Real3 > Real3UniqueArray
Dynamic 1D array of rank 3 vectors.
Definition UtilsTypes.h:363
ArrayView< Integer > IntegerArrayView
C equivalent of a 1D array of integers.
Definition UtilsTypes.h:457
@ ST_SubDomain
The service is used at the subdomain level.
ConstArrayView< Int64 > Int64ConstArrayView
C equivalent of a 1D array of 64-bit integers.
Definition UtilsTypes.h:480
UniqueArray< Byte > ByteUniqueArray
Dynamic 1D array of characters.
Definition UtilsTypes.h:335
UniqueArray< Int32 > Int32UniqueArray
Dynamic 1D array of 32-bit integers.
Definition UtilsTypes.h:341
UniqueArray< Real > RealUniqueArray
Dynamic 1D array of reals.
Definition UtilsTypes.h:349
double Real
Type representing a real number.
Array< Real > RealArray
Dynamic one-dimensional array of reals.
Definition UtilsTypes.h:135
@ DT_Real3
Vector 3 data type.
Definition DataTypes.h:49
@ DT_Real
Real data type.
Definition DataTypes.h:43
ArrayView< Real > RealArrayView
C equivalent of a 1D array of reals.
Definition UtilsTypes.h:459
std::int32_t Int32
Signed integer type of 32 bits.