Arcane  v3.16.3.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
SimpleMeshGenerator.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 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/* SimpleMeshGenerator.cc (C) 2000-2025 */
9/* */
10/* Service de génération de maillage 'Simple'. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/std/SimpleMeshGenerator.h"
15
16#include "arcane/utils/Array.h"
17#include "arcane/utils/HashTableMap.h"
18#include "arcane/utils/PlatformUtils.h"
19#include "arcane/utils/ITraceMng.h"
20#include "arcane/utils/Real3.h"
21#include "arcane/utils/FixedArray.h"
22
23#include "arcane/core/IMeshReader.h"
24#include "arcane/core/ISubDomain.h"
25#include "arcane/core/ICaseDocument.h"
26#include "arcane/core/XmlNode.h"
27#include "arcane/core/Service.h"
28#include "arcane/core/IParallelMng.h"
29#include "arcane/core/Item.h"
30#include "arcane/core/ItemGroup.h"
31#include "arcane/core/IMesh.h"
32#include "arcane/core/IMeshSubMeshTransition.h"
33#include "arcane/core/IItemFamily.h"
34#include "arcane/core/MeshVariable.h"
36#include "arcane/core/ItemPrinter.h"
37#include "arcane/core/FactoryService.h"
38#include "arcane/core/AbstractService.h"
39#include "arcane/core/IMeshModifier.h"
40#include "arcane/core/internal/IMeshModifierInternal.h"
41
42/*---------------------------------------------------------------------------*/
43/*---------------------------------------------------------------------------*/
44
45namespace Arcane
46{
47
48/*---------------------------------------------------------------------------*/
49/*---------------------------------------------------------------------------*/
50
51SimpleMeshGenerator::
52SimpleMeshGenerator(IPrimaryMesh* mesh)
53: TraceAccessor(mesh->traceMng())
54, m_mesh(mesh)
55, m_mesh_modifier_internal(mesh->modifier()->_modifierInternalApi())
56{
57}
58
59/*---------------------------------------------------------------------------*/
60/*---------------------------------------------------------------------------*/
61
62Integer SimpleMeshGenerator::
63_addNode(const Real3& pos)
64{
65 auto i = m_coords_to_uid.find(pos);
66 if (i==m_coords_to_uid.end()){
67 Integer current_id = m_nodes_unique_id.size();
68 m_nodes_unique_id.add(current_id);
69 m_nodes_coords.add(pos);
70 m_coords_to_uid.insert(std::make_pair(pos,current_id));
71 return current_id;
72 }
73 return i->second;
74}
75
76
77/*---------------------------------------------------------------------------*/
78/*---------------------------------------------------------------------------*/
79
80Integer SimpleMeshGenerator::
81_addNode(Real x,Real y,Real z)
82{
83 return _addNode(Real3(x,y,z));
84}
85
86/*---------------------------------------------------------------------------*/
87/*---------------------------------------------------------------------------*/
88
89void SimpleMeshGenerator::
90_addCell(Int16 type_id, ConstArrayView<Int64> nodes_id)
91{
92 Integer current_id = m_current_nb_cell;
93 ++m_current_nb_cell;
94 m_mesh_modifier_internal->addCell(ItemUniqueId(current_id), ItemTypeId(type_id), nodes_id);
95}
96
97/*---------------------------------------------------------------------------*/
98/*---------------------------------------------------------------------------*/
99
100bool SimpleMeshGenerator::
101readOptions(XmlNode node)
102{
103 XmlNode modeNode = node.child(String("mode"));
104 m_mode = modeNode.valueAsInteger();
105 if (m_mode < 1 || m_mode > 3) {
106 info() << "Bad syntax for <meshgenerator>";
107 info() << "Expected is <meshgenerator><simple><mode>mode</simple></meshgenerator>";
108 info() << "with mode between 1 and 3";
109 error() << "Bad syntax for <meshgenerator>";
110 return true;
111 }
112 return false;
113}
114
115/*---------------------------------------------------------------------------*/
116/*---------------------------------------------------------------------------*/
117
118void SimpleMeshGenerator::
119_createSimpleHemiHexa7(Real x0,Real y0,Real z1,Real z2)
120{
121 FixedArray<Int64, 7> ids;
122 ids[0] = _addNode(x0 ,y0 ,z1);
123 ids[1] = _addNode(x0+1.,y0 ,z1);
124 ids[2] = _addNode(x0+1.,y0 ,z2);
125 ids[3] = _addNode(x0+1.,y0+1.,z2);
126 ids[4] = _addNode(x0 ,y0+1.,z2);
127 ids[5] = _addNode(x0 ,y0+1.,z1);
128 ids[6] = _addNode(x0 + 1., y0 + 1., z1);
129 _addCell(IT_HemiHexa7, ids.view());
130}
131
132/*---------------------------------------------------------------------------*/
133/*---------------------------------------------------------------------------*/
134
135void SimpleMeshGenerator::
136_createSimpleHemiHexa6(Real x0, Real y0, Real z1, Real z2)
137{
138 FixedArray<Int64, 6> ids;
139 ids[0] = _addNode(x0 ,y0 ,z1);
140 ids[1] = _addNode(x0+1.,y0 ,z1);
141 ids[2] = _addNode(x0+1.,y0 ,z2);
142 ids[3] = _addNode(x0+1.,y0+1.,z1);
143 ids[4] = _addNode(x0, y0 + 1., z2);
144 ids[5] = _addNode(x0, y0 + 1., z1);
145 _addCell(IT_HemiHexa6, ids.view());
146}
147
148/*---------------------------------------------------------------------------*/
149/*---------------------------------------------------------------------------*/
150
151void SimpleMeshGenerator::
152_createSimpleHemiHexa5(Real x0, Real y0, Real z1, Real z2)
153{
154 FixedArray<Int64, 5> ids;
155 ids[0] = _addNode(x0 ,y0 ,z1);
156 ids[1] = _addNode(x0+1.,y0 ,z1);
157 ids[2] = _addNode(x0+1.,y0 ,z2);
158 ids[3] = _addNode(x0 + 1., y0 + 1., z1);
159 ids[4] = _addNode(x0, y0 + 1., z1);
160 _addCell(IT_HemiHexa5, ids.view());
161}
162
163/*---------------------------------------------------------------------------*/
164/*---------------------------------------------------------------------------*/
165
166void SimpleMeshGenerator::
167_createSimpleAntiWedgeLeft6(Real x0, Real y0, Real z1, Real z2)
168{
169 FixedArray<Int64, 6> ids;
170 ids[0] = _addNode(x0 ,y0 ,z1);
171 ids[1] = _addNode(x0 ,y0+1.,z1);
172 ids[2] = _addNode(x0 ,y0+.5,z2);
173 ids[3] = _addNode(x0+1.,y0 ,z1);
174 ids[4] = _addNode(x0 + 1., y0 + 1., z1);
175 ids[5] = _addNode(x0 + 1., y0 + .5, (z1 + z2) / 2);
176 _addCell(IT_AntiWedgeLeft6, ids.view());
177}
178
179/*---------------------------------------------------------------------------*/
180/*---------------------------------------------------------------------------*/
181
182void SimpleMeshGenerator::
183_createSimpleAntiWedgeRight6(Real x0, Real y0, Real z1, Real z2)
184{
185 FixedArray<Int64, 6> ids;
186 ids[0] = _addNode(x0 ,y0 ,z1);
187 ids[1] = _addNode(x0 ,y0+1.,z1);
188 ids[2] = _addNode(x0 ,y0+.5,(z1+z2)/2);
189 ids[3] = _addNode(x0 + 1., y0, z1);
190 ids[4] = _addNode(x0 + 1., y0 + 1., z1);
191 ids[5] = _addNode(x0 + 1., y0 + .5, z2);
192 _addCell(IT_AntiWedgeRight6, ids.view());
193}
194
195/*---------------------------------------------------------------------------*/
196/*---------------------------------------------------------------------------*/
197
198void SimpleMeshGenerator::
199_createSimpleDiTetra5(Real x0, Real y0, Real z1, Real z2)
200{
201 FixedArray<Int64, 5> ids;
202 ids[0] = _addNode(x0 ,y0 ,z2);
203 ids[1] = _addNode(x0+1.,y0 ,z1);
204 ids[2] = _addNode(x0 + 2., y0, z2);
205 ids[3] = _addNode(x0 + 1., y0 + 1., (z2 + z1) / 2);
206 ids[4] = _addNode(x0 + 1., y0 - 1., (z2 + z1) / 2);
207 _addCell(IT_DiTetra5, ids.view());
208}
209
210/*---------------------------------------------------------------------------*/
211/*---------------------------------------------------------------------------*/
212
213void SimpleMeshGenerator::
214_createSimpleHexaedron8(Real x0, Real y0, Real z1, Real z2)
215{
216 FixedArray<Int64, 8> ids;
217 ids[0] = _addNode(x0 ,y0 ,z1);
218 ids[1] = _addNode(x0+1.,y0 ,z1);
219 ids[2] = _addNode(x0+1.,y0+1.,z1);
220 ids[3] = _addNode(x0, y0 + 1., z1);
221 ids[4] = _addNode(x0, y0, z2);
222 ids[5] = _addNode(x0 + 1., y0, z2);
223 ids[6] = _addNode(x0 + 1., y0 + 1., z2);
224 ids[7] = _addNode(x0, y0 + 1., z2);
225 _addCell(IT_Hexaedron8, ids.view());
226}
227
228/*---------------------------------------------------------------------------*/
229/*---------------------------------------------------------------------------*/
230
231void SimpleMeshGenerator::
232_createSimpleOctaedron12(Real x0, Real y0, Real z1, Real z2)
233{
234 FixedArray<Int64, 12> ids;
235 ids[0] = _addNode(x0 ,y0 + 0.5,z1);
236 ids[1] = _addNode(x0 + 0.25,y0 ,z1);
237 ids[2] = _addNode(x0 + 0.75,y0 ,z1);
238 ids[3] = _addNode(x0 + 1.0 ,y0 + 0.5,z1);
239 ids[4] = _addNode(x0 + 0.75,y0 + 1. ,z1);
240 ids[5] = _addNode(x0 + 0.25,y0 + 1. ,z1);
241
242 ids[6] = _addNode(x0 ,y0 + 0.5,z2);
243 ids[7] = _addNode(x0 + 0.25,y0 ,z2);
244 ids[8] = _addNode(x0 + 0.75, y0, z2);
245 ids[9] = _addNode(x0 + 1., y0 + 0.5, z2);
246 ids[10] = _addNode(x0 + 0.75, y0 + 1., z2);
247 ids[11] = _addNode(x0 + 0.25, y0 + 1., z2);
248 _addCell(IT_Octaedron12, ids.view());
249}
250
251/*---------------------------------------------------------------------------*/
252/*---------------------------------------------------------------------------*/
253
254void SimpleMeshGenerator::
255_createSimpleHeptaedron10(Real x0, Real y0, Real z1, Real z2)
256{
257 FixedArray<Int64, 10> ids;
258 ids[0] = _addNode(x0 ,y0 + 0.5 ,z1);
259 ids[1] = _addNode(x0 + 1./2.,y0 ,z1);
260 ids[2] = _addNode(x0 + 2./2.,y0 + 0.25,z1);
261 ids[3] = _addNode(x0 + 2./2.,y0 + 0.75,z1);
262 ids[4] = _addNode(x0 + 1./2.,y0 + 1 ,z1);
263
264 ids[5] = _addNode(x0 ,y0 + 0.5 ,z2);
265 ids[6] = _addNode(x0 + 1. / 2., y0, z2);
266 ids[7] = _addNode(x0 + 2. / 2., y0 + 0.25, z2);
267 ids[8] = _addNode(x0 + 2. / 2., y0 + 0.75, z2);
268 ids[9] = _addNode(x0 + 1. / 2., y0 + 1., z2);
269 _addCell(IT_Heptaedron10, ids.view());
270}
271
272/*---------------------------------------------------------------------------*/
273/*---------------------------------------------------------------------------*/
274
275void SimpleMeshGenerator::
276_createSimplePentaedron6(Real x0, Real y0, Real z1, Real z2)
277{
278 FixedArray<Int64, 6> ids;
279 ids[0] = _addNode(x0 ,y0 ,z1);
280 ids[1] = _addNode(x0 + 1., y0 + 1. / 2., z1);
281 ids[2] = _addNode(x0, y0 + 1., z1);
282 ids[3] = _addNode(x0, y0, z2);
283 ids[4] = _addNode(x0 + 1., y0 + 1. / 2., z2);
284 ids[5] = _addNode(x0, y0 + 1., z2);
285 _addCell(IT_Pentaedron6, ids.view());
286}
287
288/*---------------------------------------------------------------------------*/
289/*---------------------------------------------------------------------------*/
290
291void SimpleMeshGenerator::
292_createSimplePyramid5(Real x0, Real y0, Real z1, Real z2)
293{
294 FixedArray<Int64, 5> ids;
295 ids[0] = _addNode(x0 ,y0 ,z1);
296 ids[1] = _addNode(x0 + 1., y0, z1);
297 ids[2] = _addNode(x0 + 1., y0 + 1., z1);
298 ids[3] = _addNode(x0, y0 + 1., z1);
299 ids[4] = _addNode(x0 + 0.5, y0 + 0.5, z2);
300 _addCell(IT_Pyramid5, ids.view());
301}
302
303/*---------------------------------------------------------------------------*/
304/*---------------------------------------------------------------------------*/
305
306void SimpleMeshGenerator::
307_createSimpleTetraedron4(Real x0, Real y0, Real z1, Real z2)
308{
309 FixedArray<Int64, 4> ids;
310 ids[0] = _addNode(x0, y0, z1);
311 ids[1] = _addNode(x0 + 1., y0, z1);
312 ids[2] = _addNode(x0 + 0.5, y0 + 1., z1);
313 ids[3] = _addNode(x0 + 0.5, y0 + 0.5, z2);
314 _addCell(IT_Tetraedron4, ids.view());
315}
316
317/*---------------------------------------------------------------------------*/
318/*---------------------------------------------------------------------------*/
319
320bool SimpleMeshGenerator::
321generateMesh()
322{
323 IPrimaryMesh* mesh = m_mesh;
324
325 info() << "Using simple mesh generator";
326 mesh->setDimension(3);
327
328 if (m_mode == 1) {
329 _createSimpleHexaedron8(2.,0.,0.,1.);
330 _createSimpleOctaedron12(4.,0.,0.,1.);
331 _createSimpleHeptaedron10(6.,0.,0.,1.);
332 _createSimplePentaedron6(8.,0.,0.,1.);
333 _createSimplePyramid5(10.,0.,0.,1.);
334 _createSimpleTetraedron4(12.,0.,0.,1.);
335 _createSimpleHemiHexa7(14.,0.,0.,1.);
336 _createSimpleHemiHexa6(16.,0.,0.,1.);
337 _createSimpleHemiHexa5(18.,0.,0.,1.);
338 _createSimpleAntiWedgeLeft6(20.,0.,0.,1.);
339 _createSimpleAntiWedgeRight6(22.,0.,0.,1.);
340 _createSimpleDiTetra5(24.,0.,0.,1.);
341 }
342
343 if (m_mode==2){
344 _createSimpleHexaedron8(0. ,0.,0.,1.);
345 _createSimpleHemiHexa7(0.,0.,1.,2.);
346 _createSimpleHexaedron8(1. ,0.,0.,1.);
347
348 _createSimpleHexaedron8(2. ,0.,0.,1.);
349 _createSimpleHemiHexa6(2.,0.,1.,2.);
350 _createSimpleHexaedron8(3. ,0.,0.,1.);
351
352 _createSimpleHexaedron8(4. ,0.,0.,1.);
353 _createSimpleHemiHexa5(4.,0.,1.,2.);
354 _createSimpleHexaedron8(5. ,0.,0.,1.);
355
356 _createSimpleHexaedron8(6. ,0.,0.,1.);
357 _createSimpleAntiWedgeLeft6(6.,0.,1.,2.);
358 _createSimpleHexaedron8(7. ,0.,0.,1.);
359
360 _createSimpleHexaedron8(8. ,0.,0.,1.);
361 _createSimpleAntiWedgeRight6(8.,0.,1.,2.);
362 _createSimpleHexaedron8(9. ,0.,0.,1.);
363
364 _createSimpleHexaedron8(10.,0.,0.,1.);
365 _createSimplePyramid5(10.,0.,1.,2.);
366 _createSimpleHexaedron8(11.,0.,0.,1.);
367 }
368
369 if (m_mode==3){
370 _createSimpleHexaedron8(2.,0.,0.,1.);
371 _createSimpleOctaedron12(4.,0.,0.,1.);
372 _createSimpleHeptaedron10(6.,0.,0.,1.);
373 _createSimplePentaedron6(8.,0.,0.,1.);
374 _createSimplePyramid5(10.,0.,0.,1.);
375 _createSimpleTetraedron4(12.,0.,0.,1.);
376 }
377
378 UniqueArray<Int64> cells_infos(m_cells_infos.size());
379 for (Integer i = 0; i < m_cells_infos.size(); ++i)
380 cells_infos[i] = m_cells_infos[i];
381 mesh->endAllocate();
382
383 UniqueArray<Int64> nodes_unique_id(m_nodes_unique_id.size());
384 for(Integer i=0;i<m_nodes_unique_id.size();++i)
385 nodes_unique_id[i] = m_nodes_unique_id[i];
386
387 VariableNodeReal3& nodes_coord_var(mesh->nodesCoordinates());
388 {
389 // Remplit la variable contenant les coordonnées des noeuds
390 UniqueArray<Int32> nodes_local_id(nodes_unique_id.size());
391 IItemFamily* family = mesh->itemFamily(IK_Node);
392 family->itemsUniqueIdToLocalId(nodes_local_id,nodes_unique_id);
393 NodeInfoListView nodes_internal(family);
394 Integer nb_node_local_id = nodes_local_id.size();
395 for( Integer i=0; i<nb_node_local_id; ++i ){
396 Node node = nodes_internal[nodes_local_id[i]];
397 //Int64 unique_id = nodes_unique_id[i];
398 nodes_coord_var[node] = m_nodes_coords[i];
399 //info() << "Set coord " << ItemPrinter(node) << " coord=" << nodes_coord_var[node];
400 }
401 }
402 nodes_coord_var.synchronize();
403
404 return false;
405}
406
407/*---------------------------------------------------------------------------*/
408/*---------------------------------------------------------------------------*/
409
410} // End namespace Arcane
411
412/*---------------------------------------------------------------------------*/
413/*---------------------------------------------------------------------------*/
Fonctions utilitaires sur le maillage.
MeshVariableScalarRefT< Node, Real3 > VariableNodeReal3
Grandeur au noeud de type coordonnées.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Int32 Integer
Type représentant un entier.