Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
DynamicMeshCartesianBuilder.cc
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/* DynamicMeshCartesianBuilder.cc (C) 2000-2023 */
9/* */
10/* Generation of Cartesian meshes for DynamicMesh. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/CheckedConvert.h"
15
16#include "arcane/core/IMeshUniqueIdMng.h"
17#include "arcane/core/CartesianGridDimension.h"
18#include "arcane/core/internal/CartesianMeshAllocateBuildInfoInternal.h"
19
20#include "arcane/mesh/DynamicMesh.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane::mesh
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
37class ARCANE_MESH_EXPORT DynamicMeshCartesianBuilder
38: public TraceAccessor
39{
40 public:
41
42 DynamicMeshCartesianBuilder(DynamicMesh* mesh,
44
45 protected:
46
47 UniqueArray<Int64> m_cells_infos;
48 Int32 m_nb_cell = 0;
49 DynamicMesh* m_mesh = nullptr;
50 CartesianMeshAllocateBuildInfoInternal* m_build_info = nullptr;
51
52 public:
53
54 void allocate();
55
56 protected:
57
58 virtual void _buildCellList() = 0;
59};
60
61/*---------------------------------------------------------------------------*/
62/*---------------------------------------------------------------------------*/
63
64class DynamicMeshCartesian2DBuilder
65: public DynamicMeshCartesianBuilder
66{
67 public:
68
69 DynamicMeshCartesian2DBuilder(DynamicMesh* mesh,
71 : DynamicMeshCartesianBuilder(mesh, build_info)
72 {
73 }
74
75 protected:
76
77 void _buildCellList() override;
78};
79
80/*---------------------------------------------------------------------------*/
81/*---------------------------------------------------------------------------*/
82
83void DynamicMeshCartesian2DBuilder::
84_buildCellList()
85{
86 UniqueArray<Int64>& cells_infos = m_cells_infos;
87
88 const Int64 cell_unique_id_offset = m_build_info->cellUniqueIdOffset();
89 const Int64 node_unique_id_offset = m_build_info->nodeUniqueIdOffset();
90
91 CartesianGridDimension all_grid_dimension(m_build_info->globalNbCells());
92 CartesianGridDimension own_grid_dimension(m_build_info->ownNbCells());
93 Int64x3 first_own_cell_offset(m_build_info->firstOwnCellOffset());
94
95 Int64x3 own_nb_cell = own_grid_dimension.nbCell();
96
97 const Int64 own_nb_cell_xy = own_grid_dimension.totalNbCell();
98 m_nb_cell = CheckedConvert::toInt32(own_nb_cell_xy);
99
100 cells_infos.resize(own_nb_cell_xy * (1 + 1 + 4));
101
102 Integer cells_infos_index = 0;
103 CartesianGridDimension::NodeUniqueIdComputer2D node_uid_computer(all_grid_dimension.getNodeComputer2D(node_unique_id_offset));
104 CartesianGridDimension::CellUniqueIdComputer2D cell_uid_computer(all_grid_dimension.getCellComputer2D(cell_unique_id_offset));
105
106 for (Integer y = 0; y < own_nb_cell.y; ++y) {
107 for (Integer x = 0; x < own_nb_cell.x; ++x) {
108 Int64 gx = x + first_own_cell_offset.x;
109 Int64 gy = y + first_own_cell_offset.y;
110 Int64 cell_unique_id = cell_uid_computer.compute(gx, gy);
111 cells_infos[cells_infos_index] = IT_Quad4;
112 ++cells_infos_index;
113 cells_infos[cells_infos_index] = cell_unique_id;
114 ++cells_infos_index;
115 std::array<Int64, 4> node_uids = node_uid_computer.computeForCell(gx, gy);
116 for (Int32 i = 0; i < 4; ++i)
117 cells_infos[cells_infos_index + i] = node_uids[i];
118 cells_infos_index += 4;
119 }
120 }
121}
122
123/*---------------------------------------------------------------------------*/
124/*---------------------------------------------------------------------------*/
125
126/*---------------------------------------------------------------------------*/
127/*---------------------------------------------------------------------------*/
128
129class DynamicMeshCartesian3DBuilder
130: public DynamicMeshCartesianBuilder
131{
132 public:
133
134 DynamicMeshCartesian3DBuilder(DynamicMesh* mesh,
136 : DynamicMeshCartesianBuilder(mesh, build_info)
137 {
138 }
139
140 public:
141
142 void _buildCellList() override;
143};
144
145/*---------------------------------------------------------------------------*/
146/*---------------------------------------------------------------------------*/
147
148void DynamicMeshCartesian3DBuilder::
149_buildCellList()
150{
151 UniqueArray<Int64>& cells_infos = m_cells_infos;
152
153 const Int64 cell_unique_id_offset = m_build_info->cellUniqueIdOffset();
154 const Int64 node_unique_id_offset = m_build_info->nodeUniqueIdOffset();
155
156 CartesianGridDimension all_grid_dimension(m_build_info->globalNbCells());
157 CartesianGridDimension own_grid_dimension(m_build_info->ownNbCells());
158 Int64x3 first_own_cell_offset(m_build_info->firstOwnCellOffset());
159
160 Int64x3 own_nb_cell = own_grid_dimension.nbCell();
161
162 const Int64 own_nb_cell_xyz = own_grid_dimension.totalNbCell();
163 m_nb_cell = CheckedConvert::toInt32(own_nb_cell_xyz);
164
165 cells_infos.resize(own_nb_cell_xyz * (1 + 1 + 8));
166
167 Integer cells_infos_index = 0;
168 CartesianGridDimension::NodeUniqueIdComputer3D node_uid_computer(all_grid_dimension.getNodeComputer3D(node_unique_id_offset));
169 CartesianGridDimension::CellUniqueIdComputer3D cell_uid_computer(all_grid_dimension.getCellComputer3D(cell_unique_id_offset));
170
171 for (Integer z = 0; z < own_nb_cell.z; ++z) {
172 for (Integer y = 0; y < own_nb_cell.y; ++y) {
173 for (Integer x = 0; x < own_nb_cell.x; ++x) {
174 Int64 gx = x + first_own_cell_offset.x;
175 Int64 gy = y + first_own_cell_offset.y;
176 Int64 gz = z + first_own_cell_offset.z;
177 Int64 cell_unique_id = cell_uid_computer.compute(gx, gy, gz);
178 cells_infos[cells_infos_index] = IT_Hexaedron8;
179 ++cells_infos_index;
180 cells_infos[cells_infos_index] = cell_unique_id;
181 ++cells_infos_index;
182 std::array<Int64, 8> node_uids = node_uid_computer.computeForCell(gx, gy, gz);
183 for (Int32 i = 0; i < 8; ++i)
184 cells_infos[cells_infos_index + i] = node_uids[i];
185 cells_infos_index += 8;
186 }
187 }
188 }
189}
190
191/*---------------------------------------------------------------------------*/
192/*---------------------------------------------------------------------------*/
193
194/*---------------------------------------------------------------------------*/
195/*---------------------------------------------------------------------------*/
196
197DynamicMeshCartesianBuilder::
198DynamicMeshCartesianBuilder(DynamicMesh* mesh, CartesianMeshAllocateBuildInfoInternal* build_info)
199: TraceAccessor(mesh->traceMng())
200, m_mesh(mesh)
201, m_build_info(build_info)
202{
203}
204
205/*---------------------------------------------------------------------------*/
206/*---------------------------------------------------------------------------*/
207
208void DynamicMeshCartesianBuilder::
209allocate()
210{
211 auto* x = m_build_info;
212 const Int32 dimension = m_build_info->meshDimension();
213
214 m_mesh->setDimension(dimension);
215
216 Int32 face_builder_version = x->faceBuilderVersion();
217 if (face_builder_version >= 0)
218 m_mesh->meshUniqueIdMng()->setFaceBuilderVersion(face_builder_version);
219 Int32 edge_builder_version = x->edgeBuilderVersion();
220 if (edge_builder_version >= 0)
221 m_mesh->meshUniqueIdMng()->setEdgeBuilderVersion(edge_builder_version);
222
223 _buildCellList();
224
225 m_mesh->allocateCells(m_nb_cell, m_cells_infos, true);
226}
227
228/*---------------------------------------------------------------------------*/
229/*---------------------------------------------------------------------------*/
230
231ARCANE_MESH_EXPORT void
232allocateCartesianMesh(DynamicMesh* mesh, CartesianMeshAllocateBuildInfo& build_info)
233{
234 auto* x = build_info._internal();
235 Int32 dimension = x->meshDimension();
236
237 if (dimension == 3) {
238 DynamicMeshCartesian3DBuilder builder(mesh, x);
239 builder.allocate();
240 }
241 else if (dimension == 2) {
242 DynamicMeshCartesian2DBuilder builder(mesh, x);
243 builder.allocate();
244 }
245 else
246 ARCANE_FATAL("Not supported dimension '{0}'. Only 2 or 3 is supported", dimension);
247}
248
249/*---------------------------------------------------------------------------*/
250/*---------------------------------------------------------------------------*/
251
252} // namespace Arcane::mesh
253
254/*---------------------------------------------------------------------------*/
255/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
void resize(Int64 s)
Changes the number of elements in the array to s.
Class for calculating the uniqueId() of a cell in 2D based on its position in the grid.
Class for calculating the uniqueId() of a cell in 3D based on its position in the grid.
Class for calculating the uniqueId() of a node in 2D based on its position in the grid.
Class for calculating the uniqueId() of a node in 3D based on its position in the grid.
Information about the dimensions of a Cartesian grid.
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
1D data vector with value semantics (STL style).
Implementation of a mesh.
Definition DynamicMesh.h:98
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
std::int32_t Int32
Signed integer type of 32 bits.