DAFoam
v4.0.2
Discrete Adjoint with OpenFOAM
dafoam
src
adjoint
DATimeOp
DATimeOpMaxKS.C
Go to the documentation of this file.
1
/*---------------------------------------------------------------------------*\
2
3
DAFoam : Discrete Adjoint with OpenFOAM
4
Version : v4
5
6
\*---------------------------------------------------------------------------*/
7
8
#include "
DATimeOpMaxKS.H
"
9
10
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
11
12
namespace
Foam
13
{
14
15
defineTypeNameAndDebug
(DATimeOpMaxKS, 0);
16
addToRunTimeSelectionTable
(DATimeOp, DATimeOpMaxKS, dictionary);
17
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
18
19
DATimeOpMaxKS::DATimeOpMaxKS
(
20
const
word timeOpType,
21
const
dictionary options)
22
:
DATimeOp
(timeOpType, options)
23
{
24
coeffKS_
= options.getScalar(
"coeffKS"
);
25
}
26
27
scalar
DATimeOpMaxKS::compute
(
28
const
scalarList& valList,
29
const
label iStart,
30
const
label iEnd)
31
{
32
// return the estimated max value from valList
33
// KS = log( sum( exp(x_i*c) ) )/c
34
scalar maxKS = 0.0;
35
// NOTE. We need to use <= here
36
for
(label i = iStart; i <= iEnd; i++)
37
{
38
maxKS += exp(
coeffKS_
* valList[i]);
39
}
40
if
(maxKS > 1e200)
41
{
42
FatalErrorIn(
" "
) <<
"KS function summation term too large! "
43
<<
"Reduce coeffKS! "
<< abort(FatalError);
44
}
45
maxKS = log(maxKS) /
coeffKS_
;
46
return
maxKS;
47
}
48
49
scalar
DATimeOpMaxKS::dFScaling
(
50
const
scalarList& valList,
51
const
label iStart,
52
const
label iEnd,
53
const
label timeIdx)
54
{
55
// F = log( sum( exp(f_i*c) ) )/c
56
// dF/dx = 1/(sum(exp(f_i*c))) * exp(f_i*c) * df_i/dx
57
// so the scaling is 1/(sum(exp(f_i*c))) * exp(f_i*c)
58
// NOTE: the scaling depends on timeIdx!
59
60
scalar sum = 0.0;
61
for
(label i = iStart; i <= iEnd; i++)
62
{
63
sum += exp(
coeffKS_
* valList[i]);
64
}
65
scalar scaling = 1.0 / sum * exp(valList[timeIdx] *
coeffKS_
);
66
67
return
scaling;
68
}
69
70
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
71
72
}
// End namespace Foam
73
74
// ************************************************************************* //
Foam::DATimeOpMaxKS::DATimeOpMaxKS
DATimeOpMaxKS(const word timeOpType, const dictionary options)
Definition:
DATimeOpMaxKS.C:19
Foam::DATimeOpMaxKS::coeffKS_
scalar coeffKS_
the KS coefficient
Definition:
DATimeOpMaxKS.H:35
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(DAFunction, DAFunctionForce, dictionary)
DATimeOpMaxKS.H
Foam::DATimeOp
Definition:
DATimeOp.H:27
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(DAFunction, 0)
Foam
Definition:
checkGeometry.C:32
Foam::DATimeOpMaxKS::compute
virtual scalar compute(const scalarList &valList, const label iStart, const label iEnd)
compute the timeOp value based on valList
Definition:
DATimeOpMaxKS.C:27
Foam::DATimeOpMaxKS::dFScaling
virtual scalar dFScaling(const scalarList &valList, const label iStart, const label iEnd, const label timeIdx)
compute the scaling factor for dF/d? calculation.
Definition:
DATimeOpMaxKS.C:49
Generated by
1.8.17