From f10f67b4dd990ee05de208159387c0aae37702d9 Mon Sep 17 00:00:00 2001 From: Will Bainbridge <http://cfd.direct> Date: Mon, 22 May 2017 12:58:25 +0100 Subject: [PATCH] vectorField: vector2DField: Added zip functions for stitching together a vectorField or vector2DField from scalarField components. To do this properly and have it work for field-type combinations would require some new field function macros. --- src/OpenFOAM/Make/files | 2 + .../Fields/vector2DField/vector2DField.C | 43 ++++++++++++++++++ .../Fields/vector2DField/vector2DField.H | 15 ++++++- .../fields/Fields/vectorField/vectorField.C | 45 +++++++++++++++++++ .../fields/Fields/vectorField/vectorField.H | 11 ++++- 5 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 src/OpenFOAM/fields/Fields/vector2DField/vector2DField.C create mode 100644 src/OpenFOAM/fields/Fields/vectorField/vectorField.C diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index df5381fcf5..0dd52536e9 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -609,6 +609,8 @@ Fields = fields/Fields $(Fields)/labelField/labelField.C $(Fields)/scalarField/scalarField.C +$(Fields)/vectorField/vectorField.C +$(Fields)/vector2DField/vector2DField.C $(Fields)/sphericalTensorField/sphericalTensorField.C $(Fields)/diagTensorField/diagTensorField.C $(Fields)/symmTensorField/symmTensorField.C diff --git a/src/OpenFOAM/fields/Fields/vector2DField/vector2DField.C b/src/OpenFOAM/fields/Fields/vector2DField/vector2DField.C new file mode 100644 index 0000000000..edacb39cbe --- /dev/null +++ b/src/OpenFOAM/fields/Fields/vector2DField/vector2DField.C @@ -0,0 +1,43 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +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 <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "vector2DField.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +Foam::tmp<Foam::vector2DField> Foam::zip +( + const tmp<scalarField>& x, + const tmp<scalarField>& y +) +{ + tmp<vector2DField> txy(new vector2DField(x->size())); + vector2DField& xy = txy.ref(); + xy.replace(0, x); + xy.replace(1, y); + return txy; +} + +// ************************************************************************* // diff --git a/src/OpenFOAM/fields/Fields/vector2DField/vector2DField.H b/src/OpenFOAM/fields/Fields/vector2DField/vector2DField.H index 91d84a0d9c..2a4c7edb24 100644 --- a/src/OpenFOAM/fields/Fields/vector2DField/vector2DField.H +++ b/src/OpenFOAM/fields/Fields/vector2DField/vector2DField.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -37,6 +37,19 @@ SourceFiles // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +tmp<vector2DField> zip(const tmp<scalarField>& x, const tmp<scalarField>& y); + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + #endif // ************************************************************************* // diff --git a/src/OpenFOAM/fields/Fields/vectorField/vectorField.C b/src/OpenFOAM/fields/Fields/vectorField/vectorField.C new file mode 100644 index 0000000000..078381d8ec --- /dev/null +++ b/src/OpenFOAM/fields/Fields/vectorField/vectorField.C @@ -0,0 +1,45 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +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 <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "vectorField.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +Foam::tmp<Foam::vectorField> Foam::zip +( + const tmp<scalarField>& x, + const tmp<scalarField>& y, + const tmp<scalarField>& z +) +{ + tmp<vectorField> txyz(new vectorField(x->size())); + vectorField& xyz = txyz.ref(); + xyz.replace(0, x); + xyz.replace(1, y); + xyz.replace(2, z); + return txyz; +} + +// ************************************************************************* // diff --git a/src/OpenFOAM/fields/Fields/vectorField/vectorField.H b/src/OpenFOAM/fields/Fields/vectorField/vectorField.H index beb6541d11..c3a5a3e807 100644 --- a/src/OpenFOAM/fields/Fields/vectorField/vectorField.H +++ b/src/OpenFOAM/fields/Fields/vectorField/vectorField.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -49,6 +49,15 @@ typedef Field<vector> vectorField; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +tmp<vectorField> zip +( + const tmp<scalarField>& x, + const tmp<scalarField>& y, + const tmp<scalarField>& z +); + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + } // End namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -- GitLab