51 for (std::size_t i = 0; i < nP; ++i) {
54 element.insert(
id, val);
70 std::string name = element.
getName();
73 buffer << (std::size_t)element.size();
74 auto itE = element.cend();
75 for (
auto it=element.cbegin(); it!=itE; it++){
90 template<
typename mpv_t>
94 m_log = &bitpit::log::cout(MIMMO_LOG_FILE);
101 template<
typename mpv_t>
108 template<
typename mpv_t>
110 this->m_geometry = other.m_geometry;
111 this->m_loc = other.m_loc;
112 this->m_name = other.m_name;
113 m_log = &bitpit::log::cout(MIMMO_LOG_FILE);
120 template<
typename mpv_t>
130 template<
typename mpv_t>
133 this->bitpit::PiercedVector<mpv_t, long int>::swap(other);
142 template<
typename mpv_t>
145 std::swap(this->m_geometry, x.m_geometry);
146 std::swap(this->m_loc, x.m_loc);
147 this->m_name.swap(x.m_name);
148 this->bitpit::PiercedVector<mpv_t, long int>::swap(x);
155 template<
typename mpv_t>
158 m_geometry =
nullptr;
160 m_loc = MPVLocation::UNDEFINED;
161 bitpit::PiercedVector<mpv_t, long int>::clear();
168 template<
typename mpv_t>
178 template<
typename mpv_t>
188 template<
typename mpv_t>
198 template<
typename mpv_t>
212 template<
typename mpv_t>
215 if(getGeometry() ==
nullptr)
return std::vector<mpv_t>();
217 std::vector<mpv_t> result;
218 result.reserve(this->size());
220 if(this->exists(
id)){
221 result.push_back(this->at(
id));
224 result.shrink_to_fit();
236 template<
typename mpv_t>
239 if(getGeometry() ==
nullptr)
return std::vector<mpv_t>(0);
240 std::vector<mpv_t> result;
242 std::unordered_set<long> ids_;
243 switch (getDataLocation())
245 case MPVLocation::CELL:
246 result.reserve(getGeometry()->getPatch()->getInternalCellCount());
247 ids = getGeometryIds(ordered);
248 for(
const auto val: ids){
249 if(this->exists(val) && getGeometry()->getPatch()->getCell(val).isInterior()){
250 result.push_back((*
this)[val]);
254 case MPVLocation::POINT:
255 result.reserve(getGeometry()->getPatch()->getVertexCount());
256 for (
auto & cell : getGeometry()->getCells()){
257 if (cell.isInterior()){
258 for (
long id : cell.getVertexIds())
262 ids = getGeometryIds(ordered);
263 for(
const auto val: ids){
264 if(this->exists(val) && ids_.count(val)){
265 result.push_back((*
this)[val]);
269 case MPVLocation::INTERFACE:
270 result.reserve(getGeometry()->getPatch()->getInterfaceCount());
272 ids = getGeometryIds(ordered);
273 for(
const auto val: ids){
274 if(this->exists(val)){
275 result.push_back((*
this)[val]);
283 result.shrink_to_fit();
295 template<
typename mpv_t>
299 std::vector<mpv_t> result(this->size());
301 for(
const auto val: ids){
302 result[counter] = (*this)[val];
312 template<
typename mpv_t>
322 template<
typename mpv_t>
333 template<
typename mpv_t>
336 loc = std::max(0, loc);
346 template<
typename mpv_t>
349 bitpit::PiercedVector<mpv_t, long int>::clear();
351 this->reserve(data.size());
352 for(
const auto val: data){
353 this->insert(
id, val);
362 template<
typename mpv_t>
376 template<
typename mpv_t>
379 if(getGeometry()==
nullptr)
return false;
382 case MPVLocation::CELL:
383 check = (this->size()==m_geometry->getPatch()->getCells().size());
385 case MPVLocation::INTERFACE:
387 size_t sizeInterfaces = m_geometry->getPatch()->getInterfaces().size();
388 check = (this->size()==sizeInterfaces);
391 case MPVLocation::POINT:
392 check = (this->size()==m_geometry->getPatch()->getVertices().size());
396 (*m_log)<<
"NO suitable location data found to perform data size coherence check"<<std::endl;
410 template<
typename mpv_t>
413 if(getGeometry()==
nullptr)
return false;
414 if (this->isEmpty())
return true;
415 auto ids = this->getIds();
418 case MPVLocation::CELL:
420 auto vcell = m_geometry->getPatch()->getCells();
422 check =check && vcell.exists(el);
426 case MPVLocation::INTERFACE:
428 auto vint = m_geometry->getPatch()->getInterfaces();
430 check =check && vint.exists(el);
434 case MPVLocation::POINT:
436 auto vvert = m_geometry->getPatch()->getVertices();
437 for(
auto el = this->begin(); el != this->end(); el++ ){
438 check =check && vvert.exists(el.getId());
444 (*m_log)<<
"NO suitable location data found to perform ids coherence check"<<std::endl;
456 template<
typename mpv_t>
461 if(!this->getGeometry())
return result;
465 case MPVLocation::CELL:
467 bitpit::PiercedVector<bitpit::Cell> & cells = m_geometry->getCells();
468 result.reserve(cells.size());
470 for(
auto it=this->begin(); it!=this->end(); ++it){
472 if(cells.exists(
id)){
473 result.insert(
id, *it);
478 case MPVLocation::INTERFACE:
480 bitpit::PiercedVector<bitpit::Interface> & interfaces = m_geometry->getInterfaces();
481 result.reserve(interfaces.size());
483 for(
auto it=this->begin(); it!=this->end(); ++it){
485 if(interfaces.exists(
id)){
486 result.insert(
id, *it);
491 case MPVLocation::POINT:
493 bitpit::PiercedVector<bitpit::Vertex> & verts = m_geometry->getVertices();
494 result.reserve(verts.size());
496 for(
auto it=this->begin(); it!=this->end(); ++it){
498 if(verts.exists(
id)){
499 result.insert(
id, *it);
505 (*m_log)<<
"NO suitable location data found to perform ids coherent resizing "<<std::endl;
516 template<
typename mpv_t>
519 return !(value<0 && value>3) ;
528 template<
typename mpv_t>
531 if(getGeometry()==
nullptr)
return livector1D(0);
533 case MPVLocation::POINT:
534 return getGeometry()->getVertices().getIds(ordered);
536 case MPVLocation::CELL:
537 return getGeometry()->getCells().getIds(ordered);
539 case MPVLocation::INTERFACE:
540 return getGeometry()->getInterfaces().getIds(ordered);
551 template<
typename mpv_t>
554 return this->size() == size_t(0);
565 template<
typename mpv_t>
569 if(!this->checkDataIdsCoherence())
return false;
570 if(!this->checkDataSizeCoherence()){
573 this->reserve(ids.size());
575 if(!this->exists(
id)) this->insert(
id, defValue);
591 template<
typename mpv_t>
596 case MPVLocation::POINT :
599 this->reserve(geo->getNVertices());
602 for(
const auto & vertex: geo->getVertices()){
603 this->insert(vertex.getId(), data);
607 case MPVLocation::CELL :
610 this->reserve(geo->getNCells());
613 for(
const auto & cell: geo->getCells()){
614 this->insert(cell.getId(), data);
618 case MPVLocation::INTERFACE :
619 if(geo->getInterfacesSyncStatus() != SyncStatus::SYNC){
620 (*m_log)<<
"MimmoPiercedVector warning: geometry interfaces are not built"<<std::endl;
624 this->reserve(geo->getPatch()->getInterfaceCount());
627 for(
const auto & interf: geo->getInterfaces()){
628 this->insert(interf.getId(), data);
644 template<
typename mpv_t>
649 for (bitpit::Cell & cell : geo->getCells()){
650 long idcell = cell.getId();
651 std::array<double,3> center = geo->getPatch()->evalCellCentroid(idcell);
654 for (
long idvertex : cell.getVertexIds()){
655 std::array<double,3> point = geo->getPatch()->getVertexCoords(idvertex);
656 double weight = 1. / std::pow(norm2(center-point),p);
658 data = this->at(idvertex)*weight;
659 sumWeights.insert(idcell, weight);
663 data = data + this->at(idvertex)*weight;
664 sumWeights[idcell] = sumWeights[idcell] + weight;
667 data = data / sumWeights[idcell];
668 cellData.insert(idcell, data);
681 template<
typename mpv_t>
687 for (bitpit::Cell & cell : geo->getCells()){
688 long idcell = cell.getId();
689 if (this->exists(idcell)){
690 std::array<double,3> center = geo->getPatch()->evalCellCentroid(idcell);
691 for (
long idvertex : cell.getVertexIds()){
692 std::array<double,3> point = geo->getPatch()->getVertexCoords(idvertex);
693 double weight = 1. / std::pow(norm2(center-point),p);
694 if (!pointData.exists(idvertex)){
695 pointData.insert(idvertex, this->at(idcell)*weight);
696 sumWeights.insert(idvertex, weight);
699 pointData[idvertex] = pointData[idvertex] + this->at(idcell)*weight;
700 sumWeights[idvertex] = sumWeights[idvertex] + weight;
705 for (bitpit::Vertex & vertex : geo->getVertices()){
706 long idvertex = vertex.getId();
707 if (pointData.exists(idvertex)){
708 pointData[idvertex] = pointData[idvertex] / sumWeights[idvertex];
727 template<
typename mpv_t>
736 for (bitpit::Cell & cell : geo->getCells()){
737 long idcell = cell.getId();
738 if (this->exists(idcell)){
739 double volume = geo->evalCellVolume(idcell);
740 double weight = 1. / std::pow(volume,p);
741 std::array<double,3> center = geo->getPatch()->evalCellCentroid(idcell);
742 for (
long idvertex : cell.getVertexIds()){
743 std::array<double,3> point = geo->getPatch()->getVertexCoords(idvertex);
744 std::array<mpv_t,3> grad({cellGradientsX.at(idcell), cellGradientsY.at(idcell), cellGradientsZ.at(idcell)});
746 value = this->at(idcell) + this->at(idcell)*(grad[0]*(point-center)[0]);
747 value = value + this->at(idcell)*(grad[1]*(point-center)[1]);
748 value = value + this->at(idcell)*(grad[2]*(point-center)[2]);
749 value = value * weight;
750 if (!pointData.exists(idvertex)){
751 pointData.insert(idvertex, value);
752 sumWeights.insert(idvertex, weight);
756 if (norm2(value) > norm2(pointData[idvertex]))
757 pointData[idvertex] = value;
760 pointData[idvertex] = pointData[idvertex] + value;
761 sumWeights[idvertex] = sumWeights[idvertex] + weight;
768 for (bitpit::Vertex & vertex : geo->getVertices()){
769 long idvertex = vertex.getId();
770 if (pointData.exists(idvertex)){
771 pointData[idvertex] = pointData[idvertex] / sumWeights[idvertex];
784 template<
typename mpv_t>
789 for (bitpit::Interface & interface : geo->getInterfaces()){
791 if (interface.isBorder()){
792 long idinterface = interface.getId();
794 std::size_t found = 0;
795 for (
long idvertex : interface.getVertexIds()){
796 if (this->exists(idvertex))
799 if (found == std::size_t(interface.getVertexCount())){
801 std::array<double,3> center = geo->getPatch()->evalInterfaceCentroid(idinterface);
804 for (
long idvertex : interface.getVertexIds()){
805 std::array<double,3> point = geo->getPatch()->getVertexCoords(idvertex);
806 double weight = 1. / std::pow(norm2(center-point),p);
808 if (this->exists(idvertex)){
809 data = this->at(idvertex)*weight;
811 sumWeights.insert(idinterface, weight);
815 if (this->exists(idvertex)){
816 data = data + this->at(idvertex)*weight;
818 sumWeights[idinterface] = sumWeights[idinterface] + weight;
821 data = data / sumWeights[idinterface];
822 interfaceData.insert(idinterface, data);
826 return interfaceData;
838 template<
typename mpv_t>
842 std::size_t counter(0);
843 for(
auto it= other.begin(); it != other.end(); ++it){
845 if(this->exists(
id)){
849 this->insert(
id, *it);
862 template<
typename mpv_t>
868 std::unordered_set<long> maplist(list.begin(), list.end());
871 result.reserve(maplist.size());
872 for(
auto it = this->begin(); it != this->end(); ++it){
873 if(maplist.count(it.getId()) > 0){
874 result.insert(it.getId(), *it);
883 if(this->exists(
id)){
884 result.insert(
id, this->at(
id));
897 template<
typename mpv_t>
905 result.reserve(list.size());
906 for(
auto it = this->begin(); it != this->end(); ++it){
907 if(list.count(it.getId()) > 0){
908 result.insert(it.getId(), *it);
917 if(this->exists(
id)){
918 result.insert(
id, this->at(
id));
936 template<
typename mpv_t>
941 if (getGeometry() ==
nullptr){
946 MimmoSharedPointer<MimmoObject> geometry = getGeometry();
949 if (!geometry->isDistributed()){
956 std::unique_ptr<bitpit::DataCommunicator> dataCommunicator(
new bitpit::DataCommunicator(geometry->getCommunicator()));
960 std::unordered_map<int, std::vector<long>> sources, targets;
962 case MPVLocation::POINT :
963 sources = getGeometry()->getPatch()->getGhostVertexExchangeSources();
964 targets = getGeometry()->getPatch()->getGhostVertexExchangeTargets();
966 case MPVLocation::CELL :
967 sources = getGeometry()->getPatch()->getGhostCellExchangeSources();
968 targets = getGeometry()->getPatch()->getGhostCellExchangeTargets();
975 size_t exchangeDataSize =
sizeof(mpv_t);
978 for (
const auto entry : sources) {
979 const int rank = entry.first;
980 auto &list = entry.second;
981 dataCommunicator->setSend(rank, list.size() * exchangeDataSize);
982 bitpit::SendBuffer &buffer = dataCommunicator->getSendBuffer(rank);
983 for (
long id : list) {
984 if (this->count(
id)){
985 buffer << this->at(
id);
991 dataCommunicator->startSend(rank);
995 dataCommunicator->discoverRecvs();
996 dataCommunicator->startAllRecvs();
1000 int nCompletedRecvs = 0;
1001 while (nCompletedRecvs < dataCommunicator->getRecvCount()) {
1002 int rank = dataCommunicator->waitAnyRecv();
1003 const auto &list = targets.at(rank);
1004 bitpit::RecvBuffer &buffer = dataCommunicator->getRecvBuffer(rank);
1005 for (
long id : list) {
1007 if (this->count(
id)){
1008 this->at(
id) = value;
1012 this->insert(
id, value);
1019 dataCommunicator->waitAllSends();
1020 dataCommunicator->finalize();