Commit f8a8c546 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: use Pstream::subProc() to simplify code

parent b9760ce6
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -81,24 +81,19 @@ Foam::functionObjects::runTimePostPro::geometryCloud::gatherCloud
// Receive points
pointField points;
for
(
int slave=Pstream::firstSlave();
slave<=Pstream::lastSlave();
++slave
)
for (const int proci : Pstream::subProcs())
{
IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
IPstream fromProc(Pstream::commsTypes::scheduled, proci);
points.clear();
fromSlave >> points;
fromProc >> points;
if (points.size())
{
multiPiece->SetPiece
(
slave,
proci,
Foam::vtk::Tools::Vertices(points)
);
}
......@@ -106,7 +101,7 @@ Foam::functionObjects::runTimePostPro::geometryCloud::gatherCloud
}
else
{
// Slave - send points
// Sub-process - send points
OPstream toMaster
(
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -99,25 +99,19 @@ bool Foam::functionObjects::runTimePostPro::geometryCloud::addCloudField
// Receive field data
Field<Type> recv;
for
(
int slave=Pstream::firstSlave();
slave<=Pstream::lastSlave();
++slave
)
for (const int proci : Pstream::subProcs())
{
IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
IPstream fromProc(Pstream::commsTypes::scheduled, proci);
recv.clear();
fromSlave
>> recv;
fromProc >> recv;
if (recv.size())
{
addField<Type>
(
multiPiece->GetPiece(slave),
multiPiece->GetPiece(proci),
recv,
fieldName
);
......@@ -126,7 +120,7 @@ bool Foam::functionObjects::runTimePostPro::geometryCloud::addCloudField
}
else
{
// Slave - send field data
// Sub-process - send field data
OPstream toMaster
(
......@@ -136,13 +130,11 @@ bool Foam::functionObjects::runTimePostPro::geometryCloud::addCloudField
if (fldptr)
{
toMaster
<< *fldptr;
toMaster << *fldptr;
}
else
{
toMaster
<< List<Type>();
toMaster << Field<Type>();
}
}
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -108,29 +108,23 @@ Foam::functionObjects::runTimePostPro::geometryPatches::gatherPatchPieces
pointField points;
faceList faces;
for
(
int slave=Pstream::firstSlave();
slave<=Pstream::lastSlave();
++slave
)
for (const int proci : Pstream::subProcs())
{
const label nSlavePatches = patchIds[slave].size();
const label nPatches = patchIds[proci].size();
if (!nSlavePatches)
if (!nPatches)
{
continue;
}
IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
IPstream fromProc(Pstream::commsTypes::scheduled, proci);
for (label recvi=0; recvi < nSlavePatches; ++recvi)
for (label recvi=0; recvi < nPatches; ++recvi)
{
points.clear();
faces.clear();
fromSlave
>> points >> faces;
fromProc >> points >> faces;
multiPiece->SetPiece
(
......@@ -144,10 +138,9 @@ Foam::functionObjects::runTimePostPro::geometryPatches::gatherPatchPieces
}
else
{
// Slave - send surfaces
const labelList& slavePatchIds = patchIds[Pstream::myProcNo()];
// Sub-process - send surfaces
if (slavePatchIds.size())
if (patchIds[Pstream::myProcNo()].size())
{
OPstream toMaster
(
......@@ -159,8 +152,7 @@ Foam::functionObjects::runTimePostPro::geometryPatches::gatherPatchPieces
{
const polyPatch& pp = patches[patchId];
toMaster
<< pp.localPoints() << pp.localFaces();
toMaster << pp.localPoints() << pp.localFaces();
}
}
}
......@@ -233,27 +225,22 @@ Foam::functionObjects::runTimePostPro::geometryPatches::gatherPatchFaceCentres
// Receive points
pointField points;
for
(
int slave=Pstream::firstSlave();
slave<=Pstream::lastSlave();
++slave
)
for (const int proci : Pstream::subProcs())
{
const label nSlavePatches = patchIds[slave].size();
const label nPatches = patchIds[proci].size();
if (!nSlavePatches)
if (!nPatches)
{
continue;
}
IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
IPstream fromProc(Pstream::commsTypes::scheduled, proci);
for (label recvi=0; recvi < nSlavePatches; ++recvi)
for (label recvi=0; recvi < nPatches; ++recvi)
{
points.clear();
fromSlave >> points;
fromProc >> points;
multiPiece->SetPiece
(
......@@ -267,11 +254,9 @@ Foam::functionObjects::runTimePostPro::geometryPatches::gatherPatchFaceCentres
}
else
{
// Slave - send face centres
// Sub-process - send face centres
const labelList& slavePatchIds = patchIds[Pstream::myProcNo()];
if (slavePatchIds.size())
if (patchIds[Pstream::myProcNo()].size())
{
OPstream toMaster
(
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -143,27 +143,22 @@ int Foam::functionObjects::runTimePostPro::geometryPatches::addPatchField
// Receive field
Field<Type> recv;
for
(
int slave=Pstream::firstSlave();
slave<=Pstream::lastSlave();
++slave
)
for (const int proci : Pstream::subProcs())
{
const label nSlavePatches = patchIds[slave].size();
const label nPatches = patchIds[proci].size();
if (!nSlavePatches)
if (!nPatches)
{
continue;
}
IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
IPstream fromProc(Pstream::commsTypes::scheduled, proci);
for (label recvi=0; recvi < nSlavePatches; ++recvi)
for (label recvi=0; recvi < nPatches; ++recvi)
{
recv.clear();
fromSlave >> recv;
fromProc >> recv;
auto vtkfield = Foam::vtk::Tools::convertFieldToVTK<Type>
(
......@@ -189,10 +184,9 @@ int Foam::functionObjects::runTimePostPro::geometryPatches::addPatchField
}
else
{
// Slave - send fields
const labelList& slavePatchIds = patchIds[Pstream::myProcNo()];
// Sub-process - send fields
if (slavePatchIds.size())
if (patchIds[Pstream::myProcNo()].size())
{
OPstream toMaster
(
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -80,25 +80,20 @@ Foam::functionObjects::runTimePostPro::surface::gatherSurfacePieces
pointField points;
faceList faces;
for
(
int slave=Pstream::firstSlave();
slave<=Pstream::lastSlave();
++slave
)
for (const int proci : Pstream::subProcs())
{
IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
IPstream fromProc(Pstream::commsTypes::scheduled, proci);
points.clear();
faces.clear();
fromSlave >> points >> faces;
fromProc >> points >> faces;
if (points.size())
{
multiPiece->SetPiece
(
slave,
proci,
Foam::vtk::Tools::Patch::mesh(points, faces)
);
}
......@@ -106,7 +101,7 @@ Foam::functionObjects::runTimePostPro::surface::gatherSurfacePieces
}
else
{
// Slave - send surfaces
// Sub-process - send surfaces
OPstream toMaster
(
......@@ -116,13 +111,11 @@ Foam::functionObjects::runTimePostPro::surface::gatherSurfacePieces
if (surf)
{
toMaster
<< surf->points() << surf->faces();
toMaster << surf->points() << surf->faces();
}
else
{
toMaster
<< pointField() << faceList();
toMaster << pointField() << faceList();
}
}
......@@ -174,24 +167,19 @@ Foam::functionObjects::runTimePostPro::surface::gatherFaceCentres
// Receive points
pointField points;
for
(
int slave=Pstream::firstSlave();
slave<=Pstream::lastSlave();
++slave
)
for (const int proci : Pstream::subProcs())
{
IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
IPstream fromProc(Pstream::commsTypes::scheduled, proci);
points.clear();
fromSlave >> points;
fromProc >> points;
if (points.size())
{
multiPiece->SetPiece
(
slave,
proci,
Foam::vtk::Tools::Vertices(points)
);
}
......@@ -199,7 +187,7 @@ Foam::functionObjects::runTimePostPro::surface::gatherFaceCentres
}
else
{
// Slave - send face centres
// Sub-process - send face centres
OPstream toMaster
(
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -167,25 +167,19 @@ bool Foam::functionObjects::runTimePostPro::surface::addDimField
// Receive field data
Field<Type> recv;
for
(
int slave=Pstream::firstSlave();
slave<=Pstream::lastSlave();
++slave
)
for (const int proci : Pstream::subProcs())
{
IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
IPstream fromProc(Pstream::commsTypes::scheduled, proci);
recv.clear();
fromSlave
>> recv;
fromProc >> recv;
if (recv.size())
{
addField<Type, GeoMeshType>
(
multiPiece->GetPiece(slave),
multiPiece->GetPiece(proci),
recv,
fieldName
);
......@@ -194,7 +188,7 @@ bool Foam::functionObjects::runTimePostPro::surface::addDimField
}
else
{
// Slave - send field data
// Sub-process - send field data
OPstream toMaster
(
......@@ -204,13 +198,11 @@ bool Foam::functionObjects::runTimePostPro::surface::addDimField
if (fldptr)
{
toMaster
<< fldptr->field();
toMaster << fldptr->field();
}
else
{
toMaster
<< List<Type>();
toMaster << Field<Type>();
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment