Skip to content

Commit c699cec

Browse files
authored
Merge pull request #1946 from arcaneframework/dev/ah-fix-synchronize-in-amr-cartesian-mesh
Recompute synchronization infos after a patch creation in the AMRCartesianMesh part
2 parents ab23d3f + cc00505 commit c699cec

11 files changed

+231
-20
lines changed

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
22
//-----------------------------------------------------------------------------
3-
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3+
// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
44
// See the top-level COPYRIGHT file for details.
55
// SPDX-License-Identifier: Apache-2.0
66
//-----------------------------------------------------------------------------
77
/*---------------------------------------------------------------------------*/
8-
/* AMRCartesianMeshTesterModule.cc (C) 2000-2024 */
8+
/* AMRCartesianMeshTesterModule.cc (C) 2000-2025 */
99
/* */
1010
/* Module de test du gestionnaire de maillages cartésiens AMR. */
1111
/*---------------------------------------------------------------------------*/
@@ -117,6 +117,7 @@ class AMRCartesianMeshTesterModule
117117
Integer _cellsUidAroundCells(UniqueArray<Int64>& own_cells_uid_around_cells);
118118
Integer _cellsUidAroundFaces(UniqueArray<Int64>& own_cells_uid_around_faces);
119119
Integer _nodesUidAroundNodes(UniqueArray<Int64>& own_nodes_uid_around_nodes);
120+
void _checkSync();
120121
void _cellsInPatch(Real3 position, Real3 length, bool is_3d, Int32 level, UniqueArray<Int32>& cells_in_patch);
121122
};
122123

@@ -334,6 +335,7 @@ init()
334335
_writePostProcessing();
335336
_testDirections();
336337
_checkDirections();
338+
_checkSync();
337339
}
338340

339341
/*---------------------------------------------------------------------------*/
@@ -1172,6 +1174,31 @@ _nodesUidAroundNodes(UniqueArray<Int64>& own_nodes_uid_around_nodes)
11721174
/*---------------------------------------------------------------------------*/
11731175
/*---------------------------------------------------------------------------*/
11741176

1177+
void AMRCartesianMeshTesterModule::
1178+
_checkSync()
1179+
{
1180+
IMesh* mesh = m_cartesian_mesh->mesh();
1181+
Integer nb_error = 0;
1182+
1183+
VariableCellInt32 test_var(VariableBuildInfo(mesh, "ArcaneTestAMRCheckSync"));
1184+
test_var.fill(0);
1185+
ENUMERATE_ (Cell, icell, mesh->ownCells()) {
1186+
test_var[icell] = 1;
1187+
}
1188+
test_var.synchronize();
1189+
ENUMERATE_ (Cell, icell, mesh->allCells()) {
1190+
if (test_var[icell] != 1) {
1191+
nb_error++;
1192+
}
1193+
}
1194+
if (nb_error > 0) {
1195+
ARCANE_FATAL("Bad sync -- Nb error : {0}", nb_error);
1196+
}
1197+
}
1198+
1199+
/*---------------------------------------------------------------------------*/
1200+
/*---------------------------------------------------------------------------*/
1201+
11751202
void AMRCartesianMeshTesterModule::
11761203
_cellsInPatch(Real3 position, Real3 length, bool is_3d, Int32 level, UniqueArray<Int32>& cells_in_patch)
11771204
{

arcane/ceapart/tests/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ if (ARCANE_HAS_ACCELERATOR_API)
104104
arcane_add_accelerator_test_parallel_thread(material_sync2_v7 testMaterial-sync-2.arc 4 -We,ARCANE_MATSYNCHRONIZE_VERSION,7)
105105
arcane_add_accelerator_test_parallel_thread(material_sync2_vacc testMaterial-sync-2.arc 4 -We,ARCANE_ACC_MAT_SYNCHRONIZER,1)
106106

107+
ARCANE_ADD_TEST(material_sync3 testMaterial-sync-3.arc)
108+
ARCANE_ADD_TEST_PARALLEL_THREAD(material_sync3 testMaterial-sync-3.arc 4)
109+
107110
ARCANE_ADD_TEST(material3 testMaterial-3.arc "-m 20")
108111
# NOTE Ajoute test optmisation uniquement en sequentiel car pour l'instant cela
109112
# ne marche pas en parallele a cause de la suppression de mailles.

arcane/ceapart/tests/testAMRCartesianMesh2D-WithInitialCoarse-PatchCartesianMeshOnly-6.arc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
<length>2.0 2.0</length>
6464
</refinement-2d>
6565
<expected-number-of-cells-in-patchs>48 192 12 8 64 72</expected-number-of-cells-in-patchs>
66-
<expected-number-of-ghost-cells-in-patchs>72 288 12 8 160 168</expected-number-of-ghost-cells-in-patchs>
66+
<expected-number-of-ghost-cells-in-patchs>120 480 12 8 192 216</expected-number-of-ghost-cells-in-patchs>
6767
<nodes-uid-hash>133eed4a37931e6cd103f2fb12c354eb</nodes-uid-hash>
6868
<faces-uid-hash>0ba793345bd95bd20e83fc7cd6de9f02</faces-uid-hash>
6969
<cells-uid-hash>7eec15be89bd293981c7b92df927cb78</cells-uid-hash>

arcane/ceapart/tests/testAMRCartesianMesh2D-WithInitialCoarse-PatchCartesianMeshOnly-7.arc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
</refinement-2d>
4949

5050
<expected-number-of-cells-in-patchs>1600 6400 484</expected-number-of-cells-in-patchs>
51-
<expected-number-of-ghost-cells-in-patchs>336 1344 0</expected-number-of-ghost-cells-in-patchs>
51+
<expected-number-of-ghost-cells-in-patchs>516 2064 0</expected-number-of-ghost-cells-in-patchs>
5252
<nodes-uid-hash>be945c17467f6ba7bbf41ee1baf19c8c</nodes-uid-hash>
5353
<faces-uid-hash>c92d0e52cea7b406b449d57521f42124</faces-uid-hash>
5454
<cells-uid-hash>19dd0b9269462bd111611a5f0adac601</cells-uid-hash>

arcane/ceapart/tests/testAMRCartesianMesh2D-WithInitialCoarse-PatchCartesianMeshOnly-8.arc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<length>2.0 2.0</length>
6666
</refinement-2d>
6767
<expected-number-of-cells-in-patchs>1600 6400 484 1144 1936 3600 1600</expected-number-of-cells-in-patchs>
68-
<expected-number-of-ghost-cells-in-patchs>336 1344 0 0 352 480 640</expected-number-of-ghost-cells-in-patchs>
68+
<expected-number-of-ghost-cells-in-patchs>516 2064 0 0 528 720 960</expected-number-of-ghost-cells-in-patchs>
6969
<nodes-uid-hash>2ec1e04de3e4927fcb7578afedba1446</nodes-uid-hash>
7070
<faces-uid-hash>52335db38b14b6c2655b35770ea92dd2</faces-uid-hash>
7171
<cells-uid-hash>66dae987c5a023af83c87cd6131d86f4</cells-uid-hash>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="ISO-8859-1"?>
2+
<cas codename="ArcaneTest" xml:lang="fr" codeversion="1.0">
3+
<arcane>
4+
<titre>Test Material Synchronisation 3</titre>
5+
<description>Test Material Synchronisation 3</description>
6+
<boucle-en-temps>UnitTest</boucle-en-temps>
7+
</arcane>
8+
9+
<maillage amr-type="3" nb-ghostlayer="3" ghostlayer-builder-version="3">
10+
<meshgenerator>
11+
<cartesian>
12+
<nsd>2 2</nsd>
13+
<origine>0.0 0.0</origine>
14+
<lx nx='16'>16.0</lx>
15+
<ly ny='16'>16.0</ly>
16+
</cartesian>
17+
</meshgenerator>
18+
</maillage>
19+
20+
<module-test-unitaire>
21+
<test name="MeshMaterialSyncUnitTest">
22+
<nb-material>24</nb-material>
23+
</test>
24+
</module-test-unitaire>
25+
</cas>

arcane/src/arcane/cartesianmesh/CartesianMeshAMRPatchMng.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
22
//-----------------------------------------------------------------------------
3-
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3+
// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
44
// See the top-level COPYRIGHT file for details.
55
// SPDX-License-Identifier: Apache-2.0
66
//-----------------------------------------------------------------------------
77
/*---------------------------------------------------------------------------*/
8-
/* CartesianMeshAMRPatchMng.cc (C) 2000-2024 */
8+
/* CartesianMeshAMRPatchMng.cc (C) 2000-2025 */
99
/* */
1010
/* Gestionnaire de l'AMR par patch d'un maillage cartésien. */
1111
/*---------------------------------------------------------------------------*/
@@ -1904,6 +1904,9 @@ refine()
19041904
}
19051905
}
19061906

1907+
// Recalcule les informations de synchronisation.
1908+
m_mesh->computeSynchronizeInfos();
1909+
19071910
// ENUMERATE_(Cell, icell, m_mesh->allCells()){
19081911
// debug() << "\t" << *icell;
19091912
// for(Node node : icell->nodes()){
@@ -1975,7 +1978,12 @@ coarse()
19751978
if (version < 3)
19761979
gm->setBuilderVersion(3);
19771980
Int32 nb_ghost_layer = gm->nbGhostLayer();
1978-
gm->setNbGhostLayer(nb_ghost_layer + (nb_ghost_layer % m_num_mng->pattern()));
1981+
// TODO AH : Cette ligne permettrait d'avoir moins de mailles fantômes et
1982+
// d'éviter leurs suppressions en cas d'inutilité. Mais le comportement
1983+
// serait différent de l'AMR historique.
1984+
//gm->setNbGhostLayer(nb_ghost_layer + (nb_ghost_layer % m_num_mng->pattern()));
1985+
// Comportement de l'AMR historique.
1986+
gm->setNbGhostLayer(nb_ghost_layer * 2);
19791987
mesh_modifier->setDynamic(true);
19801988
mesh_modifier->updateGhostLayers();
19811989
// Remet le nombre initial de couches de mailles fantômes

arcane/src/arcane/materials/MeshMaterialSynchronizer.cc

Lines changed: 80 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
22
//-----------------------------------------------------------------------------
3-
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3+
// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
44
// See the top-level COPYRIGHT file for details.
55
// SPDX-License-Identifier: Apache-2.0
66
//-----------------------------------------------------------------------------
77
/*---------------------------------------------------------------------------*/
8-
/* MeshMaterialSynchronizer.cc (C) 2000-2024 */
8+
/* MeshMaterialSynchronizer.cc (C) 2000-2025 */
99
/* */
1010
/* Synchronisation des entités des matériaux. */
1111
/*---------------------------------------------------------------------------*/
1212
/*---------------------------------------------------------------------------*/
1313

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

16-
#include "arcane/VariableTypes.h"
17-
#include "arcane/IParallelMng.h"
18-
#include "arcane/ItemPrinter.h"
19-
#include "arcane/IMesh.h"
20-
2116
#include "arcane/materials/CellToAllEnvCellConverter.h"
2217
#include "arcane/materials/MatItemEnumerator.h"
2318
#include "arcane/materials/MeshMaterialModifier.h"
2419

20+
#include "arcane/utils/HashSuite.h"
21+
22+
#include "arcane/core/VariableTypes.h"
23+
#include "arcane/core/IParallelMng.h"
24+
#include "arcane/core/ItemPrinter.h"
25+
#include "arcane/core/IMesh.h"
2526
#include "arcane/core/ItemGenericInfoListView.h"
2627

2728
/*---------------------------------------------------------------------------*/
@@ -90,10 +91,15 @@ checkMaterialsInCells(Integer max_print)
9091
if (!mesh->parallelMng()->isParallel())
9192
return;
9293
m_material_mng->checkValid();
94+
9395
info(4) << "CheckMaterialsInCells";
96+
9497
VariableCellInt32 indexes(VariableBuildInfo(mesh,"ArcaneMaterialPresenceIndexes"));
95-
_checkComponents(indexes,m_material_mng->materialsAsComponents(),max_print);
96-
_checkComponents(indexes,m_material_mng->environmentsAsComponents(),max_print);
98+
_checkComponents(indexes, m_material_mng->materialsAsComponents(), max_print);
99+
_checkComponents(indexes, m_material_mng->environmentsAsComponents(), max_print);
100+
101+
VariableCellInt64 hashes(VariableBuildInfo(mesh, "ArcaneMaterialCheckHashes"));
102+
_checkComponentsInGhostCells(hashes, max_print);
97103
}
98104

99105
/*---------------------------------------------------------------------------*/
@@ -143,6 +149,71 @@ _checkComponents(VariableCellInt32& indexes,
143149
ARCANE_FATAL("Bad synchronisation");
144150
}
145151

152+
void MeshMaterialSynchronizer::
153+
_checkComponentsInGhostCells(VariableCellInt64& hashes, Integer max_print)
154+
{
155+
IMesh* mesh = m_material_mng->mesh();
156+
Integer nb_error = 0;
157+
158+
ENUMERATE_ALLENVCELL (iallenvcell, m_material_mng, mesh->ownCells()) {
159+
AllEnvCell all_env_cell = *iallenvcell;
160+
Cell cell = all_env_cell.globalCell();
161+
162+
IntegerHashSuite hash_suite;
163+
164+
Int32 nb_env = all_env_cell.nbEnvironment();
165+
hash_suite.add(nb_env);
166+
167+
for (Integer i = 0; i < nb_env; ++i) {
168+
EnvCell env_cell = all_env_cell.cell(i);
169+
Int32 nb_matt = env_cell.nbMaterial();
170+
hash_suite.add(nb_matt);
171+
172+
for (Integer j = 0; j < nb_matt; ++j) {
173+
MatCell mat = env_cell.cell(j);
174+
Int32 id = mat.materialId();
175+
hash_suite.add(id);
176+
}
177+
}
178+
179+
hashes[cell] = hash_suite.hash();
180+
}
181+
182+
hashes.synchronize();
183+
184+
ENUMERATE_ALLENVCELL (iallenvcell, m_material_mng, mesh->allCells()) {
185+
AllEnvCell all_env_cell = *iallenvcell;
186+
Cell cell = all_env_cell.globalCell();
187+
if (cell.isOwn())
188+
continue;
189+
190+
IntegerHashSuite hash_suite;
191+
192+
Int32 nb_env = all_env_cell.nbEnvironment();
193+
hash_suite.add(nb_env);
194+
195+
for (Integer i = 0; i < nb_env; ++i) {
196+
EnvCell env_cell = all_env_cell.cell(i);
197+
Int32 nb_matt = env_cell.nbMaterial();
198+
hash_suite.add(nb_matt);
199+
200+
for (Integer j = 0; j < nb_matt; ++j) {
201+
MatCell mat = env_cell.cell(j);
202+
Int32 id = mat.materialId();
203+
hash_suite.add(id);
204+
}
205+
}
206+
if (hashes[cell] != hash_suite.hash()) {
207+
nb_error++;
208+
if (max_print < 0 || nb_error < max_print) {
209+
error() << "Bad components synchronization -- Cell : " << cell << " -- Hash : " << hash_suite.hash();
210+
}
211+
}
212+
}
213+
if (nb_error != 0)
214+
ARCANE_FATAL("Bad components synchronization -- Nb error : {0}", nb_error);
215+
}
216+
146217
/*---------------------------------------------------------------------------*/
147218
/*---------------------------------------------------------------------------*/
148219

arcane/src/arcane/materials/internal/MeshMaterialSynchronizer.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
22
//-----------------------------------------------------------------------------
3-
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3+
// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
44
// See the top-level COPYRIGHT file for details.
55
// SPDX-License-Identifier: Apache-2.0
66
//-----------------------------------------------------------------------------
77
/*---------------------------------------------------------------------------*/
8-
/* MeshMaterialSynchronizer.h (C) 2000-2024 */
8+
/* MeshMaterialSynchronizer.h (C) 2000-2025 */
99
/* */
1010
/* Synchronisation de la liste des matériaux/milieux des entités. */
1111
/*---------------------------------------------------------------------------*/
@@ -17,7 +17,7 @@
1717
#include "arcane/utils/TraceAccessor.h"
1818
#include "arcane/utils/ArrayView.h"
1919

20-
#include "arcane/VariableTypedef.h"
20+
#include "arcane/core/VariableTypedef.h"
2121

2222
#include "arcane/materials/MaterialsGlobal.h"
2323
#include "arcane/materials/MatItem.h"
@@ -77,6 +77,8 @@ class MeshMaterialSynchronizer
7777
void _checkComponents(VariableCellInt32& indexes,
7878
ConstArrayView<IMeshComponent*> components,
7979
Integer max_print);
80+
void _checkComponentsInGhostCells(VariableCellInt64& hashes,
81+
Integer max_print);
8082
};
8183

8284
/*---------------------------------------------------------------------------*/

arcane/src/arcane/utils/HashSuite.h

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2+
//-----------------------------------------------------------------------------
3+
// Copyright 2000-2025 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+
/* HashSuite.h (C) 2000-2025 */
9+
/* */
10+
/* Fonction de hachage d'une suite de valeur. */
11+
/*---------------------------------------------------------------------------*/
12+
#ifndef ARCANE_UTILS_HASHSUITE_H
13+
#define ARCANE_UTILS_HASHSUITE_H
14+
/*---------------------------------------------------------------------------*/
15+
/*---------------------------------------------------------------------------*/
16+
17+
#include "arcane/utils/HashFunction.h"
18+
19+
/*---------------------------------------------------------------------------*/
20+
/*---------------------------------------------------------------------------*/
21+
22+
namespace Arcane
23+
{
24+
25+
/*---------------------------------------------------------------------------*/
26+
/*---------------------------------------------------------------------------*/
27+
28+
/*!
29+
* \internal
30+
* \brief Classe permettant de calculer un hash de manière itératif.
31+
* \warning L'ordre dans lequel les valeurs sont données via la méthode add() est important.
32+
*/
33+
34+
class IntegerHashSuite
35+
{
36+
public:
37+
38+
/*!
39+
* \brief Méthode permettant d'ajouter une valeur dans le calcul du hash.
40+
* \warning L'ordre dans lequel les valeurs sont données via la méthode
41+
* add() est important.
42+
* \param value La valeur à ajouter.
43+
*/
44+
template <class T>
45+
void add(T value)
46+
{
47+
const UInt64 next_hash = static_cast<UInt64>(IntegerHashFunctionT<T>::hashfunc(value));
48+
m_hash ^= next_hash + 0x9e3779b9 + (m_hash << 6) + (m_hash >> 2);
49+
}
50+
51+
/*!
52+
* \brief Méthode permettant de récupérer le hash calculé à partir de
53+
* toutes les valeurs passées à la méthode add().
54+
* \return Le hash.
55+
*/
56+
Int64 hash() const
57+
{
58+
return static_cast<Int64>(m_hash);
59+
}
60+
61+
private:
62+
63+
UInt64 m_hash{0};
64+
};
65+
66+
/*---------------------------------------------------------------------------*/
67+
/*---------------------------------------------------------------------------*/
68+
69+
} // End namespace Arcane
70+
71+
/*---------------------------------------------------------------------------*/
72+
/*---------------------------------------------------------------------------*/
73+
74+
#endif

0 commit comments

Comments
 (0)