Merge branch 'olesenm'

This commit is contained in:
andy
2010-10-04 11:08:48 +01:00
86 changed files with 3271 additions and 861 deletions

View File

@ -0,0 +1,162 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::IndirectList2
Description
A List with indirect addressing.
SourceFiles
IndirectListI.H
\*---------------------------------------------------------------------------*/
#ifndef IndirectList2_H
#define IndirectList2_H
#include "UIndirectList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class IndirectListAddressing Declaration
\*---------------------------------------------------------------------------*/
//- A helper class for storing addresses.
class IndirectListAddressing
{
// Private data
//- Storage for the list addressing
List<label> addressing_;
// Private Member Functions
//- Disallow default bitwise copy construct
IndirectListAddressing(const IndirectListAddressing&);
//- Disallow default bitwise assignment
void operator=(const IndirectListAddressing&);
protected:
// Constructors
//- Construct by copying the addressing array
explicit inline IndirectListAddressing(const UList<label>& addr);
//- Construct by transferring addressing array
explicit inline IndirectListAddressing(const Xfer<List<label> >& addr);
// Member Functions
// Access
//- Return the list addressing
inline const List<label>& addressing() const;
// Edit
//- Reset addressing
inline void resetAddressing(const UList<label>&);
inline void resetAddressing(const Xfer<List<label> >&);
};
/*---------------------------------------------------------------------------*\
Class IndirectList2 Declaration
\*---------------------------------------------------------------------------*/
template<class T>
class IndirectList2
:
private IndirectListAddressing,
public UIndirectList<T>
{
// Private Member Functions
//- Disable default assignment operator
void operator=(const IndirectList2<T>&);
//- Disable assignment from UIndirectList
void operator=(const UIndirectList<T>&);
public:
// Constructors
//- Construct given the complete list and the addressing array
inline IndirectList2(const UList<T>&, const UList<label>&);
//- Construct given the complete list and by transferring addressing
inline IndirectList2(const UList<T>&, const Xfer<List<label> >&);
//- Copy constructor
inline IndirectList2(const IndirectList2<T>&);
//- Construct from UIndirectList
explicit inline IndirectList2(const UIndirectList<T>&);
// Member Functions
// Access
//- Return the list addressing
using UIndirectList<T>::addressing;
// Edit
//- Reset addressing
using IndirectListAddressing::resetAddressing;
// Member Operators
//- Assignment operator
using UIndirectList<T>::operator=;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "IndirectList2I.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,136 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline Foam::IndirectListAddressing::IndirectListAddressing
(
const UList<label>& addr
)
:
addressing_(addr)
{}
inline Foam::IndirectListAddressing::IndirectListAddressing
(
const Xfer<List<label> >& addr
)
:
addressing_(addr)
{}
template<class T>
inline Foam::IndirectList2<T>::IndirectList2
(
const UList<T>& completeList,
const UList<label>& addr
)
:
IndirectListAddressing(addr),
UIndirectList<T>
(
completeList,
IndirectListAddressing::addressing()
)
{}
template<class T>
inline Foam::IndirectList2<T>::IndirectList2
(
const UList<T>& completeList,
const Xfer<List<label> >& addr
)
:
IndirectListAddressing(addr),
UIndirectList<T>
(
completeList,
IndirectListAddressing::addressing()
)
{}
template<class T>
inline Foam::IndirectList2<T>::IndirectList2
(
const IndirectList2<T>& lst
)
:
IndirectListAddressing(lst.addressing()),
UIndirectList<T>
(
lst.completeList(),
IndirectListAddressing::addressing()
)
{}
template<class T>
inline Foam::IndirectList2<T>::IndirectList2
(
const UIndirectList<T>& lst
)
:
IndirectListAddressing(lst.addressing()),
UIndirectList<T>
(
lst.completeList(),
IndirectListAddressing::addressing()
)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline const Foam::List<Foam::label>&
Foam::IndirectListAddressing::addressing() const
{
return addressing_;
}
inline void Foam::IndirectListAddressing::resetAddressing
(
const UList<label>& addr
)
{
addressing_ = addr;
}
inline void Foam::IndirectListAddressing::resetAddressing
(
const Xfer<List<label> >& addr
)
{
addressing_.transfer(addr());
}
// ************************************************************************* //

View File

@ -0,0 +1,101 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
\*---------------------------------------------------------------------------*/
#include "IndirectList2.H"
#include "IOstreams.H"
using namespace Foam;
template<class ListType>
void printInfo(const ListType& lst)
{
Info<< "addr: " << lst.addressing() << nl
<< "list: " << lst << nl
<< endl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
List<double> completeList(10);
forAll(completeList, i)
{
completeList[i] = 0.1*i;
}
Info<< "raw : " << completeList << nl << endl;
List<label> addresses(5);
addresses[0] = 1;
addresses[1] = 0;
addresses[2] = 7;
addresses[3] = 8;
addresses[4] = 5;
IndirectList2<double> idl1(completeList, addresses);
printInfo(idl1);
addresses[4] = 1;
addresses[3] = 0;
addresses[2] = 7;
addresses[1] = 8;
addresses[0] = 5;
idl1.resetAddressing(addresses.xfer());
printInfo(idl1);
// test copying
UIndirectList<double> uidl1(idl1);
IndirectList2<double> idl2(uidl1);
IndirectList2<double> idl3(idl2);
printInfo(uidl1);
idl1.resetAddressing(List<label>());
// idl2.resetAddressing(List<label>());
Info<<"after resetAddressing:" << nl << endl;
printInfo(uidl1);
printInfo(idl1);
printInfo(idl2);
printInfo(idl3);
Info<< "End\n" << endl;
return 0;
}
// ************************************************************************* //

View File

@ -0,0 +1,3 @@
IndirectListTest2.C
EXE = $(FOAM_USER_APPBIN)/IndirectListTest2

View File

@ -0,0 +1,2 @@
/* EXE_INC = -I$(LIB_SRC)/cfdTools/include */
/* EXE_LIBS = -lfiniteVolume */

View File

@ -166,7 +166,7 @@ int main(int argc, char *argv[])
if (args.optionFound("info"))
{
packLst.print(Info);
packLst.printInfo(Info);
}
Info<< nl;

View File

@ -42,42 +42,42 @@ int main(int argc, char *argv[])
Info<< "\ntest allocation with value\n";
PackedList<3> list1(5,1);
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest assign uniform value\n";
list1 = 3;
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest assign uniform value (with overflow)\n";
list1 = -1;
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest zero\n";
list1 = 0;
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest set() with default argument (max_value)\n";
list1.set(1);
list1.set(3);
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest unset() with in-range and out-of-range\n";
list1.unset(3);
list1.unset(100000);
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest assign between references\n";
list1[2] = 3;
list1[4] = list1[2];
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest assign between references, with chaining\n";
list1[0] = list1[4] = 1;
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest assign between references, with chaining and auto-vivify\n";
list1[1] = list1[8] = list1[10] = list1[14] = 2;
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest operator== between references\n";
@ -126,7 +126,7 @@ int main(int argc, char *argv[])
{
const PackedList<3>& constLst = list1;
Info<< "\ntest operator[] const with out-of-range index\n";
constLst.print(Info);
constLst.printInfo(Info, true);
if (constLst[20])
{
Info<< "[20] is true (unexpected)\n";
@ -136,7 +136,7 @@ int main(int argc, char *argv[])
Info<< "[20] is false (expected) list size should be unchanged "
<< "(const)\n";
}
constLst.print(Info);
constLst.printInfo(Info, true);
Info<< "\ntest operator[] non-const with out-of-range index\n";
if (list1[20])
@ -148,7 +148,7 @@ int main(int argc, char *argv[])
Info<< "[20] is false (expected) but list was resized?? "
<< "(non-const)\n";
}
list1.print(Info);
list1.printInfo(Info, true);
}
@ -157,85 +157,85 @@ int main(int argc, char *argv[])
{
Info<< "[20] is false, as expected\n";
}
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest resize with value (without reallocation)\n";
list1.resize(8, list1.max_value());
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest flip() function\n";
list1.flip();
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\nre-flip()\n";
list1.flip();
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest set() function\n";
list1.set(1, 5);
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest assign bool\n";
list1 = false;
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest assign bool\n";
list1 = true;
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest resize without value (with reallocation)\n";
list1.resize(12);
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest resize with value (with reallocation)\n";
list1.resize(25, list1.max_value());
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest resize smaller (should not touch allocation)\n";
list1.resize(8);
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest append() operation\n";
list1.append(2);
list1.append(3);
list1.append(4);
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest reserve() operation\n";
list1.reserve(32);
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest shrink() operation\n";
list1.shrink();
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest setCapacity() operation\n";
list1.setCapacity(15);
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest setCapacity() operation\n";
list1.setCapacity(100);
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest operator[] assignment\n";
list1[16] = 5;
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest operator[] assignment with auto-vivify\n";
list1[36] = list1.max_value();
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest setCapacity smaller\n";
list1.setCapacity(24);
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest resize much smaller\n";
list1.resize(150);
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest trim\n";
list1.trim();
list1.print(Info);
list1.printInfo(Info, true);
// add in some misc values
list1[31] = 1;
@ -245,40 +245,40 @@ int main(int argc, char *argv[])
Info<< "\ntest iterator\n";
PackedList<3>::iterator iter = list1.begin();
Info<< "begin():";
iter.print(Info) << "\n";
iter.printInfo(Info) << "\n";
Info<< "iterator:" << iter() << "\n";
iter() = 5;
iter.print(Info);
list1.print(Info);
iter.printInfo(Info);
list1.printInfo(Info, true);
iter = list1[31];
Info<< "iterator:" << iter() << "\n";
iter.print(Info);
iter.printInfo(Info);
Info<< "\ntest get() method\n";
Info<< "get(10):" << list1.get(10) << " and list[10]:" << list1[10] << "\n";
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest iterator indexing\n";
Info<< "cend() ";
list1.cend().print(Info) << "\n";
list1.cend().printInfo(Info) << "\n";
{
Info<< "\ntest assignment of iterator\n";
list1.print(Info);
list1.printInfo(Info, true);
Info<< "cend()\n";
list1.end().print(Info);
list1.end().printInfo(Info);
PackedList<3>::iterator cit = list1[100];
Info<< "out-of-range: ";
cit.print(Info);
cit.printInfo(Info);
cit = list1[15];
Info<< "in-range: ";
cit.print(Info);
cit.printInfo(Info);
Info<< "out-of-range: ";
cit = list1[1000];
cit.print(Info);
cit.printInfo(Info);
}
@ -289,7 +289,7 @@ int main(int argc, char *argv[])
++cit
)
{
cit.print(Info);
cit.printInfo(Info);
}
Info<< "\ntest operator[] auto-vivify\n";
@ -304,16 +304,16 @@ int main(int argc, char *argv[])
Info<< "size after write:" << list1.size() << "\n";
Info<< "list[45]:" << list1[45] << "\n";
list1[49] = list1[100];
list1.print(Info);
list1.printInfo(Info, true);
Info<< "\ntest copy constructor + append\n";
PackedList<3> list2(list1);
list2.append(4);
Info<< "source list:\n";
list1.print(Info);
list1.printInfo(Info, true);
Info<< "destination list:\n";
list2.print(Info);
list2.printInfo(Info, true);
Info<< "\ntest pattern that fills all bits\n";
PackedList<4> list3(8, 8);
@ -323,29 +323,50 @@ int main(int argc, char *argv[])
list3[pos--] = list3.max_value();
list3[pos--] = 0;
list3[pos--] = list3.max_value();
list3.print(Info);
list3.printInfo(Info, true);
Info<< "removed final value: " << list3.remove() << endl;
list3.print(Info);
list3.printInfo(Info, true);
Info<<"list: " << list3 << endl;
List<bool> list4(4, true);
List<bool> list4(16, false);
{
const List<bool>& constLst = list4;
// fill with some values
forAll(list4, i)
{
list4[i] = i % 3;
}
const UList<bool>& constLst = list4;
Info<< "\ntest operator[] const with out-of-range index\n";
Info<< constLst << endl;
if (constLst[20])
if (constLst[100])
{
Info<< "[20] is true (unexpected)\n";
Info<< "[100] is true (unexpected)\n";
}
else
{
Info<< "[20] is false (expected) list size should be unchanged "
<< "(const)\n";
Info<< "[100] is false (expected) "
<< "list size should be unchanged (const)\n";
}
Info<< constLst << endl;
}
PackedBoolList listb(list4);
Info<< "copied from bool list " << endl;
listb.printInfo(Info, true);
{
labelList indices = listb.used();
Info<< "indices: " << indices << endl;
}
Info<< "\n\nDone.\n";
return 0;

View File

@ -33,7 +33,6 @@ Description
#include "StaticHashTable.H"
#include "cpuTime.H"
#include <vector>
#include "PackedList.H"
#include "PackedBoolList.H"
using namespace Foam;
@ -57,7 +56,7 @@ int main(int argc, char *argv[])
{
if ((i % nReport) == 0 && i)
{
Info<< "i:" << i << " in " << timer.cpuTimeIncrement() << " s"
Info<< "i:" << i << " in " << timer.cpuTimeIncrement() << " s"
<<endl;
}
packed[i] = 1;

View File

@ -0,0 +1,3 @@
PackedListTest4.C
EXE = $(FOAM_USER_APPBIN)/PackedListTest4

View File

@ -0,0 +1,207 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application
Description
\*---------------------------------------------------------------------------*/
#include "uLabel.H"
#include "IOstreams.H"
#include "PackedBoolList.H"
#include "IStringStream.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
PackedBoolList list1(20);
// set every third one on
forAll(list1, i)
{
list1[i] = !(i % 3);
}
Info<< "\nalternating bit pattern\n";
list1.printInfo(Info, true);
PackedBoolList list2 = ~list1;
Info<< "\ncomplementary bit pattern\n";
list2.printBits(Info);
// set every other on
forAll(list2, i)
{
list2[i] = !(i % 2);
}
Info<< "\nalternating bit pattern\n";
list2.printBits(Info);
list2.resize(28, false);
list2.resize(34, true);
list2.resize(40, false);
for (label i=0; i < 4; ++i)
{
list2[i] = true;
}
Info<< "\nresized with false, 6 true + 6 false, bottom 4 bits true\n";
list2.printInfo(Info, true);
labelList list2Labels = list2.used();
Info<< "\noperator|\n";
list1.printBits(Info);
list2.printBits(Info);
Info<< "==\n";
(list1 | list2).printBits(Info);
Info<< "\noperator& : does trim\n";
(list1 & list2).printBits(Info);
Info<< "\noperator^\n";
(list1 ^ list2).printBits(Info);
Info<< "\noperator|=\n";
{
PackedBoolList list3 = list1;
(list3 |= list2).printBits(Info);
}
Info<< "\noperator|= with UList<label>\n";
{
PackedBoolList list3 = list1;
(list3 |= list2Labels).printBits(Info);
}
Info<< "\noperator&=\n";
{
PackedBoolList list3 = list1;
(list3 &= list2).printBits(Info);
}
Info<< "\noperator+=\n";
{
PackedBoolList list3 = list1;
(list3 += list2).printBits(Info);
}
Info<< "\noperator+= with UList<label>\n";
{
PackedBoolList list3 = list1;
(list3 += list2Labels).printBits(Info);
}
Info<< "\noperator-=\n";
{
PackedBoolList list3 = list1;
(list3 -= list2).printBits(Info);
}
Info<< "\noperator-= with UList<label>\n";
{
PackedBoolList list3 = list1;
(list3 -= list2Labels).printBits(Info);
}
PackedBoolList list4
(
IStringStream
(
"(1 n 1 n 1 n 1 1 off 0 0 f f 0 y yes y true y false on t)"
)()
);
Info<< "\ntest Istream constructor\n";
list4.printInfo(Info, true);
Info<< list4 << " indices: " << list4.used()() <<endl;
Info<< "\nassign from labelList\n";
list4 = labelList
(
IStringStream
(
"(0 1 2 3 12 13 14 19 20 21)"
)()
);
list4.printInfo(Info, true);
Info<< list4 << " indices: " << list4.used()() <<endl;
Info<< "\nassign from indices\n";
list4.read
(
IStringStream
(
"{0 1 2 3 12 13 14 19 20 21}"
)()
);
list4.printInfo(Info, true);
Info<< list4 << " indices: " << list4.used()() <<endl;
List<bool> boolLst(list4.size());
forAll(list4, i)
{
boolLst[i] = list4[i];
}
Info<< "List<bool>: " << boolLst <<endl;
// check roundabout assignments
PackedList<2> pl2
(
IStringStream
(
"{(0 3)(1 3)(2 3)(3 3)(12 3)(13 3)(14 3)(19 3)(20 3)(21 3)}"
)()
);
Info<< "roundabout assignment: " << pl2 << endl;
list4.clear();
forAll(pl2, i)
{
list4[i] = pl2[i];
}
list4.write(Info, true) << endl;
list4.writeEntry("PackedBoolList", Info);
return 0;
}
// ************************************************************************* //