diff --git a/src/OpenFOAM/containers/Bits/PackedList/PackedList.H b/src/OpenFOAM/containers/Bits/PackedList/PackedList.H index 6bc3942c81617e926d51a3458a20836e5c2ccae8..1ae6f228f2592f4d38ad8ded51768520411f096f 100644 --- a/src/OpenFOAM/containers/Bits/PackedList/PackedList.H +++ b/src/OpenFOAM/containers/Bits/PackedList/PackedList.H @@ -401,6 +401,12 @@ public: //- A pointer to the raw storage inline unsigned int* data() noexcept; + //- A const pointer to the raw storage, reinterpreted as byte data + inline const char* cdata_bytes() const noexcept; + + //- A pointer to the raw storage, reinterpreted as byte data + inline char* data_bytes() noexcept; + //- The number of bytes used in the raw storage //- including any unused padding. inline std::streamsize size_bytes() const noexcept; diff --git a/src/OpenFOAM/containers/Bits/PackedList/PackedListI.H b/src/OpenFOAM/containers/Bits/PackedList/PackedListI.H index 95aa8e32d79498a7e726465b4862cd2dbdc2ce6c..a525746d39bdb76884982894c57a3137ec3e0567 100644 --- a/src/OpenFOAM/containers/Bits/PackedList/PackedListI.H +++ b/src/OpenFOAM/containers/Bits/PackedList/PackedListI.H @@ -561,6 +561,20 @@ inline unsigned int* Foam::PackedList<Width>::data() noexcept } +template<unsigned Width> +inline const char* Foam::PackedList<Width>::cdata_bytes() const noexcept +{ + return blocks_.cdata_bytes(); +} + + +template<unsigned Width> +inline char* Foam::PackedList<Width>::data_bytes() noexcept +{ + return blocks_.data_bytes(); +} + + template<unsigned Width> inline std::streamsize Foam::PackedList<Width>::size_bytes() const noexcept { diff --git a/src/OpenFOAM/containers/Bits/PackedList/PackedListIO.C b/src/OpenFOAM/containers/Bits/PackedList/PackedListIO.C index c2b0ca7e63720757c16797cfeb9bc8f179512cfb..b61897267f5f8f4d1881fcf894d7992100503f92 100644 --- a/src/OpenFOAM/containers/Bits/PackedList/PackedListIO.C +++ b/src/OpenFOAM/containers/Bits/PackedList/PackedListIO.C @@ -88,11 +88,7 @@ Foam::Istream& Foam::PackedList<Width>::readList(Istream& is) if (len) { // NOTE: independent of WM_LABEL_SIZE - is.read - ( - reinterpret_cast<char*>(list.data()), - list.size_bytes() - ); + is.read(list.data_bytes(), list.size_bytes()); is.fatalCheck ( @@ -197,11 +193,7 @@ Foam::Ostream& Foam::PackedList<Width>::writeList if (len) { // write(...) includes surrounding start/end delimiters - os.write - ( - reinterpret_cast<const char*>(list.cdata()), - list.size_bytes() - ); + os.write(list.cdata_bytes(), list.size_bytes()); } } else if (len > 1 && list.uniform()) diff --git a/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.C b/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListList.C similarity index 98% rename from src/OpenFOAM/containers/Lists/CompactListList/CompactListList.C rename to src/OpenFOAM/containers/CompactLists/CompactListList/CompactListList.C index 2f17099edda63f14bff46e4bdc9a6d1df2ebaf67..ca1b88304a0d6ac1002cc5ed3cb930344b214eae 100644 --- a/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.C +++ b/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListList.C @@ -248,8 +248,4 @@ const } -// * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * // - -#include "CompactListListIO.C" - // ************************************************************************* // diff --git a/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.H b/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListList.H similarity index 99% rename from src/OpenFOAM/containers/Lists/CompactListList/CompactListList.H rename to src/OpenFOAM/containers/CompactLists/CompactListList/CompactListList.H index b9f80dda9b5b657a91f00f5bb6147e8fc8523779..b9b2332307a5e7c93ea7ceb649fc97f9387392ca 100644 --- a/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.H +++ b/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListList.H @@ -275,6 +275,7 @@ public: #ifdef NoRepository #include "CompactListList.C" + #include "CompactListListIO.C" #endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/containers/Lists/CompactListList/CompactListListI.H b/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListListI.H similarity index 100% rename from src/OpenFOAM/containers/Lists/CompactListList/CompactListListI.H rename to src/OpenFOAM/containers/CompactLists/CompactListList/CompactListListI.H diff --git a/src/OpenFOAM/containers/Lists/CompactListList/CompactListListIO.C b/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListListIO.C similarity index 100% rename from src/OpenFOAM/containers/Lists/CompactListList/CompactListListIO.C rename to src/OpenFOAM/containers/CompactLists/CompactListList/CompactListListIO.C diff --git a/src/OpenFOAM/containers/IndirectLists/BiIndirectList/BiIndirectList.H b/src/OpenFOAM/containers/IndirectLists/BiIndirectList/BiIndirectList.H index 3d3036bb76829e10af735c15696f001ea9f6a2f2..8584736338202dde4a3f635715a2c54745542fbf 100644 --- a/src/OpenFOAM/containers/IndirectLists/BiIndirectList/BiIndirectList.H +++ b/src/OpenFOAM/containers/IndirectLists/BiIndirectList/BiIndirectList.H @@ -56,7 +56,8 @@ class BiIndirectList UList<T>& posList_; UList<T>& negList_; - List<label> addressing_; + + labelList addressing_; public: @@ -76,7 +77,7 @@ public: ( const UList<T>& posList, const UList<T>& negList, - List<label>&& addr + labelList&& addr ); @@ -90,23 +91,24 @@ public: //- True if the list is empty (ie, size() is zero). inline bool empty() const noexcept; - inline const UList<T>& posList() const; - inline const UList<T>& negList() const; + inline const UList<T>& posList() const noexcept; + inline const UList<T>& negList() const noexcept; //- Return the list addressing - inline const List<label>& addressing() const; + inline const labelList& addressing() const noexcept; //- Calculate index given whether index is into posList or negList inline static label posIndex(const label i); inline static label negIndex(const label i); + // Edit //- Copy reset addressing inline void resetAddressing(const labelUList& addr); //- Move reset addressing - inline void resetAddressing(List<label>&& addr); + inline void resetAddressing(labelList&& addr); // Member Operators diff --git a/src/OpenFOAM/containers/IndirectLists/BiIndirectList/BiIndirectListI.H b/src/OpenFOAM/containers/IndirectLists/BiIndirectList/BiIndirectListI.H index 7a84ff1abc18b31e498eb2d86836777c84948aa5..d9ac3ce68d34a45261af34f60273099769106566 100644 --- a/src/OpenFOAM/containers/IndirectLists/BiIndirectList/BiIndirectListI.H +++ b/src/OpenFOAM/containers/IndirectLists/BiIndirectList/BiIndirectListI.H @@ -63,7 +63,7 @@ inline Foam::BiIndirectList<T>::BiIndirectList ( const UList<T>& posList, const UList<T>& negList, - List<label>&& addr + labelList&& addr ) : posList_(const_cast<UList<T>&>(posList)), @@ -89,22 +89,22 @@ inline bool Foam::BiIndirectList<T>::empty() const noexcept template<class T> -inline const Foam::UList<T>& Foam::BiIndirectList<T>::posList() const +inline const Foam::UList<T>& Foam::BiIndirectList<T>::posList() const noexcept { return posList_; } template<class T> -inline const Foam::UList<T>& Foam::BiIndirectList<T>::negList() const +inline const Foam::UList<T>& Foam::BiIndirectList<T>::negList() const noexcept { return negList_; } template<class T> -inline const Foam::List<Foam::label>& Foam::BiIndirectList<T>::addressing() - const +inline const Foam::labelList& +Foam::BiIndirectList<T>::addressing() const noexcept { return addressing_; } @@ -123,7 +123,7 @@ inline void Foam::BiIndirectList<T>::resetAddressing template<class T> inline void Foam::BiIndirectList<T>::resetAddressing ( - List<label>&& addr + labelList&& addr ) { addressing_.transfer(addr); diff --git a/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListAddressing.H b/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListAddressing.H index 913b3fdfad96054912a066c968c070dd21a8b6e2..b760a3d6fc5eb7ef56290440a0faefb8597db81f 100644 --- a/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListAddressing.H +++ b/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListAddressing.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -31,8 +31,6 @@ Description normally to used by IndirectList. Private inheritance is often used by any inheriting classes. -SourceFiles - \*---------------------------------------------------------------------------*/ #ifndef IndirectListAddressing_H @@ -76,13 +74,13 @@ public: // Member Functions //- Const access to the addressing - const Addr& addressing() const + const Addr& addressing() const noexcept { return storedAddr_; } //- Non-const access to the addressing - Addr& addressing() + Addr& addressing() noexcept { return storedAddr_; } diff --git a/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBase.H b/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBase.H index c9b01667edc7b949f143d2c158647c466de4659f..ae540580057f6f6123bd48c4a323a91de3c33337 100644 --- a/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBase.H +++ b/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBase.H @@ -147,7 +147,7 @@ public: } //- The addressing used for the list - inline const Addr& addressing() const + inline const Addr& addressing() const noexcept { return addr_; } diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H index 378d54ab71a7588dcf610388f352bec5dabc0e3d..d45d836afdcb47f312590d363efbcda5a553ce23 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H @@ -36,8 +36,9 @@ Description SizeMin template parameter dictating a lower bound. SourceFiles - DynamicListI.H DynamicList.C + DynamicListI.H + DynamicListIO.C \*---------------------------------------------------------------------------*/ @@ -56,10 +57,10 @@ namespace Foam template<class T, int SizeMin> class DynamicList; template<class T, int SizeMin> -inline Istream& operator>>(Istream&, DynamicList<T, SizeMin>&); +Istream& operator>>(Istream& is, DynamicList<T, SizeMin>& list); template<class T, int SizeMin> -inline Ostream& operator<<(Ostream&, const DynamicList<T, SizeMin>&); +Ostream& operator<<(Ostream& os, const DynamicList<T, SizeMin>& list); /*---------------------------------------------------------------------------*\ @@ -156,6 +157,10 @@ public: //- Size of the underlying storage. inline label capacity() const noexcept; + //- Number of contiguous bytes of the underlying storage. + // \note Only meaningful for contiguous data + inline std::streamsize capacity_bytes() const noexcept; + // Sizing @@ -336,12 +341,12 @@ public: // Reading/writing //- Read from Istream, discarding existing contents - inline Istream& readList(Istream& is); + Istream& readList(Istream& is); // IOstream Operators - //- Read from Istream, discarding existing contents + //- Use the readList() method to read contents from Istream. friend Istream& operator>> <T, SizeMin> ( Istream& is, @@ -357,6 +362,24 @@ public: }; +// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // + +//- Read List contents from Istream +template<class T, int SizeMin> +Istream& operator>>(Istream& is, DynamicList<T, SizeMin>& list) +{ + return list.readList(is); +} + + +//- Write List to Ostream, as per UList::writeList() with default length. +template<class T, int SizeMin> +Ostream& operator<<(Ostream& os, const DynamicList<T, SizeMin>& list) +{ + return (os << static_cast<const UList<T>&>(list)); +} + + // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // // Exchange contents of lists - see DynamicList::swap(). @@ -367,6 +390,8 @@ inline void Swap(DynamicList<T, SizeMinA>& a, DynamicList<T, SizeMinB>& b) } +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + //- Hashing for List data template<class T, int SizeMin> struct Hash<DynamicList<T, SizeMin>> : List<T>::hasher {}; @@ -384,6 +409,7 @@ struct Hash<DynamicList<T, SizeMin>> : List<T>::hasher {}; #ifdef NoRepository #include "DynamicList.C" + #include "DynamicListIO.C" #endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H index 911087b6e18256f74ee57ed7f1bb29191a927eec..047aa3423aecc51003b7b668c97e9eeb49d31598 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H @@ -207,22 +207,20 @@ inline Foam::DynamicList<T, SizeMin>::DynamicList } +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + template<class T, int SizeMin> -inline Foam::DynamicList<T, SizeMin>::DynamicList(Istream& is) -: - List<T>(), - capacity_(0) +inline Foam::label Foam::DynamicList<T, SizeMin>::capacity() const noexcept { - this->readList(is); + return capacity_; } -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - template<class T, int SizeMin> -inline Foam::label Foam::DynamicList<T, SizeMin>::capacity() const noexcept +inline std::streamsize +Foam::DynamicList<T, SizeMin>::capacity_bytes() const noexcept { - return capacity_; + return std::streamsize(capacity_)*sizeof(T); } @@ -867,47 +865,4 @@ inline void Foam::DynamicList<T, SizeMin>::operator= } -// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // - -template<class T, int SizeMin> -inline Foam::Istream& Foam::DynamicList<T, SizeMin>::readList -( - Istream& is -) -{ - DynamicList<T, SizeMin>& list = *this; - - // Use entire storage - ie, resize(capacity()) - (void) list.expandStorage(); - - static_cast<List<T>&>(list).readList(is); - list.capacity_ = list.size(); - - return is; -} - - -template<class T, int SizeMin> -inline Foam::Istream& Foam::operator>> -( - Istream& is, - DynamicList<T, SizeMin>& list -) -{ - return list.readList(is); -} - - -template<class T, int SizeMin> -inline Foam::Ostream& Foam::operator<< -( - Ostream& os, - const DynamicList<T, SizeMin>& list -) -{ - os << static_cast<const List<T>&>(list); - return os; -} - - // ************************************************************************* // diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListIO.C b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListIO.C new file mode 100644 index 0000000000000000000000000000000000000000..5fa5e9d00fa709a300f6d01f78ca75abe07ddb4e --- /dev/null +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListIO.C @@ -0,0 +1,67 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2021 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "List.H" +#include "Istream.H" +#include "token.H" +#include "SLList.H" +#include "contiguous.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template<class T, int SizeMin> +Foam::DynamicList<T, SizeMin>::DynamicList(Istream& is) +: + List<T>(), + capacity_(0) +{ + this->readList(is); +} + + +// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // + +template<class T, int SizeMin> +Foam::Istream& Foam::DynamicList<T, SizeMin>::readList +( + Istream& is +) +{ + DynamicList<T, SizeMin>& list = *this; + + // Needs rewrite (2021-10) + // Use entire storage - ie, resize(capacity()) + (void) list.expandStorage(); + + static_cast<List<T>&>(list).readList(is); + list.capacity_ = list.size(); + + return is; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedList.C b/src/OpenFOAM/containers/Lists/FixedList/FixedList.C index d0570f2a98cafc6c0a1245cf6073a1eeb9ef0cd1..0c8f0f13d9ea896fcd9fd9087bf83a926469d28c 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedList.C +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedList.C @@ -29,10 +29,10 @@ License #include "FixedList.H" #include "ListLoopM.H" -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // template<class T, unsigned N> -std::streamsize Foam::FixedList<T, N>::byteSize() const +std::streamsize Foam::FixedList<T, N>::byteSize() { if (!is_contiguous<T>::value) { @@ -40,10 +40,12 @@ std::streamsize Foam::FixedList<T, N>::byteSize() const << "Invalid for non-contiguous data types" << abort(FatalError); } - return this->size_bytes(); + return FixedList<T, N>::size_bytes(); } +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + template<class T, unsigned N> Foam::label Foam::FixedList<T, N>::find(const T& val, label pos) const { @@ -215,8 +217,4 @@ bool Foam::FixedList<T, N>::operator>=(const FixedList<T, N>& list) const } -// * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * // - -#include "FixedListIO.C" - // ************************************************************************* // diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H index a79a318d06a30bf57edb500250e1a4cbce27b50c..3a3a6c63ef8146d858eb07cf04f3183e44cf28ae 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H @@ -69,6 +69,9 @@ template<class T> class UList; template<class T, unsigned N> Istream& operator>>(Istream& is, FixedList<T, N>& list); +template<class T, unsigned N> +Ostream& operator<<(Ostream& os, const FixedList<T, N>& list); + /*---------------------------------------------------------------------------*\ Class FixedList Declaration @@ -197,16 +200,23 @@ public: // Access - //- Return a const pointer to the first data element. - // Similar to the STL front() method and the string::data() method - // This can be used (with caution) when interfacing with C code + //- Return pointer to the underlying array serving as data storage. inline const T* cdata() const noexcept; - //- Return a pointer to the first data element. - // Similar to the STL front() method and the string::data() method - // This can be used (with caution) when interfacing with C code + //- Return pointer to the underlying array serving as data storage. inline T* data() noexcept; + //- Return pointer to the underlying array serving as data storage, + // reinterpreted as byte data + // \note Only meaningful for contiguous data + inline const char* cdata_bytes() const noexcept; + + //- Return pointer to the underlying array serving as data storage, + // reinterpreted as byte data + // \note Only meaningful for contiguous data + inline char* data_bytes() noexcept; + + //- The first element of the list, position [0] inline T& first() noexcept; @@ -220,12 +230,12 @@ public: inline const T& last() const noexcept; //- Number of contiguous bytes for the list data, - //- no runtime check that the type is actually contiguous + // \note Only meaningful for contiguous data inline static std::streamsize size_bytes() noexcept; //- Number of contiguous bytes for the list data, - //- with runtime check that the type is actually contiguous - std::streamsize byteSize() const; + //- runtime FatalError if type is not contiguous + static std::streamsize byteSize(); //- Return the forward circular index, i.e. next index //- which returns to the first at the end of the list @@ -448,7 +458,7 @@ public: // IOstream Operators - //- Read from Istream, discarding contents of existing List + //- Use the readList() method to read contents from Istream. friend Istream& operator>> <T, N> ( Istream& is, @@ -523,6 +533,14 @@ inline void Swap(FixedList<T, N>& a, FixedList<T, N>& b) // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // +//- Read List contents from Istream, list must have the proper size! +template<class T, unsigned N> +Istream& operator>>(Istream& is, FixedList<T, N>& list) +{ + return list.readList(is); +} + + //- Write List to Ostream, as per FixedList::writeList() with default length. // The default short-length is given by Detail::ListPolicy::short_length template<class T, unsigned N> @@ -545,6 +563,7 @@ Ostream& operator<<(Ostream& os, const FixedList<T, N>& list) #ifdef NoRepository #include "FixedList.C" + #include "FixedListIO.C" #endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H index 78611d47640f2388ef534f1dd2b01778984fb689..d72b3fb94440dc76dd4e441dea1a16ad4c6af65b 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H @@ -180,6 +180,22 @@ Foam::FixedList<T, N>::data() noexcept } +template<class T, unsigned N> +inline const char* +Foam::FixedList<T, N>::cdata_bytes() const noexcept +{ + return reinterpret_cast<const char*>(v_); +} + + +template<class T, unsigned N> +inline char* +Foam::FixedList<T, N>::data_bytes() noexcept +{ + return reinterpret_cast<char*>(v_); +} + + template<class T, unsigned N> inline std::streamsize Foam::FixedList<T, N>::size_bytes() noexcept { diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C b/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C index 437b608f9b7b13c02effb5c28c63150fa28a50d3..db491874a226c1cd1866138d9f235b79ea21bddd 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C @@ -45,6 +45,15 @@ void Foam::FixedList<T, N>::writeEntry(Ostream& os) const } +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template<class T, unsigned N> +Foam::FixedList<T, N>::FixedList(Istream& is) +{ + this->readList(is); +} + + // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // template<class T, unsigned N> @@ -81,11 +90,7 @@ Foam::Ostream& Foam::FixedList<T, N>::writeList // Binary and contiguous. Size is always non-zero // write(...) includes surrounding start/end delimiters - os.write - ( - reinterpret_cast<const char*>(list.cdata()), - list.size_bytes() - ); + os.write(list.cdata_bytes(), list.size_bytes()); } else if ( @@ -155,7 +160,7 @@ Foam::Istream& Foam::FixedList<T, N>::readList Detail::readContiguous<T> ( is, - reinterpret_cast<char*>(list.data()), + list.data_bytes(), list.size_bytes() ); @@ -247,20 +252,4 @@ Foam::Istream& Foam::FixedList<T, N>::readList } -// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // - -template<class T, unsigned N> -Foam::FixedList<T, N>::FixedList(Istream& is) -{ - this->readList(is); -} - - -template<class T, unsigned N> -Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, N>& list) -{ - return list.readList(is); -} - - // ************************************************************************* // diff --git a/src/OpenFOAM/containers/Lists/List/List.C b/src/OpenFOAM/containers/Lists/List/List.C index ef0df3dbca79e07cccf2b8939391d16474ae8311..1a7186cace438ac7491b200c9e533832f9ce902e 100644 --- a/src/OpenFOAM/containers/Lists/List/List.C +++ b/src/OpenFOAM/containers/Lists/List/List.C @@ -660,8 +660,4 @@ void Foam::List<T>::operator=(SLList<T>&& list) } -// * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * // - -#include "ListIO.C" - // ************************************************************************* // diff --git a/src/OpenFOAM/containers/Lists/List/List.H b/src/OpenFOAM/containers/Lists/List/List.H index ebded60c266d09491256967a5bfaafb0adf5f05d..4cb9815a42fb2120f2950ac152c6783a26c1d113 100644 --- a/src/OpenFOAM/containers/Lists/List/List.H +++ b/src/OpenFOAM/containers/Lists/List/List.H @@ -305,7 +305,7 @@ public: // IOstream Operators - //- Read List from Istream, discarding contents of existing List + //- Use the readList() method to read contents from Istream. friend Istream& operator>> <T> ( Istream& is, @@ -360,6 +360,16 @@ template<class T> struct Hash<List<T>> : List<T>::hasher {}; +// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // + +//- Read List contents from Istream +template<class T> +Istream& operator>>(Istream& is, List<T>& list) +{ + return list.readList(is); +} + + // * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * // //- Create identity map of the given length with (map[i] == i) @@ -379,6 +389,7 @@ labelList identity(const label len, label start=0); #ifdef NoRepository #include "List.C" + #include "ListIO.C" #endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/containers/Lists/List/ListIO.C b/src/OpenFOAM/containers/Lists/List/ListIO.C index 863603d8b80b8138fe2a21e1e6f5493fa18d87c4..4eb8b0e6925ab41ce780cd62537c6b05b51f9883 100644 --- a/src/OpenFOAM/containers/Lists/List/ListIO.C +++ b/src/OpenFOAM/containers/Lists/List/ListIO.C @@ -32,7 +32,7 @@ License #include "SLList.H" #include "contiguous.H" -// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template<class T> Foam::List<T>::List(Istream& is) @@ -43,6 +43,8 @@ Foam::List<T>::List(Istream& is) } +// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // + template<class T> Foam::Istream& Foam::List<T>::readList(Istream& is) { @@ -87,7 +89,7 @@ Foam::Istream& Foam::List<T>::readList(Istream& is) Detail::readContiguous<T> ( is, - reinterpret_cast<char*>(list.data()), + list.data_bytes(), list.size_bytes() ); @@ -164,11 +166,4 @@ Foam::Istream& Foam::List<T>::readList(Istream& is) } -template<class T> -Foam::Istream& Foam::operator>>(Istream& is, List<T>& list) -{ - return list.readList(is); -} - - // ************************************************************************* // diff --git a/src/OpenFOAM/containers/Lists/UList/UList.C b/src/OpenFOAM/containers/Lists/UList/UList.C index 3263d6f0c8adb0af77530747069571772de4b0c1..c35bcf81abd949b8b928a1ed9150acc09367e02f 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.C +++ b/src/OpenFOAM/containers/Lists/UList/UList.C @@ -388,8 +388,4 @@ bool Foam::UList<T>::operator>=(const UList<T>& list) const } -// * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * // - -#include "UListIO.C" - // ************************************************************************* // diff --git a/src/OpenFOAM/containers/Lists/UList/UList.H b/src/OpenFOAM/containers/Lists/UList/UList.H index 1fd97cb99ee407deae51dad8d6462d437da61032..9c6b39cfdea30bb8b1cfa1dfc14fa4929b45a4ea 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.H +++ b/src/OpenFOAM/containers/Lists/UList/UList.H @@ -257,16 +257,22 @@ public: //- Return reverse circular value (ie, previous value in the list) inline T& rcValue(const label i); - //- Return a const pointer to the first data element. - // Similar to the STL front() method and the string::data() method - // This can be used (with caution) when interfacing with C code + //- Return pointer to the underlying array serving as data storage. inline const T* cdata() const noexcept; - //- Return a pointer to the first data element. - // Similar to the STL front() method and the string::data() method - // This can be used (with caution) when interfacing with C code + //- Return pointer to the underlying array serving as data storage. inline T* data() noexcept; + //- Return pointer to the underlying array serving as data storage, + // reinterpreted as byte data + // \note Only meaningful for contiguous data + inline const char* cdata_bytes() const noexcept; + + //- Return pointer to the underlying array serving as data storage, + // reinterpreted as byte data + // \note Only meaningful for contiguous data + inline char* data_bytes() noexcept; + //- Return the first element of the list inline T& first(); @@ -279,12 +285,12 @@ public: //- Return the last element of the list inline const T& last() const; - //- Number of contiguous bytes for the List data, - //- no runtime check that the type is actually contiguous + //- Number of contiguous bytes for the List data. + // \note Only meaningful for contiguous data inline std::streamsize size_bytes() const noexcept; //- Number of contiguous bytes for the List data, - //- with runtime check that the type is actually contiguous + //- runtime FatalError if type is not contiguous std::streamsize byteSize() const; @@ -484,8 +490,7 @@ public: // IOstream Operators - //- Read List contents from Istream. - // The List must have the proper size before calling + //- Use the readList() method to read contents from Istream. friend Istream& operator>> <T> ( Istream& os, @@ -586,6 +591,14 @@ Ostream& UList<char>::writeList(Ostream& os, const label /*unused*/) const; // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // +//- Read List contents from Istream, list must have the proper size! +template<class T> +Istream& operator>>(Istream& is, UList<T>& list) +{ + return list.readList(is); +} + + //- Write List to Ostream, as per UList::writeList() with default length. // The default short-length is given by Detail::ListPolicy::short_length template<class T> @@ -594,7 +607,7 @@ Ostream& operator<<(Ostream& os, const UList<T>& list) return list.writeList(os, Detail::ListPolicy::short_length<T>::value); } -//- Write std::vector to Ostream +//- Write std::vector to Ostream. ASCII only, no line-breaks template<class T> Ostream& operator<<(Ostream& os, const std::vector<T>& list); @@ -685,6 +698,7 @@ struct sizeOp #ifdef NoRepository #include "UList.C" + #include "UListIO.C" #include "stdVectorIO.C" #endif diff --git a/src/OpenFOAM/containers/Lists/UList/UListI.H b/src/OpenFOAM/containers/Lists/UList/UListI.H index dc46db9fafd23beb5b0fc668a35378dcea110968..ef5354e15a64cbb1af6bca8741bf97c6aeda86e7 100644 --- a/src/OpenFOAM/containers/Lists/UList/UListI.H +++ b/src/OpenFOAM/containers/Lists/UList/UListI.H @@ -207,6 +207,20 @@ inline T* Foam::UList<T>::data() noexcept } +template<class T> +inline const char* Foam::UList<T>::cdata_bytes() const noexcept +{ + return reinterpret_cast<const char*>(v_); +} + + +template<class T> +inline char* Foam::UList<T>::data_bytes() noexcept +{ + return reinterpret_cast<char*>(v_); +} + + template<class T> inline std::streamsize Foam::UList<T>::size_bytes() const noexcept { diff --git a/src/OpenFOAM/containers/Lists/UList/UListIO.C b/src/OpenFOAM/containers/Lists/UList/UListIO.C index 05923a379d0c8405904234d416c6fe2740dc7853..42247829241c2a96f2a7103e60193d78300137dc 100644 --- a/src/OpenFOAM/containers/Lists/UList/UListIO.C +++ b/src/OpenFOAM/containers/Lists/UList/UListIO.C @@ -94,11 +94,7 @@ Foam::Ostream& Foam::UList<T>::writeList if (len) { // write(...) includes surrounding start/end delimiters - os.write - ( - reinterpret_cast<const char*>(list.cdata()), - list.size_bytes() - ); + os.write(list.cdata_bytes(), list.size_bytes()); } } else if (len > 1 && is_contiguous<T>::value && list.uniform()) @@ -224,7 +220,7 @@ Foam::Istream& Foam::UList<T>::readList(Istream& is) Detail::readContiguous<T> ( is, - reinterpret_cast<char*>(list.data()), + list.data_bytes(), list.size_bytes() ); @@ -313,11 +309,4 @@ Foam::Istream& Foam::UList<T>::readList(Istream& is) } -template<class T> -Foam::Istream& Foam::operator>>(Istream& is, UList<T>& list) -{ - return list.readList(is); -} - - // ************************************************************************* // diff --git a/src/OpenFOAM/containers/Lists/UList/stdVectorIO.C b/src/OpenFOAM/containers/Lists/UList/stdVectorIO.C index 9f525e5ba1a6f5e4b8af1ce8da17bb424aefaf90..ba8db32641c11f2e9fb798f628bc8ebc569ef337 100644 --- a/src/OpenFOAM/containers/Lists/UList/stdVectorIO.C +++ b/src/OpenFOAM/containers/Lists/UList/stdVectorIO.C @@ -38,7 +38,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const std::vector<T>& list) auto iter = list.cbegin(); const auto last = list.cend(); - // Write ascii list contents, no breaks + // Write ascii list contents, no line breaks os << label(list.size()) << token::BEGIN_LIST; diff --git a/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C b/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C index 7470ad6c31268db7bf69e68069dd6dda415273c6..ee795672bf8416483154f7e3bdd23ff562b09633 100644 --- a/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C +++ b/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C @@ -583,9 +583,9 @@ void Foam::decomposedBlockData::gather ) { const label nProcs = UPstream::nProcs(comm); - datas.setSize(nProcs); + datas.resize(nProcs); - char* data0Ptr = reinterpret_cast<char*>(datas.data()); + char* data0Ptr = datas.data_bytes(); List<int> recvOffsets; List<int> recvSizes; diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/combineGatherScatter.C b/src/OpenFOAM/db/IOstreams/Pstreams/combineGatherScatter.C index 2e7627db904295daae074a4d36af34b89a9af7f3..e1c4f0cfc8950173fea790359c5e0d7b31252977 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/combineGatherScatter.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/combineGatherScatter.C @@ -313,7 +313,7 @@ void Foam::Pstream::listCombineGather ( UPstream::commsTypes::scheduled, belowID, - reinterpret_cast<char*>(receivedValues.data()), + receivedValues.data_bytes(), receivedValues.size_bytes(), tag, comm @@ -370,7 +370,7 @@ void Foam::Pstream::listCombineGather ( UPstream::commsTypes::scheduled, myComm.above(), - reinterpret_cast<const char*>(Values.cdata()), + Values.cdata_bytes(), Values.size_bytes(), tag, comm @@ -450,7 +450,7 @@ void Foam::Pstream::listCombineScatter ( UPstream::commsTypes::scheduled, myComm.above(), - reinterpret_cast<char*>(Values.data()), + Values.data_bytes(), Values.size_bytes(), tag, comm @@ -492,7 +492,7 @@ void Foam::Pstream::listCombineScatter ( UPstream::commsTypes::scheduled, belowID, - reinterpret_cast<const char*>(Values.cdata()), + Values.cdata_bytes(), Values.size_bytes(), tag, comm diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/exchange.C b/src/OpenFOAM/db/IOstreams/Pstreams/exchange.C index e5c9319c939e0150720a7736e340aaa057747c50..8d6352375deb3fb2bbdee61844424c38dfed97a0 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/exchange.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/exchange.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2019 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -59,7 +59,7 @@ void Foam::Pstream::exchangeContainer ( UPstream::commsTypes::nonBlocking, proci, - reinterpret_cast<char*>(recvBufs[proci].begin()), + recvBufs[proci].data_bytes(), recvSizes[proci]*sizeof(T), tag, comm @@ -81,8 +81,8 @@ void Foam::Pstream::exchangeContainer ( UPstream::commsTypes::nonBlocking, proci, - reinterpret_cast<const char*>(sendBufs[proci].begin()), - sendBufs[proci].size()*sizeof(T), + sendBufs[proci].cdata_bytes(), + sendBufs[proci].size_bytes(), tag, comm ) diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/gatherScatterList.C b/src/OpenFOAM/db/IOstreams/Pstreams/gatherScatterList.C index a3282d1ece6d941f6c54779f9f65b17d454d2f1e..7de5fd1224df7ada29985ae476e25c22f9d963ea 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/gatherScatterList.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/gatherScatterList.C @@ -84,7 +84,7 @@ void Pstream::gatherList ( UPstream::commsTypes::scheduled, belowID, - reinterpret_cast<char*>(receivedValues.data()), + receivedValues.data_bytes(), receivedValues.size_bytes(), tag, comm @@ -160,7 +160,7 @@ void Pstream::gatherList ( UPstream::commsTypes::scheduled, myComm.above(), - reinterpret_cast<const char*>(sendingValues.cdata()), + sendingValues.cdata_bytes(), sendingValues.size_bytes(), tag, comm @@ -246,7 +246,7 @@ void Pstream::scatterList ( UPstream::commsTypes::scheduled, myComm.above(), - reinterpret_cast<char*>(receivedValues.data()), + receivedValues.data_bytes(), receivedValues.size_bytes(), tag, comm @@ -302,7 +302,7 @@ void Pstream::scatterList ( UPstream::commsTypes::scheduled, belowID, - reinterpret_cast<const char*>(sendingValues.cdata()), + sendingValues.cdata_bytes(), sendingValues.size_bytes(), tag, comm diff --git a/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H b/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H index 0330f968d311dd99c25b4f6e7d5b33865ee1c766..517d292afd5550a0a183d6f9846dbd375f91df84 100644 --- a/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H +++ b/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H @@ -167,6 +167,10 @@ public: //- Size of the underlying storage. inline label capacity() const noexcept; + //- Number of contiguous bytes of the underlying storage. + // \note Only meaningful for contiguous data + inline std::streamsize capacity_bytes() const noexcept; + // Sizing @@ -240,6 +244,13 @@ public: inline T remove(); + // Reading/writing + + //- Read from Istream, discarding existing contents + // Uses a DynamicList::readList internally + inline Istream& readList(Istream& is); + + // Member Operators //- Return non-const access to an element, resizing list if needed @@ -270,7 +281,7 @@ public: // IOstream Operators - //- Read from Istream, discarding existing contents + //- Use the readList() method to read contents from Istream. friend Istream& operator>> <T, SizeMin> ( Istream& is, diff --git a/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H b/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H index 835841d8b1e155b936db5219bcae6a7b1e27ff97..8d41f1e36351aba021296231e6fe6b48ea3e8f68 100644 --- a/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H +++ b/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H @@ -244,6 +244,14 @@ inline Foam::label Foam::DynamicField<T, SizeMin>::capacity() const noexcept } +template<class T, int SizeMin> +inline std::streamsize +Foam::DynamicField<T, SizeMin>::capacity_bytes() const noexcept +{ + return std::streamsize(capacity_)*sizeof(T); +} + + template<class T, int SizeMin> inline void Foam::DynamicField<T, SizeMin>::setCapacity ( @@ -611,12 +619,13 @@ inline void Foam::DynamicField<T, SizeMin>::operator= // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // template<class T, int SizeMin> -inline Foam::Istream& Foam::operator>> +inline Foam::Istream& Foam::DynamicField<T, SizeMin>::readList ( - Istream& is, - DynamicField<T, SizeMin>& rhs + Istream& is ) { + DynamicField<T, SizeMin>& rhs = *this; + // Use entire storage - ie, resize(capacity()) (void) rhs.expandStorage(); @@ -627,6 +636,17 @@ inline Foam::Istream& Foam::operator>> } +template<class T, int SizeMin> +inline Foam::Istream& Foam::operator>> +( + Istream& is, + DynamicField<T, SizeMin>& rhs +) +{ + return rhs.readList(is); +} + + template<class T, int SizeMin> inline Foam::Ostream& Foam::operator<< ( diff --git a/src/OpenFOAM/fields/pointPatchFields/constraint/processorCyclic/processorCyclicPointPatchField.C b/src/OpenFOAM/fields/pointPatchFields/constraint/processorCyclic/processorCyclicPointPatchField.C index 118b720c70ba52063f7f84e9b8674ffc68cdd1d6..0e4ab1e9e51ea135babadd7026209bc020be2575 100644 --- a/src/OpenFOAM/fields/pointPatchFields/constraint/processorCyclic/processorCyclicPointPatchField.C +++ b/src/OpenFOAM/fields/pointPatchFields/constraint/processorCyclic/processorCyclicPointPatchField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -123,8 +123,8 @@ void Foam::processorCyclicPointPatchField<Type>::initSwapAddSeparated ( commsType, procPatch_.neighbProcNo(), - reinterpret_cast<char*>(receiveBuf_.data()), - receiveBuf_.byteSize(), + receiveBuf_.data_bytes(), + receiveBuf_.size_bytes(), procPatch_.tag(), procPatch_.comm() ); @@ -133,8 +133,8 @@ void Foam::processorCyclicPointPatchField<Type>::initSwapAddSeparated ( commsType, procPatch_.neighbProcNo(), - reinterpret_cast<const char*>(pf.cdata()), - pf.byteSize(), + pf.cdata_bytes(), + pf.size_bytes(), procPatch_.tag(), procPatch_.comm() ); @@ -159,8 +159,8 @@ void Foam::processorCyclicPointPatchField<Type>::swapAddSeparated ( commsType, procPatch_.neighbProcNo(), - reinterpret_cast<char*>(receiveBuf_.data()), - receiveBuf_.byteSize(), + receiveBuf_.data_bytes(), + receiveBuf_.size_bytes(), procPatch_.tag(), procPatch_.comm() ); diff --git a/src/OpenFOAM/matrices/LUscalarMatrix/LUscalarMatrixTemplates.C b/src/OpenFOAM/matrices/LUscalarMatrix/LUscalarMatrixTemplates.C index 1c8d0fe6e738d7a196ee2052645fafbf989659fe..159a6af98f342cd673e01302429e82df1cbc9d2b 100644 --- a/src/OpenFOAM/matrices/LUscalarMatrix/LUscalarMatrixTemplates.C +++ b/src/OpenFOAM/matrices/LUscalarMatrix/LUscalarMatrixTemplates.C @@ -76,7 +76,7 @@ void Foam::LUscalarMatrix::solve ( Pstream::commsTypes::scheduled, Pstream::masterNo(), - reinterpret_cast<const char*>(x.cdata()), + x.cdata_bytes(), x.byteSize(), Pstream::msgType(), comm_ @@ -111,7 +111,7 @@ void Foam::LUscalarMatrix::solve ( Pstream::commsTypes::scheduled, Pstream::masterNo(), - reinterpret_cast<char*>(x.data()), + x.data_bytes(), x.byteSize(), Pstream::msgType(), comm_ diff --git a/src/OpenFOAM/matrices/Matrix/Matrix.C b/src/OpenFOAM/matrices/Matrix/Matrix.C index 1a45c0460ecf087056bb8fc97952a84027db4b04..7de050fc9e7a045faa213120de553582998f1030 100644 --- a/src/OpenFOAM/matrices/Matrix/Matrix.C +++ b/src/OpenFOAM/matrices/Matrix/Matrix.C @@ -1035,8 +1035,4 @@ operator^ } // End namespace Foam -// * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * // - -#include "MatrixIO.C" - // ************************************************************************* // diff --git a/src/OpenFOAM/matrices/Matrix/Matrix.H b/src/OpenFOAM/matrices/Matrix/Matrix.H index e6882cbbe78271bddbcd528fe56b6ab7d7287fe7..24eb0bd7e6bbee218223ecece66ec813086416bc 100644 --- a/src/OpenFOAM/matrices/Matrix/Matrix.H +++ b/src/OpenFOAM/matrices/Matrix/Matrix.H @@ -66,6 +66,12 @@ template<class Form, class Type> class Matrix; template<class MatrixType> class ConstMatrixBlock; template<class MatrixType> class MatrixBlock; +template<class Form, class Type> +Istream& operator>>(Istream& is, Matrix<Form, Type>& mat); + +template<class Form, class Type> +Ostream& operator<<(Ostream& os, const Matrix<Form, Type>& mat); + /*---------------------------------------------------------------------------*\ Class Matrix Declaration @@ -204,12 +210,23 @@ public: //- be used to address into Matrix contents inline Type* data() noexcept; + //- Return pointer to the underlying array serving as data storage, + //- reinterpreted as byte data. + // \note Only meaningful for contiguous data + inline const char* cdata_bytes() const noexcept; + + //- Return pointer to the underlying array serving as data storage, + //- reinterpreted as byte data. + // \note Only meaningful for contiguous data + inline char* data_bytes() noexcept; + //- Number of contiguous bytes for the Matrix data, //- no runtime check that the type is actually contiguous + // \note Only meaningful for contiguous data inline std::streamsize size_bytes() const noexcept; //- Number of contiguous bytes for the Matrix data, - //- with runtime check that the type is actually contiguous + //- runtime FatalError if type is not contiguous std::streamsize byteSize() const; //- Return const pointer to data in the specified row @@ -590,12 +607,20 @@ public: //- Read Matrix from Istream, discarding contents of existing Matrix. template<class Form, class Type> -Istream& operator>>(Istream& is, Matrix<Form, Type>& mat); +Istream& operator>>(Istream& is, Matrix<Form, Type>& mat) +{ + mat.readMatrix(is); + return is; +} + //- Write Matrix to Ostream, as per Matrix::writeMatrix() with //- default length, which is given by Detail::ListPolicy::short_length template<class Form, class Type> -Ostream& operator<<(Ostream& os, const Matrix<Form, Type>& mat); +Ostream& operator<<(Ostream& os, const Matrix<Form, Type>& mat) +{ + return mat.writeMatrix(os, Detail::ListPolicy::short_length<Type>::value); +} // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -610,6 +635,7 @@ Ostream& operator<<(Ostream& os, const Matrix<Form, Type>& mat); #ifdef NoRepository #include "Matrix.C" + #include "MatrixIO.C" #endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/matrices/Matrix/MatrixI.H b/src/OpenFOAM/matrices/Matrix/MatrixI.H index c44b1d6853903886e7c2d40a933a82670c9e3855..707965a4c32bd98702714ee7874b5b78ce98a175 100644 --- a/src/OpenFOAM/matrices/Matrix/MatrixI.H +++ b/src/OpenFOAM/matrices/Matrix/MatrixI.H @@ -212,6 +212,20 @@ inline Type* Foam::Matrix<Form, Type>::data() noexcept } +template<class Form, class Type> +inline const char* Foam::Matrix<Form, Type>::cdata_bytes() const noexcept +{ + return reinterpret_cast<const char*>(v_); +} + + +template<class Form, class Type> +inline char* Foam::Matrix<Form, Type>::data_bytes() noexcept +{ + return reinterpret_cast<char*>(v_); +} + + template<class Form, class Type> inline std::streamsize Foam::Matrix<Form, Type>::size_bytes() const noexcept { diff --git a/src/OpenFOAM/matrices/Matrix/MatrixIO.C b/src/OpenFOAM/matrices/Matrix/MatrixIO.C index e6369d2cc286484091eebf6ba769399b1a72572b..b13f41097ae7b4ddede8f7ee323f17f09a28a642 100644 --- a/src/OpenFOAM/matrices/Matrix/MatrixIO.C +++ b/src/OpenFOAM/matrices/Matrix/MatrixIO.C @@ -34,7 +34,7 @@ License #include "ListPolicy.H" #include <algorithm> -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template<class Form, class Type> Foam::Matrix<Form, Type>::Matrix(Istream& is) @@ -43,10 +43,12 @@ Foam::Matrix<Form, Type>::Matrix(Istream& is) nCols_(0), v_(nullptr) { - operator>>(is, *this); + this->readMatrix(is); } +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + template<class Form, class Type> bool Foam::Matrix<Form, Type>::readMatrix(Istream& is) { @@ -77,7 +79,7 @@ bool Foam::Matrix<Form, Type>::readMatrix(Istream& is) Detail::readContiguous<Type> ( is, - reinterpret_cast<char*>(v_), + this->data_bytes(), this->size_bytes() ); @@ -159,11 +161,7 @@ Foam::Ostream& Foam::Matrix<Form, Type>::writeMatrix if (len) { // write(...) includes surrounding start/end delimiters - os.write - ( - reinterpret_cast<const char*>(mat.cdata()), - mat.size_bytes() - ); + os.write(mat.cdata_bytes(), mat.size_bytes()); } } else @@ -240,19 +238,4 @@ Foam::Ostream& Foam::Matrix<Form, Type>::writeMatrix } -template<class Form, class Type> -Foam::Istream& Foam::operator>>(Istream& is, Matrix<Form, Type>& mat) -{ - mat.readMatrix(is); - return is; -} - - -template<class Form, class Type> -Foam::Ostream& Foam::operator<<(Ostream& os, const Matrix<Form, Type>& mat) -{ - return mat.writeMatrix(os, Detail::ListPolicy::short_length<Type>::value); -} - - // ************************************************************************* // diff --git a/src/OpenFOAM/matrices/lduMatrix/lduAddressing/lduInterface/processorLduInterfaceTemplates.C b/src/OpenFOAM/matrices/lduMatrix/lduAddressing/lduInterface/processorLduInterfaceTemplates.C index 1913b0ac9d66777f80fe5cb726722ce5bc4e770c..70a5639ef60799eee75c1df3503abffdf0f94f2e 100644 --- a/src/OpenFOAM/matrices/lduMatrix/lduAddressing/lduInterface/processorLduInterfaceTemplates.C +++ b/src/OpenFOAM/matrices/lduMatrix/lduAddressing/lduInterface/processorLduInterfaceTemplates.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -51,7 +51,7 @@ void Foam::processorLduInterface::send ( commsType, neighbProcNo(), - reinterpret_cast<const char*>(f.cdata()), + f.cdata_bytes(), nBytes, tag(), comm() @@ -113,7 +113,7 @@ void Foam::processorLduInterface::receive ( commsType, neighbProcNo(), - reinterpret_cast<char*>(f.data()), + f.data_bytes(), f.byteSize(), tag(), comm() diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaceFields/processorGAMGInterfaceField/processorGAMGInterfaceField.C b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaceFields/processorGAMGInterfaceField/processorGAMGInterfaceField.C index 2451f8f6e752f4da2e2b01119a594d39fcc34133..13ff33c5d554eacbad1888702373c39603ea284d 100644 --- a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaceFields/processorGAMGInterfaceField/processorGAMGInterfaceField.C +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaceFields/processorGAMGInterfaceField/processorGAMGInterfaceField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -114,8 +114,8 @@ void Foam::processorGAMGInterfaceField::initInterfaceMatrixUpdate ( Pstream::commsTypes::nonBlocking, procInterface_.neighbProcNo(), - reinterpret_cast<char*>(scalarReceiveBuf_.data()), - scalarReceiveBuf_.byteSize(), + scalarReceiveBuf_.data_bytes(), + scalarReceiveBuf_.size_bytes(), procInterface_.tag(), comm() ); @@ -125,8 +125,8 @@ void Foam::processorGAMGInterfaceField::initInterfaceMatrixUpdate ( Pstream::commsTypes::nonBlocking, procInterface_.neighbProcNo(), - reinterpret_cast<const char*>(scalarSendBuf_.cdata()), - scalarSendBuf_.byteSize(), + scalarSendBuf_.cdata_bytes(), + scalarSendBuf_.size_bytes(), procInterface_.tag(), comm() ); diff --git a/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalIndexTemplates.C b/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalIndexTemplates.C index 9893418c00ebe7f114d38bcc355979a5033eddcb..3db3c653fad2e89588110747209fcac7f921dc59 100644 --- a/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalIndexTemplates.C +++ b/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalIndexTemplates.C @@ -77,7 +77,7 @@ void Foam::globalIndex::gather ( commsType, procIDs[i], - reinterpret_cast<char*>(procSlot.data()), + procSlot.data_bytes(), procSlot.size_bytes(), tag, comm @@ -112,7 +112,7 @@ void Foam::globalIndex::gather ( commsType, procIDs[i], - reinterpret_cast<char*>(procSlot.data()), + procSlot.data_bytes(), procSlot.size_bytes(), tag, comm @@ -137,7 +137,7 @@ void Foam::globalIndex::gather ( commsType, procIDs[0], - reinterpret_cast<const char*>(fld.cdata()), + fld.cdata_bytes(), fld.size_bytes(), tag, comm @@ -167,7 +167,7 @@ void Foam::globalIndex::gather ( commsType, procIDs[0], - reinterpret_cast<const char*>(fld.cdata()), + fld.cdata_bytes(), fld.size_bytes(), tag, comm @@ -403,7 +403,7 @@ void Foam::globalIndex::scatter ( commsType, procIDs[i], - reinterpret_cast<const char*>(procSlot.cdata()), + procSlot.cdata_bytes(), procSlot.size_bytes(), tag, comm @@ -438,7 +438,7 @@ void Foam::globalIndex::scatter ( commsType, procIDs[i], - reinterpret_cast<const char*>(procSlot.cdata()), + procSlot.cdata_bytes(), procSlot.size_bytes(), tag, comm @@ -463,7 +463,7 @@ void Foam::globalIndex::scatter ( commsType, procIDs[0], - reinterpret_cast<char*>(fld.data()), + fld.data_bytes(), fld.size_bytes(), tag, comm @@ -493,7 +493,7 @@ void Foam::globalIndex::scatter ( commsType, procIDs[0], - reinterpret_cast<char*>(fld.data()), + fld.data_bytes(), fld.size_bytes(), tag, comm diff --git a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBase.C b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBase.C index eabb9262202a00e140968c4a85cc8c5bab771ae7..d72d9e445b230a10fc946219274d277830d4922d 100644 --- a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBase.C +++ b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBase.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2015-2017 OpenFOAM Foundation - Copyright (C) 2015-2020 OpenCFD Ltd. + Copyright (C) 2015-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -960,8 +960,8 @@ void Foam::mapDistributeBase::compact ( Pstream::commsTypes::nonBlocking, domain, - reinterpret_cast<char*>(recvFields[domain].data()), - recvFields[domain].size()*sizeof(bool), + recvFields[domain].data_bytes(), + recvFields[domain].size_bytes(), tag, comm_ ); @@ -994,8 +994,8 @@ void Foam::mapDistributeBase::compact ( Pstream::commsTypes::nonBlocking, domain, - reinterpret_cast<const char*>(subField.cdata()), - subField.size()*sizeof(bool), + subField.cdata_bytes(), + subField.size_bytes(), tag, comm_ ); @@ -1132,8 +1132,8 @@ void Foam::mapDistributeBase::compact ( Pstream::commsTypes::nonBlocking, domain, - reinterpret_cast<char*>(recvFields[domain].data()), - recvFields[domain].size()*sizeof(bool), + recvFields[domain].data_bytes(), + recvFields[domain].size_bytes(), tag, comm_ ); @@ -1165,8 +1165,8 @@ void Foam::mapDistributeBase::compact ( Pstream::commsTypes::nonBlocking, domain, - reinterpret_cast<const char*>(subField.cdata()), - subField.size()*sizeof(bool), + subField.cdata_bytes(), + subField.size_bytes(), tag, comm_ ); diff --git a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBaseTemplates.C b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBaseTemplates.C index 61813efd663e167dc7a9d9dd111a8e5d8103a4b6..a16a88a2fc6244058baed8ae85b9cca7fa19ac05 100644 --- a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBaseTemplates.C +++ b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBaseTemplates.C @@ -535,7 +535,7 @@ void Foam::mapDistributeBase::distribute ( Pstream::commsTypes::nonBlocking, domain, - reinterpret_cast<const char*>(subField.cdata()), + subField.cdata_bytes(), subField.size_bytes(), tag, comm @@ -558,7 +558,7 @@ void Foam::mapDistributeBase::distribute ( Pstream::commsTypes::nonBlocking, domain, - reinterpret_cast<char*>(recvFields[domain].data()), + recvFields[domain].data_bytes(), recvFields[domain].size_bytes(), tag, comm @@ -1060,7 +1060,7 @@ void Foam::mapDistributeBase::distribute ( Pstream::commsTypes::nonBlocking, domain, - reinterpret_cast<const char*>(subField.cdata()), + subField.cdata_bytes(), subField.size_bytes(), tag, comm @@ -1083,7 +1083,7 @@ void Foam::mapDistributeBase::distribute ( Pstream::commsTypes::nonBlocking, domain, - reinterpret_cast<char*>(recvFields[domain].data()), + recvFields[domain].data_bytes(), recvFields[domain].size_bytes(), tag, comm diff --git a/src/OpenFOAM/meshes/polyMesh/syncTools/syncToolsTemplates.C b/src/OpenFOAM/meshes/polyMesh/syncTools/syncToolsTemplates.C index 8e9d91dfd0e36682b05757242f11282f065d11d7..aca1207b1587f20088351f54a8daf788894fc183 100644 --- a/src/OpenFOAM/meshes/polyMesh/syncTools/syncToolsTemplates.C +++ b/src/OpenFOAM/meshes/polyMesh/syncTools/syncToolsTemplates.C @@ -1052,7 +1052,7 @@ void Foam::syncTools::syncBoundaryFaceList ( Pstream::commsTypes::nonBlocking, procPatch.neighbProcNo(), - reinterpret_cast<char*>(fld.data()), + fld.data_bytes(), fld.size_bytes() ); } @@ -1078,7 +1078,7 @@ void Foam::syncTools::syncBoundaryFaceList ( Pstream::commsTypes::nonBlocking, procPatch.neighbProcNo(), - reinterpret_cast<const char*>(fld.cdata()), + fld.cdata_bytes(), fld.size_bytes() ); } @@ -1279,7 +1279,7 @@ void Foam::syncTools::syncFaceList ( Pstream::commsTypes::nonBlocking, procPatch.neighbProcNo(), - reinterpret_cast<char*>(recvInfo.data()), + recvInfo.data_bytes(), recvInfo.size_bytes() ); } @@ -1314,7 +1314,7 @@ void Foam::syncTools::syncFaceList ( Pstream::commsTypes::nonBlocking, procPatch.neighbProcNo(), - reinterpret_cast<const char*>(sendInfo.cdata()), + sendInfo.cdata_bytes(), sendInfo.size_bytes() ); } diff --git a/src/fileFormats/vtk/output/foamVtkOutput.C b/src/fileFormats/vtk/output/foamVtkOutput.C index 08a00cf6e40f49917cc31f082ff013e60dec6ba5..7598e5c07f0bfbecb42a77004f62e1b5f009a5f4 100644 --- a/src/fileFormats/vtk/output/foamVtkOutput.C +++ b/src/fileFormats/vtk/output/foamVtkOutput.C @@ -138,11 +138,7 @@ void Foam::vtk::writeListParallel if (!Pstream::master()) { UOPstream os(Pstream::masterNo(), pBufs); - os.write - ( - reinterpret_cast<const char*>(values.cdata()), - values.size_bytes() - ); + os.write(values.cdata_bytes(), values.size_bytes()); } pBufs.finishedSends(); @@ -164,11 +160,7 @@ void Foam::vtk::writeListParallel List<label> recv(sizes.localSize(proci)); UIPstream is(proci, pBufs); - is.read - ( - reinterpret_cast<char*>(recv.data()), - recv.size_bytes() - ); + is.read(recv.data_bytes(), recv.size_bytes()); // Write with offset const label offsetId = procOffset.offset(proci); diff --git a/src/fileFormats/vtk/output/foamVtkOutputTemplates.C b/src/fileFormats/vtk/output/foamVtkOutputTemplates.C index 59bdb0e88fe227c59f4d5cddc89277217170921b..2717f19645f9958154a79b05d109418e066bf04b 100644 --- a/src/fileFormats/vtk/output/foamVtkOutputTemplates.C +++ b/src/fileFormats/vtk/output/foamVtkOutputTemplates.C @@ -179,11 +179,7 @@ void Foam::vtk::writeListParallel UOPstream os(Pstream::masterNo(), pBufs); if (is_contiguous<Type>::value) { - os.write - ( - reinterpret_cast<const char*>(values.cdata()), - values.size_bytes() - ); + os.write(values.cdata_bytes(), values.size_bytes()); } else { @@ -208,11 +204,7 @@ void Foam::vtk::writeListParallel if (is_contiguous<Type>::value) { - is.read - ( - reinterpret_cast<char*>(recv.data()), - recv.size_bytes() - ); + is.read(recv.data_bytes(), recv.size_bytes()); } else { @@ -295,11 +287,7 @@ void Foam::vtk::writeListParallel UOPstream os(Pstream::masterNo(), pBufs); if (is_contiguous<Type>::value) { - os.write - ( - reinterpret_cast<const char*>(send.cdata()), - send.size_bytes() - ); + os.write(send.cdata_bytes(), send.size_bytes()); } else { @@ -324,11 +312,7 @@ void Foam::vtk::writeListParallel if (is_contiguous<Type>::value) { - is.read - ( - reinterpret_cast<char*>(recv.data()), - recv.size_bytes() - ); + is.read(recv.data_bytes(), recv.size_bytes()); } else { @@ -361,16 +345,8 @@ void Foam::vtk::writeListsParallel UOPstream os(Pstream::masterNo(), pBufs); if (is_contiguous<Type>::value) { - os.write - ( - reinterpret_cast<const char*>(values1.cdata()), - values1.size_bytes() - ); - os.write - ( - reinterpret_cast<const char*>(values2.cdata()), - values2.size_bytes() - ); + os.write(values1.cdata_bytes(), values1.size_bytes()); + os.write(values2.cdata_bytes(), values2.size_bytes()); } else { @@ -402,11 +378,7 @@ void Foam::vtk::writeListsParallel List<Type> recv(sizes1.localSize(proci)); if (is_contiguous<Type>::value) { - is.read - ( - reinterpret_cast<char*>(recv.data()), - recv.size_bytes() - ); + is.read(recv.data_bytes(), recv.size_bytes()); } else { @@ -420,11 +392,7 @@ void Foam::vtk::writeListsParallel List<Type> recv(sizes2.localSize(proci)); if (is_contiguous<Type>::value) { - is.read - ( - reinterpret_cast<char*>(recv.data()), - recv.size_bytes() - ); + is.read(recv.data_bytes(), recv.size_bytes()); } else { diff --git a/src/finiteArea/faMesh/faMeshDemandDrivenData.C b/src/finiteArea/faMesh/faMeshDemandDrivenData.C index 63ec9815bdc7ac037e5bbec5d081ef185f9962d4..c70b7d9e0de049c8c6cbf21925dbd9f2ad23ca0a 100644 --- a/src/finiteArea/faMesh/faMeshDemandDrivenData.C +++ b/src/finiteArea/faMesh/faMeshDemandDrivenData.C @@ -1058,7 +1058,7 @@ void Foam::faMesh::calcPointAreaNormals() const ( Pstream::commsTypes::blocking, procPatch.neighbProcNo(), - reinterpret_cast<const char*>(patchPointNormals.cdata()), + patchPointNormals.cdata_bytes(), patchPointNormals.byteSize() ); } @@ -1074,7 +1074,7 @@ void Foam::faMesh::calcPointAreaNormals() const ( Pstream::commsTypes::blocking, procPatch.neighbProcNo(), - reinterpret_cast<char*>(ngbPatchPointNormals.data()), + ngbPatchPointNormals.data_bytes(), ngbPatchPointNormals.byteSize() ); } diff --git a/src/finiteVolume/fields/fvPatchFields/constraint/calculatedProcessor/calculatedProcessorFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/constraint/calculatedProcessor/calculatedProcessorFvPatchField.C index 2713b4e8fb8c51c8218d25ef0587eb6fbe3fbf36..ba02bd7fa5ba63c07cf9050b50d889e0b7db9bae 100644 --- a/src/finiteVolume/fields/fvPatchFields/constraint/calculatedProcessor/calculatedProcessorFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/constraint/calculatedProcessor/calculatedProcessorFvPatchField.C @@ -144,6 +144,13 @@ void Foam::calculatedProcessorFvPatchField<Type>::initEvaluate { if (Pstream::parRun()) { + if (!is_contiguous<Type>::value) + { + FatalErrorInFunction + << "Invalid for non-contiguous data types" + << abort(FatalError); + } + //this->patchInternalField(sendBuf_); // Bypass patchInternalField since uses fvPatch addressing { @@ -163,8 +170,8 @@ void Foam::calculatedProcessorFvPatchField<Type>::initEvaluate ( Pstream::commsTypes::nonBlocking, procInterface_.neighbProcNo(), - reinterpret_cast<char*>(this->data()), - this->byteSize(), + this->data_bytes(), + this->size_bytes(), procInterface_.tag(), procInterface_.comm() ); @@ -174,8 +181,8 @@ void Foam::calculatedProcessorFvPatchField<Type>::initEvaluate ( Pstream::commsTypes::nonBlocking, procInterface_.neighbProcNo(), - reinterpret_cast<const char*>(sendBuf_.cdata()), - this->byteSize(), + sendBuf_.cdata_bytes(), + sendBuf_.size_bytes(), procInterface_.tag(), procInterface_.comm() ); @@ -245,8 +252,8 @@ void Foam::calculatedProcessorFvPatchField<Type>::initInterfaceMatrixUpdate ( Pstream::commsTypes::nonBlocking, procInterface_.neighbProcNo(), - reinterpret_cast<char*>(scalarReceiveBuf_.data()), - scalarReceiveBuf_.byteSize(), + scalarReceiveBuf_.data_bytes(), + scalarReceiveBuf_.size_bytes(), procInterface_.tag(), procInterface_.comm() ); @@ -257,8 +264,8 @@ void Foam::calculatedProcessorFvPatchField<Type>::initInterfaceMatrixUpdate ( Pstream::commsTypes::nonBlocking, procInterface_.neighbProcNo(), - reinterpret_cast<const char*>(scalarSendBuf_.cdata()), - scalarSendBuf_.byteSize(), + scalarSendBuf_.cdata_bytes(), + scalarSendBuf_.size_bytes(), procInterface_.tag(), procInterface_.comm() ); diff --git a/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.C index c87c52a8d9631e5b794f40452911792ff3d54878..f13d8a4aeca9510914437e2062c8bb8b7426fd85 100644 --- a/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -225,15 +225,22 @@ void Foam::processorFvPatchField<Type>::initEvaluate && !Pstream::floatTransfer ) { - // Fast path. Receive into *this + if (!is_contiguous<Type>::value) + { + FatalErrorInFunction + << "Invalid for non-contiguous data types" + << abort(FatalError); + } + + // Receive straight into *this this->setSize(sendBuf_.size()); outstandingRecvRequest_ = UPstream::nRequests(); UIPstream::read ( Pstream::commsTypes::nonBlocking, procPatch_.neighbProcNo(), - reinterpret_cast<char*>(this->data()), - this->byteSize(), + this->data_bytes(), + this->size_bytes(), procPatch_.tag(), procPatch_.comm() ); @@ -243,8 +250,8 @@ void Foam::processorFvPatchField<Type>::initEvaluate ( Pstream::commsTypes::nonBlocking, procPatch_.neighbProcNo(), - reinterpret_cast<const char*>(sendBuf_.cdata()), - sendBuf_.byteSize(), + sendBuf_.cdata_bytes(), + sendBuf_.size_bytes(), procPatch_.tag(), procPatch_.comm() ); @@ -353,8 +360,8 @@ void Foam::processorFvPatchField<Type>::initInterfaceMatrixUpdate ( Pstream::commsTypes::nonBlocking, procPatch_.neighbProcNo(), - reinterpret_cast<char*>(scalarReceiveBuf_.data()), - scalarReceiveBuf_.byteSize(), + scalarReceiveBuf_.data_bytes(), + scalarReceiveBuf_.size_bytes(), procPatch_.tag(), procPatch_.comm() ); @@ -364,8 +371,8 @@ void Foam::processorFvPatchField<Type>::initInterfaceMatrixUpdate ( Pstream::commsTypes::nonBlocking, procPatch_.neighbProcNo(), - reinterpret_cast<const char*>(scalarSendBuf_.cdata()), - scalarSendBuf_.byteSize(), + scalarSendBuf_.cdata_bytes(), + scalarSendBuf_.size_bytes(), procPatch_.tag(), procPatch_.comm() ); @@ -503,8 +510,8 @@ void Foam::processorFvPatchField<Type>::initInterfaceMatrixUpdate ( Pstream::commsTypes::nonBlocking, procPatch_.neighbProcNo(), - reinterpret_cast<char*>(receiveBuf_.data()), - receiveBuf_.byteSize(), + receiveBuf_.data_bytes(), + receiveBuf_.size_bytes(), procPatch_.tag(), procPatch_.comm() ); @@ -514,8 +521,8 @@ void Foam::processorFvPatchField<Type>::initInterfaceMatrixUpdate ( Pstream::commsTypes::nonBlocking, procPatch_.neighbProcNo(), - reinterpret_cast<const char*>(sendBuf_.cdata()), - sendBuf_.byteSize(), + sendBuf_.cdata_bytes(), + sendBuf_.size_bytes(), procPatch_.tag(), procPatch_.comm() ); diff --git a/src/meshTools/polyTopoChange/polyTopoChange.C b/src/meshTools/polyTopoChange/polyTopoChange.C index 806ddb58b66448ea1ee04968536cf6c75a139704..38013b4c3ce980ef223c99d7b015a122a4f5be08 100644 --- a/src/meshTools/polyTopoChange/polyTopoChange.C +++ b/src/meshTools/polyTopoChange/polyTopoChange.C @@ -39,7 +39,6 @@ License #include "polyRemoveCell.H" #include "objectMap.H" #include "processorPolyPatch.H" -#include "CompactListList.H" #include "ListOps.H" #include "mapPolyMesh.H" @@ -584,7 +583,7 @@ void Foam::polyTopoChange::makeCellCells // Handles removed cells. Returns number of remaining cells. Foam::label Foam::polyTopoChange::getCellOrder ( - const CompactListList<label, labelList>& cellCellAddressing, + const CompactListList<label>& cellCellAddressing, labelList& oldToNew ) const { diff --git a/src/meshTools/polyTopoChange/polyTopoChange.H b/src/meshTools/polyTopoChange/polyTopoChange.H index d7661e4c43bbd4d5c0c5d0649ed6d676e2de8f31..cea7508ab4561781710fcef6bc67caf6833e7a05 100644 --- a/src/meshTools/polyTopoChange/polyTopoChange.H +++ b/src/meshTools/polyTopoChange/polyTopoChange.H @@ -68,6 +68,7 @@ SourceFiles #include "DynamicList.H" #include "labelList.H" +#include "CompactListList.H" #include "pointField.H" #include "Map.H" #include "HashSet.H" @@ -78,7 +79,7 @@ SourceFiles namespace Foam { -// Forward declarations +// Forward Declarations class face; class primitiveMesh; class polyMesh; @@ -91,7 +92,6 @@ class topoAction; class objectMap; class IOobject; class mapPolyMesh; -template<class T, class Container> class CompactListList; /*---------------------------------------------------------------------------*\ Class polyTopoChange Declaration @@ -294,13 +294,13 @@ class polyTopoChange void makeCellCells ( const label nActiveFaces, - CompactListList<label, labelList>& cellCells + CompactListList<label>& cellCells ) const; //- Cell ordering (bandCompression). Returns number of remaining cells. label getCellOrder ( - const CompactListList<label, labelList>& cellCellAddressing, + const CompactListList<label>& cellCellAddressing, labelList& oldToNew ) const; diff --git a/src/overset/lduPrimitiveProcessorInterface/GAMG/calculatedProcessorGAMGInterfaceField.C b/src/overset/lduPrimitiveProcessorInterface/GAMG/calculatedProcessorGAMGInterfaceField.C index b856cd26a48db7aa023ceff7d8d07941bc7caecc..c67e0922c8ac77f3a589c7dfdc96515d688ec831 100644 --- a/src/overset/lduPrimitiveProcessorInterface/GAMG/calculatedProcessorGAMGInterfaceField.C +++ b/src/overset/lduPrimitiveProcessorInterface/GAMG/calculatedProcessorGAMGInterfaceField.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -115,8 +115,8 @@ void Foam::calculatedProcessorGAMGInterfaceField::initInterfaceMatrixUpdate ( Pstream::commsTypes::nonBlocking, procInterface_.neighbProcNo(), - reinterpret_cast<char*>(scalarReceiveBuf_.data()), - scalarReceiveBuf_.byteSize(), + scalarReceiveBuf_.data_bytes(), + scalarReceiveBuf_.size_bytes(), procInterface_.tag(), comm() ); @@ -126,8 +126,8 @@ void Foam::calculatedProcessorGAMGInterfaceField::initInterfaceMatrixUpdate ( Pstream::commsTypes::nonBlocking, procInterface_.neighbProcNo(), - reinterpret_cast<const char*>(scalarSendBuf_.cdata()), - scalarSendBuf_.byteSize(), + scalarSendBuf_.cdata_bytes(), + scalarSendBuf_.size_bytes(), procInterface_.tag(), comm() );