Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
AllCellToAllEnvCellConverter.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/* AllCellToAllEnvCellConverter.h (C) 2000-2024 */
9/* */
10/* Conversion of 'Cell' to 'AllEnvCell'. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_MATERIALS_ALLCELLTOALLENVCELLCONVERTER_H
13#define ARCANE_MATERIALS_ALLCELLTOALLENVCELLCONVERTER_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18
19#include "arcane/core/materials/MatItem.h"
21#include "arcane/core/materials/CellToAllEnvCellConverter.h"
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26namespace Arcane::Materials
27{
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32/*!
33 * \ingroup ArcaneMaterials
34 * \brief Connectivity table from 'Cell' to its 'AllEnvCell' intended
35 * for use on accelerator.
36 *
37 * Class that maintains the connectivity of all cells
38 * \a Cell to all their cells \a AllEnvCell.
39 *
40 * An instance is created via the create() method.
41 *
42 * The initialization cost is high; memory must be allocated and structures
43 * filled. We iterate through all meshes and for each cell, we call
44 * the CellToAllEnvCellConverter.
45 *
46 * Once the instance is created, it must be updated every time that
47 * the material/environment topology changes (which is also costly).
48 *
49 * This class is an internal class and should not be manipulated directly.
50 * You must use the associated helpers in IMeshMaterialMng and
51 * the CellToAllEnvCellAccessor class.
52 */
54{
55 friend class CellToAllEnvCellAccessor;
56 friend class CellToAllComponentCellEnumerator;
57 friend AllCellToAllEnvCellContainer;
58
59 private:
60
61 //! Access method for the "connectivity" table cell -> all env cells
62 ARCCORE_HOST_DEVICE Span<ComponentItemLocalId> operator[](Int32 cell_id) const
63 {
64 return m_allcell_allenvcell_ptr[cell_id];
65 }
66
67 private:
68
69 Span<Span<ComponentItemLocalId>> m_allcell_allenvcell_ptr;
70};
71
72/*---------------------------------------------------------------------------*/
73/*---------------------------------------------------------------------------*/
74
75/*!
76 * \ingroup ArcaneMaterials
77 * \brief Encapsulation class to access the equivalent connectivity
78 * cell -> allenvcell. Intended to be used with the accelerator API
79 * via RUNCOMMAND_...
80 * \note It has no inherent interest, other than forcing the user to create
81 * this object in addition to calling a RUNCOMMAND_ENUMERATE_CELL_ALLENVCELL and thus
82 * to guarantee the copy of the AllCellToAllEnvCell pointer for the lambda to execute on
83 * the accelerator
84 */
85class ARCANE_MATERIALS_EXPORT CellToAllEnvCellAccessor
86{
87 friend class CellToAllComponentCellEnumerator;
88
89 public:
90
91 using size_type = Span<ComponentItemLocalId>::size_type;
92
93 public:
94
95 CellToAllEnvCellAccessor() = default;
96 explicit CellToAllEnvCellAccessor(const IMeshMaterialMng* mm);
97
98 ARCCORE_HOST_DEVICE size_type nbEnvironment(Int32 cid) const
99 {
100 return m_cell_allenvcell[cid].size();
101 }
102
103 private:
104
105 ARCCORE_HOST_DEVICE AllCellToAllEnvCell _getAllCellToAllEnvCell() const
106 {
107 return m_cell_allenvcell;
108 }
109
110 private:
111
112 AllCellToAllEnvCell m_cell_allenvcell;
113};
114
115/*---------------------------------------------------------------------------*/
116/*---------------------------------------------------------------------------*/
117
118class ARCANE_MATERIALS_EXPORT CellToAllComponentCellEnumerator
119{
120 friend class EnumeratorTracer;
121
122 public:
123
124 using index_type = Span<ComponentItemLocalId>::index_type;
125 using size_type = Span<ComponentItemLocalId>::size_type;
126
127 public:
128
129 // The CPU version allows verification that initialization was done before ENUMERATE
130 ARCCORE_HOST_DEVICE explicit CellToAllComponentCellEnumerator(Int32 cell_id, const CellToAllEnvCellAccessor& acc)
131 {
132 AllCellToAllEnvCell all_env_view = acc._getAllCellToAllEnvCell();
133 m_ptr = all_env_view[cell_id];
134 }
135 ARCCORE_HOST_DEVICE void operator++()
136 {
137 ++m_index;
138 }
139
140 ARCCORE_HOST_DEVICE bool hasNext() const
141 {
142 return m_index < m_ptr.size();
143 }
144
145 ARCCORE_HOST_DEVICE ComponentItemLocalId operator*() const
146 {
147 return m_ptr[m_index];
148 }
149
150 private:
151
152 index_type m_index = 0;
154};
155
156/*---------------------------------------------------------------------------*/
157/*---------------------------------------------------------------------------*/
158
159/*!
160 * \brief Macro to iterate over a group of cells in order to iterate
161 * over the allenvcells of each cell.
162 *
163 * \note By forcing the use of CellToAllEnvCellAccessor in the macro,
164 * we ensure the capture by copy of the AllCellToAllEnvCell pointer, allowing
165 * the use of ENUMERATE_CELL_ALLENVCELL.
166 *
167 * TODO Very likely to be moved elsewhere if this prototype is kept
168 */
169#define RUNCOMMAND_ENUMERATE_CELL_ALLENVCELL(cell_to_allenvcellaccessor, iter_name, cell_group) \
170 A_FUNCINFO << cell_group << [=] ARCCORE_HOST_DEVICE(CellLocalId iter_name)
171
172/*---------------------------------------------------------------------------*/
173/*---------------------------------------------------------------------------*/
174
175// TODO Very likely to be moved elsewhere if this prototype is kept
176#define A_ENUMERATE_CELL_ALLCOMPONENTCELL(_EnumeratorClassName, iname, cid, cell_to_allenvcellaccessor) \
177 for (A_TRACE_COMPONENT(_EnumeratorClassName) iname(::Arcane::Materials::_EnumeratorClassName(cid, cell_to_allenvcellaccessor) A_TRACE_ENUMERATOR_WHERE); iname.hasNext(); ++iname)
178
179/*---------------------------------------------------------------------------*/
180/*---------------------------------------------------------------------------*/
181
182/*!
183 * \brief Macro to iterate over all environments within a cell.
184 * "Raw and lightweight" ENUMERATE_CELL_ENVCELL version, intended for
185 * use on accelerator, i.e. within a RUN_COMMAND...
186 *
187 * \param iname variable name (type MatVarIndex) allowing access to
188 * data.
189 * \param cid cell identifier (type Integer).
190 * \param cell_to_allenvcellaccessor cell->allenvcell connectivity (type CellToAllEnvCellAccessor)
191 */
192// TODO Very likely to be moved elsewhere if this prototype is kept
193#define ENUMERATE_CELL_ALLENVCELL(iname, cid, cell_to_allenvcellaccessor) \
194 A_ENUMERATE_CELL_ALLCOMPONENTCELL(CellToAllComponentCellEnumerator, iname, cid, cell_to_allenvcellaccessor)
195
196/*---------------------------------------------------------------------------*/
197/*---------------------------------------------------------------------------*/
198
199} // End namespace Arcane::Materials
200
201/*---------------------------------------------------------------------------*/
202/*---------------------------------------------------------------------------*/
203
204#endif
Connectivity table from 'Cell' to its 'AllEnvCell' intended for use on accelerator.
Encapsulation class to access the equivalent connectivity cell -> allenvcell. Intended to be used wit...
Interface for the material and environment manager of a mesh.
View of an array of elements of type T.
Definition Span.h:635
Always enables tracing in Arcane parts concerning materials.
class ARCANE_MATERIALS_EXPORT(64) SimdMatVarIndex
SIMD indexer on a component.
Real2 operator*(Real sca, const Real2Proxy &vec)
Multiplication by a scalar.
Definition Real2Proxy.h:364
std::int32_t Int32
Signed integer type of 32 bits.