tanhInterpolation.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2020-2023 PCOpt/NTUA
9  Copyright (C) 2020-2023 FOSS GP
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "tanhInterpolation.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(tanhInterpolation, 0);
38  (
40  tanhInterpolation,
41  dictionary
42  );
43 }
44 
45 
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47 
48 Foam::tanhInterpolation::tanhInterpolation
49 (
50  const fvMesh& mesh,
51  const dictionary& dict
52 )
53 :
55  b_(Function1<scalar>::New("b", dict)),
56  eta_(dict.getOrDefault<scalar>("eta", scalar(0.5)))
57 {}
58 
59 
60 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
61 
63 (
64  const scalarField& arg,
65  scalarField& res
66 ) const
67 {
68  const scalar time(mesh_.time().timeOutputValue());
69  const scalar t(time == 0 ? 1. : time);
70  const scalar b(b_->value(t));
71  if (debug > 1)
72  {
73  Info<< type() << "::interpolate:: t, b value " << t << " " << b
74  << " eta " << eta_ << endl;
75  }
76 
77  res = (tanh(b*eta_) + tanh(b*(arg - eta_)))
78  /(tanh(b*eta_) + tanh(b*(scalar(1) - eta_)));
79 }
80 
81 
83 (
84  const scalarField& arg
85 ) const
86 {
88  scalarField& deriv = tderiv.ref();
89 
90  const scalar t(mesh_.time().timeOutputValue());
91  const scalar b(b_->value(t));
92  DebugInfo
93  << type() << "::interpolate:: t, b value " << t << " " << b
94  << " eta " << eta_ << endl;
95  deriv = b*(scalar(1) - sqr(tanh(b*(arg - eta_))))
96  /(tanh(b*eta_) + tanh(b*(scalar(1) - eta_)));
97 
98  return tderiv;
99 }
100 
101 
102 void Foam::tanhInterpolation::setLengthScaleParam(const scalar lengthScale)
103 {
104  eta_ = lengthScale;
105 }
106 
107 
108 // ************************************************************************* //
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Abstract base class for interpolation functions used in topology optimisation.
dimensionedScalar tanh(const dimensionedScalar &ds)
dictionary dict
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
T & ref() const
Return non-const reference to the contents of a non-null managed pointer.
Definition: tmpI.H:235
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:360
Macros for easy insertion into run-time selection tables.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
dynamicFvMesh & mesh
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
#define DebugInfo
Report an information message using Foam::Info.
virtual tmp< scalarField > derivative(const scalarField &arg) const
Return of function with respect to the argument field.
int debug
Static debugging option.
defineTypeNameAndDebug(combustionModel, 0)
virtual void setLengthScaleParam(const scalar lengthScale)
Set the parameter determining length scale.
scalar timeOutputValue() const
Return the current user-time value. (ie, after applying any timeToUserTime() conversion) ...
Definition: TimeStateI.H:24
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
messageStream Info
Information stream (stdout output on master, null elsewhere)
A class for managing temporary objects.
Definition: HashPtrTable.H:50
virtual void interpolate(const scalarField &arg, scalarField &res) const
Interpolate argument and write to result.
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127