ENH: multi-region support for transformPoints (#2080)

This commit is contained in:
Mark Olesen
2021-05-30 21:33:20 +02:00
parent 3e87a46498
commit 5d9e42cb70
2 changed files with 201 additions and 135 deletions

View File

@ -0,0 +1,49 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
Description
Create a fvMesh for a specified named region
Required Variables
- regionName [word]
- runTime [Time]
Provided Variables
- mesh [fvMesh]
\*---------------------------------------------------------------------------*/
Foam::Info << "Create mesh";
if (regionName != Foam::polyMesh::defaultRegion)
{
Foam::Info << ' ' << regionName;
}
Foam::Info << " for time = " << runTime.timeName() << Foam::nl;
Foam::fvMesh mesh
(
Foam::IOobject
(
regionName,
runTime.timeName(),
runTime,
Foam::IOobject::MUST_READ
),
false
);
mesh.init(true); // Initialise all (lower levels and current)
Foam::Info << Foam::endl;
// ************************************************************************* //

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2020 OpenCFD Ltd.
Copyright (C) 2017-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -79,6 +79,7 @@ Note
#include "surfaceFields.H"
#include "ReadFields.H"
#include "pointFields.H"
#include "regionProperties.H"
#include "transformField.H"
#include "transformGeometricField.H"
#include "axisAngleRotation.H"
@ -99,18 +100,18 @@ void readAndRotateFields
)
{
ReadFields(mesh, objects, flds);
forAll(flds, i)
for (GeoField& fld : flds)
{
Info<< "Transforming " << flds[i].name() << endl;
const dimensionedTensor dimT("t", flds[i].dimensions(), rotT);
transform(flds[i], dimT, flds[i]);
Info<< "Transforming " << fld.name() << endl;
const dimensionedTensor dimT("t", fld.dimensions(), rotT);
transform(fld, dimT, fld);
}
}
void rotateFields(const argList& args, const Time& runTime, const tensor& T)
void rotateFields(const word& regionName, const Time& runTime, const tensor& T)
{
#include "createNamedMesh.H"
#include "createRegionMesh.H"
// Read objects in time directory
IOobjectList objects(mesh, runTime.timeName());
@ -300,7 +301,7 @@ int main(int argc, char *argv[])
// Compatibility with surfaceTransformPoints
argList::addOptionCompat("scale", {"write-scale", 0});
#include "addRegionOption.H"
#include "addAllRegionOptions.H"
#include "setRootCase.H"
const bool doRotateFields = args.found("rotateFields");
@ -336,16 +337,10 @@ int main(int argc, char *argv[])
}
}
// ------------------------------------------------------------------------
#include "createTime.H"
word regionName = polyMesh::defaultRegion;
fileName meshDir = polyMesh::meshSubDir;
if (args.readIfPresent("region", regionName))
{
meshDir = regionName/polyMesh::meshSubDir;
}
if (args.found("time"))
{
if (args["time"] == "constant")
@ -359,6 +354,25 @@ int main(int argc, char *argv[])
}
}
// Handle -allRegions, -regions, -region
#include "getAllRegionOptions.H"
// ------------------------------------------------------------------------
forAll(regionNames, regioni)
{
const word& regionName = regionNames[regioni];
const word& regionDir =
(
regionName == polyMesh::defaultRegion ? word::null : regionName
);
const fileName meshDir = regionDir/polyMesh::meshSubDir;
if (regionNames.size() > 1)
{
Info<< "region=" << regionName << nl;
}
pointIOField points
(
IOobject
@ -420,7 +434,7 @@ int main(int argc, char *argv[])
if (doRotateFields)
{
rotateFields(args, runTime, rot);
rotateFields(regionName, runTime, rot);
}
}
else if (args.found("rotate-angle"))
@ -444,7 +458,7 @@ int main(int argc, char *argv[])
if (doRotateFields)
{
rotateFields(args, runTime, rot);
rotateFields(regionName, runTime, rot);
}
}
else if (args.readIfPresent("rollPitchYaw", v))
@ -461,7 +475,7 @@ int main(int argc, char *argv[])
if (doRotateFields)
{
rotateFields(args, runTime, rot);
rotateFields(regionName, runTime, rot);
}
}
else if (args.readIfPresent("yawPitchRoll", v))
@ -478,7 +492,7 @@ int main(int argc, char *argv[])
if (doRotateFields)
{
rotateFields(args, runTime, rot);
rotateFields(regionName, runTime, rot);
}
}
@ -495,8 +509,11 @@ int main(int argc, char *argv[])
// Set the precision of the points data to 10
IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision()));
Info<< "Writing points into directory " << points.path() << nl << endl;
Info<< "Writing points into directory "
<< runTime.relativePath(points.path()) << nl
<< endl;
points.write();
}
Info<< nl << "End" << nl << endl;