From 21234ae2960ace32c9c2036b930f4d5d126bb5fe Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 25 May 2022 17:12:06 +0200 Subject: [PATCH] ENH: support zip/unzip rows of symmTensor (#2487) - was previously only implemented for tensor --- .../Test-tensorFieldFields1.C | 23 ++- .../test/tensorFields1/Test-tensorFields1.C | 26 ++- .../symmTensorFieldField.C | 99 ++++++++++- .../symmTensorFieldField.H | 66 ++++++- .../tensorFieldField/tensorFieldField.C | 13 +- .../tensorFieldField/tensorFieldField.H | 10 +- .../Fields/symmTensorField/symmTensorField.H | 97 ++++++++++- .../symmTensorFieldTemplates.C | 140 ++++++++++++++- .../fields/Fields/tensorField/tensorField.H | 14 +- .../Fields/tensorField/tensorFieldTemplates.C | 18 +- .../GeometricSymmTensorField.C | 138 ++++++++++++++- .../GeometricSymmTensorField.H | 67 +++++++- .../GeometricTensorField.C | 14 +- .../GeometricTensorField.H | 17 +- .../primitives/SymmTensor/SymmTensor.H | 133 ++++++++++---- .../primitives/SymmTensor/SymmTensorI.H | 120 ++++++++++++- src/OpenFOAM/primitives/Tensor/Tensor.H | 162 ++++++++---------- src/OpenFOAM/primitives/Tensor/TensorI.H | 68 ++++---- src/OpenFOAM/primitives/Tensor2D/Tensor2D.H | 113 ++++++------ src/OpenFOAM/primitives/Tensor2D/Tensor2DI.H | 48 +++--- .../functionObjects/volRegion/volRegion.C | 6 +- 21 files changed, 1079 insertions(+), 313 deletions(-) diff --git a/applications/test/tensorFieldFields1/Test-tensorFieldFields1.C b/applications/test/tensorFieldFields1/Test-tensorFieldFields1.C index ad9cf11ddf..c7be55e686 100644 --- a/applications/test/tensorFieldFields1/Test-tensorFieldFields1.C +++ b/applications/test/tensorFieldFields1/Test-tensorFieldFields1.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,6 +28,7 @@ Application \*---------------------------------------------------------------------------*/ +#include "symmTensorField.H" #include "tensorField.H" #include "FieldFields.H" #include "Random.H" @@ -189,11 +190,21 @@ int main(int argc, char *argv[]) Info<<" =>"; printFieldField(sf1); + Info<< nl; + for (direction cmpt = 0; cmpt < vector::nComponents; ++cmpt) + { + unzipRow(sf1, cmpt, slice[0]); + + Info<< "row " << label(cmpt) << ": "; + printFieldField(slice[0]); + } + unzipDiag(sf1, slice[0]); - Info<< nl - << "diag: "; - printFieldField(cmpts[0]); + Info<< "diag: "; + printFieldField(slice[0]); + + Info<< nl; unzip ( @@ -215,8 +226,8 @@ int main(int argc, char *argv[]) cmpts[1] ); - Info<<"rezip (swapped diag): " - <<" => " << sf1 << nl; + Info<< "rezip (swapped diag): " + << " => " << sf1 << nl; } // sphericalTensorField diff --git a/applications/test/tensorFields1/Test-tensorFields1.C b/applications/test/tensorFields1/Test-tensorFields1.C index c6e0598bd9..60dadb2629 100644 --- a/applications/test/tensorFields1/Test-tensorFields1.C +++ b/applications/test/tensorFields1/Test-tensorFields1.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -168,12 +168,24 @@ int main(int argc, char *argv[]) Info<< sf1 << nl; Info<<" => " << tf1 << nl; + sf1 = symmTensor(1, 2, 3, 4, 5, 6); + Info<< nl << "reset: " << sf1 << nl; + FixedList cmpts(scalarField(sf1.size())); - Info<<" => " << sf1 << nl; + for (direction cmpt = 0; cmpt < vector::nComponents; ++cmpt) + { + Info<< "col/row " << label(cmpt) << ": " + << sf1[0].col(cmpt) << ' ' + << sf1[0].row(cmpt) << nl; + } Info<< nl - << "diag: " << unzipDiag(sf1) << nl; + << "diag: " << unzipDiag(sf1) << nl + << "row 0: " << unzipRow(sf1, vector::X) << nl + << "row 1: " << unzipCol(sf1, vector::Y) << nl // same as row + << "row 2: " << unzipRow(sf1, vector::Z) << nl; + unzip ( @@ -183,7 +195,7 @@ int main(int argc, char *argv[]) cmpts[5] ); - Info<<"unzip:" << nl + Info<< "unzip:" << nl << "xx : " << cmpts[0] << nl << "xy : " << cmpts[1] << nl << "xz : " << cmpts[2] << nl @@ -192,7 +204,7 @@ int main(int argc, char *argv[]) << "zz : " << cmpts[5] << nl << nl; - // Transposed + // Transposed diagonal zip ( sf1, @@ -201,8 +213,8 @@ int main(int argc, char *argv[]) cmpts[1] ); - Info<<"rezip (swapped diag): " - <<" => " << sf1 << nl; + Info<< "rezip (swapped diag): " + << " => " << sf1 << nl; } diff --git a/src/OpenFOAM/fields/FieldFields/symmTensorFieldField/symmTensorFieldField.C b/src/OpenFOAM/fields/FieldFields/symmTensorFieldField/symmTensorFieldField.C index cb8cdd7c3b..9692042a69 100644 --- a/src/OpenFOAM/fields/FieldFields/symmTensorFieldField/symmTensorFieldField.C +++ b/src/OpenFOAM/fields/FieldFields/symmTensorFieldField/symmTensorFieldField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -24,9 +24,6 @@ License You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . -Description - Specialisation of FieldField\ for symmTensor. - \*---------------------------------------------------------------------------*/ #include "symmTensorFieldField.H" @@ -86,6 +83,100 @@ void Foam::unzip } +template class Field, class Cmpt> +void Foam::zipRows +( + FieldField>& result, + const FieldField>& x, + const FieldField>& y, + const FieldField>& z +) +{ + forAll(result, i) + { + Foam::zipRows(result[i], x[i], y[i], z[i]); + } +} + + +template class Field, class Cmpt> +void Foam::zipCols +( + FieldField>& result, + const FieldField>& x, + const FieldField>& y, + const FieldField>& z +) +{ + forAll(result, i) + { + Foam::zipCols(result[i], x[i], y[i], z[i]); + } +} + + +template class Field, class Cmpt> +void Foam::unzipRows +( + const FieldField>& input, + FieldField>& x, + FieldField>& y, + FieldField>& z +) +{ + forAll(input, i) + { + Foam::unzipRows(input[i], x[i], y[i], z[i]); + } +} + + +template class Field, class Cmpt> +void Foam::unzipCols +( + const FieldField>& input, + FieldField>& x, + FieldField>& y, + FieldField>& z +) +{ + forAll(input, i) + { + Foam::unzipCols(input[i], x[i], y[i], z[i]); + } +} + + +template class Field, class Cmpt> +void Foam::unzipRow +( + const FieldField>& input, + const direction idx, + FieldField>& result +) +{ + forAll(input, i) + { + Foam::unzipRow(input[i], idx, result[i]); + } +} + + +template class Field, class Cmpt> +void Foam::unzipCol +( + const FieldField>& input, + const direction idx, + FieldField>& result +) +{ + forAll(input, i) + { + Foam::unzipCol(input[i], idx, result[i]); + } +} + + template class Field, class Cmpt> void Foam::unzipDiag ( diff --git a/src/OpenFOAM/fields/FieldFields/symmTensorFieldField/symmTensorFieldField.H b/src/OpenFOAM/fields/FieldFields/symmTensorFieldField/symmTensorFieldField.H index 37de06d7a2..37cb8f67de 100644 --- a/src/OpenFOAM/fields/FieldFields/symmTensorFieldField/symmTensorFieldField.H +++ b/src/OpenFOAM/fields/FieldFields/symmTensorFieldField/symmTensorFieldField.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -35,8 +35,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef symmTensorFieldField_H -#define symmTensorFieldField_H +#ifndef Foam_symmTensorFieldField_H +#define Foam_symmTensorFieldField_H #include "FieldField.H" #include "symmTensor.H" @@ -77,6 +77,66 @@ void unzip FieldField& zz ); +//- Zip together symmTensor field field from row components +template class Field, class Cmpt> +void zipRows +( + FieldField>& result, + const FieldField>& x, + const FieldField>& y, + const FieldField>& z +); + +//- Zip together symmTensor field from column components +template class Field, class Cmpt> +void zipCols +( + FieldField>& result, + const FieldField>& x, + const FieldField>& y, + const FieldField>& z +); + + +//- Extract symmTensor field field rows +template class Field, class Cmpt> +void unzipRows +( + const FieldField>& input, + FieldField>& x, + FieldField>& y, + FieldField>& z +); + +//- Extract symmTensor field field columns +template class Field, class Cmpt> +void unzipCols +( + const FieldField>& input, + FieldField>& x, + FieldField>& y, + FieldField>& z +); + + +//- Extract a symmTensor field field row (x,y,z) == (0,1,2) +template class Field, class Cmpt> +void unzipRow +( + const FieldField>& input, + const direction idx, //!< vector::components + FieldField>& result +); + +//- Extract a symmTensor field field column (x,y,z) == (0,1,2) +template class Field, class Cmpt> +void unzipCol +( + const FieldField>& input, + const direction idx, //!< vector::components + FieldField>& result +); + //- Extract a symmTensor field field diagonal template class Field, class Cmpt> void unzipDiag diff --git a/src/OpenFOAM/fields/FieldFields/tensorFieldField/tensorFieldField.C b/src/OpenFOAM/fields/FieldFields/tensorFieldField/tensorFieldField.C index 08efa9d114..f6e5c647f5 100644 --- a/src/OpenFOAM/fields/FieldFields/tensorFieldField/tensorFieldField.C +++ b/src/OpenFOAM/fields/FieldFields/tensorFieldField/tensorFieldField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2019-2021 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -24,9 +24,6 @@ License You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . -Description - Specialisation of FieldField\ for tensor. - \*---------------------------------------------------------------------------*/ #include "tensorFieldField.H" @@ -160,13 +157,13 @@ template class Field, class Cmpt> void Foam::unzipRow ( const FieldField>& input, - const vector::components cmpt, + const direction idx, FieldField>& result ) { forAll(input, i) { - Foam::unzipRow(input[i], cmpt, result[i]); + Foam::unzipRow(input[i], idx, result[i]); } } @@ -175,13 +172,13 @@ template class Field, class Cmpt> void Foam::unzipCol ( const FieldField>& input, - const vector::components cmpt, + const direction idx, FieldField>& result ) { forAll(input, i) { - Foam::unzipCol(input[i], cmpt, result[i]); + Foam::unzipCol(input[i], idx, result[i]); } } diff --git a/src/OpenFOAM/fields/FieldFields/tensorFieldField/tensorFieldField.H b/src/OpenFOAM/fields/FieldFields/tensorFieldField/tensorFieldField.H index aa5ef82a31..ac20dffdda 100644 --- a/src/OpenFOAM/fields/FieldFields/tensorFieldField/tensorFieldField.H +++ b/src/OpenFOAM/fields/FieldFields/tensorFieldField/tensorFieldField.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019-2021 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -35,8 +35,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef tensorFieldField_H -#define tensorFieldField_H +#ifndef Foam_tensorFieldField_H +#define Foam_tensorFieldField_H #include "sphericalTensorFieldField.H" #include "symmTensorFieldField.H" @@ -132,7 +132,7 @@ template class Field, class Cmpt> void unzipRow ( const FieldField>& input, - const vector::components cmpt, + const direction idx, //!< vector::components FieldField>& result ); @@ -141,7 +141,7 @@ template class Field, class Cmpt> void unzipCol ( const FieldField>& input, - const vector::components cmpt, + const direction idx, //!< vector::components FieldField>& result ); diff --git a/src/OpenFOAM/fields/Fields/symmTensorField/symmTensorField.H b/src/OpenFOAM/fields/Fields/symmTensorField/symmTensorField.H index ae9cea5e39..2b0871bbcf 100644 --- a/src/OpenFOAM/fields/Fields/symmTensorField/symmTensorField.H +++ b/src/OpenFOAM/fields/Fields/symmTensorField/symmTensorField.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -35,8 +35,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef symmTensorField_H -#define symmTensorField_H +#ifndef Foam_symmTensorField_H +#define Foam_symmTensorField_H #include "scalarField.H" #include "vectorField.H" @@ -86,6 +86,76 @@ tmp>> zip ); +//- Zip together symmTensor field from row components +template +void zipRows +( + Field>& result, + const UList>& x, + const UList>& y, + const UList>& z +); + +//- Zip together symmTensor field from column components +template +void zipCols +( + Field>& result, + const UList>& x, + const UList>& y, + const UList>& z +) +{ + zipRows(result, x, y, z); +} + + +//- Extract symmTensor field rows +template +void unzipRows +( + const UList>& input, + Field>& x, + Field>& y, + Field>& z +); + +//- Extract symmTensor field columns +template +void unzipCols +( + const UList>& input, + Field>& x, + Field>& y, + Field>& z +) +{ + unzipRows(input, x, y, z); +} + + +//- Extract a symmTensor field row (x,y,z) == (0,1,2) +template +void unzipRow +( + const UList>& input, + const direction idx, //!< vector::components + Field>& result +); + +//- Extract a symmTensor field column (x,y,z) == (0,1,2) +template +void unzipCol +( + const UList>& input, + const direction idx, //!< vector::components + Field>& result +) +{ + unzipRow(input, idx, result); +} + + //- Extract a symmTensor field diagonal template void unzipDiag @@ -94,7 +164,26 @@ void unzipDiag Field>& result ); -//- Extract a symmTensor field diagonal +//- Extract a symmTensor field row (x,y,z) == (0,1,2) +template +tmp>> unzipRow +( + const Field>& input, + const direction idx //!< vector::components +); + +//- Extract a symmTensor field column (x,y,z) == (0,1,2) +template +tmp>> unzipCol +( + const Field>& input, + const direction idx //!< vector::components +) +{ + return unzipRow(input, idx); +} + +//- Extract a symmTensor field diagonal template tmp>> unzipDiag ( diff --git a/src/OpenFOAM/fields/Fields/symmTensorField/symmTensorFieldTemplates.C b/src/OpenFOAM/fields/Fields/symmTensorField/symmTensorFieldTemplates.C index c0a8013947..2d0b6accd8 100644 --- a/src/OpenFOAM/fields/Fields/symmTensorField/symmTensorFieldTemplates.C +++ b/src/OpenFOAM/fields/Fields/symmTensorField/symmTensorFieldTemplates.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -125,6 +125,128 @@ Foam::zip } +template +void Foam::zipRows +( + Field>& result, + const UList>& x, + const UList>& y, + const UList>& z +) +{ + const label len = result.size(); + + #ifdef FULLDEBUG + if (len != x.size() || len != y.size() || len != z.size()) + { + FatalErrorInFunction + << "Components sizes do not match: " << len << " (" + << x.size() << ' ' << y.size() << ' ' << z.size() << ')' + << nl + << abort(FatalError); + } + #endif + + for (label i=0; i < len; ++i) + { + // Like symmTensor::rows() but removed redundancy + + result[i].xx() = x[i].x(); + result[i].xy() = x[i].y(); + result[i].xz() = x[i].z(); + + result[i].yy() = y[i].y(); + result[i].yz() = y[i].z(); + + result[i].zz() = z[i].z(); + } +} + + +template +void Foam::unzipRows +( + const UList>& input, + Field>& x, + Field>& y, + Field>& z +) +{ + const label len = input.size(); + + #ifdef FULLDEBUG + if (len != x.size() || len != y.size() || len != z.size()) + { + FatalErrorInFunction + << "Components sizes do not match: " << len << " (" + << x.size() << ' ' << y.size() << ' ' << z.size() << ')' + << nl + << abort(FatalError); + } + #endif + + for (label i=0; i < len; ++i) + { + x[i] = input[i].x(); + y[i] = input[i].y(); + z[i] = input[i].z(); + } +} + + +template +void Foam::unzipRow +( + const UList>& input, + const direction idx, + Field>& result +) +{ + const label len = input.size(); + + #ifdef FULLDEBUG + if (len != result.size()) + { + FatalErrorInFunction + << "Components sizes do not match: " << len << " (" + << result.size() << ')' + << nl + << abort(FatalError); + } + #endif + + switch (idx) + { + case vector::components::X : + { + for (label i=0; i < len; ++i) + { + result[i] = input[i].x(); + } + } + break; + + case vector::components::Y : + { + for (label i=0; i < len; ++i) + { + result[i] = input[i].y(); + } + } + break; + + case vector::components::Z : + { + for (label i=0; i < len; ++i) + { + result[i] = input[i].z(); + } + } + break; + } +} + + template void Foam::unzipDiag ( @@ -152,6 +274,22 @@ void Foam::unzipDiag } +template +Foam::tmp>> +Foam::unzipRow +( + const Field>& input, + const direction idx +) +{ + auto tresult = tmp>>::New(input.size()); + + Foam::unzipRow(input, idx, tresult.ref()); + + return tresult; +} + + template Foam::tmp>> Foam::unzipDiag diff --git a/src/OpenFOAM/fields/Fields/tensorField/tensorField.H b/src/OpenFOAM/fields/Fields/tensorField/tensorField.H index 386d8ce648..b831118d7a 100644 --- a/src/OpenFOAM/fields/Fields/tensorField/tensorField.H +++ b/src/OpenFOAM/fields/Fields/tensorField/tensorField.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -35,8 +35,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef tensorField_H -#define tensorField_H +#ifndef Foam_tensorField_H +#define Foam_tensorField_H #include "scalarField.H" #include "vectorField.H" @@ -133,7 +133,7 @@ template void unzipRow ( const UList>& input, - const vector::components cmpt, + const direction idx, //!< vector::components Field>& result ); @@ -142,7 +142,7 @@ template void unzipCol ( const UList>& input, - const vector::components cmpt, + const direction idx, //!< vector::components Field>& result ); @@ -159,7 +159,7 @@ template tmp>> unzipRow ( const Field>& input, - const vector::components cmpt + const direction idx //!< vector::components ); //- Extract a tensor field column (x,y,z) == (0,1,2) @@ -167,7 +167,7 @@ template tmp>> unzipCol ( const Field>& input, - const vector::components cmpt + const direction idx //!< vector::components ); //- Extract a tensor field diagonal diff --git a/src/OpenFOAM/fields/Fields/tensorField/tensorFieldTemplates.C b/src/OpenFOAM/fields/Fields/tensorField/tensorFieldTemplates.C index 63ab126017..3d590c414c 100644 --- a/src/OpenFOAM/fields/Fields/tensorField/tensorFieldTemplates.C +++ b/src/OpenFOAM/fields/Fields/tensorField/tensorFieldTemplates.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -249,7 +249,7 @@ template void Foam::unzipRow ( const UList>& input, - const vector::components cmpt, + const direction idx, Field>& result ) { @@ -266,7 +266,7 @@ void Foam::unzipRow } #endif - switch (cmpt) + switch (idx) { case vector::components::X : { @@ -302,7 +302,7 @@ template void Foam::unzipCol ( const UList>& input, - const vector::components cmpt, + const direction idx, Field>& result ) { @@ -319,7 +319,7 @@ void Foam::unzipCol } #endif - switch (cmpt) + switch (idx) { case vector::components::X : { @@ -383,12 +383,12 @@ Foam::tmp>> Foam::unzipRow ( const Field>& input, - const vector::components cmpt + const direction idx ) { auto tresult = tmp>>::New(input.size()); - Foam::unzipRow(input, cmpt, tresult.ref()); + Foam::unzipRow(input, idx, tresult.ref()); return tresult; } @@ -399,12 +399,12 @@ Foam::tmp>> Foam::unzipCol ( const Field>& input, - const vector::components cmpt + const direction idx ) { auto tresult = tmp>>::New(input.size()); - Foam::unzipCol(input, cmpt, tresult.ref()); + Foam::unzipCol(input, idx, tresult.ref()); return tresult; } diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricSymmTensorField/GeometricSymmTensorField.C b/src/OpenFOAM/fields/GeometricFields/GeometricSymmTensorField/GeometricSymmTensorField.C index e17cad56dc..162987ef8f 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricSymmTensorField/GeometricSymmTensorField.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricSymmTensorField/GeometricSymmTensorField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -94,6 +94,142 @@ void Foam::unzip } +template class PatchField, class GeoMesh> +void Foam::zipRows +( + GeometricField, PatchField, GeoMesh>& result, + const GeometricField, PatchField, GeoMesh>& x, + const GeometricField, PatchField, GeoMesh>& y, + const GeometricField, PatchField, GeoMesh>& z +) +{ + Foam::zipRows + ( + result.primitiveFieldRef(), + x.primitiveField(), + y.primitiveField(), + z.primitiveField() + ); + + Foam::zipRows + ( + result.boundaryFieldRef(), + x.boundaryField(), + y.boundaryField(), + z.boundaryField() + ); +} + + +template class PatchField, class GeoMesh> +void Foam::zipCols +( + GeometricField, PatchField, GeoMesh>& result, + const GeometricField, PatchField, GeoMesh>& x, + const GeometricField, PatchField, GeoMesh>& y, + const GeometricField, PatchField, GeoMesh>& z +) +{ + Foam::zipCols + ( + result.primitiveFieldRef(), + x.primitiveField(), + y.primitiveField(), + z.primitiveField() + ); + + Foam::zipCols + ( + result.boundaryFieldRef(), + x.boundaryField(), + y.boundaryField(), + z.boundaryField() + ); +} + + +template class PatchField, class GeoMesh> +void Foam::unzipRows +( + const GeometricField, PatchField, GeoMesh>& input, + GeometricField, PatchField, GeoMesh>& x, + GeometricField, PatchField, GeoMesh>& y, + GeometricField, PatchField, GeoMesh>& z +) +{ + Foam::unzipRows + ( + input.primitiveField(), + x.primitiveFieldRef(), + y.primitiveFieldRef(), + z.primitiveFieldRef() + ); + + Foam::unzipRows + ( + input.boundaryField(), + x.boundaryFieldRef(), + y.boundaryFieldRef(), + z.boundaryFieldRef() + ); +} + + +template class PatchField, class GeoMesh> +void Foam::unzipCols +( + const GeometricField, PatchField, GeoMesh>& input, + GeometricField, PatchField, GeoMesh>& x, + GeometricField, PatchField, GeoMesh>& y, + GeometricField, PatchField, GeoMesh>& z +) +{ + Foam::unzipCols + ( + input.primitiveField(), + x.primitiveFieldRef(), + y.primitiveFieldRef(), + z.primitiveFieldRef() + ); + + Foam::unzipCols + ( + input.boundaryField(), + x.boundaryFieldRef(), + y.boundaryFieldRef(), + z.boundaryFieldRef() + ); +} + + +template class PatchField, class GeoMesh> +void Foam::unzipRow +( + const GeometricField, PatchField, GeoMesh>& input, + const direction idx, + GeometricField, PatchField, GeoMesh>& result +) +{ + Foam::unzipRow(input.primitiveField(), idx, result.primitiveFieldRef()); + + Foam::unzipRow(input.boundaryField(), idx, result.boundaryFieldRef()); +} + + +template class PatchField, class GeoMesh> +void Foam::unzipCol +( + const GeometricField, PatchField, GeoMesh>& input, + const direction idx, + GeometricField, PatchField, GeoMesh>& result +) +{ + Foam::unzipCol(input.primitiveField(), idx, result.primitiveFieldRef()); + + Foam::unzipCol(input.boundaryField(), idx, result.boundaryFieldRef()); +} + + template class PatchField, class GeoMesh> void Foam::unzipDiag ( diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricSymmTensorField/GeometricSymmTensorField.H b/src/OpenFOAM/fields/GeometricFields/GeometricSymmTensorField/GeometricSymmTensorField.H index f73aa7aed6..402eeadd90 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricSymmTensorField/GeometricSymmTensorField.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricSymmTensorField/GeometricSymmTensorField.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -35,8 +35,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef GeometricSymmTensorField_H -#define GeometricSymmTensorField_H +#ifndef Foam_GeometricSymmTensorField_H +#define Foam_GeometricSymmTensorField_H #include "GeometricField.H" #include "DimensionedSymmTensorField.H" @@ -77,6 +77,67 @@ void unzip GeometricField& zz ); + +//- Zip together symmTensor field from row components +template class PatchField, class GeoMesh> +void zipRows +( + GeometricField, PatchField, GeoMesh>& result, + const GeometricField, PatchField, GeoMesh>& x, + const GeometricField, PatchField, GeoMesh>& y, + const GeometricField, PatchField, GeoMesh>& z +); + +//- Zip together symmTensor field from column components +template class PatchField, class GeoMesh> +void zipCols +( + GeometricField, PatchField, GeoMesh>& result, + const GeometricField, PatchField, GeoMesh>& x, + const GeometricField, PatchField, GeoMesh>& y, + const GeometricField, PatchField, GeoMesh>& z +); + +//- Extract symmTensor field rows +template class PatchField, class GeoMesh> +void unzipRows +( + const GeometricField, PatchField, GeoMesh>& input, + GeometricField, PatchField, GeoMesh>& x, + GeometricField, PatchField, GeoMesh>& y, + GeometricField, PatchField, GeoMesh>& z +); + +//- Extract symmTensor field columns +template class PatchField, class GeoMesh> +void unzipCols +( + const GeometricField, PatchField, GeoMesh>& input, + GeometricField, PatchField, GeoMesh>& x, + GeometricField, PatchField, GeoMesh>& y, + GeometricField, PatchField, GeoMesh>& z +); + + +//- Extract a symmTensor field row (x,y,z) == (0,1,2) +template class PatchField, class GeoMesh> +void unzipRow +( + const GeometricField, PatchField, GeoMesh>& input, + const direction idx, //!< vector::components + GeometricField, PatchField, GeoMesh>& result +); + +//- Extract a symmTensor field column (x,y,z) == (0,1,2) +template class PatchField, class GeoMesh> +void unzipCol +( + const GeometricField, PatchField, GeoMesh>& input, + const direction idx, //!< vector::components + GeometricField, PatchField, GeoMesh>& result +); + + //- Extract a symmTensor field diagonal template class PatchField, class GeoMesh> void unzipDiag diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricTensorField/GeometricTensorField.C b/src/OpenFOAM/fields/GeometricFields/GeometricTensorField/GeometricTensorField.C index 2348c6d987..9bbda4c3f2 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricTensorField/GeometricTensorField.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricTensorField/GeometricTensorField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2013 OpenFOAM Foundation - Copyright (C) 2019-2021 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -212,13 +212,13 @@ template class PatchField, class GeoMesh> void Foam::unzipRow ( const GeometricField, PatchField, GeoMesh>& input, - const vector::components cmpt, + const direction idx, GeometricField, PatchField, GeoMesh>& result ) { - Foam::unzipRow(input.primitiveField(), cmpt, result.primitiveFieldRef()); + Foam::unzipRow(input.primitiveField(), idx, result.primitiveFieldRef()); - Foam::unzipRow(input.boundaryField(), cmpt, result.boundaryFieldRef()); + Foam::unzipRow(input.boundaryField(), idx, result.boundaryFieldRef()); } @@ -226,13 +226,13 @@ template class PatchField, class GeoMesh> void Foam::unzipCol ( const GeometricField, PatchField, GeoMesh>& input, - const vector::components cmpt, + const direction idx, GeometricField, PatchField, GeoMesh>& result ) { - Foam::unzipCol(input.primitiveField(), cmpt, result.primitiveFieldRef()); + Foam::unzipCol(input.primitiveField(), idx, result.primitiveFieldRef()); - Foam::unzipCol(input.boundaryField(), cmpt, result.boundaryFieldRef()); + Foam::unzipCol(input.boundaryField(), idx, result.boundaryFieldRef()); } diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricTensorField/GeometricTensorField.H b/src/OpenFOAM/fields/GeometricFields/GeometricTensorField/GeometricTensorField.H index 28e88f9892..345919de23 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricTensorField/GeometricTensorField.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricTensorField/GeometricTensorField.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019-2021 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -35,8 +35,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef GeometricTensorField_H -#define GeometricTensorField_H +#ifndef Foam_GeometricTensorField_H +#define Foam_GeometricTensorField_H #include "GeometricSphericalTensorField.H" #include "GeometricSymmTensorField.H" @@ -85,8 +85,7 @@ void unzip ); - -//- Zip together tensor field field from row components +//- Zip together tensor field from row components template class PatchField, class GeoMesh> void zipRows ( @@ -106,7 +105,7 @@ void zipCols const GeometricField, PatchField, GeoMesh>& z ); -//- Extract tensor field field rows +//- Extract tensor field rows template class PatchField, class GeoMesh> void unzipRows ( @@ -116,7 +115,7 @@ void unzipRows GeometricField, PatchField, GeoMesh>& z ); -//- Extract tensor field field columns +//- Extract tensor field columns template class PatchField, class GeoMesh> void unzipCols ( @@ -132,7 +131,7 @@ template class PatchField, class GeoMesh> void unzipRow ( const GeometricField, PatchField, GeoMesh>& input, - const vector::components cmpt, + const direction idx, //!< vector::components GeometricField, PatchField, GeoMesh>& result ); @@ -141,7 +140,7 @@ template class PatchField, class GeoMesh> void unzipCol ( const GeometricField, PatchField, GeoMesh>& input, - const vector::components cmpt, + const direction idx, //!< vector::components GeometricField, PatchField, GeoMesh>& result ); diff --git a/src/OpenFOAM/primitives/SymmTensor/SymmTensor.H b/src/OpenFOAM/primitives/SymmTensor/SymmTensor.H index 95130e088b..04d9c80752 100644 --- a/src/OpenFOAM/primitives/SymmTensor/SymmTensor.H +++ b/src/OpenFOAM/primitives/SymmTensor/SymmTensor.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -31,16 +31,13 @@ Description A templated (3 x 3) symmetric tensor of objects of \, effectively containing 6 elements, derived from VectorSpace. -See also - Test-SymmTensor.C - SourceFiles SymmTensorI.H \*---------------------------------------------------------------------------*/ -#ifndef SymmTensor_H -#define SymmTensor_H +#ifndef Foam_SymmTensor_H +#define Foam_SymmTensor_H #include "contiguous.H" #include "Vector.H" @@ -107,6 +104,15 @@ public: //- Construct given SphericalTensor inline SymmTensor(const SphericalTensor&); + //- Construct given the three row (or column) vectors + inline SymmTensor + ( + const Vector& x, + const Vector& y, + const Vector& z, + const bool transposed = false /* ignored */ + ); + //- Construct given the six components inline SymmTensor ( @@ -121,36 +127,103 @@ public: // Member Functions - // Component access + // Component Access - inline const Cmpt& xx() const; - inline const Cmpt& xy() const; - inline const Cmpt& xz() const; - inline const Cmpt& yx() const; - inline const Cmpt& yy() const; - inline const Cmpt& yz() const; - inline const Cmpt& zx() const; - inline const Cmpt& zy() const; - inline const Cmpt& zz() const; + inline const Cmpt& xx() const; + inline const Cmpt& xy() const; + inline const Cmpt& xz() const; + inline const Cmpt& yx() const; + inline const Cmpt& yy() const; + inline const Cmpt& yz() const; + inline const Cmpt& zx() const; + inline const Cmpt& zy() const; + inline const Cmpt& zz() const; - inline Cmpt& xx(); - inline Cmpt& xy(); - inline Cmpt& xz(); - inline Cmpt& yx(); - inline Cmpt& yy(); - inline Cmpt& yz(); - inline Cmpt& zx(); - inline Cmpt& zy(); - inline Cmpt& zz(); + inline Cmpt& xx(); + inline Cmpt& xy(); + inline Cmpt& xz(); + inline Cmpt& yx(); + inline Cmpt& yy(); + inline Cmpt& yz(); + inline Cmpt& zx(); + inline Cmpt& zy(); + inline Cmpt& zz(); - // Diagonal access and manipulation + // Column-vector access - //- Extract the diagonal as a vector - inline Vector diag() const; + //- Extract vector for column 0 + Vector cx() const { return this->x(); } - //- Set values of the diagonal - inline void diag(const Vector& v); + //- Extract vector for column 1 + Vector cy() const { return this->y(); } + + //- Extract vector for column 2 + Vector cz() const { return this->z(); } + + //- Extract vector for given column: compile-time check of index + template + Vector col() const { return this->row(); } + + //- Extract vector for given column (0,1,2): runtime check of index + Vector col(const direction c) const { return this->row(c); } + + //- Set values of given column (0,1,2): runtime check of index + void col(const direction c, const Vector& v) { this->row(c, v); } + + //- Set column values + void cols + ( + const Vector& x, + const Vector& y, + const Vector& z + ) + { + this->rows(x, y, z); + } + + + // Row-vector access + + //- Extract vector for row 0 + inline Vector x() const; + + //- Extract vector for row 1 + inline Vector y() const; + + //- Extract vector for row 2 + inline Vector z() const; + + //- Extract vector for given row: compile-time check of index + template + inline Vector row() const; + + //- Extract vector for given row (0,1,2): runtime check of index + inline Vector row(const direction r) const; + + //- Set values of given row: compile-time check of index + template + inline void row(const Vector& v); + + //- Set values of given row (0,1,2): runtime check of row + inline void row(const direction r, const Vector& v); + + //- Set row values + inline void rows + ( + const Vector& x, + const Vector& y, + const Vector& z + ); + + + // Diagonal access and manipulation + + //- Extract the diagonal as a vector + inline Vector diag() const; + + //- Set values of the diagonal + inline void diag(const Vector& v); // Tensor Operations diff --git a/src/OpenFOAM/primitives/SymmTensor/SymmTensorI.H b/src/OpenFOAM/primitives/SymmTensor/SymmTensorI.H index 2170ea5961..1be88f3c95 100644 --- a/src/OpenFOAM/primitives/SymmTensor/SymmTensorI.H +++ b/src/OpenFOAM/primitives/SymmTensor/SymmTensorI.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -57,6 +57,19 @@ inline Foam::SymmTensor::SymmTensor(const SphericalTensor& st) } +template +inline Foam::SymmTensor::SymmTensor +( + const Vector& x, + const Vector& y, + const Vector& z, + const bool transposed /* ignored */ +) +{ + this->rows(x, y, z); +} + + template inline Foam::SymmTensor::SymmTensor ( @@ -190,6 +203,111 @@ inline Cmpt& Foam::SymmTensor::zz() } +template +inline Foam::Vector Foam::SymmTensor::x() const +{ + return Vector(this->v_[XX], this->v_[XY], this->v_[XZ]); +} + + +template +inline Foam::Vector Foam::SymmTensor::y() const +{ + return Vector(this->v_[XY], this->v_[YY], this->v_[YZ]); +} + + +template +inline Foam::Vector Foam::SymmTensor::z() const +{ + return Vector(this->v_[XZ], this->v_[YZ], this->v_[ZZ]); +} + + +template +template +inline Foam::Vector Foam::SymmTensor::row() const +{ + if (Idx == 0) return x(); + else if (Idx == 1) return y(); + else if (Idx == 2) return z(); + + static_assert(Idx < 3, "Invalid row access"); + return Zero; +} + + +template +inline Foam::Vector Foam::SymmTensor::row(const direction r) const +{ + switch (r) + { + case 0: return x(); break; + case 1: return y(); break; + case 2: return z(); break; + default: + FatalErrorInFunction + << "Invalid row access " << r << abort(FatalError); + } + + return Zero; +} + + +template +template +inline void Foam::SymmTensor::row(const Vector& v) +{ + if (Idx == 0) + { + this->v_[XX] = v.x(); this->v_[XY] = v.y(); this->v_[XZ] = v.z(); + } + else if (Idx == 1) + { + this->v_[XY] = v.x(); this->v_[YY] = v.y(); this->v_[YZ] = v.z(); + } + else if (Idx == 2) + { + this->v_[XZ] = v.x(); this->v_[YZ] = v.y(); this->v_[ZZ] = v.z(); + } + + static_assert(Idx < 3, "Invalid row access"); +} + + +template +inline void Foam::SymmTensor::rows +( + const Vector& x, + const Vector& y, + const Vector& z +) +{ + this->v_[XX] = x.x(); this->v_[XY] = x.y(); this->v_[XZ] = x.z(); + this->v_[YY] = y.y(); this->v_[YZ] = y.z(); + this->v_[ZZ] = z.z(); +} + + +template +inline void Foam::SymmTensor::row +( + const direction r, + const Vector& v +) +{ + switch (r) + { + case 0: row<0>(v); break; + case 1: row<1>(v); break; + case 2: row<2>(v); break; + default: + FatalErrorInFunction + << "Invalid row access " << r << abort(FatalError); + } +} + + template inline Foam::Vector Foam::SymmTensor::diag() const { diff --git a/src/OpenFOAM/primitives/Tensor/Tensor.H b/src/OpenFOAM/primitives/Tensor/Tensor.H index a9151e7983..5d5113930b 100644 --- a/src/OpenFOAM/primitives/Tensor/Tensor.H +++ b/src/OpenFOAM/primitives/Tensor/Tensor.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -30,9 +30,6 @@ Class Description A templated (3 x 3) tensor of objects of \ derived from MatrixSpace. -See also - Test-Tensor.C - SourceFiles TensorI.H @@ -42,8 +39,8 @@ See also \*---------------------------------------------------------------------------*/ -#ifndef Tensor_H -#define Tensor_H +#ifndef Foam_Tensor_H +#define Foam_Tensor_H #include "MatrixSpace.H" #include "Vector.H" @@ -57,7 +54,6 @@ namespace Foam // Forward Declarations template class SymmTensor; - /*---------------------------------------------------------------------------*\ Class Tensor Declaration \*---------------------------------------------------------------------------*/ @@ -165,112 +161,104 @@ public: // Member Functions - // Component access + // Component access - inline const Cmpt& xx() const; - inline const Cmpt& xy() const; - inline const Cmpt& xz() const; - inline const Cmpt& yx() const; - inline const Cmpt& yy() const; - inline const Cmpt& yz() const; - inline const Cmpt& zx() const; - inline const Cmpt& zy() const; - inline const Cmpt& zz() const; + inline const Cmpt& xx() const; + inline const Cmpt& xy() const; + inline const Cmpt& xz() const; + inline const Cmpt& yx() const; + inline const Cmpt& yy() const; + inline const Cmpt& yz() const; + inline const Cmpt& zx() const; + inline const Cmpt& zy() const; + inline const Cmpt& zz() const; - inline Cmpt& xx(); - inline Cmpt& xy(); - inline Cmpt& xz(); - inline Cmpt& yx(); - inline Cmpt& yy(); - inline Cmpt& yz(); - inline Cmpt& zx(); - inline Cmpt& zy(); - inline Cmpt& zz(); + inline Cmpt& xx(); + inline Cmpt& xy(); + inline Cmpt& xz(); + inline Cmpt& yx(); + inline Cmpt& yy(); + inline Cmpt& yz(); + inline Cmpt& zx(); + inline Cmpt& zy(); + inline Cmpt& zz(); - // Column-vector access. + // Column-vector access - //- Extract vector for column 0 - inline Vector cx() const; + //- Extract vector for column 0 + inline Vector cx() const; - //- Extract vector for column 1 - inline Vector cy() const; + //- Extract vector for column 1 + inline Vector cy() const; - //- Extract vector for column 2 - inline Vector cz() const; + //- Extract vector for column 2 + inline Vector cz() const; - //- Extract vector for given column. - // Compile-time check of column index. - template - inline Vector col() const; + //- Extract vector for given column: compile-time check of index + template + inline Vector col() const; - //- Extract vector for given column (0,1,2). - // Runtime check of column index. - inline Vector col(const direction c) const; + //- Extract vector for given column (0,1,2): runtime check of index + inline Vector col(const direction c) const; - //- Set values of given column - // Compile-time check of column index. - template - inline void col(const Vector& v); + //- Set values of given column: compile-time check of index + template + inline void col(const Vector& v); - //- Set values of given column (0,1,2) - // Runtime check of column index. - inline void col(const direction c, const Vector& v); + //- Set values of given column (0,1,2): runtime check of index + inline void col(const direction c, const Vector& v); - //- Set column values - inline void cols - ( - const Vector& x, - const Vector& y, - const Vector& z - ); + //- Set column values + inline void cols + ( + const Vector& x, + const Vector& y, + const Vector& z + ); - // Row-vector access. + // Row-vector access - //- Extract vector for row 0 - inline Vector x() const; + //- Extract vector for row 0 + inline Vector x() const; - //- Extract vector for row 1 - inline Vector y() const; + //- Extract vector for row 1 + inline Vector y() const; - //- Extract vector for row 2 - inline Vector z() const; + //- Extract vector for row 2 + inline Vector z() const; - //- Extract vector for given row. - // Compile-time check of row index. - template - inline Vector row() const; + //- Extract vector for given row: compile-time check of index + template + inline Vector row() const; - //- Extract vector for given row (0,1,2) - // Runtime check of row index. - inline Vector row(const direction r) const; + //- Extract vector for given row (0,1,2): runtime check of index + inline Vector row(const direction r) const; - //- Set values of given row - // Compile-time check of row index. - template - inline void row(const Vector& v); + //- Set values of given row: compile-time check of index + template + inline void row(const Vector& v); - //- Set values of given row (0,1,2) - // Runtime check of row index. - inline void row(const direction r, const Vector& v); + //- Set values of given row (0,1,2): runtime check of row + inline void row(const direction r, const Vector& v); - //- Set row values - inline void rows - ( - const Vector& x, - const Vector& y, - const Vector& z - ); + //- Set row values + inline void rows + ( + const Vector& x, + const Vector& y, + const Vector& z + ); - // Diagonal access and manipulation + // Diagonal access and manipulation - //- Extract the diagonal as a vector - inline Vector diag() const; + //- Extract the diagonal as a vector + inline Vector diag() const; - //- Set values of the diagonal - inline void diag(const Vector& v); + //- Set values of the diagonal + inline void diag(const Vector& v); // Tensor Operations diff --git a/src/OpenFOAM/primitives/Tensor/TensorI.H b/src/OpenFOAM/primitives/Tensor/TensorI.H index 974129af2c..145498f25b 100644 --- a/src/OpenFOAM/primitives/Tensor/TensorI.H +++ b/src/OpenFOAM/primitives/Tensor/TensorI.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -317,14 +317,14 @@ inline Foam::Vector Foam::Tensor::cz() const template -template +template inline Foam::Vector Foam::Tensor::col() const { - if (Col == 0) return cx(); - else if (Col == 1) return cy(); - else if (Col == 2) return cz(); + if (Idx == 0) return cx(); + else if (Idx == 1) return cy(); + else if (Idx == 2) return cz(); - static_assert(Col < 3, "Invalid column access"); + static_assert(Idx < 3, "Invalid column access"); return Zero; } @@ -337,24 +337,24 @@ inline Foam::Vector Foam::Tensor::col(const direction c) const case 0: return cx(); break; case 1: return cy(); break; case 2: return cz(); break; + default: + FatalErrorInFunction + << "Invalid column access " << c << abort(FatalError); } - FatalErrorInFunction - << "Invalid column access " << c << abort(FatalError); - return Zero; } template -template +template inline Foam::Vector Foam::Tensor::row() const { - if (Row == 0) return x(); - else if (Row == 1) return y(); - else if (Row == 2) return z(); + if (Idx == 0) return x(); + else if (Idx == 1) return y(); + else if (Idx == 2) return z(); - static_assert(Row < 3, "Invalid row access"); + static_assert(Idx < 3, "Invalid row access"); return Zero; } @@ -367,60 +367,60 @@ inline Foam::Vector Foam::Tensor::row(const direction r) const case 0: return x(); break; case 1: return y(); break; case 2: return z(); break; + default: + FatalErrorInFunction + << "Invalid row access " << r << abort(FatalError); } - FatalErrorInFunction - << "Invalid row access " << r << abort(FatalError); - return Zero; } template -template +template inline void Foam::Tensor::col(const Vector& v) { - if (Col == 0) + if (Idx == 0) { this->v_[XX] = v.x(); this->v_[YX] = v.y(); this->v_[ZX] = v.z(); } - else if (Col == 1) + else if (Idx == 1) { this->v_[XY] = v.x(); this->v_[YY] = v.y(); this->v_[ZY] = v.z(); } - else if (Col == 2) + else if (Idx == 2) { this->v_[XZ] = v.x(); this->v_[YZ] = v.y(); this->v_[ZZ] = v.z(); } - static_assert(Col < 3, "Invalid column access"); + static_assert(Idx < 3, "Invalid column access"); } template -template +template inline void Foam::Tensor::row(const Vector& v) { - if (Row == 0) + if (Idx == 0) { this->v_[XX] = v.x(); this->v_[XY] = v.y(); this->v_[XZ] = v.z(); } - else if (Row == 1) + else if (Idx == 1) { this->v_[YX] = v.x(); this->v_[YY] = v.y(); this->v_[YZ] = v.z(); } - else if (Row == 2) + else if (Idx == 2) { this->v_[ZX] = v.x(); this->v_[ZY] = v.y(); this->v_[ZZ] = v.z(); } - static_assert(Row < 3, "Invalid row access"); + static_assert(Idx < 3, "Invalid row access"); } @@ -453,7 +453,11 @@ inline void Foam::Tensor::rows template -inline void Foam::Tensor::col(const direction c, const Vector& v) +inline void Foam::Tensor::col +( + const direction c, + const Vector& v +) { switch (c) { @@ -463,13 +467,16 @@ inline void Foam::Tensor::col(const direction c, const Vector& v) default: FatalErrorInFunction << "Invalid column access " << c << abort(FatalError); - break; } } template -inline void Foam::Tensor::row(const direction r, const Vector& v) +inline void Foam::Tensor::row +( + const direction r, + const Vector& v +) { switch (r) { @@ -479,7 +486,6 @@ inline void Foam::Tensor::row(const direction r, const Vector& v) default: FatalErrorInFunction << "Invalid row access " << r << abort(FatalError); - break; } } diff --git a/src/OpenFOAM/primitives/Tensor2D/Tensor2D.H b/src/OpenFOAM/primitives/Tensor2D/Tensor2D.H index ad14806d8d..e5e82d3379 100644 --- a/src/OpenFOAM/primitives/Tensor2D/Tensor2D.H +++ b/src/OpenFOAM/primitives/Tensor2D/Tensor2D.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -30,16 +30,13 @@ Class Description A templated (2 x 2) tensor of objects of \ derived from VectorSpace. -See also - Test-Tensor2D.C - SourceFiles Tensor2DI.H \*---------------------------------------------------------------------------*/ -#ifndef Tensor2D_H -#define Tensor2D_H +#ifndef Foam_Tensor2D_H +#define Foam_Tensor2D_H #include "Vector2D.H" #include "SphericalTensor2D.H" @@ -130,86 +127,78 @@ public: // Member Functions - // Component access + // Component access - inline const Cmpt& xx() const; - inline const Cmpt& xy() const; - inline const Cmpt& yx() const; - inline const Cmpt& yy() const; + inline const Cmpt& xx() const; + inline const Cmpt& xy() const; + inline const Cmpt& yx() const; + inline const Cmpt& yy() const; - inline Cmpt& xx(); - inline Cmpt& xy(); - inline Cmpt& yx(); - inline Cmpt& yy(); + inline Cmpt& xx(); + inline Cmpt& xy(); + inline Cmpt& yx(); + inline Cmpt& yy(); - // Column-vector access. + // Column-vector access - //- Extract vector for column 0 - inline Vector2D cx() const; + //- Extract vector for column 0 + inline Vector2D cx() const; - //- Extract vector for column 1 - inline Vector2D cy() const; + //- Extract vector for column 1 + inline Vector2D cy() const; - //- Extract vector for given column. - // Compile-time check of column index. - template - inline Vector2D col() const; + //- Extract vector for given column: compile-time check of index + template + inline Vector2D col() const; - //- Extract vector for given column (0,1). - // Runtime check of column index. - inline Vector2D col(const direction c) const; + //- Extract vector for given column (0,1): runtime check of index + inline Vector2D col(const direction c) const; - //- Set values of given column - // Compile-time check of column index. - template - inline void col(const Vector2D& v); + //- Set values of given column: compile-time check of index + template + inline void col(const Vector2D& v); - //- Set values of given column (0,1) - // Runtime check of column index. - inline void col(const direction c, const Vector2D& v); + //- Set values of given column (0,1): runtime check of index + inline void col(const direction c, const Vector2D& v); - //- Set column values - inline void cols(const Vector2D& x, const Vector2D& y); + //- Set column values + inline void cols(const Vector2D& x, const Vector2D& y); - // Row-vector access. + // Row-vector access - //- Extract vector for row 0 - inline Vector2D x() const; + //- Extract vector for row 0 + inline Vector2D x() const; - //- Extract vector for row 1 - inline Vector2D y() const; + //- Extract vector for row 1 + inline Vector2D y() const; - //- Extract vector for given row. - // Compile-time check of row index. - template - inline Vector2D row() const; + //- Extract vector for given row: compile-time check of index + template + inline Vector2D row() const; - //- Extract vector for given row (0,1) - // Runtime check of row index. - inline Vector2D row(const direction r) const; + //- Extract vector for given row (0,1): runtime check of index + inline Vector2D row(const direction r) const; - //- Set values of given row - // Compile-time check of row index. - template - inline void row(const Vector2D& v); + //- Set values of given row: compile-time check of index + template + inline void row(const Vector2D& v); - //- Set values of given row (0,1) - // Runtime check of row index. - inline void row(const direction r, const Vector2D& v); + //- Set values of given row (0,1): compile-time check of index + inline void row(const direction r, const Vector2D& v); - //- Set row values - inline void rows(const Vector2D& x, const Vector2D& y); + //- Set row values + inline void rows(const Vector2D& x, const Vector2D& y); - // Diagonal access and manipulation + // Diagonal access and manipulation - //- Extract the diagonal as a vector - inline Vector2D diag() const; + //- Extract the diagonal as a vector + inline Vector2D diag() const; - //- Set values of the diagonal - inline void diag(const Vector2D& v); + //- Set values of the diagonal + inline void diag(const Vector2D& v); // Tensor Operations diff --git a/src/OpenFOAM/primitives/Tensor2D/Tensor2DI.H b/src/OpenFOAM/primitives/Tensor2D/Tensor2DI.H index 1d4523def9..b8a16954aa 100644 --- a/src/OpenFOAM/primitives/Tensor2D/Tensor2DI.H +++ b/src/OpenFOAM/primitives/Tensor2D/Tensor2DI.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -171,13 +171,13 @@ inline Foam::Vector2D Foam::Tensor2D::cy() const template -template +template inline Foam::Vector2D Foam::Tensor2D::col() const { - if (Col == 0) return cx(); - else if (Col == 1) return cy(); + if (Idx == 0) return cx(); + else if (Idx == 1) return cy(); - static_assert(Col < 2, "Invalid column access"); + static_assert(Idx < 2, "Invalid column access"); return Zero; } @@ -189,23 +189,23 @@ inline Foam::Vector2D Foam::Tensor2D::col(const direction c) const { case 0: return cx(); break; case 1: return cy(); break; + default: + FatalErrorInFunction + << "Invalid column access " << c << abort(FatalError); } - FatalErrorInFunction - << "Invalid column access " << c << abort(FatalError); - return Zero; } template -template +template inline Foam::Vector2D Foam::Tensor2D::row() const { - if (Row == 0) return x(); - else if (Row == 1) return y(); + if (Idx == 0) return x(); + else if (Idx == 1) return y(); - static_assert(Row < 2, "Invalid row access"); + static_assert(Idx < 2, "Invalid row access"); return Zero; } @@ -217,48 +217,48 @@ inline Foam::Vector2D Foam::Tensor2D::row(const direction r) const { case 0: return x(); break; case 1: return y(); break; + default: + FatalErrorInFunction + << "Invalid row access " << r << abort(FatalError); } - FatalErrorInFunction - << "Invalid row access " << r << abort(FatalError); - return Zero; } template -template +template inline void Foam::Tensor2D::col(const Vector2D& v) { - if (Col == 0) + if (Idx == 0) { this->v_[XX] = v.x(); this->v_[YX] = v.y(); } - else if (Col == 1) + else if (Idx == 1) { this->v_[XY] = v.x(); this->v_[YY] = v.y(); } - static_assert(Col < 2, "Invalid column access"); + static_assert(Idx < 2, "Invalid column access"); } template -template +template inline void Foam::Tensor2D::row(const Vector2D& v) { - if (Row == 0) + if (Idx == 0) { this->v_[XX] = v.x(); this->v_[XY] = v.y(); } - else if (Row == 1) + else if (Idx == 1) { this->v_[YX] = v.x(); this->v_[YY] = v.y(); } - static_assert(Row < 2, "Invalid row access"); + static_assert(Idx < 2, "Invalid row access"); } @@ -300,7 +300,6 @@ inline void Foam::Tensor2D::col default: FatalErrorInFunction << "Invalid column access " << c << abort(FatalError); - break; } } @@ -319,7 +318,6 @@ inline void Foam::Tensor2D::row default: FatalErrorInFunction << "Invalid row access " << r << abort(FatalError); - break; } } diff --git a/src/finiteVolume/functionObjects/volRegion/volRegion.C b/src/finiteVolume/functionObjects/volRegion/volRegion.C index cc0bcff17f..ec644c0bd1 100644 --- a/src/finiteVolume/functionObjects/volRegion/volRegion.C +++ b/src/finiteVolume/functionObjects/volRegion/volRegion.C @@ -98,7 +98,7 @@ void Foam::functionObjects::volRegion::calculateCache() if (regionIDs_.size() > 1) { cellIds_ = - volMesh_.cellZones().selected(regionIDs_).sortedToc(); + volMesh_.cellZones().selection(regionIDs_).sortedToc(); } break; } @@ -114,7 +114,7 @@ void Foam::functionObjects::volRegion::calculateCache() V_ += volMesh_.V()[celli]; } - nCells_ = returnReduce(selected.size(), sumOp