Arcane  v3.15.0.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
CartesianMeshTestUtils.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2024 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/* CartesianMeshTestUtils.cc (C) 2000-2024 */
9/* */
10/* Fonctions utilitaires pour les tests de 'CartesianMesh'. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/tests/CartesianMeshTestUtils.h"
15
16#include "arcane/utils/CheckedConvert.h"
17#include "arcane/utils/PlatformUtils.h"
18#include "arcane/utils/Real2.h"
19#include "arcane/utils/ValueChecker.h"
20
22
23#include "arcane/core/IMesh.h"
24#include "arcane/core/IItemFamily.h"
25#include "arcane/core/ItemPrinter.h"
26#include "arcane/core/IParallelMng.h"
27#include "arcane/core/IMeshModifier.h"
28#include "arcane/core/IMeshUtilities.h"
29#include "arcane/core/SimpleSVGMeshExporter.h"
30#include "arcane/core/UnstructuredMeshConnectivity.h"
31
32#if defined(ARCANE_HAS_ACCELERATOR_API)
33#include "arcane/accelerator/Runner.h"
36#endif
37#include "arcane/accelerator/core/IAcceleratorMng.h"
38
39#include "arcane/cartesianmesh/ICartesianMesh.h"
40#include "arcane/cartesianmesh/CellDirectionMng.h"
41#include "arcane/cartesianmesh/FaceDirectionMng.h"
42#include "arcane/cartesianmesh/NodeDirectionMng.h"
43#include "arcane/cartesianmesh/CartesianConnectivity.h"
44
45/*---------------------------------------------------------------------------*/
46/*---------------------------------------------------------------------------*/
47
48namespace ArcaneTest
49{
50
51using namespace Arcane;
52using namespace Arcane::Accelerator;
53
54/*---------------------------------------------------------------------------*/
55/*---------------------------------------------------------------------------*/
56
57CartesianMeshTestUtils::
58CartesianMeshTestUtils(ICartesianMesh* cm, IAcceleratorMng* am)
59: TraceAccessor(cm->traceMng())
60, m_cartesian_mesh(cm)
61, m_mesh(cm->mesh())
62, m_accelerator_mng(am)
63, m_cell_center(VariableBuildInfo(m_mesh, "CellCenter"))
64, m_face_center(VariableBuildInfo(m_mesh, "FaceCenter"))
65, m_node_density(VariableBuildInfo(m_mesh, "NodeDensity"))
66{
67}
68
69/*---------------------------------------------------------------------------*/
70/*---------------------------------------------------------------------------*/
71
72CartesianMeshTestUtils::
73~CartesianMeshTestUtils()
74{
75}
76
77/*---------------------------------------------------------------------------*/
78/*---------------------------------------------------------------------------*/
79
80void CartesianMeshTestUtils::
81testAll(bool is_amr)
82{
83 m_is_amr = is_amr;
84 _testDirCell();
85 _testDirCellAccelerator();
86 _testDirFace();
87 _testDirFaceAccelerator();
88 _testDirNode();
89 _testDirNodeAccelerator();
90 _testDirCellNode();
91 _testDirCellNodeAccelerator();
92 _testDirCellFace();
93 _testDirCellFaceAccelerator();
94 if (m_mesh->dimension() == 3) {
95 _testNodeToCellConnectivity3D();
96 _testNodeToCellConnectivity3DAccelerator();
97 _testCellToNodeConnectivity3D();
98 _testCellToNodeConnectivity3DAccelerator();
99 }
100 else {
101 _testNodeToCellConnectivity2D();
102 _testCellToNodeConnectivity2D();
103 _saveSVG();
104 }
105 _testConnectivityByDirection();
106}
107
108/*---------------------------------------------------------------------------*/
109/*---------------------------------------------------------------------------*/
110
111void CartesianMeshTestUtils::
112_computeCenters()
113{
114 IMesh* mesh = m_mesh;
115
116 // Calcule le centre des mailles
117 {
119 ENUMERATE_CELL (icell, m_mesh->allCells()) {
120 Cell cell = *icell;
121 Real3 center;
122 for (NodeLocalId inode : cell.nodeIds() )
123 center += nodes_coord[inode];
124 center /= cell.nbNode();
125 m_cell_center[icell] = center;
126 }
127 }
128
129 // Calcule le centre des faces
130 {
132 ENUMERATE_FACE (iface, m_mesh->allFaces()) {
133 Face face = *iface;
134 Real3 center;
135 for (NodeLocalId inode : face.nodeIds() )
136 center += nodes_coord[inode];
137 center /= face.nbNode();
138 m_face_center[iface] = center;
139 }
140 }
141}
142
143/*---------------------------------------------------------------------------*/
144/*---------------------------------------------------------------------------*/
145
146void CartesianMeshTestUtils::
147_checkSameId(FaceLocalId item, FaceLocalId local_id)
148{
149 if (item != local_id)
150 ARCANE_FATAL("Bad FaceLocalId item={0} local_id={1}", item, local_id);
151}
152
153void CartesianMeshTestUtils::
154_checkSameId(CellLocalId item, CellLocalId local_id)
155{
156 if (item != local_id)
157 ARCANE_FATAL("Bad CellLocalId item={0} local_id={1}", item, local_id);
158}
159
160void CartesianMeshTestUtils::
161_checkSameId(NodeLocalId item, NodeLocalId local_id)
162{
163 if (item.localId() != local_id)
164 ARCANE_FATAL("Bad NodeLocalId item={0} local_id={1}", item, local_id);
165}
166
167/*---------------------------------------------------------------------------*/
168/*---------------------------------------------------------------------------*/
169
170void CartesianMeshTestUtils::
171_checkItemGroupIsSorted(const ItemGroup& group)
172{
173 if (!group.checkIsSorted())
174 ARCANE_FATAL("Node direction group '{0}' is not sorted", group.name());
175}
176
177/*---------------------------------------------------------------------------*/
178/*---------------------------------------------------------------------------*/
179
180void CartesianMeshTestUtils::
181_testDirCell()
182{
183 info() << "TEST_DIR_CELL";
184
185 IMesh* mesh = m_mesh;
186 Integer nb_dir = mesh->dimension();
187 Integer nb_print = m_nb_print;
190 for (Integer idir = 0; idir < nb_dir; ++idir) {
191 CellDirectionMng cdm(m_cartesian_mesh->cellDirection(idir));
192 cdm2 = m_cartesian_mesh->cellDirection(idir);
193 cdm3 = cdm;
194 eMeshDirection md = cdm.direction();
195 Integer iprint = 0;
196 info() << "DIRECTION=" << idir << " Cells=" << cdm.allCells().name();
197 _checkItemGroupIsSorted(cdm.allCells());
198 ENUMERATE_CELL (icell, cdm.allCells()) {
199 Cell cell = *icell;
201 Cell prev_cell = dir_cell.previous();
202 Cell next_cell = dir_cell.next();
203 // AH: Désactivation de ce if : bloquant s'il n'y a qu'une seule couche de mailles.
204 // if (prev_cell.null() && next_cell.null())
205 // ARCANE_FATAL("Null previous and next cell");
207 Cell prev_cell2 = dir_cell2.previous();
208 Cell next_cell2 = dir_cell2.next();
210 Cell prev_cell3 = dir_cell3.previous();
211 Cell next_cell3 = dir_cell3.next();
212 _checkSameId(prev_cell, prev_cell2);
213 _checkSameId(next_cell, next_cell2);
214 _checkSameId(prev_cell, prev_cell3);
215 _checkSameId(next_cell, next_cell3);
216 if (nb_print < 0 || iprint < nb_print) {
217 ++iprint;
218 if (!prev_cell.null() && !next_cell.null()) {
219 info() << "Cell uid=" << ItemPrinter(cell) << " dir=" << md
220 << " prev=" << ItemPrinter(prev_cell) << " xyz=" << m_cell_center[prev_cell]
221 << " next=" << ItemPrinter(next_cell) << " xyz=" << m_cell_center[next_cell];
222 }
223 else {
224 info() << "Cell uid=" << ItemPrinter(cell) << " dir=" << md;
225 if (!prev_cell.null())
226 info() << " prev=" << ItemPrinter(prev_cell) << " xyz=" << m_cell_center[prev_cell];
227 if (!next_cell.null())
228 info() << " next=" << ItemPrinter(next_cell) << " xyz=" << m_cell_center[next_cell];
229 }
230 }
231 }
232 }
233}
234
235/*---------------------------------------------------------------------------*/
236/*---------------------------------------------------------------------------*/
237
238void CartesianMeshTestUtils::
239_testDirCellAccelerator()
240{
241#if defined(ARCANE_HAS_ACCELERATOR_API)
242 info() << "TEST_DIR_CELL_ACCELERATOR";
243
244 IMesh* mesh = m_mesh;
245 Integer nb_dir = mesh->dimension();
248
249 auto queue = m_accelerator_mng->queue();
250
251 VariableCellInt32 dummy_var(VariableBuildInfo(mesh, "DummyCellVariable"));
252 dummy_var.fill(0);
253
254 for (Integer idir = 0; idir < nb_dir; ++idir) {
255 CellDirectionMng cdm(m_cartesian_mesh->cellDirection(idir));
256 cdm2 = m_cartesian_mesh->cellDirection(idir);
257 cdm3 = cdm;
258 info() << "ACCELERATOR_DIRECTION=" << idir << " Cells=" << cdm.allCells().name();
259 _checkItemGroupIsSorted(cdm.allCells());
260 auto command = makeCommand(queue);
261 auto inout_dummy_var = viewInOut(command, dummy_var);
262 command << RUNCOMMAND_ENUMERATE(Cell, icell, cdm.allCells())
263 {
264 DirCellLocalId dir_cell(cdm.dirCellId(icell));
265 CellLocalId prev_cell = dir_cell.previous();
267 // AH: Désactivation de ce if : bloquant s'il n'y a qu'une seule couche de mailles.
268 // if (prev_cell.isNull() && next_cell.isNull()) {
269 // inout_dummy_var[icell] = -5;
270 // return;
271 // }
272
274 CellLocalId prev_cell2 = dir_cell2.previous();
277 CellLocalId prev_cell3 = dir_cell3.previous();
279 if (prev_cell != prev_cell2)
280 inout_dummy_var[icell] = -10;
281 if (next_cell != next_cell2)
282 inout_dummy_var[icell] = -11;
283 if (prev_cell != prev_cell3)
284 inout_dummy_var[icell] = -12;
285 if (next_cell != next_cell3)
286 inout_dummy_var[icell] = -13;
287
288 if (!prev_cell.isNull() && !next_cell.isNull()) {
290 }
291 else {
292 if (!prev_cell.isNull())
294 if (!next_cell.isNull())
296 }
297 };
298 ENUMERATE_ (Cell, icell, cdm.allCells()) {
299 if (dummy_var[icell] < 0)
300 ARCANE_FATAL("Bad value for dummy_var id={0} v={1}", ItemPrinter(*icell), dummy_var[icell]);
301 }
302 }
303#endif
304}
305
306/*---------------------------------------------------------------------------*/
307/*---------------------------------------------------------------------------*/
308
309void CartesianMeshTestUtils::
310_testDirFace()
311{
312 IMesh* mesh = m_mesh;
313 Integer nb_dir = mesh->dimension();
314 for (Integer idir = 0; idir < nb_dir; ++idir)
315 _testDirFace(idir);
316}
317
318/*---------------------------------------------------------------------------*/
319/*---------------------------------------------------------------------------*/
320
321void CartesianMeshTestUtils::
322_testDirFaceAccelerator()
323{
324 IMesh* mesh = m_mesh;
325 Integer nb_dir = mesh->dimension();
326 for (Integer idir = 0; idir < nb_dir; ++idir)
327 _testDirFaceAccelerator(idir);
328}
329
330/*---------------------------------------------------------------------------*/
331/*---------------------------------------------------------------------------*/
332
333void CartesianMeshTestUtils::
334_testDirFace(int idir)
335{
336 // Teste l'utilisation de DirFace et vérifie que
337 // les valeurs sont correctes: pour une face donnée,
338 // il faut que selon la direction choisie, la coordonnée du centre
339 // de la maille avant (previousCell()) soit inférieure à celle
340 // de la maille après (nextCell()) et aussi celle de la maille avant
341 // soit inférieure à ce
342 Integer nb_print = m_nb_print;
343 Integer nb_error = 0;
344 Integer iprint = 0;
345
347 FaceDirectionMng fdm(m_cartesian_mesh->faceDirection(idir));
348 fdm2 = fdm;
349 eMeshDirection md = fdm.direction();
350 info() << "TEST_DIR_FACE for direction=" << idir << " -> " << (eMeshDirection)idir;
351 _checkItemGroupIsSorted(fdm.allFaces());
352 ENUMERATE_FACE (iface, fdm.allFaces()) {
353 Face face = *iface;
354 DirFace dir_face(fdm[iface]);
356 //Integer nb_node = cell.nbNode();
357 Cell prev_cell = dir_face.previousCell();
358 Cell next_cell = dir_face.nextCell();
359 Cell prev_cell2 = dir_face2.previousCell();
360 Cell next_cell2 = dir_face2.nextCell();
361 _checkSameId(prev_cell, prev_cell2);
362 _checkSameId(next_cell, next_cell2);
363 _checkSameId(prev_cell, dir_face.previousCellId());
364 _checkSameId(next_cell, dir_face.nextCellId());
365 bool is_print = (nb_print < 0 || iprint < nb_print);
366 ++iprint;
367 Real face_coord = m_face_center[iface][idir];
368 if (!prev_cell.null() && !next_cell.null()) {
369 Real next_coord = m_cell_center[next_cell][idir];
370 Real prev_coord = m_cell_center[prev_cell][idir];
371 if (next_coord < prev_coord) {
372 info() << "Bad ordering for face";
373 is_print = true;
374 ++nb_error;
375 }
376 if (is_print)
377 info() << "Face uid=" << ItemPrinter(face) << " dir=" << md << " xyz=" << m_face_center[iface]
378 << " prev=" << prev_cell.uniqueId() << " xyz=" << m_cell_center[prev_cell]
379 << " next=" << next_cell.uniqueId() << " xyz=" << m_cell_center[next_cell];
380 }
381 else {
382 if (!prev_cell.null()) {
383 Real prev_coord = m_cell_center[prev_cell][idir];
384 if (face_coord < prev_coord) {
385 info() << "Bad ordering for face";
386 is_print = true;
387 ++nb_error;
388 }
389 if (is_print)
390 info() << "Face uid=" << ItemPrinter(face) << " dir=" << md << " xyz=" << m_face_center[iface]
391 << " prev=" << prev_cell.uniqueId() << " xyz=" << m_cell_center[prev_cell];
392 }
393 if (!next_cell.null()) {
394 Real next_coord = m_cell_center[next_cell][idir];
395 if (next_coord < face_coord) {
396 info() << "Bad ordering for face";
397 is_print = true;
398 ++nb_error;
399 }
400 if (is_print)
401 info() << "Face uid=" << ItemPrinter(face) << " dir=" << md << " xyz=" << m_face_center[iface]
402 << " next=" << next_cell.uniqueId() << " xyz=" << m_cell_center[next_cell];
403 }
404 }
405 }
406 if (nb_error != 0)
407 ARCANE_FATAL("Bad connectivity for DirFace nb_error={0}", nb_error);
408}
409
410/*---------------------------------------------------------------------------*/
411/*---------------------------------------------------------------------------*/
412
413void CartesianMeshTestUtils::
414_testDirFaceAccelerator(int idir)
415{
416#if defined(ARCANE_HAS_ACCELERATOR_API)
417 // Teste l'utilisation de DirFace et vérifie que
418 // les valeurs sont correctes: pour une face donnée,
419 // il faut que selon la direction choisie, la coordonnée du centre
420 // de la maille avant (previousCell()) soit inférieure à celle
421 // de la maille après (nextCell()) et aussi celle de la maille avant
422 // soit inférieure à ce
423
425 FaceDirectionMng fdm(m_cartesian_mesh->faceDirection(idir));
426 fdm2 = fdm;
427 info() << "TEST_DIR_FACE_ACCELERATOR for direction=" << idir << " -> " << (eMeshDirection)idir;
428
429 auto queue = m_accelerator_mng->defaultQueue();
430 auto command = makeCommand(*queue);
431
432 VariableFaceInt32 dummy_var(VariableBuildInfo(m_mesh, "DummyFaceVariable"));
433 dummy_var.fill(0);
434 auto inout_dummy_var = viewInOut(command, dummy_var);
435 auto in_face_center = viewIn(command, m_face_center);
436 auto in_cell_center = viewIn(command, m_cell_center);
437
438 command << RUNCOMMAND_ENUMERATE(Face, iface, fdm.allFaces())
439 {
440 DirFaceLocalId dir_face(fdm.dirFaceId(iface));
442 //Integer nb_node = cell.nbNode();
443 CellLocalId prev_cell = dir_face.previousCell();
444 CellLocalId next_cell = dir_face.nextCell();
445 CellLocalId prev_cell2 = dir_face2.previousCell();
446 CellLocalId next_cell2 = dir_face2.nextCell();
447 if (prev_cell != prev_cell2)
448 inout_dummy_var[iface] = -10;
449 if (next_cell != next_cell2)
450 inout_dummy_var[iface] = -11;
451 if (prev_cell != dir_face.previousCellId())
452 inout_dummy_var[iface] = -12;
453 if (next_cell != dir_face.nextCellId())
454 inout_dummy_var[iface] = -13;
455 if (inout_dummy_var[iface] < 0)
456 return;
457
459 if (!prev_cell.isNull() && !next_cell.isNull()) {
462 if (next_coord < prev_coord) {
463 inout_dummy_var[iface] = -20;
464 return;
465 }
466 }
467 else {
468 if (!prev_cell.isNull()) {
470 if (face_coord < prev_coord) {
471 inout_dummy_var[iface] = -21;
472 return;
473 }
474 }
475 if (!next_cell.isNull()) {
477 if (next_coord < face_coord) {
478 inout_dummy_var[iface] = -22;
479 return;
480 }
481 }
482 }
483 };
484
485 ENUMERATE_ (Face, iface, fdm.allFaces()) {
486 if (dummy_var[iface] < 0)
487 ARCANE_FATAL("Bad value for dummy_var id={0} v={1}", ItemPrinter(*iface), dummy_var[iface]);
488 }
489#endif
490}
491
492/*---------------------------------------------------------------------------*/
493/*---------------------------------------------------------------------------*/
494
495void CartesianMeshTestUtils::
496_testDirNode()
497{
498 info() << "TEST_DIR_NODE";
499 m_node_density.fill(0.0);
500
501 IMesh* mesh = m_mesh;
502 Integer nb_dir = mesh->dimension();
503 Integer nb_print = m_nb_print;
504 Integer nb_error = 0;
506 // Pour tester l'opérateur 'operator='
509 for (Integer idir = 0; idir < nb_dir; ++idir) {
510 NodeDirectionMng node_dm(m_cartesian_mesh->nodeDirection(idir));
511 node_dm2 = m_cartesian_mesh->nodeDirection(idir);
513 eMeshDirection md = node_dm.direction();
514 Integer iprint = 0;
515 info() << "DIRECTION=" << idir;
516 NodeGroup dm_all_nodes = node_dm.allNodes();
517 _checkItemGroupIsSorted(dm_all_nodes);
519 Node node = *inode;
520 m_node_density[inode] += 1.0;
524 Node prev_node = dir_node.previous();
525 Node next_node = dir_node.next();
526 Node prev_node2 = dir_node2.previous();
527 Node next_node2 = dir_node2.next();
528 Node prev_node3 = dir_node3.previous();
529 Node next_node3 = dir_node3.next();
530 _checkSameId(prev_node, prev_node2);
531 _checkSameId(next_node, next_node2);
532 _checkSameId(prev_node, prev_node3);
533 _checkSameId(next_node, next_node3);
534 _checkSameId(prev_node, dir_node.previousId());
535 _checkSameId(next_node, dir_node.nextId());
537 bool is_print = (nb_print < 0 || iprint < nb_print);
538 ++iprint;
539 if (is_print) {
540 Int32 node_nb_cell = node.nbCell();
541 info() << "DirNode node= " << ItemPrinter(node) << " nb_cell=" << node_nb_cell << " pos=" << nodes_coord[node];
542 for (Integer k = 0; k < node_nb_cell; ++k) {
543 Real3 cell_pos = m_cell_center[node.cell(k)];
544 info() << "Node k=" << k << " cell_pos=" << cell_pos << " cell=" << ItemPrinter(node.cell(k));
545 }
546 for (Integer k = 0; k < 8; ++k) {
547 Int32 cell_index = dir_node.cellIndex(k);
549 if (cell_index != (-1)) {
550 if ((1 + cell_index) > node_nb_cell)
551 ARCANE_FATAL("Bad value for cell_index '{0}' node_nb_cell={1}", cell_index, node_nb_cell);
552 cell_pos = m_cell_center[node.cell(cell_index)];
553 }
554 info() << "DirNode cellIndex k=" << k << " index=" << cell_index << " pos=" << cell_pos
555 << " cell_lid=" << dir_node.cellId(k)
556 << " cell=" << dir_node.cell(k);
557 }
558 info() << "DirNode direct "
559 << " " << dir_node.nextLeftCellId()
560 << " " << dir_node.nextRightCellId()
561 << " " << dir_node.previousRightCellId()
562 << " " << dir_node.previousLeftCellId()
563 << " " << dir_node.topNextLeftCellId()
564 << " " << dir_node.topNextRightCellId()
565 << " " << dir_node.topPreviousRightCellId()
566 << " " << dir_node.topPreviousLeftCellId();
567 info() << "DirNode direct "
568 << " " << ItemPrinter(dir_node.nextLeftCell())
569 << " " << ItemPrinter(dir_node.nextRightCell())
570 << " " << ItemPrinter(dir_node.previousRightCell())
571 << " " << ItemPrinter(dir_node.previousLeftCell())
572 << " " << ItemPrinter(dir_node.topNextLeftCell())
573 << " " << ItemPrinter(dir_node.topNextRightCell())
574 << " " << ItemPrinter(dir_node.topPreviousRightCell())
575 << " " << ItemPrinter(dir_node.topPreviousLeftCell());
576 }
577 if (prev_node.null() && next_node.null())
578 ARCANE_FATAL("Null previous and next node for node {0}", ItemPrinter(node));
579 //TODO: Vérifier que les coordonnées autres que celle de idir sont bien les mêmes pour next,prev et my_coord.
580 if (!prev_node.null() && !next_node.null()) {
583 if (next_coord < prev_coord) {
584 info() << "Bad ordering for node";
585 is_print = true;
586 ++nb_error;
587 }
588 if (is_print)
589 info() << "Node uid=" << ItemPrinter(node) << " dir=" << md
590 << " prev=" << ItemPrinter(prev_node) << " xyz=" << prev_coord
591 << " next=" << ItemPrinter(next_node) << " xyz=" << next_coord;
592 }
593 else {
594 if (!prev_node.null()) {
596 if (my_coord < prev_coord) {
597 info() << "Bad ordering for node";
598 is_print = true;
599 ++nb_error;
600 }
601 if (is_print)
602 info() << "Node uid=" << ItemPrinter(node) << " dir=" << md
603 << " prev=" << ItemPrinter(prev_node) << " xyz=" << nodes_coord[prev_node];
604 }
605 if (!next_node.null()) {
607 if (next_coord < my_coord) {
608 info() << "Bad ordering for node";
609 is_print = true;
610 ++nb_error;
611 }
612 if (is_print)
613 info() << "Node uid=" << ItemPrinter(node) << " dir=" << md
614 << " next=" << ItemPrinter(next_node) << " xyz=" << nodes_coord[next_node];
615 }
616 }
617 }
618 }
619
620 if (nb_error != 0)
621 ARCANE_FATAL("Bad connectivity for DirNode");
622
623 // Vérifie qu'on a parcouru tous les noeuds
624 ENUMERATE_NODE (inode, m_mesh->allNodes()) {
625 Node node = *inode;
626 if (node.cell(0).level() != 0)
627 continue;
628 if (m_node_density[inode] == 0.0) {
629 ++nb_error;
630 info() << "Bad value for node " << ItemPrinter(node);
631 }
632 }
633 if (nb_error != 0)
634 ARCANE_FATAL("Bad values for DirNode");
635}
636
637/*---------------------------------------------------------------------------*/
638/*---------------------------------------------------------------------------*/
639
640void CartesianMeshTestUtils::
641_testDirNodeAccelerator()
642{
643#if defined(ARCANE_HAS_ACCELERATOR_API)
644 info() << "TEST_DIR_NODE Accelerator";
645 m_node_density.fill(0.0);
646
647 IMesh* mesh = m_mesh;
648 Integer nb_dir = mesh->dimension();
650 // Pour tester l'opérateur 'operator='
653
654 //auto in_face_center = viewIn(command, m_face_center);
655 //auto in_cell_center = viewIn(command, m_cell_center);
656
657 VariableNodeInt32 dummy_var(VariableBuildInfo(m_mesh, "DummyNodeVariable"));
658
660 m_connectivity_view.setMesh(mesh);
661 auto cnc = m_connectivity_view.nodeCell();
662
663 for (Integer idir = 0; idir < nb_dir; ++idir) {
664 NodeDirectionMng node_dm(m_cartesian_mesh->nodeDirection(idir));
665 node_dm2 = m_cartesian_mesh->nodeDirection(idir);
667 info() << "DIRECTION=" << idir;
668 NodeGroup dm_all_nodes = node_dm.allNodes();
669 _checkItemGroupIsSorted(dm_all_nodes);
670
671 auto queue = m_accelerator_mng->defaultQueue();
672 auto command = makeCommand(*queue);
673
674 dummy_var.fill(0);
675 auto inout_dummy_var = viewInOut(command, dummy_var);
676 auto in_nodes_coord = viewInOut(command, nodes_coord);
677
678 command << RUNCOMMAND_ENUMERATE(Node, node, dm_all_nodes)
679 {
680 DirNodeLocalId dir_node(node_dm.dirNodeId(node));
681 DirNodeLocalId dir_node2(node_dm2.dirNodeId(node));
682 DirNodeLocalId dir_node3(node_dm3.dirNodeId(node));
683 NodeLocalId prev_node = dir_node.previous();
685 NodeLocalId prev_node2 = dir_node2.previous();
687 NodeLocalId prev_node3 = dir_node3.previous();
689 Int32 vx = 0;
690 if (prev_node != prev_node2)
691 vx = -10;
692 if (next_node != next_node2)
693 vx = -11;
694 if (prev_node != prev_node3)
695 vx = -12;
696 if (next_node != next_node3)
697 vx = -13;
698 if (prev_node != dir_node.previousId())
699 vx = -14;
700 if (next_node != dir_node.nextId())
701 vx = -15;
702 inout_dummy_var[node] = vx;
703 if (vx < 0)
704 return;
705 Real my_coord = in_nodes_coord[node][idir];
706 {
707 Int32 node_nb_cell = cnc.nbCell(node);
708 for (Integer k = 0; k < 8; ++k) {
709 Int32 cell_index = dir_node.cellIndex(k);
710 if (cell_index != (-1)) {
711 if ((1 + cell_index) > node_nb_cell) {
712 inout_dummy_var[node] = -40 - k;
713 return;
714 }
715 }
716 }
717 Int32 sum_id = 20 + dir_node.nextLeftCellId() +
718 dir_node.nextRightCellId() +
719 dir_node.previousRightCellId() +
720 dir_node.previousLeftCellId() +
721 dir_node.topNextLeftCellId() +
722 dir_node.topNextRightCellId() +
723 dir_node.topPreviousRightCellId() +
724 dir_node.topPreviousLeftCellId();
725 inout_dummy_var[node] = sum_id;
726 }
727 if (prev_node.isNull() && next_node.isNull()) {
728 inout_dummy_var[node] = -20;
729 return;
730 }
731 //TODO: Vérifier que les coordonnées autres que celle de idir sont bien les mêmes pour next,prev et my_coord.
732 if (!prev_node.isNull() && !next_node.isNull()) {
735 if (next_coord < prev_coord) {
736 inout_dummy_var[node] = -30;
737 return;
738 }
739 }
740 else {
741 if (!prev_node.isNull()) {
743 if (my_coord < prev_coord) {
744 inout_dummy_var[node] = -31;
745 return;
746 }
747 }
748 if (!next_node.isNull()) {
750 if (next_coord < my_coord) {
751 inout_dummy_var[node] = -32;
752 return;
753 }
754 }
755 }
756 };
757
758 ENUMERATE_ (Node, inode, node_dm.allNodes()) {
759 if (dummy_var[inode] < 0)
760 ARCANE_FATAL("Bad value for dummy_var id={0} v={1}", ItemPrinter(*inode), dummy_var[inode]);
761 }
762 }
763#endif
764}
765
766/*---------------------------------------------------------------------------*/
767/*---------------------------------------------------------------------------*/
768
769void CartesianMeshTestUtils::
770_testDirCellNode()
771{
772 IMesh* mesh = m_mesh;
774 Integer nb_dir = mesh->dimension();
775
776 Integer nb_print = m_nb_print;
777 for (Integer idir = 0; idir < nb_dir; ++idir) {
778 CellDirectionMng cdm(m_cartesian_mesh->cellDirection(idir));
779 eMeshDirection md = cdm.direction();
780 info() << "DIRECTION=" << idir;
781 Integer iprint = 0;
782 ENUMERATE_CELL (icell, cdm.allCells()) {
783 Cell cell = *icell;
785 DirCellNode cn(cdm.cellNode(cell));
786 DirCellNode cn2(cdm.cellNode(cell_id));
787 if (cn.cellId() != cn2.cellId())
788 ARCANE_FATAL("Bad DirCellNode");
789 bool is_print = (nb_print < 0 || iprint < nb_print);
790 ++iprint;
791 if (is_print) {
792 info() << "Cell uid=" << ItemPrinter(cell) << " dir=" << md;
793 info() << "Cell nextLeft =" << ItemPrinter(cn.nextLeft()) << " xyz=" << nodes_coord[cn.nextLeft()];
794 info() << "Cell nextRight=" << ItemPrinter(cn.nextRight()) << " xyz=" << nodes_coord[cn.nextRight()];
795 info() << "Cell prevRight=" << ItemPrinter(cn.previousRight()) << " xyz=" << nodes_coord[cn.previousRight()];
796 info() << "Cell prevLeft =" << ItemPrinter(cn.previousLeft()) << " xyz=" << nodes_coord[cn.previousLeft()];
797 if (nb_dir == 3) {
798 info() << "Cell topNextLeft =" << ItemPrinter(cn.topNextLeft()) << " xyz=" << nodes_coord[cn.topNextLeft()];
799 info() << "Cell topNextRight=" << ItemPrinter(cn.topNextRight()) << " xyz=" << nodes_coord[cn.topNextRight()];
800 info() << "Cell topPrevRight=" << ItemPrinter(cn.topPreviousRight()) << " xyz=" << nodes_coord[cn.topPreviousRight()];
801 info() << "Cell topPrevLeft =" << ItemPrinter(cn.topPreviousLeft()) << " xyz=" << nodes_coord[cn.topPreviousLeft()];
802 }
803 }
804 }
805 }
806}
807
808/*---------------------------------------------------------------------------*/
809/*---------------------------------------------------------------------------*/
810
811void CartesianMeshTestUtils::
812_testDirCellNodeAccelerator()
813{
814#if defined(ARCANE_HAS_ACCELERATOR_API)
815 IMesh* mesh = m_mesh;
817 Integer nb_dir = mesh->dimension();
818
819 VariableCellInt32 dummy_var(VariableBuildInfo(mesh, "DummyCellVariable"));
820 VariableCellReal3 computed_center(VariableBuildInfo(mesh, "CellComputedCenter"));
821
822 for (Integer idir = 0; idir < nb_dir; ++idir) {
823 CellDirectionMng cdm(m_cartesian_mesh->cellDirection(idir));
824 info() << "TEST_DIR_CELL_NODE_ACCELERATOR_DIRECTION=" << idir;
825
826 auto queue = m_accelerator_mng->defaultQueue();
827 auto command = makeCommand(*queue);
828
829 auto inout_dummy_var = viewInOut(command, dummy_var);
830 auto in_nodes_coord = viewIn(command, nodes_coord);
832 command << RUNCOMMAND_ENUMERATE(Cell, cell, cdm.allCells())
833 {
834 inout_dummy_var[cell] = 0;
835 DirCellNodeLocalId cn(cdm.dirCellNodeId(cell));
836 DirCellNodeLocalId cn2(cdm.dirCellNodeId(cell));
837 if (cn.cellId() != cn2.cellId()) {
838 inout_dummy_var[cell] = -10;
839 return;
840 }
841
842 Real3 n1 = in_nodes_coord[cn.nextLeftId()];
843 Real3 n2 = in_nodes_coord[cn.nextRightId()];
844 Real3 n3 = in_nodes_coord[cn.previousRightId()];
845 Real3 n4 = in_nodes_coord[cn.previousLeftId()];
846 Real3 center = n1 + n2 + n3 + n4;
847 if (nb_dir == 3) {
848 Real3 n5 = in_nodes_coord[cn.topNextLeftId()];
849 Real3 n6 = in_nodes_coord[cn.topNextRightId()];
850 Real3 n7 = in_nodes_coord[cn.topPreviousRightId()];
851 Real3 n8 = in_nodes_coord[cn.topPreviousLeftId()];
852 center += n5 + n6 + n7 + n8;
853 center /= 8.0;
854 }
855 else
856 center /= 4.0;
857 out_computed_center[cell] = center;
858 };
859 ENUMERATE_ (Cell, icell, cdm.allCells()) {
860 if (dummy_var[icell] < 0) {
861 ARCANE_FATAL("Bad value for dummy_var id={0} v={1}", ItemPrinter(*icell), dummy_var[icell]);
862 }
863 Real3 c1 = m_cell_center[icell];
865 bool is_nearly_equal = math::isNearlyEqual(c1.x, c2.x) && math::isNearlyEqual(c1.y, c2.y) && math::isNearlyEqual(c1.z, c2.z);
866 if (!is_nearly_equal)
867 ARCANE_FATAL("Bad value for computed center id={0} center={1} computed={2}",
868 ItemPrinter(*icell), c1, c2);
869 }
870 }
871#endif
872}
873
874/*---------------------------------------------------------------------------*/
875/*---------------------------------------------------------------------------*/
876
877void CartesianMeshTestUtils::
878_testDirCellFace()
879{
880 IMesh* mesh = m_mesh;
881 //VariableNodeReal3& nodes_coord = mesh->nodesCoordinates();
882 Integer nb_dir = mesh->dimension();
883 Integer nb_print = m_nb_print;
884 for (Integer idir = 0; idir < nb_dir; ++idir) {
885 CellDirectionMng cdm(m_cartesian_mesh->cellDirection(idir));
886 eMeshDirection md = cdm.direction();
887 info() << "DIRECTION=" << idir;
888 Integer iprint = 0;
889 ENUMERATE_CELL (icell, cdm.allCells()) {
890 Cell cell = *icell;
892 DirCellFace cf(cdm.cellFace(cell));
893 DirCellFace cf2(cdm.cellFace(cell_id));
894 if (cf.cellId() != cf2.cellId())
895 ARCANE_FATAL("Bad DirCellFace");
896 bool is_print = (nb_print < 0 || iprint < nb_print);
897 ++iprint;
898 if (is_print) {
899 info() << "CellFace uid=" << ItemPrinter(cell) << " dir=" << md;
900 info() << "CellFace nextFace =" << ItemPrinter(cf.next()) << " xyz=" << m_face_center[cf.next()];
901 info() << "CellFace prevFace=" << ItemPrinter(cf.previous()) << " xyz=" << m_face_center[cf.previous()];
902 }
903 }
904 }
905}
906
907/*---------------------------------------------------------------------------*/
908/*---------------------------------------------------------------------------*/
909
910void CartesianMeshTestUtils::
911_testDirCellFaceAccelerator()
912{
913#if defined(ARCANE_HAS_ACCELERATOR_API)
914 IMesh* mesh = m_mesh;
915 //VariableNodeReal3& nodes_coord = mesh->nodesCoordinates();
916 Integer nb_dir = mesh->dimension();
917
919 m_connectivity_view.setMesh(mesh);
920 auto cfc = m_connectivity_view.cellFace();
921
922 VariableCellInt32 dummy_var(VariableBuildInfo(mesh, "DummyCellVariable"));
923
924 for (Integer idir = 0; idir < nb_dir; ++idir) {
925 CellDirectionMng cdm(m_cartesian_mesh->cellDirection(idir));
926
927 auto queue = m_accelerator_mng->defaultQueue();
928 auto command = makeCommand(*queue);
929
930 auto inout_dummy_var = viewInOut(command, dummy_var);
931
932 info() << "DIRECTION=" << idir;
933
934 command << RUNCOMMAND_ENUMERATE(Cell, cell, cdm.allCells())
935 {
936 inout_dummy_var[cell] = 0;
937
939 DirCellFaceLocalId cf(cdm.dirCellFaceId(cell));
940 DirCellFaceLocalId cf2(cdm.dirCellFaceId(cell_id));
941 if (cf.cellId() != cf2.cellId()) {
942 inout_dummy_var[cell] = -10;
943 return;
944 }
945
946 Int32 next_index = cf.nextLocalIndex();
947 Int32 previous_index = cf.previousLocalIndex();
948
949 FaceLocalId next_face1 = cf.nextId();
950 FaceLocalId next_face2 = cfc.faceId(cell, next_index);
951 if (next_face1 != next_face2)
952 inout_dummy_var[cell] = -11;
953
954 FaceLocalId previous_face1 = cf.previousId();
957 inout_dummy_var[cell] = -12;
958 };
959 ENUMERATE_ (Cell, icell, cdm.allCells()) {
960 if (dummy_var[icell] < 0) {
961 ARCANE_FATAL("Bad value for dummy_var id={0} v={1}", ItemPrinter(*icell), dummy_var[icell]);
962 }
963 }
964 }
965#endif
966}
967
968/*---------------------------------------------------------------------------*/
969/*---------------------------------------------------------------------------*/
970
971void CartesianMeshTestUtils::
972_testNodeToCellConnectivity3D()
973{
974 info() << "Test NodeToCell Connectivity3D";
975 IMesh* mesh = m_mesh;
977 CartesianConnectivity cc = m_cartesian_mesh->connectivity();
978 ENUMERATE_NODE (inode, m_mesh->allNodes()) {
979 Node node = *inode;
981 info(4) << "node_uid=" << node.uniqueId()
982 << " UL=" << cc.upperLeftId(inode)
983 << " UR=" << cc.upperRightId(inode)
984 << " LR=" << cc.lowerRightId(inode)
985 << " LL=" << cc.lowerLeftId(inode)
986 << " TUL=" << cc.topZUpperLeftId(inode)
987 << " TUR=" << cc.topZUpperRightId(inode)
988 << " TLR=" << cc.topZLowerRightId(inode)
989 << " TLL=" << cc.topZLowerLeftId(inode);
990 {
991 Cell upper_left = cc.upperLeft(node);
992 if (!upper_left.null()) {
993 Real3 c = m_cell_center[upper_left];
994 if (c.y <= node_coord.y || c.x >= node_coord.x || c.z >= node_coord.z)
995 ARCANE_FATAL("Bad upperLeft cell for node={0} c={1} n={2}", ItemPrinter(node), c, node_coord);
996 }
997 }
998 {
999 Cell upper_right = cc.upperRight(node);
1000 if (!upper_right.null()) {
1001 Real3 c = m_cell_center[upper_right];
1002 if (c.y <= node_coord.y || c.x <= node_coord.x || c.z >= node_coord.z)
1003 ARCANE_FATAL("Bad upperRight cell for node={0} c={1} n={2}", ItemPrinter(node), c, node_coord);
1004 }
1005 }
1006 {
1007 Cell lower_right = cc.lowerRight(node);
1008 if (!lower_right.null()) {
1009 Real3 c = m_cell_center[lower_right];
1010 if (c.y >= node_coord.y || c.x <= node_coord.x || c.z >= node_coord.z)
1011 ARCANE_FATAL("Bad lowerRight cell for node={0} c={1} n={2}", ItemPrinter(node), c, node_coord);
1012 }
1013 }
1014 {
1015 Cell lower_left = cc.lowerLeft(node);
1016 if (!lower_left.null()) {
1017 Real3 c = m_cell_center[lower_left];
1018 if (c.y >= node_coord.y || c.x >= node_coord.x || c.z >= node_coord.z)
1019 ARCANE_FATAL("Bad lowerLeft cell for node={0} c={1} n={2}", ItemPrinter(node), c, node_coord);
1020 }
1021 }
1022 {
1023 Cell top_upper_left = cc.topZUpperLeft(node);
1024 if (!top_upper_left.null()) {
1025 Real3 c = m_cell_center[top_upper_left];
1026 if (c.y <= node_coord.y || c.x >= node_coord.x || c.z <= node_coord.z)
1027 ARCANE_FATAL("Bad topZUpperLeft cell for node={0} c={1} n={2}", ItemPrinter(node), c, node_coord);
1028 }
1029 }
1030 {
1031 Cell top_upper_right = cc.topZUpperRight(node);
1032 if (!top_upper_right.null()) {
1033 Real3 c = m_cell_center[top_upper_right];
1034 if (c.y <= node_coord.y || c.x <= node_coord.x || c.z <= node_coord.z)
1035 ARCANE_FATAL("Bad topZUpperRight cell for node={0} c={1} n={2}", ItemPrinter(node), c, node_coord);
1036 }
1037 }
1038 {
1039 Cell top_lower_right = cc.topZLowerRight(node);
1040 if (!top_lower_right.null()) {
1041 Real3 c = m_cell_center[top_lower_right];
1042 if (c.y >= node_coord.y || c.x <= node_coord.x || c.z <= node_coord.z)
1043 ARCANE_FATAL("Bad topZLowerRight cell for node={0} c={1} n={2}", ItemPrinter(node), c, node_coord);
1044 }
1045 }
1046 {
1047 Cell top_lower_left = cc.topZLowerLeft(node);
1048 if (!top_lower_left.null()) {
1049 Real3 c = m_cell_center[top_lower_left];
1050 if (c.y >= node_coord.y || c.x >= node_coord.x || c.z <= node_coord.z)
1051 ARCANE_FATAL("Bad topZLowerLeft cell for node={0} c={1} n={2}", ItemPrinter(node), c, node_coord);
1052 }
1053 }
1054 }
1055}
1056
1057/*---------------------------------------------------------------------------*/
1058/*---------------------------------------------------------------------------*/
1059
1060void CartesianMeshTestUtils::
1061_testNodeToCellConnectivity3DAccelerator()
1062{
1063#if defined(ARCANE_HAS_ACCELERATOR_API)
1064 info() << "Test NodeToCell Connectivity3D";
1065 IMesh* mesh = m_mesh;
1067 VariableNodeInt32 dummy_var(VariableBuildInfo(mesh, "DummyNodeVariable"));
1068 CartesianConnectivityLocalId cc = m_cartesian_mesh->connectivity();
1069
1070 auto queue = m_accelerator_mng->defaultQueue();
1071 auto command = makeCommand(*queue);
1072
1073 auto in_cell_center = viewIn(command, m_cell_center);
1074 auto in_node_coord = viewIn(command, nodes_coord);
1075 auto inout_dummy_var = viewInOut(command, dummy_var);
1076 command << RUNCOMMAND_ENUMERATE(Node, node, m_mesh->allNodes())
1077 {
1079 {
1080 CellLocalId upper_left = cc.upperLeftId(node);
1081 if (!upper_left.isNull()) {
1083 if (c.y <= node_coord.y || c.x >= node_coord.x || c.z >= node_coord.z)
1084 inout_dummy_var[node] = -10;
1085 }
1086 }
1087 {
1088 CellLocalId upper_right = cc.upperRightId(node);
1089 if (!upper_right.isNull()) {
1091 if (c.y <= node_coord.y || c.x <= node_coord.x || c.z >= node_coord.z)
1092 inout_dummy_var[node] = -11;
1093 }
1094 }
1095 {
1096 CellLocalId lower_right = cc.lowerRightId(node);
1097 if (!lower_right.isNull()) {
1099 if (c.y >= node_coord.y || c.x <= node_coord.x || c.z >= node_coord.z)
1100 inout_dummy_var[node] = -12;
1101 }
1102 }
1103 {
1104 CellLocalId lower_left = cc.lowerLeftId(node);
1105 if (!lower_left.isNull()) {
1107 if (c.y >= node_coord.y || c.x >= node_coord.x || c.z >= node_coord.z)
1108 inout_dummy_var[node] = -13;
1109 }
1110 }
1111 {
1112 CellLocalId top_upper_left = cc.topZUpperLeftId(node);
1113 if (!top_upper_left.isNull()) {
1115 if (c.y <= node_coord.y || c.x >= node_coord.x || c.z <= node_coord.z)
1116 inout_dummy_var[node] = -14;
1117 }
1118 }
1119 {
1120 CellLocalId top_upper_right = cc.topZUpperRightId(node);
1121 if (!top_upper_right.isNull()) {
1123 if (c.y <= node_coord.y || c.x <= node_coord.x || c.z <= node_coord.z)
1124 inout_dummy_var[node] = -15;
1125 }
1126 }
1127 {
1128 CellLocalId top_lower_right = cc.topZLowerRightId(node);
1129 if (!top_lower_right.isNull()) {
1131 if (c.y >= node_coord.y || c.x <= node_coord.x || c.z <= node_coord.z)
1132 inout_dummy_var[node] = -16;
1133 }
1134 }
1135 {
1136 CellLocalId top_lower_left = cc.topZLowerLeftId(node);
1137 if (!top_lower_left.isNull()) {
1139 if (c.y >= node_coord.y || c.x >= node_coord.x || c.z <= node_coord.z)
1140 inout_dummy_var[node] = -17;
1141 }
1142 }
1143 };
1144 ENUMERATE_ (Node, inode, m_mesh->allNodes()) {
1145 if (dummy_var[inode] < 0) {
1146 ARCANE_FATAL("Bad value for dummy_var id={0} v={1}", ItemPrinter(*inode), dummy_var[inode]);
1147 }
1148 }
1149#endif
1150}
1151
1152/*---------------------------------------------------------------------------*/
1153/*---------------------------------------------------------------------------*/
1154
1155void CartesianMeshTestUtils::
1156_testNodeToCellConnectivity2D()
1157{
1158 info() << "Test NodeToCell Connectivity 2D";
1159 IMesh* mesh = m_mesh;
1161 CartesianConnectivity cc = m_cartesian_mesh->connectivity();
1162 ENUMERATE_NODE (inode, mesh->allNodes()) {
1163 Node node = *inode;
1165 info(4) << "node_uid=" << node.uniqueId()
1166 << " UL=" << cc.upperLeftId(inode)
1167 << " UR=" << cc.upperRightId(inode)
1168 << " LR=" << cc.lowerRightId(inode)
1169 << " LL=" << cc.lowerLeftId(inode);
1170 {
1171 Cell upper_left = cc.upperLeft(node);
1172 if (!upper_left.null()) {
1173 Real3 c = m_cell_center[upper_left];
1174 if (c.y <= node_coord.y || c.x >= node_coord.x)
1175 ARCANE_FATAL("Bad upperLeft cell for node={0} c={1} n={2}", ItemPrinter(node), c, node_coord);
1176 }
1177 }
1178 {
1179 Cell upper_right = cc.upperRight(node);
1180 if (!upper_right.null()) {
1181 Real3 c = m_cell_center[upper_right];
1182 if (c.y <= node_coord.y || c.x <= node_coord.x)
1183 ARCANE_FATAL("Bad upperRight cell for node={0} c={1} n={2}", ItemPrinter(node), c, node_coord);
1184 }
1185 }
1186 {
1187 Cell lower_right = cc.lowerRight(node);
1188 if (!lower_right.null()) {
1189 Real3 c = m_cell_center[lower_right];
1190 if (c.y >= node_coord.y || c.x <= node_coord.x)
1191 ARCANE_FATAL("Bad lowerRight cell for node={0} c={1} n={2}", ItemPrinter(node), c, node_coord);
1192 }
1193 }
1194 {
1195 Cell lower_left = cc.lowerLeft(node);
1196 if (!lower_left.null()) {
1197 Real3 c = m_cell_center[lower_left];
1198 if (c.y >= node_coord.y || c.x >= node_coord.x)
1199 ARCANE_FATAL("Bad lowerLeft cell for node={0} c={1} n={2}", ItemPrinter(node), c, node_coord);
1200 }
1201 }
1202 }
1203}
1204
1205/*---------------------------------------------------------------------------*/
1206/*---------------------------------------------------------------------------*/
1207
1208void CartesianMeshTestUtils::
1209_testCellToNodeConnectivity3D()
1210{
1211 info() << "Test CellToNode Connectivity3D";
1212 IMesh* mesh = m_mesh;
1214 CartesianConnectivity cc = m_cartesian_mesh->connectivity();
1215 const bool is_not_amr = !m_is_amr;
1216 ENUMERATE_CELL (icell, m_mesh->allCells()) {
1217 Cell cell = *icell;
1218 Real3 cell_coord = m_cell_center[icell];
1219 info(4) << "cell_uid=" << cell.uniqueId()
1220 << " UL=" << cc.upperLeftId(icell)
1221 << " UR=" << cc.upperRightId(icell)
1222 << " LR=" << cc.lowerRightId(icell)
1223 << " LL=" << cc.lowerLeftId(icell)
1224 << " TUL=" << cc.topZUpperLeftId(icell)
1225 << " TUR=" << cc.topZUpperRightId(icell)
1226 << " TLR=" << cc.topZLowerRightId(icell)
1227 << " TLL=" << cc.topZLowerLeftId(icell);
1228 {
1229 Node upper_left = cc.upperLeft(cell);
1230 Cell ccell = cc.topZLowerRight(upper_left);
1232 if (n.y <= cell_coord.y || n.x >= cell_coord.x || n.z >= cell_coord.z)
1233 ARCANE_FATAL("Bad upperLeft node for cell={0}", ItemPrinter(cell));
1234 if (cell != ccell && is_not_amr)
1235 ARCANE_FATAL("Bad correspondance UL -> TLR cell={0} corresponding_cell={1}", ItemPrinter(cell), ccell);
1236 }
1237 {
1238 Node upper_right = cc.upperRight(cell);
1239 Cell ccell = cc.topZLowerLeft(upper_right);
1241 if (n.y <= cell_coord.y || n.x <= cell_coord.x || n.z >= cell_coord.z)
1242 ARCANE_FATAL("Bad upperRight node for cell={0}", ItemPrinter(cell));
1243 if (cell != ccell && is_not_amr)
1244 ARCANE_FATAL("Bad correspondance UR -> TLL cell={0} corresponding_cell={1}", ItemPrinter(cell), ccell);
1245 }
1246 {
1247 Node lower_right = cc.lowerRight(cell);
1248 Cell ccell = cc.topZUpperLeft(lower_right);
1250 if (n.y >= cell_coord.y || n.x <= cell_coord.x || n.z >= cell_coord.z)
1251 ARCANE_FATAL("Bad lowerRight node for cell={0}", ItemPrinter(cell));
1252 if (cell != ccell && is_not_amr)
1253 ARCANE_FATAL("Bad correspondance LR -> TUL cell={0} corresponding_cell={1}", ItemPrinter(cell), ccell);
1254 }
1255 {
1256 Node lower_left = cc.lowerLeft(cell);
1257 Cell ccell = cc.topZUpperRight(lower_left);
1259 if (n.y >= cell_coord.y || n.x >= cell_coord.x || n.z >= cell_coord.z)
1260 ARCANE_FATAL("Bad lowerLeft node for cell={0}", ItemPrinter(cell));
1261 if (cell != ccell && is_not_amr)
1262 ARCANE_FATAL("Bad correspondance LL -> TUR cell={0} corresponding_cell={1}", ItemPrinter(cell), ccell);
1263 }
1264 {
1265 Node top_upper_left = cc.topZUpperLeft(cell);
1266 Cell ccell = cc.lowerRight(top_upper_left);
1268 if (n.y <= cell_coord.y || n.x >= cell_coord.x || n.z <= cell_coord.z)
1269 ARCANE_FATAL("Bad topZUpperLeft node for cell={0}", ItemPrinter(cell));
1270 if (cell != ccell && is_not_amr)
1271 ARCANE_FATAL("Bad correspondance TUL -> LR cell={0} corresponding_cell={1}", ItemPrinter(cell), ccell);
1272 }
1273 {
1274 Node top_upper_right = cc.topZUpperRight(cell);
1275 Cell ccell = cc.lowerLeft(top_upper_right);
1277 if (n.y <= cell_coord.y || n.x <= cell_coord.x || n.z <= cell_coord.z)
1278 ARCANE_FATAL("Bad topZUpperRight node for cell={0}", ItemPrinter(cell));
1279 if (cell != ccell && is_not_amr)
1280 ARCANE_FATAL("Bad correspondance TUR -> LL cell={0} corresponding_cell={1}", ItemPrinter(cell), ccell);
1281 }
1282 {
1283 Node top_lower_right = cc.topZLowerRight(cell);
1284 Cell ccell = cc.upperLeft(top_lower_right);
1286 if (n.y >= cell_coord.y || n.x <= cell_coord.x || n.z <= cell_coord.z)
1287 ARCANE_FATAL("Bad topZLowerRight node for cell={0}", ItemPrinter(cell));
1288 if (cell != ccell && is_not_amr)
1289 ARCANE_FATAL("Bad correspondance TLR -> UL cell={0} corresponding_cell={1}", ItemPrinter(cell), ccell);
1290 }
1291 {
1292 Node top_lower_left = cc.topZLowerLeft(cell);
1293 Cell ccell = cc.upperRight(top_lower_left);
1295 if (n.y >= cell_coord.y || n.x >= cell_coord.x || n.z <= cell_coord.z)
1296 ARCANE_FATAL("Bad topZLowerLeft node for cell={0}", ItemPrinter(cell));
1297 if (cell != ccell && is_not_amr)
1298 ARCANE_FATAL("Bad correspondance TLL -> UR cell={0} corresponding_cell={1}", ItemPrinter(cell), ccell);
1299 }
1300 }
1301}
1302
1303/*---------------------------------------------------------------------------*/
1304/*---------------------------------------------------------------------------*/
1305
1306void CartesianMeshTestUtils::
1307_testCellToNodeConnectivity3DAccelerator()
1308{
1309#if defined(ARCANE_HAS_ACCELERATOR_API)
1310 info() << "Test CellToNode Connectivity3D Accelerator";
1311 IMesh* mesh = m_mesh;
1312 VariableCellInt32 dummy_var(VariableBuildInfo(mesh, "DummyCellVariable"));
1314 CartesianConnectivityLocalId cc = m_cartesian_mesh->connectivity();
1315 const bool is_not_amr = !m_is_amr;
1316
1317 auto queue = m_accelerator_mng->defaultQueue();
1318 auto command = makeCommand(*queue);
1319
1320 auto in_cell_center = viewIn(command, m_cell_center);
1321 auto in_node_coord = viewIn(command, nodes_coord);
1322 auto inout_dummy_var = viewInOut(command, dummy_var);
1323
1324 command << RUNCOMMAND_ENUMERATE(Cell, cell, m_mesh->allCells())
1325 {
1327 inout_dummy_var[cell] = 0;
1328 {
1329 NodeLocalId upper_left = cc.upperLeftId(cell);
1330 CellLocalId ccell = cc.topZLowerRightId(upper_left);
1332 if (n.y <= cell_coord.y || n.x >= cell_coord.x || n.z >= cell_coord.z)
1333 inout_dummy_var[cell] = -10;
1334 if (cell != ccell && is_not_amr)
1335 inout_dummy_var[cell] = -20;
1336 }
1337 {
1338 NodeLocalId upper_right = cc.upperRightId(cell);
1339 CellLocalId ccell = cc.topZLowerLeftId(upper_right);
1341 if (n.y <= cell_coord.y || n.x <= cell_coord.x || n.z >= cell_coord.z)
1342 inout_dummy_var[cell] = -11;
1343 if (cell != ccell && is_not_amr)
1344 inout_dummy_var[cell] = -21;
1345 }
1346 {
1347 NodeLocalId lower_right = cc.lowerRightId(cell);
1348 CellLocalId ccell = cc.topZUpperLeftId(lower_right);
1350 if (n.y >= cell_coord.y || n.x <= cell_coord.x || n.z >= cell_coord.z)
1351 inout_dummy_var[cell] = -12;
1352 if (cell != ccell && is_not_amr)
1353 inout_dummy_var[cell] = -22;
1354 }
1355 {
1356 NodeLocalId lower_left = cc.lowerLeftId(cell);
1357 CellLocalId ccell = cc.topZUpperRightId(lower_left);
1359 if (n.y >= cell_coord.y || n.x >= cell_coord.x || n.z >= cell_coord.z)
1360 inout_dummy_var[cell] = -13;
1361 if (cell != ccell && is_not_amr)
1362 inout_dummy_var[cell] = -23;
1363 }
1364 {
1365 NodeLocalId top_upper_left = cc.topZUpperLeftId(cell);
1366 CellLocalId ccell = cc.lowerRightId(top_upper_left);
1368 if (n.y <= cell_coord.y || n.x >= cell_coord.x || n.z <= cell_coord.z)
1369 inout_dummy_var[cell] = -14;
1370 if (cell != ccell && is_not_amr)
1371 inout_dummy_var[cell] = -24;
1372 }
1373 {
1374 NodeLocalId top_upper_right = cc.topZUpperRightId(cell);
1375 CellLocalId ccell = cc.lowerLeftId(top_upper_right);
1377 if (n.y <= cell_coord.y || n.x <= cell_coord.x || n.z <= cell_coord.z)
1378 inout_dummy_var[cell] = -15;
1379 if (cell != ccell && is_not_amr)
1380 inout_dummy_var[cell] = -25;
1381 }
1382 {
1383 NodeLocalId top_lower_right = cc.topZLowerRightId(cell);
1384 CellLocalId ccell = cc.upperLeftId(top_lower_right);
1386 if (n.y >= cell_coord.y || n.x <= cell_coord.x || n.z <= cell_coord.z)
1387 inout_dummy_var[cell] = -16;
1388 if (cell != ccell && is_not_amr)
1389 inout_dummy_var[cell] = -26;
1390 }
1391 {
1392 NodeLocalId top_lower_left = cc.topZLowerLeftId(cell);
1393 CellLocalId ccell = cc.upperRightId(top_lower_left);
1395 if (n.y >= cell_coord.y || n.x >= cell_coord.x || n.z <= cell_coord.z)
1396 inout_dummy_var[cell] = -17;
1397 if (cell != ccell && is_not_amr)
1398 inout_dummy_var[cell] = -27;
1399 }
1400 };
1401 ENUMERATE_ (Cell, icell, m_mesh->allCells()) {
1402 if (dummy_var[icell] < 0) {
1403 ARCANE_FATAL("Bad value for dummy_var id={0} v={1}", ItemPrinter(*icell), dummy_var[icell]);
1404 }
1405 }
1406#endif
1407}
1408
1409/*---------------------------------------------------------------------------*/
1410/*---------------------------------------------------------------------------*/
1411
1412void CartesianMeshTestUtils::
1413_testCellToNodeConnectivity2D()
1414{
1415 info() << "Test CellToNode Connectivity 2D";
1416 IMesh* mesh = m_mesh;
1418 CartesianConnectivity cc = m_cartesian_mesh->connectivity();
1419 const bool is_not_amr = !m_is_amr;
1420 ENUMERATE_CELL (icell, mesh->allCells()) {
1421 Cell cell = *icell;
1422 Real3 cell_coord = m_cell_center[icell];
1423 info(4) << "cell_uid=" << cell.uniqueId()
1424 << " UL=" << cc.upperLeftId(icell)
1425 << " UR=" << cc.upperRightId(icell)
1426 << " LR=" << cc.lowerRightId(icell)
1427 << " LL=" << cc.lowerLeftId(icell);
1428 {
1429 Node upper_left = cc.upperLeft(cell);
1430 Cell ccell = cc.lowerRight(upper_left);
1432 if (n.y <= cell_coord.y || n.x >= cell_coord.x)
1433 ARCANE_FATAL("Bad upperLeft node for cell={0} c={1} n={2}", ItemPrinter(cell), cell_coord, n);
1434 if (cell != ccell && is_not_amr)
1435 ARCANE_FATAL("Bad correspondance UL -> LR cell={0} corresponding_cell={1}", ItemPrinter(cell), ccell);
1436 }
1437 {
1438 Node upper_right = cc.upperRight(cell);
1439 Cell ccell = cc.lowerLeft(upper_right);
1441 if (n.y <= cell_coord.y || n.x <= cell_coord.x)
1442 ARCANE_FATAL("Bad upperRight node for cell={0} c={1} n={2}", ItemPrinter(cell), cell_coord, n);
1443 if (cell != ccell && is_not_amr)
1444 ARCANE_FATAL("Bad correspondance UR -> LF cell={0} corresponding_cell={1}", ItemPrinter(cell), ccell);
1445 }
1446 {
1447 Node lower_right = cc.lowerRight(cell);
1448 Cell ccell = cc.upperLeft(lower_right);
1450 if (n.y >= cell_coord.y || n.x <= cell_coord.x)
1451 ARCANE_FATAL("Bad lowerRight node for cell={0} c={1} n={2}", ItemPrinter(cell), cell_coord, n);
1452 if (cell != ccell && is_not_amr)
1453 ARCANE_FATAL("Bad correspondance UL -> LR cell={0} corresponding_cell={1}", ItemPrinter(cell), ccell);
1454 }
1455 {
1456 Node lower_left = cc.lowerLeft(cell);
1457 Cell ccell = cc.upperRight(lower_left);
1459 if (n.y >= cell_coord.y || n.x >= cell_coord.x)
1460 ARCANE_FATAL("Bad lowerLeft node for cell={0} c={1} n={2}", ItemPrinter(cell), cell_coord, n);
1461 if (cell != ccell && is_not_amr)
1462 ARCANE_FATAL("Bad correspondance LL -> UR cell={0} corresponding_cell={1}", ItemPrinter(cell), ccell);
1463 }
1464 }
1465}
1466
1467/*---------------------------------------------------------------------------*/
1468/*---------------------------------------------------------------------------*/
1469
1470template<typename ItemType> void CartesianMeshTestUtils::
1471_testConnectivityByDirectionHelper(const ItemGroup& group)
1472{
1473 ValueChecker vc(A_FUNCINFO);
1474 Int32 nb_dim = m_mesh->dimension();
1475
1476 info() << "Test ConnectivityByDirection 2D";
1477 CartesianConnectivity cc = m_cartesian_mesh->connectivity();
1478 ENUMERATE_ (ItemType, iitem, group) {
1479 vc.areEqual(cc.upperLeftId(iitem),cc.upperLeftId(iitem,0),"Item0 dir0");
1480 vc.areEqual(cc.upperRightId(iitem),cc.upperRightId(iitem,0),"Item1 dir0");
1481 vc.areEqual(cc.lowerRightId(iitem),cc.lowerRightId(iitem,0),"Item2 dir0");
1482 vc.areEqual(cc.lowerLeftId(iitem),cc.lowerLeftId(iitem,0),"Item3 dir0");
1483
1484 if (nb_dim>1){
1485 vc.areEqual(cc.lowerLeftId(iitem),cc.upperLeftId(iitem,1),"Item0 dir1");
1486 vc.areEqual(cc.upperLeftId(iitem),cc.upperRightId(iitem,1),"Item1 dir1");
1487 vc.areEqual(cc.upperRightId(iitem),cc.lowerRightId(iitem,1),"Item2 dir1");
1488 vc.areEqual(cc.lowerRightId(iitem),cc.lowerLeftId(iitem,1),"Item3 dir1");
1489 }
1490
1491 if (nb_dim>2){
1492 vc.areEqual(cc.upperRightId(iitem),cc.upperLeftId(iitem,2),"Item0 dir2");
1493 vc.areEqual(cc.topZUpperRightId(iitem),cc.upperRightId(iitem,2),"Item1 dir2");
1494 vc.areEqual(cc.topZLowerRightId(iitem),cc.lowerRightId(iitem,2),"Item2 dir2");
1495 vc.areEqual(cc.lowerRightId(iitem),cc.lowerLeftId(iitem,2),"Item3 dir2");
1496
1497 vc.areEqual(cc.upperLeftId(iitem),cc.topZUpperLeftId(iitem,2),"Item4 dir2");
1498 vc.areEqual(cc.topZUpperLeftId(iitem),cc.topZUpperRightId(iitem,2),"Item5 dir2");
1499 vc.areEqual(cc.topZLowerLeftId(iitem),cc.topZLowerRightId(iitem,2),"Item6 dir2");
1500 vc.areEqual(cc.lowerLeftId(iitem),cc.topZLowerLeftId(iitem,2),"Item7 dir2");
1501 }
1502 }
1503}
1504
1505/*---------------------------------------------------------------------------*/
1506/*---------------------------------------------------------------------------*/
1507
1508void CartesianMeshTestUtils::
1509_testConnectivityByDirection()
1510{
1511 info() << "Test Node ConnectivityByDirection";
1512 _testConnectivityByDirectionHelper<Node>(m_mesh->allNodes());
1513 info() << "Test Cell ConnectivityByDirection";
1514 _testConnectivityByDirectionHelper<Cell>(m_mesh->allCells());
1515}
1516
1517/*---------------------------------------------------------------------------*/
1518/*---------------------------------------------------------------------------*/
1519
1520void CartesianMeshTestUtils::
1522{
1524 CartesianConnectivity cc = cartesian_mesh->connectivity();
1525 ENUMERATE_NODE (inode, m_mesh->allNodes()) {
1526 Node n = *inode;
1527 Cell c1 = cc.upperLeft(n); // Maille en haut à gauche
1528 Cell c2 = cc.upperRight(n); // Maille en haut à droite
1529 Cell c3 = cc.lowerRight(n); // Maille en bas à droite
1530 Cell c4 = cc.lowerLeft(n); // Maille en bas à gauche
1531 info(6) << " C1=" << ItemPrinter(c1) << " C2=" << ItemPrinter(c2)
1532 << " C3=" << ItemPrinter(c3) << " C4=" << ItemPrinter(c4);
1533 }
1535}
1536
1537/*---------------------------------------------------------------------------*/
1538/*---------------------------------------------------------------------------*/
1539
1540void CartesianMeshTestUtils::
1541_saveSVG()
1542{
1543 ICartesianMesh* cm = m_cartesian_mesh;
1544 IMesh* mesh = cm->mesh();
1545 info() << "Saving mesh to SVG format";
1546 std::ofstream ofile("toto.svg");
1548 writer.write(mesh->allCells());
1549}
1550
1551/*---------------------------------------------------------------------------*/
1552/*---------------------------------------------------------------------------*/
1553
1554} // End namespace ArcaneTest
1555
1556/*---------------------------------------------------------------------------*/
1557/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
#define ENUMERATE_FACE(name, group)
Enumérateur générique d'un groupe de faces.
#define ENUMERATE_(type, name, group)
Enumérateur générique d'un groupe d'entité
#define ENUMERATE_CELL(name, group)
Enumérateur générique d'un groupe de mailles.
#define ENUMERATE_NODE(name, group)
Enumérateur générique d'un groupe de noeuds.
Fonctions utilitaires sur le maillage.
Types et macros pour gérer les énumérations des entités sur les accélérateurs.
#define RUNCOMMAND_ENUMERATE(ItemTypeName, iter_name, item_group,...)
Macro pour itérer sur accélérateur sur un groupe d'entités.
Interface du gestionnaire des accélérateurs.
Classe d'accès aux connectivités cartésiennes.
Informations de connectivité d'un maillage cartésien.
Infos sur les mailles d'une direction spécifique X,Y ou Z d'un maillage structuré.
Maille d'un maillage.
Definition Item.h:1178
Int32 level() const
Definition Item.h:1328
Maille avec info directionnelle des faces.
Maille avec info directionnelle des faces.
Maille avant et après une maille suivant une direction.
Maille avec info directionnelle des noeuds.
Maille avec info directionnelle des noeuds.
Maille avant et après une maille suivant une direction.
Infos sur maille avant et après une face suivant une direction.
Infos sur maille avant et après une face suivant une direction.
Noeud avant et après un noeud suivant une direction.
Noeud avant et après un noeud suivant une direction.
Infos sur les face d'une direction spécifique X,Y ou Z d'un maillage structuré.
Face d'une maille.
Definition Item.h:932
Interface d'un maillage cartésien.
virtual Integer dimension()=0
Dimension du maillage (1D, 2D ou 3D).
virtual NodeGroup allNodes()=0
Groupe de tous les noeuds.
virtual CellGroup allCells()=0
Groupe de toutes les mailles.
virtual VariableNodeReal3 & nodesCoordinates()=0
Coordonnées des noeuds.
Groupe d'entités de maillage.
Definition ItemGroup.h:49
bool checkIsSorted() const
Vérifie et retourne si le groupe est trié par uniqueId() croissants.
Definition ItemGroup.cc:654
const String & name() const
Nom du groupe.
Definition ItemGroup.h:76
Classe utilitaire pour imprimer les infos sur une entité.
Definition ItemPrinter.h:35
Int32 nbNode() const
Nombre de noeuds de l'entité
Definition Item.h:765
constexpr Int32 localId() const
Identifiant local de l'entité dans le sous-domaine du processeur.
Definition Item.h:210
ItemUniqueId uniqueId() const
Identifiant unique sur tous les domaines.
Definition Item.h:216
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:149
Infos sur les noeuds d'une direction spécifique X,Y ou Z d'un maillage structuré.
Noeud d'un maillage.
Definition Item.h:564
Cell cell(Int32 i) const
i-ème maille du noeud
Definition Item.h:1568
Int32 nbCell() const
Nombre de mailles connectées au noeud.
Definition Item.h:643
Classe gérant un vecteur de réel de dimension 3.
Definition Real3.h:132
Exportation d'un maillage au format SVG.
Vue sur les connectivités standards d'un maillage non structuré.
Vérification de la validité de certaines valeurs.
Paramètres nécessaires à la construction d'une variable.
Espace de nom pour l'utilisation des accélérateurs.
RunCommand makeCommand(const RunQueue &run_queue)
Créé une commande associée à la file run_queue.
auto viewInOut(const ViewBuildInfo &vbi, CellMaterialVariableScalarRef< DataType > &var)
Vue en lecture/écriture pour les variables materiaux scalaire.
auto viewOut(const ViewBuildInfo &vbi, CellMaterialVariableScalarRef< DataType > &var)
Vue en écriture pour les variables materiaux scalaire.
auto viewIn(const ViewBuildInfo &vbi, const CellMaterialVariableScalarRef< DataType > &var)
Vue en lecture pour les variables materiaux scalaire.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
eMeshDirection
Type de la direction pour un maillage structuré
Int32 Integer
Type représentant un entier.
Real y
deuxième composante du triplet
Definition Real3.h:36
Real z
troisième composante du triplet
Definition Real3.h:37
Real x
première composante du triplet
Definition Real3.h:35