Merge branch 'master' into cvm

This commit is contained in:
graham
2010-10-06 15:40:52 +01:00
162 changed files with 5017 additions and 20767 deletions

77
ReleaseNotes-dev Normal file
View File

@ -0,0 +1,77 @@
# -*- mode: org; -*-
#
#+TITLE: OpenFOAM release notes for version dev
#+AUTHOR: OpenCFD Ltd.
#+DATE: TBA
#+LINK: http://www.openfoam.com
#+OPTIONS: author:nil ^:{}
# Copyright (c) 2010 OpenCFD Ltd.
* Overview
OpenFOAM-dev is the latest major release of OpenFOAM including many new
developments a number of bug-fixes. This release passes our standard tests
and the tutorials have been broadly checked. Please report any bugs by
following the link: http://www.openfoam.com/bugs.
* GNU/Linux version
This release of OpenFOAM is distributed primarily in 2 ways: (1) as a Debian
pack containing binaries and source; (2) from the SourceForge source code
repository (see [[./README.org][README]]).
The Ubuntu/Debian pack is available for 32 and 64 bit versions of the 10.04
LTS operating system using the system compiler and libraries that will be
installed automatically from standard Debian packs.
To use the source version from the SourceForge repository, we provide a source
pack of third-party packages that can be compiled on the user's system. This
does not include =gcc=, since the system installed version is typically
sufficient, but includes =paraview-3.8.0=, =openmpi-1.4.1=, =scotch_5.1=,
=metis-5.0pre2=, =ParMetis-3.1= and =ParMGridGen-1.0=.
* Library developments
There have been a number of developments to the libraries to support the
extension of functionality in solver and utility applications.
*** Core library
+ Large number of code refinements and consistency improvements to support
other developments.
*** Turbulence modelling
*** Thermo-physical Models
*** DSMC
*** Dynamic Mesh
*** Numerics
* Solvers
A number of new solvers have been developed for a range of engineering
applications. There has been a set of improvements to certain classes of
solver that are introduced in this release.
*** *New* Solvers
+ ...
*** Modifications to multiphase and buoyant solvers
+ ...
*** Modifications to solvers for sensible enthalpy
+ ...
*** Modifications to steady-state compressible solvers
+ ...
*** Other modifications
+ ...
* Boundary conditions
New boundary conditions have been introduced to support new applications in
OpenFOAM.
+ ...
* Utilities
There have been some utilities added and updated in this release.
*** *New* utilities
+ ...
*** Updated utilities
+ ...
* Post-processing
+ =foamToEnsight=: new =-nodeValues= option to generate and output nodal
field data.
* New tutorials
There is a large number of new tutorials to support the new solvers in the
release.
+ ...

View File

@ -1,9 +1,8 @@
{
volScalarField kappaEff
(
"kappaEff",
turbulence->nu()/Pr + turbulence->nut()/Prt
);
kappat = turbulence->nut()/Prt;
kappat.correctBoundaryConditions();
volScalarField kappaEff("kappaEff", turbulence->nu()/Pr + kappat);
fvScalarMatrix TEqn
(

View File

@ -52,6 +52,21 @@
incompressible::RASModel::New(U, phi, laminarTransport)
);
// kinematic turbulent thermal thermal conductivity m2/s
Info<< "Reading field kappat\n" << endl;
volScalarField kappat
(
IOobject
(
"kappat",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);
label pRefCell = 0;
scalar pRefValue = 0.0;
setRefCell

View File

@ -1,9 +1,8 @@
{
volScalarField kappaEff
(
"kappaEff",
turbulence->nu()/Pr + turbulence->nut()/Prt
);
kappat = turbulence->nut()/Prt;
kappat.correctBoundaryConditions();
volScalarField kappaEff("kappaEff", turbulence->nu()/Pr + kappat);
fvScalarMatrix TEqn
(

View File

@ -64,6 +64,21 @@
1.0 - beta*(T - TRef)
);
// kinematic turbulent thermal thermal conductivity m2/s
Info<< "Reading field kappat\n" << endl;
volScalarField kappat
(
IOobject
(
"kappat",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);
Info<< "Calculating field g.h\n" << endl;
volScalarField gh("gh", g & mesh.C());
surfaceScalarField ghf("ghf", g & mesh.Cf());

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -30,6 +30,15 @@ Description
using namespace Foam;
template<class ListType>
void printInfo(const ListType& lst)
{
Info<< "addr: " << lst.addressing() << nl
<< "list: " << lst << nl
<< endl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
@ -42,8 +51,7 @@ int main(int argc, char *argv[])
completeList[i] = 0.1*i;
}
Info<< "raw : " << completeList << nl
<< endl;
Info<< "raw : " << completeList << nl << endl;
List<label> addresses(5);
@ -53,11 +61,9 @@ int main(int argc, char *argv[])
addresses[3] = 8;
addresses[4] = 5;
IndirectList<double> idl(completeList, addresses);
IndirectList<double> idl1(completeList, addresses);
Info<< "addr: " << idl.addressing() << nl
<< "list: " << idl() << nl
<< endl;
printInfo(idl1);
addresses[4] = 1;
addresses[3] = 0;
@ -65,11 +71,26 @@ int main(int argc, char *argv[])
addresses[1] = 8;
addresses[0] = 5;
idl.resetAddressing(addresses.xfer());
idl1.resetAddressing(addresses.xfer());
Info<< "addr: " << idl.addressing() << nl
<< "list: " << idl() << nl
<< endl;
printInfo(idl1);
// test copying
UIndirectList<double> uidl1(idl1);
IndirectList<double> idl2(uidl1);
IndirectList<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;

View File

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

View File

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

View File

@ -33,7 +33,6 @@ Description
#include "StaticHashTable.H"
#include "cpuTime.H"
#include <vector>
#include "PackedList.H"
#include "PackedBoolList.H"
using namespace Foam;

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

@ -57,4 +57,5 @@ EXE_LIBS = \
-lthermophysicalFunctions \
-ltopoChangerFvMesh \
-ltriSurface \
-ltwoPhaseInterfaceProperties \
-lutilityFunctionObjects

View File

@ -402,17 +402,17 @@ int main(int argc, char *argv[])
PtrList< List<SLList<indexedParticle*>*> > cellParticles(cloudDirs.size());
PtrList<PtrList<labelIOField> > lagrangianLabelFields(cloudDirs.size());
PtrList<PtrList<labelIOFieldField> > lagrangianLabelFieldFields
PtrList<PtrList<labelFieldCompactIOField> > lagrangianLabelFieldFields
(
cloudDirs.size()
);
PtrList<PtrList<scalarIOField> > lagrangianScalarFields(cloudDirs.size());
PtrList<PtrList<scalarIOFieldField> > lagrangianScalarFieldFields
PtrList<PtrList<scalarFieldCompactIOField> > lagrangianScalarFieldFields
(
cloudDirs.size()
);
PtrList<PtrList<vectorIOField> > lagrangianVectorFields(cloudDirs.size());
PtrList<PtrList<vectorIOFieldField> > lagrangianVectorFieldFields
PtrList<PtrList<vectorFieldCompactIOField> > lagrangianVectorFieldFields
(
cloudDirs.size()
);
@ -420,13 +420,14 @@ int main(int argc, char *argv[])
(
cloudDirs.size()
);
PtrList<PtrList<sphericalTensorIOFieldField> >
PtrList<PtrList<sphericalTensorFieldCompactIOField> >
lagrangianSphericalTensorFieldFields(cloudDirs.size());
PtrList<PtrList<symmTensorIOField> > lagrangianSymmTensorFields
(
cloudDirs.size()
);
PtrList<PtrList<symmTensorIOFieldField> > lagrangianSymmTensorFieldFields
PtrList<PtrList<symmTensorFieldCompactIOField> >
lagrangianSymmTensorFieldFields
(
cloudDirs.size()
);
@ -434,7 +435,7 @@ int main(int argc, char *argv[])
(
cloudDirs.size()
);
PtrList<PtrList<tensorIOFieldField> > lagrangianTensorFieldFields
PtrList<PtrList<tensorFieldCompactIOField> > lagrangianTensorFieldFields
(
cloudDirs.size()
);

View File

@ -37,7 +37,7 @@ SourceFiles
#define lagrangianFieldDecomposer_H
#include "Cloud.H"
#include "IOFieldField.H"
#include "CompactIOField.H"
#include "indexedParticle.H"
#include "passiveParticle.H"
@ -111,9 +111,9 @@ public:
const IOobjectList& lagrangianObjects,
PtrList
<
PtrList<IOFieldField<Field<Type>, Type> >
PtrList<CompactIOField<Field<Type>, Type> >
>& lagrangianFields
// PtrList<IOFieldField<Field<Type>, Type > >& lagrangianFields
// PtrList<CompactIOField<Field<Type>, Type > >& lagrangianFields
);
@ -126,10 +126,10 @@ public:
) const;
template<class Type>
tmp<IOFieldField<Field<Type>, Type> > decomposeFieldField
tmp<CompactIOField<Field<Type>, Type> > decomposeFieldField
(
const word& cloudName,
const IOFieldField<Field<Type>, Type>& field
const CompactIOField<Field<Type>, Type>& field
) const;

View File

@ -68,7 +68,7 @@ void Foam::lagrangianFieldDecomposer::readFieldFields
(
const label cloudI,
const IOobjectList& lagrangianObjects,
PtrList<PtrList<IOFieldField<Field<Type>, Type> > >& lagrangianFields
PtrList<PtrList<CompactIOField<Field<Type>, Type> > >& lagrangianFields
)
{
// Search list of objects for lagrangian fields
@ -79,13 +79,17 @@ void Foam::lagrangianFieldDecomposer::readFieldFields
IOobjectList lagrangianTypeObjectsB
(
lagrangianObjects.lookupClass(IOFieldField<Field<Type>, Type>::typeName)
lagrangianObjects.lookupClass
(
CompactIOField<Field<Type>,
Type>::typeName
)
);
lagrangianFields.set
(
cloudI,
new PtrList<IOFieldField<Field<Type>, Type> >
new PtrList<CompactIOField<Field<Type>, Type> >
(
lagrangianTypeObjectsA.size() + lagrangianTypeObjectsB.size()
)
@ -98,7 +102,7 @@ void Foam::lagrangianFieldDecomposer::readFieldFields
lagrangianFields[cloudI].set
(
lagrangianFieldi++,
new IOFieldField<Field<Type>, Type>(*iter())
new CompactIOField<Field<Type>, Type>(*iter())
);
}
@ -107,7 +111,7 @@ void Foam::lagrangianFieldDecomposer::readFieldFields
lagrangianFields[cloudI].set
(
lagrangianFieldi++,
new IOFieldField<Field<Type>, Type>(*iter())
new CompactIOField<Field<Type>, Type>(*iter())
);
}
}
@ -145,20 +149,20 @@ Foam::lagrangianFieldDecomposer::decomposeField
template<class Type>
Foam::tmp<Foam::IOFieldField<Foam::Field<Type>, Type> >
Foam::tmp<Foam::CompactIOField<Foam::Field<Type>, Type> >
Foam::lagrangianFieldDecomposer::decomposeFieldField
(
const word& cloudName,
const IOFieldField<Field<Type>, Type>& field
const CompactIOField<Field<Type>, Type>& field
) const
{
// Create and map the internal field values
Field<Field<Type> > procField(field, particleIndices_);
// Create the field for the processor
return tmp<IOFieldField<Field<Type>, Type> >
return tmp<CompactIOField<Field<Type>, Type> >
(
new IOFieldField<Field<Type>, Type>
new CompactIOField<Field<Type>, Type>
(
IOobject
(

View File

@ -2,6 +2,5 @@ itoa.C
ensightMesh.C
ensightParticlePositions.C
foamToEnsight.C
ensightWriteBinary.C
EXE = $(FOAM_APPBIN)/foamToEnsight

View File

@ -44,15 +44,6 @@ namespace Foam
class cellSets
{
// Private Member Functions
//- Disallow default bitwise copy construct
cellSets(const cellSets&);
//- Disallow default bitwise assignment
void operator=(const cellSets&);
public:
label nHexesWedges;

View File

@ -0,0 +1,156 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::ensightAsciiStream
Description
SourceFiles
ensightAsciiStream.C
\*---------------------------------------------------------------------------*/
#ifndef ensightAsciiStream_H
#define ensightAsciiStream_H
#include "ensightStream.H"
#include "OFstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class ensightAsciiStream Declaration
\*---------------------------------------------------------------------------*/
class ensightAsciiStream
:
public ensightStream
{
// Private data
//- Description of data_
OFstream str_;
// Private Member Functions
//- Disallow default bitwise copy construct
ensightAsciiStream(const ensightAsciiStream&);
//- Disallow default bitwise assignment
void operator=(const ensightAsciiStream&);
public:
// Constructors
//- Construct from components
ensightAsciiStream(const fileName& f, const Time& runTime)
:
ensightStream(f),
str_
(
f,
runTime.writeFormat(),
runTime.writeVersion(),
IOstream::UNCOMPRESSED
)
{
str_.setf(ios_base::scientific, ios_base::floatfield);
str_.precision(5);
}
//- Destructor
virtual ~ensightAsciiStream()
{}
// Member Functions
virtual void write(const char* c)
{
str_ << c << nl;
}
virtual void write(const int v)
{
str_ << setw(10) << v << nl;
}
virtual void write(const scalarField& sf)
{
forAll(sf, i)
{
if (mag(sf[i]) >= scalar(floatScalarVSMALL))
{
str_ << setw(12) << sf[i] << nl;
}
else
{
str_ << setw(12) << scalar(0) << nl;
}
}
}
virtual void write(const List<int>& sf)
{
forAll(sf, i)
{
str_ << setw(10) << sf[i];
}
str_<< nl;
}
virtual void writePartHeader(const label partI)
{
str_<< "part" << nl
<< setw(10) << partI << nl;
}
// Member Operators
// Friend Functions
// Friend Operators
// IOstream Operators
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,158 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::ensightBinaryStream
Description
SourceFiles
ensightBinaryStream.C
\*---------------------------------------------------------------------------*/
#ifndef ensightBinaryStream_H
#define ensightBinaryStream_H
#include "ensightStream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class ensightBinaryStream Declaration
\*---------------------------------------------------------------------------*/
class ensightBinaryStream
:
public ensightStream
{
// Private data
//- Description of data_
autoPtr<std::ofstream> str_;
// Private Member Functions
//- Disallow default bitwise copy construct
ensightBinaryStream(const ensightBinaryStream&);
//- Disallow default bitwise assignment
void operator=(const ensightBinaryStream&);
public:
// Constructors
//- Construct from components
ensightBinaryStream(const fileName& f, const Time&)
:
ensightStream(f),
str_
(
new std::ofstream
(
f.c_str(),
ios_base::out | ios_base::binary | ios_base::trunc
)
)
{}
//- Destructor
virtual ~ensightBinaryStream()
{}
// Member Functions
virtual void write(const char* val)
{
char buffer[80] = {0};
strcpy(buffer, val);
str_().write(buffer, 80*sizeof(char));
}
virtual void write(const int val)
{
str_().write(reinterpret_cast<const char*>(&val), sizeof(int));
}
virtual void write(const scalarField& sf)
{
if (sf.size())
{
List<float> temp(sf.size());
forAll(sf, i)
{
temp[i] = float(sf[i]);
}
str_().write
(
reinterpret_cast<const char*>(temp.begin()),
sf.size()*sizeof(float)
);
}
}
virtual void write(const List<int>& sf)
{
str_().write
(
reinterpret_cast<const char*>(sf.begin()),
sf.size()*sizeof(int)
);
}
virtual void writePartHeader(const label partI)
{
write("part");
write(partI);
}
// Member Operators
// Friend Functions
// Friend Operators
// IOstream Operators
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -29,28 +29,14 @@ License
#include "OFstream.H"
#include "IOmanip.H"
#include "itoa.H"
#include "ensightWriteBinary.H"
#include "volPointInterpolation.H"
#include "ensightBinaryStream.H"
#include "ensightAsciiStream.H"
using namespace Foam;
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
void writeData(const scalarField& sf, OFstream& ensightFile)
{
forAll(sf, i)
{
if (mag( sf[i] ) >= scalar(floatScalarVSMALL))
{
ensightFile << setw(12) << sf[i] << nl;
}
else
{
ensightFile << setw(12) << scalar(0) << nl;
}
}
}
template<class Type>
scalarField map
(
@ -104,64 +90,25 @@ void writeAllData
const Field<Type>& vf,
const labelList& prims,
const label nPrims,
OFstream& ensightFile
ensightStream& ensightFile
)
{
if (nPrims)
{
if (Pstream::master())
{
ensightFile << key << nl;
ensightFile.write(key);
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
writeData(map(vf, prims, cmpt), ensightFile);
scalarField masterData(map(vf, prims, cmpt));
ensightFile.write(masterData);
for (int slave=1; slave<Pstream::nProcs(); slave++)
{
IPstream fromSlave(Pstream::scheduled, slave);
scalarField data(fromSlave);
writeData(data, ensightFile);
}
}
}
else
{
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
toMaster<< map(vf, prims, cmpt);
}
}
}
}
template<class Type>
void writeAllDataBinary
(
const char* key,
const Field<Type>& vf,
const labelList& prims,
const label nPrims,
std::ofstream& ensightFile
)
{
if (nPrims)
{
if (Pstream::master())
{
writeEnsDataBinary(key,ensightFile);
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
writeEnsDataBinary(map(vf, prims, cmpt), ensightFile);
for (int slave=1; slave<Pstream::nProcs(); slave++)
{
IPstream fromSlave(Pstream::scheduled, slave);
scalarField data(fromSlave);
writeEnsDataBinary(data, ensightFile);
scalarField slaveData(fromSlave);
ensightFile.write(slaveData);
}
}
}
@ -184,66 +131,25 @@ void writeAllFaceData
const labelList& prims,
const label nPrims,
const Field<Type>& pf,
OFstream& ensightFile
ensightStream& ensightFile
)
{
if (nPrims)
{
if (Pstream::master())
{
ensightFile << key << nl;
ensightFile.write(key);
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
writeData(map(pf, prims, cmpt), ensightFile);
ensightFile.write(map(pf, prims, cmpt));
for (int slave=1; slave<Pstream::nProcs(); slave++)
{
IPstream fromSlave(Pstream::scheduled, slave);
scalarField pf(fromSlave);
writeData(pf, ensightFile);
}
}
}
else
{
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
toMaster<< map(pf, prims, cmpt);
}
}
}
}
template<class Type>
void writeAllFaceDataBinary
(
const char* key,
const labelList& prims,
const label nPrims,
const Field<Type>& pf,
std::ofstream& ensightFile
)
{
if (nPrims)
{
if (Pstream::master())
{
writeEnsDataBinary(key,ensightFile);
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
writeEnsDataBinary(map(pf, prims, cmpt), ensightFile);
for (int slave=1; slave<Pstream::nProcs(); slave++)
{
IPstream fromSlave(Pstream::scheduled, slave);
scalarField pf(fromSlave);
writeEnsDataBinary(pf, ensightFile);
ensightFile.write(pf);
}
}
}
@ -267,16 +173,14 @@ bool writePatchField
const Foam::label ensightPatchI,
const Foam::faceSets& boundaryFaceSet,
const Foam::ensightMesh::nFacePrimitives& nfp,
Foam::OFstream& ensightFile
ensightStream& ensightFile
)
{
if (nfp.nTris || nfp.nQuads || nfp.nPolys)
{
if (Pstream::master())
{
ensightFile
<< "part" << nl
<< setw(10) << ensightPatchI << nl;
ensightFile.writePartHeader(ensightPatchI);
}
writeAllFaceData
@ -315,61 +219,6 @@ bool writePatchField
}
template<class Type>
bool writePatchFieldBinary
(
const Foam::Field<Type>& pf,
const Foam::label patchi,
const Foam::label ensightPatchI,
const Foam::faceSets& boundaryFaceSet,
const Foam::ensightMesh::nFacePrimitives& nfp,
std::ofstream& ensightFile
)
{
if (nfp.nTris || nfp.nQuads || nfp.nPolys)
{
if (Pstream::master())
{
writeEnsDataBinary("part",ensightFile);
writeEnsDataBinary(ensightPatchI,ensightFile);
}
writeAllFaceDataBinary
(
"tria3",
boundaryFaceSet.tris,
nfp.nTris,
pf,
ensightFile
);
writeAllFaceDataBinary
(
"quad4",
boundaryFaceSet.quads,
nfp.nQuads,
pf,
ensightFile
);
writeAllFaceDataBinary
(
"nsided",
boundaryFaceSet.polys,
nfp.nPolys,
pf,
ensightFile
);
return true;
}
else
{
return false;
}
}
template<class Type>
void writePatchField
(
@ -380,6 +229,7 @@ void writePatchField
const Foam::fileName& postProcPath,
const Foam::word& prepend,
const Foam::label timeIndex,
const bool binary,
Foam::Ostream& ensightCaseFile
)
{
@ -409,7 +259,7 @@ void writePatchField
word timeFile = prepend + itoa(timeIndex);
OFstream *ensightFilePtr = NULL;
ensightStream* ensightFilePtr = NULL;
if (Pstream::master())
{
if (timeIndex == 0)
@ -426,20 +276,30 @@ void writePatchField
// set the filename of the ensight file
fileName ensightFileName(timeFile + "." + pfName);
ensightFilePtr = new OFstream
if (binary)
{
ensightFilePtr = new ensightBinaryStream
(
postProcPath/ensightFileName,
runTime.writeFormat(),
runTime.writeVersion(),
runTime.writeCompression()
runTime
);
}
else
{
ensightFilePtr = new ensightAsciiStream
(
postProcPath/ensightFileName,
runTime
);
}
}
OFstream& ensightFile = *ensightFilePtr;
ensightStream& ensightFile = *ensightFilePtr;
if (Pstream::master())
{
ensightFile << pTraits<Type>::typeName << nl;
ensightFile.write(pTraits<Type>::typeName);
}
if (patchi >= 0)
@ -477,17 +337,18 @@ void writePatchField
template<class Type>
void ensightFieldAscii
void ensightField
(
const Foam::IOobject& fieldObject,
const GeometricField<Type, fvPatchField, volMesh>& vf,
const Foam::ensightMesh& eMesh,
const Foam::fileName& postProcPath,
const Foam::word& prepend,
const Foam::label timeIndex,
const bool binary,
Foam::Ostream& ensightCaseFile
)
{
Info<< "Converting field " << fieldObject.name() << endl;
Info<< "Converting field " << vf.name() << endl;
word timeFile = prepend + itoa(timeIndex);
@ -512,23 +373,31 @@ void ensightFieldAscii
const labelList& hexes = meshCellSets.hexes;
const labelList& polys = meshCellSets.polys;
OFstream *ensightFilePtr = NULL;
ensightStream* ensightFilePtr = NULL;
if (Pstream::master())
{
// set the filename of the ensight file
fileName ensightFileName(timeFile + "." + fieldObject.name());
ensightFilePtr = new OFstream
fileName ensightFileName(timeFile + "." + vf.name());
if (binary)
{
ensightFilePtr = new ensightBinaryStream
(
postProcPath/ensightFileName,
runTime.writeFormat(),
runTime.writeVersion(),
IOstream::UNCOMPRESSED
runTime
);
}
else
{
ensightFilePtr = new ensightAsciiStream
(
postProcPath/ensightFileName,
runTime
);
}
}
OFstream& ensightFile = *ensightFilePtr;
GeometricField<Type, fvPatchField, volMesh> vf(fieldObject, mesh);
ensightStream& ensightFile = *ensightFilePtr;
if (patchNames.empty())
{
@ -548,34 +417,26 @@ void ensightFieldAscii
<< nl;
}
ensightFile
<< pTraits<Type>::typeName << nl
<< "part" << nl
<< setw(10) << 1 << nl;
ensightFile.setf(ios_base::scientific, ios_base::floatfield);
ensightFile.precision(5);
ensightFile.write(pTraits<Type>::typeName);
ensightFile.writePartHeader(1);
}
if (meshCellSets.nHexesWedges)
{
if (Pstream::master())
{
ensightFile << "hexa8" << nl;
ensightFile.write("hexa8");
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
writeData
(
map(vf, hexes, wedges, cmpt),
ensightFile
);
scalarField masterData(map(vf, hexes, wedges, cmpt));
ensightFile.write(masterData);
for (int slave=1; slave<Pstream::nProcs(); slave++)
{
IPstream fromSlave(Pstream::scheduled, slave);
scalarField data(fromSlave);
writeData(data, ensightFile);
ensightFile.write(data);
}
}
}
@ -727,7 +588,6 @@ void ensightFieldAscii
}
}
}
if (Pstream::master())
{
delete ensightFilePtr;
@ -736,59 +596,48 @@ void ensightFieldAscii
template<class Type>
void ensightFieldBinary
void ensightPointField
(
const Foam::IOobject& fieldObject,
const GeometricField<Type, pointPatchField, pointMesh>& pf,
const Foam::ensightMesh& eMesh,
const Foam::fileName& postProcPath,
const Foam::word& prepend,
const Foam::label timeIndex,
const bool binary,
Foam::Ostream& ensightCaseFile
)
{
Info<< "Converting field (binary) " << fieldObject.name() << endl;
Info<< "Converting field " << pf.name() << endl;
word timeFile = prepend + itoa(timeIndex);
const fvMesh& mesh = eMesh.mesh();
//const Time& runTime = mesh.time();
const cellSets& meshCellSets = eMesh.meshCellSets();
const List<faceSets>& boundaryFaceSets = eMesh.boundaryFaceSets();
const wordList& allPatchNames = eMesh.allPatchNames();
const wordHashSet& patchNames = eMesh.patchNames();
const HashTable<ensightMesh::nFacePrimitives>&
nPatchPrims = eMesh.nPatchPrims();
const List<faceSets>& faceZoneFaceSets = eMesh.faceZoneFaceSets();
const wordHashSet& faceZoneNames = eMesh.faceZoneNames();
const HashTable<ensightMesh::nFacePrimitives>&
nFaceZonePrims = eMesh.nFaceZonePrims();
const labelList& tets = meshCellSets.tets;
const labelList& pyrs = meshCellSets.pyrs;
const labelList& prisms = meshCellSets.prisms;
const labelList& wedges = meshCellSets.wedges;
const labelList& hexes = meshCellSets.hexes;
const labelList& polys = meshCellSets.polys;
std::ofstream *ensightFilePtr = NULL;
ensightStream* ensightFilePtr = NULL;
if (Pstream::master())
{
// set the filename of the ensight file
fileName ensightFileName(timeFile + "." + fieldObject.name());
ensightFilePtr = new std::ofstream
fileName ensightFileName(timeFile + "." + pf.name());
if (binary)
{
ensightFilePtr = new ensightBinaryStream
(
(postProcPath/ensightFileName).c_str(),
ios_base::out | ios_base::binary | ios_base::trunc
postProcPath/ensightFileName,
eMesh.mesh().time()
);
// Check on file opened?
}
else
{
ensightFilePtr = new ensightAsciiStream
(
postProcPath/ensightFileName,
eMesh.mesh().time()
);
}
}
std::ofstream& ensightFile = *ensightFilePtr;
ensightStream& ensightFile = *ensightFilePtr;
GeometricField<Type, fvPatchField, volMesh> vf(fieldObject, mesh);
if (patchNames.empty())
if (eMesh.patchNames().empty())
{
eMesh.barrier();
@ -800,192 +649,49 @@ void ensightFieldBinary
ensightCaseFile
<< pTraits<Type>::typeName
<< " per element: 1 "
<< setw(15) << vf.name()
<< (' ' + prepend + "***." + vf.name()).c_str()
<< " per node: 1 "
<< setw(15) << pf.name()
<< (' ' + prepend + "***." + pf.name()).c_str()
<< nl;
}
writeEnsDataBinary(pTraits<Type>::typeName,ensightFile);
writeEnsDataBinary("part",ensightFile);
writeEnsDataBinary(1,ensightFile);
ensightFile.write(pTraits<Type>::typeName);
ensightFile.write("part");
ensightFile.write(1);
}
if (meshCellSets.nHexesWedges)
{
if (Pstream::master())
{
writeEnsDataBinary("hexa8",ensightFile);
ensightFile.write("coordinates");
Field<Type> uniqueFld(pf.internalField(), eMesh.uniquePointMap());
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
writeEnsDataBinary
(
map(vf, hexes, wedges, cmpt),
ensightFile
);
ensightFile.write(uniqueFld.component(cmpt));
for (int slave=1; slave<Pstream::nProcs(); slave++)
{
IPstream fromSlave(Pstream::scheduled, slave);
scalarField data(fromSlave);
writeEnsDataBinary(data, ensightFile);
ensightFile.write(data);
}
}
}
else
{
Field<Type> uniqueFld(pf.internalField(), eMesh.uniquePointMap());
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
toMaster<< map(vf, hexes, wedges, cmpt);
}
}
}
writeAllDataBinary
(
"penta6",
vf,
prisms,
meshCellSets.nPrisms,
ensightFile
);
writeAllDataBinary
(
"pyramid5",
vf,
pyrs,
meshCellSets.nPyrs,
ensightFile
);
writeAllDataBinary
(
"tetra4",
vf,
tets,
meshCellSets.nTets,
ensightFile
);
writeAllDataBinary
(
"nfaced",
vf,
polys,
meshCellSets.nPolys,
ensightFile
);
}
label ensightPatchI = eMesh.patchPartOffset();
forAll(allPatchNames, patchi)
{
const word& patchName = allPatchNames[patchi];
eMesh.barrier();
if (patchNames.empty() || patchNames.found(patchName))
{
if
(
writePatchFieldBinary
(
vf.boundaryField()[patchi],
patchi,
ensightPatchI,
boundaryFaceSets[patchi],
nPatchPrims.find(patchName)(),
ensightFile
)
)
{
ensightPatchI++;
}
}
}
// write faceZones, if requested
if (faceZoneNames.size())
{
// Interpolates cell values to faces - needed only when exporting
// faceZones...
GeometricField<Type, fvsPatchField, surfaceMesh> sf
(
linearInterpolate(vf)
);
forAllConstIter(wordHashSet, faceZoneNames, iter)
{
const word& faceZoneName = iter.key();
eMesh.barrier();
label zoneID = mesh.faceZones().findZoneID(faceZoneName);
const faceZone& fz = mesh.faceZones()[zoneID];
// Prepare data to write
label nIncluded = 0;
forAll(fz, i)
{
if (eMesh.faceToBeIncluded(fz[i]))
{
++nIncluded;
}
}
Field<Type> values(nIncluded);
// Loop on the faceZone and store the needed field values
label j = 0;
forAll(fz, i)
{
label faceI = fz[i];
if (mesh.isInternalFace(faceI))
{
values[j] = sf[faceI];
++j;
}
else
{
if (eMesh.faceToBeIncluded(faceI))
{
label patchI = mesh.boundaryMesh().whichPatch(faceI);
const polyPatch& pp = mesh.boundaryMesh()[patchI];
label patchFaceI = pp.whichFace(faceI);
Type value = sf.boundaryField()[patchI][patchFaceI];
values[j] = value;
++j;
}
}
}
if
(
writePatchFieldBinary
(
values,
zoneID,
ensightPatchI,
faceZoneFaceSets[zoneID],
nFaceZonePrims.find(faceZoneName)(),
ensightFile
)
)
{
ensightPatchI++;
toMaster<< uniqueFld.component(cmpt);
}
}
}
if (Pstream::master())
{
ensightFile.close();
delete ensightFilePtr;
}
}
@ -999,30 +705,42 @@ void ensightField
const Foam::word& prepend,
const Foam::label timeIndex,
const bool binary,
const bool nodeValues,
Foam::Ostream& ensightCaseFile
)
{
if (binary)
// Read field
GeometricField<Type, fvPatchField, volMesh> vf(fieldObject, eMesh.mesh());
if (nodeValues)
{
ensightFieldBinary<Type>
tmp<GeometricField<Type, pointPatchField, pointMesh> > pfld
(
fieldObject,
volPointInterpolation::New(eMesh.mesh()).interpolate(vf)
);
pfld().rename(vf.name());
ensightPointField<Type>
(
pfld,
eMesh,
postProcPath,
prepend,
timeIndex,
binary,
ensightCaseFile
);
}
else
{
ensightFieldAscii<Type>
ensightField<Type>
(
fieldObject,
vf,
eMesh,
postProcPath,
prepend,
timeIndex,
binary,
ensightCaseFile
);
}

View File

@ -38,10 +38,13 @@ SourceFiles
#include "faceSets.H"
#include "HashTable.H"
#include "HashSet.H"
#include "fvMesh.H"
#include "OFstream.H"
#include <fstream>
#include "PackedBoolList.H"
#include "wordReList.H"
#include "scalarField.H"
#include "cellShapeList.H"
#include "cellList.H"
#include <fstream>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -51,6 +54,7 @@ namespace Foam
class fvMesh;
class argList;
class globalIndex;
class ensightStream;
/*---------------------------------------------------------------------------*\
Class ensightMesh Declaration
@ -82,8 +86,19 @@ private:
//- Reference to the OpenFOAM mesh
const fvMesh& mesh_;
//- Suppress patches
const bool noPatches_;
//- Output selected patches only
const bool patches_;
const wordReList patchPatterns_;
//- Output selected faceZones
const bool faceZones_;
const wordReList faceZonePatterns_;
//- Set binary file output
bool binary_;
const bool binary_;
//- The ensight part id for the first patch
label patchPartOffset_;
@ -109,6 +124,19 @@ private:
PackedBoolList boundaryFaceToBeIncluded_;
// Parallel merged points
//- Global numbering for merged points
autoPtr<globalIndex> globalPointsPtr_;
//- From mesh point to global merged point
labelList pointToGlobal_;
//- Local points that are unique
labelList uniquePointMap_;
// Private Member Functions
//- Disallow default bitwise copy construct
@ -120,7 +148,7 @@ private:
void writePoints
(
const scalarField& pointsComponent,
OFstream& ensightGeometryFile
ensightStream& ensightGeometryFile
) const;
cellShapeList map
@ -141,14 +169,14 @@ private:
void writePrims
(
const cellShapeList& cellShapes,
OFstream& ensightGeometryFile
ensightStream& ensightGeometryFile
) const;
void writePolysNFaces
(
const labelList& polys,
const cellList& cellFaces,
OFstream& ensightGeometryFile
ensightStream& ensightGeometryFile
) const;
void writePolysNPointsPerFace
@ -156,7 +184,7 @@ private:
const labelList& polys,
const cellList& cellFaces,
const faceList& faces,
OFstream& ensightGeometryFile
ensightStream& ensightGeometryFile
) const;
void writePolysPoints
@ -164,13 +192,13 @@ private:
const labelList& polys,
const cellList& cellFaces,
const faceList& faces,
OFstream& ensightGeometryFile
ensightStream& ensightGeometryFile
) const;
void writeAllPolys
(
const labelList& pointToGlobal,
OFstream& ensightGeometryFile
ensightStream& ensightGeometryFile
) const;
void writeAllPrims
@ -178,13 +206,13 @@ private:
const char* key,
const label nPrims,
const cellShapeList& cellShapes,
OFstream& ensightGeometryFile
ensightStream& ensightGeometryFile
) const;
void writeFacePrims
(
const faceList& patchFaces,
OFstream& ensightGeometryFile
ensightStream& ensightGeometryFile
) const;
void writeAllFacePrims
@ -193,19 +221,19 @@ private:
const labelList& prims,
const label nPrims,
const faceList& patchFaces,
OFstream& ensightGeometryFile
ensightStream& ensightGeometryFile
) const;
void writeNSidedNPointsPerFace
(
const faceList& patchFaces,
OFstream& ensightGeometryFile
ensightStream& ensightGeometryFile
) const;
void writeNSidedPoints
(
const faceList& patchFaces,
OFstream& ensightGeometryFile
ensightStream& ensightGeometryFile
) const;
void writeAllNSided
@ -213,14 +241,14 @@ private:
const labelList& prims,
const label nPrims,
const faceList& patchFaces,
OFstream& ensightGeometryFile
ensightStream& ensightGeometryFile
) const;
void writeAllInternalPoints
(
const pointField& uniquePoints,
const label nPoints,
OFstream& ensightGeometryFile
ensightStream& ensightGeometryFile
) const;
void writeAllPatchPoints
@ -229,123 +257,7 @@ private:
const word& patchName,
const pointField& uniquePoints,
const label nPoints,
OFstream& ensightGeometryFile
) const;
void writeAllInternalPointsBinary
(
const pointField& uniquePoints,
const label nPoints,
std::ofstream& ensightGeometryFile
) const;
void writeAllPatchPointsBinary
(
label ensightPatchI,
const word& patchName,
const pointField& uniquePoints,
const label nPoints,
std::ofstream& ensightGeometryFile
) const;
void writeAscii
(
const fileName& postProcPath,
const word& prepend,
const label timeIndex,
Ostream& ensightCaseFile,
const labelList& pointToGlobal,
const pointField& uniquePoints,
const globalIndex& globalPoints
) const;
void writeBinary
(
const fileName& postProcPath,
const word& prepend,
const label timeIndex,
Ostream& ensightCaseFile,
const labelList& pointToGlobal,
const pointField& uniquePoints,
const globalIndex& globalPoints
) const;
void writePrimsBinary
(
const cellShapeList& cellShapes,
std::ofstream& ensightGeometryFile
) const;
void writeAllPrimsBinary
(
const char* key,
const label nPrims,
const cellShapeList& cellShapes,
std::ofstream& ensightGeometryFile
) const;
void writePolysNFacesBinary
(
const labelList& polys,
const cellList& cellFaces,
std::ofstream& ensightGeometryFile
) const;
void writePolysNPointsPerFaceBinary
(
const labelList& polys,
const cellList& cellFaces,
const faceList& faces,
std::ofstream& ensightGeometryFile
) const;
void writePolysPointsBinary
(
const labelList& polys,
const cellList& cellFaces,
const faceList& faces,
std::ofstream& ensightGeometryFile
) const;
void writeAllPolysBinary
(
const labelList& pointToGlobal,
std::ofstream& ensightGeometryFile
) const;
void writeAllFacePrimsBinary
(
const char* key,
const labelList& prims,
const label nPrims,
const faceList& patchFaces,
std::ofstream& ensightGeometryFile
) const;
void writeFacePrimsBinary
(
const faceList& patchFaces,
std::ofstream& ensightGeometryFile
) const;
void writeNSidedPointsBinary
(
const faceList& patchFaces,
std::ofstream& ensightGeometryFile
) const;
void writeNSidedNPointsPerFaceBinary
(
const faceList& patchFaces,
std::ofstream& ensightGeometryFile
) const;
void writeAllNSidedBinary
(
const labelList& prims,
const label nPrims,
const faceList& patchFaces,
std::ofstream& ensightGeometryFile
ensightStream& ensightGeometryFile
) const;
public:
@ -355,8 +267,12 @@ public:
//- Construct from fvMesh
ensightMesh
(
const fvMesh&,
const argList& args,
const fvMesh& mesh,
const bool noPatches,
const bool patches,
const wordReList& patchPatterns,
const bool faceZones,
const wordReList& faceZonePatterns,
const bool binary
);
@ -420,8 +336,35 @@ public:
return patchPartOffset_;
}
// Parallel point merging
//- Global numbering for merged points
const globalIndex& globalPoints() const
{
return globalPointsPtr_();
}
//- From mesh point to global merged point
const labelList& pointToGlobal() const
{
return pointToGlobal_;
}
//- Local points that are unique
const labelList& uniquePointMap() const
{
return uniquePointMap_;
}
// Other
//- Update for new mesh
void correct();
//- When exporting faceZones, check if a given face has to be included
// or not (i.e. faces on processor boundaries)
bool faceToBeIncluded(const label faceI) const;

View File

@ -0,0 +1,112 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::ensightStream
Description
Abstract base class for writing Ensight data
SourceFiles
ensightStream.C
\*---------------------------------------------------------------------------*/
#ifndef ensightStream_H
#define ensightStream_H
#include "fileName.H"
#include "scalarField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class ensightStream Declaration
\*---------------------------------------------------------------------------*/
class ensightStream
{
// Private data
const fileName name_;
// Private Member Functions
//- Disallow default bitwise copy construct
ensightStream(const ensightStream&);
//- Disallow default bitwise assignment
void operator=(const ensightStream&);
public:
// Constructors
//- Construct from components
ensightStream(const fileName& f)
:
name_(f)
{}
//- Destructor
virtual ~ensightStream()
{}
// Member Functions
const fileName& name() const
{
return name_;
}
virtual void write(const char*) = 0;
virtual void write(const int) = 0;
virtual void write(const scalarField&) = 0;
virtual void write(const List<int>&) = 0;
virtual void writePartHeader(const label) = 0;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -1,78 +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/>.
\*---------------------------------------------------------------------------*/
#include "ensightWriteBinary.H"
#include <fstream>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void writeEnsDataBinary
(
const char* val,
std::ofstream& ensFile
)
{
char buffer[80] = {0};
strcpy(buffer, val);
ensFile.write(buffer, 80*sizeof(char));
}
void writeEnsDataBinary
(
const int val,
std::ofstream& ensFile
)
{
ensFile.write(reinterpret_cast<const char*>(&val), sizeof(int));
}
void writeEnsDataBinary
(
const scalarField& sf,
std::ofstream& ensightFile
)
{
if (sf.size())
{
List<float> temp(sf.size());
forAll(sf, i)
{
temp[i] = float(sf[i]);
}
ensightFile.write
(
reinterpret_cast<char*>(temp.begin()),
sf.size()*sizeof(float)
);
}
}
// ************************************************************************* //

View File

@ -1,67 +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/>.
InApplication
foamToEnsight
Description
Collection of functions for binary write in EnSight files
SourceFiles
ensightWriteBinary.C
\*---------------------------------------------------------------------------*/
#ifndef ensightWriteBinary_H
#define ensightWriteBinary_H
#include "ensightMesh.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void writeEnsDataBinary
(
const char* val,
std::ofstream& ensFile
);
void writeEnsDataBinary
(
const int val,
std::ofstream& ensFile
);
void writeEnsDataBinary
(
const scalarField& sf,
std::ofstream& ensightFile
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -44,15 +44,6 @@ namespace Foam
class faceSets
{
// Private Member Functions
//- Disallow default bitwise copy construct
faceSets(const faceSets&);
//- Disallow default bitwise assignment
void operator=(const faceSets&);
public:
label nTris;

View File

@ -104,6 +104,11 @@ int main(int argc, char *argv[])
"write in ASCII format instead of 'C Binary'"
);
argList::addBoolOption
(
"nodeValues",
"write values in nodes"
);
argList::addBoolOption
(
"noPatches",
"suppress writing any patches"
@ -126,6 +131,7 @@ int main(int argc, char *argv[])
// Check options
const bool binary = !args.optionFound("ascii");
const bool nodeValues = args.optionFound("nodeValues");
# include "createTime.H"
@ -191,7 +197,29 @@ int main(int argc, char *argv[])
OFstream& ensightCaseFile = *ensightCaseFilePtr;
// Construct the EnSight mesh
ensightMesh eMesh(mesh, args, binary);
const bool selectedPatches = args.optionFound("patches");
wordReList patchPatterns;
if (selectedPatches)
{
patchPatterns = wordReList(args.optionLookup("patches")());
}
const bool selectedZones = args.optionFound("faceZones");
wordReList zonePatterns;
if (selectedZones)
{
zonePatterns = wordReList(args.optionLookup("faceZones")());
}
ensightMesh eMesh
(
mesh,
args.optionFound("noPatches"),
selectedPatches,
patchPatterns,
selectedZones,
zonePatterns,
binary
);
// Set Time to the last time before looking for the lagrangian objects
runTime.setTime(Times.last(), Times.size()-1);
@ -313,6 +341,11 @@ int main(int argc, char *argv[])
polyMesh::readUpdateState meshState = mesh.readUpdate();
if (meshState != polyMesh::UNCHANGED)
{
eMesh.correct();
}
if (timeIndex == 0 || (meshState != polyMesh::UNCHANGED))
{
eMesh.write
@ -371,6 +404,7 @@ int main(int argc, char *argv[])
prepend,
timeIndex,
binary,
nodeValues,
ensightCaseFile
);
}
@ -384,6 +418,7 @@ int main(int argc, char *argv[])
prepend,
timeIndex,
binary,
nodeValues,
ensightCaseFile
);
}
@ -397,6 +432,7 @@ int main(int argc, char *argv[])
prepend,
timeIndex,
binary,
nodeValues,
ensightCaseFile
);
}
@ -410,6 +446,7 @@ int main(int argc, char *argv[])
prepend,
timeIndex,
binary,
nodeValues,
ensightCaseFile
);
}
@ -423,6 +460,7 @@ int main(int argc, char *argv[])
prepend,
timeIndex,
binary,
nodeValues,
ensightCaseFile
);
}

View File

@ -37,7 +37,7 @@ Description
#include "GeometricField.H"
#include "meshToMesh.H"
#include "IOobjectList.H"
#include "IOFieldField.H"
#include "CompactIOField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -106,9 +106,9 @@ void MapLagrangianFields
// Read field (does not need mesh)
IOField<Field<Type> > fieldSource(*fieldIter());
// Map - use IOFieldField to automatically write in
// Map - use CompactIOField to automatically write in
// compact form for binary format.
IOFieldField<Field<Type>, Type> fieldTarget
CompactIOField<Field<Type>, Type> fieldTarget
(
IOobject
(
@ -135,7 +135,7 @@ void MapLagrangianFields
{
IOobjectList fieldFields =
objects.lookupClass(IOFieldField<Field<Type>, Type>::typeName);
objects.lookupClass(CompactIOField<Field<Type>, Type>::typeName);
forAllIter(IOobjectList, fieldFields, fieldIter)
{
@ -143,10 +143,10 @@ void MapLagrangianFields
<< fieldIter()->name() << endl;
// Read field (does not need mesh)
IOFieldField<Field<Type>, Type> fieldSource(*fieldIter());
CompactIOField<Field<Type>, Type> fieldSource(*fieldIter());
// Map
IOFieldField<Field<Type>, Type> fieldTarget
CompactIOField<Field<Type>, Type> fieldTarget
(
IOobject
(

View File

@ -76,6 +76,11 @@ cleanCase()
sets/streamLines \
> /dev/null 2>&1
if [ -e constant/polyMesh/blockMeshDict.m4 ]
then
rm -f constant/polyMesh/blockMeshDict > /dev/null 2>&1
fi
for f in `find . -name "*Dict"`
do
sed -e /arguments/d $f > temp.$$

View File

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

View File

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

View File

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

View File

@ -45,6 +45,9 @@
# Note
# 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()
{
@ -52,13 +55,14 @@ die()
echo '-----------------------' 1>&2
echo '' 1>&2
echo "$@" 1>&2
echo '' 1>&2
exit 1
}
#-----------------------------------------------------------------------------
# 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
against=HEAD
else
@ -66,10 +70,30 @@ else
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
# list of all files
fileList=$(git diff-index --name-only $against --)
unset badFiles
# called manually with arguments for the files/directories to be tested?
if [ "$#" -gt 0 ]
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
Indent=" "
@ -97,16 +121,18 @@ dieOnBadFiles()
#
checkIllegalCode()
{
echo "pre-commit: check bad strings/characters etc ..." 1>&2
reBad="(N""abla|"$'\t'")"
msgBad="N""abla or <TAB>"
badFiles=$(
for f in $fileList
do
# parse line numbers from this:
# path/fileName:<lineNr>: contents
lines=$(git grep --cached -n -E -e "$reBad" -- "$f" |
sed -e 's@^[^:]*:\([0-9]*\):.*@\1@' |
# parse line numbers from grep output:
# <lineNr>: contents
lines=$(git grep --cached -E -hn -e "$reBad" -- "$f" |
sed -e 's@:.*@@' |
tr '\n' ' '
)
[ -n "$lines" ] && echo "$Indent$f -- lines: $lines"
@ -123,18 +149,22 @@ checkIllegalCode()
checkCopyright()
{
year=$(date +%Y)
echo "pre-commit: check copyright ..." 1>&2
badFiles=$(
for f in $fileList
do
# parse line numbers from this:
# path/fileName:<lineNr>: contents
# for Copyright lines without the current year
lines=$(git grep --cached -n -e Copyright -- "$f" |
sed -n \
-e '/OpenCFD/{ ' \
-e "/$year/b" \
-e 's@^[^:]*:\([0-9]*\):.*@\1@p }' |
# NB: need to have OpenCFD on a separate line to prevent
# this check being caught by itself!
#
# parse line numbers from grep output:
# <lineNr>: contents
#
lines=$(git grep --cached -F -hn -e Copyright \
--and -e OpenCFD \
--and --not -e "$year" \
-- "$f" |
sed -e 's@:.*@@' |
tr '\n' ' '
)
[ -n "$lines" ] && echo "$Indent$f -- lines: $lines"
@ -150,16 +180,18 @@ checkCopyright()
#
checkLineLength()
{
echo "pre-commit: check line lengths ..." 1>&2
badFiles=$(
for f in $fileList
do
# limit to *.[CH] files
case "$f" in
(*.[CH])
# parse line numbers from this:
# path/fileName:<lineNr>: contents
lines=$(git grep --cached -n -e ".\{81,\}" -- "$f" |
sed -e 's@^[^:]*:\([0-9]*\):.*@\1@' |
# parse line numbers from grep output:
# <lineNr>: contents
lines=$(git grep --cached -hn -e '^.\{81,\}' -- "$f" |
sed -e 's@:.*@@' |
tr '\n' ' '
)
[ -n "$lines" ] && echo "$Indent$f -- lines: $lines"
@ -177,18 +209,20 @@ checkLineLength()
#
checkLineLengthNonComments()
{
echo "pre-commit: check line lengths ..." 1>&2
badFiles=$(
for f in $fileList
do
# limit to *.[CH] files
case "$f" in
(*.[CH])
# parse line numbers from this (strip comment lines):
# path/fileName:<lineNr>: contents
lines=$(git grep --cached -n -e ".\{81,\}" -- "$f" |
sed -n \
-e '\@^[^:]*:[^:]*: *//.*@b' \
-e 's@^[^:]*:\([0-9]*\):.*@\1@p' |
# parse line numbers from grep output:
# <lineNr>: contents
lines=$(git grep --cached -hn -e '^.\{81,\}' \
--and --not -e "^ *//" \
-- "$f" |
sed -e 's@:.*@@' |
tr '\n' ' '
)
[ -n "$lines" ] && echo "$Indent$f -- lines: $lines"
@ -205,18 +239,20 @@ checkLineLengthNonComments()
#
checkLineLengthNonDirective()
{
echo "pre-commit: check line lengths ..." 1>&2
badFiles=$(
for f in $fileList
do
# limit to *.[CH] files
case "$f" in
(*.[CH])
# parse line numbers from this (strip comment lines):
# path/fileName:<lineNr>: contents
lines=$(git grep --cached -n -e ".\{81,\}" -- "$f" |
sed -n \
-e '\@^[^:]*:[^:]*: *#.*@b' \
-e 's@^[^:]*:\([0-9]*\):.*@\1@p' |
# parse line numbers from grep output:
# <lineNr>: contents
lines=$(git grep --cached -hn -e '^.\{81,\}' \
--and --not -e "^ *#" \
-- "$f" |
sed -e 's@:.*@@' |
tr '\n' ' '
)
[ -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
# 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
# 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
# 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
# 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
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
{
return std::string::npos != find(str);

View File

@ -52,8 +52,8 @@ $(strings)/word/word.C
$(strings)/word/wordIO.C
$(strings)/fileName/fileName.C
$(strings)/fileName/fileNameIO.C
$(strings)/keyType/keyTypeIO.C
$(strings)/wordRe/wordReIO.C
$(strings)/keyType/keyType.C
$(strings)/wordRe/wordRe.C
primitives/hashes/Hasher/Hasher.C
@ -66,7 +66,8 @@ primitives/random/Random.C
containers/HashTables/HashTable/HashTableCore.C
containers/HashTables/StaticHashTable/StaticHashTableCore.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/LinkedLists/linkTypes/SLListBase/SLListBase.C
containers/LinkedLists/linkTypes/DLListBase/DLListBase.C
@ -329,7 +330,7 @@ $(cellShape)/cellShapeEqual.C
$(cellShape)/cellShapeIO.C
$(cellShape)/cellShapeIOList.C
meshes/patchIdentifier/patchIdentifier.C
meshes/Identifiers/patch/patchIdentifier.C
polyMesh = meshes/polyMesh

View File

@ -180,13 +180,22 @@ public:
// Member Operators
//- 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
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
inline void append(const UIndirectList<T>&);
inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& append
(
const UIndirectList<T>&
);
//- Remove and return the top element
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>
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
)
@ -314,11 +315,13 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::append
setSize(elemI + 1);
this->operator[](elemI) = t;
return *this;
}
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
)
@ -339,11 +342,13 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::append
{
this->operator[](nextFree++) = lst[elemI];
}
return *this;
}
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
)
@ -355,6 +360,7 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::append
{
this->operator[](nextFree++) = lst[elemI];
}
return *this;
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -25,7 +25,11 @@ Class
Foam::IndirectList
Description
A List with indirect addressing
A List with indirect addressing.
SeeAlso
Foam::UIndirectList for a version without any allocation for the
addressing.
SourceFiles
IndirectListI.H
@ -35,24 +39,79 @@ SourceFiles
#ifndef IndirectList_H
#define IndirectList_H
#include "List.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 IndirectList Declaration
\*---------------------------------------------------------------------------*/
template<class T>
class IndirectList
:
private IndirectListAddressing,
public UIndirectList<T>
{
// Private data
// Private Member Functions
UList<T>& completeList_;
List<label> addressing_;
//- Disable default assignment operator
void operator=(const IndirectList<T>&);
//- Disable assignment from UIndirectList
void operator=(const UIndirectList<T>&);
public:
@ -65,59 +124,32 @@ public:
//- Construct given the complete list and by transferring addressing
inline IndirectList(const UList<T>&, const Xfer<List<label> >&);
//- Copy constructor
inline IndirectList(const IndirectList<T>&);
//- Construct from UIndirectList
explicit inline IndirectList(const UIndirectList<T>&);
// Member Functions
// Access
//- Return the number of elements in the list
inline label size() const;
//- Return true if the list is empty (ie, size() is zero).
inline bool empty() const;
//- Return the first element of the list.
inline T& first();
//- Return first element of the list.
inline const T& first() const;
//- Return the last element of the list.
inline T& last();
//- Return the last element of the list.
inline const T& last() const;
//- Return the complete list
inline const UList<T>& completeList() const;
//- Return the list addressing
inline const List<label>& addressing() const;
using UIndirectList<T>::addressing;
// Edit
//- Reset addressing
inline void resetAddressing(const UList<label>&);
inline void resetAddressing(const Xfer<List<label> >&);
using IndirectListAddressing::resetAddressing;
// Member Operators
//- Return the addressed elements as a List
inline List<T> operator()() const;
//- Return non-const access to an element
inline T& operator[](const label);
//- Return const access to an element
inline const T& operator[](const label) const;
//- Assignment from UList of addressed elements
inline void operator=(const UList<T>&);
//- Assignment of all entries to the given value
inline void operator=(const T&);
//- Assignment operator
using UIndirectList<T>::operator=;
};

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -25,6 +25,25 @@ License
// * * * * * * * * * * * * * * * * 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::IndirectList<T>::IndirectList
(
@ -32,8 +51,12 @@ inline Foam::IndirectList<T>::IndirectList
const UList<label>& addr
)
:
completeList_(const_cast<UList<T>&>(completeList)),
addressing_(addr)
IndirectListAddressing(addr),
UIndirectList<T>
(
completeList,
IndirectListAddressing::addressing()
)
{}
@ -44,71 +67,55 @@ inline Foam::IndirectList<T>::IndirectList
const Xfer<List<label> >& addr
)
:
completeList_(const_cast<UList<T>&>(completeList)),
addressing_(addr)
IndirectListAddressing(addr),
UIndirectList<T>
(
completeList,
IndirectListAddressing::addressing()
)
{}
template<class T>
inline Foam::IndirectList<T>::IndirectList
(
const IndirectList<T>& lst
)
:
IndirectListAddressing(lst.addressing()),
UIndirectList<T>
(
lst.completeList(),
IndirectListAddressing::addressing()
)
{}
template<class T>
inline Foam::IndirectList<T>::IndirectList
(
const UIndirectList<T>& lst
)
:
IndirectListAddressing(lst.addressing()),
UIndirectList<T>
(
lst.completeList(),
IndirectListAddressing::addressing()
)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
inline Foam::label Foam::IndirectList<T>::size() const
{
return addressing_.size();
}
template<class T>
inline bool Foam::IndirectList<T>::empty() const
{
return addressing_.empty();
}
template<class T>
inline T& Foam::IndirectList<T>::first()
{
return completeList_[addressing_.first()];
}
template<class T>
inline const T& Foam::IndirectList<T>::first() const
{
return completeList_[addressing_.first()];
}
template<class T>
inline T& Foam::IndirectList<T>::last()
{
return completeList_[addressing_.last()];
}
template<class T>
inline const T& Foam::IndirectList<T>::last() const
{
return completeList_[addressing_.last()];
}
template<class T>
inline const Foam::UList<T>& Foam::IndirectList<T>::completeList() const
{
return completeList_;
}
template<class T>
inline const Foam::List<Foam::label>& Foam::IndirectList<T>::addressing() const
inline const Foam::List<Foam::label>&
Foam::IndirectListAddressing::addressing() const
{
return addressing_;
}
template<class T>
inline void Foam::IndirectList<T>::resetAddressing
inline void Foam::IndirectListAddressing::resetAddressing
(
const UList<label>& addr
)
@ -117,8 +124,7 @@ inline void Foam::IndirectList<T>::resetAddressing
}
template<class T>
inline void Foam::IndirectList<T>::resetAddressing
inline void Foam::IndirectListAddressing::resetAddressing
(
const Xfer<List<label> >& addr
)
@ -127,63 +133,4 @@ inline void Foam::IndirectList<T>::resetAddressing
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T>
inline Foam::List<T> Foam::IndirectList<T>::operator()() const
{
List<T> result(size());
forAll(*this, i)
{
result[i] = operator[](i);
}
return result;
}
template<class T>
inline T& Foam::IndirectList<T>::operator[](const label i)
{
return completeList_[addressing_[i]];
}
template<class T>
inline const T& Foam::IndirectList<T>::operator[](const label i) const
{
return completeList_[addressing_[i]];
}
template<class T>
inline void Foam::IndirectList<T>::operator=(const UList<T>& ae)
{
if (addressing_.size() != ae.size())
{
FatalErrorIn("IndirectList<T>::operator=(const UList<T>&)")
<< "Addressing and list of addressed elements "
"have different sizes: "
<< addressing_.size() << " " << ae.size()
<< abort(FatalError);
}
forAll(addressing_, i)
{
completeList_[addressing_[i]] = ae[i];
}
}
template<class T>
inline void Foam::IndirectList<T>::operator=(const T& t)
{
forAll(addressing_, i)
{
completeList_[addressing_[i]] = t;
}
}
// ************************************************************************* //

View File

@ -266,24 +266,6 @@ Foam::List<T>::List(const SLList<T>& lst)
}
// Construct as copy of IndirectList<T>
template<class T>
Foam::List<T>::List(const IndirectList<T>& lst)
:
UList<T>(NULL, lst.size())
{
if (this->size_)
{
this->v_ = new T[this->size_];
forAll(*this, i)
{
this->operator[](i) = lst[i];
}
}
}
// Construct as copy of UIndirectList<T>
template<class T>
Foam::List<T>::List(const UIndirectList<T>& lst)
@ -381,7 +363,7 @@ void Foam::List<T>::setSize(const label newSize)
template<class T>
void Foam::List<T>::setSize(const label newSize, const T& a)
{
label oldSize = this->size_;
label oldSize = label(this->size_);
this->setSize(newSize);
if (newSize > oldSize)
@ -517,25 +499,6 @@ void Foam::List<T>::operator=(const SLList<T>& lst)
}
// Assignment operator. Takes linear time.
template<class T>
void Foam::List<T>::operator=(const IndirectList<T>& lst)
{
if (lst.size() != this->size_)
{
if (this->v_) delete[] this->v_;
this->v_ = 0;
this->size_ = lst.size();
if (this->size_) this->v_ = new T[this->size_];
}
forAll(*this, i)
{
this->operator[](i) = lst[i];
}
}
// Assignment operator. Takes linear time.
template<class T>
void Foam::List<T>::operator=(const UIndirectList<T>& lst)

View File

@ -131,9 +131,6 @@ public:
//- Construct as copy of SLList<T>
explicit List(const SLList<T>&);
//- Construct as copy of IndirectList<T>
explicit List(const IndirectList<T>&);
//- Construct as copy of UIndirectList<T>
explicit List(const UIndirectList<T>&);
@ -219,9 +216,6 @@ public:
//- Assignment from SLList operator. Takes linear time.
void operator=(const SLList<T>&);
//- Assignment from IndirectList operator. Takes linear time.
void operator=(const IndirectList<T>&);
//- Assignment from UIndirectList operator. Takes linear time.
void operator=(const UIndirectList<T>&);

View File

@ -135,7 +135,7 @@ Foam::Istream& Foam::operator>>(Istream& is, List<T>& L)
<< exit(FatalIOError);
}
// Putback the openning bracket
// Putback the opening bracket
is.putBack(firstToken);
// 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,276 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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"
// * * * * * * * * * * * * * * * * 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]);
}
}
#include "IOstreams.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
#if (UINT_MAX == 0xFFFFFFFF)
// 32-bit counting, Hamming weight method
# define COUNT_PACKEDBITS(sum, x) \
@ -82,25 +58,10 @@ unsigned int Foam::PackedList<nBits>::count() const
if (size_)
{
// mask value for complete segments
unsigned int mask = maskLower(packing());
const unsigned int endSeg = size_ / packing();
const unsigned int endOff = size_ % packing();
// count bits in complete segments
for (unsigned i = 0; i < endSeg; ++i)
const label packLen = packedLength();
for (label i = 0; i < packLen; ++i)
{
register unsigned int bits = StorageList::operator[](i) & mask;
COUNT_PACKEDBITS(c, bits);
}
// count bits in partial segment
if (endOff)
{
mask = maskLower(endOff);
register unsigned int bits = StorageList::operator[](endSeg) & mask;
register unsigned int bits = StorageList::operator[](i);
COUNT_PACKEDBITS(c, bits);
}
}
@ -117,64 +78,60 @@ bool Foam::PackedList<nBits>::trim()
return false;
}
// mask value for complete segments
unsigned int mask = maskLower(packing());
label currElem = packedLength(size_) - 1;
unsigned int endOff = size_ % packing();
// clear trailing bits on final segment
if (endOff)
const label oldSize = size_;
for (label storeI = packedLength()-1; storeI >= 0; --storeI)
{
StorageList::operator[](currElem) &= maskLower(endOff);
size_ = storeI * packing();
unsigned int bits = StorageList::operator[](storeI);
// found some bits
if (bits)
{
while (bits)
{
bits >>= nBits;
++size_;
}
// test entire segment
while (currElem > 0 && !(StorageList::operator[](currElem) &= mask))
{
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)
{
break;
}
mask >>= nBits;
}
if (size_ == newsize)
{
return false;
}
size_ = newsize;
return false;
return (size_ != oldSize);
}
template<unsigned nBits>
void Foam::PackedList<nBits>::flip()
{
label packLen = packedLength(size_);
for (label i=0; i < packLen; i++)
if (!size_)
{
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>
Foam::labelList Foam::PackedList<nBits>::values() const
Foam::Xfer<Foam::labelList> Foam::PackedList<nBits>::values() const
{
labelList elems(size_);
@ -182,12 +139,16 @@ Foam::labelList Foam::PackedList<nBits>::values() const
{
elems[i] = get(i);
}
return elems;
return elems.xfer();
}
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) << "> ["
<< this->index_ << "]"
@ -201,44 +162,45 @@ Foam::Ostream& Foam::PackedList<nBits>::iteratorBase::print(Ostream& os) const
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_);
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";
const label packLen = packedLength();
// mask value for complete segments
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);
// 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
}
else if (i == packLen)
{
continue;
}
// no mask for unaddressed bit
mask = 0u;
}
for (unsigned int testBit = (1u << max_bits()); testBit; testBit >>= 1)
{
if (mask & testBit)
{
// addressable region
if (rawBits & testBit)
{
os << '1';
@ -250,7 +212,14 @@ Foam::Ostream& Foam::PackedList<nBits>::print(Ostream& os) const
}
else
{
os << 'x';
if (rawBits & testBit)
{
os << '!';
}
else
{
os << '.';
}
}
}
os << '\n';
@ -261,18 +230,313 @@ Foam::Ostream& Foam::PackedList<nBits>::print(Ostream& os) const
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<unsigned nBits>
void Foam::PackedList<nBits>::operator=(const PackedList<nBits>& lst)
Foam::Ostream& Foam::PackedList<nBits>::printInfo
(
Ostream& os,
const bool fullOutput
) const
{
StorageList::operator=(lst);
size_ = lst.size();
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>
void Foam::PackedList<nBits>::operator=(const UList<label>& lst)
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 * * * * * * * * * * * * * //
template<unsigned nBits>
Foam::PackedList<nBits>&
Foam::PackedList<nBits>::operator=(const PackedList<nBits>& lst)
{
StorageList::operator=(lst);
size_ = lst.size();
return *this;
}
template<unsigned nBits>
Foam::PackedList<nBits>&
Foam::PackedList<nBits>::operator=(const UList<label>& lst)
{
setCapacity(lst.size());
size_ = lst.size();
@ -281,19 +545,39 @@ void Foam::PackedList<nBits>::operator=(const UList<label>& lst)
{
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>
//Foam::Ostream& ::Foam::operator<<(Ostream& os, const PackedList<nBits>& lst)
//{
// os << lst();
// return os;
//}
forAll(lst, i)
{
set(i, lst[i]);
}
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;
@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
Foam::DynamicList
@ -85,6 +102,7 @@ SourceFiles
#define PackedList_H
#include "labelList.H"
#include "UIndirectList.H"
#include "StaticAssert.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -92,18 +110,34 @@ SourceFiles
namespace Foam
{
// Forward declaration of classes
class Istream;
class Ostream;
// Forward declaration of friend functions and operators
template<unsigned nBits> class PackedList;
// template<unsigned nBits>
// Ostream& operator<<(Ostream&, const PackedList<nBits>&);
template<unsigned 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
@ -112,25 +146,41 @@ TemplateName(PackedList);
template<unsigned nBits=1>
class PackedList
:
public PackedListCore,
private List<unsigned int>
{
protected:
typedef unsigned int StorageType;
typedef List<StorageType> StorageList;
//- nBits must be positive (non-zero) and fit within the storage
// For simplicity, assume 8-bit bytes
StaticAssert(nBits && nBits < (sizeof(StorageType) << 3));
// Protected Member Functions
//- 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
//- Number of nBits entries
label size_;
// Private Member Functions
//- Calculate the list length when packed
inline static label packedLength(const label);
public:
@ -163,20 +213,26 @@ public:
//- Null constructor
inline PackedList();
//- Construct with given size, initializes list to 0.
//- Construct with given size, initializes list to 0
explicit inline PackedList(const label size);
//- Construct with given size and value for all elements.
PackedList(const label size, const unsigned val);
//- Construct with given size and value for all elements
inline PackedList(const label size, const unsigned val);
//- Copy constructor.
//- Construct from Istream
inline PackedList(Istream&);
//- Copy constructor
inline PackedList(const PackedList<nBits>&);
//- Construct by transferring the parameter contents
inline PackedList(const Xfer<PackedList<nBits> >&);
//- 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
inline autoPtr< PackedList<nBits> > clone() const;
@ -209,30 +265,52 @@ public:
inline bool unset(const label);
//- Return the underlying packed storage
// Manipulate with utmost caution
inline List<unsigned int>& storage();
//- Return the underlying packed storage
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))
// Uses the Hamming weight (population count) method
// http://en.wikipedia.org/wiki/Hamming_weight
unsigned int count() const;
//- Return the values as a labelList
labelList values() const;
//- Return the values as a list of labels
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
//- Trim any trailing zero elements
bool trim();
//- Invert the bits in the addressable region.
//- Invert the bits in the addressable region
void flip();
//- Clear all bits
inline void reset();
//- Alter the size of the underlying storage.
// The addressed size will be truncated if needed to fit, but will
// remain otherwise untouched.
@ -240,10 +318,10 @@ public:
//- Reset addressable list size, does not shrink the allocated size.
// 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()
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.
// Never shrinks the allocated size.
@ -269,10 +347,43 @@ public:
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
//- 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
inline unsigned int remove();
@ -287,23 +398,16 @@ public:
inline iteratorBase operator[](const label);
//- 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.
void operator=(const PackedList<nBits>&);
//- Assignment operator.
PackedList<nBits>& operator=(const PackedList<nBits>&);
//- Assignment operator. Takes linear time.
void operator=(const UList<label>&);
//- Assignment operator.
PackedList<nBits>& operator=(const UList<label>&);
// Ostream operator
// // Write PackedList to Ostream.
// friend Ostream& operator<< <nBits>
// (
// Ostream&,
// const PackedList<nBits>&
// );
//- Assignment operator.
PackedList<nBits>& operator=(const UIndirectList<label>&);
// Iterators and helpers
@ -347,6 +451,15 @@ 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
//- Compare values (not positions)
@ -365,8 +478,8 @@ public:
// Never auto-vivify entries.
inline operator unsigned int () const;
//- Print value and information
Ostream& print(Ostream&) const;
//- Print information and values
Ostream& printInfo(Ostream&) const;
};
@ -376,11 +489,12 @@ public:
public iteratorBase
{
//- Disallow copy constructor from const_iterator -
// violates const-ness!
//- Disallow copy constructor from const_iterator
// This would violate const-ness!
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&);
@ -497,6 +611,20 @@ public:
//- const_iterator set to beyond the end of the PackedList
inline const_iterator end() const;
// IOstream Operators
friend Istream& operator>> <nBits>
(
Istream&,
PackedList<nBits>&
);
friend Ostream& operator<< <nBits>
(
Ostream&,
const PackedList<nBits>&
);
};

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -27,6 +27,7 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(Foam::PackedListName, 0);
defineTypeNameAndDebug(Foam::PackedListCore, 0);
// ************************************************************************* //

View File

@ -21,7 +21,6 @@ License
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "error.H"
@ -67,11 +66,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 * * * * * * * * * * * * * * //
template<unsigned nBits>
inline Foam::PackedList<nBits>::PackedList()
:
PackedListCore(),
StorageList(),
size_(0)
{}
@ -80,14 +185,45 @@ inline Foam::PackedList<nBits>::PackedList()
template<unsigned nBits>
inline Foam::PackedList<nBits>::PackedList(const label size)
:
PackedListCore(),
StorageList(packedLength(size), 0u),
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>
inline Foam::PackedList<nBits>::PackedList(const PackedList<nBits>& lst)
:
PackedListCore(),
StorageList(lst),
size_(lst.size_)
{}
@ -100,6 +236,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>
inline Foam::autoPtr<Foam::PackedList<nBits> >
Foam::PackedList<nBits>::clone() const
@ -151,27 +315,34 @@ Foam::PackedList<nBits>::iteratorBase::set(const unsigned int val)
const unsigned int seg = 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);
const unsigned int prev = stored;
const unsigned int startBit = nBits * off;
const unsigned int maskNew = max_value() << startBit;
if (val & ~max_value())
if (val >= max_value())
{
// overflow is max_value, fill everything
stored |= maskNew;
stored |= mask;
}
else
{
stored &= ~maskNew;
stored |= maskNew & (val << startBit);
stored &= ~mask;
stored |= mask & (val << startBit);
}
return prev != stored;
}
template<unsigned nBits>
inline Foam::label Foam::PackedList<nBits>::iteratorBase::key() const
{
return index_;
}
template<unsigned nBits>
inline bool Foam::PackedList<nBits>::iteratorBase::operator==
(
@ -564,24 +735,27 @@ inline bool Foam::PackedList<nBits>::empty() const
template<unsigned nBits>
inline void Foam::PackedList<nBits>::resize
(
const label nElem,
const label newSize,
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
if (size_)
if (val)
{
// fill value for complete segments
unsigned int fill = val;
if (fill & ~max_value())
if (val >= max_value())
{
// overflow is max_value, fill everything
fill = ~0u;
// fill everything
fill = maskLower(packing());
}
else
{
@ -591,36 +765,64 @@ inline void Foam::PackedList<nBits>::resize
}
}
unsigned int seg = size_ / packing();
unsigned int off = size_ % packing();
// fill in complete segments
const label oldLen = packedLength(oldSize);
const label newLen = packedLength(size_);
for (label i=oldLen; i < newLen; ++i)
{
StorageList::operator[](i) = fill;
}
// partial segment, preserve existing value
// finish previous partial segment, preserve existing value
{
const unsigned int off = oldSize % packing();
if (off)
{
unsigned int maskOld = maskLower(off);
const unsigned int seg = oldSize / packing();
const unsigned int mask = maskLower(off);
StorageList::operator[](seg) &= maskOld;
StorageList::operator[](seg) |= ~maskOld & fill;
// continue with the next segment
seg++;
StorageList::operator[](seg) &= mask;
StorageList::operator[](seg) |= ~mask & fill;
}
}
unsigned int endSeg = nElem / packing();
// fill in complete elements
while (seg < endSeg)
// mask off the (new) final partial segment
{
StorageList::operator[](seg++) = fill;
}
}
else
const unsigned int off = size_ % packing();
if (off)
{
// no original size - simply flood-fill
operator=(val);
const unsigned int seg = size_ / packing();
StorageList::operator[](seg) &= maskLower(off);
}
}
}
}
else if (size_ < oldSize)
{
// resize shrinking
// - clear newly exposed elements
// 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;
}
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);
}
}
}
}
@ -648,21 +850,27 @@ inline void Foam::PackedList<nBits>::setCapacity(const label nElem)
{
StorageList::setSize(packedLength(nElem), 0u);
// truncate addressed size too?
// truncate addressed size too
if (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>
inline void Foam::PackedList<nBits>::reserve
(
const label nElem
)
inline void Foam::PackedList<nBits>::reserve(const label nElem)
{
label len = packedLength(nElem);
const label len = packedLength(nElem);
// need more capacity?
if (len > StorageList::size())
@ -681,9 +889,17 @@ inline void Foam::PackedList<nBits>::reserve
}
template<unsigned nBits>
inline void Foam::PackedList<nBits>::reset()
{
StorageList::operator=(0u);
}
template<unsigned nBits>
inline void Foam::PackedList<nBits>::clear()
{
reset();
size_ = 0;
}
@ -699,9 +915,8 @@ inline void Foam::PackedList<nBits>::clearStorage()
template<unsigned nBits>
inline void Foam::PackedList<nBits>::shrink()
{
label len = packedLength(size_);
// we have unused space?
// any uneed space allocated?
const label len = packedLength();
if (len < StorageList::size())
{
StorageList::setSize(len);
@ -722,6 +937,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>
inline void Foam::PackedList<nBits>::transfer(PackedList<nBits>& lst)
{
@ -742,23 +971,14 @@ inline Foam::Xfer<Foam::PackedList<nBits> > Foam::PackedList<nBits>::xfer()
template<unsigned nBits>
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
if (i < size_)
if (i < 0 || i >= size_)
{
return iteratorBase(this, i).get();
return 0;
}
else
{
return 0;
return iteratorBase(this, i).get();
}
}
@ -767,13 +987,13 @@ template<unsigned nBits>
inline unsigned int Foam::PackedList<nBits>::operator[](const label i) const
{
// lazy evaluation - return 0 for out-of-range
if (i < size_)
if (i < 0 || i >= size_)
{
return iteratorBase(this, i).get();
return 0;
}
else
{
return 0;
return iteratorBase(this, i).get();
}
}
@ -785,18 +1005,14 @@ inline bool Foam::PackedList<nBits>::set
const unsigned int val
)
{
# ifdef FULLDEBUG
if (i < 0)
{
FatalErrorIn("PackedList<nBits>::set(const label)")
<< "negative index " << i << " max=" << size_-1
<< abort(FatalError);
// lazy evaluation - ignore out-of-bounds
return false;
}
# endif
// lazy evaluation - increase size on assigment
if (i >= size_)
else if (i >= size_)
{
// lazy evaluation - increase size on assigment
resize(i + 1);
}
@ -807,24 +1023,28 @@ inline bool Foam::PackedList<nBits>::set
template<unsigned nBits>
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_)
{
return false;
}
else
{
return iteratorBase(this, i).set(0u);
}
}
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);
size_++;
iteratorBase(this, elemI).set(val);
return *this;
}
@ -855,35 +1075,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>
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;
if (fill & ~max_value())
if (val >= max_value())
{
// treat overflow as max_value
fill = ~0u;
// fill everything
fill = maskLower(packing());
}
else
{
@ -893,13 +1098,32 @@ 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
{
StorageList::operator=(0u);
for (label i=0; i < packLen; ++i)
{
StorageList::operator[](i) = 0u;
}
}
return *this;
}
// ************************************************************************* //

View File

@ -23,13 +23,13 @@ License
\*---------------------------------------------------------------------------*/
#include "IOFieldField.H"
#include "CompactIOField.H"
#include "labelList.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class T, class BaseType>
void Foam::IOFieldField<T, BaseType>::readFromStream()
void Foam::CompactIOField<T, BaseType>::readFromStream()
{
Istream& is = readStream(word::null);
@ -47,7 +47,7 @@ void Foam::IOFieldField<T, BaseType>::readFromStream()
{
FatalIOErrorIn
(
"IOFieldField<T, BaseType>::readFromStream()",
"CompactIOField<T, BaseType>::readFromStream()",
is
) << "unexpected class name " << headerClassName()
<< " expected " << typeName << " or " << IOField<T>::typeName
@ -61,7 +61,7 @@ void Foam::IOFieldField<T, BaseType>::readFromStream()
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
template<class T, class BaseType>
Foam::IOFieldField<T, BaseType>::IOFieldField(const IOobject& io)
Foam::CompactIOField<T, BaseType>::CompactIOField(const IOobject& io)
:
regIOobject(io)
{
@ -77,7 +77,7 @@ Foam::IOFieldField<T, BaseType>::IOFieldField(const IOobject& io)
template<class T, class BaseType>
Foam::IOFieldField<T, BaseType>::IOFieldField
Foam::CompactIOField<T, BaseType>::CompactIOField
(
const IOobject& io,
const label size
@ -101,7 +101,7 @@ Foam::IOFieldField<T, BaseType>::IOFieldField
template<class T, class BaseType>
Foam::IOFieldField<T, BaseType>::IOFieldField
Foam::CompactIOField<T, BaseType>::CompactIOField
(
const IOobject& io,
const Field<T>& list
@ -125,7 +125,7 @@ Foam::IOFieldField<T, BaseType>::IOFieldField
template<class T, class BaseType>
Foam::IOFieldField<T, BaseType>::IOFieldField
Foam::CompactIOField<T, BaseType>::CompactIOField
(
const IOobject& io,
const Xfer<Field<T> >& list
@ -149,7 +149,7 @@ Foam::IOFieldField<T, BaseType>::IOFieldField
// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
template<class T, class BaseType>
Foam::IOFieldField<T, BaseType>::~IOFieldField()
Foam::CompactIOField<T, BaseType>::~CompactIOField()
{}
@ -157,7 +157,7 @@ Foam::IOFieldField<T, BaseType>::~IOFieldField()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T, class BaseType>
bool Foam::IOFieldField<T, BaseType>::writeObject
bool Foam::CompactIOField<T, BaseType>::writeObject
(
IOstream::streamFormat fmt,
IOstream::versionNumber ver,
@ -186,7 +186,7 @@ bool Foam::IOFieldField<T, BaseType>::writeObject
template<class T, class BaseType>
bool Foam::IOFieldField<T, BaseType>::writeData(Ostream& os) const
bool Foam::CompactIOField<T, BaseType>::writeData(Ostream& os) const
{
return (os << *this).good();
}
@ -195,9 +195,9 @@ bool Foam::IOFieldField<T, BaseType>::writeData(Ostream& os) const
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T, class BaseType>
void Foam::IOFieldField<T, BaseType>::operator=
void Foam::CompactIOField<T, BaseType>::operator=
(
const IOFieldField<T, BaseType>& rhs
const CompactIOField<T, BaseType>& rhs
)
{
Field<T>::operator=(rhs);
@ -205,7 +205,7 @@ void Foam::IOFieldField<T, BaseType>::operator=
template<class T, class BaseType>
void Foam::IOFieldField<T, BaseType>::operator=(const Field<T>& rhs)
void Foam::CompactIOField<T, BaseType>::operator=(const Field<T>& rhs)
{
Field<T>::operator=(rhs);
}
@ -217,7 +217,7 @@ template<class T, class BaseType>
Foam::Istream& Foam::operator>>
(
Foam::Istream& is,
Foam::IOFieldField<T, BaseType>& L
Foam::CompactIOField<T, BaseType>& L
)
{
// Read compact
@ -248,7 +248,7 @@ template<class T, class BaseType>
Foam::Ostream& Foam::operator<<
(
Foam::Ostream& os,
const Foam::IOFieldField<T, BaseType>& L
const Foam::CompactIOField<T, BaseType>& L
)
{
// Keep ascii writing same.

View File

@ -22,18 +22,22 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::IOFieldField
Foam::CompactIOField
Description
A Field of objects of type \<T\> with automated input and output.
A Field of objects of type \<T\> with automated input and output using
a compact storage. Behaves like IOField except when binary output in
case it writes a CompactListList.
Useful for fields of small subfields e.g. in lagrangian
SourceFiles
IOFieldField.C
CompactIOField.C
\*---------------------------------------------------------------------------*/
#ifndef IOFieldField_H
#define IOFieldField_H
#ifndef CompactIOField_H
#define CompactIOField_H
#include "IOField.H"
#include "regIOobject.H"
@ -47,25 +51,25 @@ class Istream;
class Ostream;
// Forward declaration of friend functions and operators
template<class T, class BaseType> class IOFieldField;
template<class T, class BaseType> class CompactIOField;
template<class T, class BaseType> Istream& operator>>
(
Istream&,
IOFieldField<T, BaseType>&
CompactIOField<T, BaseType>&
);
template<class T, class BaseType> Ostream& operator<<
(
Ostream&,
const IOFieldField<T, BaseType>&
const CompactIOField<T, BaseType>&
);
/*---------------------------------------------------------------------------*\
Class IOFieldField Declaration
Class CompactIOField Declaration
\*---------------------------------------------------------------------------*/
template<class T, class BaseType>
class IOFieldField
class CompactIOField
:
public regIOobject,
public Field<T>
@ -84,21 +88,21 @@ public:
// Constructors
//- Construct from IOobject
IOFieldField(const IOobject&);
CompactIOField(const IOobject&);
//- Construct from IOobject and size of IOFieldField
IOFieldField(const IOobject&, const label);
//- Construct from IOobject and size
CompactIOField(const IOobject&, const label);
//- Construct from IOobject and a Field
IOFieldField(const IOobject&, const Field<T>&);
CompactIOField(const IOobject&, const Field<T>&);
//- Construct by transferring the Field contents
IOFieldField(const IOobject&, const Xfer<Field<T> >&);
CompactIOField(const IOobject&, const Xfer<Field<T> >&);
// Destructor
virtual ~IOFieldField();
virtual ~CompactIOField();
// Member functions
@ -115,7 +119,7 @@ public:
// Member operators
void operator=(const IOFieldField<T, BaseType>&);
void operator=(const CompactIOField<T, BaseType>&);
void operator=(const Field<T>&);
@ -126,14 +130,14 @@ public:
friend Istream& operator>> <T, BaseType>
(
Istream&,
IOFieldField<T, BaseType>&
CompactIOField<T, BaseType>&
);
// Write Field to Ostream.
friend Ostream& operator<< <T, BaseType>
(
Ostream&,
const IOFieldField<T, BaseType>&
const CompactIOField<T, BaseType>&
);
};
@ -145,7 +149,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "IOFieldField.C"
# include "CompactIOField.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

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

View File

@ -41,8 +41,8 @@ namespace Foam
defineTemplateTypeNameAndDebugWithName
(
diagTensorIOFieldField,
"diagTensorCompactFieldField",
diagTensorFieldCompactIOField,
"diagTensorFieldCompactField",
0
);
}

View File

@ -33,15 +33,15 @@ Description
#define diagTensorFieldIOField_H
#include "diagTensorField.H"
#include "IOField.H"
#include "IOFieldField.H"
#include "CompactIOField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef IOField<diagTensorField> diagTensorFieldIOField;
typedef IOFieldField<diagTensorField, diagTensor> diagTensorIOFieldField;
typedef CompactIOField<diagTensorField, diagTensor>
diagTensorFieldCompactIOField;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -41,8 +41,8 @@ namespace Foam
defineTemplateTypeNameAndDebugWithName
(
labelIOFieldField,
"labelCompactFieldField",
labelFieldCompactIOField,
"labelFieldCompactField",
0
);
}

View File

@ -34,14 +34,14 @@ Description
#include "labelField.H"
#include "IOField.H"
#include "IOFieldField.H"
#include "CompactIOField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef IOField<labelField> labelFieldIOField;
typedef IOFieldField<labelField, label> labelIOFieldField;
typedef CompactIOField<labelField, label> labelFieldCompactIOField;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -41,8 +41,8 @@ namespace Foam
defineTemplateTypeNameAndDebugWithName
(
scalarIOFieldField,
"scalarCompactFieldField",
scalarFieldCompactIOField,
"scalarFieldCompactField",
0
);
}

View File

@ -33,15 +33,14 @@ Description
#define scalarFieldIOField_H
#include "scalarField.H"
#include "IOField.H"
#include "IOFieldField.H"
#include "CompactIOField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef IOField<scalarField> scalarFieldIOField;
typedef IOFieldField<scalarField, scalar> scalarIOFieldField;
typedef CompactIOField<scalarField, scalar> scalarFieldCompactIOField;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -41,8 +41,8 @@ namespace Foam
defineTemplateTypeNameAndDebugWithName
(
sphericalTensorIOFieldField,
"sphericalTensorCompactFieldField",
sphericalTensorFieldCompactIOField,
"sphericalTensorFieldCompactField",
0
);
}

View File

@ -33,8 +33,7 @@ Description
#define sphericalTensorFieldIOField_H
#include "sphericalTensorField.H"
#include "IOField.H"
#include "IOFieldField.H"
#include "CompactIOField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -42,8 +41,8 @@ namespace Foam
{
typedef IOField<sphericalTensorField> sphericalTensorFieldIOField;
typedef IOFieldField<sphericalTensorField, sphericalTensor>
sphericalTensorIOFieldField;
typedef CompactIOField<sphericalTensorField, sphericalTensor>
sphericalTensorFieldCompactIOField;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -41,8 +41,8 @@ namespace Foam
defineTemplateTypeNameAndDebugWithName
(
symmTensorIOFieldField,
"symmTensorCompactFieldField",
symmTensorFieldCompactIOField,
"symmTensorFieldCompactField",
0
);
}

View File

@ -33,15 +33,15 @@ Description
#define symmTensorFieldIOField_H
#include "symmTensorField.H"
#include "IOField.H"
#include "IOFieldField.H"
#include "CompactIOField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef IOField<symmTensorField> symmTensorFieldIOField;
typedef IOFieldField<symmTensorField, symmTensor> symmTensorIOFieldField;
typedef CompactIOField<symmTensorField, symmTensor>
symmTensorFieldCompactIOField;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -41,8 +41,8 @@ namespace Foam
defineTemplateTypeNameAndDebugWithName
(
tensorIOFieldField,
"tensorCompactFieldField",
tensorFieldCompactIOField,
"tensorFieldCompactField",
0
);
}

View File

@ -33,15 +33,14 @@ Description
#define tensorFieldIOField_H
#include "tensorField.H"
#include "IOField.H"
#include "IOFieldField.H"
#include "CompactIOField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef IOField<tensorField> tensorFieldIOField;
typedef IOFieldField<tensorField, tensor> tensorIOFieldField;
typedef CompactIOField<tensorField, tensor> tensorFieldCompactIOField;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -41,8 +41,8 @@ namespace Foam
defineTemplateTypeNameAndDebugWithName
(
vector2DIOFieldField,
"vector2DCompactFieldField",
vector2DFieldCompactIOField,
"vector2DFieldCompactField",
0
);
}

View File

@ -33,15 +33,14 @@ Description
#define vector2DFieldIOField_H
#include "vector2DField.H"
#include "IOField.H"
#include "IOFieldField.H"
#include "CompactIOField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef IOField<vector2DField> vector2DFieldIOField;
typedef IOFieldField<vector2DField, vector2D> vector2DIOFieldField;
typedef CompactIOField<vector2DField, vector2D> vector2DFieldCompactIOField;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -41,8 +41,8 @@ namespace Foam
defineTemplateTypeNameAndDebugWithName
(
vectorIOFieldField,
"vectorCompactFieldField",
vectorFieldCompactIOField,
"vectorFieldCompactField",
0
);
}

View File

@ -33,15 +33,14 @@ Description
#define vectorFieldIOField_H
#include "vectorField.H"
#include "IOField.H"
#include "IOFieldField.H"
#include "CompactIOField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef IOField<vectorField> vectorFieldIOField;
typedef IOFieldField<vectorField, vector> vectorIOFieldField;
typedef CompactIOField<vectorField, vector> vectorFieldCompactIOField;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

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

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -21,25 +21,20 @@ License
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Typedef
Foam::PackedBoolList
Description
A bit-packed bool list
\*---------------------------------------------------------------------------*/
#ifndef PackedBoolList_H
#define PackedBoolList_H
#ifndef polyPatchID_H
#define polyPatchID_H
#include "bool.H"
#include "PackedList.H"
#include "DynamicID.H"
#include "polyBoundaryMesh.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
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
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -26,21 +26,26 @@ License
#ifndef ZoneIDs_H
#define ZoneIDs_H
#include "ZoneID.H"
#include "pointZone.H"
#include "faceZone.H"
#include "cellZone.H"
#include "DynamicID.H"
#include "cellZoneMeshFwd.H"
#include "faceZoneMeshFwd.H"
#include "pointZoneMeshFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
//- Foam::pointZoneID
typedef ZoneID<pointZone> pointZoneID;
//- Foam::faceZoneID
typedef ZoneID<faceZone> faceZoneID;
//- 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 "lduSchedule.H"
#include "globalMeshData.H"
#include "stringListOps.H"
// * * * * * * * * * * * * * * 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
{
const polyPatchList& patches = *this;
@ -444,7 +505,11 @@ Foam::label Foam::polyBoundaryMesh::whichPatch(const label faceIndex) const
// with patch start labels.
// If the face is internal, return -1;
// 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
(
@ -453,10 +518,6 @@ Foam::label Foam::polyBoundaryMesh::whichPatch(const label faceIndex) const
<< abort(FatalError);
}
if (faceIndex < mesh().nInternalFaces())
{
return -1;
}
forAll(*this, patchI)
{
@ -578,7 +639,7 @@ bool Foam::polyBoundaryMesh::checkParallelSync(const bool report) const
// 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
(

View File

@ -38,6 +38,7 @@ SourceFiles
#include "polyPatchList.H"
#include "regIOobject.H"
#include "labelPair.H"
#include "HashSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -151,6 +152,12 @@ public:
//- Return a list of physical types
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
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,6 +250,9 @@ Foam::labelList Foam::ZoneMesh<ZoneType, MeshType>::findIndices
) const
{
labelList indices;
if (!key.empty())
{
if (key.isPattern())
{
indices = findStrings(key, this->names());
@ -267,6 +270,7 @@ Foam::labelList Foam::ZoneMesh<ZoneType, MeshType>::findIndices
}
indices.setSize(nFound);
}
}
return indices;
}
@ -277,10 +281,13 @@ Foam::label Foam::ZoneMesh<ZoneType, MeshType>::findIndex
(
const keyType& key
) const
{
if (!key.empty())
{
if (key.isPattern())
{
labelList indices = this->findIndices(key);
// return first element
if (!indices.empty())
{
@ -297,6 +304,7 @@ Foam::label Foam::ZoneMesh<ZoneType, MeshType>::findIndex
}
}
}
}
// not found
return -1;
@ -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>
void Foam::ZoneMesh<ZoneType, MeshType>::clearAddressing()
{

View File

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

View File

@ -47,7 +47,7 @@ const char * const Foam::cellZone::labelsName = "cellLabels";
Foam::cellZone::cellZone
(
const word& name,
const labelList& addr,
const unallocLabelList& addr,
const label index,
const cellZoneMesh& zm
)
@ -86,7 +86,7 @@ Foam::cellZone::cellZone
Foam::cellZone::cellZone
(
const cellZone& cz,
const labelList& addr,
const unallocLabelList& addr,
const label index,
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();
labelList::operator=(addr);

View File

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

View File

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

View File

@ -154,7 +154,7 @@ public:
faceZone
(
const word& name,
const labelList& addr,
const unallocLabelList& addr,
const boolList& fm,
const label index,
const faceZoneMesh& zm
@ -184,7 +184,7 @@ public:
faceZone
(
const faceZone&,
const labelList& addr,
const unallocLabelList& addr,
const boolList& fm,
const label index,
const faceZoneMesh&
@ -214,7 +214,7 @@ public:
// and zone mesh
virtual autoPtr<faceZone> clone
(
const labelList& addr,
const unallocLabelList& addr,
const boolList& fm,
const label index,
const faceZoneMesh& zm
@ -279,7 +279,7 @@ public:
virtual void clearAddressing();
//- 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.
virtual bool checkDefinition(const bool report = false) const;

View File

@ -47,7 +47,7 @@ const char* const Foam::pointZone::labelsName = "pointLabels";
Foam::pointZone::pointZone
(
const word& name,
const labelList& addr,
const unallocLabelList& addr,
const label index,
const pointZoneMesh& zm
)
@ -86,7 +86,7 @@ Foam::pointZone::pointZone
Foam::pointZone::pointZone
(
const pointZone& pz,
const labelList& addr,
const unallocLabelList& addr,
const label index,
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();
labelList::operator=(addr);

View File

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

View File

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

View File

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

View File

@ -37,6 +37,7 @@ const char* Foam::Switch::names[Foam::Switch::INVALID+1] =
"off", "on",
"no", "yes",
"n", "y",
"f", "t",
"none", "true", // is there a reasonable counterpart to "none"?
"invalid"
};
@ -54,18 +55,39 @@ Foam::Switch::switchType Foam::Switch::asEnum
{
if (str == names[sw])
{
// convert n/y to no/yes - perhaps should deprecate y/n
if (sw == Switch::NO_1 || sw == Switch::NONE)
// handle aliases
switch (sw)
{
case Switch::NO_1:
case Switch::NONE:
{
return Switch::NO;
break;
}
else if (sw == Switch::YES_1)
case Switch::YES_1:
{
return Switch::YES;
break;
}
else
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
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
Switch.C
@ -78,6 +78,8 @@ public:
#undef YES
#undef NO_1
#undef YES_1
#undef FALSE_1
#undef TRUE_1
#undef NONE
#undef PLACEHOLDER
#undef INVALID
@ -90,7 +92,8 @@ public:
OFF = 2, ON = 3,
NO = 4, YES = 5,
NO_1 = 6, YES_1 = 7,
NONE = 8, PLACEHOLDER = 9,
FALSE_1 = 8, TRUE_1 = 9,
NONE = 10, PLACEHOLDER = 11,
INVALID
};

View File

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

View File

@ -22,24 +22,54 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
Istream constructor and IOstream operators for word.
Istream constructor and IOstream operators for keyType.
\*---------------------------------------------------------------------------*/
#include "keyType.H"
#include "regExp.H"
#include "IOstreams.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::keyType Foam::keyType::null;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::keyType::keyType(Istream& is)
:
word()
word(),
isPattern_(false)
{
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);
@ -51,15 +81,16 @@ Foam::Istream& Foam::operator>>(Istream& is, keyType& w)
if (t.isWord())
{
w = t.wordToken();
kw = t.wordToken();
}
else if (t.isString())
{
// Assign from string. Sets regular expression.
w = t.stringToken();
// Assign from string. Set as regular expression.
kw = t.stringToken();
kw.isPattern_ = true;
// flag empty strings as an error
if (w.empty())
if (kw.empty())
{
is.setBad();
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&)");
return os;
}

View File

@ -32,7 +32,6 @@ Description
SourceFiles
keyType.C
keyTypeIO.C
\*---------------------------------------------------------------------------*/
@ -59,7 +58,7 @@ class keyType
:
public word
{
// Private member data
// Private data
//- Is the keyType a pattern (regular expression)
bool isPattern_;
@ -71,6 +70,11 @@ class keyType
public:
// Static data members
//- An empty keyType
static const keyType null;
// Constructors
@ -80,19 +84,21 @@ public:
//- Construct as copy
inline keyType(const keyType&);
//- Construct as copy of word
//- Construct as copy of word. Not treated as a regular expression
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&);
//- Construct as copy of character array
//- Construct as copy of character array.
// Not treated as a regular expression
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);
//- Construct from Istream
// Treat as regular expression if surrounded by quotation marks.
keyType(Istream&);
@ -101,15 +107,24 @@ public:
//- Should be treated as a match rather than a literal string
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
// Assignment
//- Assignment operator
inline const keyType& operator=(const keyType&);
//- Assign as word, not as non regular expression
inline const keyType& operator=(const word&);
//- Assign from regular expression.
//- Assign as regular expression
inline const keyType& operator=(const string&);
//- Assign as word, not as non regular expression
inline const keyType& operator=(const char*);

View File

@ -23,10 +23,6 @@ License
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
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)
:
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)
:
word(s, false),
@ -66,7 +60,6 @@ inline Foam::keyType::keyType(const char* s)
{}
//- Construct as copy of std::string
inline Foam::keyType::keyType
(
const std::string& s,

View File

@ -82,6 +82,8 @@ public:
static const char* const typeName;
static int debug;
//- An empty string
static const string null;
@ -143,6 +145,9 @@ public:
template<class String>
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
using std::string::replace;

View File

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

Some files were not shown because too many files have changed in this diff Show More