mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: relocate/rename expression-related ops to exprOps
This commit is contained in:
136
src/OpenFOAM/expressions/exprOps/exprOps.H
Normal file
136
src/OpenFOAM/expressions/exprOps/exprOps.H
Normal file
@ -0,0 +1,136 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
InNamespace
|
||||
Foam::expressions
|
||||
|
||||
Description
|
||||
Operations involving expressions.
|
||||
|
||||
SourceFiles
|
||||
exprOps.H
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef exprOps_H
|
||||
#define exprOps_H
|
||||
|
||||
#include "scalar.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Namespace expressions Declarations
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
//- Convert [0-1] values (usually scalars) as false/true
|
||||
template<class T>
|
||||
struct boolOp
|
||||
{
|
||||
bool operator()(const T& val) const
|
||||
{
|
||||
return (0.5 < Foam::mag(val));
|
||||
}
|
||||
};
|
||||
|
||||
//- Inverse of boolOp()
|
||||
template<class T>
|
||||
struct boolNotOp
|
||||
{
|
||||
bool operator()(const T& val) const
|
||||
{
|
||||
return (Foam::mag(val) < 0.5);
|
||||
}
|
||||
};
|
||||
|
||||
//- Convert to bool, pass-through for bool
|
||||
template<>
|
||||
struct boolOp<bool>
|
||||
{
|
||||
bool operator()(bool val) const
|
||||
{
|
||||
return val;
|
||||
}
|
||||
};
|
||||
|
||||
//- Inverse of boolOp, no conversion required for bool
|
||||
template<>
|
||||
struct boolNotOp<bool>
|
||||
{
|
||||
bool operator()(bool val) const
|
||||
{
|
||||
return !val;
|
||||
}
|
||||
};
|
||||
|
||||
//- Logical 'and', possibly with scalars as (false, true) values
|
||||
template<class T>
|
||||
struct boolAndOp
|
||||
{
|
||||
bool operator()(const T& a, const T& b) const
|
||||
{
|
||||
return (boolOp<T>()(a) && boolOp<T>()(b));
|
||||
}
|
||||
};
|
||||
|
||||
//- Logical 'or', possibly with scalars as (false, true) values
|
||||
template<class T>
|
||||
struct boolOrOp
|
||||
{
|
||||
bool operator()(const T& a, const T& b) const
|
||||
{
|
||||
return (boolOp<T>()(a) || boolOp<T>()(b));
|
||||
}
|
||||
};
|
||||
|
||||
//- Logical 'xor', possibly with scalars as (false, true) values
|
||||
template<class T>
|
||||
struct boolXorOp
|
||||
{
|
||||
bool operator()(const T& a, const T& b) const
|
||||
{
|
||||
return (boolOp<T>()(a) != boolOp<T>()(b));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // End namespace expressions
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -38,8 +38,8 @@ SourceFiles
|
||||
#ifndef exprTools_H
|
||||
#define exprTools_H
|
||||
|
||||
#include "exprOps.H"
|
||||
#include "exprString.H"
|
||||
#include "scalar.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -47,7 +47,7 @@ namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Namespace exprTools Declaration
|
||||
Namespace exprTools Declarations
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
namespace exprTools
|
||||
@ -100,81 +100,9 @@ List<expressions::exprString> getList
|
||||
);
|
||||
|
||||
|
||||
// Boolean-like values
|
||||
|
||||
//- Convert [0-1] values (usually scalars) as false/true
|
||||
template<class T>
|
||||
struct toBoolOp
|
||||
{
|
||||
int operator()(const T& val) const
|
||||
{
|
||||
return (0.5 < Foam::mag(val));
|
||||
}
|
||||
};
|
||||
|
||||
//- No conversion needed for bool
|
||||
template<>
|
||||
struct toBoolOp<bool>
|
||||
{
|
||||
int operator()(bool val) const
|
||||
{
|
||||
return val;
|
||||
}
|
||||
};
|
||||
|
||||
//- Inverse test of toBoolOp()
|
||||
template<class T>
|
||||
struct toBoolNotOp
|
||||
{
|
||||
int operator()(const T& val) const
|
||||
{
|
||||
return (Foam::mag(val) < 0.5);
|
||||
}
|
||||
};
|
||||
|
||||
//- Inverse test of toBoolOp, no conversion needed for bool
|
||||
template<>
|
||||
struct toBoolNotOp<bool>
|
||||
{
|
||||
int operator()(bool val) const
|
||||
{
|
||||
return !val;
|
||||
}
|
||||
};
|
||||
|
||||
//- Logical 'and' with scalars as (false, true) values
|
||||
template<class T>
|
||||
struct toBoolAndOp
|
||||
{
|
||||
int operator()(const T& a, const T& b) const
|
||||
{
|
||||
return (toBoolOp<T>()(a) && toBoolOp<T>()(b));
|
||||
}
|
||||
};
|
||||
|
||||
//- Logical 'or' with scalars as (false, true) values
|
||||
template<class T>
|
||||
struct toBoolOrOp
|
||||
{
|
||||
int operator()(const T& a, const T& b) const
|
||||
{
|
||||
return (toBoolOp<T>()(a) || toBoolOp<T>()(b));
|
||||
}
|
||||
};
|
||||
|
||||
//- Logical 'xor' with scalars as (false, true) values
|
||||
template<class T>
|
||||
struct toBoolXorOp
|
||||
{
|
||||
int operator()(const T& a, const T& b) const
|
||||
{
|
||||
return (toBoolOp<T>()(a) ? toBoolNotOp<T>()(b) : toBoolOp<T>()(b));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // End namespace exprTools
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
Reference in New Issue
Block a user