DAFunctionVonMisesStressKS.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2 
3  DAFoam : Discrete Adjoint with OpenFOAM
4  Version : v4
5 
6 \*---------------------------------------------------------------------------*/
7 
9 
10 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
11 
12 namespace Foam
13 {
14 
15 defineTypeNameAndDebug(DAFunctionVonMisesStressKS, 0);
16 addToRunTimeSelectionTable(DAFunction, DAFunctionVonMisesStressKS, dictionary);
17 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
18 
20  const fvMesh& mesh,
21  const DAOption& daOption,
22  const DAModel& daModel,
23  const DAIndex& daIndex,
24  const word functionName)
25  : DAFunction(
26  mesh,
27  daOption,
28  daModel,
29  daIndex,
30  functionName)
31 {
32 
33  functionDict_.readEntry<scalar>("coeffKS", coeffKS_);
34 }
35 
38 {
39  /*
40  Description:
41  Calculate the maximal von Mises stress aggregated using the KS function
42  von Mises stress = KS( mu*twoSymm(fvc::grad(D)) + lambda*(I*tr(fvc::grad(D))) )
43  where the KS function KS(x) = 1/coeffKS * ln( sum[exp(coeffKS*x_i)] )
44  */
45 
46  scalar functionValue = 0.0;
47 
48  const objectRegistry& db = mesh_.thisDb();
49  const volTensorField& gradD = db.lookupObject<volTensorField>("gradD");
50  const volScalarField& lambda = db.lookupObject<volScalarField>("solid:lambda");
51  const volScalarField& mu = db.lookupObject<volScalarField>("solid:mu");
52  const volScalarField& rho = db.lookupObject<volScalarField>("solid:rho");
53 
54  // volTensorField gradD(fvc::grad(D));
55  volSymmTensorField sigma = rho * (mu * twoSymm(gradD) + (lambda * I) * tr(gradD));
56 
57  // NOTE: vonMises stress is scaled by scale_ provided in the function dict
58  volScalarField vonMises = scale_ * sqrt((3.0 / 2.0) * magSqr(dev(sigma)));
59 
60  scalar objValTmp = 0.0;
61  forAll(cellSources_, idxI)
62  {
63  const label& cellI = cellSources_[idxI];
64 
65  objValTmp += exp(coeffKS_ * vonMises[cellI]);
66 
67  if (objValTmp > 1e200)
68  {
69  FatalErrorIn(" ") << "KS function summation term too large! "
70  << "Reduce coeffKS! " << abort(FatalError);
71  }
72  }
73 
74  // need to reduce the sum of force across all processors
75  reduce(objValTmp, sumOp<scalar>());
76 
77  functionValue = log(objValTmp) / coeffKS_;
78 
79  // check if we need to calculate refDiff.
80  this->calcRefVar(functionValue);
81 
82  return functionValue;
83 }
84 
85 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
86 
87 } // End namespace Foam
88 
89 // ************************************************************************* //
mu
volScalarField & mu
Definition: createRefsSolidDisplacement.H:6
Foam::DAFunctionVonMisesStressKS::coeffKS_
scalar coeffKS_
coefficient for the KS function
Definition: DAFunctionVonMisesStressKS.H:32
Foam::DAOption
Definition: DAOption.H:29
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(DAFunction, DAFunctionForce, dictionary)
Foam::DAFunctionVonMisesStressKS::calcFunction
virtual scalar calcFunction()
calculate the value of objective function
Definition: DAFunctionVonMisesStressKS.C:37
Foam::DAFunction::calcRefVar
void calcRefVar(scalar &functionValue)
calculate (var-ref)^2
Definition: DAFunction.C:216
mesh
fvMesh & mesh
Definition: createRefsHeatTransfer.H:4
Foam::DAIndex
Definition: DAIndex.H:32
Foam::DAModel
Definition: DAModel.H:57
Foam::DAFunction
Definition: DAFunction.H:31
sigma
volSymmTensorField sigma(IOobject("sigma", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), rho *sigmaD)
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(DAFunction, 0)
Foam
Definition: checkGeometry.C:32
rho
volScalarField & rho
Definition: createRefsRhoPimple.H:8
forAll
forAll(nuTilda1, cellI)
Definition: nuTilda1EqnIrkPimple.H:19
gradD
volTensorField & gradD
Definition: createRefsSolidDisplacement.H:9
lambda
volScalarField & lambda
Definition: createRefsSolidDisplacement.H:7
Foam::DAFunctionVonMisesStressKS::DAFunctionVonMisesStressKS
DAFunctionVonMisesStressKS(const fvMesh &mesh, const DAOption &daOption, const DAModel &daModel, const DAIndex &daIndex, const word functionName)
Definition: DAFunctionVonMisesStressKS.C:19
Foam::DAFunction::functionDict_
dictionary functionDict_
dictionary containing the information for the objective function
Definition: DAFunction.H:64
Foam::DAFunction::cellSources_
labelList cellSources_
a sorted list of all cell sources for the objective function
Definition: DAFunction.H:70
Foam::DAFunction::scale_
scalar scale_
scale of the objective function
Definition: DAFunction.H:73
DAFunctionVonMisesStressKS.H
Foam::DAFunction::mesh_
const fvMesh & mesh_
fvMesh
Definition: DAFunction.H:43