Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
IMeshMaterialVariable.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/* IMeshMaterialVariable.cc (C) 2000-2025 */
9/* */
10/* Material variable interface. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/core/materials/IMeshMaterialVariable.h"
15
16#include "arcane/utils/FatalErrorException.h"
17
18#include "arcane/core/materials/IScalarMeshMaterialVariable.h"
19#include "arcane/core/materials/IArrayMeshMaterialVariable.h"
20#include "arcane/core/materials/MaterialVariableTypeInfo.h"
21#include "arcane/core/materials/MaterialVariableBuildInfo.h"
22#include "arcane/core/materials/IMeshMaterialMng.h"
23#include "arcane/core/materials/IMeshMaterialVariableFactoryMng.h"
24
25#include "arcane/core/VariableDataTypeTraits.h"
26#include "arcane/core/IVariable.h"
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31namespace Arcane::Materials
32{
33
34/*---------------------------------------------------------------------------*/
35/*---------------------------------------------------------------------------*/
36
37template <typename TrueType> MaterialVariableTypeInfo
40{
41 using ItemType = typename TrueType::ItemTypeType;
42 using DataType = typename TrueType::DataTypeType;
43 int dim = TrueType::dimension();
45 eDataType dt = VariableDataTypeTraitsT<DataType>::type();
46 return MaterialVariableTypeInfo(ik, dt, dim, space);
47}
48
49/*---------------------------------------------------------------------------*/
50/*---------------------------------------------------------------------------*/
51
58template <typename TrueType> TrueType*
61{
62 MaterialVariableTypeInfo x = _buildVarTypeInfo(mvs);
63
64 MeshHandle mesh_handle = v.meshHandle();
65 if (mesh_handle.isNull())
66 ARCANE_FATAL("No mesh handle for material variable");
67
68 // If the material manager does not yet exist, we create it.
69 IMeshMaterialMng* mat_mng = v.materialMng();
70 // TODO: check if a lock is necessary
71 if (!mat_mng)
72 mat_mng = IMeshMaterialMng::getReference(mesh_handle, true);
73
76
77 auto* true_var = dynamic_cast<TrueType*>(var);
78 ARCANE_CHECK_POINTER(true_var);
79 return true_var;
80}
81
82/*---------------------------------------------------------------------------*/
83/*---------------------------------------------------------------------------*/
84
91template <typename TrueType> TrueType*
94{
96 auto* true_var = dynamic_cast<TrueType*>(var);
97 if (!true_var)
98 ARCANE_FATAL("Can not convert variable '{0}' in the template type of this class", var->globalVariable()->fullName());
99 return true_var;
100}
101
102/*---------------------------------------------------------------------------*/
103/*---------------------------------------------------------------------------*/
104
105#define ARCANE_INSTANTIATE_MAT(type) \
106 template class ARCANE_TEMPLATE_EXPORT MeshMaterialVariableBuildTraits<IScalarMeshMaterialVariable<Cell, type>>; \
107 template class ARCANE_TEMPLATE_EXPORT MeshMaterialVariableBuildTraits<IArrayMeshMaterialVariable<Cell, type>>
108
109ARCANE_INSTANTIATE_MAT(Byte);
110ARCANE_INSTANTIATE_MAT(Int8);
111ARCANE_INSTANTIATE_MAT(Int16);
112ARCANE_INSTANTIATE_MAT(Int32);
113ARCANE_INSTANTIATE_MAT(Int64);
114ARCANE_INSTANTIATE_MAT(BFloat16);
115ARCANE_INSTANTIATE_MAT(Float16);
116ARCANE_INSTANTIATE_MAT(Float32);
117ARCANE_INSTANTIATE_MAT(Real);
118ARCANE_INSTANTIATE_MAT(Real2);
119ARCANE_INSTANTIATE_MAT(Real3);
120ARCANE_INSTANTIATE_MAT(Real2x2);
121ARCANE_INSTANTIATE_MAT(Real3x3);
122
123/*---------------------------------------------------------------------------*/
124/*---------------------------------------------------------------------------*/
125
126} // End namespace Arcane::Materials
127
128/*---------------------------------------------------------------------------*/
129/*---------------------------------------------------------------------------*/
#define ARCANE_CHECK_POINTER(ptr)
Macro returning the pointer ptr if it is not null or throwing an exception if it is null.
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Half-precision floating-point type.
virtual String fullName() const =0
Full variable name (with family prefix).
static eItemKind kind()
Entity kind.
Definition ItemTypes.h:629
Interface for the material and environment manager of a mesh.
virtual IMeshMaterialVariableFactoryMng * variableFactoryMng() const =0
Interface of the variable factory.
static IMeshMaterialMng * getReference(const MeshHandleOrMesh &mesh_handle, bool create=true)
Retrieves or creates the reference associated with mesh.
Interface of the material variable factory manager.
virtual IMeshMaterialVariable * createVariable(const String &storage_type, const MaterialVariableBuildInfo &build_info)=0
Creates a material variable.
Interface of a material variable on a mesh.
virtual IVariable * globalVariable() const =0
Associated global variable on the mesh.
Information characterizing the type of a material variable.
String fullName() const
Full name of the variable type.
Class for managing the creation of the concrete type of the material variable.
static TrueType * getVariableReference(const MaterialVariableBuildInfo &v, MatVarSpace mvs)
Returns a variable associated with a constituent.
Handle on a mesh.
Definition MeshHandle.h:48
bool isNull() const
Indicates if the handle is null (it does not reference any existing mesh or not).
Definition MeshHandle.h:163
Class managing a 2-dimensional real vector.
Definition Real2.h:122
Class managing a 2x2 matrix of reals.
Definition Real2x2.h:55
Class managing a 3-dimensional real vector.
Definition Real3.h:132
Class managing a 3x3 real matrix.
Definition Real3x3.h:67
Always enables tracing in Arcane parts concerning materials.
MatVarSpace
Definition space for a material variable.
std::int8_t Int8
Signed integer type of 8 bits.
std::int64_t Int64
Signed integer type of 64 bits.
eItemKind
Mesh entity type.
std::int16_t Int16
Signed integer type of 16 bits.
double Real
Type representing a real number.
unsigned char Byte
Type of a byte.
Definition BaseTypes.h:43
float Float32
IEEE-753 single-precision floating-point type.
eDataType
Data type.
Definition DataTypes.h:41
std::int32_t Int32
Signed integer type of 32 bits.
Structure equivalent to the boolean value true.