diff --git a/applications/test/PackedList/PackedListTest.C b/applications/test/PackedList/PackedListTest.C index a8488eb1836f7ed90af878965892d8843e6c63b4..41796562bade616f5b2336e26755cc1d3e43ac83 100644 --- a/applications/test/PackedList/PackedListTest.C +++ b/applications/test/PackedList/PackedListTest.C @@ -77,14 +77,22 @@ int main(int argc, char *argv[]) const PackedList<3>& constLst = list1; Info<< "\ntest operator[] const with out-of-range index\n"; constLst.print(Info); - if (!constLst[20]) + if (constLst[20]) + { + Info<< "[20] is true (unexpected)\n"; + } + else { Info<< "[20] is false (expected) list size should be unchanged (const)\n"; } constLst.print(Info); Info<< "\ntest operator[] non-const with out-of-range index\n"; - if (!list1[20]) + if (list1[20]) + { + Info<< "[20] is true (unexpected)\n"; + } + else { Info<< "[20] is false (expected) but list was resized?? (non-const)\n"; } @@ -268,6 +276,23 @@ int main(int argc, char *argv[]) Info<< "removed final value: " << list3.remove() << endl; list3.print(Info); + + List<bool> list4(4, true); + { + const List<bool>& constLst = list4; + Info<< "\ntest operator[] const with out-of-range index\n"; + Info<< constLst << endl; + if (constLst[20]) + { + Info<< "[20] is true (unexpected)\n"; + } + else + { + Info<< "[20] is false (expected) list size should be unchanged (const)\n"; + } + Info<< constLst << endl; + } + Info<< "\n\nDone.\n"; return 0; diff --git a/applications/test/primitivePatch/testPrimitivePatch.C b/applications/test/primitivePatch/testPrimitivePatch.C index 7130e90628f2cfb4fc87000802ac59f6d4053a95..e19b7d0512ba0517975e2395a3d5c5da8bc1694b 100644 --- a/applications/test/primitivePatch/testPrimitivePatch.C +++ b/applications/test/primitivePatch/testPrimitivePatch.C @@ -69,7 +69,7 @@ void checkFaceEdges forAll(f, fp) { - label fp1 = (fp + 1) % f.size(); + label fp1 = f.fcIndex(fp); if (edges[myEdges[fp]] != edge(f[fp], f[fp1])) { diff --git a/applications/utilities/mesh/advanced/collapseEdges/collapseEdges.C b/applications/utilities/mesh/advanced/collapseEdges/collapseEdges.C index c92418dc803e98f119ed83d90801a0074dd8a619..1dc59edb7c40390e868eda26f83b39970fad7658 100644 --- a/applications/utilities/mesh/advanced/collapseEdges/collapseEdges.C +++ b/applications/utilities/mesh/advanced/collapseEdges/collapseEdges.C @@ -74,20 +74,17 @@ labelList getSortedEdges const edge& e = edges[edgeI]; label fp = findIndex(f, e[0]); - - label fp1 = (fp+1) % f.size(); + label fp1 = f.fcIndex(fp); if (f[fp1] == e[1]) { - // Edgei in fp-fp1 order + // EdgeI between fp -> fp1 faceEdges[fp] = edgeI; } else { - // Edgei between fp-1 and fp - label fpMin1 = (fp == 0 ? f.size()-1 : fp-1); - - faceEdges[fpMin1] = edgeI; + // EdgeI between fp-1 -> fp + faceEdges[f.rcIndex(fp)] = edgeI; } } diff --git a/applications/utilities/mesh/advanced/modifyMesh/cellSplitter.C b/applications/utilities/mesh/advanced/modifyMesh/cellSplitter.C index ce532b979f67e0494842e3a828b9994d2f074c8e..3ae39131a10a8348efb9e1fcb530187840eb4ea0 100644 --- a/applications/utilities/mesh/advanced/modifyMesh/cellSplitter.C +++ b/applications/utilities/mesh/advanced/modifyMesh/cellSplitter.C @@ -211,7 +211,7 @@ void Foam::cellSplitter::setRefinement // Add other pyramids for (label i = 1; i < cFaces.size(); i++) - { + { label addedCellI = meshMod.setAction ( @@ -277,7 +277,7 @@ void Foam::cellSplitter::setRefinement label index = findIndex(f0, e[0]); - bool edgeInFaceOrder = (f0[(index+1) % f0.size()] == e[1]); + bool edgeInFaceOrder = (f0[f0.fcIndex(index)] == e[1]); // Check if cellI is the face owner @@ -323,7 +323,7 @@ void Foam::cellSplitter::setRefinement label index = findIndex(f1, e[0]); - bool edgeInFaceOrder = (f1[(index+1) % f1.size()] == e[1]); + bool edgeInFaceOrder = (f1[f1.fcIndex(index)] == e[1]); // Check if cellI is the face owner @@ -362,7 +362,7 @@ void Foam::cellSplitter::setRefinement } } } - + // // Update all existing faces for split owner or neighbour. @@ -441,7 +441,7 @@ void Foam::cellSplitter::setRefinement label patchID, zoneID, zoneFlip; getFaceInfo(faceI, patchID, zoneID, zoneFlip); - + meshMod.setAction ( polyModifyFace @@ -458,7 +458,7 @@ void Foam::cellSplitter::setRefinement ) ); } - + faceUpToDate[faceI] = true; } } diff --git a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.H b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.H index cb25ac50895f3a6ccc5d85b97822ff91ebf65bb4..af0fb849a4f46b594232e25fe1d67fdde6864ead 100644 --- a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.H +++ b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.H @@ -156,7 +156,7 @@ class vtkPV3Foam bool empty() const { - return (size_ == 0); + return !size_; } void reset() diff --git a/applications/utilities/surface/surfaceSplitNonManifolds/surfaceSplitNonManifolds.C b/applications/utilities/surface/surfaceSplitNonManifolds/surfaceSplitNonManifolds.C index 8968831e6445d0c6b16ec4d4719b5ec674555453..f7131d87db8483e4763ebb03ddac4fb6ffbcb7ed 100644 --- a/applications/utilities/surface/surfaceSplitNonManifolds/surfaceSplitNonManifolds.C +++ b/applications/utilities/surface/surfaceSplitNonManifolds/surfaceSplitNonManifolds.C @@ -351,7 +351,7 @@ label otherEdge return -1; } - + // Starting from startPoint on startEdge on startFace walk along border // and insert faces along the way. Walk keeps always one point or one edge @@ -461,18 +461,8 @@ label sharedFace label startIndex = findIndex(f, e.start()); - bool edgeOrder; - - if (f[(startIndex + 1) % f.size()] == e.end()) - { - // points in face in same order as edge - edgeOrder = true; - } - else - { - // points in face in reverse order as edge - edgeOrder = false; - } + // points in face in same order as edge + bool edgeOrder = (f[f.fcIndex(startIndex)] == e.end()); // Get faces using edge in sorted order. (sorted such that walking // around them in anti-clockwise order corresponds to edge vector @@ -485,25 +475,18 @@ label sharedFace if (edgeOrder) { // Get face before firstFaceI - if (faceIndex == 0) - { - return eFaces[eFaces.size() - 1]; - } - else - { - return eFaces[faceIndex - 1]; - } + return eFaces[eFaces.rcIndex(faceIndex)]; } else { // Get face after firstFaceI - return eFaces[(faceIndex+1) % eFaces.size()]; + return eFaces[eFaces.fcIndex(faceIndex)]; } } // Calculate (inward pointing) normals on edges shared by faces in faceToEdge and -// averages them to pointNormals. +// averages them to pointNormals. void calcPointVecs ( const triSurface& surf, @@ -602,7 +585,7 @@ void calcPointVecs } scalar magMidVec = mag(midVec); - + if (magMidVec > SMALL) { midVec /= magMidVec; @@ -925,7 +908,7 @@ int main(int argc, char *argv[]) newPoints[newPointI] = newPoints[pointI] + 0.1 * minLen * n; } } - + // // Renumber all faces in connectedFaces diff --git a/src/OSspecific/Unix/Unix.C b/src/OSspecific/Unix/Unix.C index f243c48ed4ac6508c5647c75e40f6dcc65630be5..9378a21c7caacf345d715be1a1cdc20b6e33a9d1 100644 --- a/src/OSspecific/Unix/Unix.C +++ b/src/OSspecific/Unix/Unix.C @@ -432,7 +432,7 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode) // Set the file mode -bool Foam::chmod(const fileName& name, const mode_t m) +bool Foam::chMod(const fileName& name, const mode_t m) { return ::chmod(name.c_str(), m) == 0; } diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C index ae9bcc2718776adca0557f7515d1c4d24042ae3f..3ed474b32db9ecfb9a518be93971fa2e1c35a063 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C @@ -226,7 +226,7 @@ bool Foam::HashTable<T, Key, Hash>::set const bool protect ) { - if (tableSize_ == 0) + if (!tableSize_) { resize(2); } @@ -556,7 +556,7 @@ void Foam::HashTable<T, Key, Hash>::operator= } // could be zero-sized from a previous transfer() - if (tableSize_ == 0) + if (!tableSize_) { resize(rhs.tableSize_); } diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H index 79ff3741453e3863093e73492307da9a636294bd..aea5f3043ad8dd6ed258c83df3a3a72bd49a6021 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H @@ -54,7 +54,7 @@ inline Foam::label Foam::HashTable<T, Key, Hash>::size() const template<class T, class Key, class Hash> inline bool Foam::HashTable<T, Key, Hash>::empty() const { - return (nElmts_ == 0); + return !nElmts_; } diff --git a/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTableI.H b/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTableI.H index 329437a07a40d774545c36cbb23a80b5db65a383..5cd380357a7c890c5e70c706f69abcc40a9b2c91 100644 --- a/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTableI.H +++ b/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTableI.H @@ -41,7 +41,7 @@ inline Foam::label Foam::StaticHashTable<T, Key, Hash>::size() const template<class T, class Key, class Hash> inline bool Foam::StaticHashTable<T, Key, Hash>::empty() const { - return (nElmts_ == 0); + return !nElmts_; } diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H index 9b80941bf9abaa9679b0df74c29769f15879bea1..bcc20289ca39662ff82a24c2461d03264de9f715 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H @@ -83,7 +83,7 @@ inline Foam::label Foam::DLListBase::size() const inline bool Foam::DLListBase::empty() const { - return (nElmts_ == 0); + return !nElmts_; } diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H index de34257d342f82751ebce088b4edd349744d684d..339963da5e5bf16cc3fe8abaa86508fb19006b91 100644 --- a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H +++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H @@ -73,7 +73,7 @@ inline Foam::label Foam::SLListBase::size() const inline bool Foam::SLListBase::empty() const { - return (nElmts_ == 0); + return !nElmts_; } diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H index 2e3ddf408bd474e74a46f3f51e5bf3387d96051f..0079f13a0290e09eeac0ec998d64242ff9c770a6 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H @@ -135,10 +135,21 @@ public: inline label fcIndex(const label i) const; //- Return the reverse circular index, i.e. the previous index - // which returns to the last at the begining of the list + // which returns to the last at the beginning of the list inline label rcIndex(const label i) const; + //- 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. + inline const T* cdata() const; + + //- 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. + inline T* data(); + + // Check //- Check start is within valid range (0 ... size-1). @@ -174,10 +185,10 @@ public: // Member operators - //- Return subscript-checked element of FixedList. + //- Return element of FixedList. inline T& operator[](const label); - //- Return subscript-checked element of constant FixedList. + //- Return element of constant FixedList. inline const T& operator[](const label) const; //- Assignment from array operator. Takes linear time. @@ -282,7 +293,7 @@ public: //- Return size of the largest possible FixedList. inline label max_size() const; - //- Return true if the FixedList is empty (i.e., if size() == 0). + //- Return true if the FixedList is empty (ie, size() is zero). inline bool empty() const; //- Swap two FixedLists of the same type in constant time. diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H index d618cb6e386751b804e433228c8633b5a4914e5d..a800b04b1d19d8527984215478763b6d14e333a4 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H @@ -121,7 +121,7 @@ inline Foam::label Foam::FixedList<T, Size>::fcIndex(const label i) const template<class T, Foam::label Size> inline Foam::label Foam::FixedList<T, Size>::rcIndex(const label i) const { - return (i == 0 ? Size-1 : i-1); + return (i ? i-1 : Size-1); } @@ -195,9 +195,26 @@ inline void Foam::FixedList<T, Size>::transfer(const FixedList<T, Size>& lst) } } + +template<class T, Foam::label Size> +inline const T* +Foam::FixedList<T, Size>::cdata() const +{ + return v_; +} + + +template<class T, Foam::label Size> +inline T* +Foam::FixedList<T, Size>::data() +{ + return v_; +} + + // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // -// Return subscript-checked element access +// element access template<class T, Foam::label Size> inline T& Foam::FixedList<T, Size>::operator[](const label i) { @@ -208,7 +225,7 @@ inline T& Foam::FixedList<T, Size>::operator[](const label i) } -// Return subscript-checked const element access +// const element access template<class T, Foam::label Size> inline const T& Foam::FixedList<T, Size>::operator[](const label i) const { diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C b/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C index b76bf3be242f3485f5ee6dd9d77aa0c5b305f263..49caad2a0adb439149b658609604157257f80a2a 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C @@ -119,7 +119,7 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& L) } else { - is.read(reinterpret_cast<char*>(L.begin()), Size*sizeof(T)); + is.read(reinterpret_cast<char*>(L.data()), Size*sizeof(T)); is.fatalCheck ( @@ -231,7 +231,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const FixedList<T, Size>& L) } else { - os.write(reinterpret_cast<const char*>(L.v_), Size*sizeof(T)); + os.write(reinterpret_cast<const char*>(L.cdata()), Size*sizeof(T)); } // Check state of IOstream diff --git a/src/OpenFOAM/containers/Lists/List/ListIO.C b/src/OpenFOAM/containers/Lists/List/ListIO.C index b7cb86c4ee785e39886390f058b68049f00c4015..7cfdfb0397f99049cf79076bdf70265189170686 100644 --- a/src/OpenFOAM/containers/Lists/List/ListIO.C +++ b/src/OpenFOAM/containers/Lists/List/ListIO.C @@ -117,7 +117,7 @@ Foam::Istream& Foam::operator>>(Istream& is, List<T>& L) { if (s) { - is.read(reinterpret_cast<char*>(L.begin()), s*sizeof(T)); + is.read(reinterpret_cast<char*>(L.data()), s*sizeof(T)); is.fatalCheck ( diff --git a/src/OpenFOAM/containers/Lists/ListOps/ListOps.H b/src/OpenFOAM/containers/Lists/ListOps/ListOps.H index b7e90d53d13c7bed9567d4947838ebc5d9d31089..7de9239d04deed112a68f7ddf745c5d1d933133c 100644 --- a/src/OpenFOAM/containers/Lists/ListOps/ListOps.H +++ b/src/OpenFOAM/containers/Lists/ListOps/ListOps.H @@ -90,17 +90,31 @@ void duplicateOrder(const UList<T>&, labelList& order); template<class T> void uniqueOrder(const UList<T>&, labelList& order); -//- Extract elements of List whose region is certain value. -// Use e.g. to extract all selected elements: -// subset<boolList, labelList>(selectedElems, true, lst); +//- Extract elements of List when select is a certain value. +// eg, to extract all selected elements: +// subset<bool, labelList>(selectedElems, true, lst); template<class T, class ListType> -ListType subset(const UList<T>& regions, const T& region, const ListType&); +ListType subset(const UList<T>& select, const T& value, const ListType&); -//- Inplace extract elements of List whose region is certain value. Use e.g. -// to extract all selected elements: -// inplaceSubset<boolList, labelList>(selectedElems, true, lst); +//- Inplace extract elements of List when select is a certain value. +// eg, to extract all selected elements: +// inplaceSubset<bool, labelList>(selectedElems, true, lst); template<class T, class ListType> -void inplaceSubset(const UList<T>& regions, const T& region, ListType&); +void inplaceSubset(const UList<T>& select, const T& value, ListType&); + +//- Extract elements of List when select is true +// eg, to extract all selected elements: +// subset<boolList, labelList>(selectedElems, lst); +// Note a labelHashSet could also be used for the bool-list +template<class BoolListType, class ListType> +ListType subset(const BoolListType& select, const ListType&); + +//- Inplace extract elements of List when select is true +// eg, to extract all selected elements: +// inplaceSubset<boolList, labelList>(selectedElems, lst); +// Note a labelHashSet could also be used for the bool-list +template<class BoolListType, class ListType> +void inplaceSubset(const BoolListType& select, ListType&); //- Invert one-to-one map. Unmapped elements will be -1. labelList invert(const label len, const UList<label>&); @@ -108,8 +122,9 @@ labelList invert(const label len, const UList<label>&); //- Invert one-to-many map. Unmapped elements will be size 0. labelListList invertOneToMany(const label len, const UList<label>&); -//- Invert many-to-many. Input and output types need to be inherited -// from List. E.g. faces to pointFaces. +//- Invert many-to-many. +// Input and output types need to be inherited from List. +// eg, faces to pointFaces. template<class InList, class OutList> void invertManyToMany(const label len, const UList<InList>&, List<OutList>&); diff --git a/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C b/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C index f12b5efd5542e5b7ec52303936b8d861bc7bd3d6..f2178ee38df53e583476328496325f068ef8fc34 100644 --- a/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C +++ b/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C @@ -243,16 +243,17 @@ void Foam::uniqueOrder template<class T, class ListType> ListType Foam::subset ( - const UList<T>& regions, - const T& region, + const UList<T>& select, + const T& value, const ListType& lst ) { - if (regions.size() < lst.size()) + // select must at least cover the list range + if (select.size() < lst.size()) { FatalErrorIn("subset(const UList<T>&, const T&, const ListType&)") - << "Regions is of size " << regions.size() - << "; list it is supposed to index is of size " << lst.size() + << "select is of size " << select.size() + << "; but it must index a list of size " << lst.size() << abort(FatalError); } @@ -261,7 +262,7 @@ ListType Foam::subset label nElem = 0; forAll(lst, elemI) { - if (regions[elemI] == region) + if (select[elemI] == value) { newLst[nElem++] = lst[elemI]; } @@ -275,23 +276,77 @@ ListType Foam::subset template<class T, class ListType> void Foam::inplaceSubset ( - const UList<T>& regions, - const T& region, + const UList<T>& select, + const T& value, ListType& lst ) { - if (regions.size() < lst.size()) + // select must at least cover the list range + if (select.size() < lst.size()) { FatalErrorIn("inplaceSubset(const UList<T>&, const T&, ListType&)") - << "Regions is of size " << regions.size() - << "; list it is supposed to index is of size " << lst.size() + << "select is of size " << select.size() + << "; but it must index a list of size " << lst.size() << abort(FatalError); } label nElem = 0; forAll(lst, elemI) { - if (regions[elemI] == region) + if (select[elemI] == value) + { + if (nElem != elemI) + { + lst[nElem] = lst[elemI]; + } + ++nElem; + } + } + + lst.setSize(nElem); +} + + +template<class BoolListType, class ListType> +ListType Foam::subset +( + const BoolListType& select, + const ListType& lst +) +{ + // select can have a different size + // eg, when it is a PackedBoolList or a labelHashSet + + ListType newLst(lst.size()); + + label nElem = 0; + forAll(lst, elemI) + { + if (select[elemI]) + { + newLst[nElem++] = lst[elemI]; + } + } + newLst.setSize(nElem); + + return newLst; +} + + +template<class BoolListType, class ListType> +void Foam::inplaceSubset +( + const BoolListType& select, + ListType& lst +) +{ + // select can have a different size + // eg, when it is a PackedBoolList or a labelHashSet + + label nElem = 0; + forAll(lst, elemI) + { + if (select[elemI]) { if (nElem != elemI) { diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedList.H b/src/OpenFOAM/containers/Lists/PackedList/PackedList.H index a9cd59da86c75742febc6d62c082d8886ecf1817..5f71976aa9d09c1730265fc7f21eb87136ddf8a1 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedList.H +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedList.H @@ -185,7 +185,7 @@ public: //- Number of entries. inline label size() const; - //- Return true if the list is empty (i.e., size() == 0). + //- Return true if the list is empty (ie, size() is zero). inline bool empty() const; //- Get value at index I. diff --git a/src/OpenFOAM/containers/Lists/PtrList/PtrList.H b/src/OpenFOAM/containers/Lists/PtrList/PtrList.H index 5de1345f10d6069e0534f4f9aa0811858590b667..b5167e5ef8977f02334642c9d31f32ed91ac16e3 100644 --- a/src/OpenFOAM/containers/Lists/PtrList/PtrList.H +++ b/src/OpenFOAM/containers/Lists/PtrList/PtrList.H @@ -158,7 +158,7 @@ public: //- Return the number of elements in the PtrList inline label size() const; - //- Return true if the PtrList is empty (i.e., if size() == 0). + //- Return true if the PtrList is empty (ie, size() is zero). inline bool empty() const; diff --git a/src/OpenFOAM/containers/Lists/UList/UList.H b/src/OpenFOAM/containers/Lists/UList/UList.H index 83c0913a5fee09a44c548ab396a24d512b641314..80bf066e19c7b6e2ba3211712e038ce3f3f4fdd1 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.H +++ b/src/OpenFOAM/containers/Lists/UList/UList.H @@ -27,7 +27,7 @@ Class Description A 1D vector of objects of type \<T\>, where the size of the vector is - known and used for subscript bounds checking, etc. + known and can be used for subscript bounds checking, etc. Storage is not allocated during construction or use but is supplied to the constructor as an argument. This type of list is particularly useful @@ -140,6 +140,17 @@ public: label byteSize() const; + //- 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. + inline const T* cdata() const; + + //- 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. + inline T* data(); + + // Check //- Check start is within valid range (0 ... size-1). @@ -164,10 +175,12 @@ public: // Member operators - //- Return subscript-checked element of UList. + //- Return element of UList. inline T& operator[](const label); - //- Return subscript-checked element of constant UList. + //- Return element of constant UList. + // Note that the bool specialization adds lazy evaluation so reading + // an out-of-range element returns false without any ill-effects inline const T& operator[](const label) const; //- Allow cast to a const List<T>& @@ -266,7 +279,7 @@ public: //- Return size of the largest possible UList. inline label max_size() const; - //- Return true if the UList is empty (i.e., if size() == 0). + //- Return true if the UList is empty (ie, size() is zero). inline bool empty() const; //- Swap two ULists of the same type in constant time. diff --git a/src/OpenFOAM/containers/Lists/UList/UListI.H b/src/OpenFOAM/containers/Lists/UList/UListI.H index 7d8d87006c8420fe6b7f5b79554c2590fee69f19..5c1df4be15c318df142cb195940dd5643b7db0d7 100644 --- a/src/OpenFOAM/containers/Lists/UList/UListI.H +++ b/src/OpenFOAM/containers/Lists/UList/UListI.H @@ -25,6 +25,7 @@ License \*---------------------------------------------------------------------------*/ #include "error.H" +#include "pTraits.H" #include "Swap.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -64,7 +65,7 @@ inline Foam::label Foam::UList<T>::fcIndex(const label i) const template<class T> inline Foam::label Foam::UList<T>::rcIndex(const label i) const { - return (i == 0 ? size()-1 : i-1); + return (i ? i-1 : size()-1); } @@ -113,9 +114,24 @@ inline void Foam::UList<T>::checkIndex(const label i) const } +template<class T> +inline const T* Foam::UList<T>::cdata() const +{ + return v_; +} + + +template<class T> +inline T* Foam::UList<T>::data() +{ + return v_; +} + + // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // -// Return subscript-checked element access + +// element access template<class T> inline T& Foam::UList<T>::operator[](const label i) { @@ -126,7 +142,28 @@ inline T& Foam::UList<T>::operator[](const label i) } -// Return subscript-checked const element access +namespace Foam +{ + + // Template specialization for bool + template<> + inline const bool& Foam::UList<bool>::operator[](const label i) const + { + // lazy evaluation - return false for out-of-range + if (i < size_) + { + return v_[i]; + } + else + { + return Foam::pTraits<bool>::zero; + } + } + +} // end of namespace Foam + + +// const element access template<class T> inline const T& Foam::UList<T>::operator[](const label i) const { @@ -248,7 +285,7 @@ inline Foam::label Foam::UList<T>::max_size() const template<class T> inline bool Foam::UList<T>::empty() const { - return (size_ == 0); + return !size_; } diff --git a/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H b/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H index cfcae367184a3b656c83e7d4d425d4e184e19781..a334e812543688364dbbde8b6754e4fff2542286 100644 --- a/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H +++ b/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H @@ -124,7 +124,7 @@ public: //- Return the number of elements in the UPtrList inline label size() const; - //- Return true if the UPtrList is empty (i.e., if size() == 0). + //- Return true if the UPtrList is empty (ie, size() is zero). inline bool empty() const; diff --git a/src/OpenFOAM/db/Time/Time.C b/src/OpenFOAM/db/Time/Time.C index f20055509e8645ce32c2f0366819556927e6569b..f2096b7968827712150b6d89bdf431ca0d196f9b 100644 --- a/src/OpenFOAM/db/Time/Time.C +++ b/src/OpenFOAM/db/Time/Time.C @@ -31,11 +31,7 @@ License // * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * * // -namespace Foam -{ - defineTypeNameAndDebug(Time, 0); -} - +defineTypeNameAndDebug(Foam::Time, 0); template<> const char* Foam::NamedEnum<Foam::Time::stopAtControls, 4>::names[] = @@ -100,9 +96,11 @@ void Foam::Time::adjustDeltaT() void Foam::Time::setControls() { // default is to resume calculation from "latestTime" - word startFrom("latestTime"); - - controlDict_.readIfPresent("startFrom", startFrom); + word startFrom = controlDict_.lookupOrDefault<word> + ( + "startFrom", + "latestTime" + ); if (startFrom == "startTime") { @@ -421,7 +419,7 @@ Foam::instant Foam::Time::findClosestTime(const scalar t) const label nearestIndex = -1; scalar deltaT = GREAT; - for (label i=1; i<times.size(); i++) + for (label i=1; i < times.size(); i++) { scalar diff = mag(times[i].value() - t); if (diff < deltaT) diff --git a/src/OpenFOAM/db/Time/timeSelector.C b/src/OpenFOAM/db/Time/timeSelector.C index 8b91422fac4a57d8aab97864f757a55ae3fe3e54..8cd7940ccff7884a15a245fabed7d3a0c0f14e15 100644 --- a/src/OpenFOAM/db/Time/timeSelector.C +++ b/src/OpenFOAM/db/Time/timeSelector.C @@ -103,7 +103,7 @@ Foam::List<Foam::instant> Foam::timeSelector::select const List<instant>& Times ) const { - return subset(selected(Times), true, Times); + return subset(selected(Times), Times); } @@ -112,7 +112,7 @@ void Foam::timeSelector::inplaceSelect List<instant>& Times ) const { - inplaceSubset(selected(Times), true, Times); + inplaceSubset(selected(Times), Times); } @@ -219,7 +219,7 @@ Foam::List<Foam::instant> Foam::timeSelector::select } } - return subset(selectTimes, true, timeDirs); + return subset(selectTimes, timeDirs); } else { diff --git a/src/OpenFOAM/db/scalarRange/scalarRanges.C b/src/OpenFOAM/db/scalarRange/scalarRanges.C index c7c7f4848670ebd8b7a2a421d7ce3bfd847e2207..c59e2b5a9d615e49c05bfa8432e51eaa9261c10d 100644 --- a/src/OpenFOAM/db/scalarRange/scalarRanges.C +++ b/src/OpenFOAM/db/scalarRange/scalarRanges.C @@ -123,7 +123,7 @@ Foam::List<Foam::scalar> Foam::scalarRanges::select const List<scalar>& values ) const { - return subset(selected(values), true, values); + return subset(selected(values), values); } @@ -132,7 +132,7 @@ void Foam::scalarRanges::inplaceSelect List<scalar>& values ) const { - inplaceSubset(selected(values), true, values); + inplaceSubset(selected(values), values); } diff --git a/src/OpenFOAM/include/OSspecific.H b/src/OpenFOAM/include/OSspecific.H index 5aaf2f6626372148c7d27e7fe0c5779eeb8345a0..e4227879a6a55f17fc35c8464885cade7c554f69 100644 --- a/src/OpenFOAM/include/OSspecific.H +++ b/src/OpenFOAM/include/OSspecific.H @@ -110,7 +110,7 @@ fileName findEtcFile(const fileName&, bool mandatory=false); bool mkDir(const fileName&, mode_t=0777); //- Set the file mode -bool chmod(const fileName&, const mode_t); +bool chMod(const fileName&, const mode_t); //- Return the file mode mode_t mode(const fileName&); diff --git a/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C b/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C index 345aed54cc7f4ba7ac00438c0e659297db79fb31..aa6d0d750fe14abf03ddff76ca5ca31d070cd7b3 100644 --- a/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C +++ b/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C @@ -44,7 +44,7 @@ void Foam::interpolationTable<Type>::readTable() // Check that the data are okay check(); - if (this->size() == 0) + if (this->empty()) { FatalErrorIn ( diff --git a/src/OpenFOAM/memory/tmp/refCount.H b/src/OpenFOAM/memory/tmp/refCount.H index d297997cb43ab5c1da5a845010f4c9b86bf48e83..6af7317cedc4179bf27a4bee3c2d71d6b7d4ad73 100644 --- a/src/OpenFOAM/memory/tmp/refCount.H +++ b/src/OpenFOAM/memory/tmp/refCount.H @@ -82,7 +82,7 @@ public: //- Return true if the reference count is zero bool okToDelete() const { - return (count_ == 0); + return !count_; } diff --git a/src/OpenFOAM/meshes/meshShapes/face/faceI.H b/src/OpenFOAM/meshes/meshShapes/face/faceI.H index 500798e532a14f9e6683d3292efc353bb308bb1c..57f5eeaf99ab4ffc1a6087a785723d693b48f89f 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/faceI.H +++ b/src/OpenFOAM/meshes/meshShapes/face/faceI.H @@ -36,7 +36,7 @@ inline Foam::label Foam::face::right(const label i) const // Edge to the left of face vertex i inline Foam::label Foam::face::left(const label i) const { - return i == 0 ? size() - 1 : (i - 1); + return i ? i-1 : size()-1; } diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshCheck.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshCheck.C index 8938faf69bcea9d710ed2cb749322802f84b6ad4..e73d1d078d2b41b6ccdf005bcf24823c7ff79774 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshCheck.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshCheck.C @@ -867,7 +867,7 @@ bool primitiveMesh::checkFaceAngles forAll(f, fp0) { // Get vertex after fp - label fp1 = (fp0 + 1) % f.size(); + label fp1 = f.fcIndex(fp0); // Normalized vector between two consecutive points vector e10(p[f[fp1]] - p[f[fp0]]); @@ -1636,12 +1636,12 @@ bool primitiveMesh::checkCommonOrder // Vertices before and after on curFace - label fpPlus1 = (fp+1) % curFace.size(); - label fpMin1 = (fp == 0 ? curFace.size()-1 : fp-1); + label fpPlus1 = curFace.fcIndex(fp); + label fpMin1 = curFace.rcIndex(fp); // Vertices before and after on nbFace - label nbPlus1 = (nb+1) % nbFace.size(); - label nbMin1 = (nb == 0 ? nbFace.size()-1 : nb-1); + label nbPlus1 = nbFace.fcIndex(nb); + label nbMin1 = nbFace.rcIndex(nb); // Find order of walking by comparing next points on both // faces. diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitivePatch/walkPatch.C b/src/OpenFOAM/meshes/primitiveMesh/primitivePatch/walkPatch.C index f49c8beca8baef9edc740b22808a8333bdeccc74..022cf60ab2eda992f268437c557c4497ce6b5bc0 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitivePatch/walkPatch.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitivePatch/walkPatch.C @@ -155,20 +155,10 @@ void Foam::walkPatch::faceToFace indexInFace_.append(fp); - // Visit neighbouring faces in order, starting at fp. for (label i = 0; i < f.size(); i++) { - label fp1; - if (reverse_) - { - fp1 = (fp == 0 ? f.size()-1 : fp-1); - } - else - { - fp1 = (fp + 1) % f.size(); - } - + label fp1 = reverse_ ? f.rcIndex(fp) : f.fcIndex(fp); label nbr = getNeighbour(faceI, fp, f[fp], f[fp1]); if diff --git a/src/dynamicMesh/boundaryMesh/octreeDataFaceList.C b/src/dynamicMesh/boundaryMesh/octreeDataFaceList.C index 575a0a0ef4f49298e48632ca267fa91681067168..c44c455c74f1cdc7a2fe56d6660cb60c5842cd7e 100644 --- a/src/dynamicMesh/boundaryMesh/octreeDataFaceList.C +++ b/src/dynamicMesh/boundaryMesh/octreeDataFaceList.C @@ -340,8 +340,8 @@ Foam::label Foam::octreeDataFaceList::getSampleType // Face intersection point lies on edge between two face triangles // Calculate edge normal as average of the two triangle normals - label fpPrev = (fp == 0 ? f.size()-1 : fp-1); - label fpNext = (fp + 1) % f.size(); + label fpPrev = f.rcIndex(fp); + label fpNext = f.fcIndex(fp); vector e = points[f[fp]] - ctr; vector ePrev = points[f[fpPrev]] - ctr; @@ -434,7 +434,7 @@ bool Foam::octreeDataFaceList::intersects // Disable picking up intersections behind us. scalar oldTol = intersection::setPlanarTol(0.0); - pointHit inter = + pointHit inter = f.ray ( start, @@ -486,7 +486,7 @@ bool Foam::octreeDataFaceList::findTightest else { // Construct bb around sample and myFar - const point dist2(fabs(dist.x()), fabs(dist.y()), fabs(dist.z())); + const point dist2(fabs(dist.x()), fabs(dist.y()), fabs(dist.z())); tightest.min() = sample - dist2; tightest.max() = sample + dist2; @@ -558,7 +558,7 @@ Foam::scalar Foam::octreeDataFaceList::calcNearest } return nearHit.distance(); } - + void Foam::octreeDataFaceList::write ( diff --git a/src/dynamicMesh/meshCut/cellCuts/cellCuts.C b/src/dynamicMesh/meshCut/cellCuts/cellCuts.C index 7e0e1fbb8d072ddf4fb0d74f672d6133d3d3709f..78bae37eb60efe41258d55495b4265ff2c819e6c 100644 --- a/src/dynamicMesh/meshCut/cellCuts/cellCuts.C +++ b/src/dynamicMesh/meshCut/cellCuts/cellCuts.C @@ -374,7 +374,7 @@ void Foam::cellCuts::calcFaceCuts() const label cutI = 0; // Do point-edge-point walk over face and collect all cuts. - // Problem is that we want to start from one of the endpoints of a + // Problem is that we want to start from one of the endpoints of a // string of connected cuts; we don't want to start somewhere in the // middle. @@ -387,17 +387,16 @@ void Foam::cellCuts::calcFaceCuts() const if (pointIsCut_[v0]) { - label fpMin1 = (fp == 0 ? f.size()-1 : fp-1); - label vMin1 = f[fpMin1]; + label vMin1 = f[f.rcIndex(fp)]; - if + if ( !pointIsCut_[vMin1] && !edgeIsCut_[findEdge(faceI, v0, vMin1)] ) { cuts[cutI++] = vertToEVert(v0); - startFp = (fp+1) % f.size(); + startFp = f.fcIndex(fp); break; } } @@ -408,7 +407,7 @@ void Foam::cellCuts::calcFaceCuts() const { forAll(f, fp) { - label fp1 = (fp+1) % f.size(); + label fp1 = f.fcIndex(fp); label v0 = f[fp]; label v1 = f[fp1]; @@ -438,7 +437,7 @@ void Foam::cellCuts::calcFaceCuts() const forAll(f, i) { - label fp1 = (fp+1) % f.size(); + label fp1 = f.fcIndex(fp); // Get the three items: current vertex, next vertex and edge // inbetween @@ -659,7 +658,7 @@ bool Foam::cellCuts::crossEdge return true; } else - { + { // No success. Restore state (i.e. backtrack) nVisited = oldNVisited; @@ -794,7 +793,7 @@ bool Foam::cellCuts::walkFace -// Walk across cuts (cut edges or cut vertices) of cell. Stops when hit cut +// Walk across cuts (cut edges or cut vertices) of cell. Stops when hit cut // already visited. Returns true when loop of 3 or more vertices found. bool Foam::cellCuts::walkCell ( @@ -1202,7 +1201,7 @@ Foam::labelList Foam::cellCuts::nonAnchorPoints if ( - findIndex(anchorPoints, pointI) == -1 + findIndex(anchorPoints, pointI) == -1 && findIndex(loop, vertToEVert(pointI)) == -1 ) { @@ -1556,7 +1555,7 @@ bool Foam::cellCuts::calcAnchors } prevStat = eStat; } - } + } } @@ -2135,7 +2134,7 @@ bool Foam::cellCuts::setFromCellLoop // Storage for points on one side of cell labelList anchorPoints; - okLoop = + okLoop = validLoop(cellI, loop, loopWeights, faceSplitCuts, anchorPoints); if (okLoop) @@ -3007,7 +3006,7 @@ void Foam::cellCuts::flip(const label cellI) mesh().cellPoints()[cellI], cellAnchorPoints_[cellI], loop - ); + ); } diff --git a/src/dynamicMesh/meshCut/cellLooper/geomCellLooper.C b/src/dynamicMesh/meshCut/cellLooper/geomCellLooper.C index 2576ff9867374721913fb4c4651b3c5e74a77840..1cca5d6111e78e5abceeaa4c48d78b29cc358820 100644 --- a/src/dynamicMesh/meshCut/cellLooper/geomCellLooper.C +++ b/src/dynamicMesh/meshCut/cellLooper/geomCellLooper.C @@ -53,7 +53,6 @@ namespace Foam { defineTypeNameAndDebug(geomCellLooper, 0); - addToRunTimeSelectionTable(cellLooper, geomCellLooper, word); } @@ -187,8 +186,8 @@ bool Foam::geomCellLooper::edgeEndsCut const edge& e = mesh().edges()[edgeI]; - label prevCut = loop[(index == 0 ? loop.size()-1 : index-1)]; - label nextCut = loop[(index == loop.size()-1 ? 0 : index+1)]; + const label prevCut = loop[loop.rcIndex(index)]; + const label nextCut = loop[loop.fcIndex(index)]; if (!isEdge(prevCut) && !isEdge(nextCut)) { @@ -360,7 +359,7 @@ bool Foam::geomCellLooper::cut } else { - // Cut through edge end point. Might be duplicate + // Cut through edge end point. Might be duplicate // since connected edge might also be snapped to same // endpoint so only insert if unique. label cut = vertToEVert(cutVertI); diff --git a/src/dynamicMesh/meshCut/meshModifiers/meshCutAndRemove/meshCutAndRemove.C b/src/dynamicMesh/meshCut/meshModifiers/meshCutAndRemove/meshCutAndRemove.C index 6cbf8ecfc0d3da07da0cd78f7549540081383e22..a8dfe9ffcae5f4094ae254ec0e12382120de8057 100644 --- a/src/dynamicMesh/meshCut/meshModifiers/meshCutAndRemove/meshCutAndRemove.C +++ b/src/dynamicMesh/meshCut/meshModifiers/meshCutAndRemove/meshCutAndRemove.C @@ -76,24 +76,11 @@ bool Foam::meshCutAndRemove::isIn return false; } - label nextIndex = (index + 1) % cuts.size(); - - if (cuts[nextIndex] == twoCuts[1]) - { - return true; - } - - - label prevIndex = (index == 0 ? cuts.size()-1 : index - 1); - - if (cuts[prevIndex] == twoCuts[1]) - { - return true; - } - else - { - return false; - } + return + ( + cuts[cuts.fcIndex(index)] == twoCuts[1] + || cuts[cuts.rcIndex(index)] == twoCuts[1] + ); } @@ -502,11 +489,11 @@ Foam::face Foam::meshCutAndRemove::addEdgeCutsToFace(const label faceI) const forAll(f, fp) { - // Duplicate face vertex . + // Duplicate face vertex. newFace[newFp++] = f[fp]; // Check if edge has been cut. - label fp1 = (fp + 1) % f.size(); + label fp1 = f.fcIndex(fp); HashTable<label, edge, Hash<edge> >::const_iterator fnd = addedPoints_.find(edge(f[fp], f[fp1])); @@ -558,7 +545,7 @@ Foam::face Foam::meshCutAndRemove::loopToFace newFace[newFaceI++] = vertI; - label nextCut = loop[(fp+1) % loop.size()]; + label nextCut = loop[loop.fcIndex(fp)]; if (!isEdge(nextCut)) { diff --git a/src/dynamicMesh/meshCut/meshModifiers/meshCutter/meshCutter.C b/src/dynamicMesh/meshCut/meshModifiers/meshCutter/meshCutter.C index 6a97db625685b39f31f1c7f7cc6a764e5ec77289..80e18af319a12c1504cda9ec4eaf23842d063f7a 100644 --- a/src/dynamicMesh/meshCut/meshModifiers/meshCutter/meshCutter.C +++ b/src/dynamicMesh/meshCut/meshModifiers/meshCutter/meshCutter.C @@ -72,24 +72,11 @@ bool Foam::meshCutter::isIn return false; } - label nextIndex = (index + 1) % cuts.size(); - - if (cuts[nextIndex] == twoCuts[1]) - { - return true; - } - - - label prevIndex = (index == 0 ? cuts.size()-1 : index - 1); - - if (cuts[prevIndex] == twoCuts[1]) - { - return true; - } - else - { - return false; - } + return + ( + cuts[cuts.fcIndex(index)] == twoCuts[1] + || cuts[cuts.rcIndex(index)] == twoCuts[1] + ); } @@ -459,7 +446,7 @@ Foam::face Foam::meshCutter::addEdgeCutsToFace(const label faceI) const newFace[newFp++] = f[fp]; // Check if edge has been cut. - label fp1 = (fp + 1) % f.size(); + label fp1 = f.fcIndex(fp); HashTable<label, edge, Hash<edge> >::const_iterator fnd = addedPoints_.find(edge(f[fp], f[fp1])); @@ -511,7 +498,7 @@ Foam::face Foam::meshCutter::loopToFace newFace[newFaceI++] = vertI; - label nextCut = loop[(fp+1) % loop.size()]; + label nextCut = loop[loop.fcIndex(fp)]; if (!isEdge(nextCut)) { diff --git a/src/dynamicMesh/motionSmoother/polyMeshGeometry/polyMeshGeometry.C b/src/dynamicMesh/motionSmoother/polyMeshGeometry/polyMeshGeometry.C index 851c8cdec422c558924297b59715dc53a0e8efac..f2f7ec17bee2590ad940f864d3823d1307174323 100644 --- a/src/dynamicMesh/motionSmoother/polyMeshGeometry/polyMeshGeometry.C +++ b/src/dynamicMesh/motionSmoother/polyMeshGeometry/polyMeshGeometry.C @@ -1284,7 +1284,7 @@ bool Foam::polyMeshGeometry::checkFaceAngles forAll(f, fp0) { // Get vertex after fp - label fp1 = (fp0 + 1) % f.size(); + label fp1 = f.fcIndex(fp0); // Normalized vector between two consecutive points vector e10(p[f[fp1]] - p[f[fp0]]); diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/combineFaces.C b/src/dynamicMesh/polyTopoChange/polyTopoChange/combineFaces.C index caa3642f5c9d1d4e78404a565c4d3e2db30fb6fd..e0fae6f9712208aec54fee1a9014d160a518276a 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/combineFaces.C +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/combineFaces.C @@ -69,7 +69,7 @@ bool Foam::combineFaces::convexFace forAll(f, fp0) { // Get vertex after fp - label fp1 = (fp0 + 1) % f.size(); + label fp1 = f.fcIndex(fp0); // Normalized vector between two consecutive points vector e10(points[f[fp1]] - points[f[fp0]]); @@ -730,7 +730,7 @@ void Foam::combineFaces::setRefinement } else { - // Count removed points + // Count removed points label n = 0; forAll(nPointFaces, pointI) { diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/faceCollapser.C b/src/dynamicMesh/polyTopoChange/polyTopoChange/faceCollapser.C index 3bb5c345d3d7ec1e2ae83dada361e3376a8e811b..da303ca404ded83cef9d40cf3046dab7d467e2b2 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/faceCollapser.C +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/faceCollapser.C @@ -71,7 +71,7 @@ Foam::label Foam::faceCollapser::findEdge label edgeI = edgeLabels[i]; const edge& e = edges[edgeI]; - + if ( (e[0] == v0 && e[1] == v1) @@ -113,7 +113,7 @@ void Foam::faceCollapser::filterFace newFace.append(v0); // Look ahead one to get edge. - label fp1 = (fp + 1) % f.size(); + label fp1 = f.fcIndex(fp); label v1 = f[fp1]; @@ -410,7 +410,7 @@ void Foam::faceCollapser::setRefinement forAll(f, fp) { - label fp1 = (fp + 1) % f.size(); + label fp1 = f.fcIndex(fp); // Get index in sorted list label sorted0 = sortedFp[fp]; diff --git a/src/meshTools/cellFeatures/cellFeatures.C b/src/meshTools/cellFeatures/cellFeatures.C index 605624473b5ab3e343a4e86196c287093b6990cf..8d3170dca39c7a620a51b47f3446c06df3551ab6 100644 --- a/src/meshTools/cellFeatures/cellFeatures.C +++ b/src/meshTools/cellFeatures/cellFeatures.C @@ -50,7 +50,7 @@ bool Foam::cellFeatures::faceAlignedEdge(const label faceI, const label edgeI) { if (f[fp] == e.start()) { - label fp1 = (fp + 1) % f.size(); + label fp1 = f.fcIndex(fp); return f[fp1] == e.end(); } @@ -112,7 +112,7 @@ Foam::label Foam::cellFeatures::nextEdge << thisEdgeI << " at vertex " << thisVertI << endl << "This might mean that the externalEdges do not form a closed loop" << abort(FatalError); - + return -1; } @@ -146,12 +146,12 @@ bool Foam::cellFeatures::isCellFeatureEdge const face& f0 = mesh_.faces()[face0]; label face0Start = findIndex(f0, e.start()); - label face0End = (face0Start + 1) % f0.size(); + label face0End = f0.fcIndex(face0Start); const face& f1 = mesh_.faces()[face1]; label face1Start = findIndex(f1, e.start()); - label face1End = (face1Start + 1) % f1.size(); + label face1End = f1.fcIndex(face1Start); if ( @@ -268,7 +268,7 @@ void Foam::cellFeatures::calcSuperFaces() const { faceMap_[superI].shrink(); } - + // Construct superFaces diff --git a/src/meshTools/octree/octreeDataFace.C b/src/meshTools/octree/octreeDataFace.C index c8b9e7943c6e0f088e5fa5113313b2bbb69d6759..d93234f05c9871a8f1af971f102d1385857d336e 100644 --- a/src/meshTools/octree/octreeDataFace.C +++ b/src/meshTools/octree/octreeDataFace.C @@ -440,8 +440,8 @@ Foam::label Foam::octreeDataFace::getSampleType // Face intersection point lies on edge between two face triangles // Calculate edge normal as average of the two triangle normals - label fpPrev = (fp == 0 ? f.size()-1 : fp-1); - label fpNext = (fp + 1) % f.size(); + const label fpPrev = f.rcIndex(fp); + const label fpNext = f.fcIndex(fp); vector e = points[f[fp]] - mesh_.faceCentres()[faceI]; vector ePrev = points[f[fpPrev]] - mesh_.faceCentres()[faceI]; @@ -530,7 +530,7 @@ bool Foam::octreeDataFace::overlaps forAll(f, fp) { - label fp1 = (fp == f.size()-1 ? 0 : fp+1); + const label fp1 = f.fcIndex(fp); bool triIntersects = triangleFuncs::intersectBb ( diff --git a/src/meshTools/primitiveMeshGeometry/primitiveMeshGeometry.C b/src/meshTools/primitiveMeshGeometry/primitiveMeshGeometry.C index a0a237b8f1ade8d17365374ed978c000396e22e3..0b226e3e0241d100ad05e63f60eb5176831dd039 100644 --- a/src/meshTools/primitiveMeshGeometry/primitiveMeshGeometry.C +++ b/src/meshTools/primitiveMeshGeometry/primitiveMeshGeometry.C @@ -808,7 +808,7 @@ bool Foam::primitiveMeshGeometry::checkFaceAngles forAll(f, fp0) { // Get vertex after fp - label fp1 = (fp0 + 1) % f.size(); + label fp1 = f.fcIndex(fp0); // Normalized vector between two consecutive points vector e10(p[f[fp1]] - p[f[fp0]]); diff --git a/src/meshTools/triSurface/booleanOps/booleanSurface/booleanSurface.C b/src/meshTools/triSurface/booleanOps/booleanSurface/booleanSurface.C index ba61f6cb41cc4947eb83cba519e34dad39cc0246..3e007c880e8d80680ba91e338ff0d2ecb1c9aa93 100644 --- a/src/meshTools/triSurface/booleanOps/booleanSurface/booleanSurface.C +++ b/src/meshTools/triSurface/booleanOps/booleanSurface/booleanSurface.C @@ -241,14 +241,14 @@ void Foam::booleanSurface::propagateEdgeSide { // Edge (and hence eFaces) in same order as prevVert0. // Take next face from sorted list - nextInd = (ind + 1) % eFaces.size(); - prevInd = (ind > 0 ? ind - 1 : eFaces.size()-1); + nextInd = eFaces.fcIndex(ind); + prevInd = eFaces.rcIndex(ind); } else { // Take previous face from sorted neighbours - nextInd = (ind > 0 ? ind - 1 : eFaces.size()-1); - prevInd = (ind + 1) % eFaces.size(); + nextInd = eFaces.rcIndex(ind); + prevInd = eFaces.fcIndex(ind); } diff --git a/src/meshTools/triSurface/booleanOps/intersectedSurface/intersectedSurface.C b/src/meshTools/triSurface/booleanOps/intersectedSurface/intersectedSurface.C index eadfeb7c4b664bc2debb273e897b1c25b0007831..9450865081106b2747a9be30c70e358fc711e147 100644 --- a/src/meshTools/triSurface/booleanOps/intersectedSurface/intersectedSurface.C +++ b/src/meshTools/triSurface/booleanOps/intersectedSurface/intersectedSurface.C @@ -222,11 +222,11 @@ bool Foam::intersectedSurface::sameEdgeOrder { // Get prev/next vertex on fA label vA1 = fA[(fpA + 1) % 3]; - label vAMin1 = fA[fpA == 0 ? 2 : fpA-1]; + label vAMin1 = fA[fpA ? fpA-1 : 2]; // Get prev/next vertex on fB label vB1 = fB[(fpB + 1) % 3]; - label vBMin1 = fB[fpB == 0 ? 2 : fpB-1]; + label vBMin1 = fB[fpB ? fpB-1 : 2]; if (vA1 == vB1 || vAMin1 == vBMin1) { @@ -1308,14 +1308,14 @@ Foam::intersectedSurface::intersectedSurface // Construct mapping back into original surface faceMap_.setSize(size()); - for(label faceI = 0; faceI < surf.size()-1; faceI++) + for (label faceI = 0; faceI < surf.size()-1; faceI++) { - for(label triI = startTriI[faceI]; triI < startTriI[faceI+1]; triI++) + for (label triI = startTriI[faceI]; triI < startTriI[faceI+1]; triI++) { faceMap_[triI] = faceI; } } - for(label triI = startTriI[surf.size()-1]; triI < size(); triI++) + for (label triI = startTriI[surf.size()-1]; triI < size(); triI++) { faceMap_[triI] = surf.size()-1; } diff --git a/src/surfMesh/BasicMeshedSurface/BasicMeshedSurface.C b/src/surfMesh/BasicMeshedSurface/BasicMeshedSurface.C index 62c4bc452be7138169ae5efa1592a9cafcdc8a2a..41295b44b610453809db3818f56ac15cbcfa21db 100644 --- a/src/surfMesh/BasicMeshedSurface/BasicMeshedSurface.C +++ b/src/surfMesh/BasicMeshedSurface/BasicMeshedSurface.C @@ -473,7 +473,7 @@ Foam::label Foam::BasicMeshedSurface<Face>::triangulate for (label fp = 1; fp < f.size() - 1; ++fp) { - label fp1 = (fp + 1) % f.size(); + label fp1 = f.fcIndex(fp); newFaces[newFaceI] = triFace(f[0], f[fp], f[fp1]); faceMap[newFaceI] = faceI; diff --git a/src/surfMesh/surfMesh/surfMesh.C b/src/surfMesh/surfMesh/surfMesh.C index a29e6cfeeddfce13eee1df3594ad980d9ddd375f..c6166345da5b69bf32179e404f4df298bc27bdf6 100644 --- a/src/surfMesh/surfMesh/surfMesh.C +++ b/src/surfMesh/surfMesh/surfMesh.C @@ -269,6 +269,22 @@ void Foam::surfMesh::transfer } +Foam::Xfer< Foam::MeshedSurface<Foam::face> > +Foam::surfMesh::xfer() +{ + Xfer< MeshedSurface<face> > xf; + + xf().storedPoints().transfer(storedPoints_); + xf().storedFaces().transfer(storedFaces_); + xf().storedZones().transfer(surfZones_); + + // Clear addressing. + MeshReference::clearGeom(); + + return xf; +} + + void Foam::surfMesh::rename(const word& newName) { FatalErrorIn diff --git a/src/surfMesh/surfMesh/surfMesh.H b/src/surfMesh/surfMesh/surfMesh.H index b18080a6f5aa589af9a8683e1f51e5b7a8fc0362..358620fd61783225cec6bcbf1c36270087c88684 100644 --- a/src/surfMesh/surfMesh/surfMesh.H +++ b/src/surfMesh/surfMesh/surfMesh.H @@ -315,6 +315,9 @@ public: // Storage management + //- Transfer contents to the Xfer container as a MeshedSurface + Xfer< MeshedSurface<face> > xfer(); + //- Clear geometry void clearGeom(); diff --git a/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C index 167a98003b3824956dd34e9af73a513f622bda9e..8347bdeee8f508040163ccd3a7df827868a7765e 100644 --- a/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C @@ -227,7 +227,7 @@ bool Foam::fileFormats::AC3DsurfaceFormat<Face>::read // points may be incomplete for (label fp1 = 1; fp1 < f.size() - 1; ++fp1) { - label fp2 = (fp1 + 1) % f.size(); + label fp2 = f.fcIndex(fp1); dynFaces.append(triFace(f[0], f[fp1], f[fp2])); sizes[zoneI]++; diff --git a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C index 8500ab66d18e856a1c98d3ff6882b7fbfa2c6593..db4295ce64d5b6f334e96073dd1c9ab4df251824 100644 --- a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C @@ -182,7 +182,7 @@ bool Foam::fileFormats::OBJsurfaceFormat<Face>::read // points may be incomplete for (label fp1 = 1; fp1 < f.size() - 1; fp1++) { - label fp2 = (fp1 + 1) % f.size(); + label fp2 = f.fcIndex(fp1); dynFaces.append(triFace(f[0], f[fp1], f[fp2])); dynZones.append(zoneI); diff --git a/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.C b/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.C index 748f390d9968393d7fe2130682975342ac63b431..7e73affa17d2e97855beac7efb255f97fe9e9a49 100644 --- a/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/off/OFFsurfaceFormat.C @@ -130,7 +130,7 @@ bool Foam::fileFormats::OFFsurfaceFormat<Face>::read // cannot use face::triangulation (points may be incomplete) for (label fp1 = 1; fp1 < f.size() - 1; fp1++) { - label fp2 = (fp1 + 1) % f.size(); + label fp2 = f.fcIndex(fp1); dynFaces.append(triFace(f[0], f[fp1], f[fp2])); } diff --git a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C index 6f5dac06aea5cdf7675f11f7bd0f0fef4e80a21f..bbc1c097303d5975f67acd06099545a1ca2ba86a 100644 --- a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C @@ -54,7 +54,7 @@ inline void Foam::fileFormats::STLsurfaceFormat<Face>::writeShell const point& p0 = pointLst[f[0]]; for (label fp1 = 1; fp1 < f.size() - 1; ++fp1) { - label fp2 = (fp1 + 1) % f.size(); + label fp2 = f.fcIndex(fp1); const point& p1 = pointLst[f[fp1]]; const point& p2 = pointLst[f[fp2]]; @@ -95,7 +95,7 @@ inline void Foam::fileFormats::STLsurfaceFormat<Face>::writeShell const point& p0 = pointLst[f[0]]; for (label fp1 = 1; fp1 < f.size() - 1; ++fp1) { - label fp2 = (fp1 + 1) % f.size(); + label fp2 = f.fcIndex(fp1); STLtriangle stlTri ( diff --git a/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.C b/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.C index 5246cfdfc2b9b46b74ffcfa7ac3d7baf1ec60bc3..2058b3e8f3c0d8eb20547d1d426effa26c2ab68e 100644 --- a/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.C @@ -45,7 +45,7 @@ inline void Foam::fileFormats::TRIsurfaceFormat<Face>::writeShell const point& p0 = pointLst[f[0]]; for (label fp1 = 1; fp1 < f.size() - 1; ++fp1) { - label fp2 = (fp1 + 1) % f.size(); + label fp2 = f.fcIndex(fp1); const point& p1 = pointLst[f[fp1]]; const point& p2 = pointLst[f[fp2]]; diff --git a/src/triSurface/faceTriangulation/faceTriangulation.C b/src/triSurface/faceTriangulation/faceTriangulation.C index 0317c3a94630bf0e37979eb5391c118dc2a29cd8..a2f1ed2aa087cebabca1028a1a3e6c05d9270566 100644 --- a/src/triSurface/faceTriangulation/faceTriangulation.C +++ b/src/triSurface/faceTriangulation/faceTriangulation.C @@ -33,17 +33,17 @@ License const Foam::scalar Foam::faceTriangulation::edgeRelTol = 1E-6; -//- Edge to the right of face vertex i +// Edge to the right of face vertex i Foam::label Foam::faceTriangulation::right(const label, label i) { return i; } -//- Edge to the left of face vertex i +// Edge to the left of face vertex i Foam::label Foam::faceTriangulation::left(const label size, label i) { - return i == 0 ? size - 1 : (i - 1); + return i ? i-1 : size-1; } @@ -60,10 +60,8 @@ Foam::tmp<Foam::vectorField> Foam::faceTriangulation::calcEdges forAll(f, i) { - label ni = f.fcIndex(i); - point thisPt = points[f[i]]; - point nextPt = points[f[ni]]; + point nextPt = points[f[f.fcIndex(i)]]; vector vec(nextPt - thisPt); vec /= mag(vec) + VSMALL; @@ -109,7 +107,7 @@ void Foam::faceTriangulation::calcHalfAngle // Return true and intersection point if intersection between p1 and p2. Foam::pointHit Foam::faceTriangulation::rayEdgeIntersect ( - const vector& normal, + const vector& normal, const point& rayOrigin, const vector& rayDir, const point& p1, @@ -225,10 +223,10 @@ void Foam::faceTriangulation::findDiagonal label minIndex = -1; scalar minPosOnEdge = GREAT; - for(label i = 0; i < f.size() - 2; i++) + for (label i = 0; i < f.size() - 2; i++) { scalar posOnEdge; - pointHit inter = + pointHit inter = rayEdgeIntersect ( normal, @@ -258,7 +256,7 @@ void Foam::faceTriangulation::findDiagonal index1 = -1; index2 = -1; - return; + return; } const label leftIndex = minIndex; @@ -299,7 +297,7 @@ void Foam::faceTriangulation::findDiagonal // all vertices except for startIndex and ones to left and right of it. faceVertI = f.fcIndex(f.fcIndex(startIndex)); - for(label i = 0; i < f.size() - 3; i++) + for (label i = 0; i < f.size() - 3; i++) { const point& pt = points[f[faceVertI]]; @@ -400,7 +398,7 @@ Foam::label Foam::faceTriangulation::findStart return minIndex; } - + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // diff --git a/src/triSurface/triSurface/interfaces/OBJ/readOBJ.C b/src/triSurface/triSurface/interfaces/OBJ/readOBJ.C index cfab7e726f84593ec2025d49523debff5463e583..20c3d9cc65d4ebda88b31578e000283efac832c0 100644 --- a/src/triSurface/triSurface/interfaces/OBJ/readOBJ.C +++ b/src/triSurface/triSurface/interfaces/OBJ/readOBJ.C @@ -153,7 +153,7 @@ bool triSurface::readOBJ(const fileName& OBJfileName) // Cannot use face::triangulation since no complete points yet. for (label fp = 1; fp < verts.size() - 1; fp++) { - label fp1 = (fp + 1) % verts.size(); + label fp1 = verts.fcIndex(fp); labelledTri tri(verts[0], verts[fp], verts[fp1], groupID);