Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
NewItemOwnerBuilder.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/* NewItemOwnerBuilder.h (C) 2000-2026 */
9/* */
10/* Owner management tool for new items */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_MESH_NEWITEMOWNERBUILDER_H
13#define ARCANE_MESH_NEWITEMOWNERBUILDER_H
14
15/*---------------------------------------------------------------------------*/
16/*---------------------------------------------------------------------------*/
17
18#include "arcane/mesh/MeshGlobal.h"
19
20#include "arcane/core/Item.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane::mesh
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31// While waiting for an algorithm that better balances
32// messages, we apply the following:
33// - each sub-domain is responsible for determining the new
34// owner of nodes, faces, edges, dual nodes, and links belonging to it.
35// - for nodes and edges, the new owner is the new owner of the cell
36// connected to this node whose uniqueId() is the smallest.
37// - for faces, the new owner is the new owner of the cell behind this face
38// if it is an internal face, and the connected mesh if it is a boundary face.
39// - for dual nodes, the new owner is the new owner of the cell connected to
40// the dual element
41// - for links, the new owner is the new owner of the cell connected to the
42// first dual node, that is, the owner of the link's first dual node.
43
44class NewItemOwnerBuilder
45{
46 public:
47
48 NewItemOwnerBuilder() {}
49
50 // Determines the cell connected to the item
51 template <typename T>
52 inline Cell connectedCellOfItem(const T& item) const;
53
54 // Determines the owner of the item, that is,
55 // the owner of the cell connected to the item
56 template <typename T>
57 inline Integer ownerOfItem(const T& item) const
58 {
59 return connectedCellOfItem(item).owner();
60 }
61
62 private:
63
64 // Finds the cell with the smallest uniqueId() of an item
65 // Static polymorphism: only item types with a
66 // cell() method are accepted
67 template <typename T>
68 inline Cell _minimumUniqueIdCellOfItem(const T& item) const
69 {
70 Cell cell = item.cell(0);
71 for (Cell item_cell : item.cells()) {
72 if (item_cell.uniqueId() < cell.uniqueId())
73 cell = item_cell;
74 }
75 return cell;
76 }
77};
78
79// For nodes, the connected cell is the one with the smallest uniqueId().
80template <>
81inline Cell NewItemOwnerBuilder::connectedCellOfItem<Node>(const Node& node) const
82{
83 return _minimumUniqueIdCellOfItem(node);
84}
85
86// For edges, the connected cell is the one with the smallest uniqueId().
87template <>
88inline Cell NewItemOwnerBuilder::connectedCellOfItem<Edge>(const Edge& edge) const
89{
90 return _minimumUniqueIdCellOfItem(edge);
91}
92
93// For faces, the connected cell is backCell() if it exists, otherwise frontCell()
94template <>
95inline Cell NewItemOwnerBuilder::connectedCellOfItem<Face>(const Face& face) const
96{
97 Cell cell = face.backCell();
98 if (cell.null())
99 cell = face.frontCell();
100 return cell;
101}
102template <>
103inline Cell NewItemOwnerBuilder::connectedCellOfItem<Particle>(const Particle& particle) const
104{
105 return particle.cell();
106}
107
108/*---------------------------------------------------------------------------*/
109/*---------------------------------------------------------------------------*/
110
111} // namespace Arcane::mesh
112
113/*---------------------------------------------------------------------------*/
114/*---------------------------------------------------------------------------*/
115
116#endif
Cell of a mesh.
Definition Item.h:1300
Edge of a cell.
Definition Item.h:875
ItemUniqueId uniqueId() const
Unique identifier across all domains.
Definition Item.h:239
Node of a mesh.
Definition Item.h:598
Int32 Integer
Type representing an integer.
@ Cell
The mesh is AMR by cell.
Definition MeshKind.h:53