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