Skip to content

Recompute synchronization infos after a patch creation in the AMRCartesianMesh part #1946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 27, 2025
31 changes: 29 additions & 2 deletions arcane/ceapart/src/arcane/tests/AMRCartesianMeshTesterModule.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
//-----------------------------------------------------------------------------
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: Apache-2.0
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
/* AMRCartesianMeshTesterModule.cc (C) 2000-2024 */
/* AMRCartesianMeshTesterModule.cc (C) 2000-2025 */
/* */
/* Module de test du gestionnaire de maillages cartésiens AMR. */
/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -117,6 +117,7 @@
Integer _cellsUidAroundCells(UniqueArray<Int64>& own_cells_uid_around_cells);
Integer _cellsUidAroundFaces(UniqueArray<Int64>& own_cells_uid_around_faces);
Integer _nodesUidAroundNodes(UniqueArray<Int64>& own_nodes_uid_around_nodes);
void _checkSync();
void _cellsInPatch(Real3 position, Real3 length, bool is_3d, Int32 level, UniqueArray<Int32>& cells_in_patch);
};

Expand Down Expand Up @@ -334,6 +335,7 @@
_writePostProcessing();
_testDirections();
_checkDirections();
_checkSync();
}

/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -1172,6 +1174,31 @@
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

void AMRCartesianMeshTesterModule::
_checkSync()
{
IMesh* mesh = m_cartesian_mesh->mesh();
Integer nb_error = 0;

VariableCellInt32 test_var(VariableBuildInfo(mesh, "ArcaneTestAMRCheckSync"));
test_var.fill(0);
ENUMERATE_ (Cell, icell, mesh->ownCells()) {
test_var[icell] = 1;
}
test_var.synchronize();
ENUMERATE_ (Cell, icell, mesh->allCells()) {
if (test_var[icell] != 1) {
nb_error++;

Check warning on line 1191 in arcane/ceapart/src/arcane/tests/AMRCartesianMeshTesterModule.cc

View check run for this annotation

Codecov / codecov/patch

arcane/ceapart/src/arcane/tests/AMRCartesianMeshTesterModule.cc#L1191

Added line #L1191 was not covered by tests
}
}
if (nb_error > 0) {
ARCANE_FATAL("Bad sync -- Nb error : {0}", nb_error);

Check warning on line 1195 in arcane/ceapart/src/arcane/tests/AMRCartesianMeshTesterModule.cc

View check run for this annotation

Codecov / codecov/patch

arcane/ceapart/src/arcane/tests/AMRCartesianMeshTesterModule.cc#L1195

Added line #L1195 was not covered by tests
}
}

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

void AMRCartesianMeshTesterModule::
_cellsInPatch(Real3 position, Real3 length, bool is_3d, Int32 level, UniqueArray<Int32>& cells_in_patch)
{
Expand Down
3 changes: 3 additions & 0 deletions arcane/ceapart/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ if (ARCANE_HAS_ACCELERATOR_API)
arcane_add_accelerator_test_parallel_thread(material_sync2_v7 testMaterial-sync-2.arc 4 -We,ARCANE_MATSYNCHRONIZE_VERSION,7)
arcane_add_accelerator_test_parallel_thread(material_sync2_vacc testMaterial-sync-2.arc 4 -We,ARCANE_ACC_MAT_SYNCHRONIZER,1)

ARCANE_ADD_TEST(material_sync3 testMaterial-sync-3.arc)
ARCANE_ADD_TEST_PARALLEL_THREAD(material_sync3 testMaterial-sync-3.arc 4)

ARCANE_ADD_TEST(material3 testMaterial-3.arc "-m 20")
# NOTE Ajoute test optmisation uniquement en sequentiel car pour l'instant cela
# ne marche pas en parallele a cause de la suppression de mailles.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<length>2.0 2.0</length>
</refinement-2d>
<expected-number-of-cells-in-patchs>48 192 12 8 64 72</expected-number-of-cells-in-patchs>
<expected-number-of-ghost-cells-in-patchs>72 288 12 8 160 168</expected-number-of-ghost-cells-in-patchs>
<expected-number-of-ghost-cells-in-patchs>120 480 12 8 192 216</expected-number-of-ghost-cells-in-patchs>
<nodes-uid-hash>133eed4a37931e6cd103f2fb12c354eb</nodes-uid-hash>
<faces-uid-hash>0ba793345bd95bd20e83fc7cd6de9f02</faces-uid-hash>
<cells-uid-hash>7eec15be89bd293981c7b92df927cb78</cells-uid-hash>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
</refinement-2d>

<expected-number-of-cells-in-patchs>1600 6400 484</expected-number-of-cells-in-patchs>
<expected-number-of-ghost-cells-in-patchs>336 1344 0</expected-number-of-ghost-cells-in-patchs>
<expected-number-of-ghost-cells-in-patchs>516 2064 0</expected-number-of-ghost-cells-in-patchs>
<nodes-uid-hash>be945c17467f6ba7bbf41ee1baf19c8c</nodes-uid-hash>
<faces-uid-hash>c92d0e52cea7b406b449d57521f42124</faces-uid-hash>
<cells-uid-hash>19dd0b9269462bd111611a5f0adac601</cells-uid-hash>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<length>2.0 2.0</length>
</refinement-2d>
<expected-number-of-cells-in-patchs>1600 6400 484 1144 1936 3600 1600</expected-number-of-cells-in-patchs>
<expected-number-of-ghost-cells-in-patchs>336 1344 0 0 352 480 640</expected-number-of-ghost-cells-in-patchs>
<expected-number-of-ghost-cells-in-patchs>516 2064 0 0 528 720 960</expected-number-of-ghost-cells-in-patchs>
<nodes-uid-hash>2ec1e04de3e4927fcb7578afedba1446</nodes-uid-hash>
<faces-uid-hash>52335db38b14b6c2655b35770ea92dd2</faces-uid-hash>
<cells-uid-hash>66dae987c5a023af83c87cd6131d86f4</cells-uid-hash>
Expand Down
25 changes: 25 additions & 0 deletions arcane/ceapart/tests/testMaterial-sync-3.arc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<cas codename="ArcaneTest" xml:lang="fr" codeversion="1.0">
<arcane>
<titre>Test Material Synchronisation 3</titre>
<description>Test Material Synchronisation 3</description>
<boucle-en-temps>UnitTest</boucle-en-temps>
</arcane>

<maillage amr-type="3" nb-ghostlayer="3" ghostlayer-builder-version="3">
<meshgenerator>
<cartesian>
<nsd>2 2</nsd>
<origine>0.0 0.0</origine>
<lx nx='16'>16.0</lx>
<ly ny='16'>16.0</ly>
</cartesian>
</meshgenerator>
</maillage>

<module-test-unitaire>
<test name="MeshMaterialSyncUnitTest">
<nb-material>24</nb-material>
</test>
</module-test-unitaire>
</cas>
14 changes: 11 additions & 3 deletions arcane/src/arcane/cartesianmesh/CartesianMeshAMRPatchMng.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
//-----------------------------------------------------------------------------
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: Apache-2.0
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
/* CartesianMeshAMRPatchMng.cc (C) 2000-2024 */
/* CartesianMeshAMRPatchMng.cc (C) 2000-2025 */
/* */
/* Gestionnaire de l'AMR par patch d'un maillage cartésien. */
/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -1904,6 +1904,9 @@ refine()
}
}

// Recalcule les informations de synchronisation.
m_mesh->computeSynchronizeInfos();

// ENUMERATE_(Cell, icell, m_mesh->allCells()){
// debug() << "\t" << *icell;
// for(Node node : icell->nodes()){
Expand Down Expand Up @@ -1975,7 +1978,12 @@ coarse()
if (version < 3)
gm->setBuilderVersion(3);
Int32 nb_ghost_layer = gm->nbGhostLayer();
gm->setNbGhostLayer(nb_ghost_layer + (nb_ghost_layer % m_num_mng->pattern()));
// TODO AH : Cette ligne permettrait d'avoir moins de mailles fantômes et
// d'éviter leurs suppressions en cas d'inutilité. Mais le comportement
// serait différent de l'AMR historique.
//gm->setNbGhostLayer(nb_ghost_layer + (nb_ghost_layer % m_num_mng->pattern()));
// Comportement de l'AMR historique.
gm->setNbGhostLayer(nb_ghost_layer * 2);
mesh_modifier->setDynamic(true);
mesh_modifier->updateGhostLayers();
// Remet le nombre initial de couches de mailles fantômes
Expand Down
89 changes: 80 additions & 9 deletions arcane/src/arcane/materials/MeshMaterialSynchronizer.cc
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
//-----------------------------------------------------------------------------
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: Apache-2.0
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
/* MeshMaterialSynchronizer.cc (C) 2000-2024 */
/* MeshMaterialSynchronizer.cc (C) 2000-2025 */
/* */
/* Synchronisation des entités des matériaux. */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

#include "arcane/materials/internal/MeshMaterialSynchronizer.h"

#include "arcane/VariableTypes.h"
#include "arcane/IParallelMng.h"
#include "arcane/ItemPrinter.h"
#include "arcane/IMesh.h"

#include "arcane/materials/CellToAllEnvCellConverter.h"
#include "arcane/materials/MatItemEnumerator.h"
#include "arcane/materials/MeshMaterialModifier.h"

#include "arcane/utils/HashSuite.h"

#include "arcane/core/VariableTypes.h"
#include "arcane/core/IParallelMng.h"
#include "arcane/core/ItemPrinter.h"
#include "arcane/core/IMesh.h"
#include "arcane/core/ItemGenericInfoListView.h"

/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -90,10 +91,15 @@
if (!mesh->parallelMng()->isParallel())
return;
m_material_mng->checkValid();

info(4) << "CheckMaterialsInCells";

VariableCellInt32 indexes(VariableBuildInfo(mesh,"ArcaneMaterialPresenceIndexes"));
_checkComponents(indexes,m_material_mng->materialsAsComponents(),max_print);
_checkComponents(indexes,m_material_mng->environmentsAsComponents(),max_print);
_checkComponents(indexes, m_material_mng->materialsAsComponents(), max_print);
_checkComponents(indexes, m_material_mng->environmentsAsComponents(), max_print);

VariableCellInt64 hashes(VariableBuildInfo(mesh, "ArcaneMaterialCheckHashes"));
_checkComponentsInGhostCells(hashes, max_print);
}

/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -143,6 +149,71 @@
ARCANE_FATAL("Bad synchronisation");
}

void MeshMaterialSynchronizer::
_checkComponentsInGhostCells(VariableCellInt64& hashes, Integer max_print)
{
IMesh* mesh = m_material_mng->mesh();
Integer nb_error = 0;

ENUMERATE_ALLENVCELL (iallenvcell, m_material_mng, mesh->ownCells()) {
AllEnvCell all_env_cell = *iallenvcell;
Cell cell = all_env_cell.globalCell();

IntegerHashSuite hash_suite;

Int32 nb_env = all_env_cell.nbEnvironment();
hash_suite.add(nb_env);

for (Integer i = 0; i < nb_env; ++i) {
EnvCell env_cell = all_env_cell.cell(i);
Int32 nb_matt = env_cell.nbMaterial();
hash_suite.add(nb_matt);

for (Integer j = 0; j < nb_matt; ++j) {
MatCell mat = env_cell.cell(j);
Int32 id = mat.materialId();
hash_suite.add(id);
}
}

hashes[cell] = hash_suite.hash();
}

hashes.synchronize();

ENUMERATE_ALLENVCELL (iallenvcell, m_material_mng, mesh->allCells()) {
AllEnvCell all_env_cell = *iallenvcell;
Cell cell = all_env_cell.globalCell();
if (cell.isOwn())
continue;

IntegerHashSuite hash_suite;

Int32 nb_env = all_env_cell.nbEnvironment();
hash_suite.add(nb_env);

for (Integer i = 0; i < nb_env; ++i) {
EnvCell env_cell = all_env_cell.cell(i);
Int32 nb_matt = env_cell.nbMaterial();
hash_suite.add(nb_matt);

for (Integer j = 0; j < nb_matt; ++j) {
MatCell mat = env_cell.cell(j);
Int32 id = mat.materialId();
hash_suite.add(id);
}
}
if (hashes[cell] != hash_suite.hash()) {
nb_error++;

Check warning on line 207 in arcane/src/arcane/materials/MeshMaterialSynchronizer.cc

View check run for this annotation

Codecov / codecov/patch

arcane/src/arcane/materials/MeshMaterialSynchronizer.cc#L207

Added line #L207 was not covered by tests
if (max_print < 0 || nb_error < max_print) {
error() << "Bad components synchronization -- Cell : " << cell << " -- Hash : " << hash_suite.hash();

Check warning on line 209 in arcane/src/arcane/materials/MeshMaterialSynchronizer.cc

View check run for this annotation

Codecov / codecov/patch

arcane/src/arcane/materials/MeshMaterialSynchronizer.cc#L209

Added line #L209 was not covered by tests
}
}
}
if (nb_error != 0)
ARCANE_FATAL("Bad components synchronization -- Nb error : {0}", nb_error);

Check warning on line 214 in arcane/src/arcane/materials/MeshMaterialSynchronizer.cc

View check run for this annotation

Codecov / codecov/patch

arcane/src/arcane/materials/MeshMaterialSynchronizer.cc#L214

Added line #L214 was not covered by tests
}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
//-----------------------------------------------------------------------------
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: Apache-2.0
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
/* MeshMaterialSynchronizer.h (C) 2000-2024 */
/* MeshMaterialSynchronizer.h (C) 2000-2025 */
/* */
/* Synchronisation de la liste des matériaux/milieux des entités. */
/*---------------------------------------------------------------------------*/
Expand All @@ -17,7 +17,7 @@
#include "arcane/utils/TraceAccessor.h"
#include "arcane/utils/ArrayView.h"

#include "arcane/VariableTypedef.h"
#include "arcane/core/VariableTypedef.h"

#include "arcane/materials/MaterialsGlobal.h"
#include "arcane/materials/MatItem.h"
Expand Down Expand Up @@ -77,6 +77,8 @@ class MeshMaterialSynchronizer
void _checkComponents(VariableCellInt32& indexes,
ConstArrayView<IMeshComponent*> components,
Integer max_print);
void _checkComponentsInGhostCells(VariableCellInt64& hashes,
Integer max_print);
};

/*---------------------------------------------------------------------------*/
Expand Down
74 changes: 74 additions & 0 deletions arcane/src/arcane/utils/HashSuite.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
//-----------------------------------------------------------------------------
// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: Apache-2.0
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
/* HashSuite.h (C) 2000-2025 */
/* */
/* Fonction de hachage d'une suite de valeur. */
/*---------------------------------------------------------------------------*/
#ifndef ARCANE_UTILS_HASHSUITE_H
#define ARCANE_UTILS_HASHSUITE_H
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

#include "arcane/utils/HashFunction.h"

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

namespace Arcane
{

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

/*!
* \internal
* \brief Classe permettant de calculer un hash de manière itératif.
* \warning L'ordre dans lequel les valeurs sont données via la méthode add() est important.
*/

class IntegerHashSuite
{
public:

/*!
* \brief Méthode permettant d'ajouter une valeur dans le calcul du hash.
* \warning L'ordre dans lequel les valeurs sont données via la méthode
* add() est important.
* \param value La valeur à ajouter.
*/
template <class T>
void add(T value)
{
const UInt64 next_hash = static_cast<UInt64>(IntegerHashFunctionT<T>::hashfunc(value));
m_hash ^= next_hash + 0x9e3779b9 + (m_hash << 6) + (m_hash >> 2);
}

/*!
* \brief Méthode permettant de récupérer le hash calculé à partir de
* toutes les valeurs passées à la méthode add().
* \return Le hash.
*/
Int64 hash() const
{
return static_cast<Int64>(m_hash);
}

private:

UInt64 m_hash{0};
};

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

} // End namespace Arcane

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

#endif
Loading
Loading