diff --git a/applications/test/DynamicList/DynamicListTest.C b/applications/test/DynamicList/DynamicListTest.C index 324c5361bb78b967522476d2e58c69b83473e35f..355c65605fe0210fce847c34152def5943a6b6b3 100644 --- a/applications/test/DynamicList/DynamicListTest.C +++ b/applications/test/DynamicList/DynamicListTest.C @@ -160,18 +160,33 @@ int main(int argc, char *argv[]) << " " << lstB.size() << endl; Info<< "<dlD>" << dlD << "</dlD>" << nl << "sizes: " << " " << dlD.size() << "/" << dlD.capacity() << endl; - + DynamicList<label,10> dlE1(10); - DynamicList<label> dlE2(dlE1); + DynamicList<label> dlE2(dlE1); // construct dissimilar Info<< "<dlE1>" << dlE1 << "</dlE1>" << nl << "sizes: " << " " << dlE1.size() << "/" << dlE1.capacity() << endl; Info<< "<dlE2>" << dlE2 << "</dlE2>" << nl << "sizes: " << " " << dlE2.size() << "/" << dlE2.capacity() << endl; - dlE2.append(100); + for (label elemI=0; elemI < 5; ++elemI) + { + dlE1.append(4 - elemI); + dlE2.append(elemI); + } + Info<< "<dlE2>" << dlE2 << "</dlE2>" << endl; - + + DynamicList<label> dlE3(dlE2); // construct identical + Info<< "<dlE3>" << dlE3 << "</dlE3>" << endl; + + dlE3 = dlE1; // assign dissimilar + Info<< "<dlE3>" << dlE3 << "</dlE3>" << endl; + + dlE3 = dlE2; // assign identical + Info<< "<dlE3>" << dlE3 << "</dlE3>" << endl; + + Info<< "\nEnd\n"; return 0; diff --git a/applications/test/HashTable/hashTableTest.C b/applications/test/HashTable/hashTableTest.C index 8e3db2c9d7afbd1274d642675c559ba67ec3d1f6..25338a2bb7f870a2ed77c84c0df41d70e8732495 100644 --- a/applications/test/HashTable/hashTableTest.C +++ b/applications/test/HashTable/hashTableTest.C @@ -39,7 +39,7 @@ using namespace Foam; int main() { - HASHTABLE_CLASS<double> table1(100); + HASHTABLE_CLASS<double> table1(13); table1.insert("aaa", 1.0); table1.insert("aba", 2.0); @@ -56,7 +56,8 @@ int main() table1.erase("abs"); Info<< "\ntable1 toc: " << table1.toc() << endl; - Info<< "\ntable1 [" << table1.size() << "] " << endl; + table1.printInfo(Info) + << "table1 [" << table1.size() << "] " << endl; forAllIter(HASHTABLE_CLASS<double>, table1, iter) { Info<< iter.key() << " => " << iter() << nl; @@ -97,7 +98,7 @@ int main() << "transfer table1 -> table3 via the xfer() method" << nl; Info<< "\ntable1" << table1 << nl - << "\ntable2" << table1 << nl + << "\ntable2" << table2 << nl << "\ntable3" << table3 << nl; Info<< "\nerase table2 by iterator" << nl; @@ -113,10 +114,14 @@ int main() << "\ntable3" << table3 << nl; table3.resize(1); - Info<< "\nresize(1) table3" << table3 << nl; + Info<< "\nresize(1) table3" << nl; + table3.printInfo(Info) + << table3 << nl; table3.resize(10000); - Info<< "\nresize(10000) table3" << table3 << nl; + Info<< "\nresize(10000) table3" << nl; + table3.printInfo(Info) + << table3 << nl; HASHTABLE_CLASS<double> table4; @@ -134,26 +139,27 @@ int main() table1.erase(table1.begin()); Info<< "removed an element - test table1 != table3 : " << (table1 != table3) << nl; - + // insert a few things into table2 table2.set("ada", 14.0); table2.set("aeq", 15.0); table2.set("aaw", 16.0); table2.set("abs", 17.0); table2.set("adx", 20.0); - + Info<< "\ntable1" << table1 << nl << "\ntable2" << table2 << nl; label nErased = table1.erase(table2); - + Info<< "\nerase table2 keys from table1 (removed " << nErased << " elements)" << nl << "\ntable1" << table1 << nl << "\ntable2" << table2 << nl; - Info<< "\nclearStorage table3 ... "; + Info<< "\ntable3" << table3 + << "\nclearStorage table3 ... "; table3.clearStorage(); Info<< table3 << nl; diff --git a/applications/test/StaticHashTable/staticHashTableTest.C b/applications/test/StaticHashTable/staticHashTableTest.C index 2060ec582c273b6a794d45c807669e63ebfa00a2..c283fe9ba5674a699eebb93753e3dff14647194b 100644 --- a/applications/test/StaticHashTable/staticHashTableTest.C +++ b/applications/test/StaticHashTable/staticHashTableTest.C @@ -39,7 +39,7 @@ using namespace Foam; int main() { - HASHTABLE_CLASS<double> table1(100); + HASHTABLE_CLASS<double> table1(13); table1.insert("aaa", 1.0); table1.insert("aba", 2.0); @@ -56,7 +56,8 @@ int main() table1.erase("abs"); Info<< "\ntable1 toc: " << table1.toc() << endl; - Info<< "\ntable1 [" << table1.size() << "] " << endl; + table1.printInfo(Info) + << "table1 [" << table1.size() << "] " << endl; forAllIter(HASHTABLE_CLASS<double>, table1, iter) { Info<< iter.key() << " => " << iter() << nl; @@ -97,7 +98,7 @@ int main() << "transfer table1 -> table3 via the xfer() method" << nl; Info<< "\ntable1" << table1 << nl - << "\ntable2" << table1 << nl + << "\ntable2" << table2 << nl << "\ntable3" << table3 << nl; Info<< "\nerase table2 by iterator" << nl; @@ -113,10 +114,14 @@ int main() << "\ntable3" << table3 << nl; table3.resize(1); - Info<< "\nresize(1) table3" << table3 << nl; + Info<< "\nresize(1) table3" << nl; + table3.printInfo(Info) + << table3 << nl; table3.resize(10000); - Info<< "\nresize(10000) table3" << table3 << nl; + Info<< "\nresize(10000) table3" << nl; + table3.printInfo(Info) + << table3 << nl; HASHTABLE_CLASS<double> table4; @@ -134,26 +139,27 @@ int main() table1.erase(table1.begin()); Info<< "removed an element - test table1 != table3 : " << (table1 != table3) << nl; - + // insert a few things into table2 table2.set("ada", 14.0); table2.set("aeq", 15.0); table2.set("aaw", 16.0); table2.set("abs", 17.0); table2.set("adx", 20.0); - + Info<< "\ntable1" << table1 << nl << "\ntable2" << table2 << nl; label nErased = table1.erase(table2); - + Info<< "\nerase table2 keys from table1 (removed " << nErased << " elements)" << nl << "\ntable1" << table1 << nl << "\ntable2" << table2 << nl; - Info<< "\nclearStorage table3 ... "; + Info<< "\ntable3" << table3 + << "\nclearStorage table3 ... "; table3.clearStorage(); Info<< table3 << nl; @@ -162,4 +168,5 @@ int main() return 0; } + // ************************************************************************* // diff --git a/applications/test/UIndirectListTest/UIndirectListTest.C b/applications/test/UIndirectListTest/UIndirectListTest.C index 9c619a4b991988b061141386aea1e70ca5947db4..6902f47eeab4e2ddf1c744606f5cc1a1387a78a7 100644 --- a/applications/test/UIndirectListTest/UIndirectListTest.C +++ b/applications/test/UIndirectListTest/UIndirectListTest.C @@ -27,6 +27,7 @@ Description \*---------------------------------------------------------------------------*/ #include "UIndirectList.H" +#include "DynamicList.H" #include "IOstreams.H" #include "ListOps.H" #include "OFstream.H" @@ -58,11 +59,11 @@ int main(int argc, char *argv[]) idl[1] = -666; - Info<< "idl[1] changed:" << idl << endl; + Info<< "idl[1] changed: " << idl << endl; idl = -999; - Info<< "idl changed:" << idl << endl; + Info<< "idl changed: " << idl << endl; UIndirectList<double> idl2(idl); @@ -79,17 +80,26 @@ int main(int argc, char *argv[]) idl = ident; } - Info<< "idl assigned from UList:" << idl << endl; + Info<< "idl assigned from UList: " << idl << endl; - List<double> realList = UIndirectList<double>(completeList, addresses); + // test List operations - Info<< "realList:" << realList << endl; + List<double> flatList = UIndirectList<double>(completeList, addresses); + Info<< "List assigned from UIndirectList: " << flatList << endl; - List<double> realList2(UIndirectList<double>(completeList, addresses)); + List<double> flatList2(UIndirectList<double>(completeList, addresses)); + Info<< "List constructed from UIndirectList: " << flatList2 << endl; - Info<< "realList2:" << realList2 << endl; + flatList.append(UIndirectList<double>(completeList, addresses)); + Info<< "List::append(UIndirectList): " << flatList << endl; + DynamicList<double> dynList(UIndirectList<double>(completeList, addresses)); + Info<< "DynamicList constructed from UIndirectList: " << dynList << endl; + + dynList.append(UIndirectList<double>(completeList, addresses)); + Info<< "DynamicList::append(UIndirectList): " << dynList << endl; + Info << "\nEnd\n" << endl; return 0; diff --git a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTableIO.C b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTableIO.C index d113a99ee1cd3975d3b165cab95cc67473a4fe08..e4eb63f06e6c929976445306f94e99cc39ceb010 100644 --- a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTableIO.C +++ b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTableIO.C @@ -50,7 +50,7 @@ void Foam::HashPtrTable<T, Key, Hash>::read(Istream& is, const INew& inewt) label s = firstToken.labelToken(); // Read beginning of contents - char listDelimiter = is.readBeginList("HashPtrTable<T, Key, Hash>"); + char delimiter = is.readBeginList("HashPtrTable<T, Key, Hash>"); if (s) { @@ -59,7 +59,7 @@ void Foam::HashPtrTable<T, Key, Hash>::read(Istream& is, const INew& inewt) this->resize(2*s); } - if (listDelimiter == token::BEGIN_LIST) + if (delimiter == token::BEGIN_LIST) { for (label i=0; i<s; i++) { diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H index 5112f6fb7dcdce42bbe30ea39c9dc5a2980ae2cd..826bb95741ba387d2cc86572119d1b3780020306 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H @@ -28,6 +28,13 @@ Class Description An STL-conforming hash table. +Note + Hashing index collisions are handled via chaining using a singly-linked + list with the colliding entry being added to the head of the linked + list. Thus copying the hash table (or indeed even resizing it) will + often result in a different hash order. Use a sorted table-of-contents + when the hash order is important. + SourceFiles HashTableI.H HashTable.C diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTableIO.C b/src/OpenFOAM/containers/HashTables/HashTable/HashTableIO.C index 2a407b44a5a65e1f9e7d4432f400f91b9755f631..bef0cf50bcac828e5c7d5655d2c3acc1fd9837d4 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTableIO.C +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTableIO.C @@ -81,7 +81,7 @@ Foam::HashTable<T, Key, Hash>::printInfo(Ostream& os) const os << "HashTable<T,Key,Hash>" << " elements:" << size() << " slots:" << used << "/" << tableSize_ - << " chaining(avg/max):" << (used ? float(avgChain/used) : 0) + << " chaining(avg/max):" << (used ? (float(avgChain)/used) : 0) << "/" << maxChain << endl; return os; @@ -91,7 +91,11 @@ Foam::HashTable<T, Key, Hash>::printInfo(Ostream& os) const // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // template<class T, class Key, class Hash> -Foam::Istream& Foam::operator>>(Istream& is, HashTable<T, Key, Hash>& L) +Foam::Istream& Foam::operator>> +( + Istream& is, + HashTable<T, Key, Hash>& L +) { is.fatalCheck("operator>>(Istream&, HashTable<T, Key, Hash>&)"); @@ -113,7 +117,7 @@ Foam::Istream& Foam::operator>>(Istream& is, HashTable<T, Key, Hash>& L) label s = firstToken.labelToken(); // Read beginning of contents - char listDelimiter = is.readBeginList("HashTable<T, Key, Hash>"); + char delimiter = is.readBeginList("HashTable<T, Key, Hash>"); if (s) { @@ -122,7 +126,7 @@ Foam::Istream& Foam::operator>>(Istream& is, HashTable<T, Key, Hash>& L) L.resize(2*s); } - if (listDelimiter == token::BEGIN_LIST) + if (delimiter == token::BEGIN_LIST) { for (label i=0; i<s; i++) { @@ -209,7 +213,11 @@ Foam::Istream& Foam::operator>>(Istream& is, HashTable<T, Key, Hash>& L) template<class T, class Key, class Hash> -Foam::Ostream& Foam::operator<<(Ostream& os, const HashTable<T, Key, Hash>& L) +Foam::Ostream& Foam::operator<< +( + Ostream& os, + const HashTable<T, Key, Hash>& L +) { // Write size and start delimiter os << nl << L.size() << nl << token::BEGIN_LIST << nl; diff --git a/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTableIO.C b/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTableIO.C index 3939851fc5730253e562c8c4481999936cdb1e2e..3280ad738995f5af13e5aa31fd400be1593abbb2 100644 --- a/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTableIO.C +++ b/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTableIO.C @@ -117,7 +117,7 @@ Foam::Istream& Foam::operator>>(Istream& is, StaticHashTable<T, Key, Hash>& L) label s = firstToken.labelToken(); // Read beginning of contents - char listDelimiter = is.readBeginList("StaticHashTable<T, Key, Hash>"); + char delimiter = is.readBeginList("StaticHashTable<T, Key, Hash>"); if (s) { @@ -126,7 +126,7 @@ Foam::Istream& Foam::operator>>(Istream& is, StaticHashTable<T, Key, Hash>& L) L.resize(2*s); } - if (listDelimiter == token::BEGIN_LIST) + if (delimiter == token::BEGIN_LIST) { for (label i=0; i<s; i++) { diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILListIO.C b/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILListIO.C index 18ad4c0f20a5b4901ad0af7d71b98d9e40d25b08..e9c489169c99df4c490e0f74af6b3423b74a633c 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILListIO.C +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/ILList/ILListIO.C @@ -50,11 +50,11 @@ void Foam::ILList<LListBase, T>::read(Istream& is, const INew& iNew) label s = firstToken.labelToken(); // Read beginning of contents - char listDelimiter = is.readBeginList("ILList<LListBase, T>"); + char delimiter = is.readBeginList("ILList<LListBase, T>"); if (s) { - if (listDelimiter == token::BEGIN_LIST) + if (delimiter == token::BEGIN_LIST) { for (label i=0; i<s; i++) { diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LListIO.C b/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LListIO.C index 1fed57da16ea7b5ae35946b01b1c0a7222bd52dc..eba21661ea0eda1dfcbd0ccec0f31845331f8ccf 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LListIO.C +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/LList/LListIO.C @@ -61,11 +61,11 @@ Foam::Istream& Foam::operator>>(Istream& is, LList<LListBase, T>& L) label s = firstToken.labelToken(); // Read beginning of contents - char listDelimiter = is.readBeginList("LList<LListBase, T>"); + char delimiter = is.readBeginList("LList<LListBase, T>"); if (s) { - if (listDelimiter == token::BEGIN_LIST) + if (delimiter == token::BEGIN_LIST) { for (register label i=0; i<s; i++) { diff --git a/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrListIO.C b/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrListIO.C index 588da22cc9462df0fc6a0c0dbd763ce3c9a2c8a7..735dd8d31b7819b2d1456abed56e606e814591ae 100644 --- a/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrListIO.C +++ b/src/OpenFOAM/containers/LinkedLists/accessTypes/LPtrList/LPtrListIO.C @@ -53,11 +53,11 @@ void Foam::LPtrList<LListBase, T>::read(Istream& is, const INew& iNew) label s = firstToken.labelToken(); // Read beginning of contents - char listDelimiter = is.readBeginList("LPtrList<LListBase, T>"); + char delimiter = is.readBeginList("LPtrList<LListBase, T>"); if (s) { - if (listDelimiter == token::BEGIN_LIST) + if (delimiter == token::BEGIN_LIST) { for (label i=0; i<s; i++) { diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H index 6ad83c809a45207a85b4b25642c6b4f3c82ff0ce..460d325006d133cfa3be15018539bf76c3806bd5 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H @@ -111,8 +111,11 @@ public: // Also constructs from DynamicList with different sizing parameters. explicit inline DynamicList(const UList<T>&); + //- Construct from UIndirectList. Size set to UIndirectList size. + explicit inline DynamicList(const UIndirectList<T>&); + //- Construct by transferring the parameter contents - explicit inline DynamicList(const Xfer<List<T> >&); + explicit inline DynamicList(const Xfer< List<T> >&); //- Construct from Istream. Size set to size of read list. explicit DynamicList(Istream&); @@ -173,16 +176,19 @@ public: inline void transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>&); //- Transfer contents to the Xfer container as a plain List - inline Xfer<List<T> > xfer(); + inline Xfer< List<T> > xfer(); // Member Operators //- Append an element at the end of the list - inline void append(const T& e); + inline void append(const T&); //- Append a List at the end of this list inline void append(const UList<T>&); + //- Append a UIndirectList at the end of this list + inline void append(const UIndirectList<T>&); + //- Remove and return the top element inline T remove(); @@ -198,7 +204,7 @@ public: const DynamicList<T, SizeInc, SizeMult, SizeDiv>& ); - //- Assignment from List<T>. + //- Assignment from UList inline void operator=(const UList<T>&); // IOstream operators diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H index 5ee9a3ce870b32560cff251debf66617649b4ce0..4e0ffbd1fdeaa30382a39c1e260d8cbf7a8da86b 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H @@ -72,6 +72,17 @@ inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList {} +template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> +inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList +( + const UIndirectList<T>& lst +) +: + List<T>(lst), + capacity_(lst.size()) +{} + + template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList ( @@ -287,10 +298,10 @@ Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::transfer template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> -inline Foam::Xfer<Foam::List<T> > +inline Foam::Xfer< Foam::List<T> > Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::xfer() { - return xferMoveTo<List<T> >(*this); + return xferMoveTo< List<T> >(*this); } @@ -313,8 +324,6 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::append const UList<T>& lst ) { - label nextFree = List<T>::size(); - if (this == &lst) { FatalErrorIn @@ -324,6 +333,23 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::append ) << "attempted appending to self" << abort(FatalError); } + label nextFree = List<T>::size(); + setSize(nextFree + lst.size()); + + forAll(lst, elemI) + { + this->operator[](nextFree++) = lst[elemI]; + } +} + + +template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> +inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::append +( + const UIndirectList<T>& lst +) +{ + label nextFree = List<T>::size(); setSize(nextFree + lst.size()); forAll(lst, elemI) diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C b/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C index aab7376e0592db88fea9f315386c24d87cfa2fdb..77e8ebab6a6696a32d79ebe7bbf1e90603112b36 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C @@ -82,9 +82,9 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& L) } // Read beginning of contents - char listDelimiter = is.readBeginList("FixedList"); + char delimiter = is.readBeginList("FixedList"); - if (listDelimiter == token::BEGIN_LIST) + if (delimiter == token::BEGIN_LIST) { for (register unsigned i=0; i<Size; i++) { diff --git a/src/OpenFOAM/containers/Lists/List/List.C b/src/OpenFOAM/containers/Lists/List/List.C index 429c91f820675d4ead0d17b1827dcca15fd9fbae..3fa3dcc8748bb8a3fbb8e775a4510baa705ab189 100644 --- a/src/OpenFOAM/containers/Lists/List/List.C +++ b/src/OpenFOAM/containers/Lists/List/List.C @@ -404,61 +404,6 @@ void Foam::List<T>::clear() } -template<class T> -void Foam::List<T>::append(const UList<T>& lst) -{ - if (this == &lst) - { - FatalErrorIn - ( - "List<T>::append(const UList<T>&)" - ) << "attempted appending to self" << abort(FatalError); - } - - label nextFree = this->size_; - setSize(nextFree + lst.size()); - - forAll(lst, elemI) - { - this->operator[](nextFree++) = lst[elemI]; - } -} - - -template<class T> -void Foam::List<T>::append(const UIndirectList<T>& lst) -{ - label nextFree = this->size_; - setSize(nextFree + lst.size()); - - forAll(lst, elemI) - { - this->operator[](nextFree++) = lst[elemI]; - } -} - - -template<class T> -void Foam::List<T>::append(const SLList<T>& lst) -{ - if (lst.size()) - { - label nextFree = this->size_; - setSize(nextFree + lst.size()); - - for - ( - typename SLList<T>::const_iterator iter = lst.begin(); - iter != lst.end(); - ++iter - ) - { - this->operator[](nextFree++) = iter(); - } - } -} - - // Transfer the contents of the argument List into this List // and anull the argument list template<class T> diff --git a/src/OpenFOAM/containers/Lists/List/List.H b/src/OpenFOAM/containers/Lists/List/List.H index 5961ff174793741a484f7955872108c471791d7b..639db9bbd20f62d1b66c32affcb5f0d268ad3631 100644 --- a/src/OpenFOAM/containers/Lists/List/List.H +++ b/src/OpenFOAM/containers/Lists/List/List.H @@ -182,24 +182,21 @@ public: void clear(); //- Append a List at the end of this list - void append(const UList<T>&); + inline void append(const UList<T>&); //- Append a UIndirectList at the end of this list - void append(const UIndirectList<T>&); + inline void append(const UIndirectList<T>&); - //- Append a SLList at the end of this list - void append(const SLList<T>&); - - //- Transfer the contents of the argument List into this List + //- Transfer the contents of the argument List into this list // and annull the argument list. void transfer(List<T>&); - //- Transfer the contents of the argument List into this List + //- Transfer the contents of the argument List into this list // and annull the argument list. template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> void transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>&); - //- Transfer the contents of the argument List into this List + //- Transfer the contents of the argument List into this list // and annull the argument list. void transfer(SortableList<T>&); diff --git a/src/OpenFOAM/containers/Lists/List/ListI.H b/src/OpenFOAM/containers/Lists/List/ListI.H index c3c6ebe4fb691eb7aed7470cd874d6f9015f0fcb..58e5576f303b0d625f7b98a25c7865a2bce8e922 100644 --- a/src/OpenFOAM/containers/Lists/List/ListI.H +++ b/src/OpenFOAM/containers/Lists/List/ListI.H @@ -88,12 +88,46 @@ inline Foam::label Foam::List<T>::size() const template<class T> -inline Foam::Xfer<Foam::List<T> > Foam::List<T>::xfer() +inline Foam::Xfer< Foam::List<T> > Foam::List<T>::xfer() { return xferMove(*this); } +template<class T> +inline void Foam::List<T>::append(const UList<T>& lst) +{ + if (this == &lst) + { + FatalErrorIn + ( + "List<T>::append(const UList<T>&)" + ) << "attempted appending to self" << abort(FatalError); + } + + label nextFree = this->size(); + setSize(nextFree + lst.size()); + + forAll(lst, elemI) + { + this->operator[](nextFree++) = lst[elemI]; + } +} + + +template<class T> +inline void Foam::List<T>::append(const UIndirectList<T>& lst) +{ + label nextFree = this->size(); + setSize(nextFree + lst.size()); + + forAll(lst, elemI) + { + this->operator[](nextFree++) = lst[elemI]; + } +} + + // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template<class T> diff --git a/src/OpenFOAM/containers/Lists/List/ListIO.C b/src/OpenFOAM/containers/Lists/List/ListIO.C index 7cfdfb0397f99049cf79076bdf70265189170686..d6238ae09108a455f29a28b070f05728d1adf098 100644 --- a/src/OpenFOAM/containers/Lists/List/ListIO.C +++ b/src/OpenFOAM/containers/Lists/List/ListIO.C @@ -76,11 +76,11 @@ Foam::Istream& Foam::operator>>(Istream& is, List<T>& L) if (is.format() == IOstream::ASCII || !contiguous<T>()) { // Read beginning of contents - char listDelimiter = is.readBeginList("List"); + char delimiter = is.readBeginList("List"); if (s) { - if (listDelimiter == token::BEGIN_LIST) + if (delimiter == token::BEGIN_LIST) { for (register label i=0; i<s; i++) { diff --git a/src/OpenFOAM/containers/Lists/PtrList/PtrListIO.C b/src/OpenFOAM/containers/Lists/PtrList/PtrListIO.C index e427f68d8d411f1a88e444836e4d603166c511fb..564b22c2bccc3891272d40a0e33b914be00cb9a6 100644 --- a/src/OpenFOAM/containers/Lists/PtrList/PtrListIO.C +++ b/src/OpenFOAM/containers/Lists/PtrList/PtrListIO.C @@ -54,11 +54,11 @@ void Foam::PtrList<T>::read(Istream& is, const INew& inewt) setSize(s); // Read beginning of contents - char listDelimiter = is.readBeginList("PtrList"); + char delimiter = is.readBeginList("PtrList"); if (s) { - if (listDelimiter == token::BEGIN_LIST) + if (delimiter == token::BEGIN_LIST) { forAll(*this, i) { diff --git a/src/OpenFOAM/primitives/SphericalTensor/SphericalTensorI.H b/src/OpenFOAM/primitives/SphericalTensor/SphericalTensorI.H index 5768717db4afcc360a809c8082a90d029fa6c17e..28b7b8b9d3050737cf197100c22cd3b69204025f 100644 --- a/src/OpenFOAM/primitives/SphericalTensor/SphericalTensorI.H +++ b/src/OpenFOAM/primitives/SphericalTensor/SphericalTensorI.H @@ -177,7 +177,7 @@ inline Cmpt det(const SphericalTensor<Cmpt>& st) } -//- Return the inverse of a symmetric tensor +//- Return the inverse of a spherical tensor template <class Cmpt> inline SphericalTensor<Cmpt> inv(const SphericalTensor<Cmpt>& st) { diff --git a/src/OpenFOAM/primitives/SymmTensor/SymmTensorI.H b/src/OpenFOAM/primitives/SymmTensor/SymmTensorI.H index f59dd16754ffa085e6794cc1b97833e6176a6c1d..5a2de5dbbda00df13548802a55f409fc4ffe20ec 100644 --- a/src/OpenFOAM/primitives/SymmTensor/SymmTensorI.H +++ b/src/OpenFOAM/primitives/SymmTensor/SymmTensorI.H @@ -256,7 +256,7 @@ inline Cmpt magSqr(const SymmTensor<Cmpt>& st) } -//- Return the strace of a symmetric tensor +//- Return the trace of a symmetric tensor template <class Cmpt> inline Cmpt tr(const SymmTensor<Cmpt>& st) { @@ -280,7 +280,7 @@ inline const SymmTensor<Cmpt>& symm(const SymmTensor<Cmpt>& st) } -//- Return the stwice the symmetric part of a symmetric tensor +//- Return twice the symmetric part of a symmetric tensor template <class Cmpt> inline SymmTensor<Cmpt> twoSymm(const SymmTensor<Cmpt>& st) { @@ -361,7 +361,7 @@ inline SymmTensor<Cmpt> inv(const SymmTensor<Cmpt>& st) } -//- Return the 1spt invariant of a symmetric tensor +//- Return the 1st invariant of a symmetric tensor template <class Cmpt> inline Cmpt invariantI(const SymmTensor<Cmpt>& st) { @@ -453,14 +453,9 @@ operator&(const SphericalTensor<Cmpt>& spt1, const SymmTensor<Cmpt>& st2) { return SymmTensor<Cmpt> ( - spt1.ii()*st2.xx(), - spt1.ii()*st2.xy(), - spt1.ii()*st2.xz(), - - spt1.ii()*st2.yy(), - spt1.ii()*st2.yz(), - - spt1.ii()*st2.zz() + spt1.ii()*st2.xx(), spt1.ii()*st2.xy(), spt1.ii()*st2.xz(), + spt1.ii()*st2.yy(), spt1.ii()*st2.yz(), + spt1.ii()*st2.zz() ); } @@ -472,14 +467,9 @@ operator&(const SymmTensor<Cmpt>& st1, const SphericalTensor<Cmpt>& spt2) { return SymmTensor<Cmpt> ( - st1.xx()*spt2.ii(), - st1.xy()*spt2.ii(), - st1.xz()*spt2.ii(), - - st1.yy()*spt2.ii(), - st1.yz()*spt2.ii(), - - st1.zz()*spt2.ii() + st1.xx()*spt2.ii(), st1.xy()*spt2.ii(), st1.xz()*spt2.ii(), + st1.yy()*spt2.ii(), st1.yz()*spt2.ii(), + st1.zz()*spt2.ii() ); } diff --git a/src/OpenFOAM/primitives/SymmTensor/symmTensor/symmTensor.C b/src/OpenFOAM/primitives/SymmTensor/symmTensor/symmTensor.C index f5a56a3d86ede938e0a5ff26526a3a5862969ac9..730d728f7164b1d15ccedf3e3485d508700674c1 100644 --- a/src/OpenFOAM/primitives/SymmTensor/symmTensor/symmTensor.C +++ b/src/OpenFOAM/primitives/SymmTensor/symmTensor/symmTensor.C @@ -25,7 +25,6 @@ License \*---------------------------------------------------------------------------*/ #include "symmTensor.H" -#include "mathematicalConstants.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -65,16 +64,16 @@ template<> const symmTensor symmTensor::max ( VGREAT, VGREAT, VGREAT, - VGREAT, VGREAT, - VGREAT + VGREAT, VGREAT, + VGREAT ); template<> const symmTensor symmTensor::min ( -VGREAT, -VGREAT, -VGREAT, - -VGREAT, -VGREAT, - -VGREAT + -VGREAT, -VGREAT, + -VGREAT ); diff --git a/src/OpenFOAM/primitives/Tensor/TensorI.H b/src/OpenFOAM/primitives/Tensor/TensorI.H index 453f79185ca2457fc9a79eba42b64af78872b9f0..7ca9958aa1800237f79a2d7766d62680732c28e6 100644 --- a/src/OpenFOAM/primitives/Tensor/TensorI.H +++ b/src/OpenFOAM/primitives/Tensor/TensorI.H @@ -402,7 +402,7 @@ inline SymmTensor<Cmpt> symm(const Tensor<Cmpt>& t) } -//- Return the twice the symmetric part of a tensor +//- Return twice the symmetric part of a tensor template <class Cmpt> inline SymmTensor<Cmpt> twoSymm(const Tensor<Cmpt>& t) { @@ -609,17 +609,9 @@ operator&(const SphericalTensor<Cmpt>& st1, const Tensor<Cmpt>& t2) { return Tensor<Cmpt> ( - st1.ii()*t2.xx(), - st1.ii()*t2.xy(), - st1.ii()*t2.xz(), - - st1.ii()*t2.yx(), - st1.ii()*t2.yy(), - st1.ii()*t2.yz(), - - st1.ii()*t2.zx(), - st1.ii()*t2.zy(), - st1.ii()*t2.zz() + st1.ii()*t2.xx(), st1.ii()*t2.xy(), st1.ii()*t2.xz(), + st1.ii()*t2.yx(), st1.ii()*t2.yy(), st1.ii()*t2.yz(), + st1.ii()*t2.zx(), st1.ii()*t2.zy(), st1.ii()*t2.zz() ); } @@ -631,17 +623,9 @@ operator&(const Tensor<Cmpt>& t1, const SphericalTensor<Cmpt>& st2) { return Tensor<Cmpt> ( - t1.xx()*st2.ii(), - t1.xy()*st2.ii(), - t1.xz()*st2.ii(), - - t1.yx()*st2.ii(), - t1.yy()*st2.ii(), - t1.yz()*st2.ii(), - - t1.zx()*st2.ii(), - t1.zy()*st2.ii(), - t1.zz()*st2.ii() + t1.xx()*st2.ii(), t1.xy()*st2.ii(), t1.xz()*st2.ii(), + t1.yx()*st2.ii(), t1.yy()*st2.ii(), t1.yz()*st2.ii(), + t1.zx()*st2.ii(), t1.zy()*st2.ii(), t1.zz()*st2.ii() ); } diff --git a/src/OpenFOAM/primitives/Tensor/tensor/tensor.H b/src/OpenFOAM/primitives/Tensor/tensor/tensor.H index 297b8b47b9f6902d991a869ea5320742832c87fe..36ed4df02941ee8295866d8b6df1d457d95060f5 100644 --- a/src/OpenFOAM/primitives/Tensor/tensor/tensor.H +++ b/src/OpenFOAM/primitives/Tensor/tensor/tensor.H @@ -51,13 +51,13 @@ namespace Foam typedef Tensor<scalar> tensor; -vector eigenValues(const tensor& t); -vector eigenVector(const tensor& t, const scalar lambda); -tensor eigenVectors(const tensor& t); +vector eigenValues(const tensor&); +vector eigenVector(const tensor&, const scalar lambda); +tensor eigenVectors(const tensor&); -vector eigenValues(const symmTensor& t); -vector eigenVector(const symmTensor& t, const scalar lambda); -tensor eigenVectors(const symmTensor& t); +vector eigenValues(const symmTensor&); +vector eigenVector(const symmTensor&, const scalar lambda); +tensor eigenVectors(const symmTensor&); //- Data associated with tensor type are contiguous template<>