Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
DynamicMeshIncrementalBuilder.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2024 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/* DynamicMeshIncrementalBuilder.cc (C) 2000-2024 */
9/* */
10/* Construction d'un maillage de manière incrémentale. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/Iterator.h"
15#include "arcane/utils/ArgumentException.h"
16#include "arcane/utils/NotImplementedException.h"
17#include "arcane/utils/NotSupportedException.h"
18#include "arcane/utils/ITraceMng.h"
19#include "arcane/utils/ValueConvert.h"
20
21#include "arcane/core/ItemTypeMng.h"
23#include "arcane/core/IParallelMng.h"
24#include "arcane/core/SerializeBuffer.h"
25#include "arcane/core/ItemPrinter.h"
26#include "arcane/core/Connectivity.h"
27#include "arcane/core/MeshToMeshTransposer.h"
28#include "arcane/core/IItemFamilyModifier.h"
29
30#include "arcane/mesh/DynamicMesh.h"
31#include "arcane/mesh/DynamicMeshIncrementalBuilder.h"
32#include "arcane/mesh/OneMeshItemAdder.h"
33#include "arcane/mesh/GhostLayerBuilder.h"
34#include "arcane/mesh/FaceUniqueIdBuilder.h"
35#include "arcane/mesh/EdgeUniqueIdBuilder.h"
36#include "arcane/mesh/CellFamily.h"
37#include "arcane/mesh/GraphDoFs.h"
38#include "arcane/mesh/ParticleFamily.h"
39
40#include <set>
41#include <map>
42#include <algorithm>
43
44/*---------------------------------------------------------------------------*/
45/*---------------------------------------------------------------------------*/
46
47namespace Arcane::mesh
48{
49
50/*---------------------------------------------------------------------------*/
51/*---------------------------------------------------------------------------*/
52
53// #define ARCANE_DEBUG_DYNAMIC_MESH
54// #define ARCANE_DEBUG_DYNAMIC_MESH2
55
56/*---------------------------------------------------------------------------*/
57/*---------------------------------------------------------------------------*/
58
61: TraceAccessor(mesh->traceMng())
62, m_mesh(mesh)
63, m_item_type_mng(mesh->itemTypeMng())
64, m_has_amr(mesh->isAmrActivated())
65, m_one_mesh_item_adder(new OneMeshItemAdder(this))
66{
67 if (auto v = Convert::Type<Int32>::tryParseFromEnvironment("ARCANE_VERBOSE_MESH_BUILDER", true))
68 m_verbose = (v.value()!=0);
69}
70
71/*---------------------------------------------------------------------------*/
72/*---------------------------------------------------------------------------*/
73
74DynamicMeshIncrementalBuilder::
75~DynamicMeshIncrementalBuilder()
76{
78 delete m_face_unique_id_builder;
79 delete m_edge_unique_id_builder;
81}
82
83/*---------------------------------------------------------------------------*/
84/*---------------------------------------------------------------------------*/
85
86void DynamicMeshIncrementalBuilder::
87_printCellFaceInfos(ItemInternal* icell,const String& str)
88{
89 Cell cell(icell);
90 Integer nb_num_back_face = 0;
91 Integer nb_num_front_face = 0;
92 Integer index = 0;
93 for( Face face : cell.faces() ){
95 if (face.backCell()==cell){
97 add_msg = "is a back face";
98 }
99 else{
100 ++nb_num_front_face;
101 add_msg = "is a front face";
102 }
103 info() << str << ": celluid=" << cell.uniqueId()
104 << " faceuid=" << face.uniqueId()
105 << " faceindex=" << index
106 << add_msg;
107 ++index;
108 }
109 info() << str << ": celluid=" << cell.uniqueId()
110 << " nbback=" << nb_num_back_face
111 << " nbfront=" << nb_num_front_face;
112}
113
114/*---------------------------------------------------------------------------*/
115/*---------------------------------------------------------------------------*/
126 Integer sub_domain_id,Int32ArrayView cells,
127 bool allow_build_face)
128{
129 ItemTypeMng* itm = m_item_type_mng;
130
131 debug() << "[addCells] ADD CELLS mesh=" << m_mesh->name() << " nb=" << nb_cell;
132 Integer cells_infos_index = 0;
133 bool add_to_cells = cells.size()!=0;
134 if (add_to_cells && nb_cell!=cells.size())
135 ARCANE_THROW(ArgumentException,"return array 'cells' has to have same size as number of cells");
136 for( Integer i_cell=0; i_cell<nb_cell; ++i_cell ){
141
142 ItemTypeInfo* it = itm->typeFromId(item_type_id);
143 Integer current_cell_nb_node = it->nbLocalNode();
145
148
149 if (add_to_cells)
150 cells[i_cell] = cell->localId();
152 }
153}
154
155/*---------------------------------------------------------------------------*/
156/*---------------------------------------------------------------------------*/
166/*---------------------------------------------------------------------------*/
167
170 Integer sub_domain_id,Int32ArrayView cells,
171 bool allow_build_face)
172{
173 bool add_to_cells = cells.size()!=0;
174 if (add_to_cells && nb_cell!=cells.size())
175 throw ArgumentException(A_FUNCINFO,
176 "return array 'cells' has to have same size as number of cells");
177 ItemDataList item_data_list; // store item ids and dependency connectivities
178 ItemDataList item_relation_data_list; // store relation connectivities
179 ItemData& cell_data = item_data_list.itemData(Integer(m_mesh->cellFamily()->itemKind()),
180 nb_cell,0,cells,&mesh()->trueCellFamily(),&mesh()->trueCellFamily(),sub_domain_id);
181 // item info_size cannot be guessed
184 Integer nb_face = 0 , nb_edge = 0, nb_node = 0;
185 std::map<Int64, Int64SharedArray> cell_to_face_connectivity_info;
186 std::map<std::pair<Int64,Int64>, Int64> edge_uid_map;
187
188 // Fill classical info
191 _fillNodeInfo(nb_node, nb_face, nodes_infos, faces_infos);
192
193 // Fill Cell info 2
195 // Fill Face info 2
196 if (allow_build_face) {
197 ItemData& face_data = item_data_list.itemData(Integer(m_mesh->faceFamily()->itemKind()),nb_face,0,face_lids,&mesh()->trueFaceFamily(),&mesh()->trueFaceFamily(),sub_domain_id);
198 face_lids.resize(item_data_list[m_mesh->faceFamily()->itemKind()].nbItems());
199 _fillFaceNewInfoNew(nb_face,faces_infos,face_data.itemInfos(),edge_uid_map);// todo voir appel depuis add Faces
200 ItemData& face_relation_data = item_relation_data_list.itemData(Integer(m_mesh->faceFamily()->itemKind()),nb_face,0,face_lids,&mesh()->trueFaceFamily(),&mesh()->trueFaceFamily(),sub_domain_id);
201 _initFaceRelationInfo(face_relation_data,cell_data, faces_infos); // face-cell relations
202 }
203 // Fill Edge info 2
204 if (hasEdge()) {
205 Integer edge_info_size = 1 + nb_edge*6;//New info = Nb_connected_family + for each edge : type, uid, connected_family_kind, nb_node_connected, first_node_uid, second_node_uid
206 ItemData& edge_data = item_data_list.itemData(Integer(m_mesh->edgeFamily()->itemKind()),nb_edge,edge_info_size,edge_lids,&mesh()->trueEdgeFamily(),&mesh()->trueEdgeFamily(),sub_domain_id);
207 edge_lids.resize(item_data_list[m_mesh->edgeFamily()->itemKind()].nbItems());
208 _fillEdgeNewInfoNew(nb_edge,edges_infos,edge_data.itemInfos()); // reprendre fillEdgeInfo et voir l'appel depuis add Edges + attention ordre des noeuds,
209 ItemData& edge_relation_data = item_relation_data_list.itemData(Integer(m_mesh->edgeFamily()->itemKind()),nb_edge,edge_info_size,edge_lids,&mesh()->trueEdgeFamily(),&mesh()->trueEdgeFamily(),sub_domain_id);
210 _initEdgeRelationInfo(edge_relation_data, cell_data, edges_infos); // edge-cell relations
211 if (allow_build_face) {
212 _appendEdgeRelationInfo(edge_relation_data,item_data_list[IK_Face], edges_infos); // edge-face relations
213 _appendFaceRelationInfo(item_relation_data_list[IK_Face],edge_data,faces_infos); // face-edge relations
214 }
215 }
216 // Fill Node info 2
217 Integer node_info_size = 1 + nb_node*2;//New info = Nb_connected_family + for each node : type, uid (no connected family)
218 ItemData& node_data = item_data_list.itemData(Integer(m_mesh->nodeFamily()->itemKind()),nb_node,node_info_size,node_lids,&mesh()->trueNodeFamily(),&mesh()->trueNodeFamily(),sub_domain_id);
219 node_lids.resize(item_data_list[m_mesh->nodeFamily()->itemKind()].nbItems());
220 _fillNodeNewInfo(nodes_infos,node_data.itemInfos());
221 ItemData& node_relation_data = item_relation_data_list.itemData(Integer(m_mesh->nodeFamily()->itemKind()),nb_node,node_info_size,node_lids,&mesh()->trueNodeFamily(),&mesh()->trueNodeFamily(),sub_domain_id);
222 _initNodeRelationInfo(node_relation_data, cell_data, nodes_infos); // node-cell relations
223 if (allow_build_face)_appendNodeRelationInfo(node_relation_data, item_data_list[IK_Face], nodes_infos); // node-face relations
224 if (hasEdge())_appendNodeRelationInfo(node_relation_data, item_data_list[IK_Edge], nodes_infos); // node-edge relations
225
226 // Launch node, face and edges (not mandatory) and cell creation
228
229}
230
231/*---------------------------------------------------------------------------*/
232
233void DynamicMeshIncrementalBuilder::
234addCells2(Integer nb_cell,Int64ConstArrayView cells_infos,
235 Integer sub_domain_id,Int32ArrayView cells,
236 bool allow_build_face)
237{
239 ItemData& cell_data = item_data_list.itemData(Integer(m_mesh->cellFamily()->itemKind()),
240 nb_cell,0,cells,&mesh()->trueCellFamily(),&mesh()->trueCellFamily(),sub_domain_id);
241 // item info_size cannot be guessed
242 Int64Array& cell_infos2 = cell_data.itemInfos();
246 Integer nb_face;
247
248
249 // Fill cell info 2
251
252 // Fill face info 2
254 {
255 Integer face_infos2_size = faces_infos.size()+ 1 + 2 * nb_face; // additive info nb_connected_family + nb_face * (family_id + nb_connected_element)
256 face_lids.resize(nb_face);
257 ItemData& face_data = item_data_list.itemData(Integer(m_mesh->faceFamily()->itemKind()),
258 nb_face,face_infos2_size,face_lids,&mesh()->trueFaceFamily(),&mesh()->trueFaceFamily(),sub_domain_id);
259 Int64ArrayView face_infos2 = face_data.itemInfos().view();
260 _fillFaceInfo2(nb_face,faces_infos,face_infos2,node_uids); // if allow_build_face false, node_uids built in fillCellInfo3
261 }
262
263 // Fill node info 2
264 Integer nb_node_to_add = node_uids.size();
266 ItemData& node_data = item_data_list.itemData(Integer(m_mesh->nodeFamily()->itemKind()),
267 nb_node_to_add,2*nb_node_to_add+1,node_lids,&mesh()->trueNodeFamily(),&mesh()->trueNodeFamily(),sub_domain_id);
268 Int64Array& node_infos2 = node_data.itemInfos();
269 _fillNodeNewInfo(node_uids,node_infos2);
270
271 // Launch node and face and cell creation
273
274}
275
276/*---------------------------------------------------------------------------*/
277/*---------------------------------------------------------------------------*/
278
279void DynamicMeshIncrementalBuilder::
280_fillFaceInfo(Integer& nb_face, Integer nb_cell,Int64Array& faces_infos, Int64ConstArrayView cells_infos, std::map<Int64,Int64SharedArray>& cell_to_face_connectivity_info)
281{
282 faces_infos.reserve(2*cells_infos.size());
283 Int64UniqueArray work_face_sorted_nodes;
284 Int64UniqueArray work_face_orig_nodes;
285 ItemTypeMng* itm = m_item_type_mng;
286 Integer cells_infos_index = 0;
287 nb_face = 0;
288 NodeInFaceSet face_nodes_set;
289 for (Integer i_cell = 0; i_cell < nb_cell; ++i_cell) {
290 Integer item_type_id = (Integer)cells_infos[cells_infos_index++];
291 Int64 current_cell_unique_id = cells_infos[cells_infos_index++];
292 ItemTypeInfo* it = itm->typeFromId(item_type_id);
293 Integer current_cell_nb_node = it->nbLocalNode();
294 Int64ConstArrayView current_cell_node_uids(current_cell_nb_node,&cells_infos[cells_infos_index]);
295 Integer current_cell_nb_face = it->nbLocalFace();
296 for (Integer face_in_cell_index = 0; face_in_cell_index < current_cell_nb_face; ++face_in_cell_index)
297 {
298 const ItemTypeInfo::LocalFace& current_face = it->localFace(face_in_cell_index);
299 Integer current_face_nb_node = current_face.nbNode();
300 work_face_orig_nodes.resize(current_face_nb_node);
301 work_face_sorted_nodes.resize(current_face_nb_node);
302 Integer i = 0;
303 for (Integer node_in_face_index = 0; node_in_face_index < current_face_nb_node; ++node_in_face_index)
304 {
305 work_face_orig_nodes[i++] = current_cell_node_uids[current_face.node(node_in_face_index)];
306 }
307 mesh_utils::reorderNodesOfFace(work_face_orig_nodes,work_face_sorted_nodes);
308 // get face uid: we shouldn't have to guess, it should be given in arguments...
309 Int64 current_face_uid = _findFaceUniqueId(work_face_sorted_nodes,face_nodes_set);
310 if (current_face_uid == NULL_ITEM_ID) // face not already known add to face info
311 {
312 current_face_uid = m_face_uid_pool++;
313 faces_infos.add(current_face.typeId()); // face info type
314 faces_infos.add(current_face_uid); // face info uid
315 faces_infos.addRange(work_face_sorted_nodes); // face info node uids
316 _addFaceNodes(face_nodes_set,work_face_sorted_nodes,current_face_uid);
317 ++nb_face;
318 }
319 cell_to_face_connectivity_info[current_cell_unique_id].add(current_face_uid);
320 }
321 cells_infos_index += current_cell_nb_node;
322 }
323}
324
325/*---------------------------------------------------------------------------*/
326
327void DynamicMeshIncrementalBuilder::
328_fillEdgeInfo(Integer& nb_edge, Integer nb_face,Int64Array& edges_infos,
329 Int64ConstArrayView faces_infos,std::map<std::pair<Int64,Int64>, Int64>& edge_uid_map)
330{
331 edges_infos.reserve(2*faces_infos.size());
332 ItemTypeMng* itm = m_item_type_mng;
333 Integer faces_infos_index = 0;
334 nb_edge = 0;
335 for (Integer i_face = 0; i_face < nb_face; ++i_face) {
336 Integer item_type_id = (Integer)faces_infos[faces_infos_index++]; // face type
337 ++faces_infos_index;// face uid (unused)
338 ItemTypeInfo* it = itm->typeFromId(item_type_id);
339 Integer current_face_nb_node = it->nbLocalNode();
340 Int64ConstArrayView current_face_node_uids(current_face_nb_node,&faces_infos[faces_infos_index]);
341 Integer current_face_nb_edge = it->nbLocalEdge();
342 for (Integer edge_in_face_index = 0; edge_in_face_index < current_face_nb_edge; ++edge_in_face_index)
343 {
344 const ItemTypeInfo::LocalEdge& current_edge = it->localEdge(edge_in_face_index);
345 Int64 first_node = current_face_node_uids[current_edge.beginNode()];
346 Int64 second_node = current_face_node_uids[current_edge.endNode()];
347 if (first_node > second_node) std::swap(first_node,second_node);
348 auto edge_it = edge_uid_map.insert(std::make_pair(std::make_pair(first_node,second_node), m_edge_uid_pool));
349 if (edge_it.second)
350 {
351 edges_infos.add(m_edge_uid_pool); // edge uid
352 edges_infos.add(first_node); // first node uid
353 edges_infos.add(second_node); // second node uid
354 ++nb_edge;
356 }
357 }
358 faces_infos_index += current_face_nb_node;
359 }
360}
361
362/*---------------------------------------------------------------------------*/
363
364void DynamicMeshIncrementalBuilder::
365_fillNodeInfo(Integer& nb_node, Integer nb_face,Int64Array& nodes_infos, Int64ConstArrayView faces_infos)
366{
367 nodes_infos.reserve(faces_infos.size());
368 Integer faces_infos_index = 0;
369 std::set<Int64> nodes_set;
370 ItemTypeMng* itm = m_item_type_mng;
371 for (Integer i_face = 0; i_face < nb_face; ++i_face) {
372 Int32 type_id = CheckedConvert::toInt32(faces_infos[faces_infos_index++]);
373 Integer current_face_nb_node = itm->typeFromId(type_id)->nbLocalNode(); // face type
374 ++faces_infos_index;//face_uid (unused)
375 for (auto node_uid : faces_infos.subConstView(faces_infos_index,current_face_nb_node)) {
376 nodes_set.insert(node_uid);
377 }
378 faces_infos_index+=current_face_nb_node;
379 }
380 nb_node = CheckedConvert::toInteger(nodes_set.size());
381 for (auto node_uid : nodes_set) {
382 nodes_infos.add(node_uid);
383 }
384}
385
386/*---------------------------------------------------------------------------*/
387
388void DynamicMeshIncrementalBuilder::
389_fillNodeInfoFromEdge(Integer& nb_node, Integer nb_edge, Int64Array& nodes_infos, Int64ConstArrayView edges_infos)
390{
391 nodes_infos.reserve(2*edges_infos.size());
392 Integer edges_infos_index = 0;
393 std::set<Int64> nodes_set;
394 for (Integer i_edge = 0; i_edge < nb_edge; ++i_edge) {
395 ++edges_infos_index;//edge_uid (unused)
396 nodes_set.insert(edges_infos[edges_infos_index++]);
397 nodes_set.insert(edges_infos[edges_infos_index++]);
398 }
399 nb_node = CheckedConvert::toInteger(nodes_set.size());
400 for (auto node_uid : nodes_set) {
401 nodes_infos.add(node_uid);
402 }
403}
404/*---------------------------------------------------------------------------*/
405
406void DynamicMeshIncrementalBuilder::
407_fillCellNewInfoNew(Integer nb_cell,Int64ConstArrayView cells_infos,Int64Array& cell_infos2,
408 const std::map<Int64,Int64SharedArray>& cell_to_face_connectivity_info, const std::map<std::pair<Int64,Int64>, Int64>& edge_uid_map)
409{
410 Integer cell_infos2_size_approx = 1 + 3 * (cells_infos.size()+ 2*nb_cell); // supposes as many faces as nodes as edges...
411 cell_infos2.reserve(cell_infos2_size_approx);
412 ItemTypeMng* itm = m_item_type_mng;
413 Integer cells_infos_index = 0;
414 Integer nb_connected_families = hasEdge() ? 3 : 2;
415 cell_infos2.add(nb_connected_families); // nb_connected_families (node and face +/- edge)
416 for (Integer i_cell = 0; i_cell < nb_cell; ++i_cell) {
417 Integer item_type_id = (Integer)cells_infos[cells_infos_index];
418 cell_infos2.add(cells_infos[cells_infos_index++]); // cell type
419 Int64 current_cell_uid = cells_infos[cells_infos_index];
420 cell_infos2.add(cells_infos[cells_infos_index++]); // cell uid
421 ItemTypeInfo* it = itm->typeFromId(item_type_id);
422 //--- Cell node connectivity
423 cell_infos2.add(mesh()->nodeFamily()->itemKind()); // connected_family_id: node family
424 Integer current_cell_nb_node = it->nbLocalNode();
425 cell_infos2.add(current_cell_nb_node); // nb_connected_nodes
426 Int64ConstArrayView current_cell_node_uids(current_cell_nb_node,&cells_infos[cells_infos_index]);
427 cell_infos2.addRange(current_cell_node_uids); // node ids
428 //--- Cell face connectivity
429 cell_infos2.add(mesh()->faceFamily()->itemKind()); // connected_family_id: face family
430 Integer current_cell_nb_face = it->nbLocalFace();
431 cell_infos2.add(current_cell_nb_face); // nb_connected_faces
432 Int64ArrayView current_cell_faces = cell_to_face_connectivity_info.find(current_cell_uid)->second.view();
433 if (current_cell_nb_face != current_cell_faces.size())
434 ARCANE_FATAL("Incoherent number of faces for cell {0}. Expected {1} found {2}",
435 current_cell_uid,current_cell_nb_face,current_cell_faces.size());
436 cell_infos2.addRange(current_cell_faces); // face ids
437 //-- Cell edge connectivity
438 if (hasEdge())
439 {
440 cell_infos2.add(mesh()->edgeFamily()->itemKind()); // connected_family_id: edge family
441 Integer current_cell_nb_edge = it->nbLocalEdge();
442 cell_infos2.add(current_cell_nb_edge); // nb_connected_edges
443 for (int edge_index = 0; edge_index < current_cell_nb_edge; ++edge_index) {
444 Int64 first_node = current_cell_node_uids[it->localEdge(edge_index).beginNode()];
445 Int64 second_node = current_cell_node_uids[it->localEdge(edge_index).endNode()];
446 if (first_node > second_node) std::swap(first_node,second_node);// edge may be oriented negatively in the cell
447 auto edge_it = edge_uid_map.find(std::make_pair(first_node,second_node));
448 if (edge_it == edge_uid_map.end())
449 ARCANE_FATAL("Do not find edge with nodes {0}-{1} in edge uid map. Exiting",
450 current_cell_node_uids[it->localEdge(edge_index).beginNode()],
451 current_cell_node_uids[it->localEdge(edge_index).endNode()]);
452 cell_infos2.add(edge_it->second);
453 }
454 }
455 cells_infos_index += current_cell_nb_node;
456 }
457}
458
459
460/*---------------------------------------------------------------------------*/
461/*---------------------------------------------------------------------------*/
462
463void DynamicMeshIncrementalBuilder::
464_fillCellInfo2(Integer nb_cell,Int64ConstArrayView cells_infos,Int64Array& cell_infos2,
465 Integer& nb_face, Int64Array& faces_infos, Int64Array& node_uids, bool allow_build_face)
466{
467 Integer cell_infos2_size_approx = 1 + 2 * (cells_infos.size()+ 2*nb_cell); // supposes as many faces as nodes...
468 cell_infos2.reserve(cell_infos2_size_approx);
469 // Fill infos
470 ItemTypeMng* itm = m_item_type_mng;
471 Integer cells_infos_index = 0;
472 cell_infos2.add(2); // nb_connected_families (node and face)
473
474 nb_face = 0;
475 faces_infos.reserve(2*cells_infos.size());
476 Int64UniqueArray work_face_sorted_nodes;
477 Int64UniqueArray work_face_orig_nodes;
478 NodeInFaceSet face_nodes_set;
479 std::set<Int64> node_uid_set;
480 // Fill face_infos2 from faces_infos
481 for (Integer i_cell = 0; i_cell < nb_cell; ++i_cell) {
482
483 Integer item_type_id = (Integer)cells_infos[cells_infos_index];
484 cell_infos2.add(cells_infos[cells_infos_index++]); // cell type
485 cell_infos2.add(cells_infos[cells_infos_index++]); // cell uid
486 cell_infos2.add(mesh()->nodeFamily()->itemKind()); // connected_family_id: node family
487
488 ItemTypeInfo* it = itm->typeFromId(item_type_id);
489 // Cell node connectivity
490 Integer current_cell_nb_node = it->nbLocalNode();
491 cell_infos2.add(current_cell_nb_node); // nb_connected_nodes
492 Int64ConstArrayView current_cell_node_uids(current_cell_nb_node,&cells_infos[cells_infos_index]);
493 cell_infos2.addRange(current_cell_node_uids); // node ids
494 if (!allow_build_face) node_uid_set.insert(current_cell_node_uids.begin(),current_cell_node_uids.end()); // otherwise node ids will be computed in face info build
495 // cell face connectivity
496 cell_infos2.add(mesh()->faceFamily()->itemKind()); // connected_family_id: face family
497 Integer current_cell_nb_face = it->nbLocalFace();
498 cell_infos2.add(current_cell_nb_face); // nb_connected_faces
499 for (Integer face_in_cell_index = 0; face_in_cell_index < current_cell_nb_face; ++face_in_cell_index)
500 {
501 ItemTypeInfo::LocalFace current_face = it->localFace(face_in_cell_index);
502 Integer current_face_nb_node = current_face.nbNode();
503 work_face_orig_nodes.resize(current_face_nb_node);
504 work_face_sorted_nodes.resize(current_face_nb_node);
505 Integer i = 0;
506 for (Integer node_in_face_index = 0; node_in_face_index < current_face_nb_node; ++node_in_face_index)
507 {
508 work_face_orig_nodes[i++] = current_cell_node_uids[current_face.node(node_in_face_index)];
509 }
510 mesh_utils::reorderNodesOfFace(work_face_orig_nodes,work_face_sorted_nodes);
511 // get face uid: we shouldn't have to guess, it should be given in arguments...
512 Int64 current_face_uid = _findFaceUniqueId(work_face_sorted_nodes,face_nodes_set);
513 if (current_face_uid == NULL_ITEM_ID) // face not already known add to face info
514 {
515 current_face_uid = m_face_uid_pool++;
516 faces_infos.add(current_face.typeId()); // face info type
517 faces_infos.add(current_face_uid); // face info uid
518 faces_infos.addRange(work_face_sorted_nodes); // face info node uids
519 _addFaceNodes(face_nodes_set,work_face_sorted_nodes,current_face_uid);
520 ++nb_face;
521 }
522 cell_infos2.add(current_face_uid); // face ids
523 }
524 cells_infos_index += current_cell_nb_node;
525 }
526 if (! allow_build_face)
527 {
528 node_uids.resize(node_uid_set.size());
529 Integer index = 0;
530 for (Int64 node_uid : node_uid_set) node_uids[index++] = node_uid;
531 }
532}
533
534/*---------------------------------------------------------------------------*/
535
536void DynamicMeshIncrementalBuilder::
537_initFaceRelationInfo(ItemData& source_item_relation_data, const ItemData& target_item_dependencies_data, Int64ConstArrayView faces_info)
538{
539 _fillFaceRelationInfo(source_item_relation_data,target_item_dependencies_data,faces_info,true);
540}
541
542
543/*---------------------------------------------------------------------------*/
544
545void DynamicMeshIncrementalBuilder::
546_appendFaceRelationInfo(ItemData& source_item_relation_data, const ItemData& target_item_dependencies_data, Int64ConstArrayView faces_info)
547{
548 _fillFaceRelationInfo(source_item_relation_data,target_item_dependencies_data,faces_info,false);
549}
550
551/*---------------------------------------------------------------------------*/
552
553void DynamicMeshIncrementalBuilder::
554_fillFaceRelationInfo(ItemData& source_item_relation_data, const ItemData& target_item_dependencies_data,
555 Int64ConstArrayView faces_info, bool is_source_relation_data_empty)
556{
557 // face_infos = [{face_type, face_uid, {face_node_uids}]
558 Int64UniqueArray face_uids_and_types;
559 face_uids_and_types.reserve(2*source_item_relation_data.nbItems());
560 ItemTypeMng* itm = m_item_type_mng;
561 for (Integer face_info_index = 0; face_info_index < faces_info.size();) {
562 face_uids_and_types.add(faces_info[face_info_index+1]); // face_uid
563 face_uids_and_types.add(faces_info[face_info_index]); // face_type
564 Integer type_id = CheckedConvert::toInteger(face_uids_and_types.back());
565 face_info_index += (2+itm->typeFromId(type_id)->nbLocalNode());// increment and skip info (first & second_node_uid)
566 }
567 _fillItemRelationInfo(source_item_relation_data,target_item_dependencies_data,face_uids_and_types, is_source_relation_data_empty);
568}
569
570/*---------------------------------------------------------------------------*/
571
572void DynamicMeshIncrementalBuilder::
573_initEdgeRelationInfo(ItemData& source_item_relation_data, const ItemData& target_item_dependencies_data, Int64ConstArrayView edges_info)
574{
575 _fillEdgeRelationInfo(source_item_relation_data,target_item_dependencies_data,edges_info,true);
576}
577
578
579/*---------------------------------------------------------------------------*/
580
581void DynamicMeshIncrementalBuilder::
582_appendEdgeRelationInfo(ItemData& source_item_relation_data, const ItemData& target_item_dependencies_data, Int64ConstArrayView edges_info)
583{
584 _fillEdgeRelationInfo(source_item_relation_data,target_item_dependencies_data,edges_info,false);
585}
586
587
588/*---------------------------------------------------------------------------*/
589
590void DynamicMeshIncrementalBuilder::
591_fillEdgeRelationInfo(ItemData& source_item_relation_data, const ItemData& target_item_dependencies_data,
592 Int64ConstArrayView edges_info, bool is_source_relation_data_empty)
593{
594 // edge_infos = [{edge_uid, first_node_uid, second_node_uid}
595 ARCANE_ASSERT((source_item_relation_data.nbItems()*3 == edges_info.size()),("source_item_relation_data and edges_info size incoherent. Exiting."));
596 Int64UniqueArray edge_uids_and_types;
597 edge_uids_and_types.reserve(2*source_item_relation_data.nbItems());
598 for (Integer edge_info_index = 0; edge_info_index < edges_info.size();) {
599 edge_uids_and_types.add(edges_info[edge_info_index++]); // edge_uid
600 edge_uids_and_types.add(IT_Line2); // edge_type
601 edge_info_index+=2;// skip info (first & second_node_uid)
602 }
603 _fillItemRelationInfo(source_item_relation_data,target_item_dependencies_data,edge_uids_and_types, is_source_relation_data_empty);
604}
605
606/*---------------------------------------------------------------------------*/
607
608void DynamicMeshIncrementalBuilder::
609_initNodeRelationInfo(ItemData& source_item_relation_data, const ItemData& target_item_dependencies_data, Int64ConstArrayView nodes_info)
610{
611 _fillNodeRelationInfo(source_item_relation_data,target_item_dependencies_data,nodes_info,true);
612}
613
614
615/*---------------------------------------------------------------------------*/
616
617void DynamicMeshIncrementalBuilder::
618_appendNodeRelationInfo(ItemData& source_item_relation_data, const ItemData& target_item_dependencies_data, Int64ConstArrayView nodes_info)
619{
620 _fillNodeRelationInfo(source_item_relation_data,target_item_dependencies_data,nodes_info,false);
621}
622
623/*---------------------------------------------------------------------------*/
624
625void DynamicMeshIncrementalBuilder::
626_fillNodeRelationInfo(ItemData& source_item_relation_data, const ItemData& target_item_dependencies_data, Int64ConstArrayView nodes_info, bool is_source_relation_data_empty){
627 // nodes_info = [node_uids]
628 ARCANE_ASSERT((source_item_relation_data.nbItems() == nodes_info.size()),("source_item_relation_data and nodes_info size incoherent. Exiting."));
629 Int64UniqueArray node_uids_and_types(2*nodes_info.size());
630 for (Integer node_index = 0; node_index < nodes_info.size(); ++node_index) {
631 node_uids_and_types[2*node_index] = nodes_info[node_index];
632 node_uids_and_types[2*node_index+1] = IT_Vertex;
633 }
634 _fillItemRelationInfo(source_item_relation_data,target_item_dependencies_data,node_uids_and_types, is_source_relation_data_empty);
635}
636
637
638/*---------------------------------------------------------------------------*/
639
640void DynamicMeshIncrementalBuilder::
641_fillItemRelationInfo(ItemData& source_item_relation_data, const ItemData& target_item_dependencies_data,
642 Int64ConstArrayView source_item_uids_and_types,
643 bool is_source_item_relation_data_empty)
644{
645 ARCANE_ASSERT((source_item_relation_data.nbItems()*2 == source_item_uids_and_types.size()),
646 ("source item number incoherent between source_item_relation_data and source_item_uids_and_types. Exiting."));
647 // Fill an ItemData containing source to target relations (target to source relations are included in target_item_data)
648 auto & source_relation_info = source_item_relation_data.itemInfos();
649 const auto & target_dependencies_info = target_item_dependencies_data.itemInfos();
650 auto source_family = source_item_relation_data.itemFamily();
651 auto target_family = target_item_dependencies_data.itemFamily();
652 if (! source_family || !target_family) return;
653 std::map<Int64, Int64SharedArray> source_to_target_uids;
654 Integer nb_families_connected_to_target = CheckedConvert::toInteger(target_dependencies_info[0]);
655 Integer target_info_index = 1; // 0 is nb_connected_families
656
657 // Fill map source to target traversing target_item_dependencies_data
658 for (; target_info_index < target_dependencies_info.size();) {
659 target_info_index++; // current target item_type
660 Int64 target_item_uid = target_dependencies_info[target_info_index++];// current target item uid
661 for (Integer family_connected_to_target = 0; family_connected_to_target < nb_families_connected_to_target; ++family_connected_to_target) {
662 Int64 family_connected_to_target_kind = target_dependencies_info[target_info_index++];// current target item connected family kind
663 if (family_connected_to_target_kind != source_family->itemKind()) {//this connection info does not concern source family. Skip
664 Integer nb_non_read_values = CheckedConvert::toInteger(target_dependencies_info[target_info_index++]); // nb_connected_item on this other family (/= to source family)
665 target_info_index+= nb_non_read_values;
666 continue;
667 }
668 else {
669 Int32 nb_source_item_connected_to_target_item = CheckedConvert::toInt32(target_dependencies_info[target_info_index++]);
670 for (Integer source_item_index = 0; source_item_index < nb_source_item_connected_to_target_item; ++source_item_index) {
671 source_to_target_uids[target_dependencies_info[source_item_index+target_info_index]].add(target_item_uid);
672 }
673 target_info_index += nb_source_item_connected_to_target_item;
674 }
675 }
676 }
677 // Fill or append source_item_relation_data traversing the map source_to_target_connectivity
678 if (is_source_item_relation_data_empty) _initEmptyRelationInfo(source_relation_info, source_to_target_uids, source_item_uids_and_types,
679 target_dependencies_info.size(), target_family);
680 else _appendInitializedRelationInfo(source_relation_info, source_to_target_uids, source_item_uids_and_types,
681 target_dependencies_info.size(), target_family);
682
683}
684
685/*---------------------------------------------------------------------------*/
686
687void DynamicMeshIncrementalBuilder::
688_initEmptyRelationInfo(Int64Array& source_relation_info, std::map<Int64, Int64SharedArray>& source_to_target_uids, Int64ConstArrayView source_item_uids_and_types,
689 Integer approx_relation_size,
690 IItemFamily const * target_family)
691{
692 if (! source_relation_info.empty()) source_relation_info.clear();
693 source_relation_info.reserve(approx_relation_size); // clearly too much elements...but only available info. Do better ?
694 source_relation_info.add(1);// nb_connected_families
695 // Fill source_item_relation_data
696 for (Integer source_item_uids_and_types_index = 0; source_item_uids_and_types_index < source_item_uids_and_types.size(); source_item_uids_and_types_index+=2) {
697 Int64 source_item_uid = source_item_uids_and_types[source_item_uids_and_types_index];
698 source_relation_info.add(source_item_uids_and_types[source_item_uids_and_types_index+1]); // item type
699 source_relation_info.add(source_item_uid); // item uid
700 source_relation_info.add(target_family->itemKind());// connected family kind
701 auto & connected_items = source_to_target_uids[source_item_uid];
702 source_relation_info.add(connected_items.size());// nb_connected_item
703 source_relation_info.addRange(connected_items.view()); // connected_items uids
704 }
705}
706
707/*---------------------------------------------------------------------------*/
708
709void DynamicMeshIncrementalBuilder::
710_appendInitializedRelationInfo(Int64Array& source_relation_info, std::map<Int64, Int64SharedArray>& source_to_target_uids, Int64ConstArrayView source_item_uids_and_types,
711 Integer approx_relation_size,
712 IItemFamily const * target_family)
713{
714 // Create a working array to build the consolidated info. This array will be copied in to source_relation_info at the end.
715 Int64UniqueArray source_relation_info_wrk_copy;
716 source_relation_info_wrk_copy.reserve(source_relation_info.size()+approx_relation_size);
717 std::set<Int64> treated_items;// To detect eventual source_items not already present in source_relation_info
718 Integer source_relation_info_index = 0;
719 Integer nb_connected_family = CheckedConvert::toInteger(source_relation_info[source_relation_info_index++]);
720 source_relation_info_wrk_copy.add(nb_connected_family+1); // adding a new connected family
721 for(; source_relation_info_index < source_relation_info.size() ;){
722 source_relation_info_wrk_copy.add(source_relation_info[source_relation_info_index++]); // item type
723 Int64 source_item_uid = source_relation_info[source_relation_info_index++]; // get item uid
724 source_relation_info_wrk_copy.add(source_item_uid);
725 treated_items.insert(source_item_uid);
726 for (Integer connected_family_index = 0; connected_family_index < nb_connected_family; ++connected_family_index) {
727 source_relation_info_wrk_copy.add(source_relation_info[source_relation_info_index++]); // family kind
728 Integer nb_connected_elements = CheckedConvert::toInteger(source_relation_info[source_relation_info_index++]); // nb connected elements
729 source_relation_info_wrk_copy.add(nb_connected_elements);
730 source_relation_info_wrk_copy.addRange(source_relation_info.subConstView(source_relation_info_index,nb_connected_elements));
731 source_relation_info_index += nb_connected_elements;
732 }
733 // Add new connection info
734 source_relation_info_wrk_copy.add(target_family->itemKind()); // family kind
735 const auto& connected_items = source_to_target_uids[source_item_uid]; // get connected items
736 source_relation_info_wrk_copy.add(connected_items.size()); // nb connected elements
737 source_relation_info_wrk_copy.addRange(connected_items);
738 }
739 // Find eventual source_items not already present in source_relation_info : todo check this can happen
740 for (Integer source_item_uids_and_types_index = 0; source_item_uids_and_types_index < source_item_uids_and_types.size(); source_item_uids_and_types_index+=2) {
741 Int64 source_item_uid = source_item_uids_and_types[source_item_uids_and_types_index];
742 if (treated_items.find(source_item_uid) == treated_items.end()){
743 source_relation_info_wrk_copy.add(source_item_uids_and_types[source_item_uids_and_types_index+1]); // item type
744 source_relation_info_wrk_copy.add(source_item_uid); // item uid
745 source_relation_info_wrk_copy.add(target_family->itemKind()); // family kind
746 const auto& connected_items = source_to_target_uids[source_item_uid]; // get connected items
747 source_relation_info_wrk_copy.add(connected_items.size()); // nb connected elements
748 source_relation_info_wrk_copy.addRange(connected_items);
749 // Padd this item info with family info : we added only one family, add void values for the other nb_connected_family families
750 for (Integer connected_family_index = 0; connected_family_index < nb_connected_family; ++connected_family_index) {
751 source_relation_info_wrk_copy.add(0); // family id (does not matter)
752 source_relation_info_wrk_copy.add(0); // nb_connected_elements for this family
753 }
754 }
755 }
756 // Copy working array into destination array
757 source_relation_info.resize(source_relation_info_wrk_copy.size());
758 std::copy(source_relation_info_wrk_copy.begin(), source_relation_info_wrk_copy.end(), source_relation_info.begin());
759}
760
761/*---------------------------------------------------------------------------*/
762/*---------------------------------------------------------------------------*/
763
764Int64 DynamicMeshIncrementalBuilder::
765_findFaceUniqueId(Int64ConstArrayView work_face_sorted_nodes, NodeInFaceSet& face_nodes_set)
766{
767 // check if first node exist
768 Integer index = 0;
769// return _findFaceInFaceNodesSet(face_nodes_set,index,work_face_sorted_nodes,std::make_shared<NodeInFace>(NULL_ITEM_ID));
770 return _findFaceInFaceNodesSet(face_nodes_set,index,work_face_sorted_nodes,NodeInFacePtr(NULL_ITEM_ID));
771}
772
773/*---------------------------------------------------------------------------*/
774
775Int64 DynamicMeshIncrementalBuilder::
776_findFaceInFaceNodesSet(const NodeInFaceSet& face_nodes_set,Integer index,Int64ConstArrayView face_nodes, NodeInFacePtr node)
777{
778 if (index < face_nodes.size())
779 {
780 auto found_node = std::find(face_nodes_set.begin(),face_nodes_set.end(),NodeInFacePtr(face_nodes[index]));
781 if (found_node == face_nodes_set.end()) return node->faceUid();
782 else return _findFaceInFaceNodesSet((*found_node)->nextNodeSet(),++index,face_nodes,*found_node);
783 }
784 else return node->faceUid();
785}
786
787/*---------------------------------------------------------------------------*/
788
789void DynamicMeshIncrementalBuilder::
790_addFaceNodes(NodeInFaceSet& face_nodes_set, Int64ConstArrayView face_nodes, Int64 face_uid)
791{
792 Integer index = 0;
793// _addFaceInFaceNodesSet(face_nodes_set, index,face_nodes, std::make_shared<NodeInFace>(NULL_ITEM_ID), face_uid);
794 _addFaceInFaceNodesSet(face_nodes_set, index,face_nodes, NodeInFacePtr(NULL_ITEM_ID), face_uid);
795}
796
797/*---------------------------------------------------------------------------*/
798
799void DynamicMeshIncrementalBuilder::
800_addFaceInFaceNodesSet(NodeInFaceSet& face_nodes_set,Integer index,Int64ConstArrayView face_nodes, NodeInFacePtr node, Int64 face_uid)
801{
802 if (index < face_nodes.size())
803 {
804// auto next_node = std::make_shared<NodeInFace>(face_nodes[index]);
805 auto next_node = _insertNode(face_nodes_set,face_nodes[index]);
806// debug() << "Add node " << face_nodes[index] << " in set " << &face_nodes_set;
807// debug() << "set size " << face_nodes_set.size();
808 _addFaceInFaceNodesSet(next_node->nextNodeSet(),++index,face_nodes,next_node,face_uid);
809// else
810// _addFaceInFaceNodesSet((*insertion_return.first)->nextNodeSet(),++index,face_nodes,*insertion_return.first,face_uid); // pbe du const. Change from set to map ?
811 }
812 else
813 {
814 node->setFaceUid(face_uid);
815// debug() << "Set face uid " << face_uid << " for node " << node->m_uid;
816 }
817}
818
819DynamicMeshIncrementalBuilder::NodeInFacePtr&
820DynamicMeshIncrementalBuilder::_insertNode(NodeInFaceSet& face_nodes_set, Int64 inserted_node_uid)
821{
822 NodeInFacePtr new_node(inserted_node_uid);
823 auto found_node = std::find(face_nodes_set.begin(),face_nodes_set.end(),new_node);
824 if (found_node == face_nodes_set.end()) {
825 face_nodes_set.push_back(std::move(new_node));
826 return face_nodes_set.back();
827 }
828 else return *found_node;
829}
830
831/*---------------------------------------------------------------------------*/
832/*---------------------------------------------------------------------------*/
840addParentCells(const ItemVectorView & items)
841{
842 const Integer nb_cell = items.size();
843
844 for( Integer i_cell=0; i_cell<nb_cell; ++i_cell ){
846 }
847}
848
849/*---------------------------------------------------------------------------*/
850/*---------------------------------------------------------------------------*/
851
862 Integer sub_domain_id,Int32ArrayView cells,
863 bool allow_build_face)
864{
865 ItemTypeMng* itm = m_item_type_mng;
866 CellFamily& cell_family = m_mesh->trueCellFamily();
867
868 debug() << "[DynamicMeshIncrementalBuilder::addHChildrenCells] ADD CELLS mesh=" << m_mesh->name() << " nb_cell=" << nb_cell;
869 Integer cells_infos_index = 0;
870 bool add_to_cells = cells.size()!=0;
871 if (add_to_cells && nb_cell!=cells.size())
872 throw ArgumentException(A_FUNCINFO,
873 "return array 'cells' has to have same size as number of cells");
874 for( Integer i_cell=0; i_cell<nb_cell; ++i_cell ){
875 debug(Trace::Highest)<<"\t\t[DynamicMeshIncrementalBuilder::addHChildrenCells]cell "<<i_cell<<"/"<<nb_cell;
876
878 debug(Trace::Highest)<<"\t\t[DynamicMeshIncrementalBuilder::addHChildrenCells]cells_infos["<<cells_infos_index<<"]="<<cells_infos[cells_infos_index]<<", type_id="<<item_type_id;
880
882 debug(Trace::Highest)<<"\t\t[DynamicMeshIncrementalBuilder::addHChildrenCells]cells_infos["<<cells_infos_index<<"]="<<cells_infos[cells_infos_index]<<", uid="<<cell_unique_id;
884
885 ItemTypeInfo* it = itm->typeFromId(item_type_id);
886 Integer current_cell_nb_node = it->nbLocalNode();
887 debug(Trace::Highest) << "\t\t[DynamicMeshIncrementalBuilder::addHChildrenCells]DM ADD_CELL uid=" << cell_unique_id << " type_id=" << item_type_id
888 << " nb_node=" << current_cell_nb_node;
890 for( Integer i=0; i<current_cell_nb_node; ++i )
891 debug(Trace::Highest) << "\t\t\t[DynamicMeshIncrementalBuilder::addHChildrenCells]DM NODE uid=" << current_cell_nodes_uid[i];
892
898
899 cell_family._addParentCellToCell(cell,hParent_cell);
900 if (add_to_cells)
901 cells[i_cell] = cell->localId();
903 }
904 cell_family._addChildrenCellsToCell(hParent_cell,cells);
905
906 debug() << "[DynamicMeshIncrementalBuilder::addHChildrenCells] done";
907}
908
909/*---------------------------------------------------------------------------*/
910/*---------------------------------------------------------------------------*/
919{
920 const Integer nb_item = items.size();
921
922 for( Integer i_item=0; i_item<nb_item; ++i_item ) {
924 }
925}
926
927/*---------------------------------------------------------------------------*/
928/*---------------------------------------------------------------------------*/
938{
939 Integer nb_node_to_add = nodes_uid.size();
940 bool add_to_nodes = nodes.size()!=0;
941 if (add_to_nodes && nb_node_to_add!=nodes.size())
942 throw ArgumentException(A_FUNCINFO,
943 "return array 'nodes' has to have same size as number of nodes");
944 for( Integer i_node=0; i_node<nb_node_to_add; ++i_node ){
945 ItemInternal* node = m_one_mesh_item_adder->addOneNode(nodes_uid[i_node],owner);
946 if (add_to_nodes)
947 nodes[i_node] = node->localId();
948 }
949}
950
951/*---------------------------------------------------------------------------*/
952/*---------------------------------------------------------------------------*/
962{
963 Integer nb_node_to_add = nodes_uid.size();
964 bool add_to_nodes = nodes.size()!=0;
965 if (add_to_nodes && nb_node_to_add!=nodes.size())
966 throw ArgumentException(A_FUNCINFO,
967 "return array 'nodes' has to have same size as number of nodes");
969 ItemData& node_data = item_info_list.itemData(Integer(m_mesh->nodeFamily()->itemKind()),
970 nb_node_to_add,2*nb_node_to_add+1,nodes,&mesh()->trueNodeFamily(),&mesh()->trueNodeFamily(),owner);
971 Int64Array& node_infos2 = node_data.itemInfos();
972 // Copy node_info : to decrease the footprint of the copy, use references instead of int64
973 _fillNodeNewInfo(nodes_uid,node_infos2);
974
976 }
977
978/*---------------------------------------------------------------------------*/
979/*---------------------------------------------------------------------------*/
980
981void DynamicMeshIncrementalBuilder::
983{
984 node_infos2[0] = 0; // nb_connected_families
985 Integer index = 0;
986 for (auto node_uid : node_uids)
987 {
988 node_infos2[2*index+1] = IT_Vertex; // type
989 node_infos2[2*index+2] = node_uid; // id
990 index++;
991 }
992}
993
994/*---------------------------------------------------------------------------*/
995/*---------------------------------------------------------------------------*/
1017{
1018 // Add items : item construction done from leaves to root
1019 _addItemsOrRelations(item_info_list,IItemFamilyNetwork::InverseTopologicalOrder);
1020}
1021
1022/*---------------------------------------------------------------------------*/
1023
1026{
1027 if (item_info_list.size() == 0 || item_relation_info_list.size() == 0) return;
1029 addRelations(item_relation_info_list);
1030}
1031
1032/*---------------------------------------------------------------------------*/
1033
1034void DynamicMeshIncrementalBuilder::
1035addRelations(ItemDataList& item_relation_list)
1036{
1037 // Add relations : items are already added. Do it from root to leaves
1038 _addItemsOrRelations(item_relation_list,IItemFamilyNetwork::TopologicalOrder);
1039}
1040
1041/*---------------------------------------------------------------------------*/
1042
1043void DynamicMeshIncrementalBuilder::
1044_addItemsOrRelations(ItemDataList& info_list, IItemFamilyNetwork::eSchedulingOrder family_graph_traversal_order)
1045{
1046 // Add relations : items are already added. Do it from root to leaves
1047 if (info_list.size() == 0) return;
1048 m_mesh->itemFamilyNetwork()->schedule([&](IItemFamily* family){
1049 ItemData i_infos = info_list[family->itemKind()];
1050 this->addFamilyItems(i_infos);
1051 },
1052 family_graph_traversal_order); // item construction done from leaves to root
1053}
1054
1055/*---------------------------------------------------------------------------*/
1056/*---------------------------------------------------------------------------*/
1064{
1065 if (item_data.nbItems() == 0) return;
1066 bool add_to_items = item_data.itemLids().size()!=0;
1067 if (add_to_items && item_data.nbItems()!= item_data.itemLids().size())
1068 throw ArgumentException(A_FUNCINFO,
1069 "return array containing item lids has to have be of size number of items");
1070 // Prepare info and call OneMeshItemAdder->addOneItem
1071 Int64 item_uid;
1074 if(nb_connected_family == 0)
1075 return ;
1077 Integer nb_item_info = 0;
1078 Integer item_index = 0;
1079 for (Integer info_index = 1; info_index < item_data.itemInfos().size();){
1080 ItemTypeId item_type_id { (Int16)item_infos[info_index++] }; // item_type
1081 item_uid = item_infos[info_index++]; // item_uid
1086 nb_item_info += nb_item_info_increment; // family_id , nb_connected_elements
1087 info_index+= nb_item_info_increment; // pointing on next family id
1088 }
1089 ItemInternal* item = m_one_mesh_item_adder->addOneItem2(item_data.itemFamily(),
1090 item_data.itemFamilyModifier(),
1092 item_uid,
1093 item_data.itemOwners()[item_index],
1094 item_data.subDomainId(),
1097 if (add_to_items)
1098 item_data.itemLids()[item_index++] = item->localId();
1099 nb_item_info = 0;
1100 }
1101}
1102
1103/*---------------------------------------------------------------------------*/
1104/*---------------------------------------------------------------------------*/
1116
1117/*---------------------------------------------------------------------------*/
1118/*---------------------------------------------------------------------------*/
1129 Integer sub_domain_id,Int32ArrayView faces)
1130{
1131 ItemTypeMng* itm = m_item_type_mng;
1132
1133 bool add_to_faces = faces.size()!=0;
1134 if (add_to_faces && nb_face!=faces.size())
1135 throw ArgumentException(A_FUNCINFO,
1136 "return array 'faces' has to have same size as number of faces");
1137
1138 Integer faces_infos_index = 0;
1139 for(Integer i_face=0; i_face<nb_face; ++i_face ){
1140
1145
1146 ItemTypeInfo* it = itm->typeFromId(item_type_id);
1147
1148 Integer current_face_nb_node = it->nbLocalNode();
1151
1153
1154 if (add_to_faces)
1155 faces[i_face] = face->localId();
1156 }
1157}
1158
1159/*---------------------------------------------------------------------------*/
1160/*---------------------------------------------------------------------------*/
1171 Integer sub_domain_id,Int32ArrayView faces)
1172{
1173 bool add_to_faces = faces.size()!=0;
1174 if (add_to_faces && nb_face!=faces.size())
1175 throw ArgumentException(A_FUNCINFO,
1176 "return array 'faces' has to have same size as number of faces");
1177 // Prepare face infos 2
1178 Integer face_infos2_size = faces_infos.size()+ 1 + 2 * nb_face; // additive info nb_connected_family + nb_face * (family_id + nb_connected_element)
1180 ItemData& face_data = item_info_list.itemData(Integer(m_mesh->faceFamily()->itemKind()),
1181 nb_face,face_infos2_size,faces,&mesh()->trueFaceFamily(),&mesh()->trueFaceFamily(),sub_domain_id);
1182
1183 Int64ArrayView face_infos2 = face_data.itemInfos().view();
1186
1187 _fillFaceInfo2(nb_face,faces_infos,face_infos2,node_uids);
1188
1189 // Prepare edge data if needed
1190// if (m_has_edge) {
1191// Integer nb_edge_to_add = edge_uids.size();
1192// Int32UniqueArray edge_lids(nb_edge_to_add);
1193// ItemData& edge_data = item_info_list.itemData(Integer(m_mesh->edgeFamily()->itemKind()),
1194// nb_edge_to_add,2*nb_edge_to_add+1,edge_lids,&mesh()->trueNodeFamily(),&mesh()->trueNodeFamily(),sub_domain_id);
1195// Int64Array& edge_infos2 = edge_data.itemInfos();
1196// _fillEdgeInfo2(nb_edge_to_add,edge_uids,edge_infos2);
1197// }
1198
1199 // Prepare node data (mutualize)
1200 Integer nb_node_to_add = node_uids.size();
1202 ItemData& node_data = item_info_list.itemData(Integer(m_mesh->nodeFamily()->itemKind()),
1203 nb_node_to_add,2*nb_node_to_add+1,node_lids,&mesh()->trueNodeFamily(),&mesh()->trueNodeFamily(),sub_domain_id);
1204 Int64Array& node_infos2 = node_data.itemInfos();
1205 _fillNodeNewInfo(node_uids,node_infos2);
1206
1207 // Launch node and face creation
1209}
1210
1211/*---------------------------------------------------------------------------*/
1212
1213void DynamicMeshIncrementalBuilder::
1214addFaces3(Integer nb_face,Int64ConstArrayView faces_infos,
1215 Integer sub_domain_id,Int32ArrayView faces)
1216{
1217 bool add_to_faces = faces.size()!=0;
1218 if (add_to_faces && nb_face!=faces.size())
1219 throw ArgumentException(A_FUNCINFO,
1220 "return array 'faces' has to have same size as number of faces");
1223 // item info_size cannot be guessed
1229 Integer nb_edge = 0;
1230 Integer nb_node = 0;
1231 std::map<std::pair<Int64,Int64>, Int64> edge_uid_map;
1232
1233 // Fill classical info
1235 _fillNodeInfo(nb_node, nb_face, nodes_infos, faces_infos);
1236
1237 // Face info New
1238 ItemData& face_data = item_data_list.itemData(Integer(m_mesh->faceFamily()->itemKind()),nb_face,0,faces,&mesh()->trueFaceFamily(),&mesh()->trueFaceFamily(),sub_domain_id);
1239 _fillFaceNewInfoNew(nb_face,faces_infos,face_data.itemInfos(),edge_uid_map);
1240
1241 // Edge info New
1242 if (hasEdge()) {
1243 Integer edge_info_size = 1 + nb_edge*6;//New info = Nb_connected_family + for each edge : type, uid, connected_family_kind, nb_node_connected, first_node_uid, second_node_uid
1244 ItemData& edge_data = item_data_list.itemData(Integer(m_mesh->edgeFamily()->itemKind()),nb_edge,edge_info_size,edge_lids,&mesh()->trueEdgeFamily(),&mesh()->trueEdgeFamily(),sub_domain_id);
1245 edge_lids.resize(item_data_list[m_mesh->edgeFamily()->itemKind()].nbItems());
1246 _fillEdgeNewInfoNew(nb_edge,edges_infos,edge_data.itemInfos()); // reprendre fillEdgeInfo et voir l'appel depuis add Edges + attention ordre des noeuds,
1247 ItemData& edge_relation_data = item_relation_data_list.itemData(Integer(m_mesh->edgeFamily()->itemKind()),nb_edge,edge_info_size,edge_lids,&mesh()->trueEdgeFamily(),&mesh()->trueEdgeFamily(),sub_domain_id);
1248 _initEdgeRelationInfo(edge_relation_data,face_data, edges_infos); // edge-face relation
1249 }
1250
1251 // Node info New
1252 Integer node_info_size = 1 + nb_node*2;//New info = Nb_connected_family + for each node : type, uid (no connected family)
1253 ItemData& node_data = item_data_list.itemData(Integer(m_mesh->nodeFamily()->itemKind()),nb_node,node_info_size,node_lids,&mesh()->trueNodeFamily(),&mesh()->trueNodeFamily(),sub_domain_id);
1254 node_lids.resize(item_data_list[m_mesh->nodeFamily()->itemKind()].nbItems());
1255 _fillNodeNewInfo(nodes_infos,node_data.itemInfos());
1256 ItemData& node_relation_data = item_relation_data_list.itemData(Integer(m_mesh->nodeFamily()->itemKind()),nb_node,node_info_size,node_lids,&mesh()->trueNodeFamily(),&mesh()->trueNodeFamily(),sub_domain_id);
1257 _initNodeRelationInfo(node_relation_data,face_data, nodes_infos); // node-face relation
1258
1259
1260 // Launch node, face and edges (not compulsory) creation
1262}
1263
1264/*---------------------------------------------------------------------------*/
1265/*---------------------------------------------------------------------------*/
1266
1267void DynamicMeshIncrementalBuilder::
1268_fillFaceNewInfoNew(Integer nb_face,Int64ConstArrayView faces_infos,Int64Array& face_infos2, const std::map<std::pair<Int64,Int64>, Int64>& edge_uid_map)
1269{
1270 ItemTypeMng* itm = m_item_type_mng;
1271 Integer nb_connected_family = hasEdge() ? 2 : 1;
1272 Integer face_infos2_size_approx = 1 + 2 * (faces_infos.size()+ 2*nb_face); // supposes as many faces as edges...
1273 face_infos2.reserve(face_infos2_size_approx);
1274 Int64UniqueArray work_face_sorted_nodes;
1275 Int64UniqueArray work_face_orig_nodes;
1276 Integer faces_infos_index = 0;
1277// Integer face_infos2_index = 0;
1278 std::set<Int64> node_uids_set;
1279 face_infos2.add(nb_connected_family); // nb_connected_families nodes +/- Edges !!
1280 // Fill face_infos2 from faces_infos
1281 for(Integer i_face=0; i_face<nb_face; ++i_face ){
1282 Integer current_face_type = (Integer)faces_infos[faces_infos_index++];
1283 Integer current_face_uid = (Integer)faces_infos[faces_infos_index++];
1284 face_infos2.add(current_face_type); // type
1285 face_infos2.add(current_face_uid); // uid
1286 //--Node connectivity
1287 face_infos2.add(mesh()->nodeFamily()->itemKind()); // connected_family_id
1288 ItemTypeInfo* it = itm->typeFromId(current_face_type);
1289 Integer current_face_nb_node = it->nbLocalNode();
1290 face_infos2.add(current_face_nb_node); // nb_connected_nodes
1291 // Nodes are not necessarily sorted (if caller is addFaces...)
1292 Int64ConstArrayView current_face_node_uids(current_face_nb_node,&faces_infos[faces_infos_index]);
1293 work_face_orig_nodes.resize(current_face_nb_node);
1294 work_face_sorted_nodes.resize(current_face_nb_node);
1295 work_face_orig_nodes.copy(current_face_node_uids);
1296 mesh_utils::reorderNodesOfFace(work_face_orig_nodes,work_face_sorted_nodes);
1297 face_infos2.addRange(work_face_sorted_nodes); // connected node uids
1298 faces_infos_index += current_face_nb_node;
1299 //--Edge Connectivity
1300 if (hasEdge()){
1301 face_infos2.add(mesh()->edgeFamily()->itemKind());
1302 face_infos2.add(it->nbLocalEdge()); // nb_connected_edges
1303 for (int edge_index = 0; edge_index < it->nbLocalEdge(); ++edge_index) {
1304 Int64 first_node = work_face_sorted_nodes[it->localEdge(edge_index).beginNode()];
1305 Int64 second_node = work_face_sorted_nodes[it->localEdge(edge_index).endNode()];
1306 if (first_node > second_node) std::swap(first_node,second_node); // edge may be oriented negatively in the face
1307 auto edge_it = edge_uid_map.find(std::make_pair(first_node,second_node));
1308 if (edge_it == edge_uid_map.end())
1309 ARCANE_FATAL("Do not find edge with nodes {0}-{1} in edge uid map. Exiting",
1310 work_face_sorted_nodes[it->localEdge(edge_index).beginNode()],
1311 work_face_sorted_nodes[it->localEdge(edge_index).endNode()]);
1312 face_infos2.add(edge_it->second); // connected edge uid
1313 }
1314 }
1315 }
1316}
1317
1318/*---------------------------------------------------------------------------*/
1319
1320void DynamicMeshIncrementalBuilder::
1321_fillFaceInfo2(Integer nb_face,Int64ConstArrayView faces_infos,Int64ArrayView face_infos2, Int64Array& node_uids)
1322{
1323 ItemTypeMng* itm = m_item_type_mng;
1324 Integer faces_infos_index = 0;
1325 Integer face_infos2_index = 0;
1326 face_infos2[face_infos2_index++] = 1; // nb_connected_families (node only)
1327 Int64UniqueArray work_face_sorted_nodes;
1328 Int64UniqueArray work_face_orig_nodes;
1329 std::set<Int64> node_uids_set;
1330 // Fill face_infos2 from faces_infos
1331 for(Integer i_face=0; i_face<nb_face; ++i_face ){
1332
1333 Integer item_type_id = (Integer)faces_infos[faces_infos_index];
1334 face_infos2[face_infos2_index++] = faces_infos[faces_infos_index++]; // type
1335 face_infos2[face_infos2_index++] = faces_infos[faces_infos_index++]; // uid
1336 face_infos2[face_infos2_index++] = mesh()->nodeFamily()->itemKind(); // connected_family_id
1337
1338 ItemTypeInfo* it = itm->typeFromId(item_type_id);
1339 Integer current_face_nb_node = it->nbLocalNode();
1340 face_infos2[face_infos2_index++] = current_face_nb_node; // nb_connected_items
1341 Int64ConstArrayView current_face_node_uids(current_face_nb_node,&faces_infos[faces_infos_index]);
1342 work_face_orig_nodes.resize(current_face_nb_node);
1343 work_face_sorted_nodes.resize(current_face_nb_node);
1344 work_face_orig_nodes.copy(current_face_node_uids);
1345 mesh_utils::reorderNodesOfFace(work_face_orig_nodes,work_face_sorted_nodes);
1346 face_infos2.subView(face_infos2_index,current_face_nb_node).copy(work_face_sorted_nodes); // connected node uids
1347 faces_infos_index += current_face_nb_node;
1348 face_infos2_index += current_face_nb_node;
1349 node_uids_set.insert(current_face_node_uids.begin(),current_face_node_uids.end());
1350 }
1351 node_uids.resize(node_uids_set.size());
1352 Integer index = 0;
1353 for (Int64 node_uid : node_uids_set) node_uids[index++] = node_uid;
1354}
1355
1356/*---------------------------------------------------------------------------*/
1357/*---------------------------------------------------------------------------*/
1368 Integer sub_domain_id,Int32ArrayView edges)
1369{
1370 bool add_to_edges = edges.size()!=0;
1371 if (add_to_edges && nb_edge!=edges.size())
1372 throw ArgumentException(A_FUNCINFO,
1373 "return array 'edges' has to have same size as number of edges");
1374
1375 Integer edge_info_index = 0;
1376 for(Integer i_edge=0; i_edge<nb_edge; ++i_edge ){
1377
1380
1382 edge_info_index += 2;
1383
1385
1386 if (add_to_edges)
1387 edges[i_edge] = edge->localId();
1388 }
1389}
1390
1391/*---------------------------------------------------------------------------*/
1392/*---------------------------------------------------------------------------*/
1403 Integer sub_domain_id,Int32ArrayView edges)
1404{
1405 bool add_to_edges = edges.size()!=0;
1406 if (add_to_edges && nb_edge!=edges.size())
1407 throw ArgumentException(A_FUNCINFO,
1408 "return array 'edges' has to have same size as number of edges");
1409
1410 // Prepare face infos 2
1411 Integer edge_infos2_size = edge_infos.size()+ 1 + 2 * nb_edge; // additive info nb_connected_family + nb_face * (family_id + nb_connected_element)
1413 ItemData& edge_data = item_info_list.itemData(Integer(m_mesh->edgeFamily()->itemKind()),
1414 nb_edge,edge_infos2_size,edges,&mesh()->trueEdgeFamily(),&mesh()->trueEdgeFamily(),sub_domain_id);
1415
1416 Int64ArrayView edge_infos2 = edge_data.itemInfos().view();
1418
1419 _fillEdgeInfo2(nb_edge,edge_infos,edge_infos2,node_uids);
1420
1421 // Prepare node data (mutualize)
1422 Integer nb_node_to_add = node_uids.size();
1424 ItemData& node_data = item_info_list.itemData(Integer(m_mesh->nodeFamily()->itemKind()),
1425 nb_node_to_add,2*nb_node_to_add+1,node_lids,&mesh()->trueNodeFamily(),&mesh()->trueNodeFamily(),sub_domain_id);
1426 Int64Array& node_infos2 = node_data.itemInfos();
1427 _fillNodeNewInfo(node_uids,node_infos2);
1428
1429 // Launch node and face creation
1431}
1432
1433void DynamicMeshIncrementalBuilder::
1434addEdges3(Integer nb_edge,Int64ConstArrayView edges_infos,
1435 Integer sub_domain_id,Int32ArrayView edges)
1436{
1437 bool add_to_edges = edges.size()!=0;
1438 if (add_to_edges && nb_edge!=edges.size())
1439 throw ArgumentException(A_FUNCINFO,
1440 "return array 'edges' has to have same size as number of edges");
1443 // item info_size cannot be guessed
1446 Integer nb_node = 0;
1447
1448 // Fill classical info
1449 _fillNodeInfoFromEdge(nb_node, nb_edge, nodes_infos, edges_infos);
1450
1451 // Edge new info : edge data stores edge uids and dependency connectivities
1452 ItemData& edge_data = item_data_list.itemData(Integer(m_mesh->edgeFamily()->itemKind()),nb_edge,0,edges,&mesh()->trueEdgeFamily(),&mesh()->trueEdgeFamily(),sub_domain_id);
1453 _fillEdgeNewInfoNew(nb_edge,edges_infos,edge_data.itemInfos());
1454
1455
1456 // Node new info & relationsm
1457 ItemData& node_data = item_data_list.itemData(Integer(m_mesh->nodeFamily()->itemKind()),nb_node,0,node_lids,&mesh()->trueNodeFamily(),&mesh()->trueNodeFamily(),sub_domain_id);
1458 node_lids.resize(nb_node);
1459 _fillNodeNewInfo(nodes_infos,node_data.itemInfos());
1460 ItemData& node_relations_data = item_relation_data_list.itemData(Integer(m_mesh->nodeFamily()->itemKind()),nb_node,0,node_lids,&mesh()->trueNodeFamily(),&mesh()->trueNodeFamily(),sub_domain_id);
1461 _initNodeRelationInfo(node_relations_data,edge_data, nodes_infos); // node-edge relation
1462
1463
1464 // Launch node and edges creation
1466
1467}
1468
1469/*---------------------------------------------------------------------------*/
1470/*---------------------------------------------------------------------------*/
1471
1472void DynamicMeshIncrementalBuilder::
1474{
1475 Integer edges_infos_index = 0;
1476 Integer edge_infos2_index = 0;
1477 std::set<Int64> node_uids_set;
1478
1479 // Fill edge_infos2 from edges_infos
1480 edge_infos2[edge_infos2_index++] = 1; // nb_connected_families (node only)
1481
1482 for(Integer i_edge=0; i_edge<nb_edge; ++i_edge ){
1483 edge_infos2[edge_infos2_index++] = IT_Line2; // type
1485 edge_infos2[edge_infos2_index++] = mesh()->nodeFamily()->itemKind(); // connected_family_id
1486 edge_infos2[edge_infos2_index++] = 2; // nb_connected_items Attention : ordre des noeuds !! TODO
1487 edge_infos2[edge_infos2_index++] = edges_infos[edges_infos_index]; // first connected node uid
1489 edge_infos2[edge_infos2_index++] = edges_infos[edges_infos_index]; // second connected node uid
1491 }
1492 node_uids.resize(node_uids_set.size());
1493 Integer index = 0;
1494 for (Int64 node_uid : node_uids_set) node_uids[index++] = node_uid;
1495}
1496
1497void DynamicMeshIncrementalBuilder::
1498_fillEdgeNewInfoNew(Integer nb_edge,Int64ConstArrayView edges_infos,Int64ArrayView edges_new_infos)
1499{
1500 Integer edges_infos_index = 0;
1501 Integer edges_new_infos_index = 0;
1502
1503 // Fill edge_infos2 from edges_infos
1504 edges_new_infos[edges_new_infos_index++] = 1; // nb_connected_families (node only)
1505
1506 for(Integer i_edge=0; i_edge<nb_edge; ++i_edge ){
1507 edges_new_infos[edges_new_infos_index++] = IT_Line2; // type
1508 edges_new_infos[edges_new_infos_index++] = edges_infos[edges_infos_index++]; // uid
1509 edges_new_infos[edges_new_infos_index++] = mesh()->nodeFamily()->itemKind(); // connected_family_id
1510 edges_new_infos[edges_new_infos_index++] = 2; // nb_connected_items
1511 Int64 first_node = edges_infos[edges_infos_index++];
1512 Int64 second_node = edges_infos[edges_infos_index++];
1513 if (first_node > second_node) std::swap(first_node,second_node);
1514 edges_new_infos[edges_new_infos_index++] = first_node; // first connected node uid
1515 edges_new_infos[edges_new_infos_index++] = second_node; // second connected node uid
1516 }
1517}
1518
1519/*---------------------------------------------------------------------------*/
1520/*---------------------------------------------------------------------------*/
1521
1522void DynamicMeshIncrementalBuilder::
1523readFromDump()
1524{
1525 // Recalcul le max uniqueId() des faces pour savoir quelle valeur
1526 // utiliser en cas de creation de face.
1527 ItemInternalMap& faces_map = m_mesh->facesMap();
1528 Int64 max_uid = 0;
1529 faces_map.eachItem([&](Item face) {
1530 if (face.uniqueId() > max_uid)
1531 max_uid = face.uniqueId();
1532 });
1533 m_one_mesh_item_adder->setNextFaceUid(max_uid + 1);
1534
1535 if (m_has_edge) {
1536 ItemInternalMap& edges_map = m_mesh->edgesMap();
1537 Int64 max_uid = 0;
1538 edges_map.eachItem([&](Item edge) {
1539 if (edge.uniqueId() > max_uid)
1540 max_uid = edge.uniqueId();
1541 });
1542 m_one_mesh_item_adder->setNextEdgeUid(max_uid + 1);
1543 }
1544
1545 info(5) << "NEXT FACE UID mesh=" << m_mesh->name() << " Next=" << m_one_mesh_item_adder->nextFaceUid();
1546 info(5) << "NEXT EDGE UID mesh=" << m_mesh->name() << " Next=" << m_one_mesh_item_adder->nextEdgeUid();
1547}
1548
1549/*---------------------------------------------------------------------------*/
1550/*---------------------------------------------------------------------------*/
1551
1552void DynamicMeshIncrementalBuilder::
1553printInfos()
1554{
1555 info() << "-- Mesh information (Arcane2):";
1556 info() << "Number of nodes " << m_one_mesh_item_adder->nbNode();
1557 info() << "Number of edges " << m_one_mesh_item_adder->nbEdge();
1558 info() << "Number of faces " << m_one_mesh_item_adder->nbFace();
1559 info() << "Number of cells " << m_one_mesh_item_adder->nbCell();
1560 info() << "-- Graph information (Arcane2):";
1561}
1562
1563/*---------------------------------------------------------------------------*/
1564/*---------------------------------------------------------------------------*/
1565
1566void DynamicMeshIncrementalBuilder::
1567printStats(Int32 level)
1568{
1569 info(level) << "-- -- Statistics";
1570 info(level) << "Number of nodes after addition &: " << m_one_mesh_item_adder->nbNode()
1571 << " hashmap=" << m_mesh->nodesMap().count();
1572 info(level) << "Number of edges after addition : " << m_one_mesh_item_adder->nbEdge()
1573 << " hashmap=" << m_mesh->edgesMap().count();
1574 info(level) << "Number of faces after addition : " << m_one_mesh_item_adder->nbFace()
1575 << " hashmap=" << m_mesh->facesMap().count();
1576 info(level) << "Number of cells after addition : " << m_one_mesh_item_adder->nbCell()
1577 << " hashmap=" << m_mesh->cellsMap().count();
1578 info(level) << "--";
1579}
1580
1581/*---------------------------------------------------------------------------*/
1582/*---------------------------------------------------------------------------*/
1606{
1607 if (!m_face_unique_id_builder)
1608 m_face_unique_id_builder = new FaceUniqueIdBuilder(this);
1609 m_face_unique_id_builder->computeFacesUniqueIds();
1610
1611 if (m_has_edge) {
1612 if (!m_edge_unique_id_builder)
1613 m_edge_unique_id_builder = new EdgeUniqueIdBuilder(this);
1614 m_edge_unique_id_builder->computeEdgesUniqueIds();
1615 }
1616}
1617
1618/*---------------------------------------------------------------------------*/
1619/*---------------------------------------------------------------------------*/
1620
1621void DynamicMeshIncrementalBuilder::
1622addGhostLayers(bool is_allocate)
1623{
1624 debug() << "Add one ghost layer";
1627 m_ghost_layer_builder->addGhostLayers(is_allocate);
1628}
1629
1630/*---------------------------------------------------------------------------*/
1631/*---------------------------------------------------------------------------*/
1632
1642
1643/*---------------------------------------------------------------------------*/
1644/*---------------------------------------------------------------------------*/
1645
1646void DynamicMeshIncrementalBuilder::
1647_removeNeedRemoveMarkedItems(ItemInternalMap& map, UniqueArray<Int32>& items_local_id)
1648{
1649 // Suppression des liaisons
1651 items_to_remove.reserve(1000);
1652
1653 map.eachItem([&](Item item) {
1655 Integer f = mb_item.flags();
1656 if (f & ItemFlags::II_NeedRemove){
1657 f &= ~ItemFlags::II_NeedRemove;
1658 mb_item.setFlags(f);
1659 items_local_id.add(item.localId());
1660 }
1661 });
1662}
1663
1664/*---------------------------------------------------------------------------*/
1665/*---------------------------------------------------------------------------*/
1666
1677{
1679 {
1680
1681 IItemFamily* links_family = m_mesh->findItemFamily(IK_DoF, GraphDoFs::linkFamilyName(), false, false);
1682 if(links_family)
1683 {
1684 info() << "Remove Items for family : "<<links_family->name() ;
1685 links_family->removeNeedRemoveMarkedItems() ;
1686 }
1687
1688 for( IItemFamily* family : m_mesh->itemFamilies() )
1689 {
1690 if (family->itemKind()!=IK_DoF || family->name()==GraphDoFs::linkFamilyName())
1691 continue;
1692 info() << "Remove Items for family : "<<family->name() ;
1693 family->removeNeedRemoveMarkedItems() ;
1694 }
1695 // Supression des particules de la famille Particle
1696
1697 for( IItemFamilyCollection::Enumerator i(m_mesh->itemFamilies()); ++i; ){
1698 IItemFamily* family = *i;
1699 if (family->itemKind()==IK_Particle){
1700 ParticleFamily* particle_family = dynamic_cast<ParticleFamily*>(family) ;
1702 if(particle_family && particle_family->getEnableGhostItems()==true){
1704 lids_to_remove.reserve(1000);
1705
1707 particle_map.eachItem([&](Item item) {
1709 Integer f = mb_item.flags();
1710 if (f & ItemFlags::II_NeedRemove){
1711 f &= ~ItemFlags::II_NeedRemove;
1712 mb_item.setFlags(f);
1713 lids_to_remove.add(item.localId());
1714 }
1715 });
1716
1717 info() << "Number of particles of family "<<family->name()<<" to remove: " << lids_to_remove.size();
1718 if(lids_to_remove.size()>0)
1719 particle_family->removeParticles(lids_to_remove) ;
1720 }
1721 }
1722 }
1723
1724 // Suppression des mailles
1725 CellFamily& cell_family = m_mesh->trueCellFamily();
1727 cells_to_remove.reserve(1000);
1728 _removeNeedRemoveMarkedItems(cell_family.itemsMap(), cells_to_remove);
1729
1730 info() << "Number of cells to remove: " << cells_to_remove.size();
1731
1732#ifdef ARCANE_DEBUG_DYNAMIC_MESH
1733 for( Integer i=0, is=cells_to_remove.size(); i<is; ++i )
1734 info() << "remove cell with uid=" << cells_to_remove[i]->uniqueId()
1735 << ",lid=" << cells_to_remove[i]->localId()
1736 << ",owner=" << cells_to_remove[i]->owner();
1737#endif /* ARCANE_DEBUG_DYNAMIC_MESH */
1738
1739 cell_family.removeCells(cells_to_remove);
1740 }
1741 // With ItemFamilyNetwork
1742 else
1743 {
1744 // handle families already in the network
1747 // Remove items from family graph leaves to root
1748 }, IItemFamilyNetwork::InverseTopologicalOrder);
1749 for (auto family : m_mesh->itemFamilies()) {
1750 // handle remaining families (particles, links, dual nodes & dof).
1751 // Will have no effect on the families already handled in the graph (since NeedRemove flag is reset)
1753 }
1754 }
1755}
1756
1757/*---------------------------------------------------------------------------*/
1758/*---------------------------------------------------------------------------*/
1759
1761setConnectivity(const Integer connectivity)
1762{
1763 if (connectivity == 0)
1764 ARCANE_FATAL("Undefined connectivity !");
1765 if (m_connectivity != 0)
1766 ARCANE_FATAL("Connectivity already set: cannot redefine it");
1767 m_connectivity = connectivity;
1768 m_has_edge = Connectivity::hasConnectivity(connectivity,Connectivity::CT_HasEdge);
1769}
1770
1771/*---------------------------------------------------------------------------*/
1772/*---------------------------------------------------------------------------*/
1773
1781
1782/*---------------------------------------------------------------------------*/
1783/*---------------------------------------------------------------------------*/
1784
1785} // End namespace Arcane::mesh
1786
1787/*---------------------------------------------------------------------------*/
1788/*---------------------------------------------------------------------------*/
#define ARCANE_CHECK_POINTER(ptr)
Macro retournant le pointeur ptr s'il est non nul ou lancant une exception s'il est nul.
#define ARCANE_THROW(exception_class,...)
Macro pour envoyer une exception avec formattage.
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Fonctions utilitaires sur le maillage.
Tableau d'items de types quelconques.
Maille d'un maillage.
Definition Item.h:1178
Face d'une maille.
Definition Item.h:932
virtual void schedule(IItemFamilyNetworkTask task, eSchedulingOrder order=TopologicalOrder)=0
Ordonnance l'exécution d'une tâche, dans l'ordre topologique ou topologique inverse du graphe de dépe...
Interface d'une famille d'entités.
virtual void removeNeedRemoveMarkedItems()=0
Supprime des entités et met a jour les connectivites.
virtual String name() const =0
Nom de la famille.
virtual eItemKind itemKind() const =0
Genre des entités.
Int32 localId() const
Numéro local (au sous-domaine) de l'entité
Flags pour les caractéristiques des entités.
Definition ItemFlags.h:31
@ II_NeedRemove
L'entité doit être supprimé
Definition ItemFlags.h:55
Structure interne d'une entité de maillage.
Type d'une entité (Item).
Definition ItemTypeId.h:32
Infos sur un type d'entité du maillage.
Gestionnaire des types d'entités de maillage.
Definition ItemTypeMng.h:66
Vue sur un vecteur d'entités.
Int32 size() const
Nombre d'éléments du vecteur.
Classe de base d'un élément de maillage.
Definition Item.h:83
impl::MutableItemBase mutableItemBase() const
Partie interne modifiable de l'entité.
Definition Item.h:365
constexpr Int32 localId() const
Identifiant local de l'entité dans le sous-domaine du processeur.
Definition Item.h:210
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Méthodes permettant de modifier ItemBase.
Famille de mailles.
Definition CellFamily.h:46
ItemInternal * addFace(Int64 a_face_uid, Int64ConstArrayView a_node_list, Integer a_type)
Ajoute une face.
void addNodes2(Int64ConstArrayView nodes_uid, Integer sub_domain_id, Int32ArrayView nodes)
Ajoute des noeuds au maillage actuel. Utilise l'ajout d'item générique basé sur dépendances entre fam...
void computeFacesUniqueIds()
Calcul les numéros uniques de chaque face.
void setConnectivity(Integer c)
Définit la connectivité active pour le maillage associé
void addParentCells(const ItemVectorView &items)
Ajout au maillage courant d'item venant d'un maillage parent.
void addCells(Integer nb_cell, Int64ConstArrayView cell_infos, Integer sub_domain_id, Int32ArrayView cells, bool allow_build_face=true)
Ajoute des mailles au maillage actuel.
void addParentItems(const ItemVectorView &items, const eItemKind submesh_kind)
Ajout au maillage courant d'item venant d'un maillage parent.
OneMeshItemAdder * m_one_mesh_item_adder
Outils de construction du maillage.
Int64 m_face_uid_pool
Numéro du uniqueId() utilisé pour générer les faces.
void resetAfterDeallocate()
Remise à zéro des structures pour pouvoir faire à nouveau une allocation.
void addGhostChildFromParent(Array< Int64 > &ghost_cell_to_refine)
AMR.
void addEdges2(Integer nb_edge, Int64ConstArrayView edge_infos, Integer sub_domain_id, Int32ArrayView edges)
Ajoute des arêtes au maillage actuel. Utilise l'ajout d'item générique basé sur dépendances entre fam...
Int64 m_edge_uid_pool
Numéro du uniqueId() utilisé pour générer les edges.
void addItems(ItemDataList &item_info_list)
Ajout générique d'items d'un ensemble de famille pour lesquelles on fournit un ItemData.
void addNodes(Int64ConstArrayView nodes_uid, Integer sub_domain_id, Int32ArrayView nodes)
Ajoute des noeuds au maillage actuel.
void addFaces(Integer nb_face, Int64ConstArrayView face_infos, Integer sub_domain_id, Int32ArrayView faces)
Ajoute des faces au maillage actuel.
void addEdges(Integer nb_edge, Int64ConstArrayView edge_infos, Integer sub_domain_id, Int32ArrayView edges)
Ajoute des arêtes au maillage actuel.
GhostLayerBuilder * m_ghost_layer_builder
Outil pour construire les éléments fantômes.
void addHChildrenCells(Cell hParent_cell, Integer nb_cell, Int64ConstArrayView cells_infos, Int32 sub_domain_id, Int32ArrayView cells, bool allow_build_face)
Ajoute des mailles au maillage actuel.
bool m_has_edge
Info sur la présence d'arête (accèlere l'accès à la connectivité générale)
void addFamilyItems(ItemData &item_info)
Ajout générique d'items d'une famille, décrite par son ItemInfo.
DynamicMeshIncrementalBuilder(DynamicMesh *mesh)
Construit une instance pour le maillage mesh.
void removeNeedRemoveMarkedItems()
Supprime les items fantômes.
void addCells3(Integer nb_cell, Int64ConstArrayView cell_infos, Integer sub_domain_id, Int32ArrayView cells, bool allow_build_face=true)
Ajoute des mailles au maillage actuel. Utilise l'ajout d'item générique basé sur dépendances entre fa...
void addFaces2(Integer nb_face, Int64ConstArrayView face_infos, Integer sub_domain_id, Int32ArrayView faces)
Ajoute des faces au maillage actuel. Utilise l'ajout d'item générique basé sur dépendances entre fami...
Integer m_connectivity
Info de connectivité du maillage courant.
Implémentation d'un maillage.
Definition DynamicMesh.h:97
bool useMeshItemFamilyDependencies() const override
check if the network itemFamily dependencies is activated
IItemFamily * nodeFamily() override
Retourne la famille des noeuds.
IItemFamily * cellFamily() override
Retourne la famille des mailles.
String name() const override
Nom du maillage.
IItemFamily * faceFamily() override
Retourne la famille des faces.
IItemFamily * findItemFamily(eItemKind ik, const String &name, bool create_if_needed, bool register_modifier_if_created) override
Retourne la famille de nom name.
IItemFamilyNetwork * itemFamilyNetwork() override
Interface du réseau de familles (familles connectées)
IItemFamily * edgeFamily() override
Retourne la famille des arêtes.
Construction des couches fantômes.
Construction des couches fantômes.
Construction des couches fantômes.
Tableau associatif de ItemInternal.
Int32 count() const
Nombre d'éléments de la table.
ItemInternal * addOneCell(ItemTypeId type_id, Int64 cell_uid, Int32 sub_domain_id, Int64ConstArrayView nodes_uid, bool allow_build_face)
Ajoute une maille.
void resetAfterDeallocate()
Remise à zéro des structures pour pouvoir faire à nouveau une allocation.
ItemInternal * addOneParentItem(const Item &item, const eItemKind submesh_kind, const bool fatal_on_existing_item=true)
Ajoute d'un item parent.
ItemInternal * addOneFace(Int64 a_face_uid, Int64ConstArrayView a_node_list, Integer a_type)
Ajoute une face.
Famille de particules.
Exception lorsqu'un argument est invalide.
Vue modifiable d'un tableau d'un type T.
constexpr Integer size() const noexcept
Retourne la taille du tableau.
void reserve(Int64 new_capacity)
Réserve le mémoire pour new_capacity éléments.
Vue constante d'un tableau de type T.
Chaîne de caractères unicode.
TraceMessageDbg debug(Trace::eDebugLevel=Trace::Medium) const
Flot pour un message de debug.
TraceMessage info() const
Flot pour un message d'information.
Vecteur 1D de données avec sémantique par valeur (style STL).
Integer toInteger(Real r)
Converti un Int64 en un Integer.
Int32 toInt32(Int64 v)
Converti un Int64 en un Int32.
Array< Int64 > Int64Array
Tableau dynamique à une dimension d'entiers 64 bits.
Definition UtilsTypes.h:325
UniqueArray< Int64 > Int64UniqueArray
Tableau dynamique à une dimension d'entiers 64 bits.
Definition UtilsTypes.h:513
ArrayView< Int64 > Int64ArrayView
Equivalent C d'un tableau à une dimension d'entiers 64 bits.
Definition UtilsTypes.h:609
eItemKind
Genre d'entité de maillage.
@ IK_Particle
Entité de maillage de genre particule.
@ IK_Cell
Entité de maillage de genre maille.
@ IK_Face
Entité de maillage de genre face.
@ IK_DoF
Entité de maillage de genre degre de liberte.
@ IK_Edge
Entité de maillage de genre arête.
ConstArrayView< Int64 > Int64ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 64 bits.
Definition UtilsTypes.h:638
Int32 Integer
Type représentant un entier.