Function2s: Added 'function1', 'product' and 'radial'

The 'function1' function returns the result of a Function1 using just
one of the arguments given to the function2. The function1 is specified
as value1 or value2, depending on which argument it is to be evaluated
with. E.g.:

    <name>
    {
        type            function1;
        value2          table
        (
            (0.00 (0 0 0))
            (0.35 (0 0 1))
            (0.71 (0 0 0))
        );
    }

The 'product' function returns the product of two independent
Function1-s of the two input arguments, again specified as value1 and
value2. For example, to scale a table of vectors in the first argument
with a ramp in the second argument:

    <name>
    {
        type            product;
        value1<vector>  table
        (
            (0.00 (0 0 0))
            (0.25 (1 0 0))
            (0.50 (0 0 0))
        );
        value2<scalar>
        {
            type        linearRamp;
            start       1;
            duration    4;
        }
    }

Note that only one type specification (the <vector>/<scalar>/... part)
is needed in general for the value entries, and no type specifications
are needed if the function is scalar.

The 'radial' function returns a Function1 of the magnitude of the
two-dimensional vector with components equal to the input arguments.
E.g.:

    <name>
    {
        type            radial;
        value           table
        (
            (0.00 (0 0 0))
            (0.35 (0 0 1))
            (0.71 (0 0 0))
        );
    }
This commit is contained in:
Will Bainbridge
2024-04-25 16:34:27 +01:00
parent 42456c3ce9
commit 187b795713
10 changed files with 1309 additions and 1 deletions

View File

@ -0,0 +1,91 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2024 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 "Function12.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::Function2s::Function12<Type>::Function12
(
const word& name,
const dictionary& dict
)
:
FieldFunction2<Type, Function12<Type>>(name),
index_(),
f_()
{
static const word name1 = "value1", name2 = "value2";
const bool found1 = dict.found(name1), found2 = dict.found(name2);
if (found1 && found2)
{
FatalIOErrorInFunction(dict)
<< "Both keywords " << name1 << " and " << name2
<< " are undefined in dictionary " << dict.name()
<< exit(FatalError);
}
if (!found1 && !found2)
{
FatalIOErrorInFunction(dict)
<< "Neither keywords " << name1 << " or " << name2
<< " are defined in dictionary " << dict.name()
<< exit(FatalError);
}
index_ = found2;
f_ = Function1<Type>::New(found2 ? name2 : name1, dict);
}
template<class Type>
Foam::Function2s::Function12<Type>::Function12(const Function12<Type>& se)
:
FieldFunction2<Type, Function12<Type>>(se),
index_(se.index_),
f_(se.f_, false)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::Function2s::Function12<Type>::~Function12()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::Function2s::Function12<Type>::write(Ostream& os) const
{
writeEntry(os, f_());
}
// ************************************************************************* //

View File

@ -0,0 +1,148 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2024 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::Function2s::Function12
Description
Function2 which returns a Function1 using just one of the arguments given
to the function2. The function1 is specified as value1 or value2, depending
on which argument it is to be evaluated with.
Example for a scalar:
\verbatim
<name>
{
type function1;
value1 constant 10; // <-- The value1 function is evaluated with
// the first argument
}
\endverbatim
Example for a vector:
\verbatim
<name>
{
type function1;
value2 table // <-- The value2 function is evaluated with
( // the second argument
(0.00 (0 0 0))
(0.35 (0 0 1))
(0.71 (0 0 0))
);
}
\endverbatim
SourceFiles
Function12.C
\*---------------------------------------------------------------------------*/
#ifndef Function12_H
#define Function12_H
#include "Function1.H"
#include "Function2.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace Function2s
{
/*---------------------------------------------------------------------------*\
Class Function12 Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class Function12
:
public FieldFunction2<Type, Function12<Type>>
{
// Private Data
//- The index of the argument to use. 0 or 1, hence a bool.
bool index_;
//- Function
autoPtr<Function1<Type>> f_;
public:
// Runtime type information
TypeName("function1");
// Constructors
//- Construct from name and dictionary
Function12
(
const word& name,
const dictionary& dict
);
//- Copy constructor
Function12(const Function12<Type>& se);
//- Destructor
virtual ~Function12();
// Member Functions
//- Return value
virtual inline Type value(const scalar x, const scalar y) const;
//- Write data to dictionary stream
virtual void write(Ostream& os) const;
// Member Operators
//- Disallow default bitwise assignment
void operator=(const Function12<Type>&) = delete;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Function2s
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "Function12I.H"
#ifdef NoRepository
#include "Function12.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,42 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2024 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 "Function12.H"
#include "vector2D.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
inline Type Foam::Function2s::Function12<Type>::value
(
const scalar x,
const scalar y
) const
{
return f_->value(index_ ? y : x);
}
// ************************************************************************* //

View File

@ -0,0 +1,314 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2024 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 "Product2.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type, Foam::direction rank>
Foam::Function2s::ProductFunction1s<Type, rank>::ProductFunction1s
(
const dictionary& dict,
const Pair<Tuple2<word, label>>& typeAndRanks
)
:
ProductFunction1s<Type, rank - 1>(dict, typeAndRanks)
{
forAll(fs, i)
{
if (typeAndRanks[i].second() == rank)
{
fs[i] =
function1Type::New
(
valueName(i, typeAndRanks[i]),
dict
);
}
}
}
template<class Type>
Foam::Function2s::ProductFunction1s<Type, 0>::ProductFunction1s
(
const dictionary& dict,
const Pair<Tuple2<word, label>>& typeAndRanks
)
{
forAll(fs, i)
{
if (typeAndRanks[i].second() == 0)
{
fs[i] =
Function1<scalar>::New
(
valueName(i, typeAndRanks[i]),
dict
);
}
}
}
template<class Type, Foam::direction rank>
Foam::Function2s::ProductFunction1s<Type, rank>::ProductFunction1s
(
const ProductFunction1s<Type, rank>& p2f1s
)
:
ProductFunction1s<Type, rank - 1>(p2f1s),
fs
(
autoPtr<function1Type>(p2f1s.fs.first(), false),
autoPtr<function1Type>(p2f1s.fs.second(), false)
)
{}
template<class Type>
Foam::Function2s::ProductFunction1s<Type, 0>::ProductFunction1s
(
const ProductFunction1s<Type, 0>& p2f1s
)
:
fs
(
autoPtr<Function1<scalar>>(p2f1s.fs.first(), false),
autoPtr<Function1<scalar>>(p2f1s.fs.second(), false)
)
{}
template<class Type>
Foam::Function2s::Product<Type>::Product
(
const word& name,
const dictionary& dict
)
:
FieldFunction2<Type, Product<Type>>(name),
fs_(dict, lookupValueTypeAndRanks<Type>(dict))
{}
template<class Type>
Foam::Function2s::Product<Type>::Product(const Product<Type>& se)
:
FieldFunction2<Type, Product<Type>>(se),
fs_(se.fs_)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::Function2s::Product<Type>::~Product()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type, Foam::direction rank>
void Foam::Function2s::ProductFunction1s<Type, rank>::write(Ostream& os) const
{
ProductFunction1s<Type, rank - 1>::write(os);
forAll(fs, i)
{
if (fs[i].valid())
{
writeEntry(os, fs[i]());
}
}
}
template<class Type>
void Foam::Function2s::ProductFunction1s<Type, 0>::write(Ostream& os) const
{
forAll(fs, i)
{
if (fs[i].valid())
{
writeEntry(os, fs[i]());
}
}
}
template<class Type>
void Foam::Function2s::Product<Type>::write(Ostream& os) const
{
fs_.write(os);
}
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
template<class Type, class ValueType>
void Foam::Function2s::lookupValueTypeAndRank
(
const dictionary& dict,
const direction argument,
Tuple2<word, label>& typeAndRank,
label& found
)
{
if (dict.found(valueName<ValueType>(argument)))
{
if (found != -1)
{
FatalIOErrorInFunction(dict)
<< "Multiple " << valueName(argument) << " and/or "
<< valueName(argument, "Type") << "-s specified"
<< exit(FatalIOError);
}
typeAndRank =
Tuple2<word, label>
(
pTraits<ValueType>::typeName,
pTraits<ValueType>::rank
);
found = ProductValueTypeIsValid<Type, ValueType>::value;
}
}
template<class Type>
Foam::Tuple2<Foam::word, Foam::label> Foam::Function2s::lookupValueTypeAndRank
(
const dictionary& dict,
const direction argument
)
{
Tuple2<word, label> typeAndRank(word::null, -1);
label found = dict.found(valueName(argument)) ? 1 : -1;
#define LOOKUP_VALUE_TYPE_AND_RANK(ValueType, nullArg) \
lookupValueTypeAndRank<Type, ValueType> \
( \
dict, \
argument, \
typeAndRank, \
found \
);
FOR_ALL_FIELD_TYPES(LOOKUP_VALUE_TYPE_AND_RANK);
#undef LOOKUP_VALUE_TYPE_AND_RANK
if (found == -1)
{
FatalIOErrorInFunction(dict)
<< "Function " << valueName(argument)
<< " undefined in dictionary " << dict.name()
<< exit(FatalIOError);
}
if (found == 0)
{
FatalIOErrorInFunction(dict)
<< "Function " << valueName(argument, typeAndRank)
<< " returns a type that cannot be used to produce a product"
<< " of type " << pTraits<Type>::typeName
<< exit(FatalIOError);
}
return typeAndRank;
}
template<class Type>
Foam::Pair<Foam::Tuple2<Foam::word, Foam::label>>
Foam::Function2s::lookupValueTypeAndRanks(const dictionary& dict)
{
Pair<Tuple2<word, label>> typeAndRanks
(
lookupValueTypeAndRank<Type>(dict, 0),
lookupValueTypeAndRank<Type>(dict, 1)
);
// If this is a non-scalar type then at least one of the value entries must
// have specified the type
if
(
pTraits<Type>::rank > 0
&& typeAndRanks.first().second() == -1
&& typeAndRanks.second().second() == -1
)
{
FatalIOErrorInFunction(dict)
<< "One of the functions " << valueName(0) << " and "
<< valueName(1) << " needs to specify the return type, e.g., as "
<< valueName<Type>(0) << exit(FatalIOError);
}
// If both types are specified then the sum of their ranks must equal the
// rank of the function
if
(
typeAndRanks.first().second() != -1
&& typeAndRanks.second().second() != -1
&& typeAndRanks.first().second()
+ typeAndRanks.second().second()
!= pTraits<Type>::rank
)
{
FatalIOErrorInFunction(dict)
<< "The functions " << valueName(0, typeAndRanks.first())
<< " and " << valueName(1, typeAndRanks.second()) << " return "
<< "types for which the product is not of type "
<< pTraits<Type>::typeName << exit(FatalIOError);
}
// If this is a scalar type, then neither entry needs to specify the type.
// They both must be scalars.
if
(
pTraits<Type>::rank == 0
&& typeAndRanks.first().second() == -1
&& typeAndRanks.second().second() == -1
)
{
typeAndRanks.first().second() = 0;
typeAndRanks.second().second() = 0;
}
// Determine remaining unspecified ranks
forAll(typeAndRanks, i)
{
if (typeAndRanks[i].second() == -1)
{
typeAndRanks[i].second() =
pTraits<Type>::rank - typeAndRanks[!i].second();
}
}
return typeAndRanks;
}
// ************************************************************************* //

View File

@ -0,0 +1,348 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2024 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::Function2s::Product
Description
Function2 which returns the product of two independent Function1-s of the
two input arguments. The two function1s are specified as value1 and value2.
Example to scale a table of vectors in the first argument with a ramp in
the second argument:
\verbatim
<name>
{
type product;
value1<vector> table
(
(0.00 (0 0 0))
(0.25 (1 0 0))
(0.50 (0 0 0))
);
value2<scalar>
{
type linearRamp;
start 1;
duration 4;
}
}
\endverbatim
Note that only one type specification (the <vector>/<scalar>/... part)
is needed in general for the value entries, and no type specifications
are needed if the function is scalar.
SourceFiles
Product.C
\*---------------------------------------------------------------------------*/
#ifndef Product2_H
#define Product2_H
#include "Function1.H"
#include "Function2.H"
#include "fieldTypes.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace Function2s
{
/*---------------------------------------------------------------------------*\
Class ProductValueTypeIsValid Declaration
\*---------------------------------------------------------------------------*/
template<class Type, class ValueType, class Enable = void>
struct ProductValueTypeIsValid
{
static const bool value = false;
};
template<class Type>
struct ProductValueTypeIsValid<Type, scalar>
{
static const bool value = true;
};
template<class Type, class ValueType>
struct ProductValueTypeIsValid
<
Type,
ValueType,
typename std::enable_if
<
(pTraits<ValueType>::rank > 0)
&& (pTraits<ValueType>::rank <= pTraits<Type>::rank)
>::type
>
{
static const bool value =
std::is_same
<
Type,
typename outerProduct
<
ValueType,
typename typeOfRank
<
scalar,
pTraits<Type>::rank - pTraits<ValueType>::rank
>::type
>::type
>::value;
};
/*---------------------------------------------------------------------------*\
Class ProductFilter Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
struct ProductFilter
{
inline const Type& operator()(const Type& value) const
{
return value;
}
template<class WrongType>
const Type& operator()(const WrongType& value) const
{
return NullObjectRef<Type>();
}
};
/*---------------------------------------------------------------------------*\
Class ProductFunction1s Declaration
\*---------------------------------------------------------------------------*/
template<class Type, direction rank = pTraits<Type>::rank>
class ProductFunction1s
:
public ProductFunction1s<Type, rank - 1>
{
// Private Typedefs
//- Type of the function
typedef
Function1
<
typename std::conditional
<
rank == pTraits<Type>::rank,
Type,
typename typeOfRank<scalar, rank>::type
>::type
> function1Type;
public:
// Public Data
//- Functions
Pair<autoPtr<function1Type>> fs;
// Constructors
//- Construct from a dictionary
ProductFunction1s
(
const dictionary& dict,
const Pair<Tuple2<word, label>>& typeAndRanks
);
//- Copy construct
ProductFunction1s(const ProductFunction1s<Type, rank>& p2f1s);
// Public Member Functions
//- Evaluate
inline Type value(const scalar x, const scalar y) const;
//- Write to a stream
void write(Ostream& os) const;
};
/*---------------------------------------------------------------------------*\
Class ProductFunction1s<0> Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class ProductFunction1s<Type, 0>
{
public:
// Public Data
//- Functions
Pair<autoPtr<Function1<scalar>>> fs;
// Constructors
//- Construct from a dictionary
ProductFunction1s
(
const dictionary& dict,
const Pair<Tuple2<word, label>>& typeAndRanks
);
//- Copy construct
ProductFunction1s(const ProductFunction1s<Type, 0>& p2f1s);
// Public Member Functions
//- Evaluate
inline Type value(const scalar x, const scalar y) const;
//- Write to a stream
void write(Ostream& os) const;
};
/*---------------------------------------------------------------------------*\
Class Product Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class Product
:
public FieldFunction2<Type, Product<Type>>
{
// Private Data
//- Functions
ProductFunction1s<Type> fs_;
public:
// Runtime type information
TypeName("product");
// Constructors
//- Construct from name and dictionary
Product
(
const word& name,
const dictionary& dict
);
//- Copy constructor
Product(const Product<Type>& se);
//- Destructor
virtual ~Product();
// Member Functions
//- Return value
virtual inline Type value(const scalar x, const scalar y) const;
//- Write data to dictionary stream
virtual void write(Ostream& os) const;
// Member Operators
//- Disallow default bitwise assignment
void operator=(const Product<Type>&) = delete;
};
// Global Functions
//- Return the name of the value entry for the given argument
inline word valueName(const direction argument);
//- Return the name of the value entry for the given argument and type name
inline word valueName(const direction argument, const word& typeName);
//- Return the name of the value entry for the given argument and type
template<class Type>
inline word valueName(const direction argument);
//- Return the name of the value entry for the given argument and type and rank
inline word valueName
(
const direction argument,
const Tuple2<word, label>& typeAndRank
);
//- Lookup the type and rank for the value entry for the given argument
template<class Type, class ValueType>
void lookupValueTypeAndRank
(
const dictionary& dict,
const direction argument,
Tuple2<word, label>& typeAndRank,
label& found
);
//- Lookup the type and rank for the value entry for the given argument
template<class Type>
Tuple2<word, label> lookupValueTypeAndRank
(
const dictionary& dict,
const direction argument
);
//- Lookup the types and ranks for the value entries
template<class Type>
Pair<Tuple2<word, label>> lookupValueTypeAndRanks(const dictionary& dict);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Function2s
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "Product2I.H"
#ifdef NoRepository
#include "Product2.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,117 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2024 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 "Product2.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type, Foam::direction rank>
inline Type Foam::Function2s::ProductFunction1s<Type, rank>::value
(
const scalar x,
const scalar y
) const
{
const ProductFilter<Type> filter;
static const direction otherRank = pTraits<Type>::rank - rank;
const ProductFunction1s<Type, otherRank>& other = *this;
if (fs.first().valid())
{
return filter(fs.first()->value(x)*other.fs.second()->value(y));
}
else if (fs.second().valid())
{
return filter(other.fs.first()->value(x)*fs.second()->value(y));
}
else
{
return ProductFunction1s<Type, rank - 1>::value(x, y);
}
}
template<class Type>
inline Type Foam::Function2s::ProductFunction1s<Type, 0>::value
(
const scalar x,
const scalar y
) const
{
const ProductFilter<Type> filter;
return filter(fs.first()->value(x)*fs.second()->value(y));
}
template<class Type>
inline Type Foam::Function2s::Product<Type>::value
(
const scalar x,
const scalar y
) const
{
return fs_.value(x, y);
}
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
inline Foam::word Foam::Function2s::valueName(const direction argument)
{
return "value" + Foam::name(argument + 1);
}
inline Foam::word Foam::Function2s::valueName
(
const direction argument,
const word& typeName
)
{
return
typeName.empty()
? valueName(argument)
: valueName(argument) + "<" + typeName + ">";
}
template<class Type>
inline Foam::word Foam::Function2s::valueName(const direction argument)
{
return valueName(argument, pTraits<Type>::typeName);
}
inline Foam::word Foam::Function2s::valueName
(
const direction argument,
const Tuple2<word, label>& typeAndRank
)
{
return valueName(argument, typeAndRank.first());
}
// ************************************************************************* //

View File

@ -0,0 +1,66 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2024 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 "Radial2.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::Function2s::Radial<Type>::Radial
(
const word& name,
const dictionary& dict
)
:
FieldFunction2<Type, Radial<Type>>(name),
value_(Function1<Type>::New("value", dict))
{}
template<class Type>
Foam::Function2s::Radial<Type>::Radial(const Radial<Type>& se)
:
FieldFunction2<Type, Radial<Type>>(se),
value_(se.value_, false)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::Function2s::Radial<Type>::~Radial()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::Function2s::Radial<Type>::write(Ostream& os) const
{
value_->write(os);
}
// ************************************************************************* //

View File

@ -0,0 +1,134 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2024 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::Function2s::Radial
Description
Function2 which returns a Function1 of the magnitude of the two-dimensional
vector with components equal to the input arguments.
Example
\verbatim
<name>
{
type radial;
value table
(
(0.00 (0 0 0))
(0.35 (0 0 1))
(0.71 (0 0 0))
);
}
\endverbatim
SourceFiles
Radial.C
\*---------------------------------------------------------------------------*/
#ifndef Radial2_H
#define Radial2_H
#include "Function1.H"
#include "Function2.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace Function2s
{
/*---------------------------------------------------------------------------*\
Class Radial Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class Radial
:
public FieldFunction2<Type, Radial<Type>>
{
// Private Data
//- Function of the radius
autoPtr<Function1<Type>> value_;
public:
// Runtime type information
TypeName("radial");
// Constructors
//- Construct from name and dictionary
Radial
(
const word& name,
const dictionary& dict
);
//- Copy constructor
Radial(const Radial<Type>& se);
//- Destructor
virtual ~Radial();
// Member Functions
//- Return value
virtual inline Type value(const scalar x, const scalar y) const;
//- Write data to dictionary stream
virtual void write(Ostream& os) const;
// Member Operators
//- Disallow default bitwise assignment
void operator=(const Radial<Type>&) = delete;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Function2s
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "Radial2I.H"
#ifdef NoRepository
#include "Radial2.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,42 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2024 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 "Radial2.H"
#include "vector2D.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
inline Type Foam::Function2s::Radial<Type>::value
(
const scalar x,
const scalar y
) const
{
return value_->value(mag(vector2D(x, y)));
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2020-2023 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2020-2024 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -37,6 +37,9 @@ Description
#include "ZeroConstant2.H"
#include "OneConstant2.H"
#include "Scale2.H"
#include "Function12.H"
#include "Product2.H"
#include "Radial2.H"
#include "UniformTable2.H"
#include "CodedFunction2.H"
@ -53,6 +56,9 @@ Description
addFunction2(ZeroConstant, Type); \
addFunction2(OneConstant, Type); \
addFunction2(Scale, Type); \
addFunction2(Function12, Type); \
addFunction2(Product, Type); \
addFunction2(Radial, Type); \
addFunction2(UniformTable, Type); \
addFunction2(Coded, Type); \
}