From 00db27b969013bc2faff19d70bf01789ef66111f Mon Sep 17 00:00:00 2001 From: Henry Date: Fri, 27 Sep 2013 22:47:59 +0100 Subject: [PATCH] UniformField: New field type --- applications/test/UniformField/Make/files | 3 + applications/test/UniformField/Make/options | 2 + .../test/UniformField/Test-UniformField.C | 15 ++++ .../fields/Fields/uniformField/UniformField.H | 82 +++++++++++++++++++ .../Fields/uniformField/UniformFieldI.H | 51 ++++++++++++ 5 files changed, 153 insertions(+) create mode 100644 applications/test/UniformField/Make/files create mode 100644 applications/test/UniformField/Make/options create mode 100644 applications/test/UniformField/Test-UniformField.C create mode 100644 src/OpenFOAM/fields/Fields/uniformField/UniformField.H create mode 100644 src/OpenFOAM/fields/Fields/uniformField/UniformFieldI.H diff --git a/applications/test/UniformField/Make/files b/applications/test/UniformField/Make/files new file mode 100644 index 0000000000..3e268d0c3e --- /dev/null +++ b/applications/test/UniformField/Make/files @@ -0,0 +1,3 @@ +Test-UniformField.C + +EXE = $(FOAM_USER_APPBIN)/Test-UniformField diff --git a/applications/test/UniformField/Make/options b/applications/test/UniformField/Make/options new file mode 100644 index 0000000000..6a9e9810b3 --- /dev/null +++ b/applications/test/UniformField/Make/options @@ -0,0 +1,2 @@ +/* EXE_INC = -I$(LIB_SRC)/cfdTools/include */ +/* EXE_LIBS = -lfiniteVolume */ diff --git a/applications/test/UniformField/Test-UniformField.C b/applications/test/UniformField/Test-UniformField.C new file mode 100644 index 0000000000..88053afdba --- /dev/null +++ b/applications/test/UniformField/Test-UniformField.C @@ -0,0 +1,15 @@ +#include "UniformField.H" +#include "vector.H" +#include "IOstreams.H" + +using namespace Foam; + +int main() +{ + UniformField uf1(13.1); + UniformField uf2(vector(1, 2, 3)); + + Info<< "uf1 = " << uf1[22] << "; uf2 = " << uf2[1002] << endl; + + return 0; +} diff --git a/src/OpenFOAM/fields/Fields/uniformField/UniformField.H b/src/OpenFOAM/fields/Fields/uniformField/UniformField.H new file mode 100644 index 0000000000..140b4b4fd6 --- /dev/null +++ b/src/OpenFOAM/fields/Fields/uniformField/UniformField.H @@ -0,0 +1,82 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013 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 . + +Class + Foam::UniformField + +Description + A class representing the concept of a uniform field which stores only + the single value and providing the operator[] to return it. + +\*---------------------------------------------------------------------------*/ + +#ifndef UniformField_H +#define UniformField_H + +#include "label.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class UniformField Declaration +\*---------------------------------------------------------------------------*/ + +template +class UniformField +{ + // Private data + + Type value_; + +public: + + // Constructors + + //- Construct given value + inline UniformField(const Type& value); + + + // Member Operators + + inline Type operator[](const label) const; + + inline UniformField field() const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "UniformFieldI.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/fields/Fields/uniformField/UniformFieldI.H b/src/OpenFOAM/fields/Fields/uniformField/UniformFieldI.H new file mode 100644 index 0000000000..9c7012a7ee --- /dev/null +++ b/src/OpenFOAM/fields/Fields/uniformField/UniformFieldI.H @@ -0,0 +1,51 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013 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 . + +\*---------------------------------------------------------------------------*/ + +#include "UniformField.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +inline Foam::UniformField::UniformField(const Type& value) +: + value_(value) +{} + + +template +inline Type Foam::UniformField::operator[](const label) const +{ + return value_; +} + + +template +inline Foam::UniformField Foam::UniformField::field() const +{ + return UniformField(value_); +} + + +// ************************************************************************* //