ENH: support coordinateSystem/transform for sampled planes

- previously only defined for cell-cutting version, now for
  iso-surface version too

TUT: remove old transform/coordinateSystem syntax
This commit is contained in:
Mark Olesen
2022-06-08 12:28:02 +02:00
parent fbaadf3a94
commit 9a75ce8434
10 changed files with 197 additions and 79 deletions

View File

@ -116,6 +116,22 @@ Foam::coordinateSystems::coordinateSystems(const IOobject& io)
} }
Foam::coordinateSystems::coordinateSystems(const objectRegistry& obr)
:
coordinateSystems
(
IOobject
(
typeName,
obr.time().constant(),
obr,
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE
)
)
{}
Foam::coordinateSystems::coordinateSystems Foam::coordinateSystems::coordinateSystems
( (
const IOobject& io, const IOobject& io,
@ -162,20 +178,7 @@ const Foam::coordinateSystems& Foam::coordinateSystems::New
} }
// Read construct from registry // Read construct from registry
return obr.store return obr.store(new coordinateSystems(obr));
(
new coordinateSystems
(
IOobject
(
typeName,
obr.time().constant(),
obr,
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE
)
)
);
} }

View File

@ -107,6 +107,10 @@ public:
//- Read construct from IOobject //- Read construct from IOobject
explicit coordinateSystems(const IOobject& io); explicit coordinateSystems(const IOobject& io);
//- Read construct "coordinateSystems" from "constant"
//- using given registry
explicit coordinateSystems(const objectRegistry& obr);
//- Construct from IOobject and PtrList content //- Construct from IOobject and PtrList content
coordinateSystems coordinateSystems
( (

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2021 OpenCFD Ltd. Copyright (C) 2016-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -31,6 +31,7 @@ License
#include "fvMesh.H" #include "fvMesh.H"
#include "volFields.H" #include "volFields.H"
#include "volPointInterpolation.H" #include "volPointInterpolation.H"
#include "cartesianCS.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
#include "PtrList.H" #include "PtrList.H"
@ -51,6 +52,64 @@ namespace Foam
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::plane Foam::sampledCuttingPlane::definePlane
(
const polyMesh& mesh,
const dictionary& dict
)
{
plane pln(dict);
bool adjust = false;
const dictionary* dictptr = nullptr;
coordSystem::cartesian cs;
if (dict.found(coordinateSystem::typeName_(), keyType::LITERAL))
{
// Create with registry to allow lookup from globally defined
// coordinate systems?
auto csPtr =
coordinateSystem::New(mesh, dict, coordinateSystem::typeName_());
if (csPtr)
{
adjust = true;
cs = csPtr();
}
}
else if
(
(dictptr = dict.findDict("transform", keyType::LITERAL)) != nullptr
)
{
adjust = true;
cs = coordSystem::cartesian(*dictptr);
}
// Make plane relative to the Cartesian coordinate system
if (adjust)
{
const point orig = cs.globalPosition(pln.origin());
const vector norm = cs.globalVector(pln.normal());
DebugInfo
<< "plane "
<< " origin:" << pln.origin()
<< " normal:" << pln.normal()
<< " =>"
<< " origin:" << orig << " normal:" << norm
<< endl;
// Reassign the plane
pln = plane(orig, norm);
}
return pln;
}
void Foam::sampledCuttingPlane::checkBoundsIntersection void Foam::sampledCuttingPlane::checkBoundsIntersection
( (
const plane& pln, const plane& pln,
@ -512,7 +571,7 @@ Foam::sampledCuttingPlane::sampledCuttingPlane
) )
: :
sampledSurface(name, mesh, dict), sampledSurface(name, mesh, dict),
plane_(dict), plane_(definePlane(mesh, dict)),
offsets_(), offsets_(),
isoParams_ isoParams_
( (

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2021 OpenCFD Ltd. Copyright (C) 2016-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -60,6 +60,8 @@ Usage
exposedPatchName | name for zone subset | optional | exposedPatchName | name for zone subset | optional |
regularise | Face simplification (enum or bool) | no | true regularise | Face simplification (enum or bool) | no | true
mergeTol | tolerance for merging points | no | 1e-6 mergeTol | tolerance for merging points | no | 1e-6
coordinateSystem | define plane within given cartesian system | no |
transform | define plane within given cartesian system | no |
\endtable \endtable
Note Note
@ -73,8 +75,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef sampledCuttingPlane_H #ifndef Foam_sampledCuttingPlane_H
#define sampledCuttingPlane_H #define Foam_sampledCuttingPlane_H
#include "sampledSurface.H" #include "sampledSurface.H"
#include "plane.H" #include "plane.H"
@ -153,6 +155,10 @@ class sampledCuttingPlane
// Private Member Functions // Private Member Functions
//- Define plane from dictionary entry and apply any coordinate
//- transformations
static plane definePlane(const polyMesh& mesh, const dictionary& dict);
//- Check and warn if bounding box does not intersect mesh or plane //- Check and warn if bounding box does not intersect mesh or plane
void checkBoundsIntersection void checkBoundsIntersection
( (

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2021 OpenCFD Ltd. Copyright (C) 2017-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -50,6 +50,65 @@ namespace Foam
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::plane Foam::sampledPlane::definePlane
(
const polyMesh& mesh,
const dictionary& dict
)
{
plane pln(dict);
bool adjust = false;
const dictionary* dictptr = nullptr;
coordSystem::cartesian cs;
if (dict.found(coordinateSystem::typeName_(), keyType::LITERAL))
{
// Create with registry to allow lookup from globally defined
// coordinate systems?
auto csPtr =
coordinateSystem::New(mesh, dict, coordinateSystem::typeName_());
if (csPtr)
{
adjust = true;
cs = csPtr();
}
}
else if
(
(dictptr = dict.findDict("transform", keyType::LITERAL)) != nullptr
)
{
adjust = true;
cs = coordSystem::cartesian(*dictptr);
}
// Make plane relative to the Cartesian coordinate system
if (adjust)
{
const point orig = cs.globalPosition(pln.origin());
const vector norm = cs.globalVector(pln.normal());
DebugInfo
<< "plane "
<< " origin:" << pln.origin()
<< " normal:" << pln.normal()
<< " =>"
<< " origin:" << orig
<< " normal:" << norm
<< endl;
// Reassign the plane
pln = plane(orig, norm);
}
return pln;
}
Foam::bitSet Foam::sampledPlane::cellSelection(const bool warn) const Foam::bitSet Foam::sampledPlane::cellSelection(const bool warn) const
{ {
return cuttingPlane::cellSelection return cuttingPlane::cellSelection
@ -105,7 +164,7 @@ Foam::sampledPlane::sampledPlane
) )
: :
sampledSurface(name, mesh, dict), sampledSurface(name, mesh, dict),
cuttingPlane(plane(dict)), cuttingPlane(definePlane(mesh, dict)),
zoneNames_(), zoneNames_(),
bounds_(dict.getOrDefault("bounds", boundBox::invertedBox)), bounds_(dict.getOrDefault("bounds", boundBox::invertedBox)),
triangulate_(dict.getOrDefault("triangulate", true)), triangulate_(dict.getOrDefault("triangulate", true)),
@ -117,31 +176,6 @@ Foam::sampledPlane::sampledPlane
dict.readEntry("zone", zoneNames_.first()); dict.readEntry("zone", zoneNames_.first());
} }
// Make plane relative to the coordinateSystem (Cartesian)
// allow lookup from global coordinate systems
if (dict.found(coordinateSystem::typeName_()))
{
coordSystem::cartesian cs
(
coordinateSystem::New(mesh, dict, coordinateSystem::typeName_())
);
plane& pln = planeDesc();
const point orig = cs.globalPosition(pln.origin());
const vector norm = cs.globalVector(pln.normal());
DebugInfo
<< "plane " << name << " :"
<< " origin:" << origin()
<< " normal:" << normal()
<< " defined within a local coordinateSystem" << endl;
// Reassign the plane
pln = plane(orig, norm);
}
if (debug) if (debug)
{ {
Info<< "plane " << name << " :" Info<< "plane " << name << " :"

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2021 OpenCFD Ltd. Copyright (C) 2016-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -49,14 +49,15 @@ Usage
Where the sub-entries comprise: Where the sub-entries comprise:
\table \table
Property | Description | Required | Default Property | Description | Reqd | Default
type | plane | yes | type | plane | yes |
planeType | Plane description (pointAndNormal etc) | no | planeType | Plane description (pointAndNormal etc) | no |
triangulate | triangulate faces | no | true triangulate | triangulate faces | no | true
bounds | limit with bounding box | no | bounds | limit with bounding box | no |
zone | limit to cell zone (name or regex) | no | zone | limit to cell zone (name or regex) | no |
zones | limit to cell zones (names, regexs) | no | zones | limit to cell zones (names, regexs) | no |
coordinateSystem | define plane within given coordinate system | no | coordinateSystem | define plane within given cartesian system | no |
transform | define plane within given cartesian system | no |
\endtable \endtable
SeeAlso SeeAlso
@ -73,8 +74,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef sampledPlane_H #ifndef Foam_sampledPlane_H
#define sampledPlane_H #define Foam_sampledPlane_H
#include "sampledSurface.H" #include "sampledSurface.H"
#include "cuttingPlane.H" #include "cuttingPlane.H"
@ -110,6 +111,10 @@ class sampledPlane
// Private Member Functions // Private Member Functions
//- Define plane from dictionary entry and apply any coordinate
//- transformations
static plane definePlane(const polyMesh& mesh, const dictionary& dict);
//- Define cell selection from zones and bounding box. //- Define cell selection from zones and bounding box.
// Optionally check and warn if the plane does not intersect // Optionally check and warn if the plane does not intersect
// with the bounds of the mesh (or submesh) or if the bounding box // with the bounds of the mesh (or submesh) or if the bounding box

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\ /*--------------------------------*- C++ -*----------------------------------*\
| ========= | | | ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 | | \\ / O peration | Version: v2206 |
| \\ / A nd | Website: www.openfoam.com | | \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | | | \\/ M anipulation | |
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -26,8 +26,9 @@ porosity1
coordinateSystem coordinateSystem
{ {
origin (0 0 0); origin (0 0 0);
e1 (0.70710678 0.70710678 0); rotation axisAngle;
e2 (0 0 1); axis (0 0 1);
angle 45;
} }
} }

View File

@ -94,7 +94,7 @@ plane
writeControl writeTime; writeControl writeTime;
surfaceFormat vtk; surfaceFormat vtk;
fields ( cellZoneID ); fields ( cellZoneID U );
surfaces surfaces
{ {
@ -105,6 +105,24 @@ plane
normal (0 0 1); normal (0 0 1);
interpolate false; interpolate false;
} }
slices
{
type cuttingPlane;
point (0 0 0);
normal (1 0 0);
offsets (0.02 0.04 0.06 0.08);
interpolate true;
transform
{
origin (0 0 0);
rotation axisAngle;
axis (0 0 1);
angle 45;
}
}
} }
} }

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\ /*--------------------------------*- C++ -*----------------------------------*\
| ========= | | | ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 | | \\ / O peration | Version: v2206 |
| \\ / A nd | Website: www.openfoam.com | | \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | | | \\/ M anipulation | |
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -55,8 +55,7 @@ geometry
transform transform
{ {
origin (2 2 0); origin (2 2 0);
e1 (1 0 0); rotation none;
e3 (0 0 1);
} }
} }
herring herring

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\ /*--------------------------------*- C++ -*----------------------------------*\
| ========= | | | ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 | | \\ / O peration | Version: v2206 |
| \\ / A nd | Website: www.openfoam.com | | \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | | | \\/ M anipulation | |
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -53,28 +53,17 @@ geometry
surface box1; surface box1;
scale (1.0 1.0 2.1); scale (1.0 1.0 2.1);
// Old syntax
transform transform
{ {
coordinateSystem origin (2 2 0);
{ rotation none;
type cartesian;
origin (2 2 0);
rotation
{
type axes;
e1 (1 0 0);
e3 (0 0 1);
}
}
} }
} }
herring herring
{ {
surface box1; surface box1;
scale (1.0 1.0 2.1); scale (1.0 1.0 2.1);
// Simplified syntax
transform transform
{ {
origin (3.5 3 0); origin (3.5 3 0);