From 3781f17eeeb7772d44305df9393f1120924d5914 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Wed, 13 Oct 2021 15:14:47 +0200 Subject: [PATCH] ENH: add '_bytes()' versions of List data(), cdata() - simply adds in the reinterpret_cast, which simplifies coding for binary data movement. Name complements the size_bytes() method for contiguous data STYLE: container IO.C files into main headers for better visibility STYLE: include CompactListList.H in polyTopoChange - avoids future mismatches if the CompactListList template signature changes GIT: relocate CompactListList into CompactLists/ directory --- .../containers/Bits/PackedList/PackedList.H | 6 ++ .../containers/Bits/PackedList/PackedListI.H | 14 ++++ .../containers/Bits/PackedList/PackedListIO.C | 12 +--- .../CompactListList/CompactListList.C | 4 -- .../CompactListList/CompactListList.H | 1 + .../CompactListList/CompactListListI.H | 0 .../CompactListList/CompactListListIO.C | 0 .../BiIndirectList/BiIndirectList.H | 14 ++-- .../BiIndirectList/BiIndirectListI.H | 12 ++-- .../IndirectListBase/IndirectListAddressing.H | 8 +-- .../IndirectListBase/IndirectListBase.H | 2 +- .../Lists/DynamicList/DynamicList.H | 36 ++++++++-- .../Lists/DynamicList/DynamicListI.H | 59 ++-------------- .../Lists/DynamicList/DynamicListIO.C | 67 +++++++++++++++++++ .../containers/Lists/FixedList/FixedList.C | 12 ++-- .../containers/Lists/FixedList/FixedList.H | 39 ++++++++--- .../containers/Lists/FixedList/FixedListI.H | 16 +++++ .../containers/Lists/FixedList/FixedListIO.C | 33 +++------ src/OpenFOAM/containers/Lists/List/List.C | 4 -- src/OpenFOAM/containers/Lists/List/List.H | 13 +++- src/OpenFOAM/containers/Lists/List/ListIO.C | 13 ++-- src/OpenFOAM/containers/Lists/UList/UList.C | 4 -- src/OpenFOAM/containers/Lists/UList/UList.H | 38 +++++++---- src/OpenFOAM/containers/Lists/UList/UListI.H | 14 ++++ src/OpenFOAM/containers/Lists/UList/UListIO.C | 15 +---- .../containers/Lists/UList/stdVectorIO.C | 2 +- .../decomposedBlockData/decomposedBlockData.C | 4 +- .../IOstreams/Pstreams/combineGatherScatter.C | 8 +-- src/OpenFOAM/db/IOstreams/Pstreams/exchange.C | 8 +-- .../db/IOstreams/Pstreams/gatherScatterList.C | 8 +-- .../fields/Fields/DynamicField/DynamicField.H | 13 +++- .../Fields/DynamicField/DynamicFieldI.H | 26 ++++++- .../processorCyclicPointPatchField.C | 14 ++-- .../LUscalarMatrix/LUscalarMatrixTemplates.C | 4 +- src/OpenFOAM/matrices/Matrix/Matrix.C | 4 -- src/OpenFOAM/matrices/Matrix/Matrix.H | 32 ++++++++- src/OpenFOAM/matrices/Matrix/MatrixI.H | 14 ++++ src/OpenFOAM/matrices/Matrix/MatrixIO.C | 29 ++------ .../processorLduInterfaceTemplates.C | 6 +- .../processorGAMGInterfaceField.C | 10 +-- .../globalMeshData/globalIndexTemplates.C | 16 ++--- .../mapDistribute/mapDistributeBase.C | 18 ++--- .../mapDistributeBaseTemplates.C | 8 +-- .../polyMesh/syncTools/syncToolsTemplates.C | 8 +-- src/fileFormats/vtk/output/foamVtkOutput.C | 12 +--- .../vtk/output/foamVtkOutputTemplates.C | 48 +++---------- .../faMesh/faMeshDemandDrivenData.C | 4 +- .../calculatedProcessorFvPatchField.C | 23 ++++--- .../processor/processorFvPatchField.C | 35 ++++++---- src/meshTools/polyTopoChange/polyTopoChange.C | 3 +- src/meshTools/polyTopoChange/polyTopoChange.H | 8 +-- .../calculatedProcessorGAMGInterfaceField.C | 10 +-- 52 files changed, 464 insertions(+), 347 deletions(-) rename src/OpenFOAM/containers/{Lists => CompactLists}/CompactListList/CompactListList.C (98%) rename src/OpenFOAM/containers/{Lists => CompactLists}/CompactListList/CompactListList.H (99%) rename src/OpenFOAM/containers/{Lists => CompactLists}/CompactListList/CompactListListI.H (100%) rename src/OpenFOAM/containers/{Lists => CompactLists}/CompactListList/CompactListListIO.C (100%) create mode 100644 src/OpenFOAM/containers/Lists/DynamicList/DynamicListIO.C diff --git a/src/OpenFOAM/containers/Bits/PackedList/PackedList.H b/src/OpenFOAM/containers/Bits/PackedList/PackedList.H index 6bc3942c816..1ae6f228f25 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 95aa8e32d79..a525746d39b 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 c2b0ca7e637..b61897267f5 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 2f17099edda..ca1b88304a0 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 b9f80dda9b5..b9b2332307a 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 3d3036bb768..85847363382 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 7a84ff1abc1..d9ac3ce68d3 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 913b3fdfad9..b760a3d6fc5 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 c9b01667edc..ae540580057 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 378d54ab71a..d45d836afdc 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 911087b6e18..047aa3423ae 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 00000000000..5fa5e9d00fa --- /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 d0570f2a98c..0c8f0f13d9e 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 a79a318d06a..3a3a6c63ef8 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 78611d47640..d72b3fb9444 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 437b608f9b7..db491874a22 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 ef0df3dbca7..1a7186cace4 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 ebded60c266..4cb9815a42f 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 863603d8b80..4eb8b0e6925 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 3263d6f0c8a..c35bcf81abd 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 1fd97cb99ee..9c6b39cfdea 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 dc46db9fafd..ef5354e15a6 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 05923a379d0..42247829241 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 9f525e5ba1a..ba8db32641c 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 7470ad6c312..ee795672bf8 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 2e7627db904..e1c4f0cfc89 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 e5c9319c939..8d6352375de 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 a3282d1ece6..7de5fd1224d 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 0330f968d31..517d292afd5 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 835841d8b1e..8d41f1e3635 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 118b720c70b..0e4ab1e9e51 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 1c8d0fe6e73..159a6af98f3 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 1a45c0460ec..7de050fc9e7 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 e6882cbbe78..24eb0bd7e6b 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 c44b1d68539..707965a4c32 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 e6369d2cc28..b13f41097ae 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 1913b0ac9d6..70a5639ef60 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 2451f8f6e75..13ff33c5d55 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 9893418c00e..3db3c653fad 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 eabb9262202..d72d9e445b2 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 61813efd663..a16a88a2fc6 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 8e9d91dfd0e..aca1207b158 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 08a00cf6e40..7598e5c07f0 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 59bdb0e88fe..2717f19645f 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 63ec9815bdc..c70b7d9e0de 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 2713b4e8fb8..ba02bd7fa5b 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 c87c52a8d96..f13d8a4aeca 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 806ddb58b66..38013b4c3ce 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 d7661e4c43b..cea7508ab45 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 b856cd26a48..c67e0922c8a 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() ); -- GitLab