Skip to content
Snippets Groups Projects
Commit bb3660b9 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

ENH: add construct ConstantField with uniform value

parent 97be8fc7
Branches
Tags
No related merge requests found
Showing
with 98 additions and 98 deletions
......@@ -52,7 +52,7 @@ Foam::Function1Types::Constant<Type>::Constant
Function1<Type>(entryName),
value_(Zero)
{
Istream& is(dict.lookup(entryName));
Istream& is = dict.lookup(entryName);
word entryType(is);
is >> value_;
}
......@@ -78,13 +78,6 @@ Foam::Function1Types::Constant<Type>::Constant(const Constant<Type>& cnst)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::Function1Types::Constant<Type>::~Constant()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
......
......@@ -103,7 +103,7 @@ public:
//- Destructor
virtual ~Constant();
virtual ~Constant() = default;
// Member Functions
......
......@@ -103,6 +103,7 @@ protected:
//- Name of entry
const word name_;
// Protected Member Functions
//- No copy assignment
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018-2019 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -28,10 +28,11 @@ License
#include "Constant.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
template<class Type>
Foam::autoPtr<Foam::Function1<Type>> Foam::Function1<Type>::New
Foam::autoPtr<Foam::Function1<Type>>
Foam::Function1<Type>::New
(
const word& entryName,
const dictionary& dict,
......@@ -86,10 +87,14 @@ Foam::autoPtr<Foam::Function1<Type>> Foam::Function1<Type>::New
if (!firstToken.isWord())
{
// Backwards-compatibility for reading straight fields
is.putBack(firstToken);
const Type constValue = pTraits<Type>(is);
return autoPtr<Function1<Type>>
(
new Function1Types::Constant<Type>(entryName, is)
new Function1Types::Constant<Type>(entryName, constValue)
);
}
......
......@@ -29,6 +29,23 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::PatchFunction1Types::ConstantField<Type>::ConstantField
(
const polyPatch& pp,
const word& entryName,
const Type& uniformValue,
const dictionary& dict,
const bool faceValues
)
:
PatchFunction1<Type>(pp, entryName, dict, faceValues),
isUniform_(true),
uniformValue_(uniformValue),
value_((faceValues ? pp.size() : pp.nPoints()), uniformValue_)
{}
template<class Type>
Foam::PatchFunction1Types::ConstantField<Type>::ConstantField
(
......@@ -36,7 +53,7 @@ Foam::PatchFunction1Types::ConstantField<Type>::ConstantField
const word& entryName,
const bool isUniform,
const Type& uniformValue,
const Field<Type>& nonUniformValue,
const Field<Type>& fieldValues,
const dictionary& dict,
const bool faceValues
)
......@@ -44,21 +61,18 @@ Foam::PatchFunction1Types::ConstantField<Type>::ConstantField
PatchFunction1<Type>(pp, entryName, dict, faceValues),
isUniform_(isUniform),
uniformValue_(uniformValue),
value_(nonUniformValue)
value_(fieldValues)
{
if (faceValues && nonUniformValue.size() != pp.size())
{
FatalIOErrorInFunction(dict)
<< "Supplied field size " << nonUniformValue.size()
<< " is not equal to the number of faces " << pp.size()
<< " of patch " << pp.name() << exit(FatalIOError);
}
else if (!faceValues && nonUniformValue.size() != pp.nPoints())
const label len = (faceValues ? pp.size() : pp.nPoints());
if (fieldValues.size() != len)
{
FatalIOErrorInFunction(dict)
<< "Supplied field size " << nonUniformValue.size()
<< " is not equal to the number of points " << pp.nPoints()
<< " of patch " << pp.name() << exit(FatalIOError);
<< "Supplied field size " << fieldValues.size()
<< " is not equal to the number of "
<< (faceValues ? "faces" : "points") << ' '
<< len << " of patch " << pp.name() << nl
<< exit(FatalIOError);
}
}
......@@ -103,7 +117,7 @@ Foam::Field<Type> Foam::PatchFunction1Types::ConstantField<Type>::getValue
is >> list;
isUniform = false;
label currentSize = fld.size();
const label currentSize = fld.size();
if (currentSize != len)
{
if
......@@ -120,7 +134,7 @@ Foam::Field<Type> Foam::PatchFunction1Types::ConstantField<Type>::getValue
<< endl;
#endif
// Resize the data
// Resize (shrink) the data
fld.setSize(len);
}
else
......@@ -204,13 +218,13 @@ Foam::PatchFunction1Types::ConstantField<Type>::ConstantField
uniformValue_(cnst.uniformValue_),
value_(cnst.value_)
{
// If different sizes do what?
value_.setSize
// If sizes are different...
value_.resize
(
this->faceValues_
? this->patch_.size()
: this->patch_.nPoints()
(this->faceValues_ ? this->patch_.size() : this->patch_.nPoints()),
Zero
);
if (isUniform_)
{
value_ = uniformValue_;
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -96,6 +96,16 @@ public:
// Constructors
//- Construct from a uniform value
ConstantField
(
const polyPatch& pp,
const word& entryName,
const Type& uniformValue,
const dictionary& dict = dictionary::null,
const bool faceValues = true
);
//- Construct from components
ConstantField
(
......@@ -103,7 +113,7 @@ public:
const word& entryName,
const bool isUniform,
const Type& uniformValue,
const Field<Type>& nonUniformValue,
const Field<Type>& fieldValues,
const dictionary& dict = dictionary::null,
const bool faceValues = true
);
......
......@@ -5,8 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......
......@@ -232,19 +232,19 @@ void Foam::PatchFunction1<Type>::writeData(Ostream& os) const
}
// * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * IOStream Operators * * * * * * * * * * * * * //
template<class Type>
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const PatchFunction1<Type>& pf1
const PatchFunction1<Type>& rhs
)
{
os.check(FUNCTION_NAME);
os << pf1.name_;
pf1.writeData(os);
os << rhs.name_;
rhs.writeData(os);
return os;
}
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -56,19 +56,12 @@ SeeAlso
namespace Foam
{
// Forward declarations
// Forward Declarations
class Time;
template<class Type> class PatchFunction1;
// Forward declaration of friend functions and operators
template<class Type>
class PatchFunction1;
template<class Type>
Ostream& operator<<
(
Ostream&,
const PatchFunction1<Type>&
);
Ostream& operator<<(Ostream&, const PatchFunction1<Type>&);
/*---------------------------------------------------------------------------*\
Class PatchFunction1 Declaration
......@@ -79,15 +72,9 @@ class PatchFunction1
:
public refCount
{
// Private Member Functions
//- No copy assignment
void operator=(const PatchFunction1<Type>&) = delete;
protected:
// Protected data
// Protected Data
//- Name of entry
const word name_;
......@@ -102,6 +89,12 @@ protected:
coordinateScaling<Type> coordSys_;
// Protected Member Functions
//- No copy assignment
void operator=(const PatchFunction1<Type>&) = delete;
public:
typedef Field<Type> returnType;
......@@ -249,7 +242,7 @@ public:
friend Ostream& operator<< <Type>
(
Ostream& os,
const PatchFunction1<Type>& func
const PatchFunction1<Type>& rhs
);
//- Write in dictionary format
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018-2019 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -27,10 +27,11 @@ License
#include "ConstantField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
template<class Type>
Foam::autoPtr<Foam::PatchFunction1<Type>> Foam::PatchFunction1<Type>::New
Foam::autoPtr<Foam::PatchFunction1<Type>>
Foam::PatchFunction1<Type>::New
(
const polyPatch& pp,
const word& entryName,
......@@ -47,6 +48,7 @@ Foam::autoPtr<Foam::PatchFunction1<Type>> Foam::PatchFunction1<Type>::New
<< entryName << nl << nl
<< exit(FatalIOError);
// Failed
return nullptr;
}
else if (eptr->isDict())
......@@ -81,11 +83,6 @@ Foam::autoPtr<Foam::PatchFunction1<Type>> Foam::PatchFunction1<Type>::New
is.putBack(firstToken);
const Type uniformValue = pTraits<Type>(is);
const Field<Type> value
(
(faceValues ? pp.size() : pp.nPoints()),
uniformValue
);
return autoPtr<PatchFunction1<Type>>
(
......@@ -93,9 +90,7 @@ Foam::autoPtr<Foam::PatchFunction1<Type>> Foam::PatchFunction1<Type>::New
(
pp,
entryName,
true, // uniform
uniformValue, // uniform value
value, // Supply value
uniformValue,
dict,
faceValues
)
......
......@@ -62,9 +62,9 @@ class UniformValueField
:
public PatchFunction1<Type>
{
// Private data
// Private Data
//- Source of uniform values (in local co-ordinate system)
//- Source of uniform values (in local coordinate system)
autoPtr<Foam::Function1<Type>> uniformValuePtr_;
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -46,21 +46,16 @@ Foam::PatchFunction1Types::UniformValueField<Type>::value
const scalar x
) const
{
label sz =
(
this->faceValues_
? this->patch_.size()
: this->patch_.nPoints()
);
tmp<Field<Type>> tfld
(
const label len =
(this->faceValues_ ? this->patch_.size() : this->patch_.nPoints());
auto tfld =
tmp<Field<Type>>::New
(
sz,
len,
uniformValuePtr_->value(x)
)
);
);
return this->transform(tfld);
}
......@@ -73,21 +68,16 @@ Foam::PatchFunction1Types::UniformValueField<Type>::integrate
const scalar x2
) const
{
label sz =
(
this->faceValues_
? this->patch_.size()
: this->patch_.nPoints()
);
tmp<Field<Type>> tfld
(
const label len =
(this->faceValues_ ? this->patch_.size() : this->patch_.nPoints());
auto tfld =
tmp<Field<Type>>::New
(
sz,
len,
uniformValuePtr_->integrate(x1, x2)
)
);
);
return this->transform(tfld);
}
......
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