Commit 3963cd95 authored by Mark Olesen's avatar Mark Olesen
Browse files

STYLE: code cleanup in fileFormats, conversion

parent 4a3bb8a9
......@@ -131,11 +131,8 @@ void Foam::ensightMesh::correct()
wordList patchNames = mesh_.boundaryMesh().names();
if (Pstream::parRun())
{
patchNames.setSize
(
mesh_.boundary().size()
- mesh_.globalData().processorPatches().size()
);
// Do not include processor patches in matching
patchNames.setSize(mesh_.boundaryMesh().nNonProcessor());
}
labelList matched;
......@@ -158,9 +155,8 @@ void Foam::ensightMesh::correct()
matched = identity(patchNames.size());
}
forAll(matched, matchi)
for (const label patchId : matched)
{
const label patchId = matched[matchi];
const word& patchName = patchNames[patchId];
// use fvPatch (not polyPatch) to automatically remove empty patches
......@@ -224,9 +220,8 @@ void Foam::ensightMesh::correct()
// Mark boundary faces to be excluded from export
bitSet excludeFace(mesh_.nFaces()); // all false
forAll(mesh_.boundaryMesh(), patchi)
for (const polyPatch& pp : mesh_.boundaryMesh())
{
const polyPatch& pp = mesh_.boundaryMesh()[patchi];
if
(
isA<processorPolyPatch>(pp)
......@@ -250,9 +245,8 @@ void Foam::ensightMesh::correct()
Foam::sort(selectZones);
// Count face types in each selected faceZone
forAll(selectZones, zonei)
for (const word& zoneName : selectZones)
{
const word& zoneName = selectZones[zonei];
const label zoneID = mesh_.faceZones().findZoneID(zoneName);
const faceZone& fz = mesh_.faceZones()[zoneID];
......@@ -318,9 +312,8 @@ void Foam::ensightMesh::write(ensightGeoFile& os) const
// use sortedToc for extra safety
//
const labelList patchIds = patchLookup_.sortedToc();
forAll(patchIds, listi)
for (const label patchId : patchIds)
{
const label patchId = patchIds[listi];
const word& patchName = patchLookup_[patchId];
const ensightFaces& ensFaces = boundaryPatchFaces_[patchName];
......@@ -341,9 +334,9 @@ void Foam::ensightMesh::write(ensightGeoFile& os) const
// Renumber the patch faces,
// from local patch indexing to unique global index
faceList patchFaces(pp.localFaces());
forAll(patchFaces, i)
for (face& f : patchFaces)
{
inplaceRenumber(pointToGlobal, patchFaces[i]);
inplaceRenumber(pointToGlobal, f);
}
writeAllPoints
......@@ -363,9 +356,8 @@ void Foam::ensightMesh::write(ensightGeoFile& os) const
// write faceZones, if requested
//
const wordList zoneNames = faceZoneFaces_.sortedToc();
forAll(zoneNames, zonei)
for (const word& zoneName : zoneNames)
{
const word& zoneName = zoneNames[zonei];
const ensightFaces& ensFaces = faceZoneFaces_[zoneName];
// Use the properly sorted faceIds (ensightFaces) and do NOT use the
......
......@@ -98,14 +98,14 @@ private:
// Parallel merged points
//- Global numbering for merged points
autoPtr<globalIndex> globalPointsPtr_;
//- Global numbering for merged points
autoPtr<globalIndex> globalPointsPtr_;
//- From mesh point to global merged point
labelList pointToGlobal_;
//- From mesh point to global merged point
labelList pointToGlobal_;
//- Local points that are unique
labelList uniquePointMap_;
//- Local points that are unique
labelList uniquePointMap_;
// Private Member Functions
......@@ -117,122 +117,130 @@ private:
//- Inplace renumber of cell-shapes
static cellShapeList& renumberShapes
(
cellShapeList&,
cellShapeList& shapes,
const labelUList& pointToGlobal
);
static cellShapeList map
(
const cellShapeList&,
const labelUList& prims,
const cellShapeList& shapes,
const labelUList& addr,
const labelUList& pointToGlobal
);
//- Write list of faces
static void writeFaceList
(
const faceList&,
ensightGeoFile&
const faceList& faces,
ensightGeoFile& os
);
//- Write list of faces
static void writeFaceList
(
const UIndirectList<face>&,
ensightGeoFile&
const UIndirectList<face>& faces,
ensightGeoFile& os
);
//- Write sizes of faces in the list
static void writeFaceSizes
(
const faceList&,
ensightGeoFile&
const faceList& faces,
ensightGeoFile& os
);
//- Write sizes of faces in the list
static void writeFaceSizes
(
const UIndirectList<face>&,
ensightGeoFile&
const UIndirectList<face>& faces,
ensightGeoFile& os
);
//- Write cell connectivity via shell shapes
//- Write cell connectivity via cell shapes
static void writeCellShapes
(
const cellShapeList&,
ensightGeoFile&
const cellShapeList& shapes,
ensightGeoFile& os
);
//- Write the number of faces per poly element
void writePolysNFaces
(
const labelList& polys,
const labelUList& polys,
const cellList& cellFaces,
ensightGeoFile&
ensightGeoFile& os
) const;
//- Write the number of points per poly element
void writePolysNPointsPerFace
(
const labelList& polys,
const labelUList& polys,
const cellList& cellFaces,
const faceList& faces,
ensightGeoFile&
) const;
//- Write the point ids per poly element
void writePolysPoints
(
const labelList& polys,
const labelUList& addr,
const cellList& cellFaces,
const faceList& faces,
const labelList& faceOwner,
ensightGeoFile&
) const;
//- Write the poly connectivity
void writePolysConnectivity
(
const labelList& addr,
const labelUList& polys,
const labelList& pointToGlobal,
ensightGeoFile&
) const;
//- Write the regular cell connectivity for all types
void writeCellConnectivity
(
const ensightCells&,
const ensightCells& ensCells,
const labelList& pointToGlobal,
ensightGeoFile&
ensightGeoFile& os
) const;
//- Write the regular cell connectivity for specified type
void writeCellConnectivity
(
ensightCells::elemType elemType,
const ensightCells&,
const ensightCells& ensCells,
const labelList& pointToGlobal,
ensightGeoFile&
ensightGeoFile& os
) const;
//- Write the regular face connectivity for specified type and
//- and specified faces
void writeFaceConnectivity
(
ensightFaces::elemType elemType,
const label nTotal,
const faceList& faceLst,
const labelList& addr,
const faceList& faces,
const labelUList& addr,
ensightGeoFile&
) const;
//- Write the regular face connectivity for specified type
void writeFaceConnectivity
(
ensightFaces::elemType elemType,
const label nTotal,
const faceList& faceLst,
ensightGeoFile&
const faceList& faces,
ensightGeoFile& os
) const;
void writeFaceConnectivity
(
const ensightFaces&,
const faceList& faceLst,
ensightGeoFile&,
const ensightFaces& ensFaces,
const faceList& faces,
ensightGeoFile& os,
const bool raw = false
) const;
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -42,9 +42,9 @@ Foam::cellShapeList& Foam::ensightMesh::renumberShapes
const labelUList& pointToGlobal
)
{
forAll(shapes, i)
for (cellShape& shape : shapes)
{
inplaceRenumber(pointToGlobal, shapes[i]);
inplaceRenumber(pointToGlobal, shape);
}
return shapes;
......@@ -58,15 +58,15 @@ Foam::cellShapeList Foam::ensightMesh::map
const labelUList& pointToGlobal
)
{
cellShapeList lst(addr.size());
cellShapeList list(addr.size());
forAll(addr, i)
{
lst[i] = shapes[addr[i]];
inplaceRenumber(pointToGlobal, lst[i]);
list[i] = shapes[addr[i]];
inplaceRenumber(pointToGlobal, list[i]);
}
return lst;
return list;
}
......@@ -76,13 +76,11 @@ void Foam::ensightMesh::writeFaceList
ensightGeoFile& os
)
{
forAll(faceLst, i)
for (const face& f : faceLst)
{
const face& f = faceLst[i];
forAll(f, fp)
for (const label labi : f)
{
os.write(f[fp] + 1);
os.write(labi + 1);
}
os.newline();
......@@ -96,13 +94,11 @@ void Foam::ensightMesh::writeFaceList
ensightGeoFile& os
)
{
forAll(faceLst, i)
for (const face& f : faceLst)
{
const face& f = faceLst[i];
forAll(f, fp)
for (const label labi : f)
{
os.write(f[fp] + 1);
os.write(labi + 1);
}
os.newline();
......@@ -116,10 +112,8 @@ void Foam::ensightMesh::writeFaceSizes
ensightGeoFile& os
)
{
forAll(faceLst, i)
for (const face& f : faceLst)
{
const face& f = faceLst[i];
os.write(f.size());
os.newline();
}
......@@ -132,10 +126,8 @@ void Foam::ensightMesh::writeFaceSizes
ensightGeoFile& os
)
{
forAll(faceLst, i)
for (const face& f : faceLst)
{
const face& f = faceLst[i];
os.write(f.size());
os.newline();
}
......@@ -148,17 +140,15 @@ void Foam::ensightMesh::writeCellShapes
ensightGeoFile& os
)
{
forAll(shapes, i)
for (const cellShape& cellPoints : shapes)
{
const cellShape& cellPoints = shapes[i];
// convert global -> local index
// (note: Ensight indices start with 1)
// In ASCII, write one cell per line
forAll(cellPoints, pointI)
for (const label pointi : cellPoints)
{
os.write(cellPoints[pointI] + 1);
os.write(pointi + 1);
}
os.newline();
......@@ -170,15 +160,15 @@ void Foam::ensightMesh::writeCellShapes
void Foam::ensightMesh::writePolysNFaces
(
const labelList& addr,
const cellList& cellFaces,
const labelUList& addr,
const cellList& cellFaces,
ensightGeoFile& os
) const
{
// write the number of faces per element (1/line in ASCII)
forAll(addr, i)
// Write the number of faces per element (1/line in ASCII)
for (const label cellId : addr)
{
const labelUList& cf = cellFaces[addr[i]];
const labelUList& cf = cellFaces[cellId];
os.write(cf.size());
os.newline();
......@@ -188,20 +178,20 @@ void Foam::ensightMesh::writePolysNFaces
void Foam::ensightMesh::writePolysNPointsPerFace
(
const labelList& addr,
const labelUList& addr,
const cellList& cellFaces,
const faceList& faces,
ensightGeoFile& os
) const
{
// write the number of points per element face (1/line in ASCII)
forAll(addr, i)
// Write the number of points per element face (1/line in ASCII)
for (const label cellId : addr)
{
const labelUList& cf = cellFaces[addr[i]];
const labelUList& cf = cellFaces[cellId];
forAll(cf, facei)
for (const label facei : cf)
{
os.write(faces[cf[facei]].size());
os.write(faces[facei].size());
os.newline();
}
}
......@@ -210,21 +200,19 @@ void Foam::ensightMesh::writePolysNPointsPerFace
void Foam::ensightMesh::writePolysPoints
(
const labelList& addr,
const labelUList& addr,
const cellList& cellFaces,
const faceList& faces,
const labelList& faceOwner,
ensightGeoFile& os
) const
{
forAll(addr, i)
for (const label cellId : addr)
{
const label cellId = addr[i];
const labelUList& cf = cellFaces[cellId];
forAll(cf, facei)
for (const label faceId : cf)
{
const label faceId = cf[facei];
const face& f = faces[faceId]; // face points (in global points)
if (faceId < faceOwner.size() && faceOwner[faceId] != cellId)
......@@ -234,16 +222,16 @@ void Foam::ensightMesh::writePolysPoints
// as per face::reverseFace(), but without copying
os.write(f[0] + 1);
for (label ptI = f.size()-1; ptI > 0; --ptI)
for (label pti = f.size()-1; pti > 0; --pti)
{
os.write(f[ptI] + 1);
os.write(f[pti] + 1);
}
}
else
{
forAll(f, ptI)
for (const label labi : f)
{
os.write(f[ptI] + 1);
os.write(labi + 1);
}
}
......@@ -255,7 +243,7 @@ void Foam::ensightMesh::writePolysPoints
void Foam::ensightMesh::writePolysConnectivity
(
const labelList& addr,
const labelUList& addr,
const labelList& pointToGlobal,
ensightGeoFile& os
) const
......@@ -329,9 +317,9 @@ void Foam::ensightMesh::writePolysConnectivity
// Renumber faces to use global point numbers
faceList faces(mesh_.faces());
forAll(faces, i)
for (face& f : faces)
{
inplaceRenumber(pointToGlobal, faces[i]);
inplaceRenumber(pointToGlobal, f);
}
// List of points id for each face of the above list
......@@ -409,11 +397,14 @@ void Foam::ensightMesh::writeCellConnectivity
}
else
{
const cellShapeList shapes = map
const cellShapeList shapes
(
mesh_.cellShapes(),
addr,
pointToGlobal
map
(
mesh_.cellShapes(),
addr,
pointToGlobal
)
);
......@@ -454,7 +445,8 @@ void Foam::ensightMesh::writeCellConnectivity
{
for (label typei=0; typei < ensightCells::nTypes; ++typei)
{
const ensightCells::elemType what = ensightCells::elemType(typei);
const ensightCells::elemType what =
ensightCells::elemType(typei);
writeCellConnectivity(what, ensCells, pointToGlobal, os);
}
......@@ -489,9 +481,9 @@ void Foam::ensightMesh::writeFaceConnectivity
for (int slave=1; slave<Pstream::nProcs(); ++slave)
{
IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
faceList received(fromSlave);
faceList recv(fromSlave);
writeFaceSizes(received, os);
writeFaceSizes(recv, os);
}
}
else
......@@ -516,9 +508,9 @@ void Foam::ensightMesh::writeFaceConnectivity
for (int slave=1; slave<Pstream::nProcs(); ++slave)
{
IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
faceList received(fromSlave);
faceList recv(fromSlave);
writeFaceList(received, os);
writeFaceList(recv, os);
}
}
else
......@@ -541,7 +533,7 @@ void Foam::ensightMesh::writeFaceConnectivity
ensightFaces::elemType elemType,
const label nTotal,
const faceList& faceLst,
const labelList& addr,
const labelUList& addr,
ensightGeoFile& os
) const
{
......@@ -621,12 +613,13 @@ void Foam::ensightMesh::writeFaceConnectivity
const bool raw
) const
{
if (raw)
for (label typei=0; typei < ensightFaces::nTypes; ++typei)
{
for (label typei=0; typei < ensightFaces::nTypes; ++typei)
{
const ensightFaces::elemType what = ensightFaces::elemType(typei);
const ensightFaces::elemType what =
ensightFaces::elemType(typei);
if (raw)
{
writeFaceConnectivity
(
what,
......@@ -640,13 +633,8 @@ void Foam::ensightMesh::writeFaceConnectivity
os
);
}
}
else
{
for (label typei=0; typei < ensightFaces::nTypes; ++typei)
else
{
const ensightFaces::elemType what = ensightFaces::elemType(typei);
writeFaceConnectivity
(
what,
......
......@@ -25,7 +25,6 @@ License
#include "ensightMesh.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::ensightMesh::options::options(IOstream::streamFormat format)
......
......@@ -144,7 +144,9 @@ bool Foam::ensightOutput::writeFaceSubField
label start = 0; // start of sublist
for (label typei=0; typei < ensightFaces::nTypes; ++typei)
{
const ensightFaces::elemType what = ensightFaces::elemType(typei);
const ensightFaces::elemType what =
ensightFaces::elemType(typei);
const label size = ensFaces.faceIds(what).size();
writeFieldContent
......@@ -159,10 +161,8 @@ bool Foam::ensightOutput::writeFaceSubField