14#include "arcane/utils/ITraceMng.h"
15#include "arcane/utils/StringBuilder.h"
16#include "arcane/utils/HashTableMap.h"
17#include "arcane/utils/NotImplementedException.h"
18#include "arcane/utils/NotSupportedException.h"
19#include "arcane/utils/ArgumentException.h"
21#include "arcane/hdf5/Hdf5VariableInfoBase.h"
23#include "arcane/core/MeshVariable.h"
24#include "arcane/core/IItemFamily.h"
25#include "arcane/core/IMesh.h"
26#include "arcane/core/IMeshSubMeshTransition.h"
27#include "arcane/core/IVariable.h"
28#include "arcane/core/IVariableMng.h"
29#include "arcane/core/IParallelMng.h"
42template <
typename VariableType,
typename DataType>
43class Hdf5ItemVariableInfo
44:
public Hdf5VariableInfoBase
52 VariableType& trueVariable() {
return m_variable; }
53 virtual IVariable* variable()
const {
return m_variable.variable(); }
69 VariableType m_variable;
75template <
typename VariableType,
typename DataType>
76class Hdf5ScalarVariableInfo
77:
public Hdf5VariableInfoBase
85 VariableType& trueVariable() {
return m_variable; }
86 virtual IVariable* variable()
const {
return m_variable.variable(); }
103 VariableType m_variable;
114 return Hdf5VariableInfoBase::create(var);
120Hdf5VariableInfoBase* Hdf5VariableInfoBase::
123 _checkValidVariable(var);
124 Hdf5VariableInfoBase* var_info = 0;
226 String::format(
"IData for variable '{0}'", var->
fullName()));
233void Hdf5VariableInfoBase::
246 ARCANE_FATAL(
"Bad variable '{0}'. Variable has to be an item variable and have dimension"
247 "'1' or be a scalar variable",
272 unique_ids[index] = (*iitem).uniqueId();
277 if (save_type & SAVE_IDS) {
279 ids_writer.parallelWrite(pm, st, unique_ids, unique_ids);
290 if (save_type & SAVE_COORDS) {
299 const Real nan_value = std::numeric_limits<Real>::quiet_NaN();
300 const Real3 real3_nan =
Real3(nan_value, nan_value, nan_value);
302 ENUMERATE_ITEMWITHNODES(iitem, enumerate_group)
306 if (nb_node > max_nb_node)
307 max_nb_node = nb_node;
312 ENUMERATE_ITEMWITHNODES(iitem, enumerate_group)
317 for (NodeLocalId inode : item.
nodeIds()) {
318 coords.
add(nodes_coords[inode]);
319 item_center += nodes_coords[inode];
321 item_center /= nb_node;
323 for (
Integer k = nb_node; k < max_nb_node; ++k)
324 coords.
add(real3_nan);
325 centers.
add(item_center);
330 coords_writer.parallelWrite(pm, st, coords, unique_ids);
332 centers_writer.parallelWrite(pm, st, centers, unique_ids);
334 types_writer.parallelWrite(pm, st, items_type, unique_ids);
336 else if (item_kind ==
IK_Node) {
339 coords.
add(nodes_coords[iitem]);
342 coords_writer.parallelWrite(pm, st, coords, unique_ids);
345 tm->
pwarning() <<
"Can not save coordinates for family name="
353void Hdf5VariableInfoBase::
370 ids_reader.readDim();
372 tm->
info() <<
"NB_OLD_ITEM nb=" << nb_old_item;
373 saved_unique_ids.
resize(nb_old_item);
374 dummy_uids.
resize(nb_old_item);
376 ids_reader.parallelRead(pm, st, saved_unique_ids, dummy_uids);
379 Hdf5Utils::StandardArrayT<Real3> centers_reader(hfile.id(), hdf_path +
"_Center");
381 centers_reader.readDim();
382 centers_reader.parallelRead(pm, st, saved_centers, dummy_uids);
383 tm->
info() <<
"READ SAVED CENTERS nb=" << saved_centers.size();
385 uids.
copy(saved_unique_ids);
386 centers.
copy(saved_centers);
395template <
typename VariableType,
typename DataType>
407template <
typename VariableType,
typename DataType>
void
412 ARCANE_UNUSED(ids_hpath);
415 var_data = variable()->data();
421 const char* n =
typeid(var_data).name();
433 hfile.openRead(filename);
437 _readStandardArray(buffer, unique_ids, ids_hpath, hfile.id(), st);
439 Integer buf_size = buffer.size();
441 Integer nb_var_value = var_value.size();
442 if (var->isPartial()) {
448 for (
Integer z = 0; z < buf_size; ++z) {
449 values_from_uid.add(unique_ids[z], buffer[z]);
451 ItemGroup var_group = m_variable.itemGroup();
454 Int64 uid = item.uniqueId();
455 if (m_correspondance_functor) {
456 uid = m_correspondance_functor->getOldUniqueId(uid, iitem.index());
461 String::format(
"Can not find item uid='{0}' reading variable '{1}'",
462 uid, var->fullName()));
463 DataType value = data->value();
464 var_value[iitem.index()] = value;
469 var->itemFamily()->itemsUniqueIdToLocalId(local_ids, unique_ids,
false);
470 for (
Integer z = 0; z < buf_size; ++z) {
472 if (lid == NULL_ITEM_LOCAL_ID)
474 if (lid > nb_var_value)
475 throw FatalErrorException(A_FUNCINFO, String::format(
"Bad item index '{0}' max={1}", lid, nb_var_value));
476 var_value[lid] = buffer[z];
479 tm->info(4) <<
"End of read for variable '" << var->fullName() <<
"'";
485template <
typename VariableType,
typename DataType>
void
488 const String& ids_hpath, hid_t file_id,
491 ARCANE_UNUSED(ids_hpath);
502 if (!ids_hpath.null())
503 values.setIdsPath(ids_hpath);
508 tm->fatal() <<
"Only one-dimension array are allowed "
509 <<
" dim=" << nb_dim <<
" var_name=" << var->fullName() <<
" path=" << path();
511 tm->info(4) <<
"NB_ITEM: nb_item=" << nb_item;
512 buffer.resize(nb_item);
513 unique_ids.resize(nb_item);
515 values.parallelRead(pm, st, buffer, unique_ids);
519 Integer nb_item = buffer.size();
520 for(
Integer i=0; i<nb_item; ++i ){
522 tm->info() <<
" VAR_VAL i=" << i <<
" value=" << buffer[i] <<
" uid=" << unique_ids[i];
533template <
typename VariableType,
typename DataType>
void
540 values.write(st, buffer);
546template <
typename VariableType,
typename DataType>
void
555 ItemGroup group = m_variable.itemGroup();
558 enumerate_group = group;
564 tm->
info(4) <<
"WRITE VARIABLE name=" << m_variable.name()
565 <<
" is_partial=" << m_variable.variable()->isPartial();
570 if (iitem->isOwn()) {
571 values[index] = m_variable[iitem];
572 unique_ids[index] = iitem->uniqueId();
586 values_writer.parallelWrite(pm, st, values, unique_ids);
596template <
typename VariableType,
typename DataType>
607template <
typename VariableType,
typename DataType>
void
608Hdf5ScalarVariableInfo<VariableType, DataType>::
609readVariable(Hdf5Utils::HFile& hfile,
const String& filename,
610 Hdf5Utils::StandardTypes& st,
const String& ids_hpath, IData* data)
612 ARCANE_UNUSED(ids_hpath);
614 UniqueArray<DataType> buffer;
615 IVariable* var = m_variable.variable();
616 IVariableMng* vm = var->variableMng();
617 ITraceMng* tm = vm->traceMng();
618 IParallelMng* pm = vm->parallelMng();
619 bool is_master = pm->isMasterIO();
623 hfile.openRead(filename);
627 _readStandardArray(buffer, hfile.id(), st);
629 Integer buf_size = buffer.size();
631 data = m_variable.variable()->data();
636 for (
Integer z = 0; z < buf_size; ++z)
637 var_value[z] = buffer[z];
638 tm->info(4) <<
"End of read for variable '" << var->fullName() <<
"'";
644template <
typename VariableType,
typename DataType>
void
661 tm->fatal() <<
"Only one-dimension array are allowed "
662 <<
" dim=" << nb_dim <<
" var_name=" << var->fullName() <<
" path=" << path();
664 tm->info(4) <<
"NB_ITEM: nb_item=" << nb_item;
665 buffer.resize(nb_item);
667 values.read(st, buffer);
671 Integer nb_item = buffer.size();
672 for(
Integer i=0; i<nb_item; ++i ){
674 tm->info() <<
" VAR_VAL i=" << i <<
" value=" << buffer[i];
685template <
typename VariableType,
typename DataType>
void
690 values.write(st, buffer);
696template <
typename VariableType,
typename DataType>
void
704 bool is_master = pm->isMasterIO();
707 Integer size = var_values.size();
709 for (
Integer i = 0; i < size; ++i)
710 values[i] = var_values[i];
719 tm->info(4) <<
"WRITE SCALAR VARIABLE name=" << m_variable.variable()->fullName();
720 values_writer.write(st, values);
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Exception when an argument is invalid.
Modifiable view of an array of type T.
Base class for 1D data vectors.
void resize(Int64 s)
Changes the number of elements in the array to s.
void copy(Span< const T > rhs)
Copies the values from rhs into the instance.
void add(ConstReferenceType val)
Adds element val to the end of the array.
Constant view of an array of type T.
Exception when a fatal error has occurred.
Hash table for associative arrays.
virtual void writeVariable(Hdf5Utils::HFile &hfile, Hdf5Utils::StandardTypes &st)
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 writeGroup(Hdf5Utils::HFile &hfile, Hdf5Utils::StandardTypes &st, const String &hdf_path, Integer save_type)
const String & path() const
Path in the Hdf5 file containing the variable value.
Interface of a 1D array data item of type T.
Interface of a data item.
Interface of an entity family.
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 IMesh * mesh() const =0
Associated mesh.
virtual IParallelMng * parallelMng()=0
Parallelism manager.
Interface of the parallelism manager for a subdomain.
virtual ITraceMng * traceMng() const =0
Trace manager.
virtual bool isMasterIO() const =0
true if the instance is a master I/O manager.
virtual char reduce(eReduceType rt, char v)=0
Performs a reduction of type rt on the real v and returns the value.
virtual TraceMessage pwarning()=0
Stream for a parallel warning message.
virtual TraceMessage info()=0
Stream for an information message.
Variable manager interface.
virtual IParallelMng * parallelMng() const =0
Associated parallelism manager.
virtual ITraceMng * traceMng()=0
Message manager.
virtual eDataType dataType() const =0
Data type managed by the variable (Real, Integer, ...).
virtual String fullName() const =0
Full variable name (with family prefix).
virtual bool isPartial() const =0
Indicates if the variable is partial.
virtual Integer dimension() const =0
Dimension of the variable.
virtual ItemGroup itemGroup() const =0
Associated mesh group.
virtual IItemFamily * itemFamily() const =0
Associated entity family.
virtual IVariableMng * variableMng() const =0
Variable manager associated with the variable.
Integer size() const
Number of elements in the group.
IItemFamily * itemFamily() const
Entity family to which this group belongs (0 for the null group).
eItemKind itemKind() const
Group kind. This is the kind of its elements.
IMesh * mesh() const
Mesh to which this group belongs (0 for the null group).
ItemGroup own() const
Group equivalent to this one but containing only the local elements of the subdomain.
Int16 typeId() const
Type number.
Mesh element based on nodes (Edge,Face,Cell).
Int32 nbNode() const
Number of nodes of the entity.
NodeLocalIdView nodeIds() const
List of nodes of the entity.
Base class for a mesh element.
const ItemTypeInfo * typeInfo() const
Information about the entity type.
ItemWithNodes toItemWithNodes() const
Converts the entity to the ItemWithNodes kind.
Exception when an operation is not supported.
Class managing a 3-dimensional real vector.
Unicode character string.
1D data vector with value semantics (STL style).
MeshVariableScalarRefT< Node, Real3 > VariableNodeReal3
Coordinate type quantity at node.
@ ReduceMax
Maximum of values.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Array< Int64 > Int64Array
Dynamic one-dimensional array of 64-bit integers.
Integer arcaneCheckArraySize(unsigned long long size)
Checks that size can be converted into an 'Integer' to serve as the size of an array....
UniqueArray< Int64 > Int64UniqueArray
Dynamic 1D array of 64-bit integers.
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.
ConstArrayView< Int64 > Int64ConstArrayView
C equivalent of a 1D array of 64-bit integers.
UniqueArray< Int32 > Int32UniqueArray
Dynamic 1D array of 32-bit integers.
eItemKind
Mesh entity type.
@ IK_Node
Node mesh entity.
@ IK_Cell
Cell mesh entity.
@ IK_Face
Face mesh entity.
@ IK_Edge
Edge mesh entity.
double Real
Type representing a real number.
@ DT_Real2x2
2x2 tensor data type
@ DT_Real3x3
3x3 tensor data type
@ DT_Int32
32-bit integer data type
@ DT_Real3
Vector 3 data type.
@ DT_Int64
64-bit integer data type
@ DT_Real2
Vector 2 data type.
Array< Real3 > Real3Array
Dynamic one-dimensional array of rank 3 vectors.