14#include "arcane/materials/MeshMaterialBackup.h"
16#include "arcane/utils/IDataCompressor.h"
18#include "arcane/core/IVariable.h"
19#include "arcane/core/IData.h"
20#include "arcane/core/IMesh.h"
21#include "arcane/core/IItemFamily.h"
22#include "arcane/core/ServiceBuilder.h"
23#include "arcane/core/internal/IDataInternal.h"
24#include "arcane/core/materials/IMeshMaterialMng.h"
25#include "arcane/core/materials/IMeshMaterialVariable.h"
27#include "arcane/core/materials/internal/IMeshMaterialVariableInternal.h"
28#include "arcane/core/materials/internal/IMeshMaterialMngInternal.h"
30#include "arcane/materials/internal/MeshMaterialMng.h"
31#include "arcane/materials/internal/MeshMaterialVariableIndexer.h"
55 DataCompressionBuffer m_data_buffer;
66, m_use_unique_ids(use_unique_ids)
77 for (
const auto& iter : m_saved_data)
84void MeshMaterialBackup::
93void MeshMaterialBackup::
105 m_compressor_service_name = name;
114bool MeshMaterialBackup::
128void MeshMaterialBackup::
131 if (!m_compressor_service_name.
null())
138 for (
Integer i = 0; i < nb_index; ++i)
139 nb_value += indexers[i]->cells().size();
141 info(4) <<
"NB_EXPECTED_VALUE=" << nb_value;
143 MeshMaterialMng* mm =
dynamic_cast<MeshMaterialMng*
>(m_material_mng);
149 m_vars.reserve(max_nb_var);
150 for (
const auto& i : mm->m_full_name_variable_map) {
155 for (IMeshMaterialVariable* mv : m_vars) {
157 VarData* vd =
new VarData(mv->_internalApi()->internalCreateSaveDataRef(nb_value));
158 m_saved_data.insert(std::make_pair(mv, vd));
170void MeshMaterialBackup::
174 IMeshComponent* c = *ic;
176 for (IMeshMaterialVariable* var : m_vars) {
177 if (_isValidComponent(var, c))
178 var->_internalApi()->saveData(c, m_saved_data[var]->data.get());
186void MeshMaterialBackup::
189 IMesh* mesh = m_material_mng->mesh();
190 ServiceBuilder<IDataCompressor> sb(mesh->handle().application());
191 Ref<IDataCompressor> compressor_ref;
192 if (!m_compressor_service_name.empty())
193 compressor_ref = sb.createReference(m_compressor_service_name);
194 IDataCompressor* compressor = compressor_ref.get();
195 auto components = m_material_mng->components();
198 IMeshComponent* c = *ic;
202 for (IMeshMaterialVariable* var : m_vars) {
203 VarData* var_data = m_saved_data[var];
204 IData* saved_data = var_data->data.get();
206 var_data->m_compressor = compressor_ref;
207 var_data->m_data_buffer.m_compressor = compressor;
210 IMeshComponent* c = *ic;
211 if (_isValidComponent(var, c)) {
212 var->_internalApi()->saveData(c, saved_data);
216 IDataInternal* d = saved_data->_commonInternal();
217 d->compressAndClear(var_data->m_data_buffer);
225void MeshMaterialBackup::
226_saveIds(IMeshComponent* component)
228 if (m_use_unique_ids) {
229 auto& ids = m_unique_ids_array[component];
231 ComponentCell ec = *icell;
232 ids.add(ec.globalCell().uniqueId());
234 info(4) <<
"SAVE (uid) for component name=" << component->name()
235 <<
" nb=" << ids.size();
240 ComponentCell ec = *icell;
241 ids.add(ec.globalCell().localId());
243 info(4) <<
"SAVE (lid) for component name=" << component->name()
244 <<
" nb=" << ids.size();
251void MeshMaterialBackup::
254 if (m_use_unique_ids) {
255 info(4) <<
"RESTORE using uniqueIds()";
256 IItemFamily* cell_family = m_material_mng->mesh()->cellFamily();
260 for (
const auto& iter : m_unique_ids_array) {
261 IMeshComponent* component = iter.first;
262 auto& unique_ids = m_unique_ids_array[component];
263 auto& local_ids = m_ids_array[component];
264 local_ids.resize(unique_ids.size());
265 cell_family->itemsUniqueIdToLocalId(local_ids, unique_ids,
false);
278void MeshMaterialBackup::
283 bool allow_null_id = m_use_unique_ids;
286 IMeshComponent* c = *ic;
288 info(4) <<
"RESTORE for component name=" << c->name() <<
" nb=" << ids.size();
289 for (IMeshMaterialVariable* var : m_vars) {
290 VarData* vd = m_saved_data[var];
291 if (_isValidComponent(var, c)) {
292 var->_internalApi()->restoreData(c, vd->data.get(), vd->data_index, ids, allow_null_id);
293 vd->data_index += ids.size();
302void MeshMaterialBackup::
307 bool allow_null_id = m_use_unique_ids;
309 auto components = m_material_mng->components();
311 for (IMeshMaterialVariable* var : m_vars) {
312 VarData* vd = m_saved_data[var];
314 IDataCompressor* compressor = vd->m_data_buffer.m_compressor;
316 info(5) <<
"RESTORE decompress variable name=" << var->
name();
317 IDataInternal* d = vd->data->_commonInternal();
318 d->decompressAndFill(vd->m_data_buffer);
320 info(4) <<
"RESTORE for variable name=" << var->
name();
322 IMeshComponent* c = *ic;
324 if (_isValidComponent(var, c)) {
325 var->_internalApi()->restoreData(c, vd->data.get(), vd->data_index, ids, allow_null_id);
326 vd->data_index += ids.size();
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Constant view of an array of type T.
constexpr Integer size() const noexcept
Number of elements in the array.
virtual bool isUsed() const =0
Usage state of the variable.
Interface of a component (material or environment) of a mesh.
virtual bool isEnvironment() const =0
True if the component is an environment.
Interface for the material and environment manager of a mesh.
virtual String dataCompressorServiceName() const =0
Virtual name of the service used to compress data.
virtual IMeshMaterialMngInternal * _internalApi() const =0
Internal API for Arcane.
Interface of a material variable on a mesh.
virtual bool keepOnChange() const =0
Indicates whether the variable value should be kept after a change in the list of materials.
virtual MatVarSpace space() const =0
Variable definition space (material+environment or environment only).
virtual IVariable * globalVariable() const =0
Associated global variable on the mesh.
virtual String name() const =0
Name of the variable.
void setCompressorServiceName(const String &name)
Name of the service used to compress the data.
Reference to an instance.
Unicode character string.
bool null() const
Returns true if the string is null.
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
TraceMessage info() const
Flow for an information message.
ITraceMng * traceMng() const
Trace manager.
Always enables tracing in Arcane parts concerning materials.
MatVarSpace
Definition space for a material variable.
@ Environment
Variable having values only on environments.
@ MaterialAndEnvironment
Variable having values on environments and materials.
Integer arcaneCheckArraySize(unsigned long long size)
Checks that size can be converted into an 'Integer' to serve as the size of an array....
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
Array< Int32 > Int32Array
Dynamic one-dimensional array of 32-bit integers.