14#include "arcane/utils/Real3.h"
15#include "arcane/utils/ITraceMng.h"
17#include "arcane/core/IMesh.h"
18#include "arcane/core/SharedVariable.h"
19#include "arcane/core/IParallelMng.h"
21#include "arcane/mesh/DynamicMesh.h"
22#include "arcane/mesh/MapCoordToUid.h"
37const Real MapCoordToUid::TOLERANCE = 1.e-6;
43 const unsigned int chunkmax = 1024;
44 const unsigned long chunkmax2 = 1048576;
45 const Real chunkfloat = 1024.0;
48#ifdef ACTIVATE_PERF_COUNTER
49const std::string MapCoordToUid::PerfCounter::m_names[] =
66 m_lower_bound = std::numeric_limits<Real>::max();
67 m_upper_bound = -std::numeric_limits<Real>::max();
73void MapCoordToUid::Box::
76 m_lower_bound = std::numeric_limits<Real>::max();
77 m_upper_bound = -std::numeric_limits<Real>::max();
82 m_lower_bound[0] = std::min(m_lower_bound[0],nodes_coords[i_item].x);
83 m_lower_bound[1] = std::min(m_lower_bound[1],nodes_coords[i_item].y);
84 m_lower_bound[2] = std::min(m_lower_bound[2],nodes_coords[i_item].z);
85 m_upper_bound[0] = std::max(m_upper_bound[0],nodes_coords[i_item].x);
86 m_upper_bound[1] = std::max(m_upper_bound[1],nodes_coords[i_item].y);
87 m_upper_bound[2] = std::max(m_upper_bound[2],nodes_coords[i_item].z);
90 if (mesh->parallelMng()->isParallel()){
91 mesh->parallelMng()->reduce(Parallel::ReduceMin,m_lower_bound);
92 mesh->parallelMng()->reduce(Parallel::ReduceMax,m_upper_bound);
94 m_size = m_upper_bound - m_lower_bound;
100void MapCoordToUid::Box::
104 m_lower_bound = std::numeric_limits<Real>::max();
105 m_upper_bound = -std::numeric_limits<Real>::max();
109 ItemInternalMap& nodes_map = dmesh->nodesMap();
111 nodes_map.eachItem([&](Node node) {
112 Int64 uid = node.uniqueId().asInt64();
113 if(uid == NULL_ITEM_ID)
115 m_lower_bound[0] = std::min(m_lower_bound[0],nodes_coords[node].x);
116 m_lower_bound[1] = std::min(m_lower_bound[1],nodes_coords[node].y);
117 m_lower_bound[2] = std::min(m_lower_bound[2],nodes_coords[node].z);
118 m_upper_bound[0] = std::max(m_upper_bound[0],nodes_coords[node].x);
119 m_upper_bound[1] = std::max(m_upper_bound[1],nodes_coords[node].y);
120 m_upper_bound[2] = std::max(m_upper_bound[2],nodes_coords[node].z);
123 if (mesh->parallelMng()->isParallel()) {
124 mesh->parallelMng()->reduce(Parallel::ReduceMin,m_lower_bound);
125 mesh->parallelMng()->reduce(Parallel::ReduceMax,m_upper_bound);
127 m_size = m_upper_bound - m_lower_bound ;
134MapCoordToUid(IMesh* mesh)
137, m_nodes_coords(mesh->nodesCoordinates())
139#ifdef ACTIVATE_PERF_COUNTER
140 m_perf_counter.init() ;
147void NodeMapCoordToUid::
157void FaceMapCoordToUid::
168void NodeMapCoordToUid::
179bool NodeMapCoordToUid::
180isItemToSuppress(Node node,
const Int64 parent_uid)
const
182 for( Cell cell : node.cells() )
183 if (cell.isActive() || cell.uniqueId()==parent_uid)
191void FaceMapCoordToUid::
201Real3 FaceMapCoordToUid::
202faceCenter(Face face)
const
204 Real3 pfc = Real3::null();
205 for( Node node : face.nodes() )
206 pfc += m_nodes_coords[node];
207 pfc /=
static_cast<Real> (face.nbNode());
214bool FaceMapCoordToUid::
215isItemToSuppress(Face face)
const
217 if (face.nbCell()==1)
218 return ! face.cell(0).isActive() ;
220 Cell cell0 = face.cell(0);
221 Cell cell1 = face.cell(1);
222 Integer level0 = cell0.level();
223 Integer level1 = cell1.level();
225 return ! (cell0.isActive() || cell1.isActive()) ;
227 return ! cell0.isActive() ;
229 return ! cell1.isActive() ;
239 CHECKPERF( m_perf_counter.start(PerfCounter::Clear) )
241 for(map_type::iterator iter = m_map.begin();iter != m_map.end();++iter){
242 iter->second.second = NULL_ITEM_ID ;
244 CHECKPERF( m_perf_counter.stop(PerfCounter::Clear) )
250void NodeMapCoordToUid::
251clearData(ArrayView<ItemInternal*> coarsen_cells)
253 typedef std::set<Int64> set_type;
254 typedef std::pair<set_type::iterator,bool> insert_return_type;
256 for (Integer icell = 0; icell < coarsen_cells.size(); icell++){
257 Cell parent(coarsen_cells[icell]);
258 for (UInt32 i = 0, nc = parent.nbHChildren(); i < nc; i++){
259 Cell child = parent.hChild(i);
260 for( Node node : child.nodes() ){
261 Int64 uid = node.uniqueId() ;
262 insert_return_type value = node_list.insert(uid) ;
264 if(isItemToSuppress(node, parent.uniqueId())){
265 m_mesh->traceMng()->debug(
Trace::Highest)<<
"SUPPRESS NODE : "<<uid<<
" "<<m_nodes_coords[node] ;
266 erase(m_nodes_coords[node]) ;
279void FaceMapCoordToUid::
280clearData(ArrayView<ItemInternal*> coarsen_cells)
282 typedef std::set<Int64> set_type;
283 typedef std::pair<set_type::iterator,bool> insert_return_type;
285 for(Integer icell=0;icell<coarsen_cells.size();++icell){
286 Cell cell(coarsen_cells[icell]);
287 for (UInt32 i = 0, nc = cell.nbHChildren(); i < nc; i++){
288 Cell child = cell.hChild(i) ;
289 for( Face face : child.faces() ){
290 Int64 uid = face.uniqueId() ;
291 insert_return_type value = face_list.insert(uid) ;
297 if(isItemToSuppress(face)){
300 erase(m_face_center[face]) ;
311void NodeMapCoordToUid::
312updateData(ArrayView<ItemInternal*> refine_cells)
314 typedef std::set<Int64> set_type;
315 typedef std::pair<set_type::iterator,bool> insert_return_type;
317 std::size_t count = 0;
318 for (Integer icell = 0; icell < refine_cells.size(); icell++){
319 Cell parent=refine_cells[icell];
320 for (UInt32 i = 0, nc = parent.nbHChildren(); i < nc; i++){
321 Cell child = parent.hChild(i) ;
322 for( Node node : child.nodes() ){
323 Int64 uid = node.uniqueId() ;
324 insert_return_type value = node_list.insert(uid) ;
326 bool is_new = insert(m_nodes_coords[node],uid) ;
328 m_mesh->traceMng()->debug(
Trace::Highest)<<
"INSERT NODE : "<<uid<<
" "<<m_nodes_coords[node] ;
335 m_mesh->traceMng()->debug(
Trace::Highest)<<
"NUMBER OF ADDED NODES : "<<count ;
342void FaceMapCoordToUid::
343updateData(ArrayView<ItemInternal*> refine_cells)
345 typedef std::set<Int64> set_type;
346 typedef std::pair<set_type::iterator,bool> insert_return_type;
348 for(Integer icell=0;icell<refine_cells.size();++icell){
349 Cell cell = refine_cells[icell] ;
350 for (UInt32 i = 0, nc = cell.nbHChildren(); i < nc; i++){
351 Cell child = cell.hChild(i) ;
352 for( Face face : child.faces() ){
353 Int64 uid = face.uniqueId() ;
354 insert_return_type value = face_list.insert(uid);
356 Real3 fc = faceCenter(face);
357 m_face_center[face] = fc;
369insert(
const Real3 p,
const Int64 uid,
Real tol)
371 CHECKPERF( m_perf_counter.start(PerfCounter::Insert) )
373 Int64 pointkey = this->key(p);
376 std::pair<map_type::iterator,map_type::iterator>
377 pos = m_map.equal_range(pointkey);
378 map_type::iterator iter = pos.first ;
379 while (iter != pos.second){
380 if ( areClose(p,iter->second.first,tol)){
381 Int64 old_uid = iter->second.second;
382 iter->second.second = uid ;
383 CHECKPERF( m_perf_counter.stop(PerfCounter::Insert) )
390 for (
int xoffset = -1; xoffset != 2; ++xoffset)
391 for (
int yoffset = -1; yoffset != 2; ++yoffset)
392 for (
int zoffset = -1; zoffset != 2; ++zoffset) {
393 std::pair<map_type::iterator,map_type::iterator>
394 pos2 = m_map.equal_range(pointkey +
398 map_type::iterator iter2 = pos2.first ;
399 while (iter2 != pos2.second){
400 if ( areClose(p,iter2->second.first,tol)){
401 Int64 old_uid = iter2->second.second ;
402 iter2->second.second = uid ;
403 CHECKPERF( m_perf_counter.stop(PerfCounter::Insert) )
410 m_map.insert(pos.first,std::make_pair(pointkey, std::make_pair(p,uid)));
411 CHECKPERF( m_perf_counter.stop(PerfCounter::Insert) )
412 return NULL_ITEM_ID ;
419find(
const Real3 p,
const Real tol)
421 CHECKPERF( m_perf_counter.start(PerfCounter::Find) )
424 Int64 pointkey = this->key(p);
427 std::pair<map_type::iterator,map_type::iterator>
428 pos = m_map.equal_range(pointkey);
430 while (pos.first != pos.second)
431 if ( areClose(p,pos.first->second.first,tol)){
433 return pos.first->second.second;
439 for (
int xoffset = -1; xoffset != 2; ++xoffset)
440 for (
int yoffset = -1; yoffset != 2; ++yoffset)
441 for (
int zoffset = -1; zoffset != 2; ++zoffset){
442 std::pair<map_type::iterator,map_type::iterator>
443 pos = m_map.equal_range(pointkey +
447 while (pos.first != pos.second){
448 if ( areClose(p,pos.first->second.first,tol)){
449 return pos.first->second.second;
456 CHECKPERF( m_perf_counter.stop(PerfCounter::Find) )
464erase(
const Real3 p,
const Real tol)
468 insert(p,NULL_ITEM_ID);
477 CHECKPERF( m_perf_counter.start(PerfCounter::Key) )
478 Real xscaled = (p.x - m_box->m_lower_bound.x) / (m_box->m_size.x),
479 yscaled = (p.y - m_box->m_lower_bound.y) / (m_box->m_size.y),
480 zscaled = (m_box->m_upper_bound.z != m_box->m_lower_bound.z)
481 ? ((p.z - m_box->m_lower_bound.z)/(m_box->m_size.z)) : p.z;
482#ifndef NO_USER_WARNING
483#warning [MapCoordToUid::key] 2D m_box->m_upper_bound.z==m_box->m_lower_bound.z
485 Int64 n0 =
static_cast<Int64> (chunkfloat * xscaled),
486 n1 =
static_cast<Int64> (chunkfloat * yscaled),
487 n2 =
static_cast<Int64> (chunkfloat * zscaled);
489 CHECKPERF( m_perf_counter.stop(PerfCounter::Key) )
490 return chunkmax2*n0 + chunkmax*n1 + n2;
496void NodeMapCoordToUid::
500 CHECKPERF( m_perf_counter.start(PerfCounter::Fill) )
501 m_mesh->traceMng()->debug(
Trace::Highest)<<
"[MapCoordToUid::fill] nb allNodes="<<m_mesh->allNodes().size();
504 Int64 uid = node.uniqueId().asInt64();
505 this->insert(m_nodes_coords[i_item],uid);
507 CHECKPERF( m_perf_counter.stop(PerfCounter::Fill) )
513void NodeMapCoordToUid::
516 m_mesh->traceMng()->debug(
Trace::Highest)<<
"[NODE MapCoordToUid::fill] nb allNodes="<<m_mesh->allNodes().size();
521 Int64 uid = node.uniqueId().asInt64();
522 m_mesh->traceMng()->debug(
Trace::Highest)<<
"\t[NODE MapCoordToUid::fill] node_"<<node.localId()<<
", uid="<<uid<<
" "<<m_nodes_coords[i_item];
523 Int64 map_uid = find(m_nodes_coords[i_item]);
526 m_mesh->traceMng()->error()<<
"MAP NODE ERROR : uid = "<<uid<<
" coords="<<m_nodes_coords[i_item];
527 m_mesh->traceMng()->fatal()<<
"MAP NODE ERROR : "<<map_uid<<
" found, expected uid "<<uid;
532 for(map_type::iterator iter = m_map.begin();iter!=m_map.end();++iter)
533 if(iter->second.second!=NULL_ITEM_ID){
535 if(set.find(iter->second.second)==set.end()){
536 m_mesh->traceMng()->fatal()<<
"MAP NODE ERROR : node "<<iter->second.second<<
" "<<iter->second.first<<
" does not exist";
539 if(count !=m_mesh->allNodes().size())
540 m_mesh->traceMng()->fatal()<<
"MAP NODE ERROR : map size"<<count<<
" != "<<m_mesh->allNodes().size();
547void FaceMapCoordToUid::
550 CHECKPERF( m_perf_counter.start(PerfCounter::Fill) )
551 m_mesh->traceMng()->debug(
Trace::Highest)<<
"[MapCoordToUid::fill] nb allFaces="<<m_mesh->allFaces().size();
553 this->insert(m_face_center[iface],iface->uniqueId());
555 CHECKPERF( m_perf_counter.stop(PerfCounter::Fill) )
561void FaceMapCoordToUid::
564 m_mesh->traceMng()->debug(
Trace::Highest)<<
"[FACE MapCoordToUid::fill] nb allFaces="<<m_mesh->allFaces().size();
567 Int64 uid = iface->uniqueId() ;
568 m_mesh->traceMng()->debug(
Trace::Highest)<<
"\t[FACE MapCoordToUid::fill] face_"<<iface->localId()<<
", uid="<<uid;
569 for( Node inode : iface->nodes() ){
570 m_mesh->traceMng()->debug(
Trace::Highest)<<
"\t\t[FACE MapCoordToUid::fill] node_"<<inode.localId();
572 Int64 map_uid = find(m_face_center[iface]);
575 m_mesh->traceMng()->fatal()<<
"MAP FACE ERROR : "<<map_uid<<
" found, expected uid "<<uid;
580 for(map_type::iterator iter = m_map.begin();iter!=m_map.end();++iter)
581 if(iter->second.second!=NULL_ITEM_ID){
583 if(set.find(iter->second.second)==set.end()){
584 m_mesh->traceMng()->fatal()<<
"MAP FACE ERROR : node "<<iter->second.second<<
" "<<iter->second.first<<
" does not exist";
587 if(count !=m_mesh->allFaces().size())
588 m_mesh->traceMng()->fatal()<<
"MAP FACE ERROR : map size"<<count<<
" != "<<m_mesh->allNodes().size();
595void NodeMapCoordToUid::
598 CHECKPERF( m_perf_counter.start(PerfCounter::Fill2) )
601 ItemInternalMap& nodes_map = dmesh->nodesMap();
602 nodes_map.eachItem([&](Node node) {
603 Int64 uid = node.uniqueId().asInt64();
604 if(uid == NULL_ITEM_ID)
606 this->insert(m_nodes_coords[node],uid);
608 CHECKPERF( m_perf_counter.stop(PerfCounter::Fill2) )
614void NodeMapCoordToUid::
619 ItemInternalMap& nodes_map = dmesh->nodesMap();
620 nodes_map.eachItem([&](Node node) {
621 Int64 uid = node.uniqueId().asInt64();
622 Int64 map_uid = find(m_nodes_coords[node]);
624 ARCANE_FATAL(
"MAP NODE ERROR : '{0}' found, expected uid '{1}'",map_uid,uid);
631void FaceMapCoordToUid::
634 CHECKPERF( m_perf_counter.stop(PerfCounter::Fill2) )
636 ItemInternalMap& faces_map = dmesh->facesMap();
637 faces_map.eachItem([&](Face face) {
638 Int64 face_uid = face.uniqueId().asInt64();
639 if(face_uid == NULL_ITEM_ID)
641 this->insert(faceCenter(face),face_uid);
643 CHECKPERF( m_perf_counter.stop(PerfCounter::Fill2) )
649void FaceMapCoordToUid::
653 ItemInternalMap& faces_map = dmesh->facesMap();
654 faces_map.eachItem([&](Face face) {
655 Int64 face_uid = face.uniqueId().asInt64();
656 Int64 map_uid = find(faceCenter(face));
657 if (face_uid != map_uid)
658 ARCANE_FATAL(
"MAP NODE ERROR : '{0}' found, expected uid '{1}'",map_uid,face_uid);
665void FaceMapCoordToUid::
669 m_face_center[iface] = faceCenter(*iface);
676void FaceMapCoordToUid::
677updateFaceCenter(ArrayView<ItemInternal*> refine_cells)
679 typedef std::set<Int64> set_type ;
680 typedef std::pair<set_type::iterator,bool> insert_return_type;
682 for(Integer icell=0;icell<refine_cells.size();++icell){
683 Cell cell = refine_cells[icell] ;
684 for (UInt32 i = 0, nc = cell.nbHChildren(); i<nc; ++i ){
685 Cell child = cell.hChild(i) ;
686 for( Face face : child.faces() ){
687 Int64 uid = face.uniqueId() ;
688 insert_return_type value = face_list.insert(uid);
690 Real3 fc = faceCenter(face);
691 m_face_center[face] = fc;
#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_FATAL(...)
Macro envoyant une exception FatalErrorException.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
SharedMeshVariableScalarRefT< Node, Real3 > SharedVariableNodeReal3
Grandeur au noeud de type coordonnées.
@ Highest
Niveau le plus élevé
Int32 Integer
Type représentant un entier.