MimmoPiercedVector.hpp
1 /*---------------------------------------------------------------------------*\
2  *
3  * mimmo
4  *
5  * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6  *
7  * -------------------------------------------------------------------------
8  * License
9  * This file is part of mimmo.
10  *
11  * mimmo is free software: you can redistribute it and/or modify it
12  * under the terms of the GNU Lesser General Public License v3 (LGPL)
13  * as published by the Free Software Foundation.
14  *
15  * mimmo is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18  * License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with mimmo. If not, see <http://www.gnu.org/licenses/>.
22  *
23 \*---------------------------------------------------------------------------*/
24 #ifndef __MIMMOPIERCEDVECTOR_HPP__
25 #define __MIMMOPIERCEDVECTOR_HPP__
26 
27 #include "MimmoObject.hpp"
28 #include "MimmoNamespace.hpp"
29 #include <mimmo_binary_stream.hpp>
30 #include <piercedVector.hpp>
31 
32 
33 namespace mimmo{
34 
39 enum class MPVLocation: long {
40  UNDEFINED = 0,
41  POINT = 1 ,
42  CELL = 2 ,
43  INTERFACE = 3
44 };
45 
59 template<typename mpv_t>
60 class MimmoPiercedVector: public bitpit::PiercedVector<mpv_t, long int> {
61 private:
63  MPVLocation m_loc;
64  bitpit::Logger* m_log;
65  std::string m_name;
67 public:
69  virtual ~MimmoPiercedVector();
70  //copy constructors and operators
73  MimmoPiercedVector & operator=(bitpit::PiercedVector<mpv_t, long int> other);
74 
75  void clear();
76 
77  // get/set methods of the class;
81  std::string getName() const;
82  std::vector<mpv_t> getDataAsVector(bool ordered=false);
83  std::vector<mpv_t> getInternalDataAsVector(bool ordered=false, bool squeeze = true);
84  std::vector<mpv_t> getRawDataAsVector(bool ordered=false);
85  bool isEmpty();
86 
87  bool completeMissingData(const mpv_t & defValue);
90  void setDataLocation(MPVLocation loc);
91  void setDataLocation(int loc);
92  void setData(std::vector<mpv_t> &rawdata);
93  void setName(std::string name);
94 
96  bool checkDataIdsCoherence();
98  bool intIsValidLocation(int &);
99 
100  void swap(MimmoPiercedVector<mpv_t>& x) noexcept;
101 
104  MimmoPiercedVector cellDataToPointData(const MimmoPiercedVector<mpv_t> & cellGradientsX, const MimmoPiercedVector<mpv_t> & cellGradientsY, const MimmoPiercedVector<mpv_t> & cellGradientsZ, bool maximum = false);
106 
107  std::size_t getDataFrom(const MimmoPiercedVector<mpv_t> & other, bool strict = false);
108  void squeezeOutExcept(const std::vector<long int> & list, bool keepOrder = false);
109  void squeezeOutExcept(const std::unordered_set<long int> & list, bool keepOrder = false);
110 
111 #if MIMMO_ENABLE_MPI
112  void communicateData();
113 #endif
114 
115 private:
116  livector1D getGeometryIds(bool ordered=false);
117 };
118 
124 typedef bitpit::PiercedVector<std::pair<bool, uint8_t>, long> btpvector1D;
135 };//end namespace mimmo.
136 
141 //Template provision of binary streams for Mimmo Pierced Vectors.
142 template<typename T>
144 template<typename T>
152 #include "MimmoPiercedVector.tpp"
153 
154 #endif /* __MIMMOPIERCEDVECTOR_HPP__ */
MPVLocation getConstDataLocation() const
mimmo::MimmoPiercedVector< bool > bmpvector1D
MimmoPiercedVector cellDataToPointData(double p=0.)
MimmoPiercedVector & operator=(MimmoPiercedVector< mpv_t > other)
MPVLocation
Define data location for the MimmoPiercedVector field.
void setName(std::string name)
std::vector< long > livector1D
mimmo custom derivation of bitpit OBinaryStream (see relative doc)
bool completeMissingData(const mpv_t &defValue)
void setData(std::vector< mpv_t > &rawdata)
MimmoPiercedVector pointDataToCellData(double p=0.)
void squeezeOutExcept(const std::vector< long int > &list, bool keepOrder=false)
bitpit::PiercedVector< std::pair< bool, uint8_t >, long > btpvector1D
MimmoPiercedVector is the basic data container for mimmo library.
MimmoSharedPointer< MimmoObject > getGeometry() const
mimmo::OBinaryStream & operator<<(mimmo::OBinaryStream &buf, const mimmo::MimmoPiercedVector< T > &element)
mimmo::IBinaryStream & operator>>(mimmo::IBinaryStream &buf, mimmo::MimmoPiercedVector< T > &element)
void initialize(MimmoSharedPointer< MimmoObject >, MPVLocation, const mpv_t &)
mimmo::MimmoPiercedVector< double > dmpvector1D
void setGeometry(MimmoSharedPointer< MimmoObject > geo)
std::vector< mpv_t > getInternalDataAsVector(bool ordered=false, bool squeeze=true)
void setDataLocation(MPVLocation loc)
MimmoPiercedVector< mpv_t > resizeToCoherentDataIds()
mimmo custom derivation of bitpit IBinaryStream (see relative doc)
std::vector< mpv_t > getDataAsVector(bool ordered=false)
mimmo::MimmoPiercedVector< std::vector< double > > dmpvector2D
void swap(MimmoPiercedVector< mpv_t > &x) noexcept
std::vector< mpv_t > getRawDataAsVector(bool ordered=false)
MimmoSharedPointer is a custom implementation of shared pointer.
MimmoPiercedVector(MimmoSharedPointer< MimmoObject > geo=nullptr, MPVLocation loc=MPVLocation::UNDEFINED)
mimmo::MimmoPiercedVector< std::vector< long int > > limpvector2D
std::size_t getDataFrom(const MimmoPiercedVector< mpv_t > &other, bool strict=false)
mimmo::MimmoPiercedVector< long int > limpvector1D
MimmoPiercedVector pointDataToBoundaryInterfaceData(double p=0.)
mimmo::MimmoPiercedVector< darray3E > dmpvecarr3E