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")) if (args.optionFound("info"))
{ {
packLst.print(Info); packLst.printInfo(Info);
} }
Info<< nl; Info<< nl;

View File

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

View File

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

View File

@ -23,7 +23,7 @@
# along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. # along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
# #
# Script # Script
# doxyFilt # doxyFilter
# #
# Description # Description
# pass-through filter for doxygen # pass-through filter for doxygen
@ -43,19 +43,19 @@ then
dirName=${filePath%/[^/]*} dirName=${filePath%/[^/]*}
fileName=${filePath##*/} fileName=${filePath##*/}
awkScript=$WM_PROJECT_DIR/bin/tools/doxyFilt.awk awkScript=$WM_PROJECT_DIR/bin/tools/doxyFilter.awk
case "$1" in case "$1" in
*/applications/solvers/*.C | */applications/utilities/*.C ) */applications/solvers/*.C | */applications/utilities/*.C )
awkScript=$WM_PROJECT_DIR/bin/tools/doxyFilt-top.awk awkScript=$WM_PROJECT_DIR/bin/tools/doxyFilter-top.awk
;; ;;
# */applications/solvers/*.H | */applications/utilities/*.H ) # */applications/solvers/*.H | */applications/utilities/*.H )
# awkScript=$WM_PROJECT_DIR/bin/tools/doxyFilt-ignore.awk # awkScript=$WM_PROJECT_DIR/bin/tools/doxyFilter-ignore.awk
# ;; # ;;
esac esac
awk -f $awkScript $1 | \ awk -f $awkScript $1 | \
sed -f $WM_PROJECT_DIR/bin/tools/doxyFilt.sed \ sed -f $WM_PROJECT_DIR/bin/tools/doxyFilter.sed \
-e s@%filePath%@$filePath@g \ -e s@%filePath%@$filePath@g \
-e s@%fileName%@$fileName@g \ -e s@%fileName%@$fileName@g \
-e s@%dirName%@$dirName@g -e s@%dirName%@$dirName@g

View File

@ -22,7 +22,7 @@
# along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. # along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
# #
# Script # Script
# doxyFilt-ignore.awk # doxyFilter-ignore.awk
# #
# Description # Description
# - Prefix file contents with doxygen @file tag and %filePath% tag # - Prefix file contents with doxygen @file tag and %filePath% tag

View File

@ -22,7 +22,7 @@
# along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. # along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
# #
# Script # Script
# doxyFilt-top.awk # doxyFilter-top.awk
# #
# Description # Description
# Only output the first /* ... */ comment section found in the file # Only output the first /* ... */ comment section found in the file

View File

@ -22,7 +22,7 @@
# along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. # along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
# #
# Script # Script
# doxyFilt.awk # doxyFilter.awk
# #
# Description # Description
# Converts cocoon style sentinel strings into doxygen style strings # Converts cocoon style sentinel strings into doxygen style strings

View File

@ -1,6 +1,6 @@
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Script # Script
# doxyFilt.sed # doxyFilter.sed
# #
# Description # Description
# Transform human-readable tags such as 'Description' into the Doxygen # Transform human-readable tags such as 'Description' into the Doxygen

View File

@ -45,6 +45,9 @@
# Note # Note
# Using "git commit --no-verify" it is possible to override the hook. # Using "git commit --no-verify" it is possible to override the hook.
# #
# By supplying arguments to the hook, it can also be used to manually
# test the specified files/directories for standards conformance.
#
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
die() die()
{ {
@ -52,13 +55,14 @@ die()
echo '-----------------------' 1>&2 echo '-----------------------' 1>&2
echo '' 1>&2 echo '' 1>&2
echo "$@" 1>&2 echo "$@" 1>&2
echo '' 1>&2
exit 1 exit 1
} }
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# Check content that will be added by this commit. # Check content that will be added by this commit.
if git rev-parse --verify -q HEAD > /dev/null if git rev-parse --verify HEAD > /dev/null 2>&1
then then
against=HEAD against=HEAD
else else
@ -66,10 +70,30 @@ else
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi fi
# list of all files # called manually with arguments for the files/directories to be tested?
fileList=$(git diff-index --name-only $against --) if [ "$#" -gt 0 ]
unset badFiles then
case "$1" in
-h | -help)
die "interactive usage: supply list of files/directories to check"
;;
esac
# obtain list of all specified files/directories
fileList=$(git ls-files -- $@ 2>/dev/null)
else
# list of all files to be committed
fileList=$(git diff-index --cached --name-only $against --)
fi
#
# no files changed: can skip all the checks
# this usage can correspond to a 'git commit --amend'
#
[ -n "$fileList" ] || exit 0
unset badFiles
# join list of files with this amount of space # join list of files with this amount of space
Indent=" " Indent=" "
@ -97,16 +121,18 @@ dieOnBadFiles()
# #
checkIllegalCode() checkIllegalCode()
{ {
echo "pre-commit: check bad strings/characters etc ..." 1>&2
reBad="(N""abla|"$'\t'")" reBad="(N""abla|"$'\t'")"
msgBad="N""abla or <TAB>" msgBad="N""abla or <TAB>"
badFiles=$( badFiles=$(
for f in $fileList for f in $fileList
do do
# parse line numbers from this: # parse line numbers from grep output:
# path/fileName:<lineNr>: contents # <lineNr>: contents
lines=$(git grep --cached -n -E -e "$reBad" -- "$f" | lines=$(git grep --cached -E -hn -e "$reBad" -- "$f" |
sed -e 's@^[^:]*:\([0-9]*\):.*@\1@' | sed -e 's@:.*@@' |
tr '\n' ' ' tr '\n' ' '
) )
[ -n "$lines" ] && echo "$Indent$f -- lines: $lines" [ -n "$lines" ] && echo "$Indent$f -- lines: $lines"
@ -123,18 +149,22 @@ checkIllegalCode()
checkCopyright() checkCopyright()
{ {
year=$(date +%Y) year=$(date +%Y)
echo "pre-commit: check copyright ..." 1>&2
badFiles=$( badFiles=$(
for f in $fileList for f in $fileList
do do
# parse line numbers from this: # NB: need to have OpenCFD on a separate line to prevent
# path/fileName:<lineNr>: contents # this check being caught by itself!
# for Copyright lines without the current year #
lines=$(git grep --cached -n -e Copyright -- "$f" | # parse line numbers from grep output:
sed -n \ # <lineNr>: contents
-e '/OpenCFD/{ ' \ #
-e "/$year/b" \ lines=$(git grep --cached -F -hn -e Copyright \
-e 's@^[^:]*:\([0-9]*\):.*@\1@p }' | --and -e OpenCFD \
--and --not -e "$year" \
-- "$f" |
sed -e 's@:.*@@' |
tr '\n' ' ' tr '\n' ' '
) )
[ -n "$lines" ] && echo "$Indent$f -- lines: $lines" [ -n "$lines" ] && echo "$Indent$f -- lines: $lines"
@ -150,16 +180,18 @@ checkCopyright()
# #
checkLineLength() checkLineLength()
{ {
echo "pre-commit: check line lengths ..." 1>&2
badFiles=$( badFiles=$(
for f in $fileList for f in $fileList
do do
# limit to *.[CH] files # limit to *.[CH] files
case "$f" in case "$f" in
(*.[CH]) (*.[CH])
# parse line numbers from this: # parse line numbers from grep output:
# path/fileName:<lineNr>: contents # <lineNr>: contents
lines=$(git grep --cached -n -e ".\{81,\}" -- "$f" | lines=$(git grep --cached -hn -e '^.\{81,\}' -- "$f" |
sed -e 's@^[^:]*:\([0-9]*\):.*@\1@' | sed -e 's@:.*@@' |
tr '\n' ' ' tr '\n' ' '
) )
[ -n "$lines" ] && echo "$Indent$f -- lines: $lines" [ -n "$lines" ] && echo "$Indent$f -- lines: $lines"
@ -177,18 +209,20 @@ checkLineLength()
# #
checkLineLengthNonComments() checkLineLengthNonComments()
{ {
echo "pre-commit: check line lengths ..." 1>&2
badFiles=$( badFiles=$(
for f in $fileList for f in $fileList
do do
# limit to *.[CH] files # limit to *.[CH] files
case "$f" in case "$f" in
(*.[CH]) (*.[CH])
# parse line numbers from this (strip comment lines): # parse line numbers from grep output:
# path/fileName:<lineNr>: contents # <lineNr>: contents
lines=$(git grep --cached -n -e ".\{81,\}" -- "$f" | lines=$(git grep --cached -hn -e '^.\{81,\}' \
sed -n \ --and --not -e "^ *//" \
-e '\@^[^:]*:[^:]*: *//.*@b' \ -- "$f" |
-e 's@^[^:]*:\([0-9]*\):.*@\1@p' | sed -e 's@:.*@@' |
tr '\n' ' ' tr '\n' ' '
) )
[ -n "$lines" ] && echo "$Indent$f -- lines: $lines" [ -n "$lines" ] && echo "$Indent$f -- lines: $lines"
@ -205,18 +239,20 @@ checkLineLengthNonComments()
# #
checkLineLengthNonDirective() checkLineLengthNonDirective()
{ {
echo "pre-commit: check line lengths ..." 1>&2
badFiles=$( badFiles=$(
for f in $fileList for f in $fileList
do do
# limit to *.[CH] files # limit to *.[CH] files
case "$f" in case "$f" in
(*.[CH]) (*.[CH])
# parse line numbers from this (strip comment lines): # parse line numbers from grep output:
# path/fileName:<lineNr>: contents # <lineNr>: contents
lines=$(git grep --cached -n -e ".\{81,\}" -- "$f" | lines=$(git grep --cached -hn -e '^.\{81,\}' \
sed -n \ --and --not -e "^ *#" \
-e '\@^[^:]*:[^:]*: *#.*@b' \ -- "$f" |
-e 's@^[^:]*:\([0-9]*\):.*@\1@p' | sed -e 's@:.*@@' |
tr '\n' ' ' tr '\n' ' '
) )
[ -n "$lines" ] && echo "$Indent$f -- lines: $lines" [ -n "$lines" ] && echo "$Indent$f -- lines: $lines"

View File

@ -567,7 +567,7 @@ IMAGE_PATH =
# to standard output. If FILTER_PATTERNS is specified, this tag will be # to standard output. If FILTER_PATTERNS is specified, this tag will be
# ignored. # ignored.
INPUT_FILTER = doxyFilt INPUT_FILTER = $(WM_PROJECT_DIR)/bin/tools/doxyFilter
# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern # The FILTER_PATTERNS tag can be used to specify filters on a per file pattern
# basis. Doxygen will compare the file name with each pattern and apply the # basis. Doxygen will compare the file name with each pattern and apply the

View File

@ -669,7 +669,7 @@ IMAGE_PATH =
# If FILTER_PATTERNS is specified, this tag will be # If FILTER_PATTERNS is specified, this tag will be
# ignored. # ignored.
INPUT_FILTER = doxyFilt INPUT_FILTER = $(WM_PROJECT_DIR)/bin/tools/doxyFilter
# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern # The FILTER_PATTERNS tag can be used to specify filters on a per file pattern
# basis. # basis.

17
doc/tools/find-trailingspace Executable file
View File

@ -0,0 +1,17 @@
#!/bin/bash
# -----------------------------------------------------------------------------
# Script
# find-trailingspace
#
# Description
# Search for files with trailing whitesapce
#
# -----------------------------------------------------------------------------
set -x
cd $WM_PROJECT_DIR || exit 1
tab=$'\t'
git grep -c -E "[ $tab]+"'$' -- $@
#------------------------------------------------------------------ end-of-file

View File

@ -157,7 +157,7 @@ public:
// The begin-of-line (^) and end-of-line ($) anchors are implicit // The begin-of-line (^) and end-of-line ($) anchors are implicit
bool match(const string&, List<string>& groups) const; bool match(const string&, List<string>& groups) const;
//- Return true if the regex was found in within string //- Return true if the regex was found within string
bool search(const std::string& str) const bool search(const std::string& str) const
{ {
return std::string::npos != find(str); return std::string::npos != find(str);

View File

@ -52,8 +52,8 @@ $(strings)/word/word.C
$(strings)/word/wordIO.C $(strings)/word/wordIO.C
$(strings)/fileName/fileName.C $(strings)/fileName/fileName.C
$(strings)/fileName/fileNameIO.C $(strings)/fileName/fileNameIO.C
$(strings)/keyType/keyTypeIO.C $(strings)/keyType/keyType.C
$(strings)/wordRe/wordReIO.C $(strings)/wordRe/wordRe.C
primitives/hashes/Hasher/Hasher.C primitives/hashes/Hasher/Hasher.C
@ -66,7 +66,8 @@ primitives/random/Random.C
containers/HashTables/HashTable/HashTableCore.C containers/HashTables/HashTable/HashTableCore.C
containers/HashTables/StaticHashTable/StaticHashTableCore.C containers/HashTables/StaticHashTable/StaticHashTableCore.C
containers/Lists/SortableList/ParSortableListName.C containers/Lists/SortableList/ParSortableListName.C
containers/Lists/PackedList/PackedListName.C containers/Lists/PackedList/PackedListCore.C
containers/Lists/PackedList/PackedBoolList.C
containers/Lists/ListOps/ListOps.C containers/Lists/ListOps/ListOps.C
containers/LinkedLists/linkTypes/SLListBase/SLListBase.C containers/LinkedLists/linkTypes/SLListBase/SLListBase.C
containers/LinkedLists/linkTypes/DLListBase/DLListBase.C containers/LinkedLists/linkTypes/DLListBase/DLListBase.C
@ -328,7 +329,7 @@ $(cellShape)/cellShapeEqual.C
$(cellShape)/cellShapeIO.C $(cellShape)/cellShapeIO.C
$(cellShape)/cellShapeIOList.C $(cellShape)/cellShapeIOList.C
meshes/patchIdentifier/patchIdentifier.C meshes/Identifiers/patch/patchIdentifier.C
polyMesh = meshes/polyMesh polyMesh = meshes/polyMesh

View File

@ -180,13 +180,22 @@ public:
// Member Operators // Member Operators
//- Append an element at the end of the list //- Append an element at the end of the list
inline void append(const T&); inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& append
(
const T&
);
//- Append a List at the end of this list //- Append a List at the end of this list
inline void append(const UList<T>&); inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& append
(
const UList<T>&
);
//- Append a UIndirectList at the end of this list //- Append a UIndirectList at the end of this list
inline void append(const UIndirectList<T>&); inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& append
(
const UIndirectList<T>&
);
//- Remove and return the top element //- Remove and return the top element
inline T remove(); inline T remove();

View File

@ -305,7 +305,8 @@ Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::xfer()
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::append inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>&
Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::append
( (
const T& t const T& t
) )
@ -314,11 +315,13 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::append
setSize(elemI + 1); setSize(elemI + 1);
this->operator[](elemI) = t; this->operator[](elemI) = t;
return *this;
} }
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::append inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>&
Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::append
( (
const UList<T>& lst const UList<T>& lst
) )
@ -339,11 +342,13 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::append
{ {
this->operator[](nextFree++) = lst[elemI]; this->operator[](nextFree++) = lst[elemI];
} }
return *this;
} }
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::append inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>&
Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::append
( (
const UIndirectList<T>& lst const UIndirectList<T>& lst
) )
@ -355,6 +360,7 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::append
{ {
this->operator[](nextFree++) = lst[elemI]; this->operator[](nextFree++) = lst[elemI];
} }
return *this;
} }

View File

@ -135,7 +135,7 @@ Foam::Istream& Foam::operator>>(Istream& is, List<T>& L)
<< exit(FatalIOError); << exit(FatalIOError);
} }
// Putback the openning bracket // Putback the opening bracket
is.putBack(firstToken); is.putBack(firstToken);
// Now read as a singly-linked list // Now read as a singly-linked list

View File

@ -0,0 +1,375 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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/>.
\*---------------------------------------------------------------------------*/
#include "PackedBoolList.H"
#include "IOstreams.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::PackedBoolList::bitorPrepare
(
const PackedList<1>& lst,
label& maxPackLen
)
{
const StorageList& lhs = this->storage();
const StorageList& rhs = lst.storage();
const label packLen1 = this->packedLength();
const label packLen2 = lst.packedLength();
// check how the lists interact and if bit trimming is needed
bool needTrim = false;
maxPackLen = packLen1;
if (packLen1 == packLen2)
{
// identical packed lengths - only resize if absolutely necessary
if
(
this->size() != lst.size()
&& maxPackLen
&& rhs[maxPackLen-1] > lhs[maxPackLen-1]
)
{
// second list has a higher bit set
// extend addressable area and use trim
resize(lst.size());
needTrim = true;
}
}
else if (packLen2 < packLen1)
{
// second list is shorter, this limits the or
maxPackLen = packLen2;
}
else
{
// second list is longer, find the highest bit set
for (label storeI = packLen1; storeI < packLen2; ++storeI)
{
if (rhs[storeI])
{
maxPackLen = storeI+1;
}
}
// the upper limit moved - resize for full coverage and trim later
if (maxPackLen > packLen1)
{
resize(maxPackLen * packing());
needTrim = true;
}
}
return needTrim;
}
template<class LabelListType>
Foam::label Foam::PackedBoolList::setIndices(const LabelListType& indices)
{
// no better information, just guess something about the size
reserve(indices.size());
label cnt = 0;
forAll(indices, elemI)
{
if (set(indices[elemI]))
{
++cnt;
}
}
return cnt;
}
template<class LabelListType>
Foam::label Foam::PackedBoolList::unsetIndices(const LabelListType& indices)
{
label cnt = 0;
forAll(indices, elemI)
{
if (unset(indices[elemI]))
{
++cnt;
}
}
return cnt;
}
template<class LabelListType>
Foam::label Foam::PackedBoolList::subsetIndices(const LabelListType& indices)
{
// handle trivial case
if (empty() || indices.empty())
{
clear();
return 0;
}
// normal case
PackedBoolList anded;
anded.reserve(size());
label cnt = 0;
forAll(indices, elemI)
{
const label& index = indices[elemI];
if (operator[](index))
{
anded.set(index);
++cnt;
}
}
transfer(anded);
return cnt;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::PackedBoolList::PackedBoolList(Istream& is)
:
PackedList<1>()
{
is >> *this;
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
void Foam::PackedBoolList::set(const PackedList<1>& lst)
{
// extend addressable area if needed, return maximum size possible
label len = 0;
const bool needTrim = bitorPrepare(lst, len);
// operate directly with the underlying storage
StorageList& lhs = this->storage();
const StorageList& rhs = lst.storage();
for (label i=0; i < len; ++i)
{
lhs[i] |= rhs[i];
}
if (needTrim)
{
trim();
}
}
Foam::label Foam::PackedBoolList::set(const UList<label>& indices)
{
return setIndices(indices);
}
Foam::label Foam::PackedBoolList::set(const UIndirectList<label>& indices)
{
return setIndices(indices);
}
void Foam::PackedBoolList::unset(const PackedList<1>& lst)
{
// operate directly with the underlying storage
StorageList& lhs = this->storage();
const StorageList& rhs = lst.storage();
// overlapping storage size
const label len = min(this->packedLength(), lst.packedLength());
for (label i=0; i < len; ++i)
{
lhs[i] &= ~rhs[i];
}
}
Foam::label Foam::PackedBoolList::unset(const UList<label>& indices)
{
return unsetIndices(indices);
}
Foam::label Foam::PackedBoolList::unset(const UIndirectList<label>& indices)
{
return unsetIndices(indices);
}
void Foam::PackedBoolList::subset(const PackedList<1>& lst)
{
// shrink addressable area if needed
if (this->size() > lst.size())
{
this->resize(lst.size());
}
// operate directly with the underlying storage
StorageList& lhs = this->storage();
const StorageList& rhs = lst.storage();
const label len = this->packedLength();
for (label i=0; i < len; ++i)
{
lhs[i] &= rhs[i];
}
}
Foam::label Foam::PackedBoolList::subset(const UList<label>& indices)
{
return subsetIndices(indices);
}
Foam::label Foam::PackedBoolList::subset(const UIndirectList<label>& indices)
{
return subsetIndices(indices);
}
Foam::Xfer<Foam::labelList> Foam::PackedBoolList::used() const
{
labelList lst(this->count());
if (lst.size())
{
label nElem = 0;
forAll(*this, elemI)
{
if (get(elemI))
{
lst[nElem++] = elemI;
}
}
lst.setSize(nElem);
}
return lst.xfer();
}
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
Foam::PackedBoolList&
Foam::PackedBoolList::operator=(const UList<bool>& lst)
{
this->setSize(lst.size());
// overwrite with new true/false values
forAll(*this, elemI)
{
set(elemI, lst[elemI]);
}
return *this;
}
Foam::PackedBoolList&
Foam::PackedBoolList::operator^=(const PackedList<1>& lst)
{
// extend addressable area if needed, return maximum size possible
label len = 0;
const bool needTrim = bitorPrepare(lst, len);
// operate directly with the underlying storage
StorageList& lhs = this->storage();
const StorageList& rhs = lst.storage();
for (label i=0; i < len; ++i)
{
lhs[i] ^= rhs[i];
}
if (needTrim)
{
trim();
}
return *this;
}
// * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * * //
Foam::PackedBoolList Foam::operator&
(
const PackedBoolList& lst1,
const PackedBoolList& lst2
)
{
PackedBoolList result(lst1);
result &= lst2;
// trim to bits actually used
result.trim();
return result;
}
Foam::PackedBoolList Foam::operator^
(
const PackedBoolList& lst1,
const PackedBoolList& lst2
)
{
PackedBoolList result(lst1);
result ^= lst2;
// trim to bits actually used
result.trim();
return result;
}
Foam::PackedBoolList Foam::operator|
(
const PackedBoolList& lst1,
const PackedBoolList& lst2
)
{
PackedBoolList result(lst1);
result |= lst2;
return result;
}
// ************************************************************************* //

View File

@ -0,0 +1,296 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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/>.
Class
Foam::PackedBoolList
Description
A bit-packed bool list.
In addition to the obvious memory advantage over using a
List\<bool\>, this class also provides a number of bit-like
operations.
SourceFiles
PackedBoolListI.H
PackedBoolList.C
SeeAlso
Foam::PackedList
\*---------------------------------------------------------------------------*/
#ifndef PackedBoolList_H
#define PackedBoolList_H
#include "PackedList.H"
#include "UIndirectList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class PackedBoolList Declaration
\*---------------------------------------------------------------------------*/
class PackedBoolList
:
public PackedList<1>
{
// Private Member Functions
//- Preparation, resizing before a bitor operation
// returns true if the later result needs trimming
bool bitorPrepare(const PackedList<1>& lst, label& maxPackLen);
//- Set the listed indices. Return number of elements changed.
// Does auto-vivify for non-existent entries.
template<class LabelListType>
label setIndices(const LabelListType& indices);
//- Unset the listed indices. Return number of elements changed.
// Never auto-vivify entries.
template<class LabelListType>
label unsetIndices(const LabelListType& indices);
//- Subset with the listed indices. Return number of elements subsetted.
template<class LabelListType>
label subsetIndices(const LabelListType& indices);
public:
// Constructors
//- Construct null
inline PackedBoolList();
//- Construct from Istream
PackedBoolList(Istream&);
//- Construct with given size, initializes list to 0
explicit inline PackedBoolList(const label size);
//- Construct with given size and value for all elements
inline PackedBoolList(const label size, const bool val);
//- Copy constructor
inline PackedBoolList(const PackedBoolList&);
//- Copy constructor
explicit inline PackedBoolList(const PackedList<1>&);
//- Construct by transferring the parameter contents
inline PackedBoolList(const Xfer<PackedBoolList>&);
//- Construct by transferring the parameter contents
inline PackedBoolList(const Xfer<PackedList<1> >&);
//- Construct from a list of bools
explicit inline PackedBoolList(const UList<bool>&);
//- Construct from a list of labels
// using the labels as indices to indicate which bits are set
explicit inline PackedBoolList(const UList<label>& indices);
//- Construct from a list of labels
// using the labels as indices to indicate which bits are set
explicit inline PackedBoolList(const UIndirectList<label>& indices);
//- Clone
inline autoPtr<PackedBoolList> clone() const;
// Member Functions
// Access
using PackedList<1>::set;
using PackedList<1>::unset;
//- Set specified bits.
void set(const PackedList<1>&);
//- Set the listed indices. Return number of elements changed.
// Does auto-vivify for non-existent entries.
label set(const UList<label>& indices);
//- Set the listed indices. Return number of elements changed.
// Does auto-vivify for non-existent entries.
label set(const UIndirectList<label>& indices);
//- Unset specified bits.
void unset(const PackedList<1>&);
//- Unset the listed indices. Return number of elements changed.
// Never auto-vivify entries.
label unset(const UList<label>& indices);
//- Unset the listed indices. Return number of elements changed.
// Never auto-vivify entries.
label unset(const UIndirectList<label>& indices);
//- Subset with the specified list.
void subset(const PackedList<1>&);
//- Subset with the listed indices.
// Return number of elements subsetted.
label subset(const UList<label>& indices);
//- Subset with the listed indices.
// Return number of elements subsetted.
label subset(const UIndirectList<label>& indices);
//- Return indices of the used (true) elements as a list of labels
Xfer<labelList> used() const;
// Edit
//- Transfer the contents of the argument list into this list
// and annul the argument list.
inline void transfer(PackedBoolList&);
//- Transfer the contents of the argument list into this list
// and annul the argument list.
inline void transfer(PackedList<1>&);
//- Transfer contents to the Xfer container
inline Xfer<PackedBoolList> xfer();
// Member Operators
//- Assignment of all entries to the given value.
inline PackedBoolList& operator=(const bool val);
//- Assignment operator.
inline PackedBoolList& operator=(const PackedBoolList&);
//- Assignment operator.
inline PackedBoolList& operator=(const PackedList<1>&);
//- Assignment operator.
PackedBoolList& operator=(const UList<bool>&);
//- Assignment operator,
// using the labels as indices to indicate which bits are set
inline PackedBoolList& operator=(const UList<label>& indices);
//- Assignment operator,
// using the labels as indices to indicate which bits are set
inline PackedBoolList& operator=(const UIndirectList<label>&);
//- Complement operator
inline PackedBoolList operator~() const;
//- And operator (lists may be dissimilar sizes)
inline PackedBoolList& operator&=(const PackedList<1>&);
//- And operator (lists may be dissimilar sizes)
// using the labels as indices to indicate which bits are set
inline PackedBoolList& operator&=(const UList<label>& indices);
//- And operator (lists may be dissimilar sizes)
// using the labels as indices to indicate which bits are set
inline PackedBoolList& operator&=(const UIndirectList<label>&);
//- Xor operator (lists may be dissimilar sizes)
// Retains unique entries
PackedBoolList& operator^=(const PackedList<1>&);
//- Or operator (lists may be dissimilar sizes)
inline PackedBoolList& operator|=(const PackedList<1>&);
//- Or operator (lists may be dissimilar sizes),
// using the labels as indices to indicate which bits are set
inline PackedBoolList& operator|=(const UList<label>& indices);
//- Or operator (lists may be dissimilar sizes),
// using the labels as indices to indicate which bits are set
inline PackedBoolList& operator|=(const UIndirectList<label>&);
//- Add entries to this list, synonymous with the or operator
inline PackedBoolList& operator+=(const PackedList<1>&);
//- Add entries to this list, synonymous with the or operator
inline PackedBoolList& operator+=(const UList<label>& indices);
//- Add entries to this list, synonymous with the or operator
inline PackedBoolList& operator+=(const UIndirectList<label>&);
//- Remove entries from this list - unset the specified bits
inline PackedBoolList& operator-=(const PackedList<1>&);
//- Remove entries from this list - unset the specified bits
inline PackedBoolList& operator-=(const UList<label>& indices);
//- Remove entries from this list - unset the specified bits
inline PackedBoolList& operator-=(const UIndirectList<label>&);
};
// Global Operators
//- Intersect lists - the result is trimmed to the smallest intersecting size
PackedBoolList operator&
(
const PackedBoolList& lst1,
const PackedBoolList& lst2
);
//- Combine to form a unique list (xor)
// The result is trimmed to the smallest intersecting size
PackedBoolList operator^
(
const PackedBoolList& lst1,
const PackedBoolList& lst2
);
//- Combine lists
PackedBoolList operator|
(
const PackedBoolList& lst1,
const PackedBoolList& lst2
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "PackedBoolListI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,277 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::PackedBoolList::PackedBoolList()
:
PackedList<1>()
{}
inline Foam::PackedBoolList::PackedBoolList(const label size)
:
PackedList<1>(size)
{}
inline Foam::PackedBoolList::PackedBoolList
(
const label size,
const bool val
)
:
PackedList<1>(size, (val ? 1u : 0u))
{}
inline Foam::PackedBoolList::PackedBoolList(const PackedBoolList& lst)
:
PackedList<1>(lst)
{}
inline Foam::PackedBoolList::PackedBoolList(const PackedList<1>& lst)
:
PackedList<1>(lst)
{}
inline Foam::PackedBoolList::PackedBoolList(const Xfer<PackedBoolList>& lst)
:
PackedList<1>()
{
transfer(lst());
}
inline Foam::PackedBoolList::PackedBoolList(const Xfer<PackedList<1> >& lst)
:
PackedList<1>(lst)
{}
inline Foam::PackedBoolList::PackedBoolList(const UList<bool>& lst)
:
PackedList<1>()
{
operator=(lst);
}
inline Foam::PackedBoolList::PackedBoolList(const UList<label>& indices)
:
PackedList<1>(indices.size(), 0u)
{
set(indices);
}
inline Foam::PackedBoolList::PackedBoolList(const UIndirectList<label>& indices)
:
PackedList<1>(indices.size(), 0u)
{
set(indices);
}
inline Foam::autoPtr<Foam::PackedBoolList>
Foam::PackedBoolList::clone() const
{
return autoPtr<PackedBoolList>(new PackedBoolList(*this));
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline void Foam::PackedBoolList::transfer(PackedBoolList& lst)
{
PackedList<1>::transfer(static_cast<PackedList<1>&>(lst));
}
inline void Foam::PackedBoolList::transfer(PackedList<1>& lst)
{
PackedList<1>::transfer(lst);
}
inline Foam::Xfer<Foam::PackedBoolList> Foam::PackedBoolList::xfer()
{
return xferMove(*this);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
inline Foam::PackedBoolList&
Foam::PackedBoolList::operator=(const bool val)
{
PackedList<1>::operator=(val);
return *this;
}
inline Foam::PackedBoolList&
Foam::PackedBoolList::operator=(const PackedBoolList& lst)
{
PackedList<1>::operator=(lst);
return *this;
}
inline Foam::PackedBoolList&
Foam::PackedBoolList::operator=(const PackedList<1>& lst)
{
PackedList<1>::operator=(lst);
return *this;
}
inline Foam::PackedBoolList&
Foam::PackedBoolList::operator=(const UList<label>& indices)
{
clear();
set(indices);
return *this;
}
inline Foam::PackedBoolList&
Foam::PackedBoolList::operator=(const UIndirectList<label>& indices)
{
clear();
set(indices);
return *this;
}
inline Foam::PackedBoolList
Foam::PackedBoolList::operator~() const
{
PackedBoolList result(*this);
result.flip();
return result;
}
inline Foam::PackedBoolList&
Foam::PackedBoolList::operator&=(const PackedList<1>& lst)
{
subset(lst);
return *this;
}
inline Foam::PackedBoolList&
Foam::PackedBoolList::operator&=(const UList<label>& indices)
{
subset(indices);
return *this;
}
inline Foam::PackedBoolList&
Foam::PackedBoolList::operator&=(const UIndirectList<label>& indices)
{
subset(indices);
return *this;
}
inline Foam::PackedBoolList&
Foam::PackedBoolList::operator|=(const PackedList<1>& lst)
{
set(lst);
return *this;
}
inline Foam::PackedBoolList&
Foam::PackedBoolList::operator|=(const UList<label>& indices)
{
set(indices);
return *this;
}
inline Foam::PackedBoolList&
Foam::PackedBoolList::operator|=(const UIndirectList<label>& indices)
{
set(indices);
return *this;
}
inline Foam::PackedBoolList&
Foam::PackedBoolList::operator+=(const PackedList<1>& lst)
{
return operator|=(lst);
}
inline Foam::PackedBoolList&
Foam::PackedBoolList::operator+=(const UList<label>& indices)
{
return operator|=(indices);
}
inline Foam::PackedBoolList&
Foam::PackedBoolList::operator+=(const UIndirectList<label>& indices)
{
return operator|=(indices);
}
inline Foam::PackedBoolList&
Foam::PackedBoolList::operator-=(const PackedList<1>& lst)
{
unset(lst);
return *this;
}
inline Foam::PackedBoolList&
Foam::PackedBoolList::operator-=(const UList<label>& indices)
{
unset(indices);
return *this;
}
inline Foam::PackedBoolList&
Foam::PackedBoolList::operator-=(const UIndirectList<label>& indices)
{
unset(indices);
return *this;
}
// ************************************************************************* //

View File

@ -24,35 +24,11 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "PackedList.H" #include "PackedList.H"
#include "IOstreams.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<unsigned nBits>
Foam::PackedList<nBits>::PackedList(const label size, const unsigned int val)
:
StorageList(packedLength(size), 0u),
size_(size)
{
operator=(val);
}
template<unsigned nBits>
Foam::PackedList<nBits>::PackedList(const UList<label>& lst)
:
StorageList(packedLength(lst.size()), 0u),
size_(lst.size())
{
forAll(lst, i)
{
set(i, lst[i]);
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
#if (UINT_MAX == 0xFFFFFFFF) #if (UINT_MAX == 0xFFFFFFFF)
// 32-bit counting, Hamming weight method // 32-bit counting, Hamming weight method
# define COUNT_PACKEDBITS(sum, x) \ # define COUNT_PACKEDBITS(sum, x) \
@ -82,25 +58,10 @@ unsigned int Foam::PackedList<nBits>::count() const
if (size_) if (size_)
{ {
// mask value for complete segments const label packLen = packedLength();
unsigned int mask = maskLower(packing()); for (label i = 0; i < packLen; ++i)
const unsigned int endSeg = size_ / packing();
const unsigned int endOff = size_ % packing();
// count bits in complete segments
for (unsigned i = 0; i < endSeg; ++i)
{ {
register unsigned int bits = StorageList::operator[](i) & mask; register unsigned int bits = StorageList::operator[](i);
COUNT_PACKEDBITS(c, bits);
}
// count bits in partial segment
if (endOff)
{
mask = maskLower(endOff);
register unsigned int bits = StorageList::operator[](endSeg) & mask;
COUNT_PACKEDBITS(c, bits); COUNT_PACKEDBITS(c, bits);
} }
} }
@ -117,64 +78,60 @@ bool Foam::PackedList<nBits>::trim()
return false; return false;
} }
// mask value for complete segments const label oldSize = size_;
unsigned int mask = maskLower(packing()); for (label storeI = packedLength()-1; storeI >= 0; --storeI)
label currElem = packedLength(size_) - 1;
unsigned int endOff = size_ % packing();
// clear trailing bits on final segment
if (endOff)
{ {
StorageList::operator[](currElem) &= maskLower(endOff); size_ = storeI * packing();
} unsigned int bits = StorageList::operator[](storeI);
// test entire segment // found some bits
while (currElem > 0 && !(StorageList::operator[](currElem) &= mask)) if (bits)
{
currElem--;
}
// test segment
label newsize = (currElem + 1) * packing();
// mask for the final segment
mask = max_value() << (nBits * (packing() - 1));
for (endOff = packing(); endOff >= 1; --endOff, --newsize)
{
if (StorageList::operator[](currElem) & mask)
{ {
while (bits)
{
bits >>= nBits;
++size_;
}
break; break;
} }
mask >>= nBits;
} }
if (size_ == newsize) return (size_ != oldSize);
{
return false;
}
size_ = newsize;
return false;
} }
template<unsigned nBits> template<unsigned nBits>
void Foam::PackedList<nBits>::flip() void Foam::PackedList<nBits>::flip()
{ {
label packLen = packedLength(size_); if (!size_)
for (label i=0; i < packLen; i++)
{ {
StorageList::operator[](i) = ~StorageList::operator[](i); return;
}
// mask value for complete segments
const unsigned int mask = maskLower(packing());
const label packLen = packedLength();
for (label i=0; i < packLen; ++i)
{
StorageList::operator[](i) = mask & ~StorageList::operator[](i);
}
// mask off the final partial segment
{
const unsigned int off = size_ % packing();
if (off)
{
const unsigned int seg = size_ / packing();
StorageList::operator[](seg) &= maskLower(off);
}
} }
} }
template<unsigned nBits> template<unsigned nBits>
Foam::labelList Foam::PackedList<nBits>::values() const Foam::Xfer<Foam::labelList> Foam::PackedList<nBits>::values() const
{ {
labelList elems(size_); labelList elems(size_);
@ -182,12 +139,16 @@ Foam::labelList Foam::PackedList<nBits>::values() const
{ {
elems[i] = get(i); elems[i] = get(i);
} }
return elems;
return elems.xfer();
} }
template<unsigned nBits> template<unsigned nBits>
Foam::Ostream& Foam::PackedList<nBits>::iteratorBase::print(Ostream& os) const Foam::Ostream& Foam::PackedList<nBits>::iteratorBase::printInfo
(
Ostream& os
) const
{ {
os << "iterator<" << label(nBits) << "> [" os << "iterator<" << label(nBits) << "> ["
<< this->index_ << "]" << this->index_ << "]"
@ -201,78 +162,381 @@ Foam::Ostream& Foam::PackedList<nBits>::iteratorBase::print(Ostream& os) const
template<unsigned nBits> template<unsigned nBits>
Foam::Ostream& Foam::PackedList<nBits>::print(Ostream& os) const Foam::Ostream& Foam::PackedList<nBits>::printBits
(
Ostream& os,
const bool fullOutput
) const
{ {
const label packLen = packedLength(size_); const label packLen = packedLength();
os << "PackedList<" << nBits << ">"
<< " max_value:" << max_value()
<< " packing:" << packing() << nl
<< " count: " << count() << nl
<< " size/capacity: " << size_ << "/" << capacity() << nl
<< " storage/capacity: " << packLen << "/" << StorageList::size()
<< "\n(\n";
// mask value for complete segments // mask value for complete segments
unsigned int mask = maskLower(packing()); unsigned int mask = maskLower(packing());
const label outputLen = fullOutput ? StorageList::size() : packLen;
for (label i=0; i < packLen; i++) os << "(\n";
for (label i=0; i < outputLen; ++i)
{ {
const StorageType& rawBits = StorageList::operator[](i); const StorageType& rawBits = StorageList::operator[](i);
// the final segment may not be full, modify mask accordingly // the final segment may not be full, modify mask accordingly
if (i+1 == packLen) if (i == packLen-1)
{ {
unsigned int endOff = size_ % packing(); const unsigned int off = size_ % packing();
if (endOff) if (off)
{ {
mask = maskLower(endOff); mask = maskLower(off);
}
else
{
continue;
} }
} }
else if (i == packLen)
{
// no mask for unaddressed bit
mask = 0u;
}
for (unsigned int testBit = (1u << max_bits()); testBit; testBit >>= 1) for (unsigned int testBit = (1u << max_bits()); testBit; testBit >>= 1)
{ {
if (mask & testBit) if (mask & testBit)
{ {
// addressable region
if (rawBits & testBit) if (rawBits & testBit)
{ {
os << '1'; os << '1';
} }
else else
{ {
os << '-'; os << '-';
} }
} }
else else
{ {
os << 'x'; if (rawBits & testBit)
{
os << '!';
}
else
{
os << '.';
}
} }
} }
os << '\n'; os << '\n';
} }
os << ")\n"; os << ")\n";
return os; return os;
} }
template<unsigned nBits>
Foam::Ostream& Foam::PackedList<nBits>::printInfo
(
Ostream& os,
const bool fullOutput
) const
{
os << "PackedList<" << nBits << ">"
<< " max_value:" << max_value()
<< " packing:" << packing() << nl
<< " count: " << count() << nl
<< " size/capacity: " << size_ << "/" << capacity() << nl
<< " storage/capacity: "
<< packedLength() << "/" << StorageList::size()
<< "\n";
return printBits(os, fullOutput);
}
template<unsigned nBits>
Foam::Istream& Foam::PackedList<nBits>::read(Istream& is)
{
PackedList<nBits>& lst = *this;
lst.clear();
is.fatalCheck("PackedList<nBits>::read(Istream&)");
token firstTok(is);
is.fatalCheck
(
"PackedList<nBits>::read(Istream&) : "
"reading first token"
);
if (firstTok.isLabel())
{
const label sz = firstTok.labelToken();
// Set list length to that read
lst.resize(sz);
// Read list contents depending on data format
if (is.format() == IOstream::ASCII)
{
// Read beginning of contents
const char delimiter = is.readBeginList("PackedList<nBits>");
if (sz)
{
if (delimiter == token::BEGIN_LIST)
{
for (register label i=0; i<sz; ++i)
{
lst[i] = lst.readValue(is);
is.fatalCheck
(
"PackedList<nBits>::read(Istream&) : "
"reading entry"
);
}
}
else if (delimiter == token::BEGIN_BLOCK)
{
// assign for all entries
lst = lst.readValue(is);
is.fatalCheck
(
"PackedList<nBits>::read(Istream&) : "
"reading the single entry"
);
}
else
{
FatalIOErrorIn
(
"PackedList<nBits>::read(Istream&)",
is
)
<< "incorrect list token, expected '(' or '{', found "
<< firstTok.info()
<< exit(FatalIOError);
}
}
// Read end of contents
is.readEndList("PackedList<nBits>");
}
else
{
if (sz)
{
is.read
(
reinterpret_cast<char*>(lst.storage().data()),
lst.byteSize()
);
is.fatalCheck
(
"PackedList<nBits>::read(Istream&) : "
"reading the binary block"
);
}
}
}
else if (firstTok.isPunctuation())
{
if (firstTok.pToken() == token::BEGIN_LIST)
{
token nextTok(is);
is.fatalCheck("PackedList<nBits>::read(Istream&)");
while
(
!( nextTok.isPunctuation()
&& nextTok.pToken() == token::END_LIST
)
)
{
is.putBack(nextTok);
lst.append(lst.readValue(is));
is >> nextTok;
is.fatalCheck("PackedList<nBits>::read(Istream&)");
}
}
else if (firstTok.pToken() == token::BEGIN_BLOCK)
{
token nextTok(is);
is.fatalCheck("PackedList<nBits>::read(Istream&)");
while
(
!( nextTok.isPunctuation()
&& nextTok.pToken() == token::END_BLOCK
)
)
{
is.putBack(nextTok);
lst.setPair(is);
is >> nextTok;
is.fatalCheck("PackedList<nBits>::read(Istream&)");
}
}
else
{
FatalIOErrorIn
(
"PackedList<nBits>::read(Istream&)",
is
)
<< "incorrect first token, expected '(', found "
<< firstTok.info()
<< exit(FatalIOError);
}
}
else
{
FatalIOErrorIn
(
"PackedList<nBits>::read(Istream&)",
is
)
<< "incorrect first token, expected <int>, '(' or '{', found "
<< firstTok.info()
<< exit(FatalIOError);
}
return is;
}
template<unsigned nBits>
Foam::Ostream& Foam::PackedList<nBits>::write
(
Ostream& os,
const bool indexedOutput
) const
{
const PackedList<nBits>& lst = *this;
const label sz = lst.size();
// Write list contents depending on data format
if (os.format() == IOstream::ASCII)
{
bool uniform = false;
if (sz > 1 && !indexedOutput)
{
uniform = true;
forAll(lst, i)
{
if (lst[i] != lst[0])
{
uniform = false;
break;
}
}
}
if (uniform)
{
// uniform values:
os << sz << token::BEGIN_BLOCK << lst[0] << token::END_BLOCK;
}
else if (indexedOutput)
{
// indexed output
os << nl << token::BEGIN_BLOCK << nl;
for
(
typename PackedList<nBits>::const_iterator iter = lst.cbegin();
iter != lst.cend();
++iter
)
{
if (iter.writeIfSet(os))
{
os << nl;
}
}
os << token::END_BLOCK << nl;
}
else if (sz < 11)
{
// short list:
os << sz << token::BEGIN_LIST;
forAll(lst, i)
{
if (i)
{
os << token::SPACE;
}
os << lst[i];
}
os << token::END_LIST;
}
else
{
// longer list:
os << nl << sz << nl << token::BEGIN_LIST;
forAll(lst, i)
{
os << nl << lst[i];
}
os << nl << token::END_LIST << nl;
}
}
else
{
os << nl << sz << nl;
if (sz)
{
os.write
(
reinterpret_cast<const char*>(lst.storage().cdata()),
lst.byteSize()
);
}
}
return os;
}
template<unsigned nBits>
void Foam::PackedList<nBits>::writeEntry(Ostream& os) const
{
os << *this;
}
template<unsigned nBits>
void Foam::PackedList<nBits>::writeEntry
(
const word& keyword,
Ostream& os
) const
{
os.writeKeyword(keyword);
writeEntry(os);
os << token::END_STATEMENT << endl;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<unsigned nBits> template<unsigned nBits>
void Foam::PackedList<nBits>::operator=(const PackedList<nBits>& lst) Foam::PackedList<nBits>&
Foam::PackedList<nBits>::operator=(const PackedList<nBits>& lst)
{ {
StorageList::operator=(lst); StorageList::operator=(lst);
size_ = lst.size(); size_ = lst.size();
return *this;
} }
template<unsigned nBits> template<unsigned nBits>
void Foam::PackedList<nBits>::operator=(const UList<label>& lst) Foam::PackedList<nBits>&
Foam::PackedList<nBits>::operator=(const UList<label>& lst)
{ {
setCapacity(lst.size()); setCapacity(lst.size());
size_ = lst.size(); size_ = lst.size();
@ -281,19 +545,39 @@ void Foam::PackedList<nBits>::operator=(const UList<label>& lst)
{ {
set(i, lst[i]); set(i, lst[i]);
} }
return *this;
} }
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * // template<unsigned nBits>
Foam::PackedList<nBits>&
Foam::PackedList<nBits>::operator=(const UIndirectList<label>& lst)
{
setCapacity(lst.size());
size_ = lst.size();
//template<unsigned nBits> forAll(lst, i)
//Foam::Ostream& ::Foam::operator<<(Ostream& os, const PackedList<nBits>& lst) {
//{ set(i, lst[i]);
// os << lst(); }
// return os; return *this;
//} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
template<unsigned nBits>
Foam::Istream& Foam::operator>>(Istream& is, PackedList<nBits>& lst)
{
return lst.read(is);
}
template<unsigned nBits>
Foam::Ostream& Foam::operator<<(Ostream& os, const PackedList<nBits>& lst)
{
return lst.write(os, false);
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -72,6 +72,23 @@ Note
list[8] = 1; list[8] = 1;
@endcode @endcode
Also note that all unused internal storage elements are guaranteed to
always be bit-wise zero. This property must not be violated by any
inheriting classes.
In addition to the normal output format, PackedList also supports a
compact ASCII format that may be convenient for user input in some
situations. The general format is a group of index/value pairs:
@verbatim
{ (index1 value1) (index2 value2) (index3 value3) }
@endverbatim
The bool specialization just uses the indices corresponding to
non-zero entries instead of a index/value pair:
@verbatim
{ index1 index2 index3 }
@endverbatim
In both cases, the supplied indices can be randomly ordered.
SeeAlso SeeAlso
Foam::DynamicList Foam::DynamicList
@ -85,6 +102,7 @@ SourceFiles
#define PackedList_H #define PackedList_H
#include "labelList.H" #include "labelList.H"
#include "UIndirectList.H"
#include "StaticAssert.H" #include "StaticAssert.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -92,18 +110,34 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declaration of classes
class Istream;
class Ostream;
// Forward declaration of friend functions and operators // Forward declaration of friend functions and operators
template<unsigned nBits> class PackedList; template<unsigned nBits> class PackedList;
// template<unsigned nBits> template<unsigned nBits>
// Ostream& operator<<(Ostream&, const PackedList<nBits>&); Istream& operator>>(Istream&, PackedList<nBits>&);
template<unsigned nBits>
Ostream& operator<<(Ostream&, const PackedList<nBits>&);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class PackedListName Declaration Class PackedListCore Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
TemplateName(PackedList); //- Template-invariant bits for PackedList
struct PackedListCore
{
//- Construct null
PackedListCore()
{}
//- Define template name and debug
ClassName("PackedList");
};
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class PackedList Declaration Class PackedList Declaration
@ -112,26 +146,40 @@ TemplateName(PackedList);
template<unsigned nBits=1> template<unsigned nBits=1>
class PackedList class PackedList
: :
public PackedListCore,
private List<unsigned int> private List<unsigned int>
{ {
protected:
typedef unsigned int StorageType; typedef unsigned int StorageType;
typedef List<StorageType> StorageList; typedef List<StorageType> StorageList;
//- nBits must be positive (non-zero) and fit within the storage // Protected Member Functions
// For simplicity, assume 8-bit bytes
StaticAssert(nBits && nBits < (sizeof(StorageType) << 3)); //- Calculate the list length when packed
inline static label packedLength(const label);
//- Read a list entry (allows for specialization)
inline static unsigned int readValue(Istream&);
//- Read an index/value pair and set accordingly.
// For bool specialization, read a single index value
inline void setPair(Istream&);
private:
//- nBits must be positive (non-zero) and fit within the storage.
// For efficiency, however, require packing at least 2 items otherwise
// it is more efficient to use a normal list.
// Thus max nBits is 1/2 of the base storage size.
// For simplicity, assume 8-bit bytes in the assert.
StaticAssert(nBits && nBits <= (sizeof(StorageType) << 2));
// Private data // Private data
//- Number of nBits entries //- Number of nBits entries
label size_; label size_;
// Private Member Functions
//- Calculate the list length when packed
inline static label packedLength(const label);
public: public:
// Public data // Public data
@ -163,20 +211,26 @@ public:
//- Null constructor //- Null constructor
inline PackedList(); inline PackedList();
//- Construct with given size, initializes list to 0. //- Construct with given size, initializes list to 0
explicit inline PackedList(const label size); explicit inline PackedList(const label size);
//- Construct with given size and value for all elements. //- Construct with given size and value for all elements
PackedList(const label size, const unsigned val); inline PackedList(const label size, const unsigned val);
//- Copy constructor. //- Construct from Istream
inline PackedList(Istream&);
//- Copy constructor
inline PackedList(const PackedList<nBits>&); inline PackedList(const PackedList<nBits>&);
//- Construct by transferring the parameter contents //- Construct by transferring the parameter contents
inline PackedList(const Xfer<PackedList<nBits> >&); inline PackedList(const Xfer<PackedList<nBits> >&);
//- Construct from a list of labels //- Construct from a list of labels
explicit PackedList(const UList<label>&); explicit inline PackedList(const UList<label>&);
//- Construct from an indirect list of labels
explicit inline PackedList(const UIndirectList<label>&);
//- Clone //- Clone
inline autoPtr< PackedList<nBits> > clone() const; inline autoPtr< PackedList<nBits> > clone() const;
@ -209,30 +263,52 @@ public:
inline bool unset(const label); inline bool unset(const label);
//- Return the underlying packed storage //- Return the underlying packed storage
// Manipulate with utmost caution
inline List<unsigned int>& storage(); inline List<unsigned int>& storage();
//- Return the underlying packed storage //- Return the underlying packed storage
inline const List<unsigned int>& storage() const; inline const List<unsigned int>& storage() const;
//- The list length when packed
inline label packedLength() const;
//- Return the binary size in number of characters
// used in the underlying storage
inline label byteSize() const;
//- Count number of bits set, O(log(n)) //- Count number of bits set, O(log(n))
// Uses the Hamming weight (population count) method // Uses the Hamming weight (population count) method
// http://en.wikipedia.org/wiki/Hamming_weight // http://en.wikipedia.org/wiki/Hamming_weight
unsigned int count() const; unsigned int count() const;
//- Return the values as a labelList //- Return the values as a list of labels
labelList values() const; Xfer<labelList> values() const;
//- Print bit patterns, optionally output unused elements
//
// addressable bits:
// on: '1', off: '-'
//
// non-addressable bits:
// on: '!', off: '.'
//
Ostream& printBits(Ostream&, const bool fullOutput=false) const;
//- Print information and bit patterns (with printBits)
Ostream& printInfo(Ostream&, const bool fullOutput=false) const;
//- Print values and information
Ostream& print(Ostream&) const;
// Edit // Edit
//- Trim any trailing zero elements //- Trim any trailing zero elements
bool trim(); bool trim();
//- Invert the bits in the addressable region. //- Invert the bits in the addressable region
void flip(); void flip();
//- Clear all bits
inline void reset();
//- Alter the size of the underlying storage. //- Alter the size of the underlying storage.
// The addressed size will be truncated if needed to fit, but will // The addressed size will be truncated if needed to fit, but will
// remain otherwise untouched. // remain otherwise untouched.
@ -240,10 +316,10 @@ public:
//- Reset addressable list size, does not shrink the allocated size. //- Reset addressable list size, does not shrink the allocated size.
// Optionally specify a value for new elements. // Optionally specify a value for new elements.
inline void resize(const label, const unsigned int& val = 0); inline void resize(const label, const unsigned int& val = 0u);
//- Alias for resize() //- Alias for resize()
inline void setSize(const label, const unsigned int& val = 0); inline void setSize(const label, const unsigned int& val = 0u);
//- Reserve allocation space for at least this size. //- Reserve allocation space for at least this size.
// Never shrinks the allocated size. // Never shrinks the allocated size.
@ -269,10 +345,43 @@ public:
inline Xfer<PackedList<nBits> > xfer(); inline Xfer<PackedList<nBits> > xfer();
// IO
//- Clear list and read from stream
Istream& read(Istream&);
//- Write, optionally with indexedOutput
//
// The indexed output may be convenient in some situations.
// The general format is a group of index/value pairs:
// @verbatim
// { (index1 value1) (index2 value2) (index3 value3) }
// @endverbatim
// The bool specialization just uses the indices corresponding to
// non-zero entries instead of a index/value pair:
// @verbatim
// { index1 index2 index3 }
// @endverbatim
//
// Note the indexed output is only supported for ASCII streams.
Ostream& write
(
Ostream&,
const bool indexedOutput=false
) const;
//- Write as a dictionary entry
void writeEntry(Ostream&) const;
//- Write as a dictionary entry with keyword
void writeEntry(const word& keyword, Ostream&) const;
// Member operators // Member operators
//- Append a value at the end of the list //- Append a value at the end of the list
inline void append(const unsigned int val); inline PackedList<nBits>& append(const unsigned int val);
//- Remove and return the last element //- Remove and return the last element
inline unsigned int remove(); inline unsigned int remove();
@ -287,23 +396,16 @@ public:
inline iteratorBase operator[](const label); inline iteratorBase operator[](const label);
//- Assignment of all entries to the given value. Takes linear time. //- Assignment of all entries to the given value. Takes linear time.
inline void operator=(const unsigned int val); inline PackedList<nBits>& operator=(const unsigned int val);
//- Assignment operator. Takes linear time. //- Assignment operator.
void operator=(const PackedList<nBits>&); PackedList<nBits>& operator=(const PackedList<nBits>&);
//- Assignment operator. Takes linear time. //- Assignment operator.
void operator=(const UList<label>&); PackedList<nBits>& operator=(const UList<label>&);
//- Assignment operator.
// Ostream operator PackedList<nBits>& operator=(const UIndirectList<label>&);
// // Write PackedList to Ostream.
// friend Ostream& operator<< <nBits>
// (
// Ostream&,
// const PackedList<nBits>&
// );
// Iterators and helpers // Iterators and helpers
@ -347,6 +449,15 @@ public:
public: public:
// Member Functions
//- Return the element index corresponding to the iterator
inline label key() const;
//- Write index/value for a non-zero entry
// The bool specialization writes the index only
inline bool writeIfSet(Ostream&) const;
// Member Operators // Member Operators
//- Compare values (not positions) //- Compare values (not positions)
@ -365,8 +476,8 @@ public:
// Never auto-vivify entries. // Never auto-vivify entries.
inline operator unsigned int () const; inline operator unsigned int () const;
//- Print value and information //- Print information and values
Ostream& print(Ostream&) const; Ostream& printInfo(Ostream&) const;
}; };
@ -376,11 +487,12 @@ public:
public iteratorBase public iteratorBase
{ {
//- Disallow copy constructor from const_iterator - //- Disallow copy constructor from const_iterator
// violates const-ness! // This would violate const-ness!
iterator(const const_iterator&); iterator(const const_iterator&);
//- Disallow assignment from const_iterator - violates const-ness! //- Disallow assignment from const_iterator
// This would violate const-ness!
void operator=(const const_iterator&); void operator=(const const_iterator&);
@ -497,6 +609,21 @@ public:
//- const_iterator set to beyond the end of the PackedList //- const_iterator set to beyond the end of the PackedList
inline const_iterator end() const; inline const_iterator end() const;
// IOstream Operators
friend Istream& operator>> <nBits>
(
Istream&,
PackedList<nBits>&
);
friend Ostream& operator<< <nBits>
(
Ostream&,
const PackedList<nBits>&
);
}; };

View File

@ -27,6 +27,7 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(Foam::PackedListName, 0); defineTypeNameAndDebug(Foam::PackedListCore, 0);
// ************************************************************************* // // ************************************************************************* //

View File

@ -67,11 +67,117 @@ inline Foam::label Foam::PackedList<nBits>::packedLength(const label nElem)
} }
namespace Foam
{
// Template specialization for bool entries
template<>
inline unsigned int Foam::PackedList<1>::readValue(Istream& is)
{
return readBool(is);
}
// Template specialization for bool entries
template<>
inline void Foam::PackedList<1>::setPair(Istream& is)
{
set(readLabel(is), true);
}
// Template specialization for bool entries
template<>
inline bool Foam::PackedList<1>::iteratorBase::writeIfSet(Ostream& os) const
{
if (this->get())
{
os << index_;
return true;
}
else
{
return false;
}
}
}
template<unsigned nBits>
inline unsigned int Foam::PackedList<nBits>::readValue(Istream& is)
{
const unsigned int val = readLabel(is);
if (val > max_value())
{
FatalIOErrorIn
(
"PackedList<nBits>::readValue(Istream&)",
is
)
<< "Out-of-range value " << val << " for PackedList<" << nBits
<< ">. Maximum permitted value is " << max_value() << "."
<< exit(FatalIOError);
}
return val;
}
template<unsigned nBits>
inline void Foam::PackedList<nBits>::setPair(Istream& is)
{
is.readBegin("Tuple2<label, unsigned int>");
const label ind = readLabel(is);
const unsigned int val = readLabel(is);
is.readEnd("Tuple2<label, unsigned int>");
if (val > max_value())
{
FatalIOErrorIn
(
"PackedList<nBits>::setPair(Istream&)",
is
)
<< "Out-of-range value " << val << " for PackedList<" << nBits
<< "> at index " << ind
<< ". Maximum permitted value is " << max_value() << "."
<< exit(FatalIOError);
}
set(ind, val);
// Check state of Istream
is.check("PackedList<nBits>::setPair(Istream&)");
}
template<unsigned nBits>
inline bool Foam::PackedList<nBits>::iteratorBase::writeIfSet(Ostream& os) const
{
const label val = this->get();
if (val)
{
os << token::BEGIN_LIST
<< index_ << token::SPACE << val
<< token::END_LIST;
return true;
}
else
{
return false;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<unsigned nBits> template<unsigned nBits>
inline Foam::PackedList<nBits>::PackedList() inline Foam::PackedList<nBits>::PackedList()
: :
PackedListCore(),
StorageList(), StorageList(),
size_(0) size_(0)
{} {}
@ -80,14 +186,45 @@ inline Foam::PackedList<nBits>::PackedList()
template<unsigned nBits> template<unsigned nBits>
inline Foam::PackedList<nBits>::PackedList(const label size) inline Foam::PackedList<nBits>::PackedList(const label size)
: :
PackedListCore(),
StorageList(packedLength(size), 0u), StorageList(packedLength(size), 0u),
size_(size) size_(size)
{} {}
template<unsigned nBits>
inline Foam::PackedList<nBits>::PackedList
(
const label size,
const unsigned int val
)
:
PackedListCore(),
StorageList(packedLength(size), 0u),
size_(size)
{
if (val)
{
operator=(val);
}
}
template<unsigned nBits>
inline Foam::PackedList<nBits>::PackedList(Istream& is)
:
PackedListCore(),
StorageList(),
size_(0)
{
read(is);
}
template<unsigned nBits> template<unsigned nBits>
inline Foam::PackedList<nBits>::PackedList(const PackedList<nBits>& lst) inline Foam::PackedList<nBits>::PackedList(const PackedList<nBits>& lst)
: :
PackedListCore(),
StorageList(lst), StorageList(lst),
size_(lst.size_) size_(lst.size_)
{} {}
@ -100,6 +237,34 @@ inline Foam::PackedList<nBits>::PackedList(const Xfer<PackedList<nBits> >& lst)
} }
template<unsigned nBits>
inline Foam::PackedList<nBits>::PackedList(const UList<label>& lst)
:
PackedListCore(),
StorageList(packedLength(lst.size()), 0u),
size_(lst.size())
{
forAll(lst, i)
{
set(i, lst[i]);
}
}
template<unsigned nBits>
inline Foam::PackedList<nBits>::PackedList(const UIndirectList<label>& lst)
:
PackedListCore(),
StorageList(packedLength(lst.size()), 0u),
size_(lst.size())
{
forAll(lst, i)
{
set(i, lst[i]);
}
}
template<unsigned nBits> template<unsigned nBits>
inline Foam::autoPtr<Foam::PackedList<nBits> > inline Foam::autoPtr<Foam::PackedList<nBits> >
Foam::PackedList<nBits>::clone() const Foam::PackedList<nBits>::clone() const
@ -151,27 +316,34 @@ Foam::PackedList<nBits>::iteratorBase::set(const unsigned int val)
const unsigned int seg = index_ / packing(); const unsigned int seg = index_ / packing();
const unsigned int off = index_ % packing(); const unsigned int off = index_ % packing();
const unsigned int startBit = nBits * off;
const unsigned int mask = max_value() << startBit;
unsigned int& stored = list_->StorageList::operator[](seg); unsigned int& stored = list_->StorageList::operator[](seg);
const unsigned int prev = stored; const unsigned int prev = stored;
const unsigned int startBit = nBits * off; if (val >= max_value())
const unsigned int maskNew = max_value() << startBit;
if (val & ~max_value())
{ {
// overflow is max_value, fill everything // overflow is max_value, fill everything
stored |= maskNew; stored |= mask;
} }
else else
{ {
stored &= ~maskNew; stored &= ~mask;
stored |= maskNew & (val << startBit); stored |= mask & (val << startBit);
} }
return prev != stored; return prev != stored;
} }
template<unsigned nBits>
inline Foam::label Foam::PackedList<nBits>::iteratorBase::key() const
{
return index_;
}
template<unsigned nBits> template<unsigned nBits>
inline bool Foam::PackedList<nBits>::iteratorBase::operator== inline bool Foam::PackedList<nBits>::iteratorBase::operator==
( (
@ -564,24 +736,27 @@ inline bool Foam::PackedList<nBits>::empty() const
template<unsigned nBits> template<unsigned nBits>
inline void Foam::PackedList<nBits>::resize inline void Foam::PackedList<nBits>::resize
( (
const label nElem, const label newSize,
const unsigned int& val const unsigned int& val
) )
{ {
reserve(nElem); reserve(newSize);
if (nElem > size_) const label oldSize = size_;
size_ = newSize;
if (size_ > oldSize)
{ {
// fill new elements or newly exposed elements // fill new elements or newly exposed elements
if (size_) if (val)
{ {
// fill value for complete segments // fill value for complete segments
unsigned int fill = val; unsigned int fill = val;
if (fill & ~max_value()) if (val >= max_value())
{ {
// overflow is max_value, fill everything // fill everything
fill = ~0u; fill = maskLower(packing());
} }
else else
{ {
@ -591,36 +766,64 @@ inline void Foam::PackedList<nBits>::resize
} }
} }
unsigned int seg = size_ / packing(); // fill in complete segments
unsigned int off = size_ % packing(); const label oldLen = packedLength(oldSize);
const label newLen = packedLength(size_);
// partial segment, preserve existing value for (label i=oldLen; i < newLen; ++i)
if (off)
{ {
unsigned int maskOld = maskLower(off); StorageList::operator[](i) = fill;
StorageList::operator[](seg) &= maskOld;
StorageList::operator[](seg) |= ~maskOld & fill;
// continue with the next segment
seg++;
} }
unsigned int endSeg = nElem / packing(); // finish previous partial segment, preserve existing value
// fill in complete elements
while (seg < endSeg)
{ {
StorageList::operator[](seg++) = fill; const unsigned int off = oldSize % packing();
if (off)
{
const unsigned int seg = oldSize / packing();
const unsigned int mask = maskLower(off);
StorageList::operator[](seg) &= mask;
StorageList::operator[](seg) |= ~mask & fill;
}
}
// mask off the (new) final partial segment
{
const unsigned int off = size_ % packing();
if (off)
{
const unsigned int seg = size_ / packing();
StorageList::operator[](seg) &= maskLower(off);
}
} }
}
else
{
// no original size - simply flood-fill
operator=(val);
} }
} }
else if (size_ < oldSize)
{
// resize shrinking
// - clear newly exposed elements
size_ = nElem; // fill in complete segments
const label oldLen = packedLength(oldSize);
const label newLen = packedLength(size_);
for (label i=newLen; i < oldLen; ++i)
{
StorageList::operator[](i) = 0u;
}
// mask off the final partial segment
{
const unsigned int off = size_ % packing();
if (off)
{
const unsigned int seg = size_ / packing();
StorageList::operator[](seg) &= maskLower(off);
}
}
}
} }
@ -648,21 +851,27 @@ inline void Foam::PackedList<nBits>::setCapacity(const label nElem)
{ {
StorageList::setSize(packedLength(nElem), 0u); StorageList::setSize(packedLength(nElem), 0u);
// truncate addressed size too? // truncate addressed size too
if (size_ > nElem) if (size_ > nElem)
{ {
size_ = nElem; size_ = nElem;
// mask off the final partial segment
const unsigned int off = size_ % packing();
if (off)
{
const unsigned int seg = size_ / packing();
StorageList::operator[](seg) &= maskLower(off);
}
} }
} }
template<unsigned nBits> template<unsigned nBits>
inline void Foam::PackedList<nBits>::reserve inline void Foam::PackedList<nBits>::reserve(const label nElem)
(
const label nElem
)
{ {
label len = packedLength(nElem); const label len = packedLength(nElem);
// need more capacity? // need more capacity?
if (len > StorageList::size()) if (len > StorageList::size())
@ -681,9 +890,17 @@ inline void Foam::PackedList<nBits>::reserve
} }
template<unsigned nBits>
inline void Foam::PackedList<nBits>::reset()
{
StorageList::operator=(0u);
}
template<unsigned nBits> template<unsigned nBits>
inline void Foam::PackedList<nBits>::clear() inline void Foam::PackedList<nBits>::clear()
{ {
reset();
size_ = 0; size_ = 0;
} }
@ -699,9 +916,8 @@ inline void Foam::PackedList<nBits>::clearStorage()
template<unsigned nBits> template<unsigned nBits>
inline void Foam::PackedList<nBits>::shrink() inline void Foam::PackedList<nBits>::shrink()
{ {
label len = packedLength(size_); // any uneed space allocated?
const label len = packedLength();
// we have unused space?
if (len < StorageList::size()) if (len < StorageList::size())
{ {
StorageList::setSize(len); StorageList::setSize(len);
@ -722,6 +938,20 @@ inline const Foam::List<unsigned int>& Foam::PackedList<nBits>::storage() const
} }
template<unsigned nBits>
inline Foam::label Foam::PackedList<nBits>::packedLength() const
{
return packedLength(size_);
}
template<unsigned nBits>
inline Foam::label Foam::PackedList<nBits>::byteSize() const
{
return packedLength() * sizeof(StorageType);
}
template<unsigned nBits> template<unsigned nBits>
inline void Foam::PackedList<nBits>::transfer(PackedList<nBits>& lst) inline void Foam::PackedList<nBits>::transfer(PackedList<nBits>& lst)
{ {
@ -742,23 +972,14 @@ inline Foam::Xfer<Foam::PackedList<nBits> > Foam::PackedList<nBits>::xfer()
template<unsigned nBits> template<unsigned nBits>
inline unsigned int Foam::PackedList<nBits>::get(const label i) const inline unsigned int Foam::PackedList<nBits>::get(const label i) const
{ {
# ifdef FULLDEBUG
if (i < 0)
{
FatalErrorIn("PackedList<nBits>::get(const label)")
<< "negative index " << i << " max=" << size_-1
<< abort(FatalError);
}
# endif
// lazy evaluation - return 0 for out-of-range // lazy evaluation - return 0 for out-of-range
if (i < size_) if (i < 0 || i >= size_)
{ {
return iteratorBase(this, i).get(); return 0;
} }
else else
{ {
return 0; return iteratorBase(this, i).get();
} }
} }
@ -767,13 +988,13 @@ template<unsigned nBits>
inline unsigned int Foam::PackedList<nBits>::operator[](const label i) const inline unsigned int Foam::PackedList<nBits>::operator[](const label i) const
{ {
// lazy evaluation - return 0 for out-of-range // lazy evaluation - return 0 for out-of-range
if (i < size_) if (i < 0 || i >= size_)
{ {
return iteratorBase(this, i).get(); return 0;
} }
else else
{ {
return 0; return iteratorBase(this, i).get();
} }
} }
@ -785,18 +1006,14 @@ inline bool Foam::PackedList<nBits>::set
const unsigned int val const unsigned int val
) )
{ {
# ifdef FULLDEBUG
if (i < 0) if (i < 0)
{ {
FatalErrorIn("PackedList<nBits>::set(const label)") // lazy evaluation - ignore out-of-bounds
<< "negative index " << i << " max=" << size_-1 return false;
<< abort(FatalError);
} }
# endif else if (i >= size_)
// lazy evaluation - increase size on assigment
if (i >= size_)
{ {
// lazy evaluation - increase size on assigment
resize(i + 1); resize(i + 1);
} }
@ -807,24 +1024,28 @@ inline bool Foam::PackedList<nBits>::set
template<unsigned nBits> template<unsigned nBits>
inline bool Foam::PackedList<nBits>::unset(const label i) inline bool Foam::PackedList<nBits>::unset(const label i)
{ {
// lazy - ignore out-of-bounds // lazy evaluation - ignore out-of-bounds
if (i < 0 || i >= size_) if (i < 0 || i >= size_)
{ {
return false; return false;
} }
else
return iteratorBase(this, i).set(0u); {
return iteratorBase(this, i).set(0u);
}
} }
template<unsigned nBits> template<unsigned nBits>
inline void Foam::PackedList<nBits>::append(const unsigned int val) inline Foam::PackedList<nBits>&
Foam::PackedList<nBits>::append(const unsigned int val)
{ {
label elemI = size_; const label elemI = size_;
reserve(elemI + 1); reserve(elemI + 1);
size_++; size_++;
iteratorBase(this, elemI).set(val); iteratorBase(this, elemI).set(val);
return *this;
} }
@ -855,35 +1076,20 @@ Foam::PackedList<nBits>::operator[](const label i)
} }
namespace Foam
{
// specialization for nBits=1
template<>
inline void Foam::PackedList<1>::operator=(const unsigned int val)
{
if (val)
{
StorageList::operator=(~0u);
}
else
{
StorageList::operator=(0u);
}
}
}
template<unsigned nBits> template<unsigned nBits>
inline void Foam::PackedList<nBits>::operator=(const unsigned int val) inline Foam::PackedList<nBits>&
Foam::PackedList<nBits>::operator=(const unsigned int val)
{ {
if (val) const label packLen = packedLength();
if (val && size_)
{ {
unsigned int fill = val; unsigned int fill = val;
if (fill & ~max_value()) if (val >= max_value())
{ {
// treat overflow as max_value // fill everything
fill = ~0u; fill = maskLower(packing());
} }
else else
{ {
@ -893,12 +1099,31 @@ inline void Foam::PackedList<nBits>::operator=(const unsigned int val)
} }
} }
StorageList::operator=(fill); for (label i=0; i < packLen; ++i)
{
StorageList::operator[](i) = fill;
}
// mask off the final partial segment
{
const unsigned int off = size_ % packing();
if (off)
{
const unsigned int seg = size_ / packing();
StorageList::operator[](seg) &= maskLower(off);
}
}
} }
else else
{ {
StorageList::operator=(0u); for (label i=0; i < packLen; ++i)
{
StorageList::operator[](i) = 0u;
}
} }
return *this;
} }

View File

@ -22,11 +22,12 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description Description
Read of a non-delimited hex label Read a non-delimited hex label
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "readHexLabel.H" #include "readHexLabel.H"
#include <cctype>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -55,7 +56,7 @@ Foam::label Foam::readHexLabel(ISstream& is)
<< exit(FatalIOError); << exit(FatalIOError);
} }
result *= 16; result <<= 4;
if (isdigit(c)) if (isdigit(c))
{ {

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -22,51 +22,48 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class Class
Foam::ZoneID Foam::DynamicID
Description Description
A class that holds the data needed to identify a zone in a dynamic mesh. A class that holds the data needed to identify things (zones, patches)
in a dynamic mesh.
The zone is identified by name. The thing is identified by name.
Its index in the zoneMesh is updated if the mesh has changed. Its indices are updated if the mesh has changed.
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef ZoneID_H #ifndef DynamicID_H
#define ZoneID_H #define DynamicID_H
#include "label.H" #include "keyType.H"
#include "word.H" #include "labelList.H"
#include "polyMesh.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
template<class ZoneType, class MeshType> class ZoneMesh;
// Forward declaration of friend functions and operators // Forward declaration of friend functions and operators
template<class> class DynamicID;
template<class ZoneType> class ZoneID; template<class ObjectType>
Ostream& operator<<(Ostream&, const DynamicID<ObjectType>&);
template<class ZoneType>
Ostream& operator<<(Ostream&, const ZoneID<ZoneType>&);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class ZoneID Declaration Class DynamicID Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class ZoneType> template<class ObjectType>
class ZoneID class DynamicID
{ {
// Private data // Private data
//- Zone name //- Zone name
word name_; keyType key_;
//- Zone index //- Zone indices
label index_; labelList indices_;
public: public:
@ -74,17 +71,17 @@ public:
// Constructors // Constructors
//- Construct from name //- Construct from name
ZoneID(const word& name, const ZoneMesh<ZoneType, polyMesh>& zm) DynamicID(const keyType& key, const ObjectType& obj)
: :
name_(name), key_(key),
index_(zm.findZoneID(name)) indices_(obj.findIndices(key_))
{} {}
//- Construct from Istream //- Construct from Istream
ZoneID(Istream& is, const ZoneMesh<ZoneType, polyMesh>& zm) DynamicID(Istream& is, const ObjectType& obj)
: :
name_(is), key_(is),
index_(zm.findZoneID(name_)) indices_(obj.findIndices(key_))
{} {}
@ -96,57 +93,57 @@ public:
// Access // Access
//- Return name //- Return name
const word& name() const const keyType& name() const
{ {
return name_; return key_;
} }
//- Return index //- Return indices of matching zones
const labelList& indices() const
{
return indices_;
}
//- Return index of first matching zone
label index() const label index() const
{ {
return index_; return indices_.empty() ? -1 : indices_[0];
} }
//- Has the zone been found //- Has the zone been found
bool active() const bool active() const
{ {
return index_ > -1; return !indices_.empty();
} }
// Edit // Edit
//- Update //- Update
void update(const ZoneMesh<ZoneType, polyMesh>& zm) void update(const ObjectType& obj)
{ {
index_ = zm.findZoneID(name_); indices_ = obj.findIndices(key_);
} }
// IOstream Operators // IOstream Operators
friend Ostream& operator<< <ZoneType> friend Ostream& operator<< <ObjectType>
( (Ostream&, const DynamicID<ObjectType>&);
Ostream& os, const ZoneID<ZoneType>& p
);
}; };
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class ZoneType> template<class ObjectType>
Ostream& operator<< Ostream& operator<<(Ostream& os, const DynamicID<ObjectType>& dynId)
(
Ostream& os, const ZoneID<ZoneType>& p
)
{ {
os << token::BEGIN_LIST os << token::BEGIN_LIST
<< p.name_ << token::SPACE << dynId.name() << token::SPACE << dynId.index()
<< p.index_
<< token::END_LIST; << token::END_LIST;
// Check state of Ostream // Check state of Ostream
os.check("Ostream& operator<<(Ostream&, const ZoneID<ZoneType>&)"); os.check("Ostream& operator<<(Ostream&, const DynamicID<ObjectType>&)");
return os; return os;
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -21,25 +21,20 @@ License
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Typedef
Foam::PackedBoolList
Description
A bit-packed bool list
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef PackedBoolList_H #ifndef polyPatchID_H
#define PackedBoolList_H #define polyPatchID_H
#include "bool.H" #include "DynamicID.H"
#include "PackedList.H" #include "polyBoundaryMesh.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
typedef PackedList<> PackedBoolList; //- Foam::polyPatchID
typedef DynamicID<polyBoundaryMesh> polyPatchID;
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -26,21 +26,26 @@ License
#ifndef ZoneIDs_H #ifndef ZoneIDs_H
#define ZoneIDs_H #define ZoneIDs_H
#include "ZoneID.H" #include "DynamicID.H"
#include "pointZone.H"
#include "faceZone.H" #include "cellZoneMeshFwd.H"
#include "cellZone.H" #include "faceZoneMeshFwd.H"
#include "pointZoneMeshFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
//- Foam::pointZoneID
typedef ZoneID<pointZone> pointZoneID;
//- Foam::faceZoneID
typedef ZoneID<faceZone> faceZoneID;
//- Foam::cellZoneID //- Foam::cellZoneID
typedef ZoneID<cellZone> cellZoneID; typedef DynamicID<cellZoneMesh> cellZoneID;
//- Foam::faceZoneID
typedef DynamicID<faceZoneMesh> faceZoneID;
//- Foam::pointZoneID
typedef DynamicID<pointZoneMesh> pointZoneID;
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -31,6 +31,7 @@ License
#include "PstreamBuffers.H" #include "PstreamBuffers.H"
#include "lduSchedule.H" #include "lduSchedule.H"
#include "globalMeshData.H" #include "globalMeshData.H"
#include "stringListOps.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -413,6 +414,66 @@ Foam::wordList Foam::polyBoundaryMesh::physicalTypes() const
} }
Foam::labelList Foam::polyBoundaryMesh::findIndices(const keyType& key) const
{
labelList indices;
if (!key.empty())
{
if (key.isPattern())
{
indices = findStrings(key, this->names());
}
else
{
indices.setSize(this->size());
label nFound = 0;
forAll(*this, i)
{
if (key == operator[](i).name())
{
indices[nFound++] = i;
}
}
indices.setSize(nFound);
}
}
return indices;
}
Foam::label Foam::polyBoundaryMesh::findIndex(const keyType& key) const
{
if (!key.empty())
{
if (key.isPattern())
{
labelList indices = this->findIndices(key);
// return first element
if (!indices.empty())
{
return indices[0];
}
}
else
{
forAll(*this, i)
{
if (key == operator[](i).name())
{
return i;
}
}
}
}
// not found
return -1;
}
Foam::label Foam::polyBoundaryMesh::findPatchID(const word& patchName) const Foam::label Foam::polyBoundaryMesh::findPatchID(const word& patchName) const
{ {
const polyPatchList& patches = *this; const polyPatchList& patches = *this;
@ -444,7 +505,11 @@ Foam::label Foam::polyBoundaryMesh::whichPatch(const label faceIndex) const
// with patch start labels. // with patch start labels.
// If the face is internal, return -1; // If the face is internal, return -1;
// if it is off the end of the list, abort // if it is off the end of the list, abort
if (faceIndex >= mesh().nFaces()) if (faceIndex < mesh().nInternalFaces())
{
return -1;
}
else if (faceIndex >= mesh().nFaces())
{ {
FatalErrorIn FatalErrorIn
( (
@ -453,10 +518,6 @@ Foam::label Foam::polyBoundaryMesh::whichPatch(const label faceIndex) const
<< abort(FatalError); << abort(FatalError);
} }
if (faceIndex < mesh().nInternalFaces())
{
return -1;
}
forAll(*this, patchI) forAll(*this, patchI)
{ {
@ -578,7 +639,7 @@ bool Foam::polyBoundaryMesh::checkParallelSync(const bool report) const
// Have every processor check but only master print error. // Have every processor check but only master print error.
for (label procI = 1; procI < allNames.size(); procI++) for (label procI = 1; procI < allNames.size(); ++procI)
{ {
if if
( (

View File

@ -38,6 +38,7 @@ SourceFiles
#include "polyPatchList.H" #include "polyPatchList.H"
#include "regIOobject.H" #include "regIOobject.H"
#include "labelPair.H" #include "labelPair.H"
#include "HashSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -151,6 +152,12 @@ public:
//- Return a list of physical types //- Return a list of physical types
wordList physicalTypes() const; wordList physicalTypes() const;
//- Return patch indices for all matches
labelList findIndices(const keyType&) const;
//- Return patch index for the first match, return -1 if not found
label findIndex(const keyType&) const;
//- Find patch index given a name //- Find patch index given a name
label findPatchID(const word& patchName) const; label findPatchID(const word& patchName) const;

View File

@ -1,142 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::polyPatchID
Description
A class holds the data needed to identify a patch in a dynamic mesh.
The patch is identified by name and its index in the boundary mesh
is updated if the mesh has changed.
\*---------------------------------------------------------------------------*/
#ifndef polyPatchID_H
#define polyPatchID_H
#include "polyBoundaryMesh.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of friend functions and operators
class polyPatchID;
Ostream& operator<<(Ostream& os, const polyPatchID& p);
/*---------------------------------------------------------------------------*\
Class polyPatchID Declaration
\*---------------------------------------------------------------------------*/
class polyPatchID
{
// Private data
//- Patch name
word name_;
//- Patch index
label index_;
public:
// Constructors
//- Construct from name
polyPatchID(const word& name, const polyBoundaryMesh& bm)
:
name_(name),
index_(bm.findPatchID(name))
{}
//- Construct from Istream
polyPatchID(Istream& is, const polyBoundaryMesh& bm)
:
name_(is),
index_(bm.findPatchID(name_))
{}
// Member Functions
// Access
//- Return name
const word& name() const
{
return name_;
}
//- Return index
label index() const
{
return index_;
}
//- Has the patch been found
bool active() const
{
return index_ > -1;
}
// Edit
//- Update
void update(const polyBoundaryMesh& bm)
{
index_ = bm.findPatchID(name_);
}
// Ostream Operator
friend Ostream& operator<<(Ostream& os, const polyPatchID& p)
{
os << token::BEGIN_LIST
<< p.name_ << token::SPACE
<< p.index_
<< token::END_LIST;
// Check state of Ostream
os.check("Ostream& operator<<(Ostream&, const polyPatchID&)");
return os;
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -250,23 +250,27 @@ Foam::labelList Foam::ZoneMesh<ZoneType, MeshType>::findIndices
) const ) const
{ {
labelList indices; labelList indices;
if (key.isPattern())
if (!key.empty())
{ {
indices = findStrings(key, this->names()); if (key.isPattern())
}
else
{
indices.setSize(this->size());
label nFound = 0;
forAll(*this, i)
{ {
if (key == operator[](i).name()) indices = findStrings(key, this->names());
{
indices[nFound++] = i;
}
} }
indices.setSize(nFound); else
} {
indices.setSize(this->size());
label nFound = 0;
forAll(*this, i)
{
if (key == operator[](i).name())
{
indices[nFound++] = i;
}
}
indices.setSize(nFound);
}
}
return indices; return indices;
} }
@ -278,22 +282,26 @@ Foam::label Foam::ZoneMesh<ZoneType, MeshType>::findIndex
const keyType& key const keyType& key
) const ) const
{ {
if (key.isPattern()) if (!key.empty())
{ {
labelList indices = this->findIndices(key); if (key.isPattern())
// return first element
if (!indices.empty())
{ {
return indices[0]; labelList indices = this->findIndices(key);
}
} // return first element
else if (!indices.empty())
{
forAll(*this, i)
{
if (key == operator[](i).name())
{ {
return i; return indices[0];
}
}
else
{
forAll(*this, i)
{
if (key == operator[](i).name())
{
return i;
}
} }
} }
} }
@ -332,6 +340,24 @@ Foam::label Foam::ZoneMesh<ZoneType, MeshType>::findZoneID
} }
template<class ZoneType, class MeshType>
Foam::PackedBoolList Foam::ZoneMesh<ZoneType, MeshType>::findMatching
(
const keyType& key
) const
{
PackedBoolList lst;
const labelList indices = this->findIndices(key);
forAll(indices, i)
{
lst |= static_cast<const labelList&>(this->operator[](indices[i]));
}
return lst;
}
template<class ZoneType, class MeshType> template<class ZoneType, class MeshType>
void Foam::ZoneMesh<ZoneType, MeshType>::clearAddressing() void Foam::ZoneMesh<ZoneType, MeshType>::clearAddressing()
{ {

View File

@ -25,7 +25,7 @@ Class
Foam::ZoneMesh Foam::ZoneMesh
Description Description
List of mesh zones A list of mesh zones.
SourceFiles SourceFiles
ZoneMesh.C ZoneMesh.C
@ -37,8 +37,9 @@ SourceFiles
#include "List.H" #include "List.H"
#include "regIOobject.H" #include "regIOobject.H"
#include "HashSet.H"
#include "pointFieldsFwd.H" #include "pointFieldsFwd.H"
#include "Map.H"
#include "PackedBoolList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -131,15 +132,18 @@ public:
//- Return a list of zone names //- Return a list of zone names
wordList names() const; wordList names() const;
//- Find zone index given a name
label findZoneID(const word& zoneName) const;
//- Return zone indices for all matches //- Return zone indices for all matches
labelList findIndices(const keyType&) const; labelList findIndices(const keyType&) const;
//- Return zone index for the first match, return -1 if not found //- Return zone index for the first match, return -1 if not found
label findIndex(const keyType&) const; label findIndex(const keyType&) const;
//- Find zone index given a name
label findZoneID(const word& zoneName) const;
//- Mark cells that match the zone specification
PackedBoolList findMatching(const keyType&) const;
//- Clear addressing //- Clear addressing
void clearAddressing(); void clearAddressing();

View File

@ -47,7 +47,7 @@ const char * const Foam::cellZone::labelsName = "cellLabels";
Foam::cellZone::cellZone Foam::cellZone::cellZone
( (
const word& name, const word& name,
const labelList& addr, const unallocLabelList& addr,
const label index, const label index,
const cellZoneMesh& zm const cellZoneMesh& zm
) )
@ -86,7 +86,7 @@ Foam::cellZone::cellZone
Foam::cellZone::cellZone Foam::cellZone::cellZone
( (
const cellZone& cz, const cellZone& cz,
const labelList& addr, const unallocLabelList& addr,
const label index, const label index,
const cellZoneMesh& zm const cellZoneMesh& zm
) )
@ -154,7 +154,14 @@ void Foam::cellZone::operator=(const cellZone& zn)
} }
void Foam::cellZone::operator=(const labelList& addr) void Foam::cellZone::operator=(const unallocLabelList& addr)
{
clearAddressing();
labelList::operator=(addr);
}
void Foam::cellZone::operator=(const Xfer<labelList>& addr)
{ {
clearAddressing(); clearAddressing();
labelList::operator=(addr); labelList::operator=(addr);

View File

@ -113,7 +113,7 @@ public:
cellZone cellZone
( (
const word& name, const word& name,
const labelList& addr, const unallocLabelList& addr,
const label index, const label index,
const cellZoneMesh& const cellZoneMesh&
); );
@ -141,7 +141,7 @@ public:
cellZone cellZone
( (
const cellZone&, const cellZone&,
const labelList& addr, const unallocLabelList& addr,
const label index, const label index,
const cellZoneMesh& const cellZoneMesh&
); );
@ -169,7 +169,7 @@ public:
// and zone mesh // and zone mesh
virtual autoPtr<cellZone> clone virtual autoPtr<cellZone> clone
( (
const labelList& addr, const unallocLabelList& addr,
const label index, const label index,
const cellZoneMesh& zm const cellZoneMesh& zm
) const ) const
@ -222,11 +222,14 @@ public:
// Member Operators // Member Operators
//- Assign to zone clearing demand-driven data //- Assign to zone, clearing demand-driven data
void operator=(const cellZone&); void operator=(const cellZone&);
//- Assign addressing clearing demand-driven data //- Assign addressing, clearing demand-driven data
void operator=(const labelList&); void operator=(const unallocLabelList&);
//- Assign addressing, clearing demand-driven data
void operator=(const Xfer<labelList>&);
// I-O // I-O

View File

@ -180,7 +180,7 @@ void Foam::faceZone::checkAddressing() const
Foam::faceZone::faceZone Foam::faceZone::faceZone
( (
const word& name, const word& name,
const labelList& addr, const unallocLabelList& addr,
const boolList& fm, const boolList& fm,
const label index, const label index,
const faceZoneMesh& zm const faceZoneMesh& zm
@ -242,7 +242,7 @@ Foam::faceZone::faceZone
Foam::faceZone::faceZone Foam::faceZone::faceZone
( (
const faceZone& fz, const faceZone& fz,
const labelList& addr, const unallocLabelList& addr,
const boolList& fm, const boolList& fm,
const label index, const label index,
const faceZoneMesh& zm const faceZoneMesh& zm
@ -392,7 +392,7 @@ void Foam::faceZone::clearAddressing()
void Foam::faceZone::resetAddressing void Foam::faceZone::resetAddressing
( (
const labelList& addr, const unallocLabelList& addr,
const boolList& flipMap const boolList& flipMap
) )
{ {
@ -414,7 +414,7 @@ void Foam::faceZone::updateMesh(const mapPolyMesh& mpm)
forAll(*this, i) forAll(*this, i)
{ {
label faceI = operator[](i); const label faceI = operator[](i);
if (faceMap[faceI] >= 0) if (faceMap[faceI] >= 0)
{ {
@ -454,7 +454,7 @@ bool Foam::faceZone::checkParallelSync(const bool report) const
boolList neiZoneFlip(mesh.nFaces()-mesh.nInternalFaces(), false); boolList neiZoneFlip(mesh.nFaces()-mesh.nInternalFaces(), false);
forAll(*this, i) forAll(*this, i)
{ {
label faceI = operator[](i); const label faceI = operator[](i);
if (!mesh.isInternalFace(faceI)) if (!mesh.isInternalFace(faceI))
{ {
@ -469,13 +469,12 @@ bool Foam::faceZone::checkParallelSync(const bool report) const
forAll(*this, i) forAll(*this, i)
{ {
label faceI = operator[](i); const label faceI = operator[](i);
const label patchI = bm.whichPatch(faceI);
label patchI = bm.whichPatch(faceI);
if (patchI != -1 && bm[patchI].coupled()) if (patchI != -1 && bm[patchI].coupled())
{ {
label bFaceI = faceI-mesh.nInternalFaces(); const label bFaceI = faceI-mesh.nInternalFaces();
// Check face in zone on both sides // Check face in zone on both sides
if (myZoneFace[bFaceI] != neiZoneFace[bFaceI]) if (myZoneFace[bFaceI] != neiZoneFace[bFaceI])

View File

@ -154,7 +154,7 @@ public:
faceZone faceZone
( (
const word& name, const word& name,
const labelList& addr, const unallocLabelList& addr,
const boolList& fm, const boolList& fm,
const label index, const label index,
const faceZoneMesh& zm const faceZoneMesh& zm
@ -184,7 +184,7 @@ public:
faceZone faceZone
( (
const faceZone&, const faceZone&,
const labelList& addr, const unallocLabelList& addr,
const boolList& fm, const boolList& fm,
const label index, const label index,
const faceZoneMesh& const faceZoneMesh&
@ -214,7 +214,7 @@ public:
// and zone mesh // and zone mesh
virtual autoPtr<faceZone> clone virtual autoPtr<faceZone> clone
( (
const labelList& addr, const unallocLabelList& addr,
const boolList& fm, const boolList& fm,
const label index, const label index,
const faceZoneMesh& zm const faceZoneMesh& zm
@ -279,7 +279,7 @@ public:
virtual void clearAddressing(); virtual void clearAddressing();
//- Reset addressing and flip map (clearing demand-driven data) //- Reset addressing and flip map (clearing demand-driven data)
virtual void resetAddressing(const labelList&, const boolList&); virtual void resetAddressing(const unallocLabelList&, const boolList&);
//- Check zone definition. Return true if in error. //- Check zone definition. Return true if in error.
virtual bool checkDefinition(const bool report = false) const; virtual bool checkDefinition(const bool report = false) const;

View File

@ -47,7 +47,7 @@ const char* const Foam::pointZone::labelsName = "pointLabels";
Foam::pointZone::pointZone Foam::pointZone::pointZone
( (
const word& name, const word& name,
const labelList& addr, const unallocLabelList& addr,
const label index, const label index,
const pointZoneMesh& zm const pointZoneMesh& zm
) )
@ -86,7 +86,7 @@ Foam::pointZone::pointZone
Foam::pointZone::pointZone Foam::pointZone::pointZone
( (
const pointZone& pz, const pointZone& pz,
const labelList& addr, const unallocLabelList& addr,
const label index, const label index,
const pointZoneMesh& zm const pointZoneMesh& zm
) )
@ -198,7 +198,14 @@ void Foam::pointZone::operator=(const pointZone& zn)
} }
void Foam::pointZone::operator=(const labelList& addr) void Foam::pointZone::operator=(const unallocLabelList& addr)
{
clearAddressing();
labelList::operator=(addr);
}
void Foam::pointZone::operator=(const Xfer<labelList>& addr)
{ {
clearAddressing(); clearAddressing();
labelList::operator=(addr); labelList::operator=(addr);

View File

@ -112,7 +112,7 @@ public:
pointZone pointZone
( (
const word& name, const word& name,
const labelList& addr, const unallocLabelList& addr,
const label index, const label index,
const pointZoneMesh& const pointZoneMesh&
); );
@ -140,7 +140,7 @@ public:
pointZone pointZone
( (
const pointZone&, const pointZone&,
const labelList& addr, const unallocLabelList& addr,
const label index, const label index,
const pointZoneMesh& const pointZoneMesh&
); );
@ -170,7 +170,7 @@ public:
( (
const pointZoneMesh& zm, const pointZoneMesh& zm,
const label index, const label index,
const labelList& addr const unallocLabelList& addr
) const ) const
{ {
return autoPtr<pointZone> return autoPtr<pointZone>
@ -222,11 +222,14 @@ public:
// Member Operators // Member Operators
//- Assign to zone clearing demand-driven data //- Assign to zone, clearing demand-driven data
void operator=(const pointZone&); void operator=(const pointZone&);
//- Assign addressing clearing demand-driven data //- Assign addressing, clearing demand-driven data
void operator=(const labelList&); void operator=(const unallocLabelList&);
//- Assign addressing, clearing demand-driven data
void operator=(const Xfer<labelList>&);
// I-O // I-O

View File

@ -85,7 +85,7 @@ void Foam::zone::calcLookupMap() const
Foam::zone::zone Foam::zone::zone
( (
const word& name, const word& name,
const labelList& addr, const unallocLabelList& addr,
const label index const label index
) )
: :
@ -128,7 +128,7 @@ Foam::zone::zone
Foam::zone::zone Foam::zone::zone
( (
const zone& z, const zone& z,
const labelList& addr, const unallocLabelList& addr,
const label index const label index
) )
: :

View File

@ -101,7 +101,7 @@ public:
zone zone
( (
const word& name, const word& name,
const labelList& addr, const unallocLabelList& addr,
const label index const label index
); );
@ -127,7 +127,7 @@ public:
zone zone
( (
const zone&, const zone&,
const labelList& addr, const unallocLabelList& addr,
const label index const label index
); );

View File

@ -37,6 +37,7 @@ const char* Foam::Switch::names[Foam::Switch::INVALID+1] =
"off", "on", "off", "on",
"no", "yes", "no", "yes",
"n", "y", "n", "y",
"f", "t",
"none", "true", // is there a reasonable counterpart to "none"? "none", "true", // is there a reasonable counterpart to "none"?
"invalid" "invalid"
}; };
@ -54,18 +55,39 @@ Foam::Switch::switchType Foam::Switch::asEnum
{ {
if (str == names[sw]) if (str == names[sw])
{ {
// convert n/y to no/yes - perhaps should deprecate y/n // handle aliases
if (sw == Switch::NO_1 || sw == Switch::NONE) switch (sw)
{ {
return Switch::NO; case Switch::NO_1:
} case Switch::NONE:
else if (sw == Switch::YES_1) {
{ return Switch::NO;
return Switch::YES; break;
} }
else
{ case Switch::YES_1:
return switchType(sw); {
return Switch::YES;
break;
}
case Switch::FALSE_1:
{
return Switch::FALSE;
break;
}
case Switch::TRUE_1:
{
return Switch::TRUE;
break;
}
default:
{
return switchType(sw);
break;
}
} }
} }
} }

View File

@ -26,7 +26,7 @@ Class
Description Description
A simple wrapper around bool so that it can be read as a word: A simple wrapper around bool so that it can be read as a word:
true/false, on/off, yes/no or y/n or none. true/false, on/off, yes/no, y/n, t/f, or none.
SourceFiles SourceFiles
Switch.C Switch.C
@ -78,6 +78,8 @@ public:
#undef YES #undef YES
#undef NO_1 #undef NO_1
#undef YES_1 #undef YES_1
#undef FALSE_1
#undef TRUE_1
#undef NONE #undef NONE
#undef PLACEHOLDER #undef PLACEHOLDER
#undef INVALID #undef INVALID
@ -86,11 +88,12 @@ public:
// These also correspond to the entries in names. // These also correspond to the entries in names.
enum switchType enum switchType
{ {
FALSE = 0, TRUE = 1, FALSE = 0, TRUE = 1,
OFF = 2, ON = 3, OFF = 2, ON = 3,
NO = 4, YES = 5, NO = 4, YES = 5,
NO_1 = 6, YES_1 = 7, NO_1 = 6, YES_1 = 7,
NONE = 8, PLACEHOLDER = 9, FALSE_1 = 8, TRUE_1 = 9,
NONE = 10, PLACEHOLDER = 11,
INVALID INVALID
}; };

View File

@ -93,6 +93,8 @@ public:
static const char* const typeName; static const char* const typeName;
static int debug; static int debug;
//- An empty fileName
static const fileName null; static const fileName null;

View File

@ -22,24 +22,54 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description Description
Istream constructor and IOstream operators for word. Istream constructor and IOstream operators for keyType.
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "keyType.H" #include "keyType.H"
#include "regExp.H"
#include "IOstreams.H" #include "IOstreams.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::keyType Foam::keyType::null;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::keyType::keyType(Istream& is) Foam::keyType::keyType(Istream& is)
: :
word() word(),
isPattern_(false)
{ {
is >> *this; is >> *this;
} }
Foam::Istream& Foam::operator>>(Istream& is, keyType& w) // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::keyType::match
(
const std::string& str,
bool literalMatch
) const
{
if (literalMatch || !isPattern_)
{
// check as string
return (str == *this);
}
else
{
// check as regex
return regExp(*this).match(str);
}
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Istream& Foam::operator>>(Istream& is, keyType& kw)
{ {
token t(is); token t(is);
@ -51,15 +81,16 @@ Foam::Istream& Foam::operator>>(Istream& is, keyType& w)
if (t.isWord()) if (t.isWord())
{ {
w = t.wordToken(); kw = t.wordToken();
} }
else if (t.isString()) else if (t.isString())
{ {
// Assign from string. Sets regular expression. // Assign from string. Set as regular expression.
w = t.stringToken(); kw = t.stringToken();
kw.isPattern_ = true;
// flag empty strings as an error // flag empty strings as an error
if (w.empty()) if (kw.empty())
{ {
is.setBad(); is.setBad();
FatalIOErrorIn("operator>>(Istream&, keyType&)", is) FatalIOErrorIn("operator>>(Istream&, keyType&)", is)
@ -86,9 +117,9 @@ Foam::Istream& Foam::operator>>(Istream& is, keyType& w)
} }
Foam::Ostream& Foam::operator<<(Ostream& os, const keyType& w) Foam::Ostream& Foam::operator<<(Ostream& os, const keyType& kw)
{ {
os.write(w); os.write(kw);
os.check("Ostream& operator<<(Ostream&, const keyType&)"); os.check("Ostream& operator<<(Ostream&, const keyType&)");
return os; return os;
} }

View File

@ -32,7 +32,6 @@ Description
SourceFiles SourceFiles
keyType.C keyType.C
keyTypeIO.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -52,14 +51,14 @@ class Ostream;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class keyType Declaration Class keyType Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class keyType class keyType
: :
public word public word
{ {
// Private member data // Private data
//- Is the keyType a pattern (regular expression) //- Is the keyType a pattern (regular expression)
bool isPattern_; bool isPattern_;
@ -71,6 +70,11 @@ class keyType
public: public:
// Static data members
//- An empty keyType
static const keyType null;
// Constructors // Constructors
@ -80,19 +84,21 @@ public:
//- Construct as copy //- Construct as copy
inline keyType(const keyType&); inline keyType(const keyType&);
//- Construct as copy of word //- Construct as copy of word. Not treated as a regular expression
inline keyType(const word&); inline keyType(const word&);
//- Construct as copy of string. Expect it to be regular expression. //- Construct as copy of string. Treat as regular expression.
inline keyType(const string&); inline keyType(const string&);
//- Construct as copy of character array //- Construct as copy of character array.
// Not treated as a regular expression
inline keyType(const char*); inline keyType(const char*);
//- Construct as copy of std::string //- Construct as copy of std::string with specified treatment
inline keyType(const std::string&, const bool isPattern); inline keyType(const std::string&, const bool isPattern);
//- Construct from Istream //- Construct from Istream
// Treat as regular expression if surrounded by quotation marks.
keyType(Istream&); keyType(Istream&);
@ -101,15 +107,24 @@ public:
//- Should be treated as a match rather than a literal string //- Should be treated as a match rather than a literal string
inline bool isPattern() const; inline bool isPattern() const;
//- Smart match as regular expression or as a string
// Optionally force a literal match only
bool match(const std::string&, bool literalMatch=false) const;
// Member operators // Member operators
// Assignment // Assignment
//- Assignment operator
inline const keyType& operator=(const keyType&); inline const keyType& operator=(const keyType&);
//- Assign as word, not as non regular expression
inline const keyType& operator=(const word&); inline const keyType& operator=(const word&);
//- Assign from regular expression. //- Assign as regular expression
inline const keyType& operator=(const string&); inline const keyType& operator=(const string&);
//- Assign as word, not as non regular expression
inline const keyType& operator=(const char*); inline const keyType& operator=(const char*);

View File

@ -23,10 +23,6 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline Foam::keyType::keyType() inline Foam::keyType::keyType()
@ -50,7 +46,6 @@ inline Foam::keyType::keyType(const word& s)
{} {}
// Construct as copy of string. Expect it to be regular expression
inline Foam::keyType::keyType(const string& s) inline Foam::keyType::keyType(const string& s)
: :
word(s, false), word(s, false),
@ -58,7 +53,6 @@ inline Foam::keyType::keyType(const string& s)
{} {}
// Construct as copy of character array
inline Foam::keyType::keyType(const char* s) inline Foam::keyType::keyType(const char* s)
: :
word(s, false), word(s, false),
@ -66,7 +60,6 @@ inline Foam::keyType::keyType(const char* s)
{} {}
//- Construct as copy of std::string
inline Foam::keyType::keyType inline Foam::keyType::keyType
( (
const std::string& s, const std::string& s,

View File

@ -82,6 +82,8 @@ public:
static const char* const typeName; static const char* const typeName;
static int debug; static int debug;
//- An empty string
static const string null; static const string null;
@ -143,6 +145,9 @@ public:
template<class String> template<class String>
static inline string quotemeta(const string&, const char quote='\\'); static inline string quotemeta(const string&, const char quote='\\');
//- True when strings match literally
inline bool match(const std::string&) const;
//- Avoid masking the normal std::string replace //- Avoid masking the normal std::string replace
using std::string::replace; using std::string::replace;

View File

@ -176,6 +176,12 @@ inline String Foam::string::validate(const string& str)
return ss; return ss;
} }
inline bool Foam::string::match(const std::string& str) const
{
// check as string
return (str == *this);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //

View File

@ -73,6 +73,8 @@ public:
static const char* const typeName; static const char* const typeName;
static int debug; static int debug;
//- An empty word
static const word null; static const word null;

View File

@ -27,7 +27,12 @@ License
#include "IOstreams.H" #include "IOstreams.H"
#include "InfoProxy.H" #include "InfoProxy.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::wordRe Foam::wordRe::null;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::wordRe::wordRe(Istream& is) Foam::wordRe::wordRe(Istream& is)
: :
@ -38,6 +43,8 @@ Foam::wordRe::wordRe(Istream& is)
} }
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Istream& Foam::operator>>(Istream& is, wordRe& w) Foam::Istream& Foam::operator>>(Istream& is, wordRe& w)
{ {
token t(is); token t(is);

View File

@ -44,7 +44,6 @@ Note
SourceFiles SourceFiles
wordRe.C wordRe.C
wordReIO.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -84,6 +83,12 @@ class wordRe
public: public:
// Static data members
//- An empty wordRe
static const wordRe null;
// Public data types // Public data types
//- Enumeration with compile options //- Enumeration with compile options
@ -168,7 +173,7 @@ public:
//- Searching //- Searching
//- Smart match as regular expression or as a string //- Smart match as regular expression or as a string
// Optionally specify a literal match only // Optionally force a literal match only
inline bool match(const std::string&, bool literalMatch=false) const; inline bool match(const std::string&, bool literalMatch=false) const;
//- Miscellaneous //- Miscellaneous

View File

@ -143,7 +143,7 @@ void Foam::PorousZones<ZoneType>::addResistance
) const ) const
{ {
// addResistance for each zone, delaying the correction of the // addResistance for each zone, delaying the correction of the
// precessor BCs of AU // processor BCs of AU
forAll(*this, i) forAll(*this, i)
{ {
this->operator[](i).addResistance(UEqn, AU, false); this->operator[](i).addResistance(UEqn, AU, false);

View File

@ -27,7 +27,6 @@ License
#include "fvMesh.H" #include "fvMesh.H"
#include "fvMatrices.H" #include "fvMatrices.H"
#include "geometricOneField.H" #include "geometricOneField.H"
#include "stringListOps.H"
// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //

View File

@ -66,7 +66,7 @@ void Foam::porousZone::addPowerLawResistance
forAll(cells, i) forAll(cells, i)
{ {
Udiag[cells[i]] += Udiag[cells[i]] +=
V[cells[i]]*rho[cells[i]]*C0*pow(magSqr(U[cells[i]]), C1m1b2); V[cells[i]]*rho[cells[i]]*C0*pow(magSqr(U[cells[i]]), C1m1b2);
} }
} }
} }

View File

@ -164,8 +164,8 @@ private:
// Construction // Construction
//- Split list of indices into 8 bins according to where they are in //- Split list of indices into 8 bins
// relation to mid. // according to where they are in relation to mid.
void divide void divide
( (
const labelList& indices, const labelList& indices,
@ -173,8 +173,8 @@ private:
labelListList& result labelListList& result
) const; ) const;
//- Subdivide the contents node at position contentI. Appends to //- Subdivide the contents node at position contentI.
// contents. // Appends to contents.
node divide node divide
( (
const treeBoundBox& bb, const treeBoundBox& bb,

View File

@ -64,19 +64,7 @@ Foam::treeBoundBox Foam::treeDataCell::calcCellBb(const label cellI) const
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // void Foam::treeDataCell::update()
// Construct from components
Foam::treeDataCell::treeDataCell
(
const bool cacheBb,
const primitiveMesh& mesh,
const labelList& cellLabels
)
:
mesh_(mesh),
cellLabels_(cellLabels),
cacheBb_(cacheBb)
{ {
if (cacheBb_) if (cacheBb_)
{ {
@ -90,6 +78,38 @@ Foam::treeDataCell::treeDataCell
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::treeDataCell::treeDataCell
(
const bool cacheBb,
const primitiveMesh& mesh,
const unallocLabelList& cellLabels
)
:
mesh_(mesh),
cellLabels_(cellLabels),
cacheBb_(cacheBb)
{
update();
}
Foam::treeDataCell::treeDataCell
(
const bool cacheBb,
const primitiveMesh& mesh,
const Xfer<labelList>& cellLabels
)
:
mesh_(mesh),
cellLabels_(cellLabels),
cacheBb_(cacheBb)
{
update();
}
Foam::treeDataCell::treeDataCell Foam::treeDataCell::treeDataCell
( (
const bool cacheBb, const bool cacheBb,
@ -100,15 +120,7 @@ Foam::treeDataCell::treeDataCell
cellLabels_(identity(mesh_.nCells())), cellLabels_(identity(mesh_.nCells())),
cacheBb_(cacheBb) cacheBb_(cacheBb)
{ {
if (cacheBb_) update();
{
bbs_.setSize(cellLabels_.size());
forAll(cellLabels_, i)
{
bbs_[i] = calcCellBb(cellLabels_[i]);
}
}
} }
@ -159,7 +171,7 @@ bool Foam::treeDataCell::contains
// nearestPoint. // nearestPoint.
void Foam::treeDataCell::findNearest void Foam::treeDataCell::findNearest
( (
const labelList& indices, const unallocLabelList& indices,
const point& sample, const point& sample,
scalar& nearestDistSqr, scalar& nearestDistSqr,

View File

@ -48,7 +48,7 @@ class primitiveMesh;
template<class Type> class indexedOctree; template<class Type> class indexedOctree;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class treeDataCell Declaration Class treeDataCell Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class treeDataCell class treeDataCell
@ -72,6 +72,9 @@ class treeDataCell
//- Calculate cell bounding box //- Calculate cell bounding box
treeBoundBox calcCellBb(const label cellI) const; treeBoundBox calcCellBb(const label cellI) const;
//- Initialise all member data
void update();
public: public:
// Declare name of the class and its debug switch // Declare name of the class and its debug switch
@ -85,7 +88,15 @@ public:
( (
const bool cacheBb, const bool cacheBb,
const primitiveMesh&, const primitiveMesh&,
const labelList& const unallocLabelList&
);
//- Construct from mesh and subset of cells, transferring contents
treeDataCell
(
const bool cacheBb,
const primitiveMesh&,
const Xfer<labelList>&
); );
//- Construct from mesh. Uses all cells in mesh. //- Construct from mesh. Uses all cells in mesh.
@ -96,18 +107,18 @@ public:
// Access // Access
const labelList& cellLabels() const inline const labelList& cellLabels() const
{ {
return cellLabels_; return cellLabels_;
} }
const primitiveMesh& mesh() const inline const primitiveMesh& mesh() const
{ {
return mesh_; return mesh_;
} }
label size() const inline label size() const
{ {
return cellLabels_.size(); return cellLabels_.size();
} }
@ -153,7 +164,7 @@ public:
// Returns actual point and distance (squared) // Returns actual point and distance (squared)
void findNearest void findNearest
( (
const labelList& indices, const unallocLabelList& indices,
const point& sample, const point& sample,
scalar& nearestDistSqr, scalar& nearestDistSqr,
@ -165,7 +176,7 @@ public:
// Returns point and distance (squared) // Returns point and distance (squared)
void findNearest void findNearest
( (
const labelList& indices, const unallocLabelList& indices,
const linePointRef& ln, const linePointRef& ln,
treeBoundBox& tightest, treeBoundBox& tightest,
@ -177,7 +188,7 @@ public:
notImplemented notImplemented
( (
"treeDataCell::findNearest" "treeDataCell::findNearest"
"(const labelList&, const linePointRef&, ..)" "(const unallocLabelList&, const linePointRef&, ..)"
); );
} }

View File

@ -43,21 +43,7 @@ Foam::treeBoundBox Foam::treeDataEdge::calcBb(const label edgeI) const
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // void Foam::treeDataEdge::update()
// Construct from components
Foam::treeDataEdge::treeDataEdge
(
const bool cacheBb,
const edgeList& edges,
const pointField& points,
const labelList& edgeLabels
)
:
edges_(edges),
points_(points),
edgeLabels_(edgeLabels),
cacheBb_(cacheBb)
{ {
if (cacheBb_) if (cacheBb_)
{ {
@ -71,6 +57,42 @@ Foam::treeDataEdge::treeDataEdge
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::treeDataEdge::treeDataEdge
(
const bool cacheBb,
const edgeList& edges,
const pointField& points,
const unallocLabelList& edgeLabels
)
:
edges_(edges),
points_(points),
edgeLabels_(edgeLabels),
cacheBb_(cacheBb)
{
update();
}
Foam::treeDataEdge::treeDataEdge
(
const bool cacheBb,
const edgeList& edges,
const pointField& points,
const Xfer<labelList>& edgeLabels
)
:
edges_(edges),
points_(points),
edgeLabels_(edgeLabels),
cacheBb_(cacheBb)
{
update();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::pointField Foam::treeDataEdge::points() const Foam::pointField Foam::treeDataEdge::points() const
@ -121,7 +143,7 @@ bool Foam::treeDataEdge::overlaps
// nearestPoint. // nearestPoint.
void Foam::treeDataEdge::findNearest void Foam::treeDataEdge::findNearest
( (
const labelList& indices, const unallocLabelList& indices,
const point& sample, const point& sample,
scalar& nearestDistSqr, scalar& nearestDistSqr,
@ -131,7 +153,7 @@ void Foam::treeDataEdge::findNearest
{ {
forAll(indices, i) forAll(indices, i)
{ {
label index = indices[i]; const label index = indices[i];
const edge& e = edges_[edgeLabels_[index]]; const edge& e = edges_[edgeLabels_[index]];
@ -153,7 +175,7 @@ void Foam::treeDataEdge::findNearest
// Returns point and distance (squared) // Returns point and distance (squared)
void Foam::treeDataEdge::findNearest void Foam::treeDataEdge::findNearest
( (
const labelList& indices, const unallocLabelList& indices,
const linePointRef& ln, const linePointRef& ln,
treeBoundBox& tightest, treeBoundBox& tightest,
@ -167,7 +189,7 @@ void Foam::treeDataEdge::findNearest
forAll(indices, i) forAll(indices, i)
{ {
label index = indices[i]; const label index = indices[i];
const edge& e = edges_[edgeLabels_[index]]; const edge& e = edges_[edgeLabels_[index]];

View File

@ -81,6 +81,9 @@ class treeDataEdge
//- Calculate edge bounding box //- Calculate edge bounding box
treeBoundBox calcBb(const label edgeI) const; treeBoundBox calcBb(const label edgeI) const;
//- Initialise all member data
void update();
public: public:
// Declare name of the class and its debug switch // Declare name of the class and its debug switch
@ -95,7 +98,17 @@ public:
const bool cacheBb, const bool cacheBb,
const edgeList& edges, const edgeList& edges,
const pointField& points, const pointField& points,
const labelList& edgeLabels const unallocLabelList& edgeLabels
);
//- Construct from selected edges, transferring contents.
// !Holds references to edges and points
treeDataEdge
(
const bool cacheBb,
const edgeList& edges,
const pointField& points,
const Xfer<labelList>& edgeLabels
); );
@ -139,7 +152,7 @@ public:
// Returns actual point and distance (squared) // Returns actual point and distance (squared)
void findNearest void findNearest
( (
const labelList& indices, const unallocLabelList& indices,
const point& sample, const point& sample,
scalar& nearestDistSqr, scalar& nearestDistSqr,
@ -151,7 +164,7 @@ public:
// Returns point and distance (squared) // Returns point and distance (squared)
void findNearest void findNearest
( (
const labelList& indices, const unallocLabelList& indices,
const linePointRef& ln, const linePointRef& ln,
treeBoundBox& tightest, treeBoundBox& tightest,

View File

@ -76,12 +76,27 @@ void Foam::treeDataFace::update()
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from components
Foam::treeDataFace::treeDataFace Foam::treeDataFace::treeDataFace
( (
const bool cacheBb, const bool cacheBb,
const primitiveMesh& mesh, const primitiveMesh& mesh,
const labelList& faceLabels const unallocLabelList& faceLabels
)
:
mesh_(mesh),
faceLabels_(faceLabels),
isTreeFace_(mesh.nFaces(), 0),
cacheBb_(cacheBb)
{
update();
}
Foam::treeDataFace::treeDataFace
(
const bool cacheBb,
const primitiveMesh& mesh,
const Xfer<labelList>& faceLabels
) )
: :
mesh_(mesh), mesh_(mesh),
@ -467,7 +482,7 @@ bool Foam::treeDataFace::overlaps
// nearestPoint. // nearestPoint.
void Foam::treeDataFace::findNearest void Foam::treeDataFace::findNearest
( (
const labelList& indices, const unallocLabelList& indices,
const point& sample, const point& sample,
scalar& nearestDistSqr, scalar& nearestDistSqr,
@ -477,7 +492,7 @@ void Foam::treeDataFace::findNearest
{ {
forAll(indices, i) forAll(indices, i)
{ {
label index = indices[i]; const label index = indices[i];
const face& f = mesh_.faces()[faceLabels_[index]]; const face& f = mesh_.faces()[faceLabels_[index]];
@ -514,7 +529,7 @@ bool Foam::treeDataFace::intersects
} }
} }
label faceI = faceLabels_[index]; const label faceI = faceLabels_[index];
const vector dir(end - start); const vector dir(end - start);

View File

@ -51,7 +51,7 @@ class primitiveMesh;
class polyPatch; class polyPatch;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class treeDataFace Declaration Class treeDataFace Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class treeDataFace class treeDataFace
@ -101,7 +101,15 @@ public:
( (
const bool cacheBb, const bool cacheBb,
const primitiveMesh&, const primitiveMesh&,
const labelList& const unallocLabelList&
);
//- Construct from mesh and subset of faces, transferring contents
treeDataFace
(
const bool cacheBb,
const primitiveMesh&,
const Xfer<labelList>&
); );
//- Construct from mesh. Uses all faces in mesh. //- Construct from mesh. Uses all faces in mesh.
@ -115,17 +123,17 @@ public:
// Access // Access
const labelList& faceLabels() const inline const labelList& faceLabels() const
{ {
return faceLabels_; return faceLabels_;
} }
const primitiveMesh& mesh() const inline const primitiveMesh& mesh() const
{ {
return mesh_; return mesh_;
} }
label size() const inline label size() const
{ {
return faceLabels_.size(); return faceLabels_.size();
} }
@ -156,7 +164,7 @@ public:
// Returns actual point and distance (squared) // Returns actual point and distance (squared)
void findNearest void findNearest
( (
const labelList& indices, const unallocLabelList& indices,
const point& sample, const point& sample,
scalar& nearestDistSqr, scalar& nearestDistSqr,
@ -168,7 +176,7 @@ public:
// Returns point and distance (squared) // Returns point and distance (squared)
void findNearest void findNearest
( (
const labelList& indices, const unallocLabelList& indices,
const linePointRef& ln, const linePointRef& ln,
treeBoundBox& tightest, treeBoundBox& tightest,
@ -180,7 +188,7 @@ public:
notImplemented notImplemented
( (
"treeDataFace::findNearest" "treeDataFace::findNearest"
"(const labelList&, const linePointRef&, ..)" "(const unallocLabelList&, const linePointRef&, ..)"
); );
} }

View File

@ -36,7 +36,6 @@ defineTypeNameAndDebug(Foam::treeDataPoint, 0);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from components
Foam::treeDataPoint::treeDataPoint(const pointField& points) Foam::treeDataPoint::treeDataPoint(const pointField& points)
: :
points_(points) points_(points)
@ -78,7 +77,7 @@ bool Foam::treeDataPoint::overlaps
// nearestPoint. // nearestPoint.
void Foam::treeDataPoint::findNearest void Foam::treeDataPoint::findNearest
( (
const labelList& indices, const unallocLabelList& indices,
const point& sample, const point& sample,
scalar& nearestDistSqr, scalar& nearestDistSqr,
@ -88,7 +87,7 @@ void Foam::treeDataPoint::findNearest
{ {
forAll(indices, i) forAll(indices, i)
{ {
label index = indices[i]; const label index = indices[i];
const point& pt = points_[index]; const point& pt = points_[index];
@ -108,7 +107,7 @@ void Foam::treeDataPoint::findNearest
// Returns point and distance (squared) // Returns point and distance (squared)
void Foam::treeDataPoint::findNearest void Foam::treeDataPoint::findNearest
( (
const labelList& indices, const unallocLabelList& indices,
const linePointRef& ln, const linePointRef& ln,
treeBoundBox& tightest, treeBoundBox& tightest,
@ -122,7 +121,7 @@ void Foam::treeDataPoint::findNearest
forAll(indices, i) forAll(indices, i)
{ {
label index = indices[i]; const label index = indices[i];
const point& shapePt = points_[index]; const point& shapePt = points_[index];

View File

@ -69,14 +69,14 @@ public:
// Constructors // Constructors
//- Construct from components. Holds reference to points! //- Construct from components. Holds reference to points!
treeDataPoint(const pointField& points); treeDataPoint(const pointField&);
// Member Functions // Member Functions
// Access // Access
label size() const inline label size() const
{ {
return points_.size(); return points_.size();
} }
@ -107,7 +107,7 @@ public:
// Returns actual point and distance (squared) // Returns actual point and distance (squared)
void findNearest void findNearest
( (
const labelList& indices, const unallocLabelList& indices,
const point& sample, const point& sample,
scalar& nearestDistSqr, scalar& nearestDistSqr,
@ -119,7 +119,7 @@ public:
// Returns point and distance (squared) // Returns point and distance (squared)
void findNearest void findNearest
( (
const labelList& indices, const unallocLabelList& indices,
const linePointRef& ln, const linePointRef& ln,
treeBoundBox& tightest, treeBoundBox& tightest,

View File

@ -477,7 +477,7 @@ void
Foam::treeDataPrimitivePatch<Face, FaceList, PointField, PointType>:: Foam::treeDataPrimitivePatch<Face, FaceList, PointField, PointType>::
findNearest findNearest
( (
const labelList& indices, const unallocLabelList& indices,
const point& sample, const point& sample,
scalar& nearestDistSqr, scalar& nearestDistSqr,
@ -489,7 +489,7 @@ findNearest
forAll(indices, i) forAll(indices, i)
{ {
label index = indices[i]; const label index = indices[i];
const face& f = patch_[index]; const face& f = patch_[index];

View File

@ -56,7 +56,7 @@ TemplateName(treeDataPrimitivePatch);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class treeDataPrimitivePatch Declaration Class treeDataPrimitivePatch Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template template
@ -151,7 +151,7 @@ public:
// Returns actual point and distance (squared) // Returns actual point and distance (squared)
void findNearest void findNearest
( (
const labelList& indices, const unallocLabelList& indices,
const point& sample, const point& sample,
scalar& nearestDistSqr, scalar& nearestDistSqr,
@ -163,7 +163,7 @@ public:
// Returns point and distance (squared) // Returns point and distance (squared)
void findNearest void findNearest
( (
const labelList& indices, const unallocLabelList& indices,
const linePointRef& ln, const linePointRef& ln,
treeBoundBox& tightest, treeBoundBox& tightest,
@ -175,7 +175,7 @@ public:
notImplemented notImplemented
( (
"treeDataPrimitivePatch::findNearest" "treeDataPrimitivePatch::findNearest"
"(const labelList&, const linePointRef&, ..)" "(const unallocLabelList&, const linePointRef&, ..)"
); );
} }

View File

@ -313,7 +313,7 @@ bool Foam::treeDataTriSurface::overlaps
// nearestPoint. // nearestPoint.
void Foam::treeDataTriSurface::findNearest void Foam::treeDataTriSurface::findNearest
( (
const labelList& indices, const unallocLabelList& indices,
const point& sample, const point& sample,
scalar& nearestDistSqr, scalar& nearestDistSqr,
@ -396,7 +396,7 @@ void Foam::treeDataTriSurface::findNearest
// nearestPoint. // nearestPoint.
void Foam::treeDataTriSurface::findNearest void Foam::treeDataTriSurface::findNearest
( (
const labelList& indices, const unallocLabelList& indices,
const linePointRef& ln, const linePointRef& ln,
treeBoundBox& tightest, treeBoundBox& tightest,
@ -407,7 +407,7 @@ void Foam::treeDataTriSurface::findNearest
{ {
notImplemented notImplemented
( (
"treeDataTriSurface::findNearest(const labelList&" "treeDataTriSurface::findNearest(const unallocLabelList&"
", const linePointRef&, treeBoundBox&, label&, point&, point&) const" ", const linePointRef&, treeBoundBox&, label&, point&, point&) const"
); );
} }

View File

@ -91,12 +91,12 @@ public:
// Access // Access
const triSurface& surface() const inline const triSurface& surface() const
{ {
return surface_; return surface_;
} }
label size() const inline label size() const
{ {
return surface_.size(); return surface_.size();
} }
@ -127,7 +127,7 @@ public:
// Returns actual point and distance (squared) // Returns actual point and distance (squared)
void findNearest void findNearest
( (
const labelList& indices, const unallocLabelList& indices,
const point& sample, const point& sample,
scalar& nearestDistSqr, scalar& nearestDistSqr,
@ -139,7 +139,7 @@ public:
// Returns point and distance (squared) // Returns point and distance (squared)
void findNearest void findNearest
( (
const labelList& indices, const unallocLabelList& indices,
const linePointRef& ln, const linePointRef& ln,
treeBoundBox& tightest, treeBoundBox& tightest,

View File

@ -290,20 +290,17 @@ Foam::distanceSurface::distanceSurface
signed_(readBool(dict.lookup("signed"))), signed_(readBool(dict.lookup("signed"))),
regularise_(dict.lookupOrDefault("regularise", true)), regularise_(dict.lookupOrDefault("regularise", true)),
average_(dict.lookupOrDefault("average", false)), average_(dict.lookupOrDefault("average", false)),
zoneName_(word::null), zoneKey_(keyType::null),
needsUpdate_(true), needsUpdate_(true),
isoSurfPtr_(NULL), isoSurfPtr_(NULL),
facesPtr_(NULL) facesPtr_(NULL)
{ {
// dict.readIfPresent("zone", zoneName_); // dict.readIfPresent("zone", zoneKey_);
// //
// if (debug && zoneName_.size()) // if (debug && zoneKey_.size() && mesh.cellZones().findZoneID(zoneKey_) < 0)
// { // {
// if (mesh.cellZones().findZoneID(zoneName_) < 0) // Info<< "cellZone " << zoneKey_
// { // << " not found - using entire mesh" << endl;
// Info<< "cellZone \"" << zoneName_
// << "\" not found - using entire mesh" << endl;
// }
// } // }
} }

View File

@ -70,8 +70,8 @@ class distanceSurface
//- Whether to recalculate cell values as average of point values //- Whether to recalculate cell values as average of point values
const Switch average_; const Switch average_;
//- zone name (if restricted to zones) //- If restricted to zones, name of this zone or a regular expression
word zoneName_; keyType zoneKey_;
//- Track if the surface needs an update //- Track if the surface needs an update
mutable bool needsUpdate_; mutable bool needsUpdate_;

View File

@ -205,20 +205,17 @@ Foam::sampledIsoSurfaceCell::sampledIsoSurfaceCell
isoVal_(readScalar(dict.lookup("isoValue"))), isoVal_(readScalar(dict.lookup("isoValue"))),
regularise_(dict.lookupOrDefault("regularise", true)), regularise_(dict.lookupOrDefault("regularise", true)),
average_(dict.lookupOrDefault("average", true)), average_(dict.lookupOrDefault("average", true)),
zoneName_(word::null), zoneKey_(keyType::null),
facesPtr_(NULL), facesPtr_(NULL),
prevTimeIndex_(-1), prevTimeIndex_(-1),
meshCells_(0) meshCells_(0)
{ {
// dict.readIfPresent("zone", zoneName_); // dict.readIfPresent("zone", zoneKey_);
// //
// if (debug && zoneName_.size()) // if (debug && zoneKey_.size() && mesh.cellZones().findZoneID(zoneKey_) < 0)
// { // {
// if (mesh.cellZones().findZoneID(zoneName_) < 0) // Info<< "cellZone " << zoneKey_
// { // << " not found - using entire mesh" << endl;
// Info<< "cellZone \"" << zoneName_
// << "\" not found - using entire mesh" << endl;
// }
// } // }
} }

View File

@ -68,8 +68,8 @@ class sampledIsoSurfaceCell
//- Whether to recalculate cell values as average of point values //- Whether to recalculate cell values as average of point values
const Switch average_; const Switch average_;
//- zone name (if restricted to zones) //- If restricted to zones, name of this zone or a regular expression
word zoneName_; keyType zoneKey_;
//- triangles converted to faceList //- triangles converted to faceList
mutable autoPtr<faceList> facesPtr_; mutable autoPtr<faceList> facesPtr_;

View File

@ -45,21 +45,18 @@ Foam::sampledPlane::sampledPlane
const word& name, const word& name,
const polyMesh& mesh, const polyMesh& mesh,
const plane& planeDesc, const plane& planeDesc,
const word& zoneName const keyType& zoneKey
) )
: :
sampledSurface(name, mesh), sampledSurface(name, mesh),
cuttingPlane(planeDesc), cuttingPlane(planeDesc),
zoneName_(zoneName), zoneKey_(zoneKey),
needsUpdate_(true) needsUpdate_(true)
{ {
if (debug && zoneName_.size()) if (debug && zoneKey_.size() && mesh.cellZones().findIndex(zoneKey_) < 0)
{ {
if (mesh.cellZones().findZoneID(zoneName_) < 0) Info<< "cellZone " << zoneKey_
{ << " not found - using entire mesh" << endl;
Info<< "cellZone \"" << zoneName_
<< "\" not found - using entire mesh" << endl;
}
} }
} }
@ -73,7 +70,7 @@ Foam::sampledPlane::sampledPlane
: :
sampledSurface(name, mesh, dict), sampledSurface(name, mesh, dict),
cuttingPlane(plane(dict.lookup("basePoint"), dict.lookup("normalVector"))), cuttingPlane(plane(dict.lookup("basePoint"), dict.lookup("normalVector"))),
zoneName_(word::null), zoneKey_(keyType::null),
needsUpdate_(true) needsUpdate_(true)
{ {
// make plane relative to the coordinateSystem (Cartesian) // make plane relative to the coordinateSystem (Cartesian)
@ -89,17 +86,13 @@ Foam::sampledPlane::sampledPlane
static_cast<plane&>(*this) = plane(base, norm); static_cast<plane&>(*this) = plane(base, norm);
} }
dict.readIfPresent("zone", zoneName_); dict.readIfPresent("zone", zoneKey_);
if (debug && zoneName_.size()) if (debug && zoneKey_.size() && mesh.cellZones().findIndex(zoneKey_) < 0)
{ {
if (mesh.cellZones().findZoneID(zoneName_) < 0) Info<< "cellZone " << zoneKey_
{ << " not found - using entire mesh" << endl;
Info<< "cellZone \"" << zoneName_
<< "\" not found - using entire mesh" << endl;
}
} }
} }
@ -141,19 +134,15 @@ bool Foam::sampledPlane::update()
sampledSurface::clearGeom(); sampledSurface::clearGeom();
label zoneId = -1; labelList selectedCells = mesh().cellZones().findMatching(zoneKey_).used();
if (zoneName_.size())
{
zoneId = mesh().cellZones().findZoneID(zoneName_);
}
if (zoneId < 0) if (selectedCells.empty())
{ {
reCut(mesh(), true); // always triangulate. Note:Make option? reCut(mesh(), true); // always triangulate. Note:Make option?
} }
else else
{ {
reCut(mesh(), true, mesh().cellZones()[zoneId]); reCut(mesh(), true, selectedCells);
} }
if (debug) if (debug)

View File

@ -47,7 +47,7 @@ namespace Foam
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class sampledPlane Declaration Class sampledPlane Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class sampledPlane class sampledPlane
@ -57,8 +57,8 @@ class sampledPlane
{ {
// Private data // Private data
//- zone name (if restricted to zones) //- If restricted to zones, name of this zone or a regular expression
word zoneName_; keyType zoneKey_;
//- Track if the surface needs an update //- Track if the surface needs an update
mutable bool needsUpdate_; mutable bool needsUpdate_;
@ -92,7 +92,7 @@ public:
const word& name, const word& name,
const polyMesh& mesh, const polyMesh& mesh,
const plane& planeDesc, const plane& planeDesc,
const word& zoneName = word::null const keyType& zoneKey = word::null
); );
//- Construct from dictionary //- Construct from dictionary

View File

@ -154,7 +154,7 @@ Foam::sampledThresholdCellFaces::sampledThresholdCellFaces
fieldName_(dict.lookup("field")), fieldName_(dict.lookup("field")),
lowerThreshold_(dict.lookupOrDefault<scalar>("lowerLimit", -VGREAT)), lowerThreshold_(dict.lookupOrDefault<scalar>("lowerLimit", -VGREAT)),
upperThreshold_(dict.lookupOrDefault<scalar>("upperLimit", VGREAT)), upperThreshold_(dict.lookupOrDefault<scalar>("upperLimit", VGREAT)),
zoneName_(word::null), zoneKey_(keyType::null),
triangulate_(dict.lookupOrDefault("triangulate", false)), triangulate_(dict.lookupOrDefault("triangulate", false)),
prevTimeIndex_(-1), prevTimeIndex_(-1),
meshCells_(0) meshCells_(0)
@ -169,16 +169,12 @@ Foam::sampledThresholdCellFaces::sampledThresholdCellFaces
<< abort(FatalError); << abort(FatalError);
} }
// dict.readIfPresent("zone", zoneKey_);
// dict.readIfPresent("zone", zoneName_);
// //
// if (debug && zoneName_.size()) // if (debug && zoneKey_.size() && mesh.cellZones().findZoneID(zoneKey_) < 0)
// { // {
// if (mesh.cellZones().findZoneID(zoneName_) < 0) // Info<< "cellZone " << zoneKey_
// { // << " not found - using entire mesh" << endl;
// Info<< "cellZone \"" << zoneName_
// << "\" not found - using entire mesh" << endl;
// }
// } // }
} }

View File

@ -67,8 +67,8 @@ class sampledThresholdCellFaces
//- Threshold value //- Threshold value
const scalar upperThreshold_; const scalar upperThreshold_;
//- zone name (if restricted to zones) //- If restricted to zones, name of this zone or a regular expression
word zoneName_; keyType zoneKey_;
//- Triangulated faces or keep faces as is //- Triangulated faces or keep faces as is
bool triangulate_; bool triangulate_;