Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
Usage for materials

It is possible to use the Arcane accelerator API to manage constituents. Instances of the material manager IMeshMaterialMng use the execution manager (Runner) associated with the subdomain from which the mesh originates. Constituent management will therefore be handled automatically using the same execution environment as operations on classic mesh entities.

Using the accelerator API for materials is similar to using it for mesh entities. The macro RUNCOMMAND_MAT_ENUMERATE() allows iteration over an environment IMeshEnvironment or a material IMeshMaterial.

The possible values for this macro are:

Iteration TypeIterator ValueContainer TypeDescription
EnvAndGlobalCellEnvAndGlobalCellIteratorValueIMeshEnvironment
EnvCellVectorView
Iteration over an environment allowing the retrieval of the local cell number of the environment, the iteration index, and the associated global cell number for each iteration.
MatAndGlobalCellMatAndGlobalCellIteratorValueIMeshMaterial
MatCellVectorView
Iteration over a material allowing the retrieval of the local cell number of the material, the iteration index, and the associated global cell number for each iteration.
AllEnvCellAllEnvCellAllEnvCellVectorViewIteration over the AllEnvCell
EnvCellEnvCellLocalIdIMeshEnvironment
EnvCellVectorView
Iteration over an environment allowing the retrieval of only the local cell number of the environment for each iteration.
MatCellMatCellLocalIdIMeshMaterial
MatCellVectorView
Iteration over a material allowing the retrieval of only the local cell number of the material for each iteration.

If you only want to access the local numbers of material or environment cells, it is preferable for performance reasons to use the version with EnvCell or MatCell as the iterator type.

Here is a code example for iterating over an environment cell with the information of the iteration index and the associated global cell.

Int32 nb_cell = env1->cells().size();
Arcane::NumArray<Int32, MDDim1> cells_local_id(nb_cell);
{
auto queue = makeQueue(m_runner);
auto command = makeCommand(queue);
auto cells_local_id_view = viewOut(command, cells_local_id);
auto out_mat_a = viewOut(command, mat_a);
command << RUNCOMMAND_MAT_ENUMERATE(EnvAndGlobalCell, iter, m_env1)
{
EnvAndGlobalCellIteratorValue evi = iter; // Iterator value
auto [iter_mvi, iter_cid] = evi();
EnvCellLocalId mvi = iter_mvi; // Local ID of the middle cell
Arcane::CellLocalId cid = iter_cid; // Global ID of the current middle cell
Int32 iter_index = evi.index(); // Iteration index
cells_local_id_view[iter_index] = cid;
out_mat_a[mvi] = 1.2;
};
}

Here is another example for iterating over the AllEnvCell and retrieving information about the environments and materials present in each AllEnvCell.

Arcane::Materials::AllEnvCellVectorView all_env_view = m_mm_mng->view(allCells());
auto cmd = makeCommand(queue);
auto in_b = viewIn(cmd, m_mat_b);
auto out_c = viewOut(cmd, m_mat_c);
auto in_c_g = viewIn(cmd, m_mat_c.globalVariable());
auto out_a_g = viewOut(cmd, m_mat_a);
cmd << RUNCOMMAND_MAT_ENUMERATE(AllEnvCell, all_env_cell_iter, all_env_view)
{
Arcane::Materials::AllEnvCell all_env_cell = all_env_cell_iter;
Arcane::CellLocalId cid = all_env_cell.globalCellId();
Real sum2 = 0.0;
for (Arcane::Materials::EnvCell ev : all_env_cell.subEnvItems()) {
sum2 += in_b[ev] + in_b[cid];
}
Real sum3 = 0.0;
if (all_env_cell.nbEnvironment() > 1) {
for (Arcane::Materials::EnvCell ev : all_env_cell.subEnvItems()) {
Real contrib2 = (in_b[ev] + in_b[all_env_cell]) - (sum2 + 1.);
out_c[ev] = contrib2 * in_c_g[cid];
sum3 += contrib2;
}
}
out_a_g[cid] = sum3;
};

The class ComponentCellVector and its derived classes (MatCellVector and EnvCellVector) are supported by the accelerator API, and their creation or modification uses the default execution environment.

Starting from version 3.16 of Arcane, if the default execution environment is an accelerator, it is possible to specify a host execution policy via the method IMeshComponent::setSpecificExecutionPolicy(). This policy will be used to create and modify instances of ComponentCellVector, MatCellVector, and EnvCellVector.