smoothHeaviside.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) 2007-2019 PCOpt/NTUA
9  Copyright (C) 2013-2019 FOSS GP
10  Copyright (C) 2019 OpenCFD Ltd.
11 -------------------------------------------------------------------------------
12 License
13  This file is part of OpenFOAM.
14 
15  OpenFOAM is free software: you can redistribute it and/or modify it
16  under the terms of the GNU General Public License as published by
17  the Free Software Foundation, either version 3 of the License, or
18  (at your option) any later version.
19 
20  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
21  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23  for more details.
24 
25  You should have received a copy of the GNU General Public License
26  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
27 
28 \*---------------------------------------------------------------------------*/
29 
30 #include "smoothHeaviside.H"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 
38 // * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * * //
39 
40 defineTypeNameAndDebug(smoothHeaviside, 0);
42 (
46 );
47 
48 // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
49 
50 smoothHeaviside::smoothHeaviside
51 (
52  const fvMesh& mesh,
53  const dictionary& dict
54 )
55 :
57  b_(Function1<scalar>::New("b", dict))
58 {}
59 
60 
61 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
62 
64 (
65  const scalarField& arg,
66  scalarField& res
67 ) const
68 {
69  const scalar timeValue = mesh_.time().timeOutputValue();
70  const scalar t(timeValue == 0 ? 1. : timeValue);
71  const scalar b(b_->value(t));
72  res = 0.5*(scalar(1) + tanh(b*arg));
73 }
74 
75 
77 {
79  scalarField& deriv = tderiv.ref();
80  const scalar timeValue = mesh_.time().timeOutputValue();
81  const scalar t(timeValue == 0 ? 1. : timeValue);
82  const scalar b(b_->value(t));
83 
84  deriv = 0.5*b*(scalar(1) - sqr(tanh(b*arg)));
85 
86  return tderiv;
87 }
88 
89 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
90 
91 } // End namespace Foam
92 
93 // ************************************************************************* //
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)
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.
autoPtr< Function1< scalar > > b_
A smooth Heaviside function to project the signed distance field in level set topology optimization...
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:360
Macros for easy insertion into run-time selection tables.
dynamicFvMesh & mesh
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
virtual tmp< scalarField > derivative(const scalarField &arg) const
Return of function with respect to the argument field.
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Definition: tmp.H:206
virtual void interpolate(const scalarField &arg, scalarField &res) const
Interpolate argument to result.
defineTypeNameAndDebug(combustionModel, 0)
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
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127