Skip to content

Commit

Permalink
Merge pull request #1681 from arcaneframework/dev/gg-mark-modified-co…
Browse files Browse the repository at this point in the history
…nstituents-during-modification

Computed constituents impacted during material modification and exclude them from some treatments
  • Loading branch information
grospelliergilles authored Oct 11, 2024
2 parents 6e0ea98 + 67f8470 commit ab21b6b
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 8 deletions.
40 changes: 38 additions & 2 deletions arcane/src/arcane/materials/ConstituentConnectivityList.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,16 @@ namespace

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

/*!
* \brief Conteneur des données de connectivité pour un type de constituant.
*/
class ConstituentConnectivityList::ConstituentContainer
{
public:

/*!
* \brief Vue sur une liste de constituants des mailles.
*/
class View
{
public:
Expand Down Expand Up @@ -230,6 +235,7 @@ class ConstituentConnectivityList::NumberOfMaterialComputer
private:

ConstituentConnectivityList::ConstituentContainer::View m_view;
//! Vue indiquant le milieu associé aux matériaux
SmallSpan<const Int16> m_environment_for_materials;
};

Expand Down Expand Up @@ -565,7 +571,7 @@ fillCellsToTransform(SmallSpan<const Int32> cells_local_id, Int16 env_id,
bool do_transform = false;
// En cas d'ajout on passe de pure à partiel s'il y a plusieurs milieux ou
// plusieurs matériaux dans le milieu.
// En cas de supression, on passe de partiel à pure si on est le seul matériau
// En cas de suppression, on passe de partiel à pure si on est le seul matériau
// et le seul milieu.
const Int16 nb_env = cells_nb_env[local_id];
if (is_add) {
Expand Down Expand Up @@ -615,6 +621,36 @@ fillCellsIsPartial(SmallSpan<const Int32> cells_local_id, Int16 env_id,
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

void ConstituentConnectivityList::
fillModifiedConstituents(SmallSpan<const Int32> cells_local_id,
SmallSpan<bool> is_modified_materials,
SmallSpan<bool> is_modified_environments,
RunQueue& queue)
{
const Int32 n = cells_local_id.size();
if (n<=0)
return;

ConstituentContainer::View materials_view(m_container->m_material);
ConstituentContainer::View environments_view(m_container->m_environment);
auto command = makeCommand(queue);

command << RUNCOMMAND_LOOP1(iter, n)
{
auto [i] = iter();
Int32 local_id = cells_local_id[i];
SmallSpan<const Int16> cell_mats(materials_view.components(local_id));
for( Int16 x : cell_mats )
is_modified_materials[x] = true;
SmallSpan<const Int16> cell_envs(environments_view.components(local_id));
for( Int16 x : cell_envs )
is_modified_environments[x] = true;
};
}

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

void ConstituentConnectivityList::
notifySourceFamilyLocalIdChanged([[maybe_unused]] Int32ConstArrayView new_to_old_ids)
{
Expand Down
4 changes: 3 additions & 1 deletion arcane/src/arcane/materials/ConstituentModifierWorkInfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ ConstituentModifierWorkInfo(const MemoryAllocationOptions& opts, eMemoryRessourc
/*---------------------------------------------------------------------------*/

void ConstituentModifierWorkInfo::
initialize(Int32 max_local_id, RunQueue& queue)
initialize(Int32 max_local_id, Int32 nb_material, Int32 nb_environment, RunQueue& queue)
{
m_is_materials_modified.resizeHost(nb_material);
m_is_environments_modified.resizeHost(nb_environment);
m_cells_to_transform.resize(max_local_id);
m_cells_to_transform.fill(false, &queue);
m_removed_local_ids_filter.resize(max_local_id);
Expand Down
34 changes: 30 additions & 4 deletions arcane/src/arcane/materials/IncrementalComponentModifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ void IncrementalComponentModifier::
initialize()
{
Int32 max_local_id = m_material_mng->mesh()->cellFamily()->maxLocalId();
m_work_info.initialize(max_local_id, m_queue);
Int32 nb_mat = m_material_mng->materials().size();
Int32 nb_env = m_material_mng->environments().size();
m_work_info.initialize(max_local_id, nb_mat, nb_env, m_queue);
m_work_info.is_verbose = traceMng()->verbosityLevel() >= 5;
}

Expand Down Expand Up @@ -106,6 +108,20 @@ apply(MaterialModifierOperation* operation)
ConstituentConnectivityList* connectivity = m_all_env_data->componentConnectivityList();
const bool check_if_present = !m_queue.isAcceleratorPolicy();

m_work_info.m_is_materials_modified.fillHost(false);
m_work_info.m_is_environments_modified.fillHost(false);

const bool is_device = m_queue.isAcceleratorPolicy();

// Remplit les tableaux indicants si un constituant est concerné par
// la modification en cours. Si ce n'est pas le cas, on pourra éviter de le tester
// dans la boucle des constituants.
{
auto mat_modifier = m_work_info.m_is_materials_modified.modifier(is_device);
auto env_modifier = m_work_info.m_is_environments_modified.modifier(is_device);
connectivity->fillModifiedConstituents(orig_ids, mat_modifier.view(), env_modifier.view(), m_queue);
}

if (nb_mat != 1) {

// S'il est possible d'avoir plusieurs matériaux par milieu, il faut gérer
Expand Down Expand Up @@ -246,14 +262,18 @@ _switchCellsForMaterials(const MeshMaterial* modified_mat,
SmallSpan<const Int32> ids)
{
const bool is_add = m_work_info.isAdd();
const bool is_device = isAcceleratorPolicy(m_queue.executionPolicy());
const bool is_device = m_queue.isAcceleratorPolicy();
SmallSpan<const bool> is_materials_modified = m_work_info.m_is_materials_modified.view(false);

for (MeshEnvironment* true_env : m_material_mng->trueEnvironments()) {
for (MeshMaterial* mat : true_env->trueMaterials()) {
// Ne traite pas le matériau en cours de modification.
if (mat == modified_mat)
continue;

if (!is_materials_modified[mat->id()])
continue;

if (!is_device) {
m_work_info.pure_local_ids.clearHost();
m_work_info.partial_indexes.clearHost();
Expand All @@ -277,7 +297,8 @@ _switchCellsForMaterials(const MeshMaterial* modified_mat,
Int32 nb_partial = partial_indexes.size();
info(4) << "NB_MAT_TRANSFORM pure=" << nb_pure
<< " partial=" << nb_partial << " name=" << mat->name()
<< " is_device?=" << is_device;
<< " is_device?=" << is_device
<< " is_modified?=" << is_materials_modified[mat->id()];

CopyBetweenPartialAndGlobalArgs args(indexer->index(), pure_local_ids,
partial_indexes,
Expand Down Expand Up @@ -309,6 +330,7 @@ _switchCellsForEnvironments(const IMeshEnvironment* modified_env,
{
const bool is_add = m_work_info.isAdd();
const bool is_device = m_queue.isAcceleratorPolicy();
SmallSpan<const bool> is_environments_modified = m_work_info.m_is_materials_modified.view(false);

// Ne copie pas les valeurs partielles des milieux vers les valeurs globales
// en cas de suppression de mailles, car cela sera fait avec la valeur matériau
Expand All @@ -326,6 +348,9 @@ _switchCellsForEnvironments(const IMeshEnvironment* modified_env,
if (env == modified_env)
continue;

//if (!is_environments_modified[env->id()])
//continue;

if (!is_device) {
m_work_info.pure_local_ids.clearHost();
m_work_info.partial_indexes.clearHost();
Expand All @@ -342,7 +367,8 @@ _switchCellsForEnvironments(const IMeshEnvironment* modified_env,
SmallSpan<const Int32> partial_indexes = m_work_info.partial_indexes.view(is_device);

info(4) << "NB_ENV_TRANSFORM nb_pure=" << pure_local_ids.size()
<< " name=" << env->name();
<< " name=" << env->name()
<< " is_modified=" << is_environments_modified[env->id()];

if (is_copy) {
CopyBetweenPartialAndGlobalArgs copy_args(indexer->index(), pure_local_ids,
Expand Down
11 changes: 11 additions & 0 deletions arcane/src/arcane/materials/internal/ConstituentConnectivityList.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ class ConstituentConnectivityList
void fillCellsIsPartial(SmallSpan<const Int32> cells_local_id, Int16 env_id,
SmallSpan<bool> cells_is_partial, RunQueue& queue);

/*!
* \brief Remplit les constituant concernés par les mailles \a cells_local_id.
*
* Met à \a true les valeurs de \a is_modified_materials et \a is_modified_environments
* s'ils sont dans une des mailles de \a cells_local_id.
*/
void fillModifiedConstituents(SmallSpan<const Int32> cells_local_id,
SmallSpan<bool> is_modified_materials,
SmallSpan<bool> is_modified_environments,
RunQueue& queue);

/*!
* \brief Indique si l'instance est activée.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,26 @@ class ARCANE_MATERIALS_EXPORT ConstituentModifierWorkInfo

public:

/*!
* \brief Liste des mailles pures d'un constituant
* ajoutées/supprimées par l'opération en cours.
*/
DualUniqueArray<Int32> pure_local_ids;
/*!
* \brief Liste des mailles partielles d'un constituant
* ajoutées/supprimées par l'opération en cours.
*/
DualUniqueArray<Int32> partial_indexes;
/*!
* \brief Tableau dimensionné aux matériaux qui est vrai si un matériau est
* concerné par la modification en cours.
*/
DualUniqueArray<bool> m_is_materials_modified;
/*!
* \brief Tableau dimensionné aux milieux qui est vrai si un milieu est
* concerné par la modification en cours.
*/
DualUniqueArray<bool> m_is_environments_modified;
bool is_verbose = false;

//! Liste des mailles d'un milieu qui vont être ajoutées ou supprimées lors d'une opération
Expand Down Expand Up @@ -79,7 +97,7 @@ class ARCANE_MATERIALS_EXPORT ConstituentModifierWorkInfo
public:

//! Initialise l'instance.
void initialize(Int32 max_local_id, RunQueue& queue);
void initialize(Int32 max_local_id, Int32 nb_material, Int32 nb_environment, RunQueue& queue);

public:

Expand Down
7 changes: 7 additions & 0 deletions arcane/src/arcane/utils/DualUniqueArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ class DualUniqueArray
m_array.resize(new_size);
m_is_valid_numarray = false;
}
void fillHost(const DataType& value)
{
m_array.fill(value);
m_is_valid_numarray = false;
}
void resizeDevice(Int32 new_size)
{
_checkCreateNumArray();
Expand Down Expand Up @@ -285,6 +290,8 @@ class DualUniqueArray
{
if (!m_device_array) {
m_device_array = std::make_unique<NumArrayType>(eMemoryRessource::Device);
if (m_is_valid_array)
m_device_array->resize(m_array.size());
}
}
};
Expand Down

0 comments on commit ab21b6b

Please sign in to comment.