From 052d8b13e336f08d2f33ac53bcb2674e8a0ea090 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 12 Sep 2022 12:50:10 +0200 Subject: [PATCH] ENH: support tuple (pair) indexing into FieldField - can use a (patchi, elemi) pair to access an element of a FieldField --- applications/test/FieldFields1/Make/files | 3 + .../Make/options | 0 .../test/FieldFields1/Test-FieldFields1.C | 117 ++++++++++++++++++ applications/test/FieldFields2/Make/files | 3 + applications/test/FieldFields2/Make/options | 2 + .../Test-FieldFields2.C} | 31 +++-- .../test/tensorFieldFields1/Make/files | 3 - .../test/tensorFields1/Test-tensorFields1.C | 26 ++-- .../FieldFields/FieldField/FieldField.C | 24 ++++ .../FieldFields/FieldField/FieldField.H | 16 ++- .../FieldFields/oneFieldField/oneFieldField.H | 14 ++- .../zeroFieldField/zeroFieldField.H | 14 ++- .../fields/Fields/oneField/oneField.H | 6 +- .../fields/Fields/zeroField/zeroField.H | 6 +- src/OpenFOAM/primitives/tuples/Pair.H | 4 +- src/OpenFOAM/primitives/tuples/Tuple2.H | 105 +++++++--------- 16 files changed, 277 insertions(+), 97 deletions(-) create mode 100644 applications/test/FieldFields1/Make/files rename applications/test/{tensorFieldFields1 => FieldFields1}/Make/options (100%) create mode 100644 applications/test/FieldFields1/Test-FieldFields1.C create mode 100644 applications/test/FieldFields2/Make/files create mode 100644 applications/test/FieldFields2/Make/options rename applications/test/{tensorFieldFields1/Test-tensorFieldFields1.C => FieldFields2/Test-FieldFields2.C} (91%) delete mode 100644 applications/test/tensorFieldFields1/Make/files diff --git a/applications/test/FieldFields1/Make/files b/applications/test/FieldFields1/Make/files new file mode 100644 index 0000000000..e90b498508 --- /dev/null +++ b/applications/test/FieldFields1/Make/files @@ -0,0 +1,3 @@ +Test-FieldFields1.C + +EXE = $(FOAM_USER_APPBIN)/Test-FieldFields1 diff --git a/applications/test/tensorFieldFields1/Make/options b/applications/test/FieldFields1/Make/options similarity index 100% rename from applications/test/tensorFieldFields1/Make/options rename to applications/test/FieldFields1/Make/options diff --git a/applications/test/FieldFields1/Test-FieldFields1.C b/applications/test/FieldFields1/Test-FieldFields1.C new file mode 100644 index 0000000000..53f3314c35 --- /dev/null +++ b/applications/test/FieldFields1/Test-FieldFields1.C @@ -0,0 +1,117 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2022 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Application + Test-FieldFields1 + +\*---------------------------------------------------------------------------*/ + +#include "symmTensorField.H" +#include "tensorField.H" +#include "FieldFields.H" +#include "Random.H" + +using namespace Foam; + + +template +void printFieldField(const FieldField& ff) +{ + forAll(ff, i) + { + Info<< i << ": " << flatOutput(ff[i]) << nl; + } + Info<< nl; +} + + +template +tmp> randomField(Random& rnd, label dim) +{ + auto tfld = tmp>::New(dim); + auto& fld = tfld.ref(); + + for (Type& val : fld) + { + for (direction cmpt=0; cmpt < pTraits::nComponents; ++cmpt) + { + setComponent(val, cmpt) = rnd.position