Arcane  v3.14.10.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-2023 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-2023 */
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 if (prev_cell.null() && next_cell.null())
204 ARCANE_FATAL("Null previous and next cell");
206 Cell prev_cell2 = dir_cell2.previous();
207 Cell next_cell2 = dir_cell2.next();
209 Cell prev_cell3 = dir_cell3.previous();
210 Cell next_cell3 = dir_cell3.next();
211 _checkSameId(prev_cell, prev_cell2);
212 _checkSameId(next_cell, next_cell2);
213 _checkSameId(prev_cell, prev_cell3);
214 _checkSameId(next_cell, next_cell3);
215 if (nb_print < 0 || iprint < nb_print) {
216 ++iprint;
217 if (!prev_cell.null() && !next_cell.null()) {
218 info() << "Cell uid=" << ItemPrinter(cell) << " dir=" << md
219 << " prev=" << ItemPrinter(prev_cell) << " xyz=" << m_cell_center[prev_cell]
220 << " next=" << ItemPrinter(next_cell) << " xyz=" << m_cell_center[next_cell];
221 }
222 else {
223 info() << "Cell uid=" << ItemPrinter(cell) << " dir=" << md;
224 if (!prev_cell.null())
225 info() << " prev=" << ItemPrinter(prev_cell) << " xyz=" << m_cell_center[prev_cell];
226 if (!next_cell.null())
227 info() << " next=" << ItemPrinter(next_cell) << " xyz=" << m_cell_center[next_cell];
228 }
229 }
230 }
231 }
232}
233
234/*---------------------------------------------------------------------------*/
235/*---------------------------------------------------------------------------*/
236
237void CartesianMeshTestUtils::
238_testDirCellAccelerator()
239{
240#if defined(ARCANE_HAS_ACCELERATOR_API)
241 info() << "TEST_DIR_CELL_ACCELERATOR";
242
243 IMesh* mesh = m_mesh;
244 Integer nb_dir = mesh->dimension();
247
248 auto queue = m_accelerator_mng->defaultQueue();
249 auto command = makeCommand(*queue);
250
251 VariableCellInt32 dummy_var(VariableBuildInfo(mesh, "DummyCellVariable"));
252 dummy_var.fill(0);
253 auto inout_dummy_var = viewInOut(command, dummy_var);
254
255 for (Integer idir = 0; idir < nb_dir; ++idir) {
256 CellDirectionMng cdm(m_cartesian_mesh->cellDirection(idir));
257 cdm2 = m_cartesian_mesh->cellDirection(idir);
258 cdm3 = cdm;
259 info() << "ACCELERATOR_DIRECTION=" << idir << " Cells=" << cdm.allCells().name();
260 _checkItemGroupIsSorted(cdm.allCells());
261 command << RUNCOMMAND_ENUMERATE(Cell, icell, cdm.allCells())
262 {
263 DirCellLocalId dir_cell(cdm.dirCellId(icell));
264 CellLocalId prev_cell = dir_cell.previous();
266 if (prev_cell.isNull() && next_cell.isNull()) {
268 return;
269 }
270
272 CellLocalId prev_cell2 = dir_cell2.previous();
275 CellLocalId prev_cell3 = dir_cell3.previous();
277 if (prev_cell != prev_cell2)
278 inout_dummy_var[icell] = -10;
279 if (next_cell != next_cell2)
280 inout_dummy_var[icell] = -11;
281 if (prev_cell != prev_cell3)
282 inout_dummy_var[icell] = -12;
283 if (next_cell != next_cell3)
284 inout_dummy_var[icell] = -13;
285
286 if (!prev_cell.isNull() && !next_cell.isNull()) {
288 }
289 else {
290 if (!prev_cell.isNull())
292 if (!next_cell.isNull())
294 }
295 };
296 ENUMERATE_ (Cell, icell, cdm.allCells()) {
297 if (dummy_var[icell] < 0)
298 ARCANE_FATAL("Bad value for dummy_var id={0} v={1}", ItemPrinter(*icell), dummy_var[icell]);
299 }
300 }
301#endif
302}
303
304/*---------------------------------------------------------------------------*/
305/*---------------------------------------------------------------------------*/
306
307void CartesianMeshTestUtils::
308_testDirFace()
309{
310 IMesh* mesh = m_mesh;
311 Integer nb_dir = mesh->dimension();
312 for (Integer idir = 0; idir < nb_dir; ++idir)
313 _testDirFace(idir);
314}
315
316/*---------------------------------------------------------------------------*/
317/*---------------------------------------------------------------------------*/
318
319void CartesianMeshTestUtils::
320_testDirFaceAccelerator()
321{
322 IMesh* mesh = m_mesh;
323 Integer nb_dir = mesh->dimension();
324 for (Integer idir = 0; idir < nb_dir; ++idir)
325 _testDirFaceAccelerator(idir);
326}
327
328/*---------------------------------------------------------------------------*/
329/*---------------------------------------------------------------------------*/
330
331void CartesianMeshTestUtils::
332_testDirFace(int idir)
333{
334 // Teste l'utilisation de DirFace et vérifie que
335 // les valeurs sont correctes: pour une face donnée,
336 // il faut que selon la direction choisie, la coordonnée du centre
337 // de la maille avant (previousCell()) soit inférieure à celle
338 // de la maille après (nextCell()) et aussi celle de la maille avant
339 // soit inférieure à ce
340 Integer nb_print = m_nb_print;
341 Integer nb_error = 0;
342 Integer iprint = 0;
343
345 FaceDirectionMng fdm(m_cartesian_mesh->faceDirection(idir));
346 fdm2 = fdm;
347 eMeshDirection md = fdm.direction();
348 info() << "TEST_DIR_FACE for direction=" << idir << " -> " << (eMeshDirection)idir;
349 _checkItemGroupIsSorted(fdm.allFaces());
350 ENUMERATE_FACE (iface, fdm.allFaces()) {
351 Face face = *iface;
352 DirFace dir_face(fdm[iface]);
354 //Integer nb_node = cell.nbNode();
355 Cell prev_cell = dir_face.previousCell();
356 Cell next_cell = dir_face.nextCell();
357 Cell prev_cell2 = dir_face2.previousCell();
358 Cell next_cell2 = dir_face2.nextCell();
359 _checkSameId(prev_cell, prev_cell2);
360 _checkSameId(next_cell, next_cell2);
361 _checkSameId(prev_cell, dir_face.previousCellId());
362 _checkSameId(next_cell, dir_face.nextCellId());
363 bool is_print = (nb_print < 0 || iprint < nb_print);
364 ++iprint;
365 Real face_coord = m_face_center[iface][idir];
366 if (!prev_cell.null() && !next_cell.null()) {
367 Real next_coord = m_cell_center[next_cell][idir];
368 Real prev_coord = m_cell_center[prev_cell][idir];
369 if (next_coord < prev_coord) {
370 info() << "Bad ordering for face";
371 is_print = true;
372 ++nb_error;
373 }
374 if (is_print)
375 info() << "Face uid=" << ItemPrinter(face) << " dir=" << md << " xyz=" << m_face_center[iface]
376 << " prev=" << prev_cell.uniqueId() << " xyz=" << m_cell_center[prev_cell]
377 << " next=" << next_cell.uniqueId() << " xyz=" << m_cell_center[next_cell];
378 }
379 else {
380 if (!prev_cell.null()) {
381 Real prev_coord = m_cell_center[prev_cell][idir];
382 if (face_coord < prev_coord) {
383 info() << "Bad ordering for face";
384 is_print = true;
385 ++nb_error;
386 }
387 if (is_print)
388 info() << "Face uid=" << ItemPrinter(face) << " dir=" << md << " xyz=" << m_face_center[iface]
389 << " prev=" << prev_cell.uniqueId() << " xyz=" << m_cell_center[prev_cell];
390 }
391 if (!next_cell.null()) {
392 Real next_coord = m_cell_center[next_cell][idir];
393 if (next_coord < face_coord) {
394 info() << "Bad ordering for face";
395 is_print = true;
396 ++nb_error;
397 }
398 if (is_print)
399 info() << "Face uid=" << ItemPrinter(face) << " dir=" << md << " xyz=" << m_face_center[iface]
400 << " next=" << next_cell.uniqueId() << " xyz=" << m_cell_center[next_cell];
401 }
402 }
403 }
404 if (nb_error != 0)
405 ARCANE_FATAL("Bad connectivity for DirFace nb_error={0}", nb_error);
406}
407
408/*---------------------------------------------------------------------------*/
409/*---------------------------------------------------------------------------*/
410
411void CartesianMeshTestUtils::
412_testDirFaceAccelerator(int idir)
413{
414#if defined(ARCANE_HAS_ACCELERATOR_API)
415 // Teste l'utilisation de DirFace et vérifie que
416 // les valeurs sont correctes: pour une face donnée,
417 // il faut que selon la direction choisie, la coordonnée du centre
418 // de la maille avant (previousCell()) soit inférieure à celle
419 // de la maille après (nextCell()) et aussi celle de la maille avant
420 // soit inférieure à ce
421
423 FaceDirectionMng fdm(m_cartesian_mesh->faceDirection(idir));
424 fdm2 = fdm;
425 info() << "TEST_DIR_FACE_ACCELERATOR for direction=" << idir << " -> " << (eMeshDirection)idir;
426
427 auto queue = m_accelerator_mng->defaultQueue();
428 auto command = makeCommand(*queue);
429
430 VariableFaceInt32 dummy_var(VariableBuildInfo(m_mesh, "DummyFaceVariable"));
431 dummy_var.fill(0);
432 auto inout_dummy_var = viewInOut(command, dummy_var);
433 auto in_face_center = viewIn(command, m_face_center);
434 auto in_cell_center = viewIn(command, m_cell_center);
435
436 command << RUNCOMMAND_ENUMERATE(Face, iface, fdm.allFaces())
437 {
438 DirFaceLocalId dir_face(fdm.dirFaceId(iface));
440 //Integer nb_node = cell.nbNode();
441 CellLocalId prev_cell = dir_face.previousCell();
442 CellLocalId next_cell = dir_face.nextCell();
443 CellLocalId prev_cell2 = dir_face2.previousCell();
444 CellLocalId next_cell2 = dir_face2.nextCell();
445 if (prev_cell != prev_cell2)
446 inout_dummy_var[iface] = -10;
447 if (next_cell != next_cell2)
448 inout_dummy_var[iface] = -11;
449 if (prev_cell != dir_face.previousCellId())
450 inout_dummy_var[iface] = -12;
451 if (next_cell != dir_face.nextCellId())
452 inout_dummy_var[iface] = -13;
453 if (inout_dummy_var[iface] < 0)
454 return;
455
457 if (!prev_cell.isNull() && !next_cell.isNull()) {
460 if (next_coord < prev_coord) {
461 inout_dummy_var[iface] = -20;
462 return;
463 }
464 }
465 else {
466 if (!prev_cell.isNull()) {
468 if (face_coord < prev_coord) {
469 inout_dummy_var[iface] = -21;
470 return;
471 }
472 }
473 if (!next_cell.isNull()) {
475 if (next_coord < face_coord) {
476 inout_dummy_var[iface] = -22;
477 return;
478 }
479 }
480 }
481 };
482
483 ENUMERATE_ (Face, iface, fdm.allFaces()) {
484 if (dummy_var[iface] < 0)
485 ARCANE_FATAL("Bad value for dummy_var id={0} v={1}", ItemPrinter(*iface), dummy_var[iface]);
486 }
487#endif
488}
489
490/*---------------------------------------------------------------------------*/
491/*---------------------------------------------------------------------------*/
492
493void CartesianMeshTestUtils::
494_testDirNode()
495{
496 info() << "TEST_DIR_NODE";
497 m_node_density.fill(0.0);
498
499 IMesh* mesh = m_mesh;
500 Integer nb_dir = mesh->dimension();
501 Integer nb_print = m_nb_print;
502 Integer nb_error = 0;
504 // Pour tester l'opérateur 'operator='
507 for (Integer idir = 0; idir < nb_dir; ++idir) {
508 NodeDirectionMng node_dm(m_cartesian_mesh->nodeDirection(idir));
509 node_dm2 = m_cartesian_mesh->nodeDirection(idir);
511 eMeshDirection md = node_dm.direction();
512 Integer iprint = 0;
513 info() << "DIRECTION=" << idir;
514 NodeGroup dm_all_nodes = node_dm.allNodes();
515 _checkItemGroupIsSorted(dm_all_nodes);
517 Node node = *inode;
518 m_node_density[inode] += 1.0;
522 Node prev_node = dir_node.previous();
523 Node next_node = dir_node.next();
524 Node prev_node2 = dir_node2.previous();
525 Node next_node2 = dir_node2.next();
526 Node prev_node3 = dir_node3.previous();
527 Node next_node3 = dir_node3.next();
528 _checkSameId(prev_node, prev_node2);
529 _checkSameId(next_node, next_node2);
530 _checkSameId(prev_node, prev_node3);
531 _checkSameId(next_node, next_node3);
532 _checkSameId(prev_node, dir_node.previousId());
533 _checkSameId(next_node, dir_node.nextId());
535 bool is_print = (nb_print < 0 || iprint < nb_print);
536 ++iprint;
537 if (is_print) {
538 Int32 node_nb_cell = node.nbCell();
539 info() << "DirNode node= " << ItemPrinter(node) << " nb_cell=" << node_nb_cell << " pos=" << nodes_coord[node];
540 for (Integer k = 0; k < node_nb_cell; ++k) {
541 Real3 cell_pos = m_cell_center[node.cell(k)];
542 info() << "Node k=" << k << " cell_pos=" << cell_pos << " cell=" << ItemPrinter(node.cell(k));
543 }
544 for (Integer k = 0; k < 8; ++k) {
545 Int32 cell_index = dir_node.cellIndex(k);
547 if (cell_index != (-1)) {
548 if ((1 + cell_index) > node_nb_cell)
549 ARCANE_FATAL("Bad value for cell_index '{0}' node_nb_cell={1}", cell_index, node_nb_cell);
550 cell_pos = m_cell_center[node.cell(cell_index)];
551 }
552 info() << "DirNode cellIndex k=" << k << " index=" << cell_index << " pos=" << cell_pos
553 << " cell_lid=" << dir_node.cellId(k)
554 << " cell=" << dir_node.cell(k);
555 }
556 info() << "DirNode direct "
557 << " " << dir_node.nextLeftCellId()
558 << " " << dir_node.nextRightCellId()
559 << " " << dir_node.previousRightCellId()
560 << " " << dir_node.previousLeftCellId()
561 << " " << dir_node.topNextLeftCellId()
562 << " " << dir_node.topNextRightCellId()
563 << " " << dir_node.topPreviousRightCellId()
564 << " " << dir_node.topPreviousLeftCellId();
565 info() << "DirNode direct "
566 << " " << ItemPrinter(dir_node.nextLeftCell())
567 << " " << ItemPrinter(dir_node.nextRightCell())
568 << " " << ItemPrinter(dir_node.previousRightCell())
569 << " " << ItemPrinter(dir_node.previousLeftCell())
570 << " " << ItemPrinter(dir_node.topNextLeftCell())
571 << " " << ItemPrinter(dir_node.topNextRightCell())
572 << " " << ItemPrinter(dir_node.topPreviousRightCell())
573 << " " << ItemPrinter(dir_node.topPreviousLeftCell());
574 }
575 if (prev_node.null() && next_node.null())
576 ARCANE_FATAL("Null previous and next node for node {0}", ItemPrinter(node));
577 //TODO: Vérifier que les coordonnées autres que celle de idir sont bien les mêmes pour next,prev et my_coord.
578 if (!prev_node.null() && !next_node.null()) {
581 if (next_coord < prev_coord) {
582 info() << "Bad ordering for node";
583 is_print = true;
584 ++nb_error;
585 }
586 if (is_print)
587 info() << "Node uid=" << ItemPrinter(node) << " dir=" << md
588 << " prev=" << ItemPrinter(prev_node) << " xyz=" << prev_coord
589 << " next=" << ItemPrinter(next_node) << " xyz=" << next_coord;
590 }
591 else {
592 if (!prev_node.null()) {
594 if (my_coord < prev_coord) {
595 info() << "Bad ordering for node";
596 is_print = true;
597 ++nb_error;
598 }
599 if (is_print)
600 info() << "Node uid=" << ItemPrinter(node) << " dir=" << md
601 << " prev=" << ItemPrinter(prev_node) << " xyz=" << nodes_coord[prev_node];
602 }
603 if (!next_node.null()) {
605 if (next_coord < my_coord) {
606 info() << "Bad ordering for node";
607 is_print = true;
608 ++nb_error;
609 }
610 if (is_print)
611 info() << "Node uid=" << ItemPrinter(node) << " dir=" << md
612 << " next=" << ItemPrinter(next_node) << " xyz=" << nodes_coord[next_node];
613 }
614 }
615 }
616 }
617
618 if (nb_error != 0)
619 ARCANE_FATAL("Bad connectivity for DirNode");
620
621 // Vérifie qu'on a parcouru tous les noeuds
622 ENUMERATE_NODE (inode, m_mesh->allNodes()) {
623 Node node = *inode;
624 if (node.cell(0).level() != 0)
625 continue;
626 if (m_node_density[inode] == 0.0) {
627 ++nb_error;
628 info() << "Bad value for node " << ItemPrinter(node);
629 }
630 }
631 if (nb_error != 0)
632 ARCANE_FATAL("Bad values for DirNode");
633}
634
635/*---------------------------------------------------------------------------*/
636/*---------------------------------------------------------------------------*/
637
638void CartesianMeshTestUtils::
639_testDirNodeAccelerator()
640{
641#if defined(ARCANE_HAS_ACCELERATOR_API)
642 info() << "TEST_DIR_NODE Accelerator";
643 m_node_density.fill(0.0);
644
645 IMesh* mesh = m_mesh;
646 Integer nb_dir = mesh->dimension();
648 // Pour tester l'opérateur 'operator='
651
652 //auto in_face_center = viewIn(command, m_face_center);
653 //auto in_cell_center = viewIn(command, m_cell_center);
654
655 VariableNodeInt32 dummy_var(VariableBuildInfo(m_mesh, "DummyNodeVariable"));
656
658 m_connectivity_view.setMesh(mesh);
659 auto cnc = m_connectivity_view.nodeCell();
660
661 for (Integer idir = 0; idir < nb_dir; ++idir) {
662 NodeDirectionMng node_dm(m_cartesian_mesh->nodeDirection(idir));
663 node_dm2 = m_cartesian_mesh->nodeDirection(idir);
665 info() << "DIRECTION=" << idir;
666 NodeGroup dm_all_nodes = node_dm.allNodes();
667 _checkItemGroupIsSorted(dm_all_nodes);
668
669 auto queue = m_accelerator_mng->defaultQueue();
670 auto command = makeCommand(*queue);
671
672 dummy_var.fill(0);
673 auto inout_dummy_var = viewInOut(command, dummy_var);
674 auto in_nodes_coord = viewInOut(command, nodes_coord);
675
676 command << RUNCOMMAND_ENUMERATE(Node, node, dm_all_nodes)
677 {
678 DirNodeLocalId dir_node(node_dm.dirNodeId(node));
679 DirNodeLocalId dir_node2(node_dm2.dirNodeId(node));
680 DirNodeLocalId dir_node3(node_dm3.dirNodeId(node));
681 NodeLocalId prev_node = dir_node.previous();
683 NodeLocalId prev_node2 = dir_node2.previous();
685 NodeLocalId prev_node3 = dir_node3.previous();
687 Int32 vx = 0;
688 if (prev_node != prev_node2)
689 vx = -10;
690 if (next_node != next_node2)
691 vx = -11;
692 if (prev_node != prev_node3)
693 vx = -12;
694 if (next_node != next_node3)
695 vx = -13;
696 if (prev_node != dir_node.previousId())
697 vx = -14;
698 if (next_node != dir_node.nextId())
699 vx = -15;
700 inout_dummy_var[node] = vx;
701 if (vx < 0)
702 return;
703 Real my_coord = in_nodes_coord[node][idir];
704 {
705 Int32 node_nb_cell = cnc.nbCell(node);
706 for (Integer k = 0; k < 8; ++k) {
707 Int32 cell_index = dir_node.cellIndex(k);
708 if (cell_index != (-1)) {
709 if ((1 + cell_index) > node_nb_cell) {
710 inout_dummy_var[node] = -40 - k;
711 return;
712 }
713 }
714 }
715 Int32 sum_id = 20 + dir_node.nextLeftCellId() +
716 dir_node.nextRightCellId() +
717 dir_node.previousRightCellId() +
718 dir_node.previousLeftCellId() +
719 dir_node.topNextLeftCellId() +
720 dir_node.topNextRightCellId() +
721 dir_node.topPreviousRightCellId() +
722 dir_node.topPreviousLeftCellId();
723 inout_dummy_var[node] = sum_id;
724 }
725 if (prev_node.isNull() && next_node.isNull()) {
726 inout_dummy_var[node] = -20;
727 return;
728 }
729 //TODO: Vérifier que les coordonnées autres que celle de idir sont bien les mêmes pour next,prev et my_coord.
730 if (!prev_node.isNull() && !next_node.isNull()) {
733 if (next_coord < prev_coord) {
734 inout_dummy_var[node] = -30;
735 return;
736 }
737 }
738 else {
739 if (!prev_node.isNull()) {
741 if (my_coord < prev_coord) {
742 inout_dummy_var[node] = -31;
743 return;
744 }
745 }
746 if (!next_node.isNull()) {
748 if (next_coord < my_coord) {
749 inout_dummy_var[node] = -32;
750 return;
751 }
752 }
753 }
754 };
755
756 ENUMERATE_ (Node, inode, node_dm.allNodes()) {
757 if (dummy_var[inode] < 0)
758 ARCANE_FATAL("Bad value for dummy_var id={0} v={1}", ItemPrinter(*inode), dummy_var[inode]);
759 }
760 }
761#endif
762}
763
764/*---------------------------------------------------------------------------*/
765/*---------------------------------------------------------------------------*/
766
767void CartesianMeshTestUtils::
768_testDirCellNode()
769{
770 IMesh* mesh = m_mesh;
772 Integer nb_dir = mesh->dimension();
773
774 Integer nb_print = m_nb_print;
775 for (Integer idir = 0; idir < nb_dir; ++idir) {
776 CellDirectionMng cdm(m_cartesian_mesh->cellDirection(idir));
777 eMeshDirection md = cdm.direction();
778 info() << "DIRECTION=" << idir;
779 Integer iprint = 0;
780 ENUMERATE_CELL (icell, cdm.allCells()) {
781 Cell cell = *icell;
783 DirCellNode cn(cdm.cellNode(cell));
784 DirCellNode cn2(cdm.cellNode(cell_id));
785 if (cn.cellId() != cn2.cellId())
786 ARCANE_FATAL("Bad DirCellNode");
787 bool is_print = (nb_print < 0 || iprint < nb_print);
788 ++iprint;
789 if (is_print) {
790 info() << "Cell uid=" << ItemPrinter(cell) << " dir=" << md;
791 info() << "Cell nextLeft =" << ItemPrinter(cn.nextLeft()) << " xyz=" << nodes_coord[cn.nextLeft()];
792 info() << "Cell nextRight=" << ItemPrinter(cn.nextRight()) << " xyz=" << nodes_coord[cn.nextRight()];
793 info() << "Cell prevRight=" << ItemPrinter(cn.previousRight()) << " xyz=" << nodes_coord[cn.previousRight()];
794 info() << "Cell prevLeft =" << ItemPrinter(cn.previousLeft()) << " xyz=" << nodes_coord[cn.previousLeft()];
795 if (nb_dir == 3) {
796 info() << "Cell topNextLeft =" << ItemPrinter(cn.topNextLeft()) << " xyz=" << nodes_coord[cn.topNextLeft()];
797 info() << "Cell topNextRight=" << ItemPrinter(cn.topNextRight()) << " xyz=" << nodes_coord[cn.topNextRight()];
798 info() << "Cell topPrevRight=" << ItemPrinter(cn.topPreviousRight()) << " xyz=" << nodes_coord[cn.topPreviousRight()];
799 info() << "Cell topPrevLeft =" << ItemPrinter(cn.topPreviousLeft()) << " xyz=" << nodes_coord[cn.topPreviousLeft()];
800 }
801 }
802 }
803 }
804}
805
806/*---------------------------------------------------------------------------*/
807/*---------------------------------------------------------------------------*/
808
809void CartesianMeshTestUtils::
810_testDirCellNodeAccelerator()
811{
812#if defined(ARCANE_HAS_ACCELERATOR_API)
813 IMesh* mesh = m_mesh;
815 Integer nb_dir = mesh->dimension();
816
817 VariableCellInt32 dummy_var(VariableBuildInfo(mesh, "DummyCellVariable"));
818 VariableCellReal3 computed_center(VariableBuildInfo(mesh, "CellComputedCenter"));
819
820 for (Integer idir = 0; idir < nb_dir; ++idir) {
821 CellDirectionMng cdm(m_cartesian_mesh->cellDirection(idir));
822 info() << "TEST_DIR_CELL_NODE_ACCELERATOR_DIRECTION=" << idir;
823
824 auto queue = m_accelerator_mng->defaultQueue();
825 auto command = makeCommand(*queue);
826
827 auto inout_dummy_var = viewInOut(command, dummy_var);
828 auto in_nodes_coord = viewIn(command, nodes_coord);
830 command << RUNCOMMAND_ENUMERATE(Cell, cell, cdm.allCells())
831 {
832 inout_dummy_var[cell] = 0;
833 DirCellNodeLocalId cn(cdm.dirCellNodeId(cell));
834 DirCellNodeLocalId cn2(cdm.dirCellNodeId(cell));
835 if (cn.cellId() != cn2.cellId()) {
836 inout_dummy_var[cell] = -10;
837 return;
838 }
839
840 Real3 n1 = in_nodes_coord[cn.nextLeftId()];
841 Real3 n2 = in_nodes_coord[cn.nextRightId()];
842 Real3 n3 = in_nodes_coord[cn.previousRightId()];
843 Real3 n4 = in_nodes_coord[cn.previousLeftId()];
844 Real3 center = n1 + n2 + n3 + n4;
845 if (nb_dir == 3) {
846 Real3 n5 = in_nodes_coord[cn.topNextLeftId()];
847 Real3 n6 = in_nodes_coord[cn.topNextRightId()];
848 Real3 n7 = in_nodes_coord[cn.topPreviousRightId()];
849 Real3 n8 = in_nodes_coord[cn.topPreviousLeftId()];
850 center += n5 + n6 + n7 + n8;
851 center /= 8.0;
852 }
853 else
854 center /= 4.0;
855 out_computed_center[cell] = center;
856 };
857 ENUMERATE_ (Cell, icell, cdm.allCells()) {
858 if (dummy_var[icell] < 0) {
859 ARCANE_FATAL("Bad value for dummy_var id={0} v={1}", ItemPrinter(*icell), dummy_var[icell]);
860 }
861 Real3 c1 = m_cell_center[icell];
863 bool is_nearly_equal = math::isNearlyEqual(c1.x, c2.x) && math::isNearlyEqual(c1.y, c2.y) && math::isNearlyEqual(c1.z, c2.z);
864 if (!is_nearly_equal)
865 ARCANE_FATAL("Bad value for computed center id={0} center={1} computed={2}",
866 ItemPrinter(*icell), c1, c2);
867 }
868 }
869#endif
870}
871
872/*---------------------------------------------------------------------------*/
873/*---------------------------------------------------------------------------*/
874
875void CartesianMeshTestUtils::
876_testDirCellFace()
877{
878 IMesh* mesh = m_mesh;
879 //VariableNodeReal3& nodes_coord = mesh->nodesCoordinates();
880 Integer nb_dir = mesh->dimension();
881 Integer nb_print = m_nb_print;
882 for (Integer idir = 0; idir < nb_dir; ++idir) {
883 CellDirectionMng cdm(m_cartesian_mesh->cellDirection(idir));
884 eMeshDirection md = cdm.direction();
885 info() << "DIRECTION=" << idir;
886 Integer iprint = 0;
887 ENUMERATE_CELL (icell, cdm.allCells()) {
888 Cell cell = *icell;
890 DirCellFace cf(cdm.cellFace(cell));
891 DirCellFace cf2(cdm.cellFace(cell_id));
892 if (cf.cellId() != cf2.cellId())
893 ARCANE_FATAL("Bad DirCellFace");
894 bool is_print = (nb_print < 0 || iprint < nb_print);
895 ++iprint;
896 if (is_print) {
897 info() << "CellFace uid=" << ItemPrinter(cell) << " dir=" << md;
898 info() << "CellFace nextFace =" << ItemPrinter(cf.next()) << " xyz=" << m_face_center[cf.next()];
899 info() << "CellFace prevFace=" << ItemPrinter(cf.previous()) << " xyz=" << m_face_center[cf.previous()];
900 }
901 }
902 }
903}
904
905/*---------------------------------------------------------------------------*/
906/*---------------------------------------------------------------------------*/
907
908void CartesianMeshTestUtils::
909_testDirCellFaceAccelerator()
910{
911#if defined(ARCANE_HAS_ACCELERATOR_API)
912 IMesh* mesh = m_mesh;
913 //VariableNodeReal3& nodes_coord = mesh->nodesCoordinates();
914 Integer nb_dir = mesh->dimension();
915
917 m_connectivity_view.setMesh(mesh);
918 auto cfc = m_connectivity_view.cellFace();
919
920 VariableCellInt32 dummy_var(VariableBuildInfo(mesh, "DummyCellVariable"));
921
922 for (Integer idir = 0; idir < nb_dir; ++idir) {
923 CellDirectionMng cdm(m_cartesian_mesh->cellDirection(idir));
924
925 auto queue = m_accelerator_mng->defaultQueue();
926 auto command = makeCommand(*queue);
927
928 auto inout_dummy_var = viewInOut(command, dummy_var);
929
930 info() << "DIRECTION=" << idir;
931
932 command << RUNCOMMAND_ENUMERATE(Cell, cell, cdm.allCells())
933 {
934 inout_dummy_var[cell] = 0;
935
937 DirCellFaceLocalId cf(cdm.dirCellFaceId(cell));
938 DirCellFaceLocalId cf2(cdm.dirCellFaceId(cell_id));
939 if (cf.cellId() != cf2.cellId()) {
940 inout_dummy_var[cell] = -10;
941 return;
942 }
943
944 Int32 next_index = cf.nextLocalIndex();
945 Int32 previous_index = cf.previousLocalIndex();
946
947 FaceLocalId next_face1 = cf.nextId();
948 FaceLocalId next_face2 = cfc.faceId(cell, next_index);
949 if (next_face1 != next_face2)
950 inout_dummy_var[cell] = -11;
951
952 FaceLocalId previous_face1 = cf.previousId();
955 inout_dummy_var[cell] = -12;
956 };
957 ENUMERATE_ (Cell, icell, cdm.allCells()) {
958 if (dummy_var[icell] < 0) {
959 ARCANE_FATAL("Bad value for dummy_var id={0} v={1}", ItemPrinter(*icell), dummy_var[icell]);
960 }
961 }
962 }
963#endif
964}
965
966/*---------------------------------------------------------------------------*/
967/*---------------------------------------------------------------------------*/
968
969void CartesianMeshTestUtils::
970_testNodeToCellConnectivity3D()
971{
972 info() << "Test NodeToCell Connectivity3D";
973 IMesh* mesh = m_mesh;
975 CartesianConnectivity cc = m_cartesian_mesh->connectivity();
976 ENUMERATE_NODE (inode, m_mesh->allNodes()) {
977 Node node = *inode;
979 info(4) << "node_uid=" << node.uniqueId()
980 << " UL=" << cc.upperLeftId(inode)
981 << " UR=" << cc.upperRightId(inode)
982 << " LR=" << cc.lowerRightId(inode)
983 << " LL=" << cc.lowerLeftId(inode)
984 << " TUL=" << cc.topZUpperLeftId(inode)
985 << " TUR=" << cc.topZUpperRightId(inode)
986 << " TLR=" << cc.topZLowerRightId(inode)
987 << " TLL=" << cc.topZLowerLeftId(inode);
988 {
989 Cell upper_left = cc.upperLeft(node);
990 if (!upper_left.null()) {
991 Real3 c = m_cell_center[upper_left];
992 if (c.y <= node_coord.y || c.x >= node_coord.x || c.z >= node_coord.z)
993 ARCANE_FATAL("Bad upperLeft cell for node={0} c={1} n={2}", ItemPrinter(node), c, node_coord);
994 }
995 }
996 {
997 Cell upper_right = cc.upperRight(node);
998 if (!upper_right.null()) {
999 Real3 c = m_cell_center[upper_right];
1000 if (c.y <= node_coord.y || c.x <= node_coord.x || c.z >= node_coord.z)
1001 ARCANE_FATAL("Bad upperRight cell for node={0} c={1} n={2}", ItemPrinter(node), c, node_coord);
1002 }
1003 }
1004 {
1005 Cell lower_right = cc.lowerRight(node);
1006 if (!lower_right.null()) {
1007 Real3 c = m_cell_center[lower_right];
1008 if (c.y >= node_coord.y || c.x <= node_coord.x || c.z >= node_coord.z)
1009 ARCANE_FATAL("Bad lowerRight cell for node={0} c={1} n={2}", ItemPrinter(node), c, node_coord);
1010 }
1011 }
1012 {
1013 Cell lower_left = cc.lowerLeft(node);
1014 if (!lower_left.null()) {
1015 Real3 c = m_cell_center[lower_left];
1016 if (c.y >= node_coord.y || c.x >= node_coord.x || c.z >= node_coord.z)
1017 ARCANE_FATAL("Bad lowerLeft cell for node={0} c={1} n={2}", ItemPrinter(node), c, node_coord);
1018 }
1019 }
1020 {
1021 Cell top_upper_left = cc.topZUpperLeft(node);
1022 if (!top_upper_left.null()) {
1023 Real3 c = m_cell_center[top_upper_left];
1024 if (c.y <= node_coord.y || c.x >= node_coord.x || c.z <= node_coord.z)
1025 ARCANE_FATAL("Bad topZUpperLeft cell for node={0} c={1} n={2}", ItemPrinter(node), c, node_coord);
1026 }
1027 }
1028 {
1029 Cell top_upper_right = cc.topZUpperRight(node);
1030 if (!top_upper_right.null()) {
1031 Real3 c = m_cell_center[top_upper_right];
1032 if (c.y <= node_coord.y || c.x <= node_coord.x || c.z <= node_coord.z)
1033 ARCANE_FATAL("Bad topZUpperRight cell for node={0} c={1} n={2}", ItemPrinter(node), c, node_coord);
1034 }
1035 }
1036 {
1037 Cell top_lower_right = cc.topZLowerRight(node);
1038 if (!top_lower_right.null()) {
1039 Real3 c = m_cell_center[top_lower_right];
1040 if (c.y >= node_coord.y || c.x <= node_coord.x || c.z <= node_coord.z)
1041 ARCANE_FATAL("Bad topZLowerRight cell for node={0} c={1} n={2}", ItemPrinter(node), c, node_coord);
1042 }
1043 }
1044 {
1045 Cell top_lower_left = cc.topZLowerLeft(node);
1046 if (!top_lower_left.null()) {
1047 Real3 c = m_cell_center[top_lower_left];
1048 if (c.y >= node_coord.y || c.x >= node_coord.x || c.z <= node_coord.z)
1049 ARCANE_FATAL("Bad topZLowerLeft cell for node={0} c={1} n={2}", ItemPrinter(node), c, node_coord);
1050 }
1051 }
1052 }
1053}
1054
1055/*---------------------------------------------------------------------------*/
1056/*---------------------------------------------------------------------------*/
1057
1058void CartesianMeshTestUtils::
1059_testNodeToCellConnectivity3DAccelerator()
1060{
1061#if defined(ARCANE_HAS_ACCELERATOR_API)
1062 info() << "Test NodeToCell Connectivity3D";
1063 IMesh* mesh = m_mesh;
1065 VariableNodeInt32 dummy_var(VariableBuildInfo(mesh, "DummyNodeVariable"));
1066 CartesianConnectivityLocalId cc = m_cartesian_mesh->connectivity();
1067
1068 auto queue = m_accelerator_mng->defaultQueue();
1069 auto command = makeCommand(*queue);
1070
1071 auto in_cell_center = viewIn(command, m_cell_center);
1072 auto in_node_coord = viewIn(command, nodes_coord);
1073 auto inout_dummy_var = viewInOut(command, dummy_var);
1074 command << RUNCOMMAND_ENUMERATE(Node, node, m_mesh->allNodes())
1075 {
1077 {
1078 CellLocalId upper_left = cc.upperLeftId(node);
1079 if (!upper_left.isNull()) {
1081 if (c.y <= node_coord.y || c.x >= node_coord.x || c.z >= node_coord.z)
1082 inout_dummy_var[node] = -10;
1083 }
1084 }
1085 {
1086 CellLocalId upper_right = cc.upperRightId(node);
1087 if (!upper_right.isNull()) {
1089 if (c.y <= node_coord.y || c.x <= node_coord.x || c.z >= node_coord.z)
1090 inout_dummy_var[node] = -11;
1091 }
1092 }
1093 {
1094 CellLocalId lower_right = cc.lowerRightId(node);
1095 if (!lower_right.isNull()) {
1097 if (c.y >= node_coord.y || c.x <= node_coord.x || c.z >= node_coord.z)
1098 inout_dummy_var[node] = -12;
1099 }
1100 }
1101 {
1102 CellLocalId lower_left = cc.lowerLeftId(node);
1103 if (!lower_left.isNull()) {
1105 if (c.y >= node_coord.y || c.x >= node_coord.x || c.z >= node_coord.z)
1106 inout_dummy_var[node] = -13;
1107 }
1108 }
1109 {
1110 CellLocalId top_upper_left = cc.topZUpperLeftId(node);
1111 if (!top_upper_left.isNull()) {
1113 if (c.y <= node_coord.y || c.x >= node_coord.x || c.z <= node_coord.z)
1114 inout_dummy_var[node] = -14;
1115 }
1116 }
1117 {
1118 CellLocalId top_upper_right = cc.topZUpperRightId(node);
1119 if (!top_upper_right.isNull()) {
1121 if (c.y <= node_coord.y || c.x <= node_coord.x || c.z <= node_coord.z)
1122 inout_dummy_var[node] = -15;
1123 }
1124 }
1125 {
1126 CellLocalId top_lower_right = cc.topZLowerRightId(node);
1127 if (!top_lower_right.isNull()) {
1129 if (c.y >= node_coord.y || c.x <= node_coord.x || c.z <= node_coord.z)
1130 inout_dummy_var[node] = -16;
1131 }
1132 }
1133 {
1134 CellLocalId top_lower_left = cc.topZLowerLeftId(node);
1135 if (!top_lower_left.isNull()) {
1137 if (c.y >= node_coord.y || c.x >= node_coord.x || c.z <= node_coord.z)
1138 inout_dummy_var[node] = -17;
1139 }
1140 }
1141 };
1142 ENUMERATE_ (Node, inode, m_mesh->allNodes()) {
1143 if (dummy_var[inode] < 0) {
1144 ARCANE_FATAL("Bad value for dummy_var id={0} v={1}", ItemPrinter(*inode), dummy_var[inode]);
1145 }
1146 }
1147#endif
1148}
1149
1150/*---------------------------------------------------------------------------*/
1151/*---------------------------------------------------------------------------*/
1152
1153void CartesianMeshTestUtils::
1154_testNodeToCellConnectivity2D()
1155{
1156 info() << "Test NodeToCell Connectivity 2D";
1157 IMesh* mesh = m_mesh;
1159 CartesianConnectivity cc = m_cartesian_mesh->connectivity();
1160 ENUMERATE_NODE (inode, mesh->allNodes()) {
1161 Node node = *inode;
1163 info(4) << "node_uid=" << node.uniqueId()
1164 << " UL=" << cc.upperLeftId(inode)
1165 << " UR=" << cc.upperRightId(inode)
1166 << " LR=" << cc.lowerRightId(inode)
1167 << " LL=" << cc.lowerLeftId(inode);
1168 {
1169 Cell upper_left = cc.upperLeft(node);
1170 if (!upper_left.null()) {
1171 Real3 c = m_cell_center[upper_left];
1172 if (c.y <= node_coord.y || c.x >= node_coord.x)
1173 ARCANE_FATAL("Bad upperLeft cell for node={0} c={1} n={2}", ItemPrinter(node), c, node_coord);
1174 }
1175 }
1176 {
1177 Cell upper_right = cc.upperRight(node);
1178 if (!upper_right.null()) {
1179 Real3 c = m_cell_center[upper_right];
1180 if (c.y <= node_coord.y || c.x <= node_coord.x)
1181 ARCANE_FATAL("Bad upperRight cell for node={0} c={1} n={2}", ItemPrinter(node), c, node_coord);
1182 }
1183 }
1184 {
1185 Cell lower_right = cc.lowerRight(node);
1186 if (!lower_right.null()) {
1187 Real3 c = m_cell_center[lower_right];
1188 if (c.y >= node_coord.y || c.x <= node_coord.x)
1189 ARCANE_FATAL("Bad lowerRight cell for node={0} c={1} n={2}", ItemPrinter(node), c, node_coord);
1190 }
1191 }
1192 {
1193 Cell lower_left = cc.lowerLeft(node);
1194 if (!lower_left.null()) {
1195 Real3 c = m_cell_center[lower_left];
1196 if (c.y >= node_coord.y || c.x >= node_coord.x)
1197 ARCANE_FATAL("Bad lowerLeft cell for node={0} c={1} n={2}", ItemPrinter(node), c, node_coord);
1198 }
1199 }
1200 }
1201}
1202
1203/*---------------------------------------------------------------------------*/
1204/*---------------------------------------------------------------------------*/
1205
1206void CartesianMeshTestUtils::
1207_testCellToNodeConnectivity3D()
1208{
1209 info() << "Test CellToNode Connectivity3D";
1210 IMesh* mesh = m_mesh;
1212 CartesianConnectivity cc = m_cartesian_mesh->connectivity();
1213 const bool is_not_amr = !m_is_amr;
1214 ENUMERATE_CELL (icell, m_mesh->allCells()) {
1215 Cell cell = *icell;
1216 Real3 cell_coord = m_cell_center[icell];
1217 info(4) << "cell_uid=" << cell.uniqueId()
1218 << " UL=" << cc.upperLeftId(icell)
1219 << " UR=" << cc.upperRightId(icell)
1220 << " LR=" << cc.lowerRightId(icell)
1221 << " LL=" << cc.lowerLeftId(icell)
1222 << " TUL=" << cc.topZUpperLeftId(icell)
1223 << " TUR=" << cc.topZUpperRightId(icell)
1224 << " TLR=" << cc.topZLowerRightId(icell)
1225 << " TLL=" << cc.topZLowerLeftId(icell);
1226 {
1227 Node upper_left = cc.upperLeft(cell);
1228 Cell ccell = cc.topZLowerRight(upper_left);
1230 if (n.y <= cell_coord.y || n.x >= cell_coord.x || n.z >= cell_coord.z)
1231 ARCANE_FATAL("Bad upperLeft node for cell={0}", ItemPrinter(cell));
1232 if (cell != ccell && is_not_amr)
1233 ARCANE_FATAL("Bad correspondance UL -> TLR cell={0} corresponding_cell={1}", ItemPrinter(cell), ccell);
1234 }
1235 {
1236 Node upper_right = cc.upperRight(cell);
1237 Cell ccell = cc.topZLowerLeft(upper_right);
1239 if (n.y <= cell_coord.y || n.x <= cell_coord.x || n.z >= cell_coord.z)
1240 ARCANE_FATAL("Bad upperRight node for cell={0}", ItemPrinter(cell));
1241 if (cell != ccell && is_not_amr)
1242 ARCANE_FATAL("Bad correspondance UR -> TLL cell={0} corresponding_cell={1}", ItemPrinter(cell), ccell);
1243 }
1244 {
1245 Node lower_right = cc.lowerRight(cell);
1246 Cell ccell = cc.topZUpperLeft(lower_right);
1248 if (n.y >= cell_coord.y || n.x <= cell_coord.x || n.z >= cell_coord.z)
1249 ARCANE_FATAL("Bad lowerRight node for cell={0}", ItemPrinter(cell));
1250 if (cell != ccell && is_not_amr)
1251 ARCANE_FATAL("Bad correspondance LR -> TUL cell={0} corresponding_cell={1}", ItemPrinter(cell), ccell);
1252 }
1253 {
1254 Node lower_left = cc.lowerLeft(cell);
1255 Cell ccell = cc.topZUpperRight(lower_left);
1257 if (n.y >= cell_coord.y || n.x >= cell_coord.x || n.z >= cell_coord.z)
1258 ARCANE_FATAL("Bad lowerLeft node for cell={0}", ItemPrinter(cell));
1259 if (cell != ccell && is_not_amr)
1260 ARCANE_FATAL("Bad correspondance LL -> TUR cell={0} corresponding_cell={1}", ItemPrinter(cell), ccell);
1261 }
1262 {
1263 Node top_upper_left = cc.topZUpperLeft(cell);
1264 Cell ccell = cc.lowerRight(top_upper_left);
1266 if (n.y <= cell_coord.y || n.x >= cell_coord.x || n.z <= cell_coord.z)
1267 ARCANE_FATAL("Bad topZUpperLeft node for cell={0}", ItemPrinter(cell));
1268 if (cell != ccell && is_not_amr)
1269 ARCANE_FATAL("Bad correspondance TUL -> LR cell={0} corresponding_cell={1}", ItemPrinter(cell), ccell);
1270 }
1271 {
1272 Node top_upper_right = cc.topZUpperRight(cell);
1273 Cell ccell = cc.lowerLeft(top_upper_right);
1275 if (n.y <= cell_coord.y || n.x <= cell_coord.x || n.z <= cell_coord.z)
1276 ARCANE_FATAL("Bad topZUpperRight node for cell={0}", ItemPrinter(cell));
1277 if (cell != ccell && is_not_amr)
1278 ARCANE_FATAL("Bad correspondance TUR -> LL cell={0} corresponding_cell={1}", ItemPrinter(cell), ccell);
1279 }
1280 {
1281 Node top_lower_right = cc.topZLowerRight(cell);
1282 Cell ccell = cc.upperLeft(top_lower_right);
1284 if (n.y >= cell_coord.y || n.x <= cell_coord.x || n.z <= cell_coord.z)
1285 ARCANE_FATAL("Bad topZLowerRight node for cell={0}", ItemPrinter(cell));
1286 if (cell != ccell && is_not_amr)
1287 ARCANE_FATAL("Bad correspondance TLR -> UL cell={0} corresponding_cell={1}", ItemPrinter(cell), ccell);
1288 }
1289 {
1290 Node top_lower_left = cc.topZLowerLeft(cell);
1291 Cell ccell = cc.upperRight(top_lower_left);
1293 if (n.y >= cell_coord.y || n.x >= cell_coord.x || n.z <= cell_coord.z)
1294 ARCANE_FATAL("Bad topZLowerLeft node for cell={0}", ItemPrinter(cell));
1295 if (cell != ccell && is_not_amr)
1296 ARCANE_FATAL("Bad correspondance TLL -> UR cell={0} corresponding_cell={1}", ItemPrinter(cell), ccell);
1297 }
1298 }
1299}
1300
1301/*---------------------------------------------------------------------------*/
1302/*---------------------------------------------------------------------------*/
1303
1304void CartesianMeshTestUtils::
1305_testCellToNodeConnectivity3DAccelerator()
1306{
1307#if defined(ARCANE_HAS_ACCELERATOR_API)
1308 info() << "Test CellToNode Connectivity3D Accelerator";
1309 IMesh* mesh = m_mesh;
1310 VariableCellInt32 dummy_var(VariableBuildInfo(mesh, "DummyCellVariable"));
1312 CartesianConnectivityLocalId cc = m_cartesian_mesh->connectivity();
1313 const bool is_not_amr = !m_is_amr;
1314
1315 auto queue = m_accelerator_mng->defaultQueue();
1316 auto command = makeCommand(*queue);
1317
1318 auto in_cell_center = viewIn(command, m_cell_center);
1319 auto in_node_coord = viewIn(command, nodes_coord);
1320 auto inout_dummy_var = viewInOut(command, dummy_var);
1321
1322 command << RUNCOMMAND_ENUMERATE(Cell, cell, m_mesh->allCells())
1323 {
1325 inout_dummy_var[cell] = 0;
1326 {
1327 NodeLocalId upper_left = cc.upperLeftId(cell);
1328 CellLocalId ccell = cc.topZLowerRightId(upper_left);
1330 if (n.y <= cell_coord.y || n.x >= cell_coord.x || n.z >= cell_coord.z)
1331 inout_dummy_var[cell] = -10;
1332 if (cell != ccell && is_not_amr)
1333 inout_dummy_var[cell] = -20;
1334 }
1335 {
1336 NodeLocalId upper_right = cc.upperRightId(cell);
1337 CellLocalId ccell = cc.topZLowerLeftId(upper_right);
1339 if (n.y <= cell_coord.y || n.x <= cell_coord.x || n.z >= cell_coord.z)
1340 inout_dummy_var[cell] = -11;
1341 if (cell != ccell && is_not_amr)
1342 inout_dummy_var[cell] = -21;
1343 }
1344 {
1345 NodeLocalId lower_right = cc.lowerRightId(cell);
1346 CellLocalId ccell = cc.topZUpperLeftId(lower_right);
1348 if (n.y >= cell_coord.y || n.x <= cell_coord.x || n.z >= cell_coord.z)
1349 inout_dummy_var[cell] = -12;
1350 if (cell != ccell && is_not_amr)
1351 inout_dummy_var[cell] = -22;
1352 }
1353 {
1354 NodeLocalId lower_left = cc.lowerLeftId(cell);
1355 CellLocalId ccell = cc.topZUpperRightId(lower_left);
1357 if (n.y >= cell_coord.y || n.x >= cell_coord.x || n.z >= cell_coord.z)
1358 inout_dummy_var[cell] = -13;
1359 if (cell != ccell && is_not_amr)
1360 inout_dummy_var[cell] = -23;
1361 }
1362 {
1363 NodeLocalId top_upper_left = cc.topZUpperLeftId(cell);
1364 CellLocalId ccell = cc.lowerRightId(top_upper_left);
1366 if (n.y <= cell_coord.y || n.x >= cell_coord.x || n.z <= cell_coord.z)
1367 inout_dummy_var[cell] = -14;
1368 if (cell != ccell && is_not_amr)
1369 inout_dummy_var[cell] = -24;
1370 }
1371 {
1372 NodeLocalId top_upper_right = cc.topZUpperRightId(cell);
1373 CellLocalId ccell = cc.lowerLeftId(top_upper_right);
1375 if (n.y <= cell_coord.y || n.x <= cell_coord.x || n.z <= cell_coord.z)
1376 inout_dummy_var[cell] = -15;
1377 if (cell != ccell && is_not_amr)
1378 inout_dummy_var[cell] = -25;
1379 }
1380 {
1381 NodeLocalId top_lower_right = cc.topZLowerRightId(cell);
1382 CellLocalId ccell = cc.upperLeftId(top_lower_right);
1384 if (n.y >= cell_coord.y || n.x <= cell_coord.x || n.z <= cell_coord.z)
1385 inout_dummy_var[cell] = -16;
1386 if (cell != ccell && is_not_amr)
1387 inout_dummy_var[cell] = -26;
1388 }
1389 {
1390 NodeLocalId top_lower_left = cc.topZLowerLeftId(cell);
1391 CellLocalId ccell = cc.upperRightId(top_lower_left);
1393 if (n.y >= cell_coord.y || n.x >= cell_coord.x || n.z <= cell_coord.z)
1394 inout_dummy_var[cell] = -17;
1395 if (cell != ccell && is_not_amr)
1396 inout_dummy_var[cell] = -27;
1397 }
1398 };
1399 ENUMERATE_ (Cell, icell, m_mesh->allCells()) {
1400 if (dummy_var[icell] < 0) {
1401 ARCANE_FATAL("Bad value for dummy_var id={0} v={1}", ItemPrinter(*icell), dummy_var[icell]);
1402 }
1403 }
1404#endif
1405}
1406
1407/*---------------------------------------------------------------------------*/
1408/*---------------------------------------------------------------------------*/
1409
1410void CartesianMeshTestUtils::
1411_testCellToNodeConnectivity2D()
1412{
1413 info() << "Test CellToNode Connectivity 2D";
1414 IMesh* mesh = m_mesh;
1416 CartesianConnectivity cc = m_cartesian_mesh->connectivity();
1417 const bool is_not_amr = !m_is_amr;
1418 ENUMERATE_CELL (icell, mesh->allCells()) {
1419 Cell cell = *icell;
1420 Real3 cell_coord = m_cell_center[icell];
1421 info(4) << "cell_uid=" << cell.uniqueId()
1422 << " UL=" << cc.upperLeftId(icell)
1423 << " UR=" << cc.upperRightId(icell)
1424 << " LR=" << cc.lowerRightId(icell)
1425 << " LL=" << cc.lowerLeftId(icell);
1426 {
1427 Node upper_left = cc.upperLeft(cell);
1428 Cell ccell = cc.lowerRight(upper_left);
1430 if (n.y <= cell_coord.y || n.x >= cell_coord.x)
1431 ARCANE_FATAL("Bad upperLeft node for cell={0} c={1} n={2}", ItemPrinter(cell), cell_coord, n);
1432 if (cell != ccell && is_not_amr)
1433 ARCANE_FATAL("Bad correspondance UL -> LR cell={0} corresponding_cell={1}", ItemPrinter(cell), ccell);
1434 }
1435 {
1436 Node upper_right = cc.upperRight(cell);
1437 Cell ccell = cc.lowerLeft(upper_right);
1439 if (n.y <= cell_coord.y || n.x <= cell_coord.x)
1440 ARCANE_FATAL("Bad upperRight node for cell={0} c={1} n={2}", ItemPrinter(cell), cell_coord, n);
1441 if (cell != ccell && is_not_amr)
1442 ARCANE_FATAL("Bad correspondance UR -> LF cell={0} corresponding_cell={1}", ItemPrinter(cell), ccell);
1443 }
1444 {
1445 Node lower_right = cc.lowerRight(cell);
1446 Cell ccell = cc.upperLeft(lower_right);
1448 if (n.y >= cell_coord.y || n.x <= cell_coord.x)
1449 ARCANE_FATAL("Bad lowerRight node for cell={0} c={1} n={2}", ItemPrinter(cell), cell_coord, n);
1450 if (cell != ccell && is_not_amr)
1451 ARCANE_FATAL("Bad correspondance UL -> LR cell={0} corresponding_cell={1}", ItemPrinter(cell), ccell);
1452 }
1453 {
1454 Node lower_left = cc.lowerLeft(cell);
1455 Cell ccell = cc.upperRight(lower_left);
1457 if (n.y >= cell_coord.y || n.x >= cell_coord.x)
1458 ARCANE_FATAL("Bad lowerLeft node for cell={0} c={1} n={2}", ItemPrinter(cell), cell_coord, n);
1459 if (cell != ccell && is_not_amr)
1460 ARCANE_FATAL("Bad correspondance LL -> UR cell={0} corresponding_cell={1}", ItemPrinter(cell), ccell);
1461 }
1462 }
1463}
1464
1465/*---------------------------------------------------------------------------*/
1466/*---------------------------------------------------------------------------*/
1467
1468template<typename ItemType> void CartesianMeshTestUtils::
1469_testConnectivityByDirectionHelper(const ItemGroup& group)
1470{
1471 ValueChecker vc(A_FUNCINFO);
1472 Int32 nb_dim = m_mesh->dimension();
1473
1474 info() << "Test ConnectivityByDirection 2D";
1475 CartesianConnectivity cc = m_cartesian_mesh->connectivity();
1476 ENUMERATE_ (ItemType, iitem, group) {
1477 vc.areEqual(cc.upperLeftId(iitem),cc.upperLeftId(iitem,0),"Item0 dir0");
1478 vc.areEqual(cc.upperRightId(iitem),cc.upperRightId(iitem,0),"Item1 dir0");
1479 vc.areEqual(cc.lowerRightId(iitem),cc.lowerRightId(iitem,0),"Item2 dir0");
1480 vc.areEqual(cc.lowerLeftId(iitem),cc.lowerLeftId(iitem,0),"Item3 dir0");
1481
1482 if (nb_dim>1){
1483 vc.areEqual(cc.lowerLeftId(iitem),cc.upperLeftId(iitem,1),"Item0 dir1");
1484 vc.areEqual(cc.upperLeftId(iitem),cc.upperRightId(iitem,1),"Item1 dir1");
1485 vc.areEqual(cc.upperRightId(iitem),cc.lowerRightId(iitem,1),"Item2 dir1");
1486 vc.areEqual(cc.lowerRightId(iitem),cc.lowerLeftId(iitem,1),"Item3 dir1");
1487 }
1488
1489 if (nb_dim>2){
1490 vc.areEqual(cc.upperRightId(iitem),cc.upperLeftId(iitem,2),"Item0 dir2");
1491 vc.areEqual(cc.topZUpperRightId(iitem),cc.upperRightId(iitem,2),"Item1 dir2");
1492 vc.areEqual(cc.topZLowerRightId(iitem),cc.lowerRightId(iitem,2),"Item2 dir2");
1493 vc.areEqual(cc.lowerRightId(iitem),cc.lowerLeftId(iitem,2),"Item3 dir2");
1494
1495 vc.areEqual(cc.upperLeftId(iitem),cc.topZUpperLeftId(iitem,2),"Item4 dir2");
1496 vc.areEqual(cc.topZUpperLeftId(iitem),cc.topZUpperRightId(iitem,2),"Item5 dir2");
1497 vc.areEqual(cc.topZLowerLeftId(iitem),cc.topZLowerRightId(iitem,2),"Item6 dir2");
1498 vc.areEqual(cc.lowerLeftId(iitem),cc.topZLowerLeftId(iitem,2),"Item7 dir2");
1499 }
1500 }
1501}
1502
1503/*---------------------------------------------------------------------------*/
1504/*---------------------------------------------------------------------------*/
1505
1506void CartesianMeshTestUtils::
1507_testConnectivityByDirection()
1508{
1509 info() << "Test Node ConnectivityByDirection";
1510 _testConnectivityByDirectionHelper<Node>(m_mesh->allNodes());
1511 info() << "Test Cell ConnectivityByDirection";
1512 _testConnectivityByDirectionHelper<Cell>(m_mesh->allCells());
1513}
1514
1515/*---------------------------------------------------------------------------*/
1516/*---------------------------------------------------------------------------*/
1517
1518void CartesianMeshTestUtils::
1520{
1522 CartesianConnectivity cc = cartesian_mesh->connectivity();
1523 ENUMERATE_NODE (inode, m_mesh->allNodes()) {
1524 Node n = *inode;
1525 Cell c1 = cc.upperLeft(n); // Maille en haut à gauche
1526 Cell c2 = cc.upperRight(n); // Maille en haut à droite
1527 Cell c3 = cc.lowerRight(n); // Maille en bas à droite
1528 Cell c4 = cc.lowerLeft(n); // Maille en bas à gauche
1529 info(6) << " C1=" << ItemPrinter(c1) << " C2=" << ItemPrinter(c2)
1530 << " C3=" << ItemPrinter(c3) << " C4=" << ItemPrinter(c4);
1531 }
1533}
1534
1535/*---------------------------------------------------------------------------*/
1536/*---------------------------------------------------------------------------*/
1537
1538void CartesianMeshTestUtils::
1539_saveSVG()
1540{
1541 ICartesianMesh* cm = m_cartesian_mesh;
1542 IMesh* mesh = cm->mesh();
1543 info() << "Saving mesh to SVG format";
1544 std::ofstream ofile("toto.svg");
1546 writer.write(mesh->allCells());
1547}
1548
1549/*---------------------------------------------------------------------------*/
1550/*---------------------------------------------------------------------------*/
1551
1552} // End namespace ArcaneTest
1553
1554/*---------------------------------------------------------------------------*/
1555/*---------------------------------------------------------------------------*/
#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:120
Infos sur les noeuds d'une direction spécifique X,Y ou Z d'un maillage structuré.
Noeud d'un maillage.
Definition Dom.h:204
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.
auto viewInOut(RunCommand &cmd, CellMaterialVariableScalarRef< DataType > &var)
Vue en lecture/écriture pour les variables materiaux scalaire.
RunCommand makeCommand(const RunQueue &run_queue)
Créé une commande associée à la file run_queue.
auto viewIn(RunCommand &cmd, const CellMaterialVariableScalarRef< DataType > &var)
Vue en lecture pour les variables materiaux scalaire.
auto viewOut(RunCommand &cmd, CellMaterialVariableScalarRef< DataType > &var)
Vue en écriture 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