UniformField: New field type

This commit is contained in:
Henry
2013-09-27 22:47:59 +01:00
parent 1e85b525a6
commit 00db27b969
5 changed files with 153 additions and 0 deletions

View File

@ -0,0 +1,3 @@
Test-UniformField.C
EXE = $(FOAM_USER_APPBIN)/Test-UniformField

View File

@ -0,0 +1,2 @@
/* EXE_INC = -I$(LIB_SRC)/cfdTools/include */
/* EXE_LIBS = -lfiniteVolume */

View File

@ -0,0 +1,15 @@
#include "UniformField.H"
#include "vector.H"
#include "IOstreams.H"
using namespace Foam;
int main()
{
UniformField<scalar> uf1(13.1);
UniformField<vector> uf2(vector(1, 2, 3));
Info<< "uf1 = " << uf1[22] << "; uf2 = " << uf2[1002] << endl;
return 0;
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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 Type>
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
// ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "UniformField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
inline Foam::UniformField<Type>::UniformField(const Type& value)
:
value_(value)
{}
template<class Type>
inline Type Foam::UniformField<Type>::operator[](const label) const
{
return value_;
}
template<class Type>
inline Foam::UniformField<Type> Foam::UniformField<Type>::field() const
{
return UniformField(value_);
}
// ************************************************************************* //