Commit 28a9cde0 authored by Mark OLESEN's avatar Mark OLESEN Committed by Andrew Heather
Browse files

ENH: add boolField specializations: negate(), component()

ENH: added scalarField hypot() function
parent b465592e
Test-field1.C
EXE = $(FOAM_USER_APPBIN)/Test-field1
/* EXE_INC = */
/* EXE_LIBS = */
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ 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/>.
Description
Simple field tests
\*---------------------------------------------------------------------------*/
#include "primitiveFields.H"
#include "IOstreams.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
scalarField sfield(10, one());
forAll(sfield, i)
{
sfield[i] = (i % 4) ? i : 0;
}
Info<< "scalarField: " << sfield << nl;
sfield.negate();
Info<< "negated: " << sfield << nl;
// Does not compile (ambiguous)
// boolField lfield(10, one());
boolField lfield(10, true);
forAll(lfield, i)
{
lfield[i] = (i % 4) ? i : 0;
}
Info<< "boolField: " << lfield << nl;
lfield.negate();
Info<< "negated: " << lfield << nl;
return 0;
}
// ************************************************************************* //
......@@ -656,6 +656,7 @@ fields/cloud/cloud.C
Fields = fields/Fields
$(Fields)/Field/FieldBase.C
$(Fields)/boolField/boolField.C
$(Fields)/labelField/labelField.C
$(Fields)/labelField/labelIOField.C
$(Fields)/labelField/labelFieldIOField.C
......
......@@ -498,6 +498,17 @@ Foam::dimensionSet Foam::atan2(const dimensionSet& ds1, const dimensionSet& ds2)
}
Foam::dimensionSet Foam::hypot(const dimensionSet& ds1, const dimensionSet& ds2)
{
if (dimensionSet::debug)
{
checkDims("hypot(a, b)", ds1, ds2);
}
return ds1;
}
Foam::dimensionSet Foam::transform(const dimensionSet& ds)
{
return ds;
......
......@@ -330,9 +330,12 @@ dimensionSet inv(const dimensionSet& ds);
//- Check the argument is dimensionless (for transcendental functions)
dimensionSet trans(const dimensionSet& ds);
//- Check that the arguments have the same dimensions
//- Arguments need the same dimensions. Return dimensionless.
dimensionSet atan2(const dimensionSet& ds1, const dimensionSet& ds2);
//- Arguments need the same dimensions. Does not change the dimension.
dimensionSet hypot(const dimensionSet& ds1, const dimensionSet& ds2);
//- Return the argument; transformations do not change the dimensions
dimensionSet transform(const dimensionSet& ds);
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2017 OpenFOAM Foundation
......@@ -162,21 +162,6 @@ dimensionedScalar cbrt(const dimensionedScalar& ds)
}
dimensionedScalar hypot
(
const dimensionedScalar& x,
const dimensionedScalar& y
)
{
return dimensionedScalar
(
"hypot(" + x.name() + ',' + y.name() + ')',
x.dimensions() + y.dimensions(),
::hypot(x.value(), y.value())
);
}
dimensionedScalar sign(const dimensionedScalar& ds)
{
return dimensionedScalar
......@@ -337,6 +322,21 @@ dimensionedScalar atan2
}
dimensionedScalar hypot
(
const dimensionedScalar& x,
const dimensionedScalar& y
)
{
return dimensionedScalar
(
"hypot(" + x.name() + ',' + y.name() + ')',
hypot(x.dimensions(), y.dimensions()),
::hypot(x.value(), y.value())
);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2017 OpenFOAM Foundation
......@@ -66,7 +66,6 @@ dimensionedScalar pow025(const dimensionedScalar&);
dimensionedScalar sqrt(const dimensionedScalar&);
dimensionedScalar cbrt(const dimensionedScalar&);
dimensionedScalar hypot(const dimensionedScalar&, const dimensionedScalar&);
dimensionedScalar sign(const dimensionedScalar&);
dimensionedScalar pos(const dimensionedScalar&);
......@@ -86,6 +85,7 @@ dimensionedScalar asin(const dimensionedScalar&);
dimensionedScalar acos(const dimensionedScalar&);
dimensionedScalar atan(const dimensionedScalar&);
dimensionedScalar atan2(const dimensionedScalar&, const dimensionedScalar&);
dimensionedScalar hypot(const dimensionedScalar&, const dimensionedScalar&);
dimensionedScalar sinh(const dimensionedScalar&);
dimensionedScalar cosh(const dimensionedScalar&);
dimensionedScalar tanh(const dimensionedScalar&);
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2017 OpenFOAM Foundation
......@@ -98,6 +98,9 @@ BINARY_TYPE_FUNCTION(scalar, scalar, scalar, pow)
BINARY_FUNCTION(scalar, scalar, scalar, atan2)
BINARY_TYPE_FUNCTION(scalar, scalar, scalar, atan2)
BINARY_FUNCTION(scalar, scalar, scalar, hypot)
BINARY_TYPE_FUNCTION(scalar, scalar, scalar, hypot)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2017 OpenFOAM Foundation
......@@ -91,6 +91,9 @@ BINARY_TYPE_FUNCTION(scalar, scalar, scalar, pow)
BINARY_FUNCTION(scalar, scalar, scalar, atan2)
BINARY_TYPE_FUNCTION(scalar, scalar, scalar, atan2)
BINARY_FUNCTION(scalar, scalar, scalar, hypot)
BINARY_TYPE_FUNCTION(scalar, scalar, scalar, hypot)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -69,10 +69,6 @@ Ostream& operator<<(Ostream&, const Field<Type>&);
template<class Type>
Ostream& operator<<(Ostream&, const tmp<Field<Type>>&);
// Basic Field types
typedef Field<bool> boolField; //!< A Field of bools
typedef Field<label> labelField; //!< A Field of labels
/*---------------------------------------------------------------------------*\
Class Field Declaration
......@@ -338,7 +334,8 @@ public:
const UList<scalar>& weights
);
//- Negate this field
//- Negate this field (negative).
// Inverts the state for a bool field.
void negate();
//- Return a component field of the field
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ 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/>.
Description
Specialisation of Field\<T\> for bool.
\*---------------------------------------------------------------------------*/
#include "boolField.H"
#include "unitConversion.H"
#define TEMPLATE
#include "FieldFunctionsM.C"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<>
void boolField::negate()
{
TFOR_ALL_F_OP_OP_F(bool, *this, =, !, bool, *this)
}
template<>
tmp<boolField> boolField::component(const direction) const
{
return *this;
}
template<>
void boolField::replace(const direction, const boolUList& bf)
{
*this = bf;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "undefFieldFunctionsM.H"
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ 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/>.
Typedef
Foam::boolField
Description
Specialisation of Field\<T\> for bool
SourceFiles
boolField.C
\*---------------------------------------------------------------------------*/
#ifndef boolField_H
#define boolField_H
#include "bool.H"
#include "Field.H"
#define TEMPLATE
#include "FieldFunctionsM.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef Field<bool> boolField;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<>
void boolField::negate();
template<>
tmp<boolField> boolField::component(const direction) const;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "undefFieldFunctionsM.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -47,6 +47,7 @@ tmp<labelField> labelField::component(const direction) const
return *this;
}
template<>
void component
(
......@@ -58,6 +59,7 @@ void component
lf = f;
}
template<>
void labelField::replace(const direction, const labelUList& lf)
{
......
......@@ -48,8 +48,7 @@ SourceFiles
namespace Foam
{
// labelField = defined in Field.H
typedef Field<label> labelField;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011 OpenFOAM Foundation
......@@ -36,6 +36,7 @@ Description
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "boolField.H"
#include "labelField.H"
#include "scalarField.H"
#include "vectorField.H"
......
......@@ -46,6 +46,7 @@ namespace Foam
template<class Type> class Field;
typedef Field<bool> boolField;
typedef Field<label> labelField;
typedef Field<scalar> scalarField;
typedef Field<solveScalar> solveScalarField;
......
......@@ -131,6 +131,9 @@ BINARY_TYPE_FUNCTION(scalar, scalar, scalar, pow)
BINARY_FUNCTION(scalar, scalar, scalar, atan2)
BINARY_TYPE_FUNCTION(scalar, scalar, scalar, atan2)
BINARY_FUNCTION(scalar, scalar, scalar, hypot)
BINARY_TYPE_FUNCTION(scalar, scalar, scalar, hypot)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
UNARY_FUNCTION(scalar, scalar, pow3)
......
......@@ -101,6 +101,9 @@ BINARY_TYPE_FUNCTION(scalar, scalar, scalar, pow)
BINARY_FUNCTION(scalar, scalar, scalar, atan2)
BINARY_TYPE_FUNCTION(scalar, scalar, scalar, atan2)
BINARY_FUNCTION(scalar, scalar, scalar, hypot)
BINARY_TYPE_FUNCTION(scalar, scalar, scalar, hypot)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -417,6 +417,25 @@ Foam::orientedType Foam::atan2
}
Foam::orientedType Foam::hypot
(
const orientedType& ot1,
const orientedType& ot2
)
{
if (!orientedType::checkType(ot1, ot2))
{
FatalErrorInFunction
<< "Operator hypot is undefined for "
<< orientedType::orientedOptionNames[ot1.oriented()] << " and "
<< orientedType::orientedOptionNames[ot2.oriented()] << "types"
<< abort(FatalError);
}
return ot1;
}
Foam::orientedType Foam::transform(const orientedType& ot)
{
return ot;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment