Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
VariableInfo.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/* VariableInfo.cc (C) 2000-2024 */
9/* */
10/* Information characterizing a variable. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/core/VariableInfo.h"
15
16#include "arcane/utils/FatalErrorException.h"
17#include "arcane/utils/StringBuilder.h"
18
19#include "arcane/core/datatype/DataTypeTraits.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane
25{
26
27DataStorageTypeInfo VariableInfo::
28_internalGetStorageTypeInfo(eDataType data_type, Integer dimension, Integer multi_tag)
29{
30 Integer nb_basic = -1;
32 switch (data_type) {
33 case DT_Byte:
35 basic_data_type = DataTypeTraitsT<Byte>::basicDataType();
36 break;
37 case DT_Int8:
39 basic_data_type = DataTypeTraitsT<Int8>::basicDataType();
40 break;
41 case DT_Int16:
43 basic_data_type = DataTypeTraitsT<Int16>::basicDataType();
44 break;
45 case DT_Int32:
47 basic_data_type = DataTypeTraitsT<Int32>::basicDataType();
48 break;
49 case DT_Int64:
51 basic_data_type = DataTypeTraitsT<Int64>::basicDataType();
52 break;
53 case DT_Real:
55 basic_data_type = DataTypeTraitsT<Real>::basicDataType();
56 break;
57 case DT_Float32:
60 break;
61 case DT_Float16:
64 break;
65 case DT_BFloat16:
68 break;
69 case DT_Real2:
71 basic_data_type = DataTypeTraitsT<Real2>::basicDataType();
72 break;
73 case DT_Real3:
75 basic_data_type = DataTypeTraitsT<Real3>::basicDataType();
76 break;
77 case DT_Real2x2:
80 break;
81 case DT_Real3x3:
84 break;
85 case DT_String:
86 // For strings, the container contains
87 // 'Byte' and the dimension is 1 greater than that
88 // of the variable.
89 nb_basic = 0;
90 multi_tag = 1;
91 dimension += 1;
92 basic_data_type = eBasicDataType::Byte;
93 break;
94 case DT_Unknown:
95 break;
96 }
97 return DataStorageTypeInfo(basic_data_type, nb_basic, dimension, multi_tag);
98}
99
100/*---------------------------------------------------------------------------*/
101/*---------------------------------------------------------------------------*/
102
103VariableInfo::
104VariableInfo(const String& local_name, const String& item_family_name,
105 const String& item_group_name,
106 const String& mesh_name, eItemKind item_kind,
107 Integer dimension, Integer multi_tag, eDataType data_type)
108: VariableInfo(local_name, item_family_name, item_group_name, mesh_name,
109 VariableTypeInfo(item_kind, data_type, dimension, multi_tag, !item_group_name.null()),
110 _internalGetStorageTypeInfo(data_type, dimension, multi_tag))
111{
112}
113
114/*---------------------------------------------------------------------------*/
115/*---------------------------------------------------------------------------*/
116
117VariableInfo::
118VariableInfo(const String& local_name, const String& item_family_name,
119 const String& item_group_name,
120 const String& mesh_name,
121 const VariableTypeInfo& var_type_info,
122 const DataStorageTypeInfo& storage_info)
123: m_local_name(local_name)
124, m_item_family_name(item_family_name)
125, m_item_group_name(item_group_name)
126, m_mesh_name(mesh_name)
127, m_variable_type_info(var_type_info)
128, m_storage_type_info(storage_info)
129{
130 if (m_item_family_name.null())
131 m_item_family_name = _defaultFamilyName();
132 // m_item_group_name can be null here. In this case,
133 // it will be initialized later via
134 // setDefaultItemGroupName(). It should not be done
135 // here because updating the name entails memory allocations/deallocations
136 // and this constructor might be called often when searching
137 // for variables.
138}
139
140/*---------------------------------------------------------------------------*/
141/*---------------------------------------------------------------------------*/
142
143String VariableInfo::
144_defaultFamilyName()
145{
146 String family_name;
147 switch (itemKind()) {
148 case IK_Particle:
149 ARCANE_FATAL("No default family for 'particle' variable '{0}'", m_local_name);
150 case IK_DoF:
151 ARCANE_FATAL("No default family for 'dof' variable '{0}'", m_local_name);
152 case IK_Node:
153 family_name = ItemTraitsT<Node>::defaultFamilyName();
154 break;
155 case IK_Edge:
156 family_name = ItemTraitsT<Edge>::defaultFamilyName();
157 break;
158 case IK_Face:
159 family_name = ItemTraitsT<Face>::defaultFamilyName();
160 break;
161 case IK_Cell:
162 family_name = ItemTraitsT<Cell>::defaultFamilyName();
163 break;
164 case IK_Unknown:
165 break;
166 }
167 return family_name;
168}
169
170/*---------------------------------------------------------------------------*/
171/*---------------------------------------------------------------------------*/
172
180void VariableInfo::
181_computeFullName() const
182{
183 StringBuilder full_name;
184 if (m_mesh_name.null()) {
185 full_name = String();
186 }
187 else {
188 full_name = m_mesh_name;
189 full_name += "_";
190 }
191
192 if (m_item_family_name.null()) {
193 full_name += m_local_name;
194 }
195 else {
196 full_name += m_item_family_name;
197 full_name += "_";
198 full_name += m_local_name;
199 }
200 m_full_name = full_name.toString();
201}
202
203/*---------------------------------------------------------------------------*/
204/*---------------------------------------------------------------------------*/
205
206void VariableInfo::
207setDefaultItemGroupName()
208{
209 if (!m_item_group_name.null())
210 return;
211 // The name constructed here must be consistent with that in DynamicMeshKindInfos.cc
213}
214
215/*---------------------------------------------------------------------------*/
216/*---------------------------------------------------------------------------*/
217
218} // End namespace Arcane
219
220/*---------------------------------------------------------------------------*/
221/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Type information for a data container.
static constexpr eBasicDataType basicDataType()
Base data type.
static constexpr int nbBasicType()
Number of elements of the base type.
static constexpr eBasicDataType basicDataType()
Base data type.
static constexpr int nbBasicType()
Number of elements of the base type.
static constexpr int nbBasicType()
Number of elements of the base type.
static constexpr eBasicDataType basicDataType()
Base data type.
static constexpr eBasicDataType basicDataType()
Base data type.
static constexpr int nbBasicType()
Number of elements of the base type.
static constexpr eBasicDataType basicDataType()
Base data type.
static constexpr int nbBasicType()
Number of elements of the base type.
static constexpr eBasicDataType basicDataType()
Base data type.
static constexpr int nbBasicType()
Number of base type elements.
static constexpr eBasicDataType basicDataType()
Base data type.
static constexpr int nbBasicType()
Number of base type elements.
static constexpr eBasicDataType basicDataType()
Base data type.
static constexpr int nbBasicType()
Number of elements of the base type.
static constexpr eBasicDataType basicDataType()
Base data type.
static constexpr int nbBasicType()
Number of base type elements.
static constexpr int nbBasicType()
Number of base type elements.
static constexpr eBasicDataType basicDataType()
Base data type.
static constexpr eBasicDataType basicDataType()
Base data type.
static constexpr int nbBasicType()
Number of base type elements.
static constexpr int nbBasicType()
Number of base type elements.
static constexpr eBasicDataType basicDataType()
Base data type.
static constexpr int nbBasicType()
Number of elements of the base type.
static constexpr eBasicDataType basicDataType()
Base data type.
Unicode character string constructor.
String toString() const
Returns the constructed character string.
Information characterizing a variable.
String m_item_group_name
Name of the entity group to which the variable is associated.
String m_full_name
Full name of the variable (associated with the family).
Integer dimension() const
Dimension.
String m_local_name
Name of the variable.
String m_mesh_name
Name of the mesh to which the variable is associated.
String m_item_family_name
Name of the entity family to which the variable is associated.
Information characterizing the type of a variable.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
eBasicDataType
Type of a basic data item.
@ Unknown
Unknown or uninitialized data type.
eItemKind
Mesh entity type.
@ IK_Particle
Particle mesh entity.
@ IK_Node
Node mesh entity.
@ IK_Cell
Cell mesh entity.
@ IK_Unknown
Unknown or uninitialized mesh entity.
@ IK_Face
Face mesh entity.
@ IK_DoF
Degree of Freedom mesh entity.
@ IK_Edge
Edge mesh entity.
eDataType
Data type.
Definition DataTypes.h:41
@ DT_Float32
'Float32' data type
Definition DataTypes.h:54
@ DT_Real2x2
2x2 tensor data type
Definition DataTypes.h:50
@ DT_Int16
16-bit integer data type
Definition DataTypes.h:44
@ DT_Int8
8-bit integer data type
Definition DataTypes.h:55
@ DT_Real3x3
3x3 tensor data type
Definition DataTypes.h:51
@ DT_Int32
32-bit integer data type
Definition DataTypes.h:45
@ DT_Real3
Vector 3 data type.
Definition DataTypes.h:49
@ DT_Float16
'Float16' data type
Definition DataTypes.h:53
@ DT_Int64
64-bit integer data type
Definition DataTypes.h:46
@ DT_Unknown
Unknown or uninitialized data type.
Definition DataTypes.h:58
@ DT_String
UTF-8 character string data type.
Definition DataTypes.h:47
@ DT_BFloat16
'BFloat16' data type
Definition DataTypes.h:52
@ DT_Real2
Vector 2 data type.
Definition DataTypes.h:48
@ DT_Real
Real data type.
Definition DataTypes.h:43
@ DT_Byte
Byte data type.
Definition DataTypes.h:42