Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
12License
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// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35namespace Foam
36{
37
38// * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * * //
39
42(
43 topOInterpolationFunction,
44 smoothHeaviside,
46);
47
48// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
49
50smoothHeaviside::smoothHeaviside
51(
52 const fvMesh& mesh,
53 const dictionary& dict
54)
55:
56 topOInterpolationFunction(mesh, dict),
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// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition Function1.H:92
scalar timeOutputValue() const
Return the current user-time value. (ie, after applying any timeToUserTime() conversion).
Definition TimeStateI.H:24
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
const Time & time() const
Return the top-level database.
Definition fvMesh.H:360
A smooth Heaviside function to project the signed distance field in level set topology optimization.
virtual tmp< scalarField > derivative(const scalarField &arg) const
Return of function with respect to the argument field.
virtual void interpolate(const scalarField &arg, scalarField &res) const
Interpolate argument to result.
autoPtr< Function1< scalar > > b_
A class for managing temporary objects.
Definition tmp.H:75
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Definition tmp.H:215
T & ref() const
Return non-const reference to the contents of a non-null managed pointer.
Definition tmpI.H:235
static autoPtr< topOInterpolationFunction > New(const fvMesh &mesh, const dictionary &dict)
Return an autoPtr to the selected interpolation type.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
dynamicFvMesh & mesh
Namespace for OpenFOAM.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
dimensionedScalar tanh(const dimensionedScalar &ds)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
dictionary dict
volScalarField & b