diff --git a/src/OpenFOAM/containers/Lists/ListOps/ListOps.H b/src/OpenFOAM/containers/Lists/ListOps/ListOps.H index c322c7856f..cbaf373a44 100644 --- a/src/OpenFOAM/containers/Lists/ListOps/ListOps.H +++ b/src/OpenFOAM/containers/Lists/ListOps/ListOps.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -226,7 +226,7 @@ label findLower ( const ListType&, typename ListType::const_reference, - const label stary, + const label start, const BinaryOp& bop ); @@ -263,6 +263,15 @@ public: }; +//- Helper class for list to append unique elelements of y onto the end of x +template +class ListUniqueEqOp +{ +public: + void operator()(List& x, const List& y) const; +}; + + //- Reverse a list. First element becomes last element etc. template ListType reverseList(const ListType& list); diff --git a/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C b/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C index 29ea650551..7aabfd7964 100644 --- a/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C +++ b/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -742,6 +742,29 @@ void Foam::ListAppendEqOp::operator()(List& x, const List& y) const } +template +void Foam::ListUniqueEqOp::operator()(List& x, const List& y) const +{ + if (y.size()) + { + if (x.size()) + { + forAll(y, i) + { + if (findIndex(x, y[i]) == -1) + { + x.append(y[i]); + } + } + } + else + { + x = y; + } + } +} + + template ListType Foam::reverseList(const ListType& list) { diff --git a/src/OpenFOAM/containers/Lists/UList/UListI.H b/src/OpenFOAM/containers/Lists/UList/UListI.H index 815c9aafcd..ba72bc8871 100644 --- a/src/OpenFOAM/containers/Lists/UList/UListI.H +++ b/src/OpenFOAM/containers/Lists/UList/UListI.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -101,7 +101,7 @@ inline void Foam::UList::checkIndex(const label i) const if (!size_) { FatalErrorIn("UList::checkIndex(const label)") - << "attempt to access element from zero sized list" + << "attempt to access element " << i << " from zero sized list" << abort(FatalError); } else if (i<0 || i>=size_) diff --git a/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.C b/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.C index cc54117f8b..0d1a2fe63f 100644 --- a/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.C +++ b/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -43,6 +43,30 @@ Foam::UPtrList::UPtrList(const label s) {} +template +Foam::UPtrList::UPtrList(UList& lst) +: + ptrs_(lst.size()) +{ + forAll(lst, i) + { + ptrs_[i] = &lst[i]; + } +} + + +template +Foam::UPtrList::UPtrList(PtrList& lst) +: + ptrs_(lst.size()) +{ + forAll(lst, i) + { + ptrs_[i] = &lst[i]; + } +} + + template Foam::UPtrList::UPtrList(const Xfer >& lst) { diff --git a/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H b/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H index cdf32f630a..4df5a82627 100644 --- a/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H +++ b/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -42,6 +42,7 @@ SourceFiles #define UPtrList_H #include "List.H" +#include "PtrList.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -109,6 +110,12 @@ public: //- Construct with size specified. explicit UPtrList(const label); + //- Construct from UList + explicit UPtrList(UList&); + + //- Construct from PtrList + explicit UPtrList(PtrList&); + //- Construct by transferring the parameter contents UPtrList(const Xfer >&); diff --git a/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C b/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C index a7ada172d4..e723e6ad5e 100644 --- a/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C +++ b/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -58,6 +58,23 @@ void Foam::CompactIOList::readFromStream() } +template +bool Foam::CompactIOList::overflows() const +{ + label size = 0; + forAll(*this, i) + { + label oldSize = size; + size += this->operator[](i).size(); + if (size < oldSize) + { + return true; + } + } + return false; +} + + // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * // template @@ -178,6 +195,29 @@ bool Foam::CompactIOList::writeObject return good; } + else if (overflows()) + { + WarningIn + ( + "CompactIOList::writeObject" + "(IOstream::streamFormat, IOstream::versionNumber" + ", IOstream::compressionType) const" + ) << "Overall number of elements of CompactIOList of size " + << this->size() << " overflows the representation of a label" + << endl << " Switching to ascii writing" << endl; + + // Change type to be non-compact format type + const word oldTypeName = typeName; + + const_cast(typeName) = IOList::typeName; + + bool good = regIOobject::writeObject(IOstream::ASCII, ver, cmp); + + // Change type back + const_cast(typeName) = oldTypeName; + + return good; + } else { return regIOobject::writeObject(fmt, ver, cmp); @@ -264,7 +304,22 @@ Foam::Ostream& Foam::operator<< start[0] = 0; for (label i = 1; i < start.size(); i++) { - start[i] = start[i-1]+L[i-1].size(); + label prev = start[i-1]; + start[i] = prev+L[i-1].size(); + + if (start[i] < prev) + { + FatalIOErrorIn + ( + "operator<<" + "(Ostream& os, const CompactIOList&)", + os + ) << "Overall number of elements " << start[i] + << " of CompactIOList of size " + << L.size() << " overflows the representation of a label" + << endl << "Please recompile with a larger representation" + << " for label" << exit(FatalIOError); + } } List elems(start[start.size()-1]); diff --git a/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.H b/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.H index dc06092c59..fafcdef52f 100644 --- a/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.H +++ b/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -79,6 +79,9 @@ class CompactIOList //- Read according to header type void readFromStream(); + //- Has too many elements in it? + bool overflows() const; + public: //- Runtime type information diff --git a/src/parallel/decompose/decompositionMethods/decompositionMethod/minData.H b/src/meshTools/regionSplit/minData.H similarity index 100% rename from src/parallel/decompose/decompositionMethods/decompositionMethod/minData.H rename to src/meshTools/regionSplit/minData.H diff --git a/src/parallel/decompose/decompositionMethods/decompositionMethod/minDataI.H b/src/meshTools/regionSplit/minDataI.H similarity index 100% rename from src/parallel/decompose/decompositionMethods/decompositionMethod/minDataI.H rename to src/meshTools/regionSplit/minDataI.H