Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ItemMaterialVariableBaseT.H
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/* ItemMaterialVariableBaseT.h (C) 2000-2024 */
9/* */
10/* Implementation of the base class for material variables. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/Mutex.h"
15#include "arcane/utils/ArgumentException.h"
16#include "arcane/utils/FatalErrorException.h"
18
19#include "arcane/core/Observer.h"
20#include "arcane/core/IMesh.h"
21#include "arcane/core/IVariable.h"
22#include "arcane/core/IItemFamily.h"
23#include "arcane/core/VariableInfo.h"
24#include "arcane/core/internal/IDataInternal.h"
25#include "arcane/core/materials/MaterialVariableBuildInfo.h"
26#include "arcane/core/materials/IMeshMaterialMng.h"
27#include "arcane/core/materials/IMeshMaterialVariableFactoryMng.h"
28#include "arcane/core/materials/internal/IMeshMaterialMngInternal.h"
29
30#include "arcane/materials/MeshMaterialVariableRef.h"
31#include "arcane/materials/internal/ComponentItemListBuilder.h"
32#include "arcane/materials/internal/MeshMaterialVariablePrivate.h"
33#include "arcane/materials/internal/MeshMaterialVariableIndexer.h"
34
35#include "arcane/accelerator/core/RunQueue.h"
36#include "arcane/accelerator/core/Memory.h"
37#include "arcane/accelerator/RunCommandLoop.h"
38
39/*---------------------------------------------------------------------------*/
40/*---------------------------------------------------------------------------*/
41
42namespace Arcane::Materials
43{
44
45namespace
46{
47
48 // Allocator used for views
49 // We use accelerator memory if the execution is done on an accelerator
50 MemoryAllocationOptions
51 _getViewAllocator(IMeshMaterialMng* mm)
52 {
53 eMemoryRessource r = eMemoryRessource::Host;
54 if (mm->_internalApi()->runQueue().isAcceleratorPolicy())
55 r = eMemoryRessource::Device;
57 }
58
59} // namespace
60
61/*---------------------------------------------------------------------------*/
62/*---------------------------------------------------------------------------*/
63
64template <typename Traits>
67 PrivatePartType* global_var,
68 VariableRef* global_var_ref, MatVarSpace mvs)
70, m_global_variable(global_var)
71, m_global_variable_ref(global_var_ref)
72, m_device_views(_getViewAllocator(m_p->materialMng()))
73, m_host_views(MemoryUtils::getAllocationOptions(eMemoryRessource::HostPinned))
74{
75 m_device_views.setDebugName(String("ItemMaterialVariableViews") + v.name());
76}
77
78/*---------------------------------------------------------------------------*/
79/*---------------------------------------------------------------------------*/
80
81template <typename Traits>
82ItemMaterialVariableBase<Traits>::
83~ItemMaterialVariableBase()
84{
85 Integer nb_var = m_p->m_refs.size();
86 delete m_global_variable_ref;
87 for (Integer i = 1; i < nb_var; ++i) {
88 delete m_p->m_refs[i];
89 }
90 m_p->m_refs.clear();
91 m_vars.clear();
92}
93
94/*---------------------------------------------------------------------------*/
95/*---------------------------------------------------------------------------*/
96
97template <typename Traits> IVariable*
98ItemMaterialVariableBase<Traits>::
99globalVariable() const
100{
101 return m_global_variable;
102}
103
104/*---------------------------------------------------------------------------*/
105/*---------------------------------------------------------------------------*/
106
107template <typename Traits> void
110{
111 if (!m_vars.empty())
112 ARCANE_FATAL("Internal error: _init() already called");
113 m_vars.addRange(vars);
114 Integer nb_var = m_vars.size();
115 m_device_views.resizeNoInit(nb_var);
116 m_host_views.resize(nb_var);
117 m_views_as_bytes.resize(nb_var);
118 // We must maintain a reference to the variables we possess to
119 // ensure they are properly initialized and will not be destroyed
120 // as long as this instance exists.
121 m_p->m_refs.resize(nb_var);
122 for (Integer i = 0; i < nb_var; ++i) {
123 // m_vars[i] can be null if our variable is a medium-only variable.
124 m_p->m_refs[i] = nullptr;
125 if (i == 0) {
126 // For the global variable, it is a mesh variable.
127 m_p->m_refs[i] = m_global_variable_ref;
128 }
129 else {
130 // For the others, it is an array variable.
131 if (m_vars[i])
132 m_p->m_refs[i] = new VariableRefType(m_vars[i]);
133 }
134 // TODO: we must be able to be notified of this variable's change.
135 // to then update the views (maybe also create a MyVariableRef).
136 _setView(i);
137 //std::cout << "INIT_VIEW: " << i << " v=" << m_views[i].size() << '\n';
138 }
139 _copyHostViewsToViews(nullptr);
140}
141
142/*---------------------------------------------------------------------------*/
143/*---------------------------------------------------------------------------*/
144
145template <typename Traits> void
146ItemMaterialVariableBase<Traits>::
147buildFromManager(bool is_continue)
148{
149 IMeshMaterialMng* mat_mng = m_p->materialMng();
150
151 // We must retrieve (or create) the other variables.
152 //ConstArrayView<IMeshMaterial*> materials = mat_mng->materials();
153 IMeshMaterialMngInternal* mm_api = mat_mng->_internalApi();
154 const Real reserve_ratio = mm_api->additionalCapacityRatio();
156 Integer nb_indexer = indexers.size();
157 UniqueArray<PrivatePartType*> all_vars(nb_indexer + 1);
158 all_vars[0] = m_global_variable;
159 IMesh* mesh = m_global_variable->mesh();
160
161 if (!m_global_variable->isUsed())
162 m_global_variable->setUsed(true);
163
164 // We must attach an observer on the global variable to know when it changes.
165 // For partial variables, this is done automatically when the associated material changes.
166 m_p->m_global_variable_changed_observer = new ObserverT<ThatClass>(this, &ThatClass::_syncFromGlobalVariable);
167 m_global_variable->onSizeChangedObservable()->attachObserver(m_p->m_global_variable_changed_observer);
168
169 m_p->m_modified_times.resize(nb_indexer);
170 m_p->m_modified_times.fill(0);
171
172 bool is_env_only = m_p->space() == MatVarSpace::Environment;
173 //TODO: check if we need to store this variable's properties
174 // before its creation
175 int property = m_global_variable->property();
176 for (Integer i = 0; i < nb_indexer; ++i) {
177 MeshMaterialVariableIndexer* indexer = indexers[i];
178 // Does nothing if we are only a medium variable and the indexer
179 // is not associated with a medium.
180 if (is_env_only && !indexer->isEnvironment()) {
181 all_vars[i + 1] = nullptr;
182 continue;
183 }
184
185 // If a name is specified, it is the compatibility mode
186 // with Troll and in this case the variable is not associated
187 // with the mesh.
188 String var_name = String("Mat") + indexer->name() + "_" + this->name();
189
190 // Note: These variables are not associated with the mesh.
191 // They are just array variables.
192 IVariable* var = nullptr;
193 {
194 VariableBuildInfo vbi2(mesh, var_name, property);
195 VariableInfo vi = VariableRefType::_internalVariableInfo(vbi2);
196 var = PrivatePartType::getReference(vbi2, vi);
197 }
198 // Tag the variable for codes that would want to know that it
199 // is a material variable.
200 var->addTag("Material", "1");
201 PrivatePartType* true_ptr = dynamic_cast<PrivatePartType*>(var);
202 ARCANE_CHECK_POINTER(true_ptr);
203 all_vars[i + 1] = true_ptr;
204 if (!is_continue) {
205 // TODO: check if setUsed() is necessary.
206 true_ptr->setUsed(true);
207 // Resize the variable to the size of the mixed values array.
208 Traits::resizeWithReserve(true_ptr, indexer->maxIndexInMultipleArray(), reserve_ratio);
209 }
210 }
211 this->_init(all_vars);
212}
213
214/*---------------------------------------------------------------------------*/
215/*---------------------------------------------------------------------------*/
216
217template <typename Traits> void
220{
221 // This method is called when the global variable changes its size.
222 // In this case, only the global variable's view must be modified.
223 // But this method can also be called when the global variable's setUsed()
224 // method is called and in this case all views must be updated. Since currently
225 // we cannot distinguish the two
226 // calls, we perform a complete update in all cases.
227 const bool do_complete_sync = true;
228 if (do_complete_sync) {
229 syncReferences();
230 return;
231 }
232
233 // This method is called when the global variable changes its size.
234 // This variable is the first variable in the list.
235 // We must then notify all references of this change.
236 _setView(0);
237 _copyHostViewsToViews(nullptr);
238
239 for (MeshMaterialVariableRef::Enumerator i(this); i.hasNext(); ++i) {
240 MeshMaterialVariableRef* ref = *i;
241 ref->updateFromInternal();
242 }
243}
244
245/*---------------------------------------------------------------------------*/
246/*---------------------------------------------------------------------------*/
247
248template <typename Traits> void
249ItemMaterialVariableBase<Traits>::
250syncReferences()
251{
252 _syncReferences(true);
253}
254
255/*---------------------------------------------------------------------------*/
256/*---------------------------------------------------------------------------*/
257
258template <typename Traits> void
260_syncReferences(bool check_resize)
261{
262 if (check_resize) {
263 IMeshMaterialMngInternal* api = m_p->materialMng()->_internalApi();
265 Real ratio = api->additionalCapacityRatio();
266 Integer nb_indexer = indexers.size();
267 for (Integer i = 0; i < nb_indexer; ++i) {
268 MeshMaterialVariableIndexer* indexer = indexers[i];
269 PrivatePartType* true_ptr = m_vars[i + 1];
270 if (true_ptr) {
271 Traits::resizeWithReserve(true_ptr, indexer->maxIndexInMultipleArray(), ratio);
272 _setView(i + 1);
273 }
274 }
275 _setView(0);
276 _copyHostViewsToViews(nullptr);
277 }
278
279 for (MeshMaterialVariableRef::Enumerator i(this); i.hasNext(); ++i) {
280 MeshMaterialVariableRef* ref = *i;
281 ref->updateFromInternal();
282 }
283}
284
285/*---------------------------------------------------------------------------*/
286/*---------------------------------------------------------------------------*/
287
288template <typename Traits> Ref<IData>
289ItemMaterialVariableBase<Traits>::
290_internalCreateSaveDataRef(Integer nb_value)
291{
292 Ref<IData> data = m_global_variable->data()->cloneEmptyRef();
293 auto* true_data = dynamic_cast<ValueDataType*>(data.get());
294 ARCANE_CHECK_POINTER(true_data);
295 true_data->_internal()->reserve(nb_value);
296 return data;
297}
298
299/*---------------------------------------------------------------------------*/
300/*---------------------------------------------------------------------------*/
301
302template <typename Traits> void
303ItemMaterialVariableBase<Traits>::
304_saveData(IMeshComponent* component, IData* data)
305{
306 if (m_p->space() == MatVarSpace::Environment && !component->isEnvironment())
307 ARCANE_FATAL("Can not save data on material for environment only variable");
308 Traits::saveData(component, data, m_host_views);
309}
310
311/*---------------------------------------------------------------------------*/
312/*---------------------------------------------------------------------------*/
313
314template <typename Traits> void
315ItemMaterialVariableBase<Traits>::
316_restoreData(IMeshComponent* component, IData* data, Integer data_index,
317 Int32ConstArrayView ids, bool allow_null_id)
318{
319 if (m_p->space() == MatVarSpace::Environment && !component->isEnvironment())
320 ARCANE_FATAL("Can not restore data on material for environment only variable");
321
322 auto* true_data = dynamic_cast<ValueDataType*>(data);
323 ARCANE_CHECK_POINTER(true_data);
324 auto values = true_data->view();
325
326 PrivatePartType* global_var = this->_trueGlobalVariable();
327
328 // Array to initialize values either to zero or with
329 // the global variable's value.
330 UniqueContainerType tmp_values;
331 if (component->materialMng()->isDataInitialisationWithZero()) {
332 Integer max_id = m_global_variable->itemFamily()->maxLocalId();
333 Traits::resizeAndFillWithDefault(true_data, tmp_values, max_id);
334 }
335 else
336 tmp_values = global_var->constValueView();
337
338 if (allow_null_id) {
339 for (Integer i = 0, n = ids.size(); i < n; ++i) {
340 if (ids[i] != NULL_ITEM_ID) {
341 Traits::setValue(tmp_values[ids[i]], values[data_index + i]);
342 }
343 }
344 }
345 else {
346 for (Integer i = 0, n = ids.size(); i < n; ++i) {
347 Traits::setValue(tmp_values[ids[i]], values[data_index + i]);
348 }
349 }
350
351 ENUMERATE_COMPONENTCELL (icell, component) {
352 ComponentCell ec = *icell;
353 setValue(ec._varIndex(), tmp_values[ec.globalCell().localId()]);
354 }
355}
356
357/*---------------------------------------------------------------------------*/
358/*---------------------------------------------------------------------------*/
359
360template <typename Traits> bool
361ItemMaterialVariableBase<Traits>::
362_isValidAndUsedAndGlobalUsed(PrivatePartType* partial_var)
363{
364 if (!partial_var)
365 return false;
366 if (!m_global_variable->isUsed() || !partial_var->isUsed())
367 return false;
368 return true;
369}
370
371/*---------------------------------------------------------------------------*/
372/*---------------------------------------------------------------------------*/
373
374template <typename Traits> void
375ItemMaterialVariableBase<Traits>::
376_resizeForIndexer(ResizeVariableIndexerArgs& args)
377{
378 Int32 index = args.m_var_index;
379 RunQueue& queue = args.m_queue;
380 _setView(0);
381 PrivatePartType* partial_var = m_vars[index + 1];
382 if (_isValidAndUsedAndGlobalUsed(partial_var)) {
383 // Resizes the multiple values array if necessary.
384 // TODO: Perform on the device for view update
385 // TODO: Use asynchronous allocation if possible (if no initialization)
386 // TODO: Be able to indicate that we do not want to initialize the variable
387 // regardless of the value of eDataInitialisationPolicy
388 IMeshMaterialMngInternal* api = m_p->materialMng()->_internalApi();
389 ConstArrayView<MeshMaterialVariableIndexer*> indexers = api->variablesIndexer();
390 Real ratio = api->additionalCapacityRatio();
391 Traits::resizeWithReserve(partial_var, indexers[index]->maxIndexInMultipleArray(), ratio);
392 this->_setView(index + 1);
393 }
394 if (args.isUseOneCommand()) {
395 auto dest = asWritableBytes(m_device_views.view());
396 auto source = asBytes(m_host_views.view());
397 args.addOneCopyData(source, dest, 1);
398 }
399 else
400 _copyHostViewsToViews(&queue);
401}
402
403/*---------------------------------------------------------------------------*/
404/*---------------------------------------------------------------------------*/
405
406template <typename Traits> void
407ItemMaterialVariableBase<Traits>::
408_copyHostViewsToViews(RunQueue* queue)
409{
410 auto dest = asWritableBytes(m_device_views);
411 auto source = asBytes(m_host_views);
412 if (queue) {
413 Accelerator::MemoryCopyArgs copy_args(dest, source);
414 copy_args.addAsync(true);
415 queue->copyMemory(copy_args);
416 }
417 else
418 MemoryUtils::copy(dest, source);
419}
420
421/*---------------------------------------------------------------------------*/
422/*---------------------------------------------------------------------------*/
423
424template <typename Traits> void
425ItemMaterialVariableBase<Traits>::
426_copyBetweenPartialAndGlobal(const CopyBetweenPartialAndGlobalArgs& args)
427{
428 Int32 var_index = args.m_var_index + 1;
429 PrivatePartType* partial_var = m_vars[var_index];
430 if (!_isValidAndUsedAndGlobalUsed(partial_var))
431 return;
432 const bool is_global_to_partial = args.m_is_global_to_partial;
433 const bool use_generic = args.m_use_generic_copy;
434 const RunQueue& queue = args.m_queue;
435
436 auto input = m_host_views[var_index];
437 auto output = m_host_views[0];
438 auto output_indexes = args.m_local_ids;
439 auto input_indexes = args.m_indexes_in_multiple;
440
441 if (is_global_to_partial) {
442 std::swap(input, output);
443 std::swap(output_indexes, input_indexes);
444 }
445 if (use_generic) {
446 Int32 data_type_size = dataTypeSize();
447 SmallSpan<const std::byte> input_bytes(Traits::toBytes(input));
448 SmallSpan<std::byte> output_bytes(Traits::toBytes(output));
449 if (args.isUseOneCommand())
450 args.addOneCopyData(input_bytes, output_bytes, data_type_size);
451 else
452 _genericCopyTo(input_bytes, input_indexes,
453 output_bytes, output_indexes, queue, data_type_size);
454 }
455 else {
456 Traits::copyTo(input, input_indexes, output, output_indexes, queue);
457 }
458}
459
460/*---------------------------------------------------------------------------*/
461/*---------------------------------------------------------------------------*/
462
463template <typename Traits> void
464ItemMaterialVariableBase<Traits>::
465_initializeNewItemsWithZero(InitializeWithZeroArgs& args)
466{
467 const Int32 var_index = args.m_var_index + 1;
468 RunQueue& queue = args.m_queue;
469 PrivatePartType* partial_var = m_vars[var_index];
470 if (!_isValidAndUsedAndGlobalUsed(partial_var))
471 return;
472
473 SmallSpan<const Int32> partial_indexes = args.m_indexes_in_multiple;
474
475 ARCANE_CHECK_ACCESSIBLE_POINTER(queue, partial_indexes.data());
476
477 if (args.isUseOneCommand()) {
478 Int32 data_type_size = dataTypeSize();
479 auto output = m_host_views[var_index];
480 SmallSpan<std::byte> output_bytes(Traits::toBytes(output));
481 args.addOneCopyData({}, output_bytes, data_type_size);
482 }
483 else {
484 ContainerSpanType partial_view = m_host_views[var_index];
485 Int32 nb_partial = partial_indexes.size();
486 DataType zero = DataType();
487 auto command = makeCommand(queue);
488 command << RUNCOMMAND_LOOP1(iter, nb_partial)
489 {
490 auto [i] = iter();
491 Int32 index = partial_indexes[i];
492 Traits::setValue(partial_view[index], zero);
493 };
494 }
495}
496
497/*---------------------------------------------------------------------------*/
498/*---------------------------------------------------------------------------*/
499
500template <typename Traits> void
501ItemMaterialVariableBase<Traits>::
502fillPartialValuesWithGlobalValues()
503{
504 fillPartialValuesWithSuperValues(LEVEL_ALLENVIRONMENT);
505}
506
507/*---------------------------------------------------------------------------*/
508/*---------------------------------------------------------------------------*/
509
510template <typename Traits> void
511ItemMaterialVariableBase<Traits>::
512fillPartialValuesWithSuperValues(Int32 level)
513{
514 IMeshMaterialMng* mm = m_p->materialMng();
515 if (level == LEVEL_MATERIAL)
516 _fillPartialValuesWithSuperValues(mm->materialsAsComponents());
517 else if (level == LEVEL_ENVIRONMENT) {
518 _fillPartialValuesWithSuperValues(mm->environmentsAsComponents());
519 }
520 else if (level == LEVEL_ALLENVIRONMENT) {
521 _fillPartialValuesWithSuperValues(mm->environmentsAsComponents());
522 _fillPartialValuesWithSuperValues(mm->materialsAsComponents());
523 }
524 else
525 throw ArgumentException(A_FUNCINFO, String::format("Invalid level={0}", level));
526}
527
528/*---------------------------------------------------------------------------*/
529/*---------------------------------------------------------------------------*/
530
531template <typename Traits> void
534{
535 MatVarSpace s = this->space();
536 ENUMERATE_COMPONENT (ic, components) {
537 IMeshComponent* c = *ic;
538 if (!c->hasSpace(s))
539 continue;
540 ENUMERATE_COMPONENTCELL (iccell, c) {
541 ComponentCell c = (*iccell).superCell();
542 setValue(iccell._varIndex(), value(c._varIndex()));
543 }
544 }
545}
546
547/*---------------------------------------------------------------------------*/
548/*---------------------------------------------------------------------------*/
549
550/*---------------------------------------------------------------------------*/
551/*---------------------------------------------------------------------------*/
552
559template <typename VariableTrueType> IMeshMaterialVariable*
562{
563 typedef typename VariableTrueType::PrivatePartType PrivatePartType;
564 typedef typename VariableTrueType::VariableRefType VariableRefType;
565
566 MeshHandle mesh_handle = v.meshHandle();
567 if (mesh_handle.isNull())
568 ARCANE_FATAL("No mesh handle for material variable");
569
570 IMeshMaterialMng* mat_mng = v.materialMng();
571
572 //TODO: check if lock is necessary
573 if (!mat_mng)
574 mat_mng = IMeshMaterialMng::getReference(mesh_handle, true);
575
576 if (!mat_mng)
577 ARCANE_FATAL("No IMaterialMng for mesh");
578
579 if (!v.itemFamilyName().null())
580 ARCANE_FATAL("Can not declare material variable for specific family");
581
582 if (!v.itemGroupName().null())
583 ARCANE_FATAL("Can not declare partial material variable");
584
585 // Regarde si l'option qui force la création des variables matériaux
586 // même si on est une variable milieu est active.
587
588 if (VariableTrueType::TraitsType::dimension() == 0)
591
592 VariableBuildInfo gvar_bi(v);
593
594 {
595 Mutex::ScopedLock sl(mat_mng->variableLock());
596
598 VariableInfo gvar_vi = VariableRefType::_internalVariableInfo(gvar_bi);
599 IVariable* g_var = PrivatePartType::getReference(gvar_bi, gvar_vi);
600
601 PrivatePartType* true_ptr = dynamic_cast<PrivatePartType*>(g_var);
602
603 // TODO: check if we should also include the name of m_material_mng.
604 // If we do, it poses a problem with the global variable
605 // associated. If we don't, we can only have
606 // a single IMeshMaterialMng.
607 IMeshMaterialVariable* mat_var = mat_mng->checkVariable(g_var);
608 VariableTrueType* true_mat_var = 0;
609 // \a mat_var is not null if the associated variable already exists.
610 if (mat_var)
611 true_mat_var = dynamic_cast<VariableTrueType*>(mat_var);
612 else {
613 VariableRefType* var_ref = new VariableRefType(gvar_bi);
614 MaterialVariableBuildInfo mvbi(mat_mng, v);
615 true_mat_var = new VariableTrueType(mvbi, true_ptr, var_ref, mvs);
616 mat_mng->_internalApi()->addVariable(true_mat_var);
617 // The manager is already created, we can allocate all info
618 if (!mat_mng->_internalApi()->variablesIndexer().empty())
619 true_mat_var->buildFromManager(false);
620 }
621 ARCANE_CHECK_POINTER(true_mat_var);
622 if (mvs != true_mat_var->space())
623 ARCANE_FATAL("Incoherent space for variable '{0}' wanted_space={1} existing_space={2}.\n"
624 " Check all instances of the variables are of the same space\n"
625 " (i.e. all variables are MaterialVariable or EnvironmentVariable)",
626 true_mat_var->name(), (int)mvs, (int)true_mat_var->space());
627 // Increments the reference counter.
628 // It must be done here and not in addVariableRef() because in multithreading
629 // it is possible to create multiple references to the same variable at the same
630 // time and destroy one of the references before the addVariableRef() of the other
631 // reference is called, which causes the destruction of true_mat_var.
632 ++true_mat_var->m_p->m_nb_reference;
633 return true_mat_var;
634 }
635}
636
637/*---------------------------------------------------------------------------*/
638/*---------------------------------------------------------------------------*/
639
640template <typename TrueType> MeshMaterialVariableFactoryRegisterer
642m_auto_registerer1(_autoCreate1, TrueType::BuilderType::_buildVarTypeInfo(MatVarSpace::Environment));
643
644template <typename TrueType> MeshMaterialVariableFactoryRegisterer
646m_auto_registerer2(_autoCreate2, TrueType::BuilderType::_buildVarTypeInfo(MatVarSpace::MaterialAndEnvironment));
647
648template <typename TrueType> IMeshMaterialVariable*
651{
652 return getReference(v, MatVarSpace::Environment);
653}
654
655template <typename TrueType> IMeshMaterialVariable*
658{
659 return getReference(v, MatVarSpace::MaterialAndEnvironment);
660}
661
662/*---------------------------------------------------------------------------*/
663/*---------------------------------------------------------------------------*/
664
665} // End namespace Arcane::Materials
666
667/*---------------------------------------------------------------------------*/
668/*---------------------------------------------------------------------------*/
#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.
Memory and allocator management functions.
#define RUNCOMMAND_LOOP1(iter_name, x1,...)
1D loop on accelerator with additional arguments.
Modifiable view of an array of type T.
Constant view of an array of type T.
constexpr Integer size() const noexcept
Number of elements in the array.
Interface of a variable.
Definition IVariable.h:40
virtual void addTag(const String &tagname, const String &tagvalue)=0
Adds the tag tagname with the value tagvalue.
__host__ __device__ MatVarIndex _varIndex() const
Interface of a component (material or environment) of a mesh.
virtual bool hasSpace(MatVarSpace space) const =0
Indicates if the component is defined for space space.
Internal Arcane API for 'IMeshMaterialMng'.
virtual ConstArrayView< MeshMaterialVariableIndexer * > variablesIndexer()=0
List of information to index material variables.
virtual void addVariable(IMeshMaterialVariable *var)=0
Adds the variable var.
virtual Real additionalCapacityRatio() const =0
Ratio for additional capacity to allocate when resizing variables.
Interface for the material and environment manager of a mesh.
virtual MeshComponentList materialsAsComponents() const =0
List of materials viewed as components.
virtual bool isAllocateScalarEnvironmentVariableAsMaterial() const =0
Indicates if environment scalar variables are allocated on materials.
virtual Mutex * variableLock()=0
Lock used for multi-threading.
virtual MeshComponentList environmentsAsComponents() const =0
List of environments viewed as components.
virtual IMeshMaterialMngInternal * _internalApi() const =0
Internal API for Arcane.
virtual IMeshMaterialVariable * checkVariable(IVariable *global_var)=0
Material variable associated with the global variable global_var (nullptr if none).
static IMeshMaterialMng * getReference(const MeshHandleOrMesh &mesh_handle, bool create=true)
Retrieves or creates the reference associated with mesh.
Interface of a material variable on a mesh.
Base class for material variables with the characteristics specified by Traits.
ARCANE_MATERIALS_EXPORT void fillPartialValuesWithSuperValues(Int32 level) override
Fills partial values with the value of the super cell. If level equals LEVEL_MATERIAL,...
bool isEnvironment() const
True if this indexer is for an environment.
const String & name() const
Name of the indexer.
Base class for material variables.
String name() const override
Name of the variable.
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
bool null() const
Returns true if the string is null.
Definition String.cc:306
1D data vector with value semantics (STL style).
Parameters necessary for building a variable.
Information characterizing a variable.
#define ENUMERATE_COMPONENT(icomponent, container)
Macro to iterate over a list of components.
#define ENUMERATE_COMPONENTCELL(iname, component)
Macro to iterate over all ComponentCell cells of a component.
RunCommand makeCommand(const RunQueue &run_queue)
Creates a command associated with the queue run_queue.
Always enables tracing in Arcane parts concerning materials.
ConstArrayView< IMeshComponent * > MeshComponentList
List of multi-material components of the mesh.
MatVarSpace
Definition space for a material variable.
@ Environment
Variable having values only on environments.
@ MaterialAndEnvironment
Variable having values on environments and materials.
MemoryAllocationOptions getAllocationOptions(eMemoryResource mem_resource)
Default allocation for the resource mem_resource.
ARCANE_DATATYPE_EXPORT Integer dataTypeSize(eDataType type)
Size of data type type (which must be different from DT_String).
Definition DataTypes.cc:111
Int32 Integer
Type representing an integer.
double Real
Type representing a real number.
Arcane::eMemoryResource eMemoryRessource
Typedef for the historical Arcane version (with 2's').
Impl::SpanTypeFromSize< conststd::byte, SizeType >::SpanType asBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converts the view into an array of non-modifiable bytes.
Definition Span.h:1032
Impl::SpanTypeFromSize< std::byte, SizeType >::SpanType asWritableBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converts the view into an array of modifiable bytes.
Definition Span.h:1068
@ HostPinned
Allocates on the host.
std::int32_t Int32
Signed integer type of 32 bits.