Merge branch 'develop' of develop.openfoam.com:Development/OpenFOAM-plus into develop

This commit is contained in:
Andrew Heather
2017-05-18 12:41:07 +01:00
99 changed files with 2250 additions and 1302 deletions

View File

@ -56,7 +56,6 @@ int main(int argc, char *argv[])
Info<< "element:" << *iter << endl; Info<< "element:" << *iter << endl;
} }
Info<< nl << "And again using the same STL iterator: " << nl << endl; Info<< nl << "And again using the same STL iterator: " << nl << endl;
forAllIters(myList, iter) forAllIters(myList, iter)

View File

@ -36,14 +36,9 @@ void printTable(const HashPtrTable<T>& table)
{ {
Info<< table.size() << nl << "(" << nl; Info<< table.size() << nl << "(" << nl;
for forAllConstIters(table, iter)
(
typename HashPtrTable<T>::const_iterator iter = table.cbegin();
iter != table.cend();
++iter
)
{ {
const T* ptr = *iter; const T* ptr = iter.object();
Info<< iter.key() << " = "; Info<< iter.key() << " = ";
if (ptr) if (ptr)
{ {
@ -57,6 +52,22 @@ void printTable(const HashPtrTable<T>& table)
} }
Info<< ")" << endl; Info<< ")" << endl;
// Values only, with for-range
Info<< "values (";
for (auto val : table)
{
Info<< ' ';
if (val)
{
Info<< *val;
}
else
{
Info<< "nullptr";
}
}
Info<< " )" << nl;
} }
@ -68,7 +79,9 @@ int main()
HashPtrTable<double> myTable; HashPtrTable<double> myTable;
myTable.insert("abc", new double(42.1)); myTable.insert("abc", new double(42.1));
myTable.insert("def", nullptr); myTable.insert("def", nullptr);
myTable.insert("ghi", new double(3.14159)); myTable.insert("pi", new double(3.14159));
myTable.insert("natlog", new double(2.718282));
myTable.insert("sqrt2", new double(1.414214));
// Info<< myTable << endl; // Info<< myTable << endl;
printTable(myTable); printTable(myTable);
@ -79,8 +92,20 @@ int main()
printTable(copy); printTable(copy);
Info<< copy << endl; Info<< copy << endl;
Info<<"\nerase some existing and non-existing entries" << nl;
auto iter = myTable.find("pi");
myTable.erase(iter);
iter = myTable.find("unknownKey");
myTable.erase(iter);
myTable.erase("abc");
myTable.erase("unknownKey");
printTable(myTable);
return 0; return 0;
} }
// ************************************************************************* // // ************************************************************************* //

View File

@ -197,8 +197,12 @@ int main(int argc, char *argv[])
Info<< "setD has no 11" << endl; Info<< "setD has no 11" << endl;
} }
Info<< "setB : " << flatOutput(setB) << endl;
Info<< "setD : " << flatOutput(setD) << endl; Info<< "setD : " << flatOutput(setD) << endl;
setD -= setB;
Info<< "setD -= setB : " << flatOutput(setD) << endl;
// This should not work (yet?) // This should not work (yet?)
// setD[12] = true; // setD[12] = true;

View File

@ -25,6 +25,9 @@ License
#include "HashTable.H" #include "HashTable.H"
#include "List.H" #include "List.H"
#include "SortableList.H"
#include "DynamicList.H"
#include "FlatOutput.H"
#include "IOstreams.H" #include "IOstreams.H"
#include "IStringStream.H" #include "IStringStream.H"
#include "OStringStream.H" #include "OStringStream.H"
@ -163,15 +166,15 @@ int main()
<< "\ntable2" << table2 << nl; << "\ntable2" << table2 << nl;
Info<< "\ntable3" << table3 Info<< "\ntable3" << table2
<< "\nclearStorage table3 ... "; << "\nclearStorage table2 ... ";
table3.clearStorage(); table2.clearStorage();
Info<< table3 << nl; Info<< table2 << nl;
table1 = table1 =
{ {
{"aca", 3.0}, {"abc", 3.0},
{"aaw", 6.0}, {"def", 6.0},
{"acr", 8.0}, {"acr", 8.0},
{"aec", 10.0} {"aec", 10.0}
}; };
@ -193,7 +196,43 @@ int main()
// These do not yet work. Issues resolving the distance. // These do not yet work. Issues resolving the distance.
// //
// List<scalar> table1vals(table1.begin(), table1.end()); // List<scalar> table1vals(table1.begin(), table1.end());
// wordList table1keys(table1.begin(), table1.end());
{
Info<<"distance/size: "
<< std::distance(table1.begin(), table1.end())
<< "/" << table1.size()
<< " and "
<< std::distance(table1.keys().begin(), table1.keys().end())
<< "/" << table1.keys().size()
<< nl;
SortableList<word> sortKeys
// DynamicList<word> sortKeys
(
table1.keys().begin(),
table1.keys().end()
);
Info<<"sortKeys: " << flatOutput(sortKeys) << nl;
}
Info<< "\nFrom table1: " << flatOutput(table1.sortedToc()) << nl
<< "retain keys: " << flatOutput(table3.sortedToc()) << nl;
table1.retain(table3);
Info<< "-> " << flatOutput(table1.sortedToc()) << nl;
Info<< "Lookup non-existent" << nl;
Info<< table1.lookup("missing-const", 1.2345e+6)
<< " // const-access" << nl;
Info<< table1("missing-inadvertent", 3.14159)
<< " // (inadvertent?) non-const access" << nl;
Info<< table1("missing-autovivify")
<< " // Known auto-vivification (non-const access)" << nl;
Info<<"\ntable1: " << table1 << endl;
Info<< "\nDone\n"; Info<< "\nDone\n";

View File

@ -42,6 +42,7 @@ See also
#include "vector.H" #include "vector.H"
#include "labelRange.H" #include "labelRange.H"
#include "scalarList.H"
#include "ListOps.H" #include "ListOps.H"
#include "SubList.H" #include "SubList.H"
@ -144,6 +145,18 @@ int main(int argc, char *argv[])
labelList longLabelList = identity(15); labelList longLabelList = identity(15);
// This does not work:
// scalarList slist = identity(15);
//
// More writing, but does work:
scalarList slist
(
labelRange::null.begin(),
labelRange::identity(15).end()
);
Info<<"scalar identity:" << flatOutput(slist) << endl;
Info<< "labels (contiguous=" << contiguous<label>() << ")" << nl; Info<< "labels (contiguous=" << contiguous<label>() << ")" << nl;
Info<< "normal: " << longLabelList << nl; Info<< "normal: " << longLabelList << nl;
@ -220,7 +233,32 @@ int main(int argc, char *argv[])
} }
Info<< "sub-sorted: " << flatOutput(longLabelList) << nl; Info<< "sub-sorted: " << flatOutput(longLabelList) << nl;
// Info<<"Slice=" << longLabelList[labelRange(23,5)] << nl; // construct from a label-range
labelRange range(25,15);
labelList ident(range.begin(), range.end());
Info<<"range-list (label)=" << ident << nl;
List<scalar> sident(range.begin(), range.end());
Info<<"range-list (scalar)=" << sident << nl;
// Sub-ranges also work
List<scalar> sident2(range(3), range(10));
Info<<"range-list (scalar)=" << sident2 << nl;
// VERY BAD IDEA: List<scalar> sident3(range(10), range(3));
// This doesn't work, and don't know what it should do anyhow
// List<vector> vident(range.begin(), range.end());
// Info<<"range-list (vector)=" << vident << nl;
// Even weird things like this
List<scalar> sident4
(
labelRange().begin(),
labelRange::identity(8).end()
);
Info<<"range-list (scalar)=" << sident4 << nl;
} }
wordReList reLst; wordReList reLst;

View File

@ -58,7 +58,7 @@ int main(int argc, char *argv[])
Info<<"test sorting" << endl; Info<<"test sorting" << endl;
DynamicList<labelRange> list1(10); DynamicList<labelRange> list1(10);
list1.append(labelRange(25, 8)); list1.append(labelRange(25, 8));
list1.append(labelRange(0, 10)); list1.append(labelRange::identity(8));
list1.append(labelRange(15, 5)); list1.append(labelRange(15, 5));
list1.append(labelRange(50, -10)); list1.append(labelRange(50, -10));

View File

@ -924,8 +924,8 @@ int main(int argc, char *argv[])
} }
} }
HashTable<labelList,word> cellZones; HashTable<labelList> cellZones;
HashTable<labelList,word> faceZones; HashTable<labelList> faceZones;
List<bool> isAPatch(patchNames.size(),true); List<bool> isAPatch(patchNames.size(),true);
if (dofVertIndices.size()) if (dofVertIndices.size())

View File

@ -1,3 +1,4 @@
writeFields.C
checkTools.C checkTools.C
checkTopology.C checkTopology.C
checkGeometry.C checkGeometry.C

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -57,12 +57,18 @@ Usage
Reconstruct all cellSets and faceSets geometry and write to postProcessing/ Reconstruct all cellSets and faceSets geometry and write to postProcessing/
directory according to surfaceFormat (e.g. vtk or ensight) directory according to surfaceFormat (e.g. vtk or ensight)
\param -writeAllFields \n
Writes all mesh quality measures as fields.
\param -writeFields '(\<fieldName\>)' \n
Writes selected mesh quality measures as fields.
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "argList.H" #include "argList.H"
#include "timeSelector.H" #include "timeSelector.H"
#include "Time.H" #include "Time.H"
#include "polyMesh.H" #include "fvMesh.H"
#include "globalMeshData.H" #include "globalMeshData.H"
#include "surfaceWriter.H" #include "surfaceWriter.H"
#include "vtkSetWriter.H" #include "vtkSetWriter.H"
@ -71,6 +77,7 @@ Usage
#include "checkTopology.H" #include "checkTopology.H"
#include "checkGeometry.H" #include "checkGeometry.H"
#include "checkMeshQuality.H" #include "checkMeshQuality.H"
#include "writeFields.H"
using namespace Foam; using namespace Foam;
@ -96,6 +103,17 @@ int main(int argc, char *argv[])
"include extra topology checks" "include extra topology checks"
); );
argList::addBoolOption argList::addBoolOption
(
"writeAllFields",
"write volFields with mesh quality parameters"
);
argList::addOption
(
"writeFields",
"wordList",
"write volFields with selected mesh quality parameters"
);
argList::addBoolOption
( (
"meshQuality", "meshQuality",
"read user-defined mesh quality criterions from system/meshQualityDict" "read user-defined mesh quality criterions from system/meshQualityDict"
@ -110,7 +128,7 @@ int main(int argc, char *argv[])
#include "setRootCase.H" #include "setRootCase.H"
#include "createTime.H" #include "createTime.H"
instantList timeDirs = timeSelector::select0(runTime, args); instantList timeDirs = timeSelector::select0(runTime, args);
#include "createNamedPolyMesh.H" #include "createNamedMesh.H"
const bool noTopology = args.optionFound("noTopology"); const bool noTopology = args.optionFound("noTopology");
const bool allGeometry = args.optionFound("allGeometry"); const bool allGeometry = args.optionFound("allGeometry");
@ -119,6 +137,24 @@ int main(int argc, char *argv[])
word surfaceFormat; word surfaceFormat;
const bool writeSets = args.optionReadIfPresent("writeSets", surfaceFormat); const bool writeSets = args.optionReadIfPresent("writeSets", surfaceFormat);
HashSet<word> selectedFields;
bool writeFields = args.optionReadIfPresent
(
"writeFields",
selectedFields
);
if (!writeFields && args.optionFound("writeAllFields"))
{
selectedFields.insert("nonOrthoAngle");
selectedFields.insert("faceWeight");
selectedFields.insert("skewness");
selectedFields.insert("cellDeterminant");
selectedFields.insert("aspectRatio");
selectedFields.insert("cellShapes");
selectedFields.insert("cellVolume");
selectedFields.insert("cellVolumeRatio");
}
if (noTopology) if (noTopology)
{ {
@ -143,6 +179,11 @@ int main(int argc, char *argv[])
<< " representation" << " representation"
<< " of all faceSets and cellSets." << nl << endl; << " of all faceSets and cellSets." << nl << endl;
} }
if (selectedFields.size())
{
Info<< "Writing mesh quality as fields " << selectedFields << nl
<< endl;
}
autoPtr<IOdictionary> qualDict; autoPtr<IOdictionary> qualDict;
@ -234,6 +275,10 @@ int main(int argc, char *argv[])
Info<< "\nFailed " << nFailedChecks << " mesh checks.\n" Info<< "\nFailed " << nFailedChecks << " mesh checks.\n"
<< endl; << endl;
} }
// Write selected fields
Foam::writeFields(mesh, selectedFields);
} }
else if (state == polyMesh::POINTS_MOVED) else if (state == polyMesh::POINTS_MOVED)
{ {
@ -262,6 +307,10 @@ int main(int argc, char *argv[])
{ {
Info<< "\nMesh OK.\n" << endl; Info<< "\nMesh OK.\n" << endl;
} }
// Write selected fields
Foam::writeFields(mesh, selectedFields);
} }
} }

View File

@ -0,0 +1,360 @@
#include "writeFields.H"
#include "volFields.H"
#include "polyMeshTools.H"
#include "zeroGradientFvPatchFields.H"
#include "syncTools.H"
using namespace Foam;
void maxFaceToCell
(
const scalarField& faceData,
volScalarField& cellData
)
{
const cellList& cells = cellData.mesh().cells();
scalarField& cellFld = cellData.ref();
cellFld = -GREAT;
forAll(cells, cellI)
{
const cell& cFaces = cells[cellI];
forAll(cFaces, i)
{
cellFld[cellI] = max(cellFld[cellI], faceData[cFaces[i]]);
}
}
forAll(cellData.boundaryField(), patchI)
{
fvPatchScalarField& fvp = cellData.boundaryFieldRef()[patchI];
fvp = fvp.patch().patchSlice(faceData);
}
cellData.correctBoundaryConditions();
}
void minFaceToCell
(
const scalarField& faceData,
volScalarField& cellData
)
{
const cellList& cells = cellData.mesh().cells();
scalarField& cellFld = cellData.ref();
cellFld = GREAT;
forAll(cells, cellI)
{
const cell& cFaces = cells[cellI];
forAll(cFaces, i)
{
cellFld[cellI] = min(cellFld[cellI], faceData[cFaces[i]]);
}
}
forAll(cellData.boundaryField(), patchI)
{
fvPatchScalarField& fvp = cellData.boundaryFieldRef()[patchI];
fvp = fvp.patch().patchSlice(faceData);
}
cellData.correctBoundaryConditions();
}
void Foam::writeFields
(
const fvMesh& mesh,
const HashSet<word>& selectedFields
)
{
if (selectedFields.empty())
{
return;
}
Info<< "Writing fields with mesh quality parameters" << endl;
if (selectedFields.found("nonOrthoAngle"))
{
//- Face based orthogonality
const scalarField faceOrthogonality
(
polyMeshTools::faceOrthogonality
(
mesh,
mesh.faceAreas(),
mesh.cellCentres()
)
);
//- Face based angle
const scalarField nonOrthoAngle
(
radToDeg
(
Foam::acos(min(1.0, faceOrthogonality))
)
);
//- Cell field - max of either face
volScalarField cellNonOrthoAngle
(
IOobject
(
"nonOrthoAngle",
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
dimensionedScalar("angle", dimless, 0),
calculatedFvPatchScalarField::typeName
);
//- Take max
maxFaceToCell(nonOrthoAngle, cellNonOrthoAngle);
Info<< " Writing non-orthogonality (angle) to "
<< cellNonOrthoAngle.name() << endl;
cellNonOrthoAngle.write();
}
if (selectedFields.found("faceWeight"))
{
const scalarField faceWeights
(
polyMeshTools::faceWeights
(
mesh,
mesh.faceCentres(),
mesh.faceAreas(),
mesh.cellCentres()
)
);
volScalarField cellWeights
(
IOobject
(
"faceWeight",
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
dimensionedScalar("weight", dimless, 0),
calculatedFvPatchScalarField::typeName
);
//- Take min
minFaceToCell(faceWeights, cellWeights);
Info<< " Writing face interpolation weights (0..0.5) to "
<< cellWeights.name() << endl;
cellWeights.write();
}
// Skewness
// ~~~~~~~~
if (selectedFields.found("skewness"))
{
//- Face based skewness
const scalarField faceSkewness
(
polyMeshTools::faceSkewness
(
mesh,
mesh.points(),
mesh.faceCentres(),
mesh.faceAreas(),
mesh.cellCentres()
)
);
//- Cell field - max of either face
volScalarField cellSkewness
(
IOobject
(
"skewness",
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
dimensionedScalar("skewness", dimless, 0),
calculatedFvPatchScalarField::typeName
);
//- Take max
maxFaceToCell(faceSkewness, cellSkewness);
Info<< " Writing face skewness to " << cellSkewness.name() << endl;
cellSkewness.write();
}
// cellDeterminant
// ~~~~~~~~~~~~~~~
if (selectedFields.found("cellDeterminant"))
{
volScalarField cellDeterminant
(
IOobject
(
"cellDeterminant",
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE,
false
),
mesh,
dimensionedScalar("cellDeterminant", dimless, 0),
zeroGradientFvPatchScalarField::typeName
);
cellDeterminant.primitiveFieldRef() =
primitiveMeshTools::cellDeterminant
(
mesh,
mesh.geometricD(),
mesh.faceAreas(),
syncTools::getInternalOrCoupledFaces(mesh)
);
cellDeterminant.correctBoundaryConditions();
Info<< " Writing cell determinant to "
<< cellDeterminant.name() << endl;
cellDeterminant.write();
}
// Aspect ratio
// ~~~~~~~~~~~~
if (selectedFields.found("aspectRatio"))
{
volScalarField aspectRatio
(
IOobject
(
"aspectRatio",
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE,
false
),
mesh,
dimensionedScalar("aspectRatio", dimless, 0),
zeroGradientFvPatchScalarField::typeName
);
scalarField cellOpenness;
polyMeshTools::cellClosedness
(
mesh,
mesh.geometricD(),
mesh.faceAreas(),
mesh.cellVolumes(),
cellOpenness,
aspectRatio.ref()
);
aspectRatio.correctBoundaryConditions();
Info<< " Writing aspect ratio to " << aspectRatio.name() << endl;
aspectRatio.write();
}
// cell type
// ~~~~~~~~~
if (selectedFields.found("cellShapes"))
{
volScalarField shape
(
IOobject
(
"cellShapes",
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE,
false
),
mesh,
dimensionedScalar("cellShapes", dimless, 0),
zeroGradientFvPatchScalarField::typeName
);
const cellShapeList& cellShapes = mesh.cellShapes();
forAll(cellShapes, cellI)
{
const cellModel& model = cellShapes[cellI].model();
shape[cellI] = model.index();
}
shape.correctBoundaryConditions();
Info<< " Writing cell shape (hex, tet etc.) to " << shape.name()
<< endl;
shape.write();
}
if (selectedFields.found("cellVolume"))
{
volScalarField V
(
IOobject
(
"cellVolume",
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE,
false
),
mesh,
dimensionedScalar("cellVolume", dimVolume, 0),
calculatedFvPatchScalarField::typeName
);
V.ref() = mesh.V();
Info<< " Writing cell volume to " << V.name() << endl;
V.write();
}
if (selectedFields.found("cellVolumeRatio"))
{
const scalarField faceVolumeRatio
(
polyMeshTools::volRatio
(
mesh,
mesh.V()
)
);
volScalarField cellVolumeRatio
(
IOobject
(
"cellVolumeRatio",
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
dimensionedScalar("cellVolumeRatio", dimless, 0),
calculatedFvPatchScalarField::typeName
);
//- Take min
minFaceToCell(faceVolumeRatio, cellVolumeRatio);
Info<< " Writing cell volume ratio to "
<< cellVolumeRatio.name() << endl;
cellVolumeRatio.write();
}
Info<< endl;
}

View File

@ -0,0 +1,10 @@
#include "fvMesh.H"
namespace Foam
{
void writeFields
(
const fvMesh&,
const HashSet<word>& selectedFields
);
}

View File

@ -233,21 +233,16 @@ void Foam::vtkPVFoam::updateInfoPatches
if (meshPtr_) if (meshPtr_)
{ {
const polyBoundaryMesh& patches = meshPtr_->boundaryMesh(); const polyBoundaryMesh& patches = meshPtr_->boundaryMesh();
const HashTable<labelList, word>& groups = patches.groupPatchIDs(); const HashTable<labelList>& groups = patches.groupPatchIDs();
const wordList allPatchNames = patches.names(); const wordList allPatchNames = patches.names();
// Add patch groups // Add patch groups
// ~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~
for forAllConstIters(groups, iter)
(
HashTable<labelList, word>::const_iterator iter = groups.begin();
iter != groups.end();
++iter
)
{ {
const word& groupName = iter.key(); const word& groupName = iter.key();
const labelList& patchIDs = iter(); const labelList& patchIDs = iter.object();
label nFaces = 0; label nFaces = 0;
forAll(patchIDs, i) forAll(patchIDs, i)
@ -349,7 +344,7 @@ void Foam::vtkPVFoam::updateInfoPatches
// Add (non-zero) patch groups to the list of mesh parts // Add (non-zero) patch groups to the list of mesh parts
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HashTable<labelList, word> groups(patchEntries.size()); HashTable<labelList> groups(patchEntries.size());
forAll(patchEntries, patchi) forAll(patchEntries, patchi)
{ {
@ -360,7 +355,7 @@ void Foam::vtkPVFoam::updateInfoPatches
forAll(groupNames, groupI) forAll(groupNames, groupI)
{ {
HashTable<labelList, word>::iterator iter = groups.find HashTable<labelList>::iterator iter = groups.find
( (
groupNames[groupI] groupNames[groupI]
); );
@ -375,16 +370,10 @@ void Foam::vtkPVFoam::updateInfoPatches
} }
} }
for forAllConstIters(groups, iter)
(
HashTable<labelList, word>::const_iterator iter =
groups.begin();
iter != groups.end();
++iter
)
{ {
const word& groupName = iter.key(); const word& groupName = iter.key();
const labelList& patchIDs = iter(); const labelList& patchIDs = iter.object();
label nFaces = 0; label nFaces = 0;
forAll(patchIDs, i) forAll(patchIDs, i)

View File

@ -51,6 +51,7 @@ Description
#include "uindirectPrimitivePatch.H" #include "uindirectPrimitivePatch.H"
#include "globalMeshData.H" #include "globalMeshData.H"
#include "globalIndex.H" #include "globalIndex.H"
#include "timeSelector.H"
using namespace Foam; using namespace Foam;
@ -63,6 +64,8 @@ int main(int argc, char *argv[])
( (
"extract surface from a polyMesh" "extract surface from a polyMesh"
); );
timeSelector::addOptions();
argList::validArgs.append("output file"); argList::validArgs.append("output file");
#include "addRegionOption.H" #include "addRegionOption.H"
argList::addBoolOption argList::addBoolOption
@ -86,7 +89,14 @@ int main(int argc, char *argv[])
#include "setRootCase.H" #include "setRootCase.H"
#include "createTime.H" #include "createTime.H"
const fileName outFileName(args[1]); const fileName userOutFileName(args[1]);
if (!userOutFileName.hasExt())
{
FatalErrorInFunction
<< "Missing extension on output name " << userOutFileName
<< exit(FatalError);
}
Info<< "Extracting surface from boundaryMesh ..." Info<< "Extracting surface from boundaryMesh ..."
<< endl << endl; << endl << endl;
@ -106,275 +116,321 @@ int main(int argc, char *argv[])
Info<< "Excluding all processor patches." << nl << endl; Info<< "Excluding all processor patches." << nl << endl;
} }
Info<< "Reading mesh from time " << runTime.value() << endl; Info<< "Reading mesh from time " << runTime.value() << endl;
#include "createNamedPolyMesh.H" #include "createNamedPolyMesh.H"
// User specified times
instantList timeDirs = timeSelector::select0(runTime, args);
// Create local surface from: forAll(timeDirs, timeIndex)
// - explicitly named patches only (-patches (at your option)
// - all patches (default in sequential mode)
// - all non-processor patches (default in parallel mode)
// - all non-processor patches (sequential mode, -excludeProcPatches
// (at your option)
// Construct table of patches to include.
const polyBoundaryMesh& bMesh = mesh.boundaryMesh();
labelHashSet includePatches(bMesh.size());
if (args.optionFound("patches"))
{ {
includePatches = bMesh.patchSet runTime.setTime(timeDirs[timeIndex], timeIndex);
( Info<< "Time [" << timeIndex << "] = " << runTime.timeName();
wordReList(args.optionLookup("patches")())
);
}
else
{
forAll(bMesh, patchi)
{
const polyPatch& patch = bMesh[patchi];
if (includeProcPatches || !isA<processorPolyPatch>(patch)) fileName outFileName;
if (timeDirs.size() == 1)
{
outFileName = userOutFileName;
Info<< nl;
}
else
{
polyMesh::readUpdateState meshState = mesh.readUpdate();
if (timeIndex && meshState == polyMesh::UNCHANGED)
{ {
includePatches.insert(patchi); Info<<" ... no mesh change." << nl;
} continue;
}
}
const faceZoneMesh& fzm = mesh.faceZones();
labelHashSet includeFaceZones(fzm.size());
if (args.optionFound("faceZones"))
{
wordReList zoneNames(args.optionLookup("faceZones")());
const wordList allZoneNames(fzm.names());
forAll(zoneNames, i)
{
const wordRe& zoneName = zoneNames[i];
labelList zoneIDs = findStrings(zoneName, allZoneNames);
forAll(zoneIDs, j)
{
includeFaceZones.insert(zoneIDs[j]);
}
if (zoneIDs.empty())
{
WarningInFunction
<< "Cannot find any faceZone name matching "
<< zoneName << endl;
}
}
Info<< "Additionally triangulating faceZones "
<< UIndirectList<word>(allZoneNames, includeFaceZones.sortedToc())
<< endl;
}
// From (name of) patch to compact 'zone' index
HashTable<label> compactZoneID(1000);
// Mesh face and compact zone indx
DynamicList<label> faceLabels;
DynamicList<label> compactZones;
{
// Collect sizes. Hash on names to handle local-only patches (e.g.
// processor patches)
HashTable<label> patchSize(1000);
label nFaces = 0;
forAllConstIter(labelHashSet, includePatches, iter)
{
const polyPatch& pp = bMesh[iter.key()];
patchSize.insert(pp.name(), pp.size());
nFaces += pp.size();
}
HashTable<label> zoneSize(1000);
forAllConstIter(labelHashSet, includeFaceZones, iter)
{
const faceZone& pp = fzm[iter.key()];
zoneSize.insert(pp.name(), pp.size());
nFaces += pp.size();
}
Pstream::mapCombineGather(patchSize, plusEqOp<label>());
Pstream::mapCombineGather(zoneSize, plusEqOp<label>());
// Allocate compact numbering for all patches/faceZones
forAllConstIter(HashTable<label>, patchSize, iter)
{
label sz = compactZoneID.size();
compactZoneID.insert(iter.key(), sz);
}
forAllConstIter(HashTable<label>, zoneSize, iter)
{
label sz = compactZoneID.size();
//Info<< "For faceZone " << iter.key() << " allocating zoneID "
// << sz << endl;
compactZoneID.insert(iter.key(), sz);
}
Pstream::mapCombineScatter(compactZoneID);
// Rework HashTable into labelList just for speed of conversion
labelList patchToCompactZone(bMesh.size(), -1);
labelList faceZoneToCompactZone(bMesh.size(), -1);
forAllConstIter(HashTable<label>, compactZoneID, iter)
{
label patchi = bMesh.findPatchID(iter.key());
if (patchi != -1)
{
patchToCompactZone[patchi] = iter();
} }
else else
{ {
label zoneI = fzm.findZoneID(iter.key()); Info<< nl;
faceZoneToCompactZone[zoneI] = iter();
} }
// The filename based on the original, but with additional
// time information. The extension was previously checked that
// it exists
std::string::size_type dot = userOutFileName.rfind('.');
outFileName =
userOutFileName.substr(0, dot) + "_"
+ Foam::name(runTime.value()) + "."
+ userOutFileName.ext();
} }
// Create local surface from:
// - explicitly named patches only (-patches (at your option)
// - all patches (default in sequential mode)
// - all non-processor patches (default in parallel mode)
// - all non-processor patches (sequential mode, -excludeProcPatches
// (at your option)
faceLabels.setCapacity(nFaces); // Construct table of patches to include.
compactZones.setCapacity(nFaces); const polyBoundaryMesh& bMesh = mesh.boundaryMesh();
// Collect faces on patches labelHashSet includePatches(bMesh.size());
forAllConstIter(labelHashSet, includePatches, iter)
if (args.optionFound("patches"))
{ {
const polyPatch& pp = bMesh[iter.key()]; includePatches = bMesh.patchSet
forAll(pp, i) (
wordReList(args.optionLookup("patches")())
);
}
else
{
forAll(bMesh, patchi)
{ {
faceLabels.append(pp.start()+i); const polyPatch& patch = bMesh[patchi];
compactZones.append(patchToCompactZone[pp.index()]);
if (includeProcPatches || !isA<processorPolyPatch>(patch))
{
includePatches.insert(patchi);
}
} }
} }
// Collect faces on faceZones
forAllConstIter(labelHashSet, includeFaceZones, iter)
const faceZoneMesh& fzm = mesh.faceZones();
labelHashSet includeFaceZones(fzm.size());
if (args.optionFound("faceZones"))
{ {
const faceZone& pp = fzm[iter.key()]; wordReList zoneNames(args.optionLookup("faceZones")());
forAll(pp, i) const wordList allZoneNames(fzm.names());
forAll(zoneNames, i)
{ {
faceLabels.append(pp[i]); const wordRe& zoneName = zoneNames[i];
compactZones.append(faceZoneToCompactZone[pp.index()]);
labelList zoneIDs = findStrings(zoneName, allZoneNames);
forAll(zoneIDs, j)
{
includeFaceZones.insert(zoneIDs[j]);
}
if (zoneIDs.empty())
{
WarningInFunction
<< "Cannot find any faceZone name matching "
<< zoneName << endl;
}
} }
} Info<< "Additionally triangulating faceZones "
} << UIndirectList<word>
(
allZoneNames,
// Addressing engine for all faces includeFaceZones.sortedToc()
uindirectPrimitivePatch allBoundary )
(
UIndirectList<face>(mesh.faces(), faceLabels),
mesh.points()
);
// Find correspondence to master points
labelList pointToGlobal;
labelList uniqueMeshPoints;
autoPtr<globalIndex> globalNumbers = mesh.globalData().mergePoints
(
allBoundary.meshPoints(),
allBoundary.meshPointMap(),
pointToGlobal,
uniqueMeshPoints
);
// Gather all unique points on master
List<pointField> gatheredPoints(Pstream::nProcs());
gatheredPoints[Pstream::myProcNo()] = pointField
(
mesh.points(),
uniqueMeshPoints
);
Pstream::gatherList(gatheredPoints);
// Gather all faces
List<faceList> gatheredFaces(Pstream::nProcs());
gatheredFaces[Pstream::myProcNo()] = allBoundary.localFaces();
forAll(gatheredFaces[Pstream::myProcNo()], i)
{
inplaceRenumber(pointToGlobal, gatheredFaces[Pstream::myProcNo()][i]);
}
Pstream::gatherList(gatheredFaces);
// Gather all ZoneIDs
List<labelList> gatheredZones(Pstream::nProcs());
gatheredZones[Pstream::myProcNo()] = compactZones.xfer();
Pstream::gatherList(gatheredZones);
// On master combine all points, faces, zones
if (Pstream::master())
{
pointField allPoints = ListListOps::combine<pointField>
(
gatheredPoints,
accessOp<pointField>()
);
gatheredPoints.clear();
faceList allFaces = ListListOps::combine<faceList>
(
gatheredFaces,
accessOp<faceList>()
);
gatheredFaces.clear();
labelList allZones = ListListOps::combine<labelList>
(
gatheredZones,
accessOp<labelList>()
);
gatheredZones.clear();
// Zones
surfZoneIdentifierList surfZones(compactZoneID.size());
forAllConstIter(HashTable<label>, compactZoneID, iter)
{
surfZones[iter()] = surfZoneIdentifier(iter.key(), iter());
Info<< "surfZone " << iter() << " : " << surfZones[iter()].name()
<< endl; << endl;
} }
UnsortedMeshedSurface<face> unsortedFace
// From (name of) patch to compact 'zone' index
HashTable<label> compactZoneID(1000);
// Mesh face and compact zone indx
DynamicList<label> faceLabels;
DynamicList<label> compactZones;
{
// Collect sizes. Hash on names to handle local-only patches (e.g.
// processor patches)
HashTable<label> patchSize(1000);
label nFaces = 0;
forAllConstIter(labelHashSet, includePatches, iter)
{
const polyPatch& pp = bMesh[iter.key()];
patchSize.insert(pp.name(), pp.size());
nFaces += pp.size();
}
HashTable<label> zoneSize(1000);
forAllConstIter(labelHashSet, includeFaceZones, iter)
{
const faceZone& pp = fzm[iter.key()];
zoneSize.insert(pp.name(), pp.size());
nFaces += pp.size();
}
Pstream::mapCombineGather(patchSize, plusEqOp<label>());
Pstream::mapCombineGather(zoneSize, plusEqOp<label>());
// Allocate compact numbering for all patches/faceZones
forAllConstIter(HashTable<label>, patchSize, iter)
{
label sz = compactZoneID.size();
compactZoneID.insert(iter.key(), sz);
}
forAllConstIter(HashTable<label>, zoneSize, iter)
{
label sz = compactZoneID.size();
//Info<< "For faceZone " << iter.key() << " allocating zoneID "
// << sz << endl;
compactZoneID.insert(iter.key(), sz);
}
Pstream::mapCombineScatter(compactZoneID);
// Rework HashTable into labelList just for speed of conversion
labelList patchToCompactZone(bMesh.size(), -1);
labelList faceZoneToCompactZone(bMesh.size(), -1);
forAllConstIter(HashTable<label>, compactZoneID, iter)
{
label patchi = bMesh.findPatchID(iter.key());
if (patchi != -1)
{
patchToCompactZone[patchi] = iter();
}
else
{
label zoneI = fzm.findZoneID(iter.key());
faceZoneToCompactZone[zoneI] = iter();
}
}
faceLabels.setCapacity(nFaces);
compactZones.setCapacity(nFaces);
// Collect faces on patches
forAllConstIter(labelHashSet, includePatches, iter)
{
const polyPatch& pp = bMesh[iter.key()];
forAll(pp, i)
{
faceLabels.append(pp.start()+i);
compactZones.append(patchToCompactZone[pp.index()]);
}
}
// Collect faces on faceZones
forAllConstIter(labelHashSet, includeFaceZones, iter)
{
const faceZone& pp = fzm[iter.key()];
forAll(pp, i)
{
faceLabels.append(pp[i]);
compactZones.append(faceZoneToCompactZone[pp.index()]);
}
}
}
// Addressing engine for all faces
uindirectPrimitivePatch allBoundary
( (
xferMove(allPoints), UIndirectList<face>(mesh.faces(), faceLabels),
xferMove(allFaces), mesh.points()
xferMove(allZones),
xferMove(surfZones)
); );
MeshedSurface<face> sortedFace(unsortedFace); // Find correspondence to master points
labelList pointToGlobal;
fileName globalCasePath labelList uniqueMeshPoints;
autoPtr<globalIndex> globalNumbers = mesh.globalData().mergePoints
( (
outFileName.isAbsolute() allBoundary.meshPoints(),
? outFileName allBoundary.meshPointMap(),
: ( pointToGlobal,
runTime.processorCase() uniqueMeshPoints
? runTime.rootPath()/runTime.globalCaseName()/outFileName
: runTime.path()/outFileName
)
); );
Info<< "Writing merged surface to " << globalCasePath << endl; // Gather all unique points on master
List<pointField> gatheredPoints(Pstream::nProcs());
gatheredPoints[Pstream::myProcNo()] = pointField
(
mesh.points(),
uniqueMeshPoints
);
Pstream::gatherList(gatheredPoints);
sortedFace.write(globalCasePath); // Gather all faces
List<faceList> gatheredFaces(Pstream::nProcs());
gatheredFaces[Pstream::myProcNo()] = allBoundary.localFaces();
forAll(gatheredFaces[Pstream::myProcNo()], i)
{
inplaceRenumber
(
pointToGlobal,
gatheredFaces[Pstream::myProcNo()][i]
);
}
Pstream::gatherList(gatheredFaces);
// Gather all ZoneIDs
List<labelList> gatheredZones(Pstream::nProcs());
gatheredZones[Pstream::myProcNo()] = compactZones.xfer();
Pstream::gatherList(gatheredZones);
// On master combine all points, faces, zones
if (Pstream::master())
{
pointField allPoints = ListListOps::combine<pointField>
(
gatheredPoints,
accessOp<pointField>()
);
gatheredPoints.clear();
faceList allFaces = ListListOps::combine<faceList>
(
gatheredFaces,
accessOp<faceList>()
);
gatheredFaces.clear();
labelList allZones = ListListOps::combine<labelList>
(
gatheredZones,
accessOp<labelList>()
);
gatheredZones.clear();
// Zones
surfZoneIdentifierList surfZones(compactZoneID.size());
forAllConstIter(HashTable<label>, compactZoneID, iter)
{
surfZones[iter()] = surfZoneIdentifier(iter.key(), iter());
Info<< "surfZone " << iter()
<< " : " << surfZones[iter()].name()
<< endl;
}
UnsortedMeshedSurface<face> unsortedFace
(
xferMove(allPoints),
xferMove(allFaces),
xferMove(allZones),
xferMove(surfZones)
);
MeshedSurface<face> sortedFace(unsortedFace);
fileName globalCasePath
(
outFileName.isAbsolute()
? outFileName
: (
runTime.processorCase()
? runTime.rootPath()/runTime.globalCaseName()/outFileName
: runTime.path()/outFileName
)
);
Info<< "Writing merged surface to " << globalCasePath << endl;
sortedFace.write(globalCasePath);
}
} }
Info<< "End\n" << endl; Info<< "End\n" << endl;
return 0; return 0;

View File

@ -22,7 +22,7 @@
+ Stream output + Stream output
+ =<<= is always four characters after the start of the stream, + =<<= is always four characters after the start of the stream,
so that the =<<= symbols align, i.e. so that the =<<= symbols align, i.e.
#+begin_src c++ #+begin_src C++
Info<< ... Info<< ...
os << ... os << ...
#+end_src #+end_src
@ -215,7 +215,7 @@
*** =for= and =while= Loops *** =for= and =while= Loops
#+begin_src C++ #+begin_src C++
for (i = 0; i < maxI; i++) for (i = 0; i < maxI; ++i)
{ {
code; code;
} }
@ -226,7 +226,7 @@
( (
i = 0; i = 0;
i < maxI; i < maxI;
i++ ++i
) )
{ {
code; code;
@ -234,15 +234,22 @@
#+end_src #+end_src
*not* this (no space between =for= and =(= used) *not* this (no space between =for= and =(= used)
#+begin_src C++ #+begin_src C++
for(i = 0; i < maxI; i++) for(i = 0; i < maxI; ++i)
{ {
code; code;
} }
#+end_src #+end_src
Note that when indexing through iterators, it is often slightly more Range-base for should have a space surrounding the ':'
efficient to use the pre-increment form. Eg, =++iter= instead of =iter++= #+begin_src C++
for (auto i : range)
{
code;
}
#+end_src
Note that when indexing through iterators, it is often more efficient
to use the pre-increment form. Eg, =++iter= instead of =iter++=
*** =forAll=, =forAllIter=, =forAllConstIter=, /etc./ loops *** =forAll=, =forAllIters=, =forAllConstIters=, /etc./ loops
Like =for= loops, but Like =for= loops, but
#+begin_src C++ #+begin_src C++
forAll( forAll(
@ -251,15 +258,22 @@
#+begin_src C++ #+begin_src C++
forAll ( forAll (
#+end_src #+end_src
Using the =forAllIter= and =forAllConstIter= macros is generally In many cases, the new =forAllIters= and =forAllConstIters= macros
advantageous - less typing, easier to find later. However, since provide a good means of cycling through iterators (when a range-base
they are macros, they will fail if the iterated object contains for doesn't apply). These use the C++11 decltype and work without
any commas /e.g./ following will FAIL!: explicitly specifying the container class:
#+begin_src C++ #+begin_src C++
forAllIter(HashTable<labelPair, edge, Hash<edge>>, foo, iter) forAllIters(myEdgeHash, iter)
#+end_src
Using the older =forAllIter= and =forAllConstIter= macros will
still be seen. However, since they are macros, they will fail if
the iterated object contains any commas /e.g./ following will FAIL!:
#+begin_src C++
forAllIter(HashTable<labelPair, edge, Hash<edge>>, myEdgeHash, iter)
#+end_src #+end_src
These convenience macros are also generally avoided in other These convenience macros are also generally avoided in other
container classes and OpenFOAM primitive classes. container classes and OpenFOAM primitive classes.
In certain cases, the range-based for can also be used.
*** Splitting Over Multiple Lines *** Splitting Over Multiple Lines
***** Splitting return type and function name ***** Splitting return type and function name

View File

@ -72,30 +72,44 @@ Foam::HashPtrTable<T, Key, Hash>::~HashPtrTable()
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
T* Foam::HashPtrTable<T, Key, Hash>::remove(iterator& iter) T* Foam::HashPtrTable<T, Key, Hash>::remove(iterator& iter)
{ {
T* ptr = iter.object(); if (iter.found())
this->parent_type::erase(iter); {
return ptr; T* ptr = iter.object();
this->parent_type::erase(iter);
return ptr;
}
return nullptr;
} }
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
bool Foam::HashPtrTable<T, Key, Hash>::erase(iterator& iter) bool Foam::HashPtrTable<T, Key, Hash>::erase(iterator& iter)
{ {
T* ptr = iter.object(); if (iter.found())
if (this->parent_type::erase(iter))
{ {
if (ptr) T* ptr = iter.object();
if (this->parent_type::erase(iter))
{ {
delete ptr; if (ptr)
} {
delete ptr;
}
return true; return true;
} }
else
{
return false;
} }
return false;
}
template<class T, class Key, class Hash>
bool Foam::HashPtrTable<T, Key, Hash>::erase(const Key& key)
{
auto iter = this->find(key);
return this->erase(iter);
} }

View File

@ -116,12 +116,17 @@ public:
// Edit // Edit
//- Remove and return the pointer specified by given iterator //- Remove and return the pointer specified by given iterator.
// Includes a safeguard against the end-iterator.
T* remove(iterator& iter); T* remove(iterator& iter);
//- Erase an hashedEntry specified by given iterator //- Erase an entry specified by given iterator
// Includes a safeguard against the end-iterator.
bool erase(iterator& iter); bool erase(iterator& iter);
//- Erase an entry specified by the given key
bool erase(const Key& key);
//- Clear all entries from table //- Clear all entries from table
void clear(); void clear();

View File

@ -227,16 +227,9 @@ void Foam::HashSet<Key, Hash>::operator|=(const HashSet<Key, Hash>& rhs)
template<class Key, class Hash> template<class Key, class Hash>
void Foam::HashSet<Key, Hash>::operator&=(const HashSet<Key, Hash>& rhs) inline void Foam::HashSet<Key, Hash>::operator&=(const HashSet<Key, Hash>& rhs)
{ {
// Remove elements not also found in rhs this->parent_type::retain(rhs);
for (iterator iter = this->begin(); iter != this->end(); ++iter)
{
if (!rhs.found(iter.key()))
{
this->erase(iter);
}
}
} }
@ -259,13 +252,9 @@ void Foam::HashSet<Key, Hash>::operator^=(const HashSet<Key, Hash>& rhs)
template<class Key, class Hash> template<class Key, class Hash>
void Foam::HashSet<Key, Hash>::operator-=(const HashSet<Key, Hash>& rhs) inline void Foam::HashSet<Key, Hash>::operator-=(const HashSet<Key, Hash>& rhs)
{ {
// Remove rhs elements from lhs this->parent_type::erase(rhs);
for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
{
this->erase(iter.key());
}
} }

View File

@ -277,7 +277,7 @@ public:
void operator|=(const HashSet<Key, Hash>& rhs); void operator|=(const HashSet<Key, Hash>& rhs);
//- Only retain entries found in both HashSets //- Only retain entries found in both HashSets
void operator&=(const HashSet<Key, Hash>& rhs); inline void operator&=(const HashSet<Key, Hash>& rhs);
//- Only retain unique entries (xor) //- Only retain unique entries (xor)
void operator^=(const HashSet<Key, Hash>& rhs); void operator^=(const HashSet<Key, Hash>& rhs);
@ -289,7 +289,7 @@ public:
} }
//- Remove entries listed in the given HashSet from this HashSet //- Remove entries listed in the given HashSet from this HashSet
void operator-=(const HashSet<Key, Hash>& rhs); inline void operator-=(const HashSet<Key, Hash>& rhs);
// IOstream Operator // IOstream Operator

View File

@ -257,7 +257,7 @@ template<class T, class Key, class Hash>
bool Foam::HashTable<T, Key, Hash>::set bool Foam::HashTable<T, Key, Hash>::set
( (
const Key& key, const Key& key,
const T& newEntry, const T& obj,
const bool protect const bool protect
) )
{ {
@ -284,7 +284,7 @@ bool Foam::HashTable<T, Key, Hash>::set
if (!existing) if (!existing)
{ {
// Not found, insert it at the head // Not found, insert it at the head
table_[hashIdx] = new hashedEntry(key, newEntry, table_[hashIdx]); table_[hashIdx] = new hashedEntry(key, obj, table_[hashIdx]);
nElmts_++; nElmts_++;
if (double(nElmts_)/tableSize_ > 0.8 && tableSize_ < maxTableSize) if (double(nElmts_)/tableSize_ > 0.8 && tableSize_ < maxTableSize)
@ -316,7 +316,7 @@ bool Foam::HashTable<T, Key, Hash>::set
{ {
// Found - overwrite existing entry // Found - overwrite existing entry
// this corresponds to the Perl convention // this corresponds to the Perl convention
hashedEntry* ep = new hashedEntry(key, newEntry, existing->next_); hashedEntry* ep = new hashedEntry(key, obj, existing->next_);
// Replace existing element - within list or insert at the head // Replace existing element - within list or insert at the head
if (prev) if (prev)
@ -411,7 +411,8 @@ bool Foam::HashTable<T, Key, Hash>::erase(const iterator& iter)
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
bool Foam::HashTable<T, Key, Hash>::erase(const Key& key) bool Foam::HashTable<T, Key, Hash>::erase(const Key& key)
{ {
return erase(find(key)); auto iter = find(key);
return erase(iter);
} }
@ -450,15 +451,15 @@ Foam::label Foam::HashTable<T, Key, Hash>::erase
const HashTable<AnyType, Key, AnyHash>& other const HashTable<AnyType, Key, AnyHash>& other
) )
{ {
// Remove other keys from this table
const label nTotal = this->size(); const label nTotal = this->size();
label changed = 0; label changed = 0;
if (other.size() < nTotal) using other_iter =
typename HashTable<AnyType, Key, AnyHash>::const_iterator;
if (other.size() <= nTotal)
{ {
// other is smaller, use its keys for removal // The other is smaller/same-size, use its keys for removal
using other_iter =
typename HashTable<AnyType, Key, AnyHash>::const_iterator;
for for
( (
@ -475,7 +476,7 @@ Foam::label Foam::HashTable<T, Key, Hash>::erase
} }
else else
{ {
// other is same/larger: iterate ourselves and check for key in other // We are smaller: remove if found in the other hash
for for
( (
iterator iter = begin(); iterator iter = begin();
@ -494,6 +495,39 @@ Foam::label Foam::HashTable<T, Key, Hash>::erase
} }
template<class T, class Key, class Hash>
template<class AnyType, class AnyHash>
Foam::label Foam::HashTable<T, Key, Hash>::retain
(
const HashTable<AnyType, Key, AnyHash>& other
)
{
const label nTotal = this->size();
label changed = 0;
if (other.empty())
{
// Trivial case
changed = nTotal;
this->clear();
}
else
{
// Inverted logic: remove if *not* found in the other hash
for (iterator iter = begin(); iter != end(); ++iter)
{
if (!other.found(iter.key()) && erase(iter))
{
++changed;
}
}
}
return changed;
}
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
void Foam::HashTable<T, Key, Hash>::resize(const label sz) void Foam::HashTable<T, Key, Hash>::resize(const label sz)
{ {

View File

@ -44,6 +44,7 @@ Note
SourceFiles SourceFiles
HashTableI.H HashTableI.H
HashTable.C HashTable.C
HashTableCoreI.H
HashTableCore.C HashTableCore.C
HashTableIO.C HashTableIO.C
@ -60,6 +61,7 @@ SourceFiles
#include "nullObject.H" #include "nullObject.H"
#include <initializer_list> #include <initializer_list>
#include <iterator>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -178,10 +180,17 @@ public:
//- Type of values that the HashTable contains. //- Type of values that the HashTable contains.
typedef T value_type; typedef T value_type;
//- The type used for storing into value_type objects.
// This type is usually value_type&.
typedef T* pointer;
//- The type used for storing into value_type objects. //- The type used for storing into value_type objects.
// This type is usually value_type&. // This type is usually value_type&.
typedef T& reference; typedef T& reference;
//- The type used for reading from constant value_type objects.
typedef const T* const_pointer;
//- The type used for reading from constant value_type objects. //- The type used for reading from constant value_type objects.
typedef const T& const_reference; typedef const T& const_reference;
@ -247,7 +256,7 @@ private:
//- Assign a new hash-entry to a possibly already existing key. //- Assign a new hash-entry to a possibly already existing key.
// Return true if the new entry was set. // Return true if the new entry was set.
bool set(const Key& key, const T& newEntry, const bool protect); bool set(const Key& key, const T& obj, const bool protect);
protected: protected:
@ -307,17 +316,20 @@ public:
//- Return true if the hash table is empty //- Return true if the hash table is empty
inline bool empty() const; inline bool empty() const;
//- Return true if hashedEntry is found in table //- Return true if hashed entry is found in table
bool found(const Key& key) const; bool found(const Key& key) const;
//- Find and return an iterator set at the hashedEntry //- Find and return an iterator set at the hashed entry
// If not found iterator = end() // If not found iterator = end()
iterator find(const Key& key); iterator find(const Key& key);
//- Find and return an const_iterator set at the hashedEntry //- Find and return an const_iterator set at the hashed entry
// If not found iterator = end() // If not found iterator = end()
const_iterator find(const Key& key) const; const_iterator find(const Key& key) const;
//- Return hashed entry if it exists, or return the given default
inline const T& lookup(const Key& key, const T& deflt) const;
//- Return the table of contents //- Return the table of contents
List<Key> toc() const; List<Key> toc() const;
@ -327,42 +339,58 @@ public:
// Edit // Edit
//- Insert a new hashedEntry //- Insert a new entry
// Return true if the entry inserted, which means that it did // Return true if the entry inserted, which means that it did
// not previously exist in the table. // not previously exist in the table.
inline bool insert(const Key& key, const T& newEntry); inline bool insert(const Key& key, const T& obj);
//- Assign a new hashedEntry, overwriting existing entries. //- Assign a new entry, overwriting existing entries.
// Returns true. // Returns true.
inline bool set(const Key& key, const T& newEntry); inline bool set(const Key& key, const T& obj);
//- Erase a hashedEntry specified by given iterator //- Erase an entry specified by given iterator
// This invalidates the iterator until the next ++ operation // This invalidates the iterator until the next ++ operation.
//
// Includes a safeguard against the end-iterator such that the
// following is safe:
// \code
// auto iter = table.find(unknownKey);
// table.erase(iter);
// \endcode
// which is what \code table.erase(unknownKey) \endcode does anyhow
bool erase(const iterator& iter); bool erase(const iterator& iter);
//- Erase a hashedEntry specified by the given key //- Erase an entry specified by the given key
bool erase(const Key& key); bool erase(const Key& key);
//- Remove entries given by the listed keys from this HashTable //- Remove table entries given by the listed keys
// Return the number of elements removed // Return the number of elements removed
label erase(const UList<Key>& keys); label erase(const UList<Key>& keys);
//- Remove entries given by the listed keys from this HashTable //- Remove table entries given by the listed keys
// Return the number of elements removed // Return the number of elements removed
template<unsigned Size> template<unsigned Size>
label erase(const FixedList<Key, Size>& keys); label erase(const FixedList<Key, Size>& keys);
//- Remove entries given by the listed keys from this HashTable //- Remove table entries given by the listed keys
// Return the number of elements removed // Return the number of elements removed
label erase(std::initializer_list<Key> keys); label erase(std::initializer_list<Key> keys);
//- Remove entries given by the given keys from this HashTable //- Remove table entries given by keys of the other hash-table.
// Return the number of elements removed. // Return the number of elements removed.
// The parameter HashTable needs the same type of key, but the //
// The other hash-table must have the same type of key, but the
// type of values held and the hashing function are arbitrary. // type of values held and the hashing function are arbitrary.
template<class AnyType, class AnyHash> template<class AnyType, class AnyHash>
label erase(const HashTable<AnyType, Key, AnyHash>& other); label erase(const HashTable<AnyType, Key, AnyHash>& other);
//- Retain table entries given by keys of the other hash-table.
//
// The other hash-table must have the same type of key, but the
// type of values held and the hashing function are arbitrary.
template<class AnyType, class AnyHash>
label retain(const HashTable<AnyType, Key, AnyHash>& other);
//- Resize the hash table for efficiency //- Resize the hash table for efficiency
void resize(const label sz); void resize(const label sz);
@ -383,10 +411,10 @@ public:
// Member Operators // Member Operators
//- Find and return a hashedEntry //- Find and return a hashed entry. FatalError if it does not exist.
inline T& operator[](const Key& key); inline T& operator[](const Key& key);
//- Find and return a hashedEntry //- Find and return a hashed entry. FatalError if it does not exist.
inline const T& operator[](const Key& key) const; inline const T& operator[](const Key& key) const;
//- Return existing entry or create a new entry. //- Return existing entry or create a new entry.
@ -394,6 +422,12 @@ public:
// value-initialized. For primitives, this will be zero. // value-initialized. For primitives, this will be zero.
inline T& operator()(const Key& key); inline T& operator()(const Key& key);
//- Return existing entry or insert a new entry.
inline T& operator()(const Key& key, const T& deflt);
//- Return hashed entry if it exists, or return the given default
inline const T& operator()(const Key& key, const T& deflt) const;
//- Assignment //- Assignment
void operator=(const HashTable<T, Key, Hash>& rhs); void operator=(const HashTable<T, Key, Hash>& rhs);
@ -423,6 +457,7 @@ protected:
// Public typedefs // Public typedefs
using table_type = this_type; using table_type = this_type;
using key_type = this_type::key_type; using key_type = this_type::key_type;
using iterator_category = std::forward_iterator_tag;
using difference_type = this_type::difference_type; using difference_type = this_type::difference_type;
private: private:
@ -500,16 +535,20 @@ public:
public WrappedIterator public WrappedIterator
{ {
public: public:
using value_type = this_type::key_type;
using pointer = const Key*;
using reference = const Key&; using reference = const Key&;
using difference_type = typename WrappedIterator::difference_type;
//- Implicit conversion //- Implicit conversion
inline key_iterator_base(const WrappedIterator& iter); inline key_iterator_base(const WrappedIterator& iter);
//- Return the key //- Return the key
inline reference operator*() const; inline reference operator*() const;
}; inline reference operator()() const;
inline key_iterator_base& operator++();
inline key_iterator_base operator++(int);
};
// STL iterator // STL iterator
@ -526,9 +565,9 @@ public:
// Public typedefs // Public typedefs
using table_type = this_type; using table_type = this_type;
using key_type = this_type::key_type; using value_type = this_type::value_type;
using pointer = this_type::pointer;
using reference = this_type::reference; using reference = this_type::reference;
using difference_type = typename iterator_base::difference_type;
// Constructors // Constructors
@ -574,9 +613,9 @@ public:
// Public typedefs // Public typedefs
using table_type = const this_type; using table_type = const this_type;
using key_type = this_type::key_type; using value_type = const this_type::value_type;
using pointer = this_type::const_pointer;
using reference = this_type::const_reference; using reference = this_type::const_reference;
using difference_type = typename iterator_base::difference_type;
// Constructors // Constructors

View File

@ -79,10 +79,10 @@ template<class T, class Key, class Hash>
inline bool Foam::HashTable<T, Key, Hash>::insert inline bool Foam::HashTable<T, Key, Hash>::insert
( (
const Key& key, const Key& key,
const T& newEntry const T& obj
) )
{ {
return this->set(key, newEntry, true); return this->set(key, obj, true);
} }
@ -90,10 +90,10 @@ template<class T, class Key, class Hash>
inline bool Foam::HashTable<T, Key, Hash>::set inline bool Foam::HashTable<T, Key, Hash>::set
( (
const Key& key, const Key& key,
const T& newEntry const T& obj
) )
{ {
return this->set(key, newEntry, false); return this->set(key, obj, false);
} }
@ -105,6 +105,18 @@ Foam::HashTable<T, Key, Hash>::xfer()
} }
template<class T, class Key, class Hash>
inline const T& Foam::HashTable<T, Key, Hash>::lookup
(
const Key& key,
const T& deflt
) const
{
const_iterator iter = this->find(key);
return iter.found() ? iter.object() : deflt;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
@ -156,6 +168,36 @@ inline T& Foam::HashTable<T, Key, Hash>::operator()(const Key& key)
} }
template<class T, class Key, class Hash>
inline T& Foam::HashTable<T, Key, Hash>::operator()
(
const Key& key,
const T& deflt
)
{
iterator iter = this->find(key);
if (iter.found())
{
return iter.object();
}
this->insert(key, deflt);
return find(key).object();
}
template<class T, class Key, class Hash>
inline const T& Foam::HashTable<T, Key, Hash>::operator()
(
const Key& key,
const T& deflt
) const
{
return this->lookup(key, deflt);
}
// * * * * * * * * * * * * * * * iterator base * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * iterator base * * * * * * * * * * * * * * * //
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
@ -321,6 +363,39 @@ Foam::HashTable<T, Key, Hash>::key_iterator_base<WrappedIterator>
} }
template<class T, class Key, class Hash>
template<class WrappedIterator>
inline const Key&
Foam::HashTable<T, Key, Hash>::key_iterator_base<WrappedIterator>
::operator()() const
{
return this->key();
}
template<class T, class Key, class Hash>
template<class WrappedIterator>
inline Foam::HashTable<T, Key, Hash>::key_iterator_base<WrappedIterator>&
Foam::HashTable<T, Key, Hash>::key_iterator_base<WrappedIterator>
::operator++()
{
this->increment();
return *this;
}
template<class T, class Key, class Hash>
template<class WrappedIterator>
inline Foam::HashTable<T, Key, Hash>::key_iterator_base<WrappedIterator>
Foam::HashTable<T, Key, Hash>::key_iterator_base<WrappedIterator>
::operator++(int)
{
key_iterator_base old = *this;
this->increment();
return old;
}
// * * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * //
template<class T, class Key, class Hash> template<class T, class Key, class Hash>

View File

@ -203,7 +203,7 @@ template<class T, class Key, class Hash>
bool Foam::StaticHashTable<T, Key, Hash>::set bool Foam::StaticHashTable<T, Key, Hash>::set
( (
const Key& key, const Key& key,
const T& newEntry, const T& obj,
const bool protect const bool protect
) )
{ {
@ -229,7 +229,7 @@ bool Foam::StaticHashTable<T, Key, Hash>::set
localObjects.setSize(existing+1); localObjects.setSize(existing+1);
localKeys[existing] = key; localKeys[existing] = key;
localObjects[existing] = newEntry; localObjects[existing] = obj;
nElmts_++; nElmts_++;
} }
@ -250,7 +250,7 @@ bool Foam::StaticHashTable<T, Key, Hash>::set
{ {
// Found - overwrite existing entry // Found - overwrite existing entry
// this corresponds to the Perl convention // this corresponds to the Perl convention
objects_[hashIdx][existing] = newEntry; objects_[hashIdx][existing] = obj;
} }
return true; return true;

View File

@ -121,10 +121,10 @@ class StaticHashTable
//- Return the hash index of the Key within the current table size. //- Return the hash index of the Key within the current table size.
// No checks for zero-sized tables. // No checks for zero-sized tables.
inline label hashKeyIndex(const Key&) const; inline label hashKeyIndex(const Key& key) const;
//- Assign a new hashed entry to a possibly already existing key //- Assign a new hashed entry to a possibly already existing key
bool set(const Key&, const T& newElmt, bool protect); bool set(const Key& key, const T& obj, bool protect);
public: public:

View File

@ -26,8 +26,6 @@ License
#include "error.H" #include "error.H"
#include "IOstreams.H" #include "IOstreams.H"
// * * * * * * * * * * * * * Private Member Classes * * * * * * * * * * * * //
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
@ -59,10 +57,10 @@ template<class T, class Key, class Hash>
inline bool Foam::StaticHashTable<T, Key, Hash>::insert inline bool Foam::StaticHashTable<T, Key, Hash>::insert
( (
const Key& key, const Key& key,
const T& newEntry const T& obj
) )
{ {
return set(key, newEntry, true); return set(key, obj, true);
} }
@ -70,10 +68,10 @@ template<class T, class Key, class Hash>
inline bool Foam::StaticHashTable<T, Key, Hash>::set inline bool Foam::StaticHashTable<T, Key, Hash>::set
( (
const Key& key, const Key& key,
const T& newEntry const T& obj
) )
{ {
return set(key, newEntry, false); return set(key, obj, false);
} }

View File

@ -254,14 +254,14 @@ public:
// Member operators // Member operators
T& operator*() T& operator*() const
{ {
return return
static_cast<link&> static_cast<link&>
(LListBase_iterator::operator*()).obj_; (LListBase_iterator::operator*()).obj_;
} }
T& operator()() T& operator()() const
{ {
return operator*(); return operator*();
} }
@ -312,14 +312,14 @@ public:
// Member operators // Member operators
const T& operator*() const T& operator*() const
{ {
return return
static_cast<const link&> static_cast<const link&>
(LListBase_const_iterator::operator*()).obj_; (LListBase_const_iterator::operator*()).obj_;
} }
const T& operator()() const T& operator()() const
{ {
return operator*(); return operator*();
} }

View File

@ -196,12 +196,12 @@ public:
// Member operators // Member operators
T& operator*() T& operator*() const
{ {
return *(LList<LListBase, T*>::iterator::operator*()); return *(LList<LListBase, T*>::iterator::operator*());
} }
T& operator()() T& operator()() const
{ {
return operator*(); return operator*();
} }
@ -235,12 +235,12 @@ public:
// Member operators // Member operators
const T& operator*() const T& operator*() const
{ {
return *(LList<LListBase, T*>::const_iterator::operator*()); return *(LList<LListBase, T*>::const_iterator::operator*());
} }
const T& operator()() const T& operator()() const
{ {
return operator*(); return operator*();
} }

View File

@ -192,12 +192,12 @@ public:
// Member operators // Member operators
T& operator*() T& operator*() const
{ {
return static_cast<T&>(LListBase_iterator::operator*()); return static_cast<T&>(LListBase_iterator::operator*());
} }
T& operator()() T& operator()() const
{ {
return operator*(); return operator*();
} }
@ -247,14 +247,14 @@ public:
// Member operators // Member operators
const T& operator*() const T& operator*() const
{ {
return return
static_cast<const T&> static_cast<const T&>
(LListBase_const_iterator::operator*()); (LListBase_const_iterator::operator*());
} }
const T& operator()() const T& operator()() const
{ {
return operator*(); return operator*();
} }
@ -309,14 +309,14 @@ public:
// Member operators // Member operators
const T& operator*() const T& operator*() const
{ {
return return
static_cast<const T&> static_cast<const T&>
(LListBase::const_reverse_iterator::operator*()); (LListBase::const_reverse_iterator::operator*());
} }
const T& operator()() const T& operator()() const
{ {
return operator*(); return operator*();
} }

View File

@ -188,7 +188,7 @@ Foam::DLListBase::link* Foam::DLListBase::removeHead()
if (!first_) if (!first_)
{ {
last_ = 0; last_ = nullptr;
} }
f->deregister(); f->deregister();
@ -204,8 +204,8 @@ Foam::DLListBase::link* Foam::DLListBase::remove(DLListBase::link* l)
if (l == first_ && first_ == last_) if (l == first_ && first_ == last_)
{ {
first_ = 0; first_ = nullptr;
last_ = 0; last_ = nullptr;
} }
else if (l == first_) else if (l == first_)
{ {

View File

@ -25,9 +25,10 @@ Class
Foam::DLListBase Foam::DLListBase
Description Description
Base doubly-linked list. Base for doubly-linked lists.
SourceFiles SourceFiles
DLListBaseI.H
DLListBase.C DLListBase.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -84,10 +85,10 @@ private:
// Private Member Functions // Private Member Functions
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
DLListBase(const DLListBase&); DLListBase(const DLListBase&) = delete;
//- Disallow default bitwise assignment //- Disallow default bitwise assignment
void operator=(const DLListBase&); void operator=(const DLListBase&) = delete;
public: public:
@ -184,18 +185,14 @@ public:
friend class DLListBase; friend class DLListBase;
friend class const_iterator; friend class const_iterator;
// Private data //- Reference to the list this is an iterator for
DLListBase& curList_;
//- Reference to the list this is an iterator for //- Current element
DLListBase& curList_; link* curElmt_;
//- Current element //- Copy of the link
link* curElmt_; link curLink_;
//- Copy of the link
link curLink_;
// Private Member Functions
//- Construct for a given SLListBase with nullptr element and link. //- Construct for a given SLListBase with nullptr element and link.
// Only used to create endIter // Only used to create endIter
@ -206,17 +203,18 @@ public:
//- Construct for a given DLListBase and link //- Construct for a given DLListBase and link
inline iterator(DLListBase&, link*); inline iterator(DLListBase&, link*);
// Member operators //- Currently pointing at a valid entry
inline bool found() const;
inline void operator=(const iterator&); inline void operator=(const iterator& iter);
inline bool operator==(const iterator&) const; inline bool operator==(const iterator& iter) const;
inline bool operator!=(const iterator&) const; inline bool operator!=(const iterator& iter) const;
inline link& operator*(); inline link& operator*() const;
inline iterator& operator++(); inline iterator& operator++();
inline iterator operator++(int); inline iterator operator++(int);
}; };
inline iterator begin(); inline iterator begin();
@ -228,13 +226,11 @@ public:
//- An STL-conforming const_iterator //- An STL-conforming const_iterator
class const_iterator class const_iterator
{ {
// Private data //- Reference to the list this is an iterator for
const DLListBase& curList_;
//- Reference to the list this is an iterator for //- Current element
const DLListBase& curList_; const link* curElmt_;
//- Current element
const link* curElmt_;
public: public:
@ -242,19 +238,20 @@ public:
inline const_iterator(const DLListBase&, const link*); inline const_iterator(const DLListBase&, const link*);
//- Construct from a non-const iterator //- Construct from a non-const iterator
inline const_iterator(const iterator&); inline const_iterator(const DLListBase::iterator& iter);
// Member operators //- Currently pointing at a valid entry
inline bool found() const;
inline void operator=(const const_iterator&); inline void operator=(const const_iterator& iter);
inline bool operator==(const const_iterator&) const; inline bool operator==(const const_iterator& iter) const;
inline bool operator!=(const const_iterator&) const; inline bool operator!=(const const_iterator& iter) const;
inline const link& operator*(); inline const link& operator*() const;
inline const_iterator& operator++(); inline const_iterator& operator++();
inline const_iterator operator++(int); inline const_iterator operator++(int);
}; };
inline const_iterator cbegin() const; inline const_iterator cbegin() const;
@ -269,30 +266,29 @@ public:
//- An STL-conforming const_reverse_iterator //- An STL-conforming const_reverse_iterator
class const_reverse_iterator class const_reverse_iterator
{ {
// Private data //- Reference to the list this is an reverse_iterator for
const DLListBase& curList_;
//- Reference to the list this is an reverse_iterator for //- Current element
const DLListBase& curList_; const link* curElmt_;
//- Current element
const link* curElmt_;
public: public:
//- Construct for a given DLListBase and link //- Construct for a given DLListBase and link
inline const_reverse_iterator(const DLListBase&, const link*); inline const_reverse_iterator(const DLListBase& lst, const link*);
// Member operators //- Currently pointing at a valid entry
inline bool found() const;
inline void operator=(const const_reverse_iterator&); inline void operator=(const const_reverse_iterator& iter);
inline bool operator==(const const_reverse_iterator&) const; inline bool operator==(const const_reverse_iterator& iter) const;
inline bool operator!=(const const_reverse_iterator&) const; inline bool operator!=(const const_reverse_iterator& iter) const;
inline const link& operator*(); inline const link& operator*() const;
inline const_reverse_iterator& operator++(); inline const_reverse_iterator& operator++();
inline const_reverse_iterator operator++(int); inline const_reverse_iterator operator++(int);
}; };
inline const_reverse_iterator crbegin() const; inline const_reverse_iterator crbegin() const;

View File

@ -29,15 +29,15 @@ License
inline Foam::DLListBase::link::link() inline Foam::DLListBase::link::link()
: :
prev_(0), prev_(nullptr),
next_(0) next_(nullptr)
{} {}
inline Foam::DLListBase::DLListBase() inline Foam::DLListBase::DLListBase()
: :
first_(0), first_(nullptr),
last_(0), last_(nullptr),
nElmts_(0) nElmts_(0)
{} {}
@ -63,14 +63,14 @@ inline Foam::DLListBase::~DLListBase()
inline bool Foam::DLListBase::link::registered() const inline bool Foam::DLListBase::link::registered() const
{ {
return prev_ != 0 && next_ != 0; return prev_ != nullptr && next_ != nullptr;
} }
inline void Foam::DLListBase::link::deregister() inline void Foam::DLListBase::link::deregister()
{ {
prev_ = 0; prev_ = nullptr;
next_ = 0; next_ = nullptr;
} }
@ -140,8 +140,8 @@ Foam::DLListBase::last() const
inline void Foam::DLListBase::clear() inline void Foam::DLListBase::clear()
{ {
first_ = 0; first_ = nullptr;
last_ = 0; last_ = nullptr;
nElmts_ = 0; nElmts_ = 0;
} }
@ -195,6 +195,12 @@ inline Foam::DLListBase::iterator::iterator(DLListBase& s)
{} {}
inline bool Foam::DLListBase::iterator::found() const
{
return (curElmt_ != nullptr);
}
inline void Foam::DLListBase::iterator::operator=(const iterator& iter) inline void Foam::DLListBase::iterator::operator=(const iterator& iter)
{ {
curElmt_ = iter.curElmt_; curElmt_ = iter.curElmt_;
@ -215,7 +221,7 @@ inline bool Foam::DLListBase::iterator::operator!=(const iterator& iter) const
inline Foam::DLListBase::link& inline Foam::DLListBase::link&
Foam::DLListBase::iterator::operator*() Foam::DLListBase::iterator::operator*() const
{ {
return *curElmt_; return *curElmt_;
} }
@ -226,9 +232,9 @@ Foam::DLListBase::iterator::operator++()
{ {
// Check if the curElmt_ is the last element (if it points to itself) // Check if the curElmt_ is the last element (if it points to itself)
// or if the list is empty because the last element may have been removed // or if the list is empty because the last element may have been removed
if (curLink_.next_ == curElmt_ || curList_.last_ == 0) if (curLink_.next_ == curElmt_ || curList_.last_ == nullptr)
{ {
curElmt_ = 0; curElmt_ = nullptr;
} }
else else
{ {
@ -282,13 +288,22 @@ inline Foam::DLListBase::const_iterator::const_iterator
{} {}
inline Foam::DLListBase::const_iterator::const_iterator(const iterator& iter) inline Foam::DLListBase::const_iterator::const_iterator
(
const DLListBase::iterator& iter
)
: :
curList_(iter.curList_), curList_(iter.curList_),
curElmt_(iter.curElmt_) curElmt_(iter.curElmt_)
{} {}
inline bool Foam::DLListBase::const_iterator::found() const
{
return (curElmt_ != nullptr);
}
inline void Foam::DLListBase::const_iterator::operator= inline void Foam::DLListBase::const_iterator::operator=
( (
const const_iterator& iter const const_iterator& iter
@ -317,7 +332,7 @@ inline bool Foam::DLListBase::const_iterator::operator!=
inline const Foam::DLListBase::link& inline const Foam::DLListBase::link&
Foam::DLListBase::const_iterator::operator*() Foam::DLListBase::const_iterator::operator*() const
{ {
return *curElmt_; return *curElmt_;
} }
@ -328,7 +343,7 @@ Foam::DLListBase::const_iterator::operator++()
{ {
if (curElmt_ == curList_.last_) if (curElmt_ == curList_.last_)
{ {
curElmt_ = 0; curElmt_ = nullptr;
} }
else else
{ {
@ -387,15 +402,21 @@ Foam::DLListBase::end() const
inline Foam::DLListBase::const_reverse_iterator::const_reverse_iterator inline Foam::DLListBase::const_reverse_iterator::const_reverse_iterator
( (
const DLListBase& s, const DLListBase& lst,
const link* elmt const link* elmt
) )
: :
curList_(s), curList_(lst),
curElmt_(elmt) curElmt_(elmt)
{} {}
inline bool Foam::DLListBase::const_reverse_iterator::found() const
{
return (curElmt_ != nullptr);
}
inline void Foam::DLListBase::const_reverse_iterator::operator= inline void Foam::DLListBase::const_reverse_iterator::operator=
( (
const const_reverse_iterator& iter const const_reverse_iterator& iter
@ -424,7 +445,7 @@ inline bool Foam::DLListBase::const_reverse_iterator::operator!=
inline const Foam::DLListBase::link& inline const Foam::DLListBase::link&
Foam::DLListBase::const_reverse_iterator::operator*() Foam::DLListBase::const_reverse_iterator::operator*() const
{ {
return *curElmt_; return *curElmt_;
} }
@ -435,7 +456,7 @@ Foam::DLListBase::const_reverse_iterator::operator++()
{ {
if (curElmt_ == curList_.first_) if (curElmt_ == curList_.first_)
{ {
curElmt_ = 0; curElmt_ = nullptr;
} }
else else
{ {
@ -460,7 +481,7 @@ Foam::DLListBase::crbegin() const
{ {
if (size()) if (size())
{ {
return const_reverse_iterator(*this, last()); return const_reverse_iterator(*this, this->last());
} }
else else
{ {

View File

@ -79,7 +79,7 @@ Foam::SLListBase::link* Foam::SLListBase::removeHead()
{ {
nElmts_--; nElmts_--;
if (last_ == 0) if (last_ == nullptr)
{ {
FatalErrorInFunction FatalErrorInFunction
<< "remove from empty list" << "remove from empty list"
@ -90,7 +90,7 @@ Foam::SLListBase::link* Foam::SLListBase::removeHead()
if (f == last_) if (f == last_)
{ {
last_ = 0; last_ = nullptr;
} }
else else
{ {
@ -132,7 +132,7 @@ Foam::SLListBase::link* Foam::SLListBase::remove(SLListBase::link* it)
prev = p; prev = p;
} }
return 0; return nullptr;
} }

View File

@ -25,9 +25,10 @@ Class
Foam::SLListBase Foam::SLListBase
Description Description
Base singly-linked list. Base for singly-linked lists.
SourceFiles SourceFiles
SLListBaseI.H
SLListBase.C SLListBase.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -81,10 +82,10 @@ private:
// Private Member Functions // Private Member Functions
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
SLListBase(const SLListBase&); SLListBase(const SLListBase&) = delete;
//- Disallow default bitwise assignment //- Disallow default bitwise assignment
void operator=(const SLListBase&); void operator=(const SLListBase&) = delete;
public: public:
@ -166,18 +167,14 @@ public:
friend class SLListBase; friend class SLListBase;
friend class const_iterator; friend class const_iterator;
// Private data //- Reference to the list this is an iterator for
SLListBase& curList_;
//- Reference to the list this is an iterator for //- Current element
SLListBase& curList_; link* curElmt_;
//- Current element //- Copy of the link
link* curElmt_; link curLink_;
//- Copy of the link
link curLink_;
// Private Member Functions
//- Construct for a given SLListBase with nullptr element and link. //- Construct for a given SLListBase with nullptr element and link.
// Only used to create endIter // Only used to create endIter
@ -188,17 +185,18 @@ public:
//- Construct for a given SLListBase and link //- Construct for a given SLListBase and link
inline iterator(SLListBase&, link*); inline iterator(SLListBase&, link*);
// Member operators //- Currently pointing at a valid entry
inline bool found() const;
inline void operator=(const iterator&); inline void operator=(const iterator& iter);
inline bool operator==(const iterator&) const; inline bool operator==(const iterator& iter) const;
inline bool operator!=(const iterator&) const; inline bool operator!=(const iterator& iter) const;
inline link& operator*(); inline link& operator*() const;
inline iterator& operator++(); inline iterator& operator++();
inline iterator operator++(int); inline iterator operator++(int);
}; };
inline iterator begin(); inline iterator begin();
@ -210,13 +208,11 @@ public:
//- An STL-conforming const_iterator //- An STL-conforming const_iterator
class const_iterator class const_iterator
{ {
// Private data //- Reference to the list this is an iterator for
const SLListBase& curList_;
//- Reference to the list this is an iterator for //- Current element
const SLListBase& curList_; const link* curElmt_;
//- Current element
const link* curElmt_;
public: public:
@ -224,20 +220,20 @@ public:
inline const_iterator(const SLListBase&, const link*); inline const_iterator(const SLListBase&, const link*);
//- Construct from a non-const iterator //- Construct from a non-const iterator
inline const_iterator(const iterator&); inline const_iterator(const SLListBase::iterator& iter);
//- Currently pointing at a valid entry
inline bool found() const;
// Member operators inline void operator=(const const_iterator& iter);
inline void operator=(const const_iterator&); inline bool operator==(const const_iterator& iter) const;
inline bool operator!=(const const_iterator& iter) const;
inline bool operator==(const const_iterator&) const; inline const link& operator*() const;
inline bool operator!=(const const_iterator&) const;
inline const link& operator*(); inline const_iterator& operator++();
inline const_iterator operator++(int);
inline const_iterator& operator++();
inline const_iterator operator++(int);
}; };
inline const_iterator cbegin() const; inline const_iterator cbegin() const;

View File

@ -21,9 +21,6 @@ License
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
Base singly-linked list.
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "error.H" #include "error.H"
@ -32,7 +29,7 @@ Description
inline Foam::SLListBase::link::link() inline Foam::SLListBase::link::link()
: :
next_(0) next_(nullptr)
{} {}
@ -44,16 +41,22 @@ inline Foam::SLListBase::link::link(link* p)
inline Foam::SLListBase::SLListBase() inline Foam::SLListBase::SLListBase()
: :
last_(0), last_(nullptr),
nElmts_(0) nElmts_(0)
{} {}
inline Foam::SLListBase::SLListBase(link* a) inline Foam::SLListBase::SLListBase(link* a)
: :
last_(a->next_ = a), last_(a),
nElmts_(1) nElmts_(0)
{} {
if (a) // protect against nullptr
{
a->next_ = a;
nElmts_ = 1;
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
@ -130,7 +133,7 @@ Foam::SLListBase::last() const
inline void Foam::SLListBase::clear() inline void Foam::SLListBase::clear()
{ {
last_ = 0; last_ = nullptr;
nElmts_ = 0; nElmts_ = 0;
} }
@ -171,6 +174,12 @@ inline Foam::SLListBase::iterator::iterator(SLListBase& s)
{} {}
inline bool Foam::SLListBase::iterator::found() const
{
return (curElmt_ != nullptr);
}
inline void Foam::SLListBase::iterator::operator=(const iterator& iter) inline void Foam::SLListBase::iterator::operator=(const iterator& iter)
{ {
curElmt_ = iter.curElmt_; curElmt_ = iter.curElmt_;
@ -190,7 +199,7 @@ inline bool Foam::SLListBase::iterator::operator!=(const iterator& iter) const
} }
inline Foam::SLListBase::link& Foam::SLListBase::iterator::operator*() inline Foam::SLListBase::link& Foam::SLListBase::iterator::operator*() const
{ {
return *curElmt_; return *curElmt_;
} }
@ -198,9 +207,9 @@ inline Foam::SLListBase::link& Foam::SLListBase::iterator::operator*()
inline Foam::SLListBase::iterator& Foam::SLListBase::iterator::operator++() inline Foam::SLListBase::iterator& Foam::SLListBase::iterator::operator++()
{ {
if (curElmt_ == curList_.last_ || curList_.last_ == 0) if (curElmt_ == curList_.last_ || curList_.last_ == nullptr)
{ {
curElmt_ = 0; curElmt_ = nullptr;
} }
else else
{ {
@ -255,13 +264,22 @@ inline Foam::SLListBase::const_iterator::const_iterator
{} {}
inline Foam::SLListBase::const_iterator::const_iterator(const iterator& iter) inline Foam::SLListBase::const_iterator::const_iterator
(
const SLListBase::iterator& iter
)
: :
curList_(iter.curList_), curList_(iter.curList_),
curElmt_(iter.curElmt_) curElmt_(iter.curElmt_)
{} {}
inline bool Foam::SLListBase::const_iterator::found() const
{
return (curElmt_ != nullptr);
}
inline void Foam::SLListBase::const_iterator::operator= inline void Foam::SLListBase::const_iterator::operator=
( (
const const_iterator& iter const const_iterator& iter
@ -290,7 +308,7 @@ inline bool Foam::SLListBase::const_iterator::operator!=
inline const Foam::SLListBase::link& inline const Foam::SLListBase::link&
Foam::SLListBase::const_iterator::operator*() Foam::SLListBase::const_iterator::operator*() const
{ {
return *curElmt_; return *curElmt_;
} }
@ -301,7 +319,7 @@ Foam::SLListBase::const_iterator::operator++()
{ {
if (curElmt_ == curList_.last_) if (curElmt_ == curList_.last_)
{ {
curElmt_ = 0; curElmt_ = nullptr;
} }
else else
{ {

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -59,14 +59,14 @@ class DynamicList;
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
Ostream& operator<< Ostream& operator<<
( (
Ostream&, Ostream& os,
const DynamicList<T, SizeInc, SizeMult, SizeDiv>& const DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
); );
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
Istream& operator>> Istream& operator>>
( (
Istream&, Istream& is,
DynamicList<T, SizeInc, SizeMult, SizeDiv>& DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
); );
@ -105,29 +105,37 @@ public:
inline DynamicList(); inline DynamicList();
//- Construct given size. //- Construct given size.
explicit inline DynamicList(const label); explicit inline DynamicList(const label nElem);
//- Construct with given size and value for all elements. //- Construct with given size and value for all elements.
inline DynamicList(const label, const T&); inline DynamicList(const label nElem, const T& a);
//- Construct copy. //- Construct copy.
inline DynamicList(const DynamicList<T, SizeInc, SizeMult, SizeDiv>&); inline DynamicList
(
const DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
);
//- Construct from UList. Size set to UList size. //- Construct from UList. Size set to UList size.
// Also constructs from DynamicList with different sizing parameters. // Also constructs from DynamicList with different sizing parameters.
explicit inline DynamicList(const UList<T>&); explicit inline DynamicList(const UList<T>& lst);
//- Construct given begin/end iterators.
// Uses std::distance to determine the size.
template<class InputIterator>
inline DynamicList(InputIterator begIter, InputIterator endIter);
//- Construct from an initializer list. Size set to list size. //- Construct from an initializer list. Size set to list size.
explicit inline DynamicList(std::initializer_list<T>); explicit inline DynamicList(std::initializer_list<T> lst);
//- Construct from UIndirectList. Size set to UIndirectList size. //- Construct from UIndirectList. Size set to UIndirectList size.
explicit inline DynamicList(const UIndirectList<T>&); explicit inline DynamicList(const UIndirectList<T>& lst);
//- Construct by transferring the parameter contents //- Construct by transferring the parameter contents
explicit inline DynamicList(const Xfer<List<T>>&); explicit inline DynamicList(const Xfer<List<T>>& lst);
//- Construct from Istream. Size set to size of list read. //- Construct from Istream. Size set to size of list read.
explicit DynamicList(Istream&); explicit DynamicList(Istream& is);
// Member Functions // Member Functions
@ -143,31 +151,31 @@ public:
// The addressed size will be truncated if needed to fit, but will // The addressed size will be truncated if needed to fit, but will
// remain otherwise untouched. // remain otherwise untouched.
// Use this or reserve() in combination with append(). // Use this or reserve() in combination with append().
inline void setCapacity(const label); inline void setCapacity(const label nElem);
//- Alter the addressed list size. //- Alter the addressed list size.
// New space will be allocated if required. // New space will be allocated if required.
// Use this to resize the list prior to using the operator[] for // Use this to resize the list prior to using the operator[] for
// setting values (as per List usage). // setting values (as per List usage).
inline void setSize(const label); inline void setSize(const label nElem);
//- Alter the addressed list size and fill new space with a //- Alter the addressed list size and fill new space with a
// constant. // constant.
inline void setSize(const label, const T&); inline void setSize(const label nElem, const T& t);
//- Alter the addressed list size. //- Alter the addressed list size.
// New space will be allocated if required. // New space will be allocated if required.
// Use this to resize the list prior to using the operator[] for // Use this to resize the list prior to using the operator[] for
// setting values (as per List usage). // setting values (as per List usage).
inline void resize(const label); inline void resize(const label nElem);
//- Alter the addressed list size and fill new space with a //- Alter the addressed list size and fill new space with a
// constant. // constant.
inline void resize(const label, const T&); inline void resize(const label nElem, const T& t);
//- Reserve allocation space for at least this size. //- Reserve allocation space for at least this size.
// Never shrinks the allocated size, use setCapacity() for that. // Never shrinks the allocated size, use setCapacity() for that.
inline void reserve(const label); inline void reserve(const label nElem);
//- Clear the addressed list, i.e. set the size to zero. //- Clear the addressed list, i.e. set the size to zero.
// Allocated size does not change // Allocated size does not change
@ -181,10 +189,13 @@ public:
inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& shrink(); inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& shrink();
//- Transfer contents of the argument List into this. //- Transfer contents of the argument List into this.
inline void transfer(List<T>&); inline void transfer(List<T>& lst);
//- Transfer contents of the argument DynamicList into this. //- Transfer contents of the argument DynamicList into this.
inline void transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>&); inline void transfer
(
DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
);
//- Transfer contents to the Xfer container as a plain List //- Transfer contents to the Xfer container as a plain List
inline Xfer<List<T>> xfer(); inline Xfer<List<T>> xfer();
@ -195,25 +206,25 @@ public:
//- Append an element at the end of the list //- Append an element at the end of the list
inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& append inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& append
( (
const T& const T& t
); );
//- Append a List at the end of this list //- Append a List at the end of this list
inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& append inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& append
( (
const UList<T>& const UList<T>& lst
); );
//- Append an initializer list at the end of this list. //- Append an initializer list at the end of this list.
inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& append inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& append
( (
std::initializer_list<T> std::initializer_list<T> lst
); );
//- Append a UIndirectList at the end of this list //- Append a UIndirectList at the end of this list
inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& append inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& append
( (
const UIndirectList<T>& const UIndirectList<T>& lst
); );
//- Remove and return the top element //- Remove and return the top element
@ -221,32 +232,35 @@ public:
//- Return non-const access to an element, resizing list if //- Return non-const access to an element, resizing list if
// necessary // necessary
inline T& operator()(const label); inline T& operator()(const label elemI);
//- Assignment of all addressed entries to the given value //- Assignment of all addressed entries to the given value
inline void operator=(const T&); inline void operator=(const T& t);
//- Assignment to DynamicList //- Assignment to DynamicList
inline void operator= inline void operator=
( (
const DynamicList<T, SizeInc, SizeMult, SizeDiv>& const DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
); );
//- Assignment to UList //- Assignment to UList
inline void operator=(const UList<T>&); inline void operator=(const UList<T>& lst);
//- Assignment from initializer list //- Assignment from initializer list
inline void operator=(std::initializer_list<T>); inline void operator=(std::initializer_list<T> lst);
//- Assignment to UIndirectList //- Assignment to UIndirectList
inline void operator=(const UIndirectList<T>&); inline void operator=(const UIndirectList<T>& lst);
// STL member functions // STL member functions
//- Erase an element, move the remaining elements to fill the gap //- Erase an element, move the remaining elements to fill the gap
// and resize the List // and resize the List
typename UList<T>::iterator erase(typename UList<T>::iterator); typename UList<T>::iterator erase
(
typename UList<T>::iterator curIter
);
// IOstream operators // IOstream operators
@ -254,15 +268,15 @@ public:
// Write DynamicList to Ostream. // Write DynamicList to Ostream.
friend Ostream& operator<< <T, SizeInc, SizeMult, SizeDiv> friend Ostream& operator<< <T, SizeInc, SizeMult, SizeDiv>
( (
Ostream&, Ostream& os,
const DynamicList<T, SizeInc, SizeMult, SizeDiv>& const DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
); );
//- Read from Istream, discarding contents of existing DynamicList. //- Read from Istream, discarding contents of existing DynamicList.
friend Istream& operator>> <T, SizeInc, SizeMult, SizeDiv> friend Istream& operator>> <T, SizeInc, SizeMult, SizeDiv>
( (
Istream&, Istream& is,
DynamicList<T, SizeInc, SizeMult, SizeDiv>& DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
); );
}; };

View File

@ -80,6 +80,19 @@ inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList
{} {}
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
template<class InputIterator>
inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList
(
InputIterator begIter,
InputIterator endIter
)
:
List<T>(begIter, endIter),
capacity_(this->size())
{}
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList
( (

View File

@ -128,11 +128,12 @@ public:
explicit inline FixedList(const T& t); explicit inline FixedList(const T& t);
//- Construct from C-array //- Construct from C-array
explicit inline FixedList(const T v[Size]); explicit inline FixedList(const T lst[Size]);
//- Construct given start and end iterators //- Construct given begin/end iterators
// Uses std::distance when verifying the size.
template<class InputIterator> template<class InputIterator>
inline FixedList(InputIterator first, InputIterator last); inline FixedList(InputIterator begIter, InputIterator endIter);
//- Construct from an initializer list //- Construct from an initializer list
inline FixedList(std::initializer_list<T> lst); inline FixedList(std::initializer_list<T> lst);

View File

@ -37,7 +37,7 @@ inline Foam::FixedList<T, Size>::FixedList()
template<class T, unsigned Size> template<class T, unsigned Size>
inline Foam::FixedList<T, Size>::FixedList(const T& t) inline Foam::FixedList<T, Size>::FixedList(const T& t)
{ {
for (unsigned i=0; i<Size; i++) for (unsigned i=0; i<Size; ++i)
{ {
v_[i] = t; v_[i] = t;
} }
@ -45,11 +45,11 @@ inline Foam::FixedList<T, Size>::FixedList(const T& t)
template<class T, unsigned Size> template<class T, unsigned Size>
inline Foam::FixedList<T, Size>::FixedList(const T v[Size]) inline Foam::FixedList<T, Size>::FixedList(const T lst[Size])
{ {
for (unsigned i=0; i<Size; i++) for (unsigned i=0; i<Size; ++i)
{ {
v_[i] = v[i]; v_[i] = lst[i];
} }
} }
@ -58,25 +58,33 @@ template<class T, unsigned Size>
template<class InputIterator> template<class InputIterator>
Foam::FixedList<T, Size>::FixedList Foam::FixedList<T, Size>::FixedList
( (
InputIterator first, InputIterator begIter,
InputIterator last InputIterator endIter
) )
{ {
checkSize(std::distance(first, last)); checkSize(std::distance(begIter, endIter));
InputIterator iter = first; InputIterator iter = begIter;
for (unsigned i=0; i<Size; i++) for (unsigned i=0; i<Size; ++i)
{ {
v_[i] = *iter++; v_[i] = *iter;
++iter;
} }
} }
template<class T, unsigned Size> template<class T, unsigned Size>
inline Foam::FixedList<T, Size>::FixedList(std::initializer_list<T> lst) inline Foam::FixedList<T, Size>::FixedList(std::initializer_list<T> lst)
: {
FixedList<T, Size>(lst.begin(), lst.end()) checkSize(lst.size());
{}
auto iter = lst.begin();
for (unsigned i=0; i<Size; ++i)
{
v_[i] = *iter;
++iter;
}
}
template<class T, unsigned Size> template<class T, unsigned Size>
@ -84,7 +92,7 @@ inline Foam::FixedList<T, Size>::FixedList(const UList<T>& lst)
{ {
checkSize(lst.size()); checkSize(lst.size());
for (unsigned i=0; i<Size; i++) for (unsigned i=0; i<Size; ++i)
{ {
v_[i] = lst[i]; v_[i] = lst[i];
} }
@ -97,9 +105,10 @@ inline Foam::FixedList<T, Size>::FixedList(const SLList<T>& lst)
checkSize(lst.size()); checkSize(lst.size());
typename SLList<T>::const_iterator iter = lst.begin(); typename SLList<T>::const_iterator iter = lst.begin();
for (unsigned i=0; i<Size; i++) for (unsigned i=0; i<Size; ++i)
{ {
v_[i] = *iter++; v_[i] = *iter;
++iter;
} }
} }
@ -107,7 +116,7 @@ inline Foam::FixedList<T, Size>::FixedList(const SLList<T>& lst)
template<class T, unsigned Size> template<class T, unsigned Size>
inline Foam::FixedList<T, Size>::FixedList(const FixedList<T, Size>& lst) inline Foam::FixedList<T, Size>::FixedList(const FixedList<T, Size>& lst)
{ {
for (unsigned i=0; i<Size; i++) for (unsigned i=0; i<Size; ++i)
{ {
v_[i] = lst[i]; v_[i] = lst[i];
} }
@ -200,7 +209,7 @@ inline void Foam::FixedList<T, Size>::setSize(const label s)
template<class T, unsigned Size> template<class T, unsigned Size>
inline void Foam::FixedList<T, Size>::transfer(const FixedList<T, Size>& lst) inline void Foam::FixedList<T, Size>::transfer(const FixedList<T, Size>& lst)
{ {
for (unsigned i=0; i<Size; i++) for (unsigned i=0; i<Size; ++i)
{ {
v_[i] = lst[i]; v_[i] = lst[i];
} }
@ -276,7 +285,7 @@ inline const T& Foam::FixedList<T, Size>::operator[](const label i) const
template<class T, unsigned Size> template<class T, unsigned Size>
inline void Foam::FixedList<T, Size>::operator=(const T lst[Size]) inline void Foam::FixedList<T, Size>::operator=(const T lst[Size])
{ {
for (unsigned i=0; i<Size; i++) for (unsigned i=0; i<Size; ++i)
{ {
v_[i] = lst[i]; v_[i] = lst[i];
} }
@ -287,7 +296,7 @@ inline void Foam::FixedList<T, Size>::operator=(const UList<T>& lst)
{ {
checkSize(lst.size()); checkSize(lst.size());
for (unsigned i=0; i<Size; i++) for (unsigned i=0; i<Size; ++i)
{ {
v_[i] = lst[i]; v_[i] = lst[i];
} }
@ -299,9 +308,10 @@ inline void Foam::FixedList<T, Size>::operator=(const SLList<T>& lst)
checkSize(lst.size()); checkSize(lst.size());
typename SLList<T>::const_iterator iter = lst.begin(); typename SLList<T>::const_iterator iter = lst.begin();
for (unsigned i=0; i<Size; i++) for (unsigned i=0; i<Size; ++i)
{ {
v_[i] = *iter++; v_[i] = *iter;
++iter;
} }
} }
@ -310,17 +320,18 @@ inline void Foam::FixedList<T, Size>::operator=(std::initializer_list<T> lst)
{ {
checkSize(lst.size()); checkSize(lst.size());
typename std::initializer_list<T>::iterator iter = lst.begin(); auto iter = lst.begin();
for (unsigned i=0; i<Size; i++) for (unsigned i=0; i<Size; ++i)
{ {
v_[i] = *iter++; v_[i] = *iter;
++iter;
} }
} }
template<class T, unsigned Size> template<class T, unsigned Size>
inline void Foam::FixedList<T, Size>::operator=(const T& t) inline void Foam::FixedList<T, Size>::operator=(const T& t)
{ {
for (unsigned i=0; i<Size; i++) for (unsigned i=0; i<Size; ++i)
{ {
v_[i] = t; v_[i] = t;
} }
@ -464,7 +475,7 @@ inline unsigned Foam::FixedList<T, Size>::Hash<HashT>::operator()
// Hash incrementally // Hash incrementally
unsigned val = seed; unsigned val = seed;
for (unsigned i=0; i<Size; i++) for (unsigned i=0; i<Size; ++i)
{ {
val = HashT()(lst[i], val); val = HashT()(lst[i], val);
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -160,7 +160,7 @@ Foam::List<T>::List(List<T>& a, bool reuse)
if (reuse) if (reuse)
{ {
this->v_ = a.v_; this->v_ = a.v_;
a.v_ = 0; a.v_ = nullptr;
a.size_ = 0; a.size_ = 0;
} }
else if (this->size_) else if (this->size_)
@ -186,19 +186,19 @@ Foam::List<T>::List(List<T>& a, bool reuse)
template<class T> template<class T>
Foam::List<T>::List(const UList<T>& a, const labelUList& map) Foam::List<T>::List(const UList<T>& a, const labelUList& mapAddressing)
: :
UList<T>(nullptr, map.size()) UList<T>(nullptr, mapAddressing.size())
{ {
if (this->size_) if (this->size_)
{ {
// Note:cannot use List_ELEM since third argument has to be index. // Note: cannot use List_ELEM since third argument has to be index.
alloc(); alloc();
forAll(*this, i) forAll(*this, i)
{ {
this->operator[](i) = a[map[i]]; this->operator[](i) = a[mapAddressing[i]];
} }
} }
} }
@ -206,9 +206,9 @@ Foam::List<T>::List(const UList<T>& a, const labelUList& map)
template<class T> template<class T>
template<class InputIterator> template<class InputIterator>
Foam::List<T>::List(InputIterator first, InputIterator last) Foam::List<T>::List(InputIterator begIter, InputIterator endIter)
: :
List<T>(first, last, std::distance(first, last)) List<T>(begIter, endIter, std::distance(begIter, endIter))
{} {}
@ -231,6 +231,8 @@ Foam::List<T>::List(const PtrList<T>& lst)
} }
// Note: using first/last is not entirely accurate.
// But since the list size is correct, last() is actually ignored.
template<class T> template<class T>
Foam::List<T>::List(const SLList<T>& lst) Foam::List<T>::List(const SLList<T>& lst)
: :
@ -259,7 +261,7 @@ Foam::List<T>::List(const BiIndirectList<T>& lst)
template<class T> template<class T>
Foam::List<T>::List(std::initializer_list<T> lst) Foam::List<T>::List(std::initializer_list<T> lst)
: :
List<T>(lst.begin(), lst.end()) List<T>(lst.begin(), lst.end(), lst.size())
{} {}
@ -326,7 +328,7 @@ void Foam::List<T>::setSize(const label newSize)
template<class T> template<class T>
void Foam::List<T>::setSize(const label newSize, const T& a) void Foam::List<T>::setSize(const label newSize, const T& a)
{ {
label oldSize = label(this->size_); const label oldSize = label(this->size_);
this->setSize(newSize); this->setSize(newSize);
if (newSize > oldSize) if (newSize > oldSize)
@ -346,7 +348,7 @@ void Foam::List<T>::transfer(List<T>& a)
this->v_ = a.v_; this->v_ = a.v_;
a.size_ = 0; a.size_ = 0;
a.v_ = 0; a.v_ = nullptr;
} }
@ -419,14 +421,9 @@ void Foam::List<T>::operator=(const SLList<T>& lst)
if (this->size_) if (this->size_)
{ {
label i = 0; label i = 0;
for for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter)
(
typename SLList<T>::const_iterator iter = lst.begin();
iter != lst.end();
++iter
)
{ {
this->operator[](i++) = iter(); this->operator[](i++) = *iter;
} }
} }
} }
@ -453,10 +450,11 @@ void Foam::List<T>::operator=(std::initializer_list<T> lst)
{ {
reAlloc(lst.size()); reAlloc(lst.size());
typename std::initializer_list<T>::iterator iter = lst.begin(); auto iter = lst.begin();
forAll(*this, i) forAll(*this, i)
{ {
this->operator[](i) = *iter++; this->operator[](i) = *iter;
++iter;
} }
} }

View File

@ -58,7 +58,7 @@ class Ostream;
// Forward declaration of friend functions and operators // Forward declaration of friend functions and operators
template<class T> class List; template<class T> class List;
template<class T> Istream& operator>>(Istream&, List<T>&); template<class T> Istream& operator>>(Istream& is, List<T>& L);
template<class T, unsigned Size> class FixedList; template<class T, unsigned Size> class FixedList;
template<class T> class PtrList; template<class T> class PtrList;
@ -95,22 +95,28 @@ class List
//- Copy list of given type //- Copy list of given type
template<class List2> template<class List2>
inline void copyList(const List2&); inline void copyList(const List2& lst);
//- Allocate storage and copy list of given type //- Allocate storage and copy list of given type
template<class List2> template<class List2>
inline void allocCopyList(const List2&); inline void allocCopyList(const List2& lst);
//- Construct given start and end iterators and number of elements //- Construct given begin/end iterators and number of elements
// Since the size is provided, the end iterator is actually ignored.
template<class InputIterator> template<class InputIterator>
inline List(InputIterator first, InputIterator last, const label s); inline List
(
InputIterator begIter,
InputIterator endIter,
const label s
);
protected: protected:
//- Override size to be inconsistent with allocated storage. //- Override size to be inconsistent with allocated storage.
// Use with care // Use with care
inline void size(const label); inline void size(const label n);
public: public:
@ -127,55 +133,56 @@ public:
inline List(); inline List();
//- Construct with given size //- Construct with given size
explicit List(const label); explicit List(const label s);
//- Construct with given size and value for all elements //- Construct with given size and value for all elements
List(const label, const T&); List(const label s, const T& a);
//- Construct with given size initializing all elements to zero //- Construct with given size initializing all elements to zero
List(const label, const zero); List(const label s, const zero);
//- Copy constructor //- Copy constructor
List(const List<T>&); List(const List<T>& a);
//- Copy constructor from list containing another type //- Copy constructor from list containing another type
template<class T2> template<class T2>
explicit List(const List<T2>&); explicit List(const List<T2>& a);
//- Construct by transferring the parameter contents //- Construct by transferring the parameter contents
List(const Xfer<List<T>>&); List(const Xfer<List<T>>& lst);
//- Construct as copy or re-use as specified //- Construct as copy or re-use as specified
List(List<T>&, bool reuse); List(List<T>& a, bool reuse);
//- Construct as subset //- Construct as subset
List(const UList<T>&, const labelUList& mapAddressing); List(const UList<T>& a, const labelUList& mapAddressing);
//- Construct given start and end iterators //- Construct given begin/end iterators.
// Uses std::distance to determine the size.
template<class InputIterator> template<class InputIterator>
List(InputIterator first, InputIterator last); List(InputIterator begIter, InputIterator endIter);
//- Construct as copy of FixedList<T, Size> //- Construct as copy of FixedList<T, Size>
template<unsigned Size> template<unsigned Size>
explicit List(const FixedList<T, Size>&); explicit List(const FixedList<T, Size>& lst);
//- Construct as copy of PtrList<T> //- Construct as copy of PtrList<T>
explicit List(const PtrList<T>&); explicit List(const PtrList<T>& lst);
//- Construct as copy of SLList<T> //- Construct as copy of SLList<T>
explicit List(const SLList<T>&); explicit List(const SLList<T>& lst);
//- Construct as copy of UIndirectList<T> //- Construct as copy of UIndirectList<T>
explicit List(const UIndirectList<T>&); explicit List(const UIndirectList<T>& lst);
//- Construct as copy of BiIndirectList<T> //- Construct as copy of BiIndirectList<T>
explicit List(const BiIndirectList<T>&); explicit List(const BiIndirectList<T>& lst);
//- Construct from an initializer list //- Construct from an initializer list
List(std::initializer_list<T>); List(std::initializer_list<T> lst);
//- Construct from Istream //- Construct from Istream
List(Istream&); List(Istream& is);
//- Clone //- Clone
inline autoPtr<List<T>> clone() const; inline autoPtr<List<T>> clone() const;
@ -200,47 +207,48 @@ public:
// Edit // Edit
//- Alias for setSize(const label) //- Alias for setSize(const label)
inline void resize(const label); inline void resize(const label newSize);
//- Alias for setSize(const label, const T&) //- Alias for setSize(const label, const T&)
inline void resize(const label, const T&); inline void resize(const label newSize, const T& a);
//- Reset size of List //- Reset size of List
void setSize(const label); void setSize(const label newSize);
//- Reset size of List and value for new elements //- Reset size of List and value for new elements
void setSize(const label, const T&); void setSize(const label newSize, const T& a);
//- Clear the list, i.e. set size to zero //- Clear the list, i.e. set size to zero
inline void clear(); inline void clear();
//- Append an element at the end of the list //- Append an element at the end of the list
inline void append(const T&); inline void append(const T& t);
//- Append a List at the end of this list //- Append a List at the end of this list
inline void append(const UList<T>&); inline void append(const UList<T>& lst);
//- Append a UIndirectList at the end of this list //- Append a UIndirectList at the end of this list
inline void append(const UIndirectList<T>&); inline void append(const UIndirectList<T>& lst);
//- Transfer the contents of the argument List into this list //- Transfer the contents of the argument List into this list
// and annul the argument list // and annul the argument list
void transfer(List<T>&); void transfer(List<T>& a);
//- Transfer the contents of the argument List into this list //- Transfer the contents of the argument List into this list
// and annul the argument list // and annul the argument list
template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
void transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>&); void transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>& a);
//- Transfer the contents of the argument List into this list //- Transfer the contents of the argument List into this list
// and annul the argument list // and annul the argument list
void transfer(SortableList<T>&); void transfer(SortableList<T>& a);
//- Transfer contents to the Xfer container //- Transfer contents to the Xfer container
inline Xfer<List<T>> xfer(); inline Xfer<List<T>> xfer();
//- Return subscript-checked element of UList //- Return subscript-checked element of UList.
inline T& newElmt(const label); // Resize list if required.
inline T& newElmt(const label i);
//- Disallow implicit shallowCopy //- Disallow implicit shallowCopy
@ -250,25 +258,25 @@ public:
// Member operators // Member operators
//- Assignment to UList operator. Takes linear time //- Assignment to UList operator. Takes linear time
void operator=(const UList<T>&); void operator=(const UList<T>& a);
//- Assignment operator. Takes linear time //- Assignment operator. Takes linear time
void operator=(const List<T>&); void operator=(const List<T>& a);
//- Assignment to SLList operator. Takes linear time //- Assignment to SLList operator. Takes linear time
void operator=(const SLList<T>&); void operator=(const SLList<T>& lst);
//- Assignment to UIndirectList operator. Takes linear time //- Assignment to UIndirectList operator. Takes linear time
void operator=(const UIndirectList<T>&); void operator=(const UIndirectList<T>& lst);
//- Assignment to BiIndirectList operator. Takes linear time //- Assignment to BiIndirectList operator. Takes linear time
void operator=(const BiIndirectList<T>&); void operator=(const BiIndirectList<T>& lst);
//- Assignment to an initializer list //- Assignment to an initializer list
void operator=(std::initializer_list<T>); void operator=(std::initializer_list<T> lst);
//- Assignment of all entries to the given value //- Assignment of all entries to the given value
inline void operator=(const T&); inline void operator=(const T& t);
//- Assignment of all entries to zero //- Assignment of all entries to zero
inline void operator=(const zero); inline void operator=(const zero);
@ -278,7 +286,7 @@ public:
//- Read List from Istream, discarding contents of existing List //- Read List from Istream, discarding contents of existing List
friend Istream& operator>> <T> friend Istream& operator>> <T>
(Istream&, List<T>&); (Istream& is, List<T>& L);
}; };
@ -290,7 +298,7 @@ public:
// \endcode // \endcode
// Mostly useful for handling command-line arguments // Mostly useful for handling command-line arguments
template<class T> template<class T>
List<T> readList(Istream&); List<T> readList(Istream& is);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -77,8 +77,8 @@ template<class T>
template<class InputIterator> template<class InputIterator>
inline Foam::List<T>::List inline Foam::List<T>::List
( (
InputIterator first, InputIterator begIter,
InputIterator last, InputIterator endIter,
const label s const label s
) )
: :
@ -88,10 +88,11 @@ inline Foam::List<T>::List
{ {
alloc(); alloc();
InputIterator iter = first; InputIterator iter = begIter;
forAll(*this, i) forAll(*this, i)
{ {
this->operator[](i) = *iter++; this->operator[](i) = *iter;
++iter;
} }
} }
} }
@ -126,7 +127,7 @@ inline void Foam::List<T>::clear()
if (this->v_) if (this->v_)
{ {
delete[] this->v_; delete[] this->v_;
this->v_ = 0; this->v_ = nullptr;
} }
this->size_ = 0; this->size_ = 0;

View File

@ -28,7 +28,7 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T> template<class T>
Foam::SortableList<T>::SortableList() inline Foam::SortableList<T>::SortableList()
{} {}
@ -51,14 +51,14 @@ Foam::SortableList<T>::SortableList(const Xfer<List<T>>& values)
template<class T> template<class T>
Foam::SortableList<T>::SortableList(const label size) inline Foam::SortableList<T>::SortableList(const label size)
: :
List<T>(size) List<T>(size)
{} {}
template<class T> template<class T>
Foam::SortableList<T>::SortableList(const label size, const T& val) inline Foam::SortableList<T>::SortableList(const label size, const T& val)
: :
List<T>(size, val) List<T>(size, val)
{} {}
@ -72,6 +72,20 @@ Foam::SortableList<T>::SortableList(const SortableList<T>& lst)
{} {}
template<class T>
template<class InputIterator>
inline Foam::SortableList<T>::SortableList
(
InputIterator begIter,
InputIterator endIter
)
:
List<T>(begIter, endIter)
{
sort();
}
template<class T> template<class T>
Foam::SortableList<T>::SortableList(std::initializer_list<T> values) Foam::SortableList<T>::SortableList(std::initializer_list<T> values)
: :
@ -140,9 +154,9 @@ Foam::Xfer<Foam::List<T>> Foam::SortableList<T>::xfer()
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T> template<class T>
inline void Foam::SortableList<T>::operator=(const T& t) inline void Foam::SortableList<T>::operator=(const T& val)
{ {
UList<T>::operator=(t); UList<T>::operator=(val);
} }

View File

@ -65,27 +65,32 @@ public:
// Constructors // Constructors
//- Null constructor, sort later (eg, after assignment or transfer) //- Null constructor, sort later (eg, after assignment or transfer)
SortableList(); inline SortableList();
//- Construct from UList, sorting immediately //- Construct from UList, sorting immediately
explicit SortableList(const UList<T>&); explicit SortableList(const UList<T>& values);
//- Construct from transferred List, sorting immediately //- Construct from transferred List, sorting immediately
explicit SortableList(const Xfer<List<T>>&); explicit SortableList(const Xfer<List<T>>& values);
//- Construct given size. Sort later on //- Construct given size. Sort later on
// The indices remain empty until the list is sorted // The indices remain empty until the list is sorted
explicit SortableList(const label size); explicit inline SortableList(const label size);
//- Construct given size and initial value. Sort later on //- Construct given size and initial value. Sort later on
// The indices remain empty until the list is sorted // The indices remain empty until the list is sorted
SortableList(const label size, const T&); inline SortableList(const label size, const T& val);
//- Construct given begin/end iterators.
// Uses std::distance to determine the size.
template<class InputIterator>
inline SortableList(InputIterator begIter, InputIterator endIter);
//- Construct as copy //- Construct as copy
SortableList(const SortableList<T>&); inline SortableList(const SortableList<T>& lst);
//- Construct from an initializer list, sorting immediately //- Construct from an initializer list, sorting immediately
SortableList(std::initializer_list<T>); SortableList(std::initializer_list<T> values);
// Member Functions // Member Functions
@ -122,16 +127,16 @@ public:
// Member Operators // Member Operators
//- Assignment of all entries to the given value //- Assignment of all entries to the given value
inline void operator=(const T&); inline void operator=(const T& val);
//- Assignment to UList operator. Takes linear time //- Assignment to UList operator. Takes linear time
inline void operator=(const UList<T>&); inline void operator=(const UList<T>& lst);
//- Assignment operator. Takes linear time //- Assignment operator. Takes linear time
inline void operator=(const SortableList<T>&); inline void operator=(const SortableList<T>& lst);
//- Assignment to an initializer list //- Assignment to an initializer list
void operator=(std::initializer_list<T>); void operator=(std::initializer_list<T> lst);
}; };

View File

@ -112,6 +112,7 @@ Foam::UList<T> Foam::UList<T>::operator[](const labelRange& range)
return UList<T>(&(this->v_[slice.start()]), slice.size()); // SubList return UList<T>(&(this->v_[slice.start()]), slice.size()); // SubList
} }
template<class T> template<class T>
const Foam::UList<T> Foam::UList<T>::operator[](const labelRange& range) const const Foam::UList<T> Foam::UList<T>::operator[](const labelRange& range) const
{ {
@ -132,6 +133,7 @@ Foam::UList<T> Foam::UList<T>::operator[]
return UList<T>(&(this->v_[slice.start()]), slice.size()); // SubList return UList<T>(&(this->v_[slice.start()]), slice.size()); // SubList
} }
template<class T> template<class T>
const Foam::UList<T> Foam::UList<T>::operator[] const Foam::UList<T> Foam::UList<T>::operator[]
( (

View File

@ -91,9 +91,9 @@ Foam::IOobjectList::IOobjectList
} }
Foam::IOobjectList::IOobjectList(const IOobjectList& ioOL) Foam::IOobjectList::IOobjectList(const IOobjectList& iolist)
: :
HashPtrTable<IOobject>(ioOL) HashPtrTable<IOobject>(iolist)
{} {}
@ -113,17 +113,7 @@ bool Foam::IOobjectList::add(IOobject& io)
bool Foam::IOobjectList::remove(IOobject& io) bool Foam::IOobjectList::remove(IOobject& io)
{ {
HashPtrTable<IOobject>::iterator iter = return erase(io.name());
HashPtrTable<IOobject>::find(io.name());
if (iter != end())
{
return erase(iter);
}
else
{
return false;
}
} }
@ -131,7 +121,7 @@ Foam::IOobject* Foam::IOobjectList::lookup(const word& name) const
{ {
HashPtrTable<IOobject>::const_iterator iter = find(name); HashPtrTable<IOobject>::const_iterator iter = find(name);
if (iter != end()) if (iter.found())
{ {
if (IOobject::debug) if (IOobject::debug)
{ {
@ -152,68 +142,80 @@ Foam::IOobject* Foam::IOobjectList::lookup(const word& name) const
} }
Foam::IOobjectList Foam::IOobjectList::lookup(const wordRe& name) const Foam::IOobjectList Foam::IOobjectList::lookup(const wordRe& matcher) const
{ {
IOobjectList objectsOfName(size()); IOobjectList results(size());
forAllConstIter(HashPtrTable<IOobject>, *this, iter) forAllConstIters(*this, iter)
{ {
if (name.match(iter()->name())) if (matcher.match(iter.key()))
{ {
if (IOobject::debug) if (IOobject::debug)
{ {
InfoInFunction << "Found " << iter.key() << endl; InfoInFunction << "Found " << iter.key() << endl;
} }
objectsOfName.insert(iter.key(), new IOobject(*iter())); results.insert
(
iter.key(),
new IOobject(*(iter.object()))
);
} }
} }
return objectsOfName; return results;
} }
Foam::IOobjectList Foam::IOobjectList::lookup(const wordReList& patterns) const Foam::IOobjectList Foam::IOobjectList::lookup(const wordReList& matcher) const
{ {
wordReListMatcher names(patterns); wordReListMatcher mat(matcher);
IOobjectList objectsOfName(size()); IOobjectList results(size());
forAllConstIter(HashPtrTable<IOobject>, *this, iter) forAllConstIters(*this, iter)
{ {
if (names.match(iter()->name())) if (mat.match(iter.key()))
{ {
if (IOobject::debug) if (IOobject::debug)
{ {
InfoInFunction << "Found " << iter.key() << endl; InfoInFunction << "Found " << iter.key() << endl;
} }
objectsOfName.insert(iter.key(), new IOobject(*iter())); results.insert
(
iter.key(),
new IOobject(*(iter.object()))
);
} }
} }
return objectsOfName; return results;
} }
Foam::IOobjectList Foam::IOobjectList::lookupClass(const word& ClassName) const Foam::IOobjectList Foam::IOobjectList::lookupClass(const word& clsName) const
{ {
IOobjectList objectsOfClass(size()); IOobjectList results(size());
forAllConstIter(HashPtrTable<IOobject>, *this, iter) forAllConstIters(*this, iter)
{ {
if (iter()->headerClassName() == ClassName) if (iter()->headerClassName() == clsName)
{ {
if (IOobject::debug) if (IOobject::debug)
{ {
InfoInFunction << "Found " << iter.key() << endl; InfoInFunction << "Found " << iter.key() << endl;
} }
objectsOfClass.insert(iter.key(), new IOobject(*iter())); results.insert
(
iter.key(),
new IOobject(*(iter.object()))
);
} }
} }
return objectsOfClass; return results;
} }
@ -231,33 +233,33 @@ Foam::wordList Foam::IOobjectList::sortedNames() const
Foam::wordList Foam::IOobjectList::names Foam::wordList Foam::IOobjectList::names
( (
const word& ClassName const word& clsName
) const ) const
{ {
wordList objectNames(size()); wordList objNames(size());
label count = 0; label count = 0;
forAllConstIter(HashPtrTable<IOobject>, *this, iter) forAllConstIters(*this, iter)
{ {
if (iter()->headerClassName() == ClassName) if (iter()->headerClassName() == clsName)
{ {
objectNames[count++] = iter.key(); objNames[count++] = iter.key();
} }
} }
objectNames.setSize(count); objNames.setSize(count);
return objectNames; return objNames;
} }
Foam::wordList Foam::IOobjectList::names Foam::wordList Foam::IOobjectList::names
( (
const word& ClassName, const word& clsName,
const wordRe& matcher const wordRe& matcher
) const ) const
{ {
wordList objNames = names(ClassName); wordList objNames = names(clsName);
return wordList(objNames, findStrings(matcher, objNames)); return wordList(objNames, findStrings(matcher, objNames));
} }
@ -265,11 +267,11 @@ Foam::wordList Foam::IOobjectList::names
Foam::wordList Foam::IOobjectList::names Foam::wordList Foam::IOobjectList::names
( (
const word& ClassName, const word& clsName,
const wordReList& matcher const wordReList& matcher
) const ) const
{ {
wordList objNames = names(ClassName); wordList objNames = names(clsName);
return wordList(objNames, findStrings(matcher, objNames)); return wordList(objNames, findStrings(matcher, objNames));
} }
@ -277,10 +279,10 @@ Foam::wordList Foam::IOobjectList::names
Foam::wordList Foam::IOobjectList::sortedNames Foam::wordList Foam::IOobjectList::sortedNames
( (
const word& ClassName const word& clsName
) const ) const
{ {
wordList sortedLst = names(ClassName); wordList sortedLst = names(clsName);
sort(sortedLst); sort(sortedLst);
return sortedLst; return sortedLst;
@ -289,11 +291,11 @@ Foam::wordList Foam::IOobjectList::sortedNames
Foam::wordList Foam::IOobjectList::sortedNames Foam::wordList Foam::IOobjectList::sortedNames
( (
const word& ClassName, const word& clsName,
const wordRe& matcher const wordRe& matcher
) const ) const
{ {
wordList sortedLst = names(ClassName, matcher); wordList sortedLst = names(clsName, matcher);
sort(sortedLst); sort(sortedLst);
return sortedLst; return sortedLst;
@ -302,11 +304,11 @@ Foam::wordList Foam::IOobjectList::sortedNames
Foam::wordList Foam::IOobjectList::sortedNames Foam::wordList Foam::IOobjectList::sortedNames
( (
const word& ClassName, const word& clsName,
const wordReList& matcher const wordReList& matcher
) const ) const
{ {
wordList sortedLst = names(ClassName, matcher); wordList sortedLst = names(clsName, matcher);
sort(sortedLst); sort(sortedLst);
return sortedLst; return sortedLst;

View File

@ -77,7 +77,7 @@ public:
); );
//- Construct as copy //- Construct as copy
IOobjectList(const IOobjectList&); IOobjectList(const IOobjectList& iolist);
//- Destructor //- Destructor
@ -87,52 +87,56 @@ public:
// Member functions // Member functions
//- Add an IOobject to the list //- Add an IOobject to the list
bool add(IOobject&); bool add(IOobject& io);
//- Remove an IOobject from the list //- Remove an IOobject from the list
bool remove(IOobject&); bool remove(IOobject& io);
//- Lookup a given name and return IOobject ptr if found else nullptr //- Lookup a given name and return IOobject ptr if found else nullptr
IOobject* lookup(const word& name) const; IOobject* lookup(const word& name) const;
//- Return the list for all IOobects whose name matches name //- The list of all IOobects with matching names
IOobjectList lookup(const wordRe& name) const; IOobjectList lookup(const wordRe& matcher) const;
//- Return the list for all IOobects whose name matches name //- The list of all IOobjects with matching names
IOobjectList lookup(const wordReList& patterns) const; IOobjectList lookup(const wordReList& matcher) const;
//- Return the list for all IOobjects of a given class //- The list of all IOobjects with the given class name
IOobjectList lookupClass(const word& className) const; IOobjectList lookupClass(const word& clsName) const;
//- A list of names of the IOobjects //- A list of names of the IOobjects
wordList names() const; wordList names() const;
//- A list of names of IOobjects of the given class //- The names of IOobjects with the given class name
wordList names(const word& className) const; wordList names(const word& clsName) const;
//- A list of names of IOobjects of the given class, //- The names of IOobjects with the given class name that also
// and that also satisfy the input matcher // have a name satisfying the input matcher
wordList names(const word& className, const wordRe&) const; wordList names(const word& clsName, const wordRe& matcher) const;
//- A list of names of IOobjects of the given class, //- The names of IOobjects with the given class name that also
// and that also satisfy the input matchers // have a name satisfying the input matcher
wordList names(const word& className, const wordReList&) const; wordList names(const word& clsName, const wordReList& matcher) const;
//- A sorted list of names of the IOobjects //- A sorted list of names of the IOobjects
wordList sortedNames() const; wordList sortedNames() const;
//- A sorted list of names of IOobjects of given class //- The sorted names of IOobjects with the given class name
wordList sortedNames(const word& className) const; wordList sortedNames(const word& clsName) const;
//- A sorted list of names of IOobjects of the given class, //- The sorted names of IOobjects with the given class name that also
// and that also satisfy the input matcher // have a name satisfying the input matcher
wordList sortedNames(const word& className, const wordRe&) const; wordList sortedNames(const word& clsName, const wordRe& matcher) const;
//- A sorted list of names of IOobjects of the given class, //- The sorted names of IOobjects with the given class name that also
// and that also satisfy the input matchers // have a name satisfying the input matcher
wordList sortedNames(const word& className, const wordReList&) const; wordList sortedNames
(
const word& clsName,
const wordReList& matcher
) const;
}; };

View File

@ -161,7 +161,7 @@ const Foam::entry* Foam::dictionary::lookupScopedSubEntryPtr
bool Foam::dictionary::findInPatterns bool Foam::dictionary::findInPatterns
( (
const bool patternMatch, const bool patternMatch,
const word& Keyword, const word& keyword,
DLList<entry*>::const_iterator& wcLink, DLList<entry*>::const_iterator& wcLink,
DLList<autoPtr<regExp>>::const_iterator& reLink DLList<autoPtr<regExp>>::const_iterator& reLink
) const ) const
@ -173,8 +173,8 @@ bool Foam::dictionary::findInPatterns
if if
( (
patternMatch patternMatch
? reLink()->match(Keyword) ? reLink()->match(keyword)
: wcLink()->keyword() == Keyword : wcLink()->keyword() == keyword
) )
{ {
return true; return true;
@ -192,7 +192,7 @@ bool Foam::dictionary::findInPatterns
bool Foam::dictionary::findInPatterns bool Foam::dictionary::findInPatterns
( (
const bool patternMatch, const bool patternMatch,
const word& Keyword, const word& keyword,
DLList<entry*>::iterator& wcLink, DLList<entry*>::iterator& wcLink,
DLList<autoPtr<regExp>>::iterator& reLink DLList<autoPtr<regExp>>::iterator& reLink
) )
@ -204,8 +204,8 @@ bool Foam::dictionary::findInPatterns
if if
( (
patternMatch patternMatch
? reLink()->match(Keyword) ? reLink()->match(keyword)
: wcLink()->keyword() == Keyword : wcLink()->keyword() == keyword
) )
{ {
return true; return true;
@ -743,6 +743,24 @@ Foam::dictionary Foam::dictionary::subOrEmptyDict
} }
const Foam::dictionary& Foam::dictionary::optionalSubDict
(
const word& keyword
) const
{
const entry* entryPtr = lookupEntryPtr(keyword, false, true);
if (entryPtr)
{
return entryPtr->dict();
}
else
{
return *this;
}
}
Foam::wordList Foam::dictionary::toc() const Foam::wordList Foam::dictionary::toc() const
{ {
wordList keys(size()); wordList keys(size());
@ -933,11 +951,11 @@ void Foam::dictionary::set(const keyType& k, const dictionary& d)
} }
bool Foam::dictionary::remove(const word& Keyword) bool Foam::dictionary::remove(const word& keyword)
{ {
HashTable<entry*>::iterator iter = hashedEntries_.find(Keyword); HashTable<entry*>::iterator iter = hashedEntries_.find(keyword);
if (iter != hashedEntries_.end()) if (iter.found())
{ {
// Delete from patterns first // Delete from patterns first
DLList<entry*>::iterator wcLink = DLList<entry*>::iterator wcLink =
@ -946,7 +964,7 @@ bool Foam::dictionary::remove(const word& Keyword)
patternRegexps_.begin(); patternRegexps_.begin();
// Find in pattern using exact match only // Find in pattern using exact match only
if (findInPatterns(false, Keyword, wcLink, reLink)) if (findInPatterns(false, keyword, wcLink, reLink))
{ {
patternEntries_.remove(wcLink); patternEntries_.remove(wcLink);
patternRegexps_.remove(reLink); patternRegexps_.remove(reLink);

View File

@ -204,7 +204,7 @@ class dictionary
bool findInPatterns bool findInPatterns
( (
const bool patternMatch, const bool patternMatch,
const word& Keyword, const word& keyword,
DLList<entry*>::const_iterator& wcLink, DLList<entry*>::const_iterator& wcLink,
DLList<autoPtr<regExp>>::const_iterator& reLink DLList<autoPtr<regExp>>::const_iterator& reLink
) const; ) const;
@ -213,7 +213,7 @@ class dictionary
bool findInPatterns bool findInPatterns
( (
const bool patternMatch, const bool patternMatch,
const word& Keyword, const word& keyword,
DLList<entry*>::iterator& wcLink, DLList<entry*>::iterator& wcLink,
DLList<autoPtr<regExp>>::iterator& reLink DLList<autoPtr<regExp>>::iterator& reLink
); );
@ -436,6 +436,10 @@ public:
const bool mustRead = false const bool mustRead = false
) const; ) const;
//- Find and return a sub-dictionary if found
// otherwise return this dictionary
const dictionary& optionalSubDict(const word& keyword) const;
//- Return the table of contents //- Return the table of contents
wordList toc() const; wordList toc() const;
@ -514,7 +518,7 @@ public:
void set(const keyType& k, const T& t); void set(const keyType& k, const T& t);
//- Remove an entry specified by keyword //- Remove an entry specified by keyword
bool remove(const word& Keyword); bool remove(const word& keyword);
//- Change the keyword for an entry, //- Change the keyword for an entry,
// optionally forcing overwrite of an existing entry // optionally forcing overwrite of an existing entry

View File

@ -57,7 +57,7 @@ class dictionary;
// Forward declaration of friend functions and operators // Forward declaration of friend functions and operators
class entry; class entry;
Ostream& operator<<(Ostream&, const entry&); Ostream& operator<<(Ostream& os, const entry& e);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class entry Declaration Class entry Declaration
@ -75,11 +75,16 @@ class entry
// Private Member Functions // Private Member Functions
//- Get the next valid keyword. Return true if is valid keyType. //- Get the next valid keyword. Return true if a valid keyType.
static bool getKeyword(keyType&, token&, Istream&); static bool getKeyword
(
keyType& keyword,
token& keywordToken,
Istream& is
);
//- Get the next valid keyword otherwise return false //- Get the next valid keyword otherwise return false
static bool getKeyword(keyType&, Istream&); static bool getKeyword(keyType& keyword, Istream& is);
public: public:
@ -90,10 +95,10 @@ public:
// Constructors // Constructors
//- Construct from keyword //- Construct from keyword
entry(const keyType&); entry(const keyType& keyword);
//- Construct as copy //- Construct as copy
entry(const entry&); entry(const entry& e);
//- Construct on freestore as copy with reference to the //- Construct on freestore as copy with reference to the
// dictionary the copy belongs to // dictionary the copy belongs to
@ -107,7 +112,7 @@ public:
virtual autoPtr<entry> clone() const; virtual autoPtr<entry> clone() const;
//- Construct from Istream and insert into dictionary //- Construct from Istream and insert into dictionary
static bool New(dictionary& parentDict, Istream&); static bool New(dictionary& parentDict, Istream& is);
//- Construct on freestore from Istream and return //- Construct on freestore from Istream and return
static autoPtr<entry> New(Istream& is); static autoPtr<entry> New(Istream& is);
@ -179,7 +184,7 @@ public:
// Ostream operator // Ostream operator
friend Ostream& operator<<(Ostream&, const entry&); friend Ostream& operator<<(Ostream& os, const entry& e);
}; };

View File

@ -106,7 +106,7 @@ bool Foam::entry::getKeyword(keyType& keyword, Istream& is)
bool Foam::entry::New(dictionary& parentDict, Istream& is) bool Foam::entry::New(dictionary& parentDict, Istream& is)
{ {
is.fatalCheck("entry::New(const dictionary& parentDict, Istream&)"); is.fatalCheck(FUNCTION_NAME);
keyType keyword; keyType keyword;
token keyToken; token keyToken;
@ -324,7 +324,7 @@ bool Foam::entry::New(dictionary& parentDict, Istream& is)
Foam::autoPtr<Foam::entry> Foam::entry::New(Istream& is) Foam::autoPtr<Foam::entry> Foam::entry::New(Istream& is)
{ {
is.fatalCheck("entry::New(Istream&)"); is.fatalCheck(FUNCTION_NAME);
keyType keyword; keyType keyword;

View File

@ -46,10 +46,10 @@ Foam::label Foam::coupleGroupIdentifier::findOtherPatchID
<< exit(FatalError); << exit(FatalError);
} }
HashTable<labelList, word>::const_iterator fnd = HashTable<labelList>::const_iterator fnd =
pbm.groupPatchIDs().find(name()); pbm.groupPatchIDs().find(name());
if (fnd == pbm.groupPatchIDs().end()) if (!fnd.found())
{ {
if (&mesh == &thisPatch.boundaryMesh().mesh()) if (&mesh == &thisPatch.boundaryMesh().mesh())
{ {
@ -65,7 +65,7 @@ Foam::label Foam::coupleGroupIdentifier::findOtherPatchID
} }
// Mesh has patch group // Mesh has patch group
const labelList& patchIDs = fnd(); const labelList& patchIDs = fnd.object();
if (&mesh == &thisPatch.boundaryMesh().mesh()) if (&mesh == &thisPatch.boundaryMesh().mesh())
{ {

View File

@ -149,7 +149,11 @@ public:
//- Return true if point label is found in edge. //- Return true if point label is found in edge.
// Always false for a negative label. // Always false for a negative label.
inline bool found(const label index) const; inline bool found(const label pointLabel) const;
//- Return local index (0,1) of point label in edge -1 on failure
// Always return -1 for a negative label.
inline label which(const label pointLabel) const;
//- Do the edges share a common vertex index? //- Do the edges share a common vertex index?
// Negative point labels never connect. // Negative point labels never connect.

View File

@ -206,10 +206,28 @@ inline Foam::label Foam::edge::maxVertex() const
} }
inline bool Foam::edge::found(const label index) const inline bool Foam::edge::found(const label pointLabel) const
{ {
// -1: always false // -1: always false
return (index >= 0 && (index == start() || index == end())); return (pointLabel >= 0 && (pointLabel == start() || pointLabel == end()));
}
inline Foam::label Foam::edge::which(const label pointLabel) const
{
// -1: always false
if (pointLabel >= 0)
{
if (pointLabel == start())
{
return 0;
}
if (pointLabel == end())
{
return 1;
}
}
return -1;
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -202,7 +202,10 @@ public:
//- Navigation through face vertices //- Navigation through face vertices
//- Which vertex on face (face index given a global index) //- Return true if the global point label is found in face.
inline bool found(const label globalIndex) const;
//- Which local vertex on face given a global index.
// returns -1 if not found // returns -1 if not found
label which(const label globalIndex) const; label which(const label globalIndex) const;

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -116,20 +116,24 @@ inline Foam::edge Foam::face::faceEdge(const label n) const
} }
// Next vertex on face inline bool Foam::face::found(const label globalIndex) const
{
return which(globalIndex) != -1;
}
inline Foam::label Foam::face::nextLabel(const label i) const inline Foam::label Foam::face::nextLabel(const label i) const
{ {
return operator[](fcIndex(i)); return operator[](fcIndex(i));
} }
// Previous vertex on face
inline Foam::label Foam::face::prevLabel(const label i) const inline Foam::label Foam::face::prevLabel(const label i) const
{ {
return operator[](rcIndex(i)); return operator[](rcIndex(i));
} }
// Number of triangles directly known from number of vertices
inline Foam::label Foam::face::nTriangles() const inline Foam::label Foam::face::nTriangles() const
{ {
return size() - 2; return size() - 2;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd. \\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -21,83 +21,53 @@ License
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::faceTraits
Description
Traits class for faces
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef faceTraits_H
#define faceTraits_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
// A triFace surface only handles triangulated faces // Forward declarations
template<> class triFace;
inline bool MeshedSurface<triFace>::isTri() class labelledTri;
/*---------------------------------------------------------------------------*\
Class faceTraits Declaration
\*---------------------------------------------------------------------------*/
template<class FaceType>
class faceTraits
{ {
return true; public:
}
//- Face-type only handles triangles. Not true in general.
inline static bool isTri() { return false; }
};
// A labelledTri surface only handles triangulated faces
template<> template<>
inline bool MeshedSurface<labelledTri>::isTri() inline bool faceTraits<triFace>::isTri() { return true; }
{
return true;
}
// Number of triangles for a triFace surface
template<> template<>
inline label MeshedSurface<triFace>::nTriangles() const inline bool faceTraits<labelledTri>::isTri() { return true; }
{
return ParentType::size();
}
// Number of triangles for a labelledTri surface
template<>
inline label MeshedSurface<labelledTri>::nTriangles() const
{
return ParentType::size();
}
// Inplace triangulation of triFace surface = no-op
template<>
inline label MeshedSurface<triFace>::triangulate()
{
return 0;
}
// Inplace triangulation of labelledTri surface = no-op
template<>
inline label MeshedSurface<labelledTri>::triangulate()
{
return 0;
}
// Inplace triangulation of triFace surface (with face map) = no-op
template<>
inline label MeshedSurface<triFace>::triangulate(List<label>& faceMap)
{
if (notNull(faceMap))
{
faceMap.clear();
}
return 0;
}
// Inplace triangulation of labelledTri surface (with face map) = no-op
template<>
inline label MeshedSurface<labelledTri>::triangulate(List<label>& faceMap)
{
if (notNull(faceMap))
{
faceMap.clear();
}
return 0;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam } // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* // // ************************************************************************* //

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -137,6 +137,13 @@ public:
// The starting points of the original and reverse face are identical. // The starting points of the original and reverse face are identical.
inline triFace reverseFace() const; inline triFace reverseFace() const;
//- Return true if the global point label is found in face.
bool found(const label globalIndex) const;
//- Which local index (0,1,2) on face given a global index.
// returns -1 if not found
label which(const label globalIndex) const;
//- Return swept-volume from old-points to new-points //- Return swept-volume from old-points to new-points
inline scalar sweptVol inline scalar sweptVol
( (

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -209,6 +209,21 @@ inline Foam::triFace Foam::triFace::reverseFace() const
} }
inline bool Foam::triFace::found(const label globalIndex) const
{
return which(globalIndex) != -1;
}
inline Foam::label Foam::triFace::which(const label globalIndex) const
{
if (operator[](0) == globalIndex) return 0;
if (operator[](1) == globalIndex) return 1;
if (operator[](2) == globalIndex) return 2;
return -1;
}
inline Foam::scalar Foam::triFace::sweptVol inline Foam::scalar Foam::triFace::sweptVol
( (
const UList<point>& opts, const UList<point>& opts,

View File

@ -32,6 +32,7 @@ License
#include "lduSchedule.H" #include "lduSchedule.H"
#include "globalMeshData.H" #include "globalMeshData.H"
#include "stringListOps.H" #include "stringListOps.H"
#include "EdgeMap.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -287,7 +288,7 @@ Foam::polyBoundaryMesh::neighbourEdges() const
// From mesh edge (expressed as a point pair so as not to construct // From mesh edge (expressed as a point pair so as not to construct
// point addressing) to patch + relative edge index. // point addressing) to patch + relative edge index.
HashTable<labelPair, edge, Hash<edge>> pointsToEdge(nEdgePairs); EdgeMap<labelPair> pointsToEdge(nEdgePairs);
forAll(*this, patchi) forAll(*this, patchi)
{ {
@ -308,10 +309,9 @@ Foam::polyBoundaryMesh::neighbourEdges() const
// Edge in mesh points. // Edge in mesh points.
edge meshEdge(pp.meshPoints()[e[0]], pp.meshPoints()[e[1]]); edge meshEdge(pp.meshPoints()[e[0]], pp.meshPoints()[e[1]]);
HashTable<labelPair, edge, Hash<edge>>::iterator fnd = EdgeMap<labelPair>::iterator fnd = pointsToEdge.find(meshEdge);
pointsToEdge.find(meshEdge);
if (fnd == pointsToEdge.end()) if (!fnd.found())
{ {
// First occurrence of mesh edge. Store patch and my // First occurrence of mesh edge. Store patch and my
// local index. // local index.
@ -328,7 +328,7 @@ Foam::polyBoundaryMesh::neighbourEdges() const
else else
{ {
// Second occurrence. Store. // Second occurrence. Store.
const labelPair& edgeInfo = fnd(); const labelPair& edgeInfo = fnd.object();
neighbourEdges[patchi][edgei - pp.nInternalEdges()] = neighbourEdges[patchi][edgei - pp.nInternalEdges()] =
edgeInfo; edgeInfo;
@ -413,13 +413,13 @@ const Foam::labelList& Foam::polyBoundaryMesh::patchID() const
} }
const Foam::HashTable<Foam::labelList, Foam::word>& const Foam::HashTable<Foam::labelList>&
Foam::polyBoundaryMesh::groupPatchIDs() const Foam::polyBoundaryMesh::groupPatchIDs() const
{ {
if (!groupPatchIDsPtr_.valid()) if (!groupPatchIDsPtr_.valid())
{ {
groupPatchIDsPtr_.reset(new HashTable<labelList, word>(10)); groupPatchIDsPtr_.reset(new HashTable<labelList>(10));
HashTable<labelList, word>& groupPatchIDs = groupPatchIDsPtr_(); HashTable<labelList>& groupPatchIDs = groupPatchIDsPtr_();
const polyBoundaryMesh& bm = *this; const polyBoundaryMesh& bm = *this;
@ -431,7 +431,7 @@ Foam::polyBoundaryMesh::groupPatchIDs() const
{ {
const word& name = groups[i]; const word& name = groups[i];
HashTable<labelList, word>::iterator iter = groupPatchIDs.find HashTable<labelList>::iterator iter = groupPatchIDs.find
( (
name name
); );
@ -612,10 +612,10 @@ Foam::labelList Foam::polyBoundaryMesh::findIndices
if (usePatchGroups && groupPatchIDs().size()) if (usePatchGroups && groupPatchIDs().size())
{ {
const HashTable<labelList, word>::const_iterator iter = const HashTable<labelList>::const_iterator iter =
groupPatchIDs().find(key); groupPatchIDs().find(key);
if (iter != groupPatchIDs().end()) if (iter.found())
{ {
labelHashSet indexSet(indices); labelHashSet indexSet(indices);
@ -815,14 +815,8 @@ void Foam::polyBoundaryMesh::matchGroups
// Current set of unmatched patches // Current set of unmatched patches
nonGroupPatches = labelHashSet(patchIDs); nonGroupPatches = labelHashSet(patchIDs);
const HashTable<labelList, word>& groupPatchIDs = this->groupPatchIDs(); const HashTable<labelList>& groupPatchIDs = this->groupPatchIDs();
for forAllConstIters(groupPatchIDs, iter)
(
HashTable<labelList,word>::const_iterator iter =
groupPatchIDs.begin();
iter != groupPatchIDs.end();
++iter
)
{ {
// Store currently unmatched patches so we can restore // Store currently unmatched patches so we can restore
labelHashSet oldNonGroupPatches(nonGroupPatches); labelHashSet oldNonGroupPatches(nonGroupPatches);

View File

@ -70,7 +70,7 @@ class polyBoundaryMesh
mutable autoPtr<labelList> patchIDPtr_; mutable autoPtr<labelList> patchIDPtr_;
mutable autoPtr<HashTable<labelList, word>> groupPatchIDsPtr_; mutable autoPtr<HashTable<labelList>> groupPatchIDsPtr_;
//- Edges of neighbouring patches //- Edges of neighbouring patches
mutable autoPtr<List<labelPairList>> neighbourEdgesPtr_; mutable autoPtr<List<labelPairList>> neighbourEdgesPtr_;
@ -183,8 +183,8 @@ public:
//- Per boundary face label the patch index //- Per boundary face label the patch index
const labelList& patchID() const; const labelList& patchID() const;
//- Per patch group the patch indices //- The patch indices per patch group
const HashTable<labelList, word>& groupPatchIDs() const; const HashTable<labelList>& groupPatchIDs() const;
//- Set/add group with patches //- Set/add group with patches
void setGroup(const word& groupName, const labelList& patchIDs); void setGroup(const word& groupName, const labelList& patchIDs);

View File

@ -98,10 +98,10 @@ public:
// Access // Access
//- Return first vertex //- Return first point
inline PointRef start() const; inline PointRef start() const;
//- Return second vertex //- Return second point
inline PointRef end() const; inline PointRef end() const;
@ -113,9 +113,12 @@ public:
//- Return scalar magnitude //- Return scalar magnitude
inline scalar mag() const; inline scalar mag() const;
//- Return start-end vector //- Return start-to-end vector
inline Point vec() const; inline Point vec() const;
//- Return the unit vector (start-to-end)
inline Point unitVec() const;
//- Return nearest distance to line from a given point //- Return nearest distance to line from a given point
// If the nearest point is on the line, return a hit // If the nearest point is on the line, return a hit
PointHit<Point> nearestDist(const Point& p) const; PointHit<Point> nearestDist(const Point& p) const;

View File

@ -90,6 +90,16 @@ inline Point Foam::line<Point, PointRef>::vec() const
} }
template<class Point, class PointRef>
inline Point Foam::line<Point, PointRef>::unitVec() const
{
Point v = b_ - a_;
v /= ::Foam::mag(v) + VSMALL;
return v;
}
template<class Point, class PointRef> template<class Point, class PointRef>
Foam::PointHit<Point> Foam::line<Point, PointRef>::nearestDist Foam::PointHit<Point> Foam::line<Point, PointRef>::nearestDist
( (

View File

@ -34,6 +34,8 @@ namespace Foam
int labelRange::debug(debug::debugSwitch("labelRange", 0)); int labelRange::debug(debug::debugSwitch("labelRange", 0));
} }
const Foam::labelRange Foam::labelRange::null;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

View File

@ -35,6 +35,7 @@ SourceFiles
#define labelRange_H #define labelRange_H
#include "label.H" #include "label.H"
#include <iterator>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -63,26 +64,32 @@ class labelRange
public: public:
static int debug; // Static Data Members
static int debug;
//- An empty range with start=0, size=0.
static const labelRange null;
// STL type definitions similar to what UList has // STL type definitions similar to what UList has
//- Type of values the range contains //- Type of values the range contains
typedef label value_type; typedef label value_type;
//- The type that can represent the difference between two iterators
typedef label difference_type;
//- The type that can represent the size of the range //- The type that can represent the size of the range
typedef label size_type; typedef label size_type;
// Forward declaration
class const_iterator;
// Constructors // Constructors
//- An empty range with zero for start/size. //- An empty range with zero for start/size.
inline labelRange(); inline labelRange();
//- Construct a range from start and size, enforcing non-negative size. //- Construct a range from start/size, enforcing non-negative size.
// Optionally adjust the start to avoid any negative indices. // Optionally adjust the start to avoid any negative indices.
inline labelRange inline labelRange
( (
@ -95,6 +102,12 @@ public:
labelRange(Istream& is); labelRange(Istream& is);
// Static Member Functions
//- An identity range with range[i] == i.
inline static labelRange identity(const label len);
// Member Functions // Member Functions
//- Adjust start position //- Adjust start position
@ -184,6 +197,9 @@ public:
//- Return element in the range, no bounds checking //- Return element in the range, no bounds checking
inline label operator[](const label localIndex) const; inline label operator[](const label localIndex) const;
//- Return const_iterator to element in the range
inline const_iterator operator()(const label localIndex) const;
//- Increase the size by 1. //- Increase the size by 1.
inline label operator++(); inline label operator++();
inline label operator++(int); inline label operator++(int);
@ -197,21 +213,30 @@ public:
//- Forward iterator with const access //- Forward iterator with const access
class const_iterator class const_iterator
:
public std::iterator
<
std::input_iterator_tag,
label,
label,
const label*,
const label&
>
{ {
//- The current label (not the local index) //- The current (global) value
label index_; label value_;
public: public:
// Constructors // Constructors
//- Construct from range at given local index. //- Construct from range at given local index.
// A negative index signals the 'end' position // A negative index is invalid and corresponds to the 'end'
inline const_iterator(const labelRange* range, const label i = 0); inline const_iterator(const labelRange* range, const label i=0);
// Member operators // Member operators
//- Return the current label //- Return the current (global) value
inline label operator*() const; inline label operator*() const;
inline const_iterator& operator++(); inline const_iterator& operator++();

View File

@ -64,7 +64,7 @@ inline Foam::labelRange::const_iterator::const_iterator
const label i const label i
) )
: :
index_ value_
( (
range->start() range->start()
+ ((i < 0 || i > range->size()) ? range->size() : i) + ((i < 0 || i > range->size()) ? range->size() : i)
@ -74,14 +74,14 @@ inline Foam::labelRange::const_iterator::const_iterator
inline Foam::label Foam::labelRange::const_iterator::operator*() const inline Foam::label Foam::labelRange::const_iterator::operator*() const
{ {
return index_; return value_;
} }
inline Foam::labelRange::const_iterator& inline Foam::labelRange::const_iterator&
Foam::labelRange::const_iterator::operator++() Foam::labelRange::const_iterator::operator++()
{ {
++index_; ++value_;
return *this; return *this;
} }
@ -90,7 +90,7 @@ inline Foam::labelRange::const_iterator
Foam::labelRange::const_iterator::operator++(int) Foam::labelRange::const_iterator::operator++(int)
{ {
const_iterator old = *this; const_iterator old = *this;
++index_; ++value_;
return old; return old;
} }
@ -100,7 +100,7 @@ inline bool Foam::labelRange::const_iterator::operator==
const const_iterator& iter const const_iterator& iter
) const ) const
{ {
return (this->index_ == iter.index_); return (this->value_ == iter.value_);
} }
@ -109,7 +109,7 @@ inline bool Foam::labelRange::const_iterator::operator!=
const const_iterator& iter const const_iterator& iter
) const ) const
{ {
return (this->index_ != iter.index_); return (this->value_ != iter.value_);
} }
@ -139,6 +139,12 @@ inline const Foam::labelRange::const_iterator Foam::labelRange::cend() const
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline Foam::labelRange Foam::labelRange::identity(const label len)
{
return labelRange(0, len);
}
inline void Foam::labelRange::setStart(const label i) inline void Foam::labelRange::setStart(const label i)
{ {
start_ = i; start_ = i;
@ -264,6 +270,13 @@ inline Foam::label Foam::labelRange::operator[](const label localIndex) const
} }
inline Foam::labelRange::const_iterator
Foam::labelRange::operator()(const label localIndex) const
{
return const_iterator(this, localIndex);
}
inline Foam::label Foam::labelRange::operator++() inline Foam::label Foam::labelRange::operator++()
{ {
return ++size_; return ++size_;

View File

@ -62,7 +62,7 @@ class hashedWordList
// Private data // Private data
//- Hash of words/indices //- Hash of words/indices
mutable HashTable<label,word> indices_; mutable HashTable<label> indices_;
// Private Member Functions // Private Member Functions
@ -141,7 +141,7 @@ public:
inline bool contains(const word& name) const; inline bool contains(const word& name) const;
//- Return the hash of words/indices for inspection //- Return the hash of words/indices for inspection
inline const HashTable<label,word>& lookup() const; inline const HashTable<label>& lookup() const;
//- Transfer the contents of the argument List into this list //- Transfer the contents of the argument List into this list
// and annul the argument list, // and annul the argument list,

View File

@ -134,7 +134,7 @@ inline void Foam::hashedWordList::append
} }
inline const Foam::HashTable<Foam::label,Foam::word>& inline const Foam::HashTable<Foam::label>&
Foam::hashedWordList::lookup() const Foam::hashedWordList::lookup() const
{ {
return indices_; return indices_;

View File

@ -869,16 +869,9 @@ void Foam::boundaryCutter::updateMesh(const mapPolyMesh& morphMap)
{ {
// Create copy since we're deleting entries // Create copy since we're deleting entries
HashTable<labelList, edge, Hash<edge>> EdgeMap<labelList> newEdgeAddedPoints(edgeAddedPoints_.size());
newEdgeAddedPoints(edgeAddedPoints_.size());
for forAllConstIters(edgeAddedPoints_, iter)
(
HashTable<labelList, edge, Hash<edge>>::const_iterator iter =
edgeAddedPoints_.begin();
iter != edgeAddedPoints_.end();
++iter
)
{ {
const edge& e = iter.key(); const edge& e = iter.key();
@ -888,7 +881,7 @@ void Foam::boundaryCutter::updateMesh(const mapPolyMesh& morphMap)
if (newStart >= 0 && newEnd >= 0) if (newStart >= 0 && newEnd >= 0)
{ {
const labelList& addedPoints = iter(); const labelList& addedPoints = iter.object();
labelList newAddedPoints(addedPoints.size()); labelList newAddedPoints(addedPoints.size());
label newI = 0; label newI = 0;

View File

@ -44,7 +44,7 @@ SourceFiles
#include "Map.H" #include "Map.H"
#include "labelList.H" #include "labelList.H"
#include "edge.H" #include "EdgeMap.H"
#include "typeInfo.H" #include "typeInfo.H"
#include "labelPair.H" #include "labelPair.H"
@ -71,7 +71,7 @@ class boundaryCutter
const polyMesh& mesh_; const polyMesh& mesh_;
//- Per edge sorted (start to end) list of points added. //- Per edge sorted (start to end) list of points added.
HashTable<labelList, edge, Hash<edge>> edgeAddedPoints_; EdgeMap<labelList> edgeAddedPoints_;
//- Per face the mid point added. //- Per face the mid point added.
Map<label> faceAddedPoint_; Map<label> faceAddedPoint_;
@ -159,8 +159,7 @@ public:
// Access // Access
//- Per edge a sorted list (start to end) of added points. //- Per edge a sorted list (start to end) of added points.
const HashTable<labelList, edge, Hash<edge>>& edgeAddedPoints() const EdgeMap<labelList>& edgeAddedPoints() const
const
{ {
return edgeAddedPoints_; return edgeAddedPoints_;
} }

View File

@ -479,13 +479,13 @@ Foam::face Foam::meshCutAndRemove::addEdgeCutsToFace(const label facei) const
// Check if edge has been cut. // Check if edge has been cut.
label fp1 = f.fcIndex(fp); label fp1 = f.fcIndex(fp);
HashTable<label, edge, Hash<edge>>::const_iterator fnd = EdgeMap<label>::const_iterator fnd =
addedPoints_.find(edge(f[fp], f[fp1])); addedPoints_.find(edge(f[fp], f[fp1]));
if (fnd != addedPoints_.end()) if (fnd.found())
{ {
// edge has been cut. Introduce new vertex. // edge has been cut. Introduce new vertex.
newFace[newFp++] = fnd(); newFace[newFp++] = fnd.object();
} }
} }
@ -541,12 +541,12 @@ Foam::face Foam::meshCutAndRemove::loopToFace
if (edgeI != -1) if (edgeI != -1)
{ {
// Existing edge. Insert split-edge point if any. // Existing edge. Insert split-edge point if any.
HashTable<label, edge, Hash<edge>>::const_iterator fnd = EdgeMap<label>::const_iterator fnd =
addedPoints_.find(mesh().edges()[edgeI]); addedPoints_.find(mesh().edges()[edgeI]);
if (fnd != addedPoints_.end()) if (fnd.found())
{ {
newFace[newFacei++] = fnd(); newFace[newFacei++] = fnd.object();
} }
} }
} }
@ -1302,24 +1302,17 @@ void Foam::meshCutAndRemove::updateMesh(const mapPolyMesh& map)
} }
{ {
HashTable<label, edge, Hash<edge>> newAddedPoints(addedPoints_.size()); EdgeMap<label> newAddedPoints(addedPoints_.size());
for forAllConstIters(addedPoints_, iter)
(
HashTable<label, edge, Hash<edge>>::const_iterator iter =
addedPoints_.begin();
iter != addedPoints_.end();
++iter
)
{ {
const edge& e = iter.key(); const edge& e = iter.key();
const label addedPointi = iter.object();
label newStart = map.reversePointMap()[e.start()]; label newStart = map.reversePointMap()[e.start()];
label newEnd = map.reversePointMap()[e.end()]; label newEnd = map.reversePointMap()[e.end()];
label addedPointi = iter();
label newAddedPointi = map.reversePointMap()[addedPointi]; label newAddedPointi = map.reversePointMap()[addedPointi];
if ((newStart >= 0) && (newEnd >= 0) && (newAddedPointi >= 0)) if ((newStart >= 0) && (newEnd >= 0) && (newAddedPointi >= 0))

View File

@ -40,6 +40,7 @@ SourceFiles
#include "labelList.H" #include "labelList.H"
#include "typeInfo.H" #include "typeInfo.H"
#include "Map.H" #include "Map.H"
#include "EdgeMap.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -70,7 +71,7 @@ class meshCutAndRemove
//- Points added in last setRefinement. Per split edge label of added //- Points added in last setRefinement. Per split edge label of added
// point // point
HashTable<label, edge, Hash<edge>> addedPoints_; EdgeMap<label> addedPoints_;
// Private Static Functions // Private Static Functions
@ -225,7 +226,7 @@ public:
//- Points added. Per split edge label of added point. //- Points added. Per split edge label of added point.
// (note: fairly useless across topology changes since one of the // (note: fairly useless across topology changes since one of the
// points of the edge will probably disappear) // points of the edge will probably disappear)
const HashTable<label, edge, Hash<edge>>& addedPoints() const const EdgeMap<label>& addedPoints() const
{ {
return addedPoints_; return addedPoints_;
} }

View File

@ -424,13 +424,13 @@ Foam::face Foam::meshCutter::addEdgeCutsToFace(const label facei) const
// Check if edge has been cut. // Check if edge has been cut.
label fp1 = f.fcIndex(fp); label fp1 = f.fcIndex(fp);
HashTable<label, edge, Hash<edge>>::const_iterator fnd = EdgeMap<label>::const_iterator fnd =
addedPoints_.find(edge(f[fp], f[fp1])); addedPoints_.find(edge(f[fp], f[fp1]));
if (fnd != addedPoints_.end()) if (fnd.found())
{ {
// edge has been cut. Introduce new vertex. // edge has been cut. Introduce new vertex.
newFace[newFp++] = fnd(); newFace[newFp++] = fnd.object();
} }
} }
@ -483,12 +483,12 @@ Foam::face Foam::meshCutter::loopToFace
if (edgeI != -1) if (edgeI != -1)
{ {
// Existing edge. Insert split-edge point if any. // Existing edge. Insert split-edge point if any.
HashTable<label, edge, Hash<edge>>::const_iterator fnd = EdgeMap<label>::const_iterator fnd =
addedPoints_.find(mesh().edges()[edgeI]); addedPoints_.find(mesh().edges()[edgeI]);
if (fnd != addedPoints_.end()) if (fnd.found())
{ {
newFace[newFacei++] = fnd(); newFace[newFacei++] = fnd.object();
} }
} }
} }
@ -1043,24 +1043,17 @@ void Foam::meshCutter::updateMesh(const mapPolyMesh& morphMap)
} }
{ {
HashTable<label, edge, Hash<edge>> newAddedPoints(addedPoints_.size()); EdgeMap<label> newAddedPoints(addedPoints_.size());
for forAllConstIters(addedPoints_, iter)
(
HashTable<label, edge, Hash<edge>>::const_iterator iter =
addedPoints_.begin();
iter != addedPoints_.end();
++iter
)
{ {
const edge& e = iter.key(); const edge& e = iter.key();
const label addedPointi = iter.object();
label newStart = morphMap.reversePointMap()[e.start()]; label newStart = morphMap.reversePointMap()[e.start()];
label newEnd = morphMap.reversePointMap()[e.end()]; label newEnd = morphMap.reversePointMap()[e.end()];
label addedPointi = iter();
label newAddedPointi = morphMap.reversePointMap()[addedPointi]; label newAddedPointi = morphMap.reversePointMap()[addedPointi];
if ((newStart >= 0) && (newEnd >= 0) && (newAddedPointi >= 0)) if ((newStart >= 0) && (newEnd >= 0) && (newAddedPointi >= 0))

View File

@ -115,6 +115,7 @@ SourceFiles
#include "labelList.H" #include "labelList.H"
#include "typeInfo.H" #include "typeInfo.H"
#include "Map.H" #include "Map.H"
#include "EdgeMap.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -148,7 +149,7 @@ class meshCutter
//- Points added in last setRefinement. Per split edge label of added //- Points added in last setRefinement. Per split edge label of added
// point // point
HashTable<label, edge, Hash<edge>> addedPoints_; EdgeMap<label> addedPoints_;
// Private Static Functions // Private Static Functions
@ -307,7 +308,7 @@ public:
} }
//- Points added. Per split edge label of added point //- Points added. Per split edge label of added point
const HashTable<label, edge, Hash<edge>>& addedPoints() const const EdgeMap<label>& addedPoints() const
{ {
return addedPoints_; return addedPoints_;
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -27,24 +27,13 @@ License
#include "error.H" #include "error.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "cellModeller.H" #include "cellModeller.H"
#include "demandDrivenData.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::label Foam::ensightCells::nTypes = 5; const Foam::label Foam::ensightCells::nTypes = 5;
namespace Foam const char* Foam::ensightCells::elemNames[5] =
{ { "tetra4", "pyramid5", "penta6", "hexa8", "nfaced" };
template<>
const char* Foam::NamedEnum
<
Foam::ensightCells::elemType,
5
>::names[] = { "tetra4", "pyramid5", "penta6", "hexa8", "nfaced" };
}
const Foam::NamedEnum<Foam::ensightCells::elemType, 5>
Foam::ensightCells::elemEnum;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -63,9 +52,8 @@ void Foam::ensightCells::resizeAll()
n = 0; n = 0;
forAll(sizes_, typei) forAll(sizes_, typei)
{ {
deleteDemandDrivenData(lists_[typei]); slices_[typei].setStart(n);
slices_[typei].setSize(sizes_[typei]);
lists_[typei] = new SubList<label>(address_, sizes_[typei], n);
n += sizes_[typei]; n += sizes_[typei];
} }
@ -78,16 +66,10 @@ Foam::ensightCells::ensightCells(const label partIndex)
: :
index_(partIndex), index_(partIndex),
address_(), address_(),
sizes_(Zero), slices_(),
lists_() sizes_(Zero)
{ {
// Ensure sub-lists are properly initialized to nullptr resizeAll(); // adjust allocation/sizing
forAll(lists_, typei)
{
lists_[typei] = nullptr;
}
resizeAll(); // adjust allocation
} }
@ -95,22 +77,16 @@ Foam::ensightCells::ensightCells(const ensightCells& obj)
: :
index_(obj.index_), index_(obj.index_),
address_(obj.address_), address_(obj.address_),
sizes_(), slices_(),
lists_() sizes_()
{ {
// Ensure sub-lists are properly initialized to nullptr // Save the total (reduced) sizes
forAll(lists_, typei)
{
lists_[typei] = nullptr;
}
// Total (reduced) sizes
FixedList<label, 5> totSizes = obj.sizes_; FixedList<label, 5> totSizes = obj.sizes_;
// Local sizes // Need local sizes for the resize operation
this->sizes_ = obj.sizes(); this->sizes_ = obj.sizes();
resizeAll(); // adjust allocation resizeAll(); // adjust allocation/sizing
// Restore total (reduced) sizes // Restore total (reduced) sizes
this->sizes_ = totSizes; this->sizes_ = totSizes;
@ -120,13 +96,7 @@ Foam::ensightCells::ensightCells(const ensightCells& obj)
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::ensightCells::~ensightCells() Foam::ensightCells::~ensightCells()
{ {}
forAll(lists_, typei)
{
deleteDemandDrivenData(lists_[typei]);
}
address_.clear();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -134,27 +104,15 @@ Foam::ensightCells::~ensightCells()
Foam::FixedList<Foam::label, 5> Foam::ensightCells::sizes() const Foam::FixedList<Foam::label, 5> Foam::ensightCells::sizes() const
{ {
FixedList<label, 5> count; FixedList<label, 5> count;
forAll(lists_, typei) forAll(slices_, typei)
{ {
count[typei] = lists_[typei]->size(); count[typei] = slices_[typei].size();
} }
return count; return count;
} }
Foam::label Foam::ensightCells::offset(const enum elemType what) const
{
label n = 0;
for (label typei = 0; typei < label(what); ++typei)
{
n += lists_[typei]->size();
}
return n;
}
Foam::label Foam::ensightCells::total() const Foam::label Foam::ensightCells::total() const
{ {
label n = 0; label n = 0;
@ -175,9 +133,10 @@ void Foam::ensightCells::clear()
void Foam::ensightCells::reduce() void Foam::ensightCells::reduce()
{ {
// No listCombineGather, listCombineScatter for FixedList
forAll(sizes_, typei) forAll(sizes_, typei)
{ {
sizes_[typei] = lists_[typei]->size(); sizes_[typei] = slices_[typei].size();
Foam::reduce(sizes_[typei], sumOp<label>()); Foam::reduce(sizes_[typei], sumOp<label>());
} }
} }
@ -185,9 +144,13 @@ void Foam::ensightCells::reduce()
void Foam::ensightCells::sort() void Foam::ensightCells::sort()
{ {
forAll(lists_, typei) forAll(slices_, typei)
{ {
Foam::sort(*(lists_[typei])); if (slices_[typei].size())
{
SubList<label> idLst(address_, slices_[typei]);
Foam::sort(idLst);
}
} }
} }
@ -240,7 +203,7 @@ void Foam::ensightCells::classify
} }
resizeAll(); // adjust allocation resizeAll(); // adjust allocation
sizes_ = Zero; // reset sizes sizes_ = Zero; // reset sizes - use for local indexing here
// Assign cell-id per shape type // Assign cell-id per shape type
for (label listi = 0; listi < sz; ++listi) for (label listi = 0; listi < sz; ++listi)
@ -267,7 +230,10 @@ void Foam::ensightCells::classify
} }
// eg, the processor local cellId // eg, the processor local cellId
lists_[what]->operator[](sizes_[what]++) = id; UList<label> slice = address_[slices_[what]];
slice[sizes_[what]] = id;
sizes_[what]++;
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -35,8 +35,6 @@ Description
#include "labelList.H" #include "labelList.H"
#include "FixedList.H" #include "FixedList.H"
#include "SubList.H"
#include "NamedEnum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -58,18 +56,18 @@ public:
//- Addressable ensight element types //- Addressable ensight element types
enum elemType enum elemType
{ {
TETRA4, TETRA4, //!< "tetra4"
PYRAMID5, PYRAMID5, //!< "pyramid5"
PENTA6, PENTA6, //!< "penta6"
HEXA8, HEXA8, //!< "hexa8"
NFACED NFACED //!< "nfaced"
}; };
//- Number of element types (5) //- Number of element types (5)
static const label nTypes; static const label nTypes;
//- The Ensight names for each element type //- The ensight element type names
static const NamedEnum<elemType, 5> elemEnum; static const char* elemNames[5];
// Static Member Functions // Static Member Functions
@ -86,17 +84,16 @@ private:
// The ensight part number is typically this value +1. // The ensight part number is typically this value +1.
label index_; label index_;
//- Linear list of ids, sub-sectioned per element type via SubLists //- Linear list of ids, sub-sectioned per element type by sub-lists
labelList address_; labelList address_;
//- Slices (sub-lists) of the address ids for each element type.
FixedList<labelRange, 5> slices_;
//- List of global sizes for each element type. //- List of global sizes for each element type.
// Used temporarily for local sizes when building the element lists. // Used temporarily for local sizes when building the element lists.
FixedList<label, 5> sizes_; FixedList<label, 5> sizes_;
//- List of ids for each element type.
// Managed via pointers, since a SubList cannot be relocated/resized.
FixedList<SubList<label>*, 5> lists_;
// Private Member Functions // Private Member Functions
@ -115,7 +112,7 @@ public:
ensightCells(label partIndex = 0); ensightCells(label partIndex = 0);
//- Copy constructor. Needed for lists etc. //- Copy constructor. Needed for lists etc.
ensightCells(const ensightCells&); ensightCells(const ensightCells& obj);
//- Destructor //- Destructor
@ -135,6 +132,9 @@ public:
//- The processor local size of all elements. //- The processor local size of all elements.
inline label size() const; inline label size() const;
//- The processor local size of the specified element type.
inline label size(const enum elemType) const;
//- The global number of the specified element type. //- The global number of the specified element type.
// This value is only meaningful after a reduce operation. // This value is only meaningful after a reduce operation.
inline label total(const enum elemType) const; inline label total(const enum elemType) const;
@ -151,23 +151,23 @@ public:
FixedList<label, 5> sizes() const; FixedList<label, 5> sizes() const;
//- Processor local starting offset of element type. //- Processor local starting offset of element type.
label offset(const enum elemType what) const; inline label offset(const enum elemType what) const;
//- Return the (local) cell ids of the specified element type //- Return the (local) cell ids of the specified element type
inline const labelUList& cellIds(const enum elemType) const; inline const labelUList cellIds(const enum elemType) const;
//- Return the cell ids of all elements //- Return the cell ids of all elements
inline const labelUList& cellIds() const; inline const labelUList& cellIds() const;
// Edit // Edit
//- Classify cell types and set the element lists. //- Classify cell types and set the element lists.
// The optional indirect addressing can be used when classifying // The optional indirect addressing can be used when classifying
// groups of cells (eg, from a cellZone etc). // groups of cells (eg, from a cellZone etc).
void classify void classify
( (
const polyMesh&, const polyMesh& mesh,
const labelUList& addressing = labelUList::null() const labelUList& addressing = labelUList::null()
); );

View File

@ -29,7 +29,7 @@ License
inline const char* Foam::ensightCells::key(const enum elemType what) inline const char* Foam::ensightCells::key(const enum elemType what)
{ {
return elemEnum[what]; return elemNames[what];
} }
@ -63,20 +63,24 @@ inline Foam::label Foam::ensightCells::total(const enum elemType what) const
} }
inline const Foam::labelUList& Foam::ensightCells::cellIds inline Foam::label Foam::ensightCells::size(const enum elemType what) const
{
return slices_[what].size();
}
inline Foam::label Foam::ensightCells::offset(const enum elemType what) const
{
return slices_[what].start();
}
inline const Foam::labelUList Foam::ensightCells::cellIds
( (
const enum elemType what const enum elemType what
) const ) const
{ {
if (!lists_[what]) return address_[slices_[what]];
{
FatalErrorInFunction
<< "Accessing unallocated sublist for elem-type: "
<< elemEnum[what]
<< exit(FatalError);
}
return *(lists_[what]);
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -27,24 +27,13 @@ License
#include "error.H" #include "error.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "ListOps.H" #include "ListOps.H"
#include "demandDrivenData.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::label Foam::ensightFaces::nTypes = 3; const Foam::label Foam::ensightFaces::nTypes = 3;
namespace Foam const char* Foam::ensightFaces::elemNames[3] =
{ { "tria3", "quad4", "nsided" };
template<>
const char* Foam::NamedEnum
<
Foam::ensightFaces::elemType,
3
>::names[] = { "tria3", "quad4", "nsided" };
}
const Foam::NamedEnum<Foam::ensightFaces::elemType, 3>
Foam::ensightFaces::elemEnum;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -99,9 +88,8 @@ void Foam::ensightFaces::resizeAll()
n = 0; n = 0;
forAll(sizes_, typei) forAll(sizes_, typei)
{ {
deleteDemandDrivenData(lists_[typei]); slices_[typei].setStart(n);
slices_[typei].setSize(sizes_[typei]);
lists_[typei] = new SubList<label>(address_, sizes_[typei], n);
n += sizes_[typei]; n += sizes_[typei];
} }
@ -118,16 +106,10 @@ Foam::ensightFaces::ensightFaces(label partIndex)
index_(partIndex), index_(partIndex),
address_(), address_(),
flipMap_(), flipMap_(),
sizes_(Zero), slices_(),
lists_() sizes_(Zero)
{ {
// Ensure sub-lists are properly initialized to nullptr resizeAll(); // adjust allocation/sizing
forAll(lists_, typei)
{
lists_[typei] = nullptr;
}
resizeAll(); // adjust allocation
} }
@ -136,22 +118,16 @@ Foam::ensightFaces::ensightFaces(const ensightFaces& obj)
index_(obj.index_), index_(obj.index_),
address_(obj.address_), address_(obj.address_),
flipMap_(obj.flipMap_), flipMap_(obj.flipMap_),
sizes_(), slices_(),
lists_() sizes_()
{ {
// Ensure sub-lists are properly initialized to nullptr // Save the total (reduced) sizes
forAll(lists_, typei)
{
lists_[typei] = nullptr;
}
// Total (reduced) sizes
FixedList<label, 3> totSizes = obj.sizes_; FixedList<label, 3> totSizes = obj.sizes_;
// Local sizes // Need local sizes for the resize operation
this->sizes_ = obj.sizes(); this->sizes_ = obj.sizes();
resizeAll(); // adjust allocation resizeAll(); // adjust allocation/sizing
// Restore total (reduced) sizes // Restore total (reduced) sizes
this->sizes_ = totSizes; this->sizes_ = totSizes;
@ -161,14 +137,7 @@ Foam::ensightFaces::ensightFaces(const ensightFaces& obj)
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::ensightFaces::~ensightFaces() Foam::ensightFaces::~ensightFaces()
{ {}
forAll(lists_, typei)
{
deleteDemandDrivenData(lists_[typei]);
}
address_.clear();
flipMap_.clear();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -176,27 +145,15 @@ Foam::ensightFaces::~ensightFaces()
Foam::FixedList<Foam::label, 3> Foam::ensightFaces::sizes() const Foam::FixedList<Foam::label, 3> Foam::ensightFaces::sizes() const
{ {
FixedList<label, 3> count; FixedList<label, 3> count;
forAll(lists_, typei) forAll(slices_, typei)
{ {
count[typei] = lists_[typei]->size(); count[typei] = slices_[typei].size();
} }
return count; return count;
} }
Foam::label Foam::ensightFaces::offset(const enum elemType what) const
{
label n = 0;
for (label typei = 0; typei < label(what); ++typei)
{
n += lists_[typei]->size();
}
return n;
}
Foam::label Foam::ensightFaces::total() const Foam::label Foam::ensightFaces::total() const
{ {
label n = 0; label n = 0;
@ -217,9 +174,10 @@ void Foam::ensightFaces::clear()
void Foam::ensightFaces::reduce() void Foam::ensightFaces::reduce()
{ {
// No listCombineGather, listCombineScatter for FixedList
forAll(sizes_, typei) forAll(sizes_, typei)
{ {
sizes_[typei] = lists_[typei]->size(); sizes_[typei] = slices_[typei].size();
Foam::reduce(sizes_[typei], sumOp<label>()); Foam::reduce(sizes_[typei], sumOp<label>());
} }
} }
@ -229,20 +187,15 @@ void Foam::ensightFaces::sort()
{ {
if (flipMap_.size() == address_.size()) if (flipMap_.size() == address_.size())
{ {
// sort flip map too // Must sort flip map as well
labelList order; labelList order;
label start = 0;
forAll(lists_, typei) forAll(slices_, typei)
{ {
SubList<label>& idLst = *(lists_[typei]); if (slices_[typei].size())
const label sz = idLst.size();
if (sz)
{ {
SubList<bool> flip(flipMap_, sz, start); SubList<label> idLst(address_, slices_[typei]);
start += sz; // for next sub-list SubList<bool> flip(flipMap_, slices_[typei]);
Foam::sortedOrder(idLst, order); Foam::sortedOrder(idLst, order);
@ -254,11 +207,16 @@ void Foam::ensightFaces::sort()
else else
{ {
// no flip-maps, simpler to sort // no flip-maps, simpler to sort
forAll(lists_, typei) forAll(slices_, typei)
{ {
Foam::sort(*(lists_[typei])); if (slices_[typei].size())
{
SubList<label> idLst(address_, slices_[typei]);
Foam::sort(idLst);
}
} }
flipMap_.clear(); // for safety
flipMap_.clear(); // for extra safety
} }
} }
@ -278,7 +236,7 @@ void Foam::ensightFaces::classify(const faceList& faces)
} }
resizeAll(); // adjust allocation resizeAll(); // adjust allocation
sizes_ = Zero; // reset sizes sizes_ = Zero; // reset sizes - use for local indexing here
// Assign face-id per shape type // Assign face-id per shape type
for (label listi = 0; listi < sz; ++listi) for (label listi = 0; listi < sz; ++listi)
@ -318,7 +276,7 @@ void Foam::ensightFaces::classify
} }
resizeAll(); // adjust allocation resizeAll(); // adjust allocation
sizes_ = Zero; // reset sizes sizes_ = Zero; // reset sizes - use for local indexing here
if (useFlip) if (useFlip)
{ {
@ -330,11 +288,11 @@ void Foam::ensightFaces::classify
for (label listi = 0; listi < sz; ++listi) for (label listi = 0; listi < sz; ++listi)
{ {
const label faceId = addressing[listi]; const label faceId = addressing[listi];
const bool flip = useFlip && flipMap[listi]; const bool doFlip = useFlip && flipMap[listi];
if (!exclude[faceId]) if (!exclude[faceId])
{ {
add(faces[faceId], faceId, flip); add(faces[faceId], faceId, doFlip);
} }
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -37,7 +37,6 @@ Description
#include "faceList.H" #include "faceList.H"
#include "FixedList.H" #include "FixedList.H"
#include "PackedBoolList.H" #include "PackedBoolList.H"
#include "NamedEnum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -57,16 +56,16 @@ public:
//- Addressable ensight element types //- Addressable ensight element types
enum elemType enum elemType
{ {
TRIA3, TRIA3, //!< "tria3"
QUAD4, QUAD4, //!< "quad4"
NSIDED NSIDED //!< "nsided"
}; };
//- Number of element types (3) //- Number of element types (3)
static const label nTypes; static const label nTypes;
//- The Ensight names for each element type //- The ensight element type names
static const NamedEnum<elemType, 3> elemEnum; static const char* elemNames[3];
// Static Member Functions // Static Member Functions
@ -83,28 +82,27 @@ private:
// The ensight part number is typically this value +1. // The ensight part number is typically this value +1.
label index_; label index_;
//- Linear list of ids, sub-sectioned per element type via SubLists //- Linear list of ids, sub-sectioned per element type by sub-lists
labelList address_; labelList address_;
//- Linear list of face-flips //- Linear list of face-flips
boolList flipMap_; boolList flipMap_;
//- Slices (sub-lists) of the address and flips for each element type.
FixedList<labelRange, 3> slices_;
//- List of global sizes for each element type. //- List of global sizes for each element type.
// Used temporarily for local sizes when building the element lists. // Used temporarily for local sizes when building the element lists.
FixedList<label, 3> sizes_; FixedList<label, 3> sizes_;
//- SubLists of ids for each element type.
// Managed via pointers, since a SubList cannot be relocated/resized.
FixedList<SubList<label>*, 3> lists_;
// Private Member Functions // Private Member Functions
//- Simple classifier //- Simple classifier
inline static elemType whatType(const face&); inline static elemType whatType(const face& f);
//- Low-level internal addition routine //- Low-level internal addition routine
inline void add(const face&, const label id, const bool flip = false); inline void add(const face& f, const label id, const bool flip = false);
//- Use temporarily stored sizes to redimension the element lists //- Use temporarily stored sizes to redimension the element lists
void resizeAll(); void resizeAll();
@ -121,7 +119,7 @@ public:
ensightFaces(label partIndex = 0); ensightFaces(label partIndex = 0);
//- Copy constructor. Needed for lists etc. //- Copy constructor. Needed for lists etc.
ensightFaces(const ensightFaces&); ensightFaces(const ensightFaces& obj);
//- Destructor //- Destructor
@ -141,14 +139,17 @@ public:
//- The processor local size of all elements. //- The processor local size of all elements.
inline label size() const; inline label size() const;
//- The global number of the specified element type. //- The processor local size of the specified element type.
// This value is only meaningful after a reduce operation. inline label size(const enum elemType) const;
inline label total(const enum elemType) const;
//- The global number of all element types. //- The global number of all element types.
// This value is only meaningful after a reduce operation. // This value is only meaningful after a reduce operation.
label total() const; label total() const;
//- The global number of the specified element type.
// This value is only meaningful after a reduce operation.
inline label total(const enum elemType) const;
//- The global numbers per element type. //- The global numbers per element type.
// This value is only meaningful after a reduce operation. // This value is only meaningful after a reduce operation.
inline const FixedList<label, 3>& totals() const; inline const FixedList<label, 3>& totals() const;
@ -157,10 +158,10 @@ public:
FixedList<label, 3> sizes() const; FixedList<label, 3> sizes() const;
//- Processor local starting offset of element type. //- Processor local starting offset of element type.
label offset(const enum elemType what) const; inline label offset(const enum elemType what) const;
//- Return the (local) face ids of the specified element type //- Return the (local) face ids of the specified element type
inline const labelUList& faceIds(const enum elemType) const; inline const labelUList faceIds(const enum elemType) const;
//- Return the processor local face ids of all elements //- Return the processor local face ids of all elements
inline const labelUList& faceIds() const; inline const labelUList& faceIds() const;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -29,7 +29,7 @@ License
inline const char* Foam::ensightFaces::key(const enum elemType what) inline const char* Foam::ensightFaces::key(const enum elemType what)
{ {
return elemEnum[what]; return elemNames[what];
} }
@ -63,20 +63,24 @@ inline Foam::label Foam::ensightFaces::total(const enum elemType what) const
} }
inline const Foam::labelUList& Foam::ensightFaces::faceIds inline Foam::label Foam::ensightFaces::size(const enum elemType what) const
{
return slices_[what].size();
}
inline Foam::label Foam::ensightFaces::offset(const enum elemType what) const
{
return slices_[what].start();
}
inline const Foam::labelUList Foam::ensightFaces::faceIds
( (
const enum elemType what const enum elemType what
) const ) const
{ {
if (!lists_[what]) return address_[slices_[what]];
{
FatalErrorInFunction
<< "Accessing unallocated sublist for elem-type: "
<< elemEnum[what]
<< exit(FatalError);
}
return *(lists_[what]);
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -68,8 +68,18 @@ void Foam::gnuplotSetWriter<Type>::write
) const ) const
{ {
os << "set term postscript color" << nl os << "set term postscript color" << nl
<< "set output \"" << points.name() << ".ps\"" << nl << "set output \"" << points.name() << ".ps\"" << nl;
<< "plot";
// Set secondary Y axis if using two columns. Falls back to same
// values if both on same scale. However, ignore if more columns.
if (valueSetNames.size() == 2)
{
os << "set ylabel \"" << valueSetNames[0] << "\"" << nl
<< "set y2label \"" << valueSetNames[1] << "\"" << nl
<< "set ytics nomirror" << nl << "set y2tics" << nl;
}
os << "plot";
forAll(valueSets, i) forAll(valueSets, i)
{ {
@ -79,10 +89,14 @@ void Foam::gnuplotSetWriter<Type>::write
} }
os << " \"-\" title \"" << valueSetNames[i] << "\" with lines"; os << " \"-\" title \"" << valueSetNames[i] << "\" with lines";
if (valueSetNames.size() == 2)
{
os << " axes x1y" << (i+1) ;
}
} }
os << nl; os << nl;
forAll(valueSets, i) forAll(valueSets, i)
{ {
this->writeTable(points, *valueSets[i], os); this->writeTable(points, *valueSets[i], os);

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -45,23 +45,31 @@ void Foam::functionObjects::histogram::writeGraph
( (
const coordSet& coords, const coordSet& coords,
const word& fieldName, const word& fieldName,
const scalarField& values const scalarField& normalizedValues,
const scalarField& absoluteValues
) const ) const
{ {
const wordList fieldNames(1, fieldName);
fileName outputPath = baseTimeDir(); fileName outputPath = baseTimeDir();
mkDir(outputPath); mkDir(outputPath);
OFstream graphFile OFstream graphFile
( (
outputPath/formatterPtr_().getFileName(coords, fieldNames) outputPath
/formatterPtr_().getFileName
(
coords,
wordList(1, fieldName)
)
); );
Log << " Writing histogram of " << fieldName Log << " Writing histogram of " << fieldName
<< " to " << graphFile.name() << endl; << " to " << graphFile.name() << endl;
List<const scalarField*> yPtrs(1); wordList fieldNames(2);
yPtrs[0] = &values; fieldNames[0] = fieldName;
fieldNames[1] = fieldName + "Count";
List<const scalarField*> yPtrs(2);
yPtrs[0] = &normalizedValues;
yPtrs[1] = &absoluteValues;
formatterPtr_().write(coords, fieldNames, yPtrs, graphFile); formatterPtr_().write(coords, fieldNames, yPtrs, graphFile);
} }
@ -76,7 +84,9 @@ Foam::functionObjects::histogram::histogram
) )
: :
fvMeshFunctionObject(name, runTime, dict), fvMeshFunctionObject(name, runTime, dict),
writeFile(obr_, name) writeFile(obr_, name),
max_(-GREAT),
min_(GREAT)
{ {
read(dict); read(dict);
} }
@ -96,8 +106,9 @@ bool Foam::functionObjects::histogram::read(const dictionary& dict)
writeFile::read(dict); writeFile::read(dict);
dict.lookup("field") >> fieldName_; dict.lookup("field") >> fieldName_;
dict.lookup("max") >> max_;
min_ = dict.lookupOrDefault<scalar>("min", 0); max_ = dict.lookupOrDefault<scalar>("max", -GREAT);
min_ = dict.lookupOrDefault<scalar>("min", GREAT);
dict.lookup("nBins") >> nBins_; dict.lookup("nBins") >> nBins_;
word format(dict.lookup("setFormat")); word format(dict.lookup("setFormat"));
@ -149,38 +160,63 @@ bool Foam::functionObjects::histogram::write()
: obr_.lookupObject<volScalarField>(fieldName_) : obr_.lookupObject<volScalarField>(fieldName_)
); );
scalar histMax = max_;
scalar histMin = min_;
if (max_ == -GREAT)
{
// Determine current min and max
histMax = max(field).value();
if (min_ == GREAT)
{
histMin = min(field).value();
}
Log << " Determined histogram bounds from field"
<< " min/max(" << fieldName_ << ") = "
<< histMin << ' ' << histMax << endl;
}
else if (min_ == GREAT)
{
histMin = 0;
}
// Calculate the mid-points of bins for the graph axis // Calculate the mid-points of bins for the graph axis
pointField xBin(nBins_); pointField xBin(nBins_);
const scalar delta = (max_- min_)/nBins_; const scalar delta = (histMax- histMin)/nBins_;
scalar x = min_ + 0.5*delta; scalar x = histMin + 0.5*delta;
forAll(xBin, i) forAll(xBin, i)
{ {
xBin[i] = point(x, 0, 0); xBin[i] = point(x, 0, 0);
x += delta; x += delta;
} }
scalarField data(nBins_, 0); scalarField dataNormalized(nBins_, 0);
labelField dataCount(nBins_, 0);
const scalarField& V = mesh_.V(); const scalarField& V = mesh_.V();
forAll(field, celli) forAll(field, celli)
{ {
const label bini = (field[celli] - min_)/delta; const label bini = (field[celli] - histMin)/delta;
if (bini >= 0 && bini < nBins_) if (bini >= 0 && bini < nBins_)
{ {
data[bini] += V[celli]; dataNormalized[bini] += V[celli];
dataCount[bini]++;
} }
} }
Pstream::listCombineGather(data, plusEqOp<scalar>()); Pstream::listCombineGather(dataNormalized, plusEqOp<scalar>());
Pstream::listCombineGather(dataCount, plusEqOp<label>());
if (Pstream::master()) if (Pstream::master())
{ {
const scalar sumData = sum(data); const scalar sumData = sum(dataNormalized);
if (sumData > SMALL) if (sumData > SMALL)
{ {
data /= sumData; dataNormalized /= sumData;
const coordSet coords const coordSet coords
( (
@ -190,7 +226,15 @@ bool Foam::functionObjects::histogram::write()
mag(xBin) mag(xBin)
); );
writeGraph(coords, fieldName_, data);
// Convert count field from labelField to scalarField
scalarField count(dataCount.size());
forAll(count, i)
{
count[i] = 1.0*dataCount[i];
}
writeGraph(coords, fieldName_, dataNormalized, count);
} }
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -53,11 +53,17 @@ Usage
type | type name: histogram | yes | type | type name: histogram | yes |
field | Field to analyse | yes | field | Field to analyse | yes |
nBins | Number of bins for the histogram | yes| nBins | Number of bins for the histogram | yes|
max | Maximum value sampled | yes | max | Maximum value sampled | no | field max
min | minimum value sampled | no | 0 min | minimum value sampled | no | 0
setFormat | Output format | yes | setFormat | Output format | yes |
\endtable \endtable
Note
If max is not provided it will use the field's min and max as the bin
extremes. If max is provided but not min it will use 0. The set written
contains two columns, the first the volume averaged values, the second
the raw bin count.
See also See also
Foam::functionObject Foam::functionObject
Foam::functionObjects::fvMeshFunctionObject Foam::functionObjects::fvMeshFunctionObject
@ -115,7 +121,8 @@ class histogram
( (
const coordSet& coords, const coordSet& coords,
const word& valueName, const word& valueName,
const scalarField& values const scalarField& normalizedValues,
const scalarField& absoluteValues
) const; ) const;
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct

View File

@ -33,24 +33,17 @@ License
#include "polyMesh.H" #include "polyMesh.H"
#include "surfMesh.H" #include "surfMesh.H"
#include "primitivePatch.H" #include "primitivePatch.H"
#include "faceTraits.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<class Face>
inline bool Foam::MeshedSurface<Face>::isTri()
{
return false;
}
template<class Face> template<class Face>
Foam::wordHashSet Foam::MeshedSurface<Face>::readTypes() Foam::wordHashSet Foam::MeshedSurface<Face>::readTypes()
{ {
return wordHashSet(*fileExtensionConstructorTablePtr_); return wordHashSet(*fileExtensionConstructorTablePtr_);
} }
template<class Face> template<class Face>
Foam::wordHashSet Foam::MeshedSurface<Face>::writeTypes() Foam::wordHashSet Foam::MeshedSurface<Face>::writeTypes()
{ {
@ -116,25 +109,34 @@ void Foam::MeshedSurface<Face>::write
const fileName& name, const fileName& name,
const MeshedSurface<Face>& surf const MeshedSurface<Face>& surf
) )
{
write(name, name.ext(), surf);
}
template<class Face>
void Foam::MeshedSurface<Face>::write
(
const fileName& name,
const word& ext,
const MeshedSurface<Face>& surf
)
{ {
if (debug) if (debug)
{ {
InfoInFunction << "Writing to " << name << endl; InfoInFunction << "Writing to " << name << endl;
} }
const word ext = name.ext(); auto mfIter = writefileExtensionMemberFunctionTablePtr_->find(ext);
typename writefileExtensionMemberFunctionTable::iterator mfIter = if (!mfIter.found())
writefileExtensionMemberFunctionTablePtr_->find(ext);
if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
{ {
// No direct writer, delegate to proxy if possible // No direct writer, delegate to proxy if possible
const wordHashSet& delegate = ProxyType::writeTypes(); const wordHashSet& delegate = ProxyType::writeTypes();
if (delegate.found(ext)) if (delegate.found(ext))
{ {
MeshedSurfaceProxy<Face>(surf).write(name); MeshedSurfaceProxy<Face>(surf).write(name, ext);
} }
else else
{ {
@ -850,6 +852,11 @@ bool Foam::MeshedSurface<Face>::checkFaces
template<class Face> template<class Face>
Foam::label Foam::MeshedSurface<Face>::nTriangles() const Foam::label Foam::MeshedSurface<Face>::nTriangles() const
{ {
if (faceTraits<Face>::isTri())
{
return ParentType::size();
}
return nTriangles return nTriangles
( (
const_cast<List<label>&>(List<label>::null()) const_cast<List<label>&>(List<label>::null())
@ -905,10 +912,18 @@ Foam::label Foam::MeshedSurface<Face>::nTriangles
template<class Face> template<class Face>
Foam::label Foam::MeshedSurface<Face>::triangulate() Foam::label Foam::MeshedSurface<Face>::triangulate()
{ {
return triangulate if (faceTraits<Face>::isTri())
( {
const_cast<List<label>&>(List<label>::null()) // Inplace triangulation of triFace/labelledTri surface = no-op
); return 0;
}
else
{
return triangulate
(
const_cast<List<label>&>(List<label>::null())
);
}
} }
@ -918,6 +933,17 @@ Foam::label Foam::MeshedSurface<Face>::triangulate
List<label>& faceMapOut List<label>& faceMapOut
) )
{ {
if (faceTraits<Face>::isTri())
{
// Inplace triangulation of triFace/labelledTri surface = no-op
if (notNull(faceMapOut))
{
faceMapOut.clear();
}
return 0;
}
label nTri = 0; label nTri = 0;
label maxTri = 0; // the maximum number of triangles for any single face label maxTri = 0; // the maximum number of triangles for any single face
List<Face>& faceLst = this->storedFaces(); List<Face>& faceLst = this->storedFaces();
@ -966,7 +992,7 @@ Foam::label Foam::MeshedSurface<Face>::triangulate
{ {
label fp1 = f.fcIndex(fp); label fp1 = f.fcIndex(fp);
newFaces[nTri] = triFace(f[0], f[fp], f[fp1]); newFaces[nTri] = Face{f[0], f[fp], f[fp1]};
faceMap[nTri] = facei; faceMap[nTri] = facei;
nTri++; nTri++;
} }

View File

@ -186,9 +186,6 @@ public:
// Static // Static
//- Face storage only handles triangulated faces
inline static bool isTri();
//- Can we read this file format? //- Can we read this file format?
static bool canRead(const fileName&, const bool verbose=false); static bool canRead(const fileName&, const bool verbose=false);
@ -210,36 +207,36 @@ public:
//- Construct by transferring components (points, faces, zones). //- Construct by transferring components (points, faces, zones).
MeshedSurface MeshedSurface
( (
const Xfer<pointField>&, const Xfer<pointField>& pointLst,
const Xfer<List<Face>>&, const Xfer<List<Face>>& faceLst,
const Xfer<surfZoneList>& const Xfer<surfZoneList>& zoneLst
); );
//- Construct by transferring components (points, faces). //- Construct by transferring components (points, faces).
// Use zone information if available // Use zone information if available
MeshedSurface MeshedSurface
( (
const Xfer<pointField>&, const Xfer<pointField>& pointLst,
const Xfer<List<Face>>&, const Xfer<List<Face>>& faceLst,
const labelUList& zoneSizes = labelUList(), const labelUList& zoneSizes = labelUList(),
const UList<word>& zoneNames = UList<word>() const UList<word>& zoneNames = UList<word>()
); );
//- Construct as copy //- Construct as copy
MeshedSurface(const MeshedSurface&); MeshedSurface(const MeshedSurface& surf);
//- Construct from a UnsortedMeshedSurface //- Construct from a UnsortedMeshedSurface
MeshedSurface(const UnsortedMeshedSurface<Face>&); MeshedSurface(const UnsortedMeshedSurface<Face>& surf);
//- Construct from a boundary mesh with local points/faces //- Construct from a boundary mesh with local points/faces
MeshedSurface MeshedSurface
( (
const polyBoundaryMesh&, const polyBoundaryMesh& bMesh,
const bool globalPoints=false const bool globalPoints=false
); );
//- Construct from a surfMesh //- Construct from a surfMesh
MeshedSurface(const surfMesh&); MeshedSurface(const surfMesh& mesh);
//- Construct by transferring the contents from a UnsortedMeshedSurface //- Construct by transferring the contents from a UnsortedMeshedSurface
MeshedSurface(const Xfer<UnsortedMeshedSurface<Face>>&); MeshedSurface(const Xfer<UnsortedMeshedSurface<Face>>&);
@ -248,18 +245,18 @@ public:
MeshedSurface(const Xfer<MeshedSurface<Face>>&); MeshedSurface(const Xfer<MeshedSurface<Face>>&);
//- Construct from file name (uses extension to determine type) //- Construct from file name (uses extension to determine type)
MeshedSurface(const fileName&); MeshedSurface(const fileName& name);
//- Construct from file name (uses extension to determine type) //- Construct from file name (uses extension to determine type)
MeshedSurface(const fileName&, const word& ext); MeshedSurface(const fileName& name, const word& ext);
//- Construct from Istream //- Construct from Istream
MeshedSurface(Istream&); MeshedSurface(Istream& is);
//- Construct from database //- Construct from database
MeshedSurface MeshedSurface
( (
const Time&, const Time& t,
const word& surfName = word::null const word& surfName = word::null
); );
@ -283,7 +280,7 @@ public:
//- Select constructed from filename (explicit extension) //- Select constructed from filename (explicit extension)
static autoPtr<MeshedSurface> New static autoPtr<MeshedSurface> New
( (
const fileName&, const fileName& name,
const word& ext const word& ext
); );
@ -310,11 +307,19 @@ public:
(name, surf) (name, surf)
); );
//- Write to file //- Write to file, selecting writer based on its extension
static void write static void write
( (
const fileName&, const fileName& name,
const MeshedSurface<Face>& const MeshedSurface<Face>& surf
);
//- Write to file, selecting writer based on the given extension
static void write
(
const fileName& name,
const word& ext,
const MeshedSurface<Face>& surf
); );
@ -563,8 +568,6 @@ bool MeshedSurface<labelledTri>::addZonesToFaces();
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "MeshedSurfaceI.H"
#ifdef NoRepository #ifdef NoRepository
#include "MeshedSurface.C" #include "MeshedSurface.C"
#endif #endif

View File

@ -50,7 +50,7 @@ namespace Foam
) )
{ {
// First triangulate // First triangulate
// - slightly wasteful for space, but manages adjusts the zones too! // - slightly wasteful for space, but adjusts the zones too!
surf.triangulate(); surf.triangulate();
this->storedPoints().transfer(surf.storedPoints()); this->storedPoints().transfer(surf.storedPoints());
this->storedZones().transfer(surf.storedZones()); this->storedZones().transfer(surf.storedZones());
@ -81,12 +81,12 @@ namespace Foam
) )
{ {
// First triangulate // First triangulate
// - slightly wasteful for space, but manages adjusts the zones too! // - slightly wasteful for space, but adjusts the zones too!
surf.triangulate(); surf.triangulate();
this->storedPoints().transfer(surf.storedPoints()); this->storedPoints().transfer(surf.storedPoints());
this->storedZones().transfer(surf.storedZones()); this->storedZones().transfer(surf.storedZones());
// transcribe from face -> triFace // transcribe from face -> labelledTri (via triFace)
const List<face>& origFaces = surf.surfFaces(); const List<face>& origFaces = surf.surfFaces();
List<labelledTri> newFaces(origFaces.size()); List<labelledTri> newFaces(origFaces.size());
forAll(origFaces, facei) forAll(origFaces, facei)

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -25,6 +25,7 @@ License
#include "MeshedSurface.H" #include "MeshedSurface.H"
#include "boundBox.H" #include "boundBox.H"
#include "faceTraits.H"
#include "Istream.H" #include "Istream.H"
#include "Ostream.H" #include "Ostream.H"
@ -58,7 +59,7 @@ template<class Face>
void Foam::MeshedSurface<Face>::writeStats(Ostream& os) const void Foam::MeshedSurface<Face>::writeStats(Ostream& os) const
{ {
os << "points : " << this->points().size() << nl; os << "points : " << this->points().size() << nl;
if (MeshedSurface<Face>::isTri()) if (faceTraits<Face>::isTri())
{ {
os << "triangles : " << this->size() << nl; os << "triangles : " << this->size() << nl;
} }
@ -82,7 +83,7 @@ void Foam::MeshedSurface<Face>::writeStats(Ostream& os) const
os << "faces : " << this->size() os << "faces : " << this->size()
<< " (tri:" << nTri << " quad:" << nQuad << " (tri:" << nTri << " quad:" << nQuad
<< " poly:" << (this->size() - nTri - nQuad ) << ")" << nl; << " poly:" << (this->size() - nTri - nQuad) << ")" << nl;
} }
os << "boundingBox : " << boundBox(this->points()) << endl; os << "boundingBox : " << boundBox(this->points()) << endl;

View File

@ -38,10 +38,9 @@ Foam::MeshedSurface<Face>::New(const fileName& name, const word& ext)
InfoInFunction << "Constructing MeshedSurface" << endl; InfoInFunction << "Constructing MeshedSurface" << endl;
} }
typename fileExtensionConstructorTable::iterator cstrIter = auto cstrIter = fileExtensionConstructorTablePtr_->find(ext);
fileExtensionConstructorTablePtr_->find(ext);
if (cstrIter == fileExtensionConstructorTablePtr_->end()) if (!cstrIter.found())
{ {
// No direct reader, delegate to friend if possible // No direct reader, delegate to friend if possible
const wordHashSet& delegate = FriendType::readTypes(); const wordHashSet& delegate = FriendType::readTypes();

View File

@ -29,6 +29,7 @@ License
#include "ListOps.H" #include "ListOps.H"
#include "surfMesh.H" #include "surfMesh.H"
#include "OFstream.H" #include "OFstream.H"
#include "faceTraits.H"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
@ -59,18 +60,27 @@ void Foam::MeshedSurfaceProxy<Face>::write
const fileName& name, const fileName& name,
const MeshedSurfaceProxy& surf const MeshedSurfaceProxy& surf
) )
{
write(name, name.ext(), surf);
}
template<class Face>
void Foam::MeshedSurfaceProxy<Face>::write
(
const fileName& name,
const word& ext,
const MeshedSurfaceProxy& surf
)
{ {
if (debug) if (debug)
{ {
InfoInFunction << "Writing to " << name << endl; InfoInFunction << "Writing to " << name << endl;
} }
const word ext = name.ext(); auto mfIter = writefileExtensionMemberFunctionTablePtr_->find(ext);
typename writefileExtensionMemberFunctionTable::iterator mfIter = if (!mfIter.found())
writefileExtensionMemberFunctionTablePtr_->find(ext);
if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Unknown file extension " << ext << nl << nl << "Unknown file extension " << ext << nl << nl
@ -237,38 +247,24 @@ Foam::MeshedSurfaceProxy<Face>::~MeshedSurfaceProxy()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
namespace Foam
{
// Number of triangles for a triFace surface
template<>
inline label MeshedSurfaceProxy<triFace>::nTriangles() const
{
return this->size();
}
// Number of triangles for a labelledTri surface
template<>
inline label MeshedSurfaceProxy<labelledTri>::nTriangles() const
{
return this->size();
}
}
template<class Face> template<class Face>
inline Foam::label Foam::MeshedSurfaceProxy<Face>::nTriangles() const inline Foam::label Foam::MeshedSurfaceProxy<Face>::nTriangles() const
{ {
label nTri = 0; if (faceTraits<Face>::isTri())
const List<Face>& faceLst = this->surfFaces();
forAll(faceLst, facei)
{ {
nTri += faceLst[facei].nTriangles(); return this->size();
} }
else
{
label nTri = 0;
const List<Face>& faceLst = this->surfFaces();
forAll(faceLst, facei)
{
nTri += faceLst[facei].nTriangles();
}
return nTri; return nTri;
}
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -100,9 +100,9 @@ public:
//- Construct from component references //- Construct from component references
MeshedSurfaceProxy MeshedSurfaceProxy
( (
const pointField&, const pointField& pointLst,
const List<Face>&, const List<Face>& faceLst,
const List<surfZone>& = List<surfZone>(), const List<surfZone>& zoneLst = List<surfZone>(),
const List<label>& faceMap = List<label>() const List<label>& faceMap = List<label>()
); );
@ -126,11 +126,19 @@ public:
(name, surf) (name, surf)
); );
//- Write to file //- Write to file, selected based on its extension
static void write static void write
( (
const fileName&, const fileName& name,
const MeshedSurfaceProxy<Face>& const MeshedSurfaceProxy& surf
);
//- Write to file, selected based on given extension
static void write
(
const fileName& name,
const word& ext,
const MeshedSurfaceProxy& surf
); );
@ -188,10 +196,16 @@ public:
write(name, *this); write(name, *this);
} }
//- Generic write routine. Chooses writer based on extension.
virtual void write(const fileName& name, const word& ext) const
{
write(name, ext, *this);
}
//- Write to database //- Write to database
virtual void write virtual void write
( (
const Time&, const Time& t,
const word& surfName = word::null const word& surfName = word::null
) const; ) const;
}; };

View File

@ -113,17 +113,16 @@ void Foam::UnsortedMeshedSurface<Face>::write
const word ext = name.ext(); const word ext = name.ext();
typename writefileExtensionMemberFunctionTable::iterator mfIter = auto mfIter = writefileExtensionMemberFunctionTablePtr_->find(ext);
writefileExtensionMemberFunctionTablePtr_->find(ext);
if (mfIter == writefileExtensionMemberFunctionTablePtr_->end()) if (!mfIter.found())
{ {
// No direct writer, delegate to proxy if possible // No direct writer, delegate to proxy if possible
const wordHashSet& delegate = ProxyType::writeTypes(); const wordHashSet& delegate = ProxyType::writeTypes();
if (delegate.found(ext)) if (delegate.found(ext))
{ {
MeshedSurfaceProxy<Face>(surf).write(name); MeshedSurfaceProxy<Face>(surf).write(name, ext);
} }
else else
{ {

View File

@ -37,10 +37,9 @@ Foam::UnsortedMeshedSurface<Face>::New(const fileName& name, const word& ext)
InfoInFunction << "Constructing UnsortedMeshedSurface" << endl; InfoInFunction << "Constructing UnsortedMeshedSurface" << endl;
} }
typename fileExtensionConstructorTable::iterator cstrIter = auto cstrIter = fileExtensionConstructorTablePtr_->find(ext);
fileExtensionConstructorTablePtr_->find(ext);
if (cstrIter == fileExtensionConstructorTablePtr_->end()) if (!cstrIter.found())
{ {
// No direct reader, delegate to parent if possible // No direct reader, delegate to parent if possible
const wordHashSet& delegate = ParentType::readTypes(); const wordHashSet& delegate = ParentType::readTypes();

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -26,6 +26,7 @@ License
#include "AC3DsurfaceFormat.H" #include "AC3DsurfaceFormat.H"
#include "IStringStream.H" #include "IStringStream.H"
#include "PrimitivePatch.H" #include "PrimitivePatch.H"
#include "faceTraits.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -194,9 +195,9 @@ bool Foam::fileFormats::AC3DsurfaceFormat<Face>::read
verts[vertI] = parse<int>(line) + vertexOffset; verts[vertI] = parse<int>(line) + vertexOffset;
} }
labelUList& f = static_cast<labelUList&>(verts); const labelUList& f = static_cast<const labelUList&>(verts);
if (MeshedSurface<Face>::isTri() && f.size() > 3) if (faceTraits<Face>::isTri() && f.size() > 3)
{ {
// simple face triangulation about f[0] // simple face triangulation about f[0]
// points may be incomplete // points may be incomplete
@ -204,7 +205,7 @@ bool Foam::fileFormats::AC3DsurfaceFormat<Face>::read
{ {
label fp2 = f.fcIndex(fp1); label fp2 = f.fcIndex(fp1);
dynFaces.append(triFace(f[0], f[fp1], f[fp2])); dynFaces.append(Face{f[0], f[fp1], f[fp2]});
sizes[zoneI]++; sizes[zoneI]++;
} }
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -28,8 +28,8 @@ License
#include "clock.H" #include "clock.H"
#include "IFstream.H" #include "IFstream.H"
#include "IStringStream.H" #include "IStringStream.H"
#include "Ostream.H"
#include "OFstream.H" #include "OFstream.H"
#include "faceTraits.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -187,7 +187,7 @@ bool Foam::fileFormats::GTSsurfaceFormat<Face>::read
<< exit(FatalError); << exit(FatalError);
} }
faceLst[facei] = triFace(e0Far, common01, e1Far); faceLst[facei] = Face{e0Far, common01, e1Far};
zoneIds[facei] = zoneI; zoneIds[facei] = zoneI;
} }
@ -229,7 +229,7 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write
// check if output triangulation would be required // check if output triangulation would be required
// It is too annoying to triangulate on-the-fly // It is too annoying to triangulate on-the-fly
// just issue a warning and get out // just issue a warning and get out
if (!MeshedSurface<Face>::isTri()) if (!faceTraits<Face>::isTri())
{ {
label nNonTris = 0; label nNonTris = 0;
forAll(faceLst, facei) forAll(faceLst, facei)
@ -249,7 +249,6 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write
} }
} }
OFstream os(filename); OFstream os(filename);
if (!os.good()) if (!os.good())
{ {
@ -331,7 +330,7 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write
// check if output triangulation would be required // check if output triangulation would be required
// It is too annoying to triangulate on-the-fly // It is too annoying to triangulate on-the-fly
// just issue a warning and get out // just issue a warning and get out
if (!MeshedSurface<Face>::isTri()) if (!faceTraits<Face>::isTri())
{ {
label nNonTris = 0; label nNonTris = 0;
forAll(faceLst, facei) forAll(faceLst, facei)
@ -351,7 +350,6 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write
} }
} }
OFstream os(filename); OFstream os(filename);
if (!os.good()) if (!os.good())
{ {

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -26,6 +26,7 @@ License
#include "NASsurfaceFormat.H" #include "NASsurfaceFormat.H"
#include "IFstream.H" #include "IFstream.H"
#include "IStringStream.H" #include "IStringStream.H"
#include "faceTraits.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -191,12 +192,10 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
if (cmd == "CTRIA3") if (cmd == "CTRIA3")
{ {
triFace fTri;
label groupId = readLabel(IStringStream(line.substr(16,8))()); label groupId = readLabel(IStringStream(line.substr(16,8))());
fTri[0] = readLabel(IStringStream(line.substr(24,8))()); label a = readLabel(IStringStream(line.substr(24,8))());
fTri[1] = readLabel(IStringStream(line.substr(32,8))()); label b = readLabel(IStringStream(line.substr(32,8))());
fTri[2] = readLabel(IStringStream(line.substr(40,8))()); label c = readLabel(IStringStream(line.substr(40,8))());
// Convert groupID into zoneId // Convert groupID into zoneId
Map<label>::const_iterator fnd = lookup.find(groupId); Map<label>::const_iterator fnd = lookup.find(groupId);
@ -217,20 +216,17 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
// Info<< "zone" << zoneI << " => group " << groupId <<endl; // Info<< "zone" << zoneI << " => group " << groupId <<endl;
} }
dynFaces.append(fTri); dynFaces.append(Face{a, b, c});
dynZones.append(zoneI); dynZones.append(zoneI);
dynSizes[zoneI]++; dynSizes[zoneI]++;
} }
else if (cmd == "CQUAD4") else if (cmd == "CQUAD4")
{ {
face fQuad(4);
labelUList& f = static_cast<labelUList&>(fQuad);
label groupId = readLabel(IStringStream(line.substr(16,8))()); label groupId = readLabel(IStringStream(line.substr(16,8))());
fQuad[0] = readLabel(IStringStream(line.substr(24,8))()); label a = readLabel(IStringStream(line.substr(24,8))());
fQuad[1] = readLabel(IStringStream(line.substr(32,8))()); label b = readLabel(IStringStream(line.substr(32,8))());
fQuad[2] = readLabel(IStringStream(line.substr(40,8))()); label c = readLabel(IStringStream(line.substr(40,8))());
fQuad[3] = readLabel(IStringStream(line.substr(48,8))()); label d = readLabel(IStringStream(line.substr(48,8))());
// Convert groupID into zoneId // Convert groupID into zoneId
Map<label>::const_iterator fnd = lookup.find(groupId); Map<label>::const_iterator fnd = lookup.find(groupId);
@ -251,18 +247,17 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
// Info<< "zone" << zoneI << " => group " << groupId <<endl; // Info<< "zone" << zoneI << " => group " << groupId <<endl;
} }
if (faceTraits<Face>::isTri())
if (MeshedSurface<Face>::isTri())
{ {
dynFaces.append(triFace(f[0], f[1], f[2])); dynFaces.append(Face{a, b, c});
dynFaces.append(triFace(f[0], f[2], f[3])); dynFaces.append(Face{c, d, a});
dynZones.append(zoneI); dynZones.append(zoneI);
dynZones.append(zoneI); dynZones.append(zoneI);
dynSizes[zoneI] += 2; dynSizes[zoneI] += 2;
} }
else else
{ {
dynFaces.append(Face(f)); dynFaces.append(Face{a,b,c,d});
dynZones.append(zoneI); dynZones.append(zoneI);
dynSizes[zoneI]++; dynSizes[zoneI]++;
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -27,9 +27,9 @@ License
#include "clock.H" #include "clock.H"
#include "IFstream.H" #include "IFstream.H"
#include "IStringStream.H" #include "IStringStream.H"
#include "Ostream.H"
#include "OFstream.H" #include "OFstream.H"
#include "ListOps.H" #include "ListOps.H"
#include "faceTraits.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -172,7 +172,7 @@ bool Foam::fileFormats::OBJsurfaceFormat<Face>::read
labelUList& f = static_cast<labelUList&>(dynVertices); labelUList& f = static_cast<labelUList&>(dynVertices);
if (MeshedSurface<Face>::isTri() && f.size() > 3) if (faceTraits<Face>::isTri() && f.size() > 3)
{ {
// simple face triangulation about f[0] // simple face triangulation about f[0]
// points may be incomplete // points may be incomplete
@ -180,7 +180,7 @@ bool Foam::fileFormats::OBJsurfaceFormat<Face>::read
{ {
label fp2 = f.fcIndex(fp1); label fp2 = f.fcIndex(fp1);
dynFaces.append(triFace(f[0], f[fp1], f[fp2])); dynFaces.append(Face{f[0], f[fp1], f[fp2]});
dynZones.append(zoneI); dynZones.append(zoneI);
dynSizes[zoneI]++; dynSizes[zoneI]++;
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -27,7 +27,7 @@ License
#include "clock.H" #include "clock.H"
#include "IFstream.H" #include "IFstream.H"
#include "IStringStream.H" #include "IStringStream.H"
#include "Ostream.H" #include "faceTraits.H"
#include "OFstream.H" #include "OFstream.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -113,9 +113,9 @@ bool Foam::fileFormats::OFFsurfaceFormat<Face>::read
lineStream >> verts[vertI]; lineStream >> verts[vertI];
} }
labelUList& f = static_cast<labelUList&>(verts); const labelUList& f = static_cast<const labelUList&>(verts);
if (MeshedSurface<Face>::isTri() && f.size() > 3) if (faceTraits<Face>::isTri() && f.size() > 3)
{ {
// simple face triangulation about f[0] // simple face triangulation about f[0]
// cannot use face::triangulation (points may be incomplete) // cannot use face::triangulation (points may be incomplete)
@ -123,7 +123,7 @@ bool Foam::fileFormats::OFFsurfaceFormat<Face>::read
{ {
label fp2 = f.fcIndex(fp1); label fp2 = f.fcIndex(fp1);
dynFaces.append(triFace(f[0], f[fp1], f[fp2])); dynFaces.append(Face{f[0], f[fp1], f[fp2]});
} }
} }
else else

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -25,6 +25,7 @@ License
#include "STARCDsurfaceFormat.H" #include "STARCDsurfaceFormat.H"
#include "ListOps.H" #include "ListOps.H"
#include "faceTraits.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -193,7 +194,7 @@ bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
} }
SubList<label> vertices(vertexLabels, vertexLabels.size()); SubList<label> vertices(vertexLabels, vertexLabels.size());
if (MeshedSurface<Face>::isTri() && nLabels > 3) if (faceTraits<Face>::isTri() && nLabels > 3)
{ {
// face needs triangulation // face needs triangulation
face f(vertices); face f(vertices);

View File

@ -146,7 +146,7 @@ bool Foam::fileFormats::STLsurfaceFormat<Face>::read
forAll(faceLst, facei) forAll(faceLst, facei)
{ {
const label startPt = 3*facei; const label startPt = 3*facei;
faceLst[facei] = triFace(startPt, startPt+1, startPt+2); faceLst[facei] = Face{startPt, startPt+1, startPt+2};
} }
} }
else else
@ -160,7 +160,7 @@ bool Foam::fileFormats::STLsurfaceFormat<Face>::read
forAll(faceMap, facei) forAll(faceMap, facei)
{ {
const label startPt = 3*faceMap[facei]; const label startPt = 3*faceMap[facei];
faceLst[facei] = triFace(startPt, startPt+1, startPt+2); faceLst[facei] = Face{startPt, startPt+1, startPt+2};
} }
} }
zoneIds.clear(); zoneIds.clear();

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -97,7 +97,7 @@ bool Foam::fileFormats::TRIsurfaceFormat<Face>::read
forAll(faceLst, facei) forAll(faceLst, facei)
{ {
const label startPt = 3*facei; const label startPt = 3*facei;
faceLst[facei] = triFace(startPt, startPt+1, startPt+2); faceLst[facei] = Face{startPt, startPt+1, startPt+2};
} }
} }
else else
@ -111,7 +111,7 @@ bool Foam::fileFormats::TRIsurfaceFormat<Face>::read
forAll(faceMap, facei) forAll(faceMap, facei)
{ {
const label startPt = 3*faceMap[facei]; const label startPt = 3*faceMap[facei];
faceLst[facei] = triFace(startPt, startPt+1, startPt+2); faceLst[facei] = Face{startPt, startPt+1, startPt+2};
} }
} }
zoneIds.clear(); zoneIds.clear();

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2107 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -26,6 +26,7 @@ License
#include "VTKsurfaceFormat.H" #include "VTKsurfaceFormat.H"
#include "vtkUnstructuredReader.H" #include "vtkUnstructuredReader.H"
#include "scalarIOField.H" #include "scalarIOField.H"
#include "faceTraits.H"
#include "OFstream.H" #include "OFstream.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -150,7 +151,7 @@ bool Foam::fileFormats::VTKsurfaceFormat<Face>::read
// Check if it needs triangulation // Check if it needs triangulation
label nTri = 0; label nTri = 0;
if (MeshedSurface<Face>::isTri()) if (faceTraits<Face>::isTri())
{ {
forAll(faces, facei) forAll(faces, facei)
{ {
@ -172,7 +173,7 @@ bool Foam::fileFormats::VTKsurfaceFormat<Face>::read
{ {
label fp2 = f.fcIndex(fp1); label fp2 = f.fcIndex(fp1);
dynFaces.append(triFace(f[0], f[fp1], f[fp2])); dynFaces.append(Face{f[0], f[fp1], f[fp2]});
dynZones.append(zones[facei]); dynZones.append(zones[facei]);
} }
} }