Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
MeshMaterialIndirectModifier.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2023 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/* MeshMaterialIndirectModifier.cc (C) 2000-2023 */
9/* */
10/* Objet permettant de modifier indirectement les matériaux. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/materials/MeshMaterialIndirectModifier.h"
15
16#include "arcane/utils/ArrayView.h"
17#include "arcane/utils/FatalErrorException.h"
18#include "arcane/utils/ITraceMng.h"
19
20#include "arcane/core/ItemGroup.h"
21#include "arcane/core/IItemFamily.h"
22#include "arcane/core/materials/IMeshMaterialMng.h"
23#include "arcane/core/materials/IMeshEnvironment.h"
24#include "arcane/core/materials/IMeshMaterial.h"
25#include "arcane/core/materials/internal/IMeshMaterialMngInternal.h"
26
27#include "arcane/materials/MeshMaterialBackup.h"
28#include "arcane/materials/internal/MeshMaterialVariableIndexer.h"
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33namespace Arcane::Materials
34{
35
36/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
38
39MeshMaterialIndirectModifier::
40MeshMaterialIndirectModifier(IMeshMaterialMng* mm)
41: m_material_mng(mm)
42, m_backup(new MeshMaterialBackup(mm,true))
43, m_has_update(false)
44{
45}
46
47/*---------------------------------------------------------------------------*/
48/*---------------------------------------------------------------------------*/
49
50MeshMaterialIndirectModifier::
51~MeshMaterialIndirectModifier() noexcept(false)
52{
53 endUpdate();
54 delete m_backup;
55}
56
57/*---------------------------------------------------------------------------*/
58/*---------------------------------------------------------------------------*/
59
60/*---------------------------------------------------------------------------*/
61/*---------------------------------------------------------------------------*/
62
63void MeshMaterialIndirectModifier::
64_endUpdate(bool do_sort)
65{
66 if (!m_has_update)
67 return;
68
69 if (do_sort){
70 for( MeshMaterialVariableIndexer* v : m_material_mng->_internalApi()->variablesIndexer() ){
71 CellGroup cells = v->cells();
72 UniqueArray<Int32> items_lid(cells.view().localIds());
73 cells.clear();
74 cells.setItems(items_lid,true);
75 }
76 }
77
78 m_material_mng->forceRecompute();
79
80 m_backup->restoreValues();
81
82 m_has_update = false;
83}
84
85/*---------------------------------------------------------------------------*/
86/*---------------------------------------------------------------------------*/
87
88void MeshMaterialIndirectModifier::
89endUpdate()
90{
91 _endUpdate(false);
92}
93
94/*---------------------------------------------------------------------------*/
95/*---------------------------------------------------------------------------*/
96
97void MeshMaterialIndirectModifier::
98endUpdateWithSort()
99{
100 _endUpdate(true);
101}
102
103/*---------------------------------------------------------------------------*/
104/*---------------------------------------------------------------------------*/
105
106void MeshMaterialIndirectModifier::
107beginUpdate()
108{
109 if (m_has_update)
110 ARCANE_FATAL("beginUpdate() already called.");
111 m_has_update = true;
112 m_backup->saveValues();
113}
114
115/*---------------------------------------------------------------------------*/
116/*---------------------------------------------------------------------------*/
117
118} // End namespace Arcane::Materials
119
120/*---------------------------------------------------------------------------*/
121/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
ItemGroupT< Cell > CellGroup
Groupe de mailles.
Definition ItemTypes.h:183
Active toujours les traces dans les parties Arcane concernant les matériaux.