mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Rename DataEntry -> Function1
Function1 is an abstract base-class of run-time selectable unary functions which may be composed of other Function1's allowing the user to specify complex functions of a single scalar variable, e.g. time. The implementations need not be a simple or continuous functions; interpolated tables and polynomials are also supported. In fact form of mapping between a single scalar input and a single primitive type output is supportable. The primary application of Function1 is in time-varying boundary conditions, it also used for other functions of time, e.g. injected mass is spray simulations but is not limited to functions of time.
This commit is contained in:
60
src/OpenFOAM/primitives/functions/Function1/Table/Table.C
Normal file
60
src/OpenFOAM/primitives/functions/Function1/Table/Table.C
Normal file
@ -0,0 +1,60 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 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 "Table.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
Foam::Function1Types::Table<Type>::Table
|
||||
(
|
||||
const word& entryName,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
TableBase<Type>(entryName, dict)
|
||||
{
|
||||
Istream& is(dict.lookup(entryName));
|
||||
word entryType(is);
|
||||
is >> this->table_;
|
||||
TableBase<Type>::check();
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::Function1Types::Table<Type>::Table(const Table<Type>& tbl)
|
||||
:
|
||||
TableBase<Type>(tbl)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
Foam::Function1Types::Table<Type>::~Table()
|
||||
{}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
124
src/OpenFOAM/primitives/functions/Function1/Table/Table.H
Normal file
124
src/OpenFOAM/primitives/functions/Function1/Table/Table.H
Normal file
@ -0,0 +1,124 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 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::Function1Types::Table
|
||||
|
||||
Description
|
||||
Templated table container data entry. Items are stored in a list of
|
||||
Tuple2's. First column is always stored as scalar entries. Data is read
|
||||
in Tuple2 form, e.g. for an entry \<entryName\> that is (scalar, vector):
|
||||
|
||||
\verbatim
|
||||
<entryName> table
|
||||
(
|
||||
(0.0 (1 2 3))
|
||||
(1.0 (4 5 6))
|
||||
);
|
||||
\endverbatim
|
||||
|
||||
SourceFiles
|
||||
Table.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef Table_H
|
||||
#define Table_H
|
||||
|
||||
#include "Function1.H"
|
||||
#include "Tuple2.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
namespace Function1Types
|
||||
{
|
||||
template<class Type> class Table;
|
||||
};
|
||||
|
||||
template<class Type>
|
||||
Ostream& operator<<(Ostream&, const Function1Types::Table<Type>&);
|
||||
|
||||
namespace Function1Types
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class Table Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
template<class Type>
|
||||
class Table
|
||||
:
|
||||
public TableBase<Type>
|
||||
{
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const Table<Type>&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("table");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from entry name and Istream
|
||||
Table(const word& entryName, const dictionary& dict);
|
||||
|
||||
//- Copy constructor
|
||||
Table(const Table<Type>& tbl);
|
||||
|
||||
//- Construct and return a clone
|
||||
virtual tmp<Function1<Type>> clone() const
|
||||
{
|
||||
return tmp<Function1<Type>>(new Table<Type>(*this));
|
||||
}
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~Table();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Function1Types
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
# include "Table.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
413
src/OpenFOAM/primitives/functions/Function1/Table/TableBase.C
Normal file
413
src/OpenFOAM/primitives/functions/Function1/Table/TableBase.C
Normal file
@ -0,0 +1,413 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 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 "TableBase.H"
|
||||
#include "Time.H"
|
||||
#include "interpolationWeights.H"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
const Foam::interpolationWeights&
|
||||
Foam::Function1Types::TableBase<Type>::interpolator() const
|
||||
{
|
||||
if (interpolatorPtr_.empty())
|
||||
{
|
||||
// Re-work table into linear list
|
||||
tableSamplesPtr_.reset(new scalarField(table_.size()));
|
||||
scalarField& tableSamples = tableSamplesPtr_();
|
||||
forAll(table_, i)
|
||||
{
|
||||
tableSamples[i] = table_[i].first();
|
||||
}
|
||||
interpolatorPtr_ = interpolationWeights::New
|
||||
(
|
||||
interpolationScheme_,
|
||||
tableSamples
|
||||
);
|
||||
}
|
||||
|
||||
return interpolatorPtr_();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
Foam::Function1Types::TableBase<Type>::TableBase
|
||||
(
|
||||
const word& name,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
Function1<Type>(name),
|
||||
name_(name),
|
||||
boundsHandling_
|
||||
(
|
||||
wordToBoundsHandling
|
||||
(
|
||||
dict.lookupOrDefault<word>("outOfBounds", "clamp")
|
||||
)
|
||||
),
|
||||
interpolationScheme_
|
||||
(
|
||||
dict.lookupOrDefault<word>("interpolationScheme", "linear")
|
||||
),
|
||||
table_()
|
||||
{}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::Function1Types::TableBase<Type>::TableBase(const TableBase<Type>& tbl)
|
||||
:
|
||||
Function1<Type>(tbl),
|
||||
name_(tbl.name_),
|
||||
boundsHandling_(tbl.boundsHandling_),
|
||||
interpolationScheme_(tbl.interpolationScheme_),
|
||||
table_(tbl.table_),
|
||||
tableSamplesPtr_(tbl.tableSamplesPtr_),
|
||||
interpolatorPtr_(tbl.interpolatorPtr_)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
Foam::Function1Types::TableBase<Type>::~TableBase()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
Foam::word Foam::Function1Types::TableBase<Type>::boundsHandlingToWord
|
||||
(
|
||||
const boundsHandling& bound
|
||||
) const
|
||||
{
|
||||
word enumName("warn");
|
||||
|
||||
switch (bound)
|
||||
{
|
||||
case ERROR:
|
||||
{
|
||||
enumName = "error";
|
||||
break;
|
||||
}
|
||||
case WARN:
|
||||
{
|
||||
enumName = "warn";
|
||||
break;
|
||||
}
|
||||
case CLAMP:
|
||||
{
|
||||
enumName = "clamp";
|
||||
break;
|
||||
}
|
||||
case REPEAT:
|
||||
{
|
||||
enumName = "repeat";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return enumName;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
typename Foam::Function1Types::TableBase<Type>::boundsHandling
|
||||
Foam::Function1Types::TableBase<Type>::wordToBoundsHandling
|
||||
(
|
||||
const word& bound
|
||||
) const
|
||||
{
|
||||
if (bound == "error")
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
else if (bound == "warn")
|
||||
{
|
||||
return WARN;
|
||||
}
|
||||
else if (bound == "clamp")
|
||||
{
|
||||
return CLAMP;
|
||||
}
|
||||
else if (bound == "repeat")
|
||||
{
|
||||
return REPEAT;
|
||||
}
|
||||
else
|
||||
{
|
||||
WarningInFunction
|
||||
<< "bad outOfBounds specifier " << bound << " using 'warn'"
|
||||
<< endl;
|
||||
|
||||
return WARN;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
typename Foam::Function1Types::TableBase<Type>::boundsHandling
|
||||
Foam::Function1Types::TableBase<Type>::outOfBounds
|
||||
(
|
||||
const boundsHandling& bound
|
||||
)
|
||||
{
|
||||
boundsHandling prev = boundsHandling_;
|
||||
boundsHandling_ = bound;
|
||||
|
||||
return prev;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::Function1Types::TableBase<Type>::check() const
|
||||
{
|
||||
if (!table_.size())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Table for entry " << this->name_ << " is invalid (empty)"
|
||||
<< nl << exit(FatalError);
|
||||
}
|
||||
|
||||
label n = table_.size();
|
||||
scalar prevValue = table_[0].first();
|
||||
|
||||
for (label i = 1; i < n; ++i)
|
||||
{
|
||||
const scalar currValue = table_[i].first();
|
||||
|
||||
// avoid duplicate values (divide-by-zero error)
|
||||
if (currValue <= prevValue)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "out-of-order value: " << currValue << " at index " << i
|
||||
<< exit(FatalError);
|
||||
}
|
||||
prevValue = currValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
bool Foam::Function1Types::TableBase<Type>::checkMinBounds
|
||||
(
|
||||
const scalar x,
|
||||
scalar& xDash
|
||||
) const
|
||||
{
|
||||
if (x < table_[0].first())
|
||||
{
|
||||
switch (boundsHandling_)
|
||||
{
|
||||
case ERROR:
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "value (" << x << ") underflow"
|
||||
<< exit(FatalError);
|
||||
break;
|
||||
}
|
||||
case WARN:
|
||||
{
|
||||
WarningInFunction
|
||||
<< "value (" << x << ") underflow" << nl
|
||||
<< endl;
|
||||
|
||||
// fall-through to 'CLAMP'
|
||||
}
|
||||
case CLAMP:
|
||||
{
|
||||
xDash = table_[0].first();
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
case REPEAT:
|
||||
{
|
||||
// adjust x to >= minX
|
||||
scalar span = table_.last().first() - table_[0].first();
|
||||
xDash = fmod(x - table_[0].first(), span) + table_[0].first();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
xDash = x;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
bool Foam::Function1Types::TableBase<Type>::checkMaxBounds
|
||||
(
|
||||
const scalar x,
|
||||
scalar& xDash
|
||||
) const
|
||||
{
|
||||
if (x > table_.last().first())
|
||||
{
|
||||
switch (boundsHandling_)
|
||||
{
|
||||
case ERROR:
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "value (" << x << ") overflow"
|
||||
<< exit(FatalError);
|
||||
break;
|
||||
}
|
||||
case WARN:
|
||||
{
|
||||
WarningInFunction
|
||||
<< "value (" << x << ") overflow" << nl
|
||||
<< endl;
|
||||
|
||||
// fall-through to 'CLAMP'
|
||||
}
|
||||
case CLAMP:
|
||||
{
|
||||
xDash = table_.last().first();
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
case REPEAT:
|
||||
{
|
||||
// adjust x to >= minX
|
||||
scalar span = table_.last().first() - table_[0].first();
|
||||
xDash = fmod(x - table_[0].first(), span) + table_[0].first();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
xDash = x;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::Function1Types::TableBase<Type>::convertTimeBase(const Time& t)
|
||||
{
|
||||
forAll(table_, i)
|
||||
{
|
||||
scalar value = table_[i].first();
|
||||
table_[i].first() = t.userTimeToTime(value);
|
||||
}
|
||||
|
||||
tableSamplesPtr_.clear();
|
||||
interpolatorPtr_.clear();
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Type Foam::Function1Types::TableBase<Type>::value(const scalar x) const
|
||||
{
|
||||
scalar xDash = x;
|
||||
|
||||
if (checkMinBounds(x, xDash))
|
||||
{
|
||||
return table_[0].second();
|
||||
}
|
||||
|
||||
if (checkMaxBounds(xDash, xDash))
|
||||
{
|
||||
return table_.last().second();
|
||||
}
|
||||
|
||||
// Use interpolator
|
||||
interpolator().valueWeights(xDash, currentIndices_, currentWeights_);
|
||||
|
||||
Type t = currentWeights_[0]*table_[currentIndices_[0]].second();
|
||||
for (label i = 1; i < currentIndices_.size(); i++)
|
||||
{
|
||||
t += currentWeights_[i]*table_[currentIndices_[i]].second();
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Type Foam::Function1Types::TableBase<Type>::integrate
|
||||
(
|
||||
const scalar x1,
|
||||
const scalar x2
|
||||
) const
|
||||
{
|
||||
// Use interpolator
|
||||
interpolator().integrationWeights(x1, x2, currentIndices_, currentWeights_);
|
||||
|
||||
Type sum = currentWeights_[0]*table_[currentIndices_[0]].second();
|
||||
for (label i = 1; i < currentIndices_.size(); i++)
|
||||
{
|
||||
sum += currentWeights_[i]*table_[currentIndices_[i]].second();
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::tmp<Foam::scalarField> Foam::Function1Types::TableBase<Type>::x() const
|
||||
{
|
||||
tmp<scalarField> tfld(new scalarField(table_.size(), 0.0));
|
||||
scalarField& fld = tfld();
|
||||
|
||||
forAll(table_, i)
|
||||
{
|
||||
fld[i] = table_[i].first();
|
||||
}
|
||||
|
||||
return tfld;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::tmp<Foam::Field<Type>> Foam::Function1Types::TableBase<Type>::y() const
|
||||
{
|
||||
tmp<Field<Type>> tfld(new Field<Type>(table_.size(), pTraits<Type>::zero));
|
||||
Field<Type>& fld = tfld();
|
||||
|
||||
forAll(table_, i)
|
||||
{
|
||||
fld[i] = table_[i].second();
|
||||
}
|
||||
|
||||
return tfld;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
|
||||
|
||||
#include "TableBaseIO.C"
|
||||
|
||||
// ************************************************************************* //
|
||||
204
src/OpenFOAM/primitives/functions/Function1/Table/TableBase.H
Normal file
204
src/OpenFOAM/primitives/functions/Function1/Table/TableBase.H
Normal file
@ -0,0 +1,204 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 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::Function1Types::TableBase
|
||||
|
||||
Description
|
||||
Base class for table with bounds handling, interpolation and integration
|
||||
|
||||
SourceFiles
|
||||
TableBase.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef TableBase_H
|
||||
#define TableBase_H
|
||||
|
||||
#include "Function1.H"
|
||||
#include "Tuple2.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
class interpolationWeights;
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
namespace Function1Types
|
||||
{
|
||||
template<class Type> class TableBase;
|
||||
};
|
||||
|
||||
template<class Type>
|
||||
Ostream& operator<<(Ostream&, const Function1Types::TableBase<Type>&);
|
||||
|
||||
namespace Function1Types
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class TableBase Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
template<class Type>
|
||||
class TableBase
|
||||
:
|
||||
public Function1<Type>
|
||||
{
|
||||
public:
|
||||
|
||||
// Public data types
|
||||
|
||||
//- Enumeration for handling out-of-bound values
|
||||
enum boundsHandling
|
||||
{
|
||||
ERROR, /*!< Exit with a FatalError */
|
||||
WARN, /*!< Issue warning and clamp value (default) */
|
||||
CLAMP, /*!< Clamp value to the start/end value */
|
||||
REPEAT /*!< Treat as a repeating list */
|
||||
};
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Table name
|
||||
const word name_;
|
||||
|
||||
//- Enumeration for handling out-of-bound values
|
||||
const boundsHandling boundsHandling_;
|
||||
|
||||
//- Interpolation type
|
||||
const word interpolationScheme_;
|
||||
|
||||
//- Table data
|
||||
List<Tuple2<scalar, Type>> table_;
|
||||
|
||||
//- Extracted values
|
||||
mutable autoPtr<scalarField> tableSamplesPtr_;
|
||||
|
||||
//- Interpolator method
|
||||
mutable autoPtr<interpolationWeights> interpolatorPtr_;
|
||||
|
||||
//- Cached indices and weights
|
||||
mutable labelList currentIndices_;
|
||||
|
||||
mutable scalarField currentWeights_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Return (demand driven) interpolator
|
||||
const interpolationWeights& interpolator() const;
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const TableBase<Type>&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary - note table is not populated
|
||||
TableBase(const word& name, const dictionary& dict);
|
||||
|
||||
//- Copy constructor. Note: steals interpolator, tableSamples
|
||||
TableBase(const TableBase<Type>& tbl);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~TableBase();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Return the out-of-bounds handling as a word
|
||||
word boundsHandlingToWord(const boundsHandling& bound) const;
|
||||
|
||||
//- Return the out-of-bounds handling as an enumeration
|
||||
boundsHandling wordToBoundsHandling(const word& bound) const;
|
||||
|
||||
//- Set the out-of-bounds handling from enum, return previous setting
|
||||
boundsHandling outOfBounds(const boundsHandling& bound);
|
||||
|
||||
//- Check the table for size and consistency
|
||||
void check() const;
|
||||
|
||||
//- Check minimum table bounds
|
||||
bool checkMinBounds(const scalar x, scalar& xDash) const;
|
||||
|
||||
//- Check maximum table bounds
|
||||
bool checkMaxBounds(const scalar x, scalar& xDash) const;
|
||||
|
||||
//- Convert time
|
||||
virtual void convertTimeBase(const Time& t);
|
||||
|
||||
//- Return Table value
|
||||
virtual Type value(const scalar x) const;
|
||||
|
||||
//- Integrate between two (scalar) values
|
||||
virtual Type integrate(const scalar x1, const scalar x2) const;
|
||||
|
||||
//- Return the reference values
|
||||
virtual tmp<scalarField> x() const;
|
||||
|
||||
//- Return the dependent values
|
||||
virtual tmp<Field<Type>> y() const;
|
||||
|
||||
|
||||
// I/O
|
||||
|
||||
//- Ostream Operator
|
||||
friend Ostream& operator<< <Type>
|
||||
(
|
||||
Ostream& os,
|
||||
const TableBase<Type>& tbl
|
||||
);
|
||||
|
||||
//- Write all table data in dictionary format
|
||||
virtual void writeData(Ostream& os) const;
|
||||
|
||||
//- Write keywords only in dictionary format. Used for non-inline
|
||||
// table types
|
||||
virtual void writeEntries(Ostream& os) const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Function1Types
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
# include "TableBase.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,75 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 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 "Function1.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
Foam::Ostream& Foam::operator<<
|
||||
(
|
||||
Ostream& os,
|
||||
const Function1Types::TableBase<Type>& tbl
|
||||
)
|
||||
{
|
||||
os << static_cast<const Function1<Type>&>(tbl);
|
||||
os << token::SPACE << tbl.table_;
|
||||
|
||||
// Check state of Ostream
|
||||
os.check
|
||||
(
|
||||
"Ostream& operator<<(Ostream&, const TableBase<Type>&, const bool)"
|
||||
);
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::Function1Types::TableBase<Type>::writeData(Ostream& os) const
|
||||
{
|
||||
Function1<Type>::writeData(os);
|
||||
os << nl << indent << table_ << token::END_STATEMENT << nl;
|
||||
writeEntries(os);
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::Function1Types::TableBase<Type>::writeEntries(Ostream& os) const
|
||||
{
|
||||
if (boundsHandling_ != CLAMP)
|
||||
{
|
||||
os.writeKeyword("outOfBounds") << boundsHandlingToWord(boundsHandling_)
|
||||
<< token::END_STATEMENT << nl;
|
||||
}
|
||||
if (interpolationScheme_ != "linear")
|
||||
{
|
||||
os.writeKeyword("interpolationScheme") << interpolationScheme_
|
||||
<< token::END_STATEMENT << nl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user