Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
MeshRefinement.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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/* MeshRefinement.h (C) 2000-2024 */
9/* */
10/* Management of unstructured mesh adaptation by refinement */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_MESH_MESHREFINEMENT_H
13#define ARCANE_MESH_MESHREFINEMENT_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/TraceAccessor.h"
18#include "arcane/utils/PerfCounterMng.h"
19#include "arcane/utils/AMRCallBackMng.h"
20
21#include "arcane/core/ItemRefinementPattern.h"
22
23#include "arcane/mesh/MeshGlobal.h"
24#include "arcane/mesh/MapCoordToUid.h"
25#include "arcane/mesh/DynamicMeshKindInfos.h"
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30namespace Arcane
31{
32class IMesh;
33class Node;
34class Cell;
35class AMRCallBackMng;
36class FaceFamily;
37} // namespace Arcane
38
39/*---------------------------------------------------------------------------*/
40/*---------------------------------------------------------------------------*/
41
42namespace Arcane::mesh
43{
44
45class DynamicMesh;
46class ItemRefinement;
48
49/*---------------------------------------------------------------------------*/
50/*---------------------------------------------------------------------------*/
55: public TraceAccessor
56{
57 public:
58
59#ifdef ACTIVATE_PERF_COUNTER
60 struct PerfCounter
61 {
62 typedef enum
63 {
64 INIT,
65 CLEAR,
66 ENDUPDATE,
67 UPDATEMAP,
68 UPDATEMAP2,
69 CONSIST,
70 PCONSIST,
71 PCONSIST2,
72 PGCONSIST,
73 CONTRACT,
74 COARSEN,
75 REFINE,
76 INTERP,
77 PGHOST,
78 COMPACT,
79 NbCounters
80 } eType;
81
82 static const std::string m_names[NbCounters];
83 };
84#endif
89
90 private:
91
92 // The copy constructor and assignment operator are
93 // declared private but not implemented. This is the
94 // standard technique to prevent them from being used.
96 MeshRefinement& operator=(const MeshRefinement&);
97
98 public:
99
104
108 void clear();
112 void init();
113
114 void update();
115 bool needUpdate() const
116 {
117 return m_need_update;
118 }
119 void invalidate()
120 {
121 m_need_update = true;
122 }
123 void initMeshContainingBox();
127 void flagItems(const Int32Array& flag_per_cell,
128 const Integer max_level = -1);
129
141 virtual void flagCellToRefine(Int32ConstArrayView cells_lids);
142 virtual void flagCellToCoarsen(Int32ConstArrayView cells_lids);
143
153 bool refineAndCoarsenItems(const bool maintain_level_one = true);
154
164 bool coarsenItems(const bool maintain_level_one = true);
165
178 bool coarsenItemsV2(bool update_parent_flag);
179
188 bool refineItems(const bool maintain_level_one = true);
189
193 void uniformlyRefine(Integer n = 1);
194
198 void uniformlyCoarsen(Integer n = 1);
199
206 Integer& maxLevel();
207
209 const IMesh* getMesh() const;
210
212 IMesh* getMesh();
213
215 void registerCallBack(IAMRTransportFunctor* f);
217 void unRegisterCallBack(IAMRTransportFunctor* f);
223 Int64 findOrAddNodeUid(const Real3& p, const Real& tol);
229 Int64 findOrAddFaceUid(const Real3& face_center, const Real& tol, bool& is_added);
234
235 void _update(ArrayView<ItemInternal*> cells_to_refine);
236 void _update(ArrayView<Int64> cells_to_refine);
237 void _invalidate(ArrayView<ItemInternal*> cells_to_coarsen);
238 void _updateMaxUid(ArrayView<ItemInternal*> cells_to_refine);
239
243 template <int typeID> const ItemRefinementPatternT<typeID>& getRefinementPattern() const;
248 void populateBackFrontCellsFromParentFaces(Cell parent_cell);
249
250 private:
251
258 bool _checkLevelOne(bool arcane_assert_yes = false);
259
267 bool _checkUnflagged(bool arcane_assert_yes = false);
268
276 bool& coarsenByParents();
277
288 unsigned char& faceLevelMismatchLimit();
289
296 bool _contract();
297
299 void _interpolateData(const Int64Array& cells_to_refine);
300
302 void _upscaleData(Array<ItemInternal*>& parent_cells);
303
304 private:
305
315 bool _coarsenItems();
316
324 bool _refineItems(Int64Array& cells_to_refine);
325
326 // Updates the owners of items from the cells
327 void _updateItemOwner(Int32ArrayView cell_to_remove);
328 void _updateItemOwner2();
330 bool _removeGhostChildren();
331 //---------------------------------------------
332 // Utility algorithms
333
337 void _updateLocalityMap();
338 void _updateLocalityMap2();
344
348 bool _makeCoarseningCompatible(const bool);
349
353 bool _makeRefinementCompatible(const bool);
354
360 bool _makeFlagParallelConsistent2();
361
365 template <int typeID>
367 template <int typeID>
368 void _populateBackFrontCellsFromChildrenFaces(Face face, Cell parent_cell,
369 Cell neighbor_cell);
370
371 void _checkOwner(const String& msg); // To avoid owner desynchronization
372
373 private:
374
379 FaceFamily* m_face_family;
380 bool m_need_update;
381
387 NodeMapCoordToUid m_node_finder;
388 FaceMapCoordToUid m_face_finder;
389
394
399
404
408
410 Integer m_max_level;
411 Integer m_nb_cell_target;
412 Byte m_face_level_mismatch_limit;
413
414 Int64 m_max_node_uid;
415 Int64 m_next_node_uid;
416
417 Int64 m_max_cell_uid;
418 Int64 m_next_cell_uid;
419
420 Int64 m_max_face_uid;
421 Int64 m_next_face_uid;
422
423 Integer m_max_nb_hChildren;
424
428 const Quad4RefinementPattern4Quad m_quad4_refinement_pattern;
429 const TetraRefinementPattern2Hex_2Penta_2Py_2Tetra m_tetra_refinement_pattern;
430 const PyramidRefinementPattern4Hex_4Py m_pyramid_refinement_pattern;
431 const PrismRefinementPattern4Hex_4Pr m_prism_refinement_pattern;
432 const HexRefinementPattern8Hex m_hex_refinement_pattern;
433 const HemiHex7RefinementPattern6Hex_2HHex7 m_hemihexa7_refinement_pattern;
434 const HemiHex6RefinementPattern4Hex_4HHex7 m_hemihexa6_refinement_pattern;
435 const HemiHex5RefinementPattern2Hex_4Penta_2HHex5 m_hemihexa5_refinement_pattern;
436 const AntiWedgeLeft6RefinementPattern4Hex_4HHex7 m_antiwedgeleft6_refinement_pattern;
437 const AntiWedgeRight6RefinementPattern4Hex_4HHex7 m_antiwedgeright6_refinement_pattern;
438 const DiTetra5RefinementPattern2Hex_6HHex7 m_ditetra5_refinement_pattern;
439
440 // Node owner memory : to patch owner desynchronization
441 VariableNodeInt32 m_node_owner_memory;
442
443#ifdef ACTIVATE_PERF_COUNTER
444 PerfCounterMng<PerfCounter> m_perf_counter;
445#endif
446};
447
448/*---------------------------------------------------------------------------*/
449/*---------------------------------------------------------------------------*/
450
451// MeshRefinement class inline members
452
454{
456}
457
458/*---------------------------------------------------------------------------*/
459/*---------------------------------------------------------------------------*/
460
462{
463 return m_max_level;
464}
465
466/*---------------------------------------------------------------------------*/
467/*---------------------------------------------------------------------------*/
468
470{
471 return m_face_level_mismatch_limit;
472}
473/*---------------------------------------------------------------------------*/
474/*---------------------------------------------------------------------------*/
475
476template <>
479{
481}
482template <>
485{
486 return m_tetra_refinement_pattern;
487}
488template <>
489inline const ItemRefinementPatternT<IT_Pyramid5>&
491{
492 return m_pyramid_refinement_pattern;
493}
494template <>
495inline const ItemRefinementPatternT<IT_Pentaedron6>&
497{
498 return m_prism_refinement_pattern;
499}
500template <>
501inline const ItemRefinementPatternT<IT_Hexaedron8>&
503{
504 return m_hex_refinement_pattern;
505}
506template <>
507inline const ItemRefinementPatternT<IT_HemiHexa7>&
509{
510 return m_hemihexa7_refinement_pattern;
511}
512template <>
513inline const ItemRefinementPatternT<IT_HemiHexa6>&
515{
516 return m_hemihexa6_refinement_pattern;
517}
518template <>
519inline const ItemRefinementPatternT<IT_HemiHexa5>&
521{
522 return m_hemihexa5_refinement_pattern;
523}
524template <>
525inline const ItemRefinementPatternT<IT_AntiWedgeLeft6>&
527{
528 return m_antiwedgeleft6_refinement_pattern;
529}
530template <>
531inline const ItemRefinementPatternT<IT_AntiWedgeRight6>&
533{
534 return m_antiwedgeright6_refinement_pattern;
535}
536template <>
537inline const ItemRefinementPatternT<IT_DiTetra5>&
539{
540 return m_ditetra5_refinement_pattern;
541}
542
543/*---------------------------------------------------------------------------*/
544/*---------------------------------------------------------------------------*/
545
546} // End namespace Arcane::mesh
547
548/*---------------------------------------------------------------------------*/
549/*---------------------------------------------------------------------------*/
550
551#endif
Modifiable view of an array of type T.
Base class for 1D data vectors.
Cell of a mesh.
Definition Item.h:1300
Face of a cell.
Definition Item.h:1032
Interface of a functor with argument.
Node of a mesh.
Definition Item.h:598
Class managing a 3-dimensional real vector.
Definition Real3.h:132
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
Implementation of a mesh.
Definition DynamicMesh.h:98
bool _checkUnflagged(bool arcane_assert_yes=false)
MeshRefinement(DynamicMesh *mesh)
void populateBackFrontCellsFromChildrenFaces(Cell parent_cell)
const Quad4RefinementPattern4Quad m_quad4_refinement_pattern
bool coarsenItemsV2(bool update_parent_flag)
Method allowing the removal of cells marked with the flag "II_Coarsen".
bool refineAndCoarsenItems(const bool maintain_level_one=true)
bool refineItems(const bool maintain_level_one=true)
void flagItems(const Int32Array &flag_per_cell, const Integer max_level=-1)
unsigned char & faceLevelMismatchLimit()
const IMesh * getMesh() const
Constant reference to the mesh.
void uniformlyCoarsen(Integer n=1)
Int64 findOrAddFaceUid(const Real3 &face_center, const Real &tol, bool &is_added)
MapCoordToUid::Box m_mesh_containing_box
ParallelAMRConsistency * m_parallel_amr_consistency
bool _makeCoarseningCompatible(const bool)
const ItemRefinementPatternT< typeID > & getRefinementPattern() const
bool _makeRefinementCompatible(const bool)
void _upscaleData(Array< ItemInternal * > &parent_cells)
Upscaling of data on the parent cells.
ItemRefinement * m_item_refinement
Int64 findOrAddNodeUid(const Real3 &p, const Real &tol)
bool _checkLevelOne(bool arcane_assert_yes=false)
void uniformlyRefine(Integer n=1)
bool coarsenItems(const bool maintain_level_one=true)
void _populateBackFrontCellsFromParentFaces(Cell parent_cell)
void _interpolateData(const Int64Array &cells_to_refine)
Interpolation of data on the child cells.
virtual void flagCellToRefine(Int32ConstArrayView cells_lids)
Passing the error committed by the cell to the refinement flag.
bool _refineItems(Int64Array &cells_to_refine)
MeshVariableScalarRefT< Node, Int32 > VariableNodeInt32
Quantity at the node of 32-bit integer type.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Array< Int64 > Int64Array
Dynamic one-dimensional array of 64-bit integers.
Definition UtilsTypes.h:125
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:482
ArrayView< Int32 > Int32ArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:453
double Real
Type representing a real number.
unsigned char Byte
Type of a byte.
Definition BaseTypes.h:43
Array< Int32 > Int32Array
Dynamic one-dimensional array of 32-bit integers.
Definition UtilsTypes.h:127