From 66835ba9a9d6a2631b52b51bf9b84353016076ef Mon Sep 17 00:00:00 2001 From: Will Bainbridge Date: Wed, 28 Feb 2024 10:40:41 +0000 Subject: [PATCH 1/2] functionObjects::cylindrical: Corrected normalisation of axes Resolves bug report https://bugs.openfoam.org/view.php?id=4058 --- .../field/cylindrical/cylindricalFunctionObject.C | 9 ++++----- .../coordinateSystems/coordinateRotation/cylindrical.C | 8 ++------ 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/functionObjects/field/cylindrical/cylindricalFunctionObject.C b/src/functionObjects/field/cylindrical/cylindricalFunctionObject.C index 54829d7e69..65fde2471a 100644 --- a/src/functionObjects/field/cylindrical/cylindricalFunctionObject.C +++ b/src/functionObjects/field/cylindrical/cylindricalFunctionObject.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2020-2024 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -49,13 +49,12 @@ namespace functionObjects Foam::tensor Foam::functionObjects::cylindrical::R(const vector& p) const { - vector dir = p - origin_; - dir /= mag(dir) + vSmall; + const vector dir = normalised(p - origin_); - const vector axis = axis_/mag(axis_); + const vector axis = normalised(axis_); const vector r = dir - (dir & axis)*axis; - return tensor(r, axis^r, axis); + return tensor(normalised(r), normalised(axis^r), axis); } diff --git a/src/meshTools/coordinateSystems/coordinateRotation/cylindrical.C b/src/meshTools/coordinateSystems/coordinateRotation/cylindrical.C index 3630a8db98..76f08e344d 100644 --- a/src/meshTools/coordinateSystems/coordinateRotation/cylindrical.C +++ b/src/meshTools/coordinateSystems/coordinateRotation/cylindrical.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -53,12 +53,8 @@ Foam::tensor Foam::cylindrical::R(const vector& p) const // If the point is on the axis choose any radial direction return axesRotation(axis, perpendicular(axis)).R(); } - else - { - return axesRotation(axis, dir).R(); - } - return tensor(r, axis^r, axis); + return axesRotation(axis, dir).R(); } From 1622e190213f644d4d594a547a353b30dadbb5f3 Mon Sep 17 00:00:00 2001 From: Will Bainbridge Date: Wed, 28 Feb 2024 10:41:15 +0000 Subject: [PATCH 2/2] functionObjects::cylindrical: Added packaged configuration This function can now be run interactively using the following command: foamPostProcess -func "cylindrical(origin=(0 0 0), axis=(0 0 1), U)" Or it can be executed at run time by adding the following entry in the system/functions file: #includeFunc cylindrical(origin=(0 0 0), axis=(0 0 1), U) --- etc/caseDicts/functions/fields/cylindrical | 20 +++++++++++++++++++ .../functions/fields/cylindrical.cfg | 15 ++++++++++++++ .../channel/system/functionSets | 2 ++ 3 files changed, 37 insertions(+) create mode 100644 etc/caseDicts/functions/fields/cylindrical create mode 100644 etc/caseDicts/functions/fields/cylindrical.cfg diff --git a/etc/caseDicts/functions/fields/cylindrical b/etc/caseDicts/functions/fields/cylindrical new file mode 100644 index 0000000000..6a320eb49f --- /dev/null +++ b/etc/caseDicts/functions/fields/cylindrical @@ -0,0 +1,20 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: dev + \\/ M anipulation | +------------------------------------------------------------------------------- +Description + Transforms a vector field into cylindrical coordinates + +\*---------------------------------------------------------------------------*/ + +#includeEtc "caseDicts/functions/fields/cylindrical.cfg" + +field ; + +origin ; +axis ; + +// ************************************************************************* // diff --git a/etc/caseDicts/functions/fields/cylindrical.cfg b/etc/caseDicts/functions/fields/cylindrical.cfg new file mode 100644 index 0000000000..467364d45f --- /dev/null +++ b/etc/caseDicts/functions/fields/cylindrical.cfg @@ -0,0 +1,15 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: dev + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ + +type cylindrical; +libs ("libfieldFunctionObjects.so"); + +executeControl writeTime; +writeControl writeTime; + +// ************************************************************************* // diff --git a/test/postProcessing/channel/system/functionSets b/test/postProcessing/channel/system/functionSets index 2b4201e429..4a29283b0a 100644 --- a/test/postProcessing/channel/system/functionSets +++ b/test/postProcessing/channel/system/functionSets @@ -43,6 +43,8 @@ fieldsFunctions #includeFunc CourantNo + #includeFunc cylindrical(origin=(0 0 0), axis=(0 0 1), U) + #includeFunc ddt(p) #includeFunc div(phi)