DAResidualSolidDisplacementFoam.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(DAResidualSolidDisplacementFoam, 0);
16 addToRunTimeSelectionTable(DAResidual, DAResidualSolidDisplacementFoam, dictionary);
17 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
18 
20  const word modelType,
21  const fvMesh& mesh,
22  const DAOption& daOption,
23  const DAModel& daModel,
24  const DAIndex& daIndex)
25  : DAResidual(modelType, mesh, daOption, daModel, daIndex),
26  // initialize and register state variables and their residuals, we use macros defined in macroFunctions.H
27  setResidualClassMemberVector(D, dimensionSet(0, 1, -2, 0, 0, 0, 0)),
28  // these are intermediate variables or objects
29  gradD_(const_cast<volTensorField&>(
30  mesh.thisDb().lookupObject<volTensorField>("gradD"))),
31  lambda_(const_cast<volScalarField&>(
32  mesh.thisDb().lookupObject<volScalarField>("solid:lambda"))),
33  mu_(const_cast<volScalarField&>(
34  mesh.thisDb().lookupObject<volScalarField>("solid:mu")))
35 {
36 }
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
40 {
41  /*
42  Description:
43  Clear all members to avoid memory leak because we will initalize
44  multiple objects of DAResidual. Here we need to delete all members
45  in the parent and child classes
46  */
47  DRes_.clear();
48 }
49 
50 void DAResidualSolidDisplacementFoam::calcResiduals(const dictionary& options)
51 {
52  /*
53  Description:
54  This is the function to compute residuals.
55 
56  Input:
57  options.isPC: 1 means computing residuals for preconditioner matrix.
58  This essentially use the first order scheme for div(phi,U), div(phi,e)
59 
60  p_, T_, U_, phi_, etc: State variables in OpenFOAM
61 
62  Output:
63  URes_, pRes_, TRes_, phiRes_: residual field variables
64  */
65 
66  volSymmTensorField sigmaD = mu_ * twoSymm(gradD_) + (lambda_ * I) * tr(gradD_);
67 
68  volVectorField divSigmaExp = fvc::div(sigmaD - (2 * mu_ + lambda_) * gradD_, "div(sigmaD)");
69 
70  fvVectorMatrix DEqn(
71  fvm::d2dt2(D_)
72  == fvm::laplacian(2 * mu_ + lambda_, D_, "laplacian(DD,D)")
73  + divSigmaExp);
74 
75  DRes_ = DEqn & D_;
76  normalizeResiduals(DRes);
77 }
78 
80 {
81  /*
82  Description:
83  Update the intermediate variables that depend on the state variables
84  */
85 
86  gradD_ = fvc::grad(D_);
87 }
88 
90 {
91  /*
92  Description:
93  Update the boundary condition for all the states in the selected solver
94  */
95 
96  D_.correctBoundaryConditions();
97 }
98 
99 } // End namespace Foam
100 
101 // ************************************************************************* //
Foam::DAResidualSolidDisplacementFoam::D_
volVectorField & D_
Definition: DAResidualSolidDisplacementFoam.H:33
D
volVectorField & D
Definition: createRefsSolidDisplacement.H:8
Foam::DAResidualSolidDisplacementFoam::clear
virtual void clear()
clear the members
Definition: DAResidualSolidDisplacementFoam.C:39
Foam::DAOption
Definition: DAOption.H:29
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(DAFunction, DAFunctionForce, dictionary)
Foam::DAResidualSolidDisplacementFoam::updateIntermediateVariables
virtual void updateIntermediateVariables()
update any intermediate variables that are dependent on state variables and are used in calcResiduals
Definition: DAResidualSolidDisplacementFoam.C:79
Foam::DAResidualSolidDisplacementFoam::calcResiduals
virtual void calcResiduals(const dictionary &options)
compute residual
Definition: DAResidualSolidDisplacementFoam.C:50
normalizeResiduals
#define normalizeResiduals(resName)
Definition: DAMacroFunctions.H:28
mesh
fvMesh & mesh
Definition: createRefsHeatTransfer.H:4
Foam::DAIndex
Definition: DAIndex.H:32
setResidualClassMemberVector
#define setResidualClassMemberVector(stateName, stateUnit)
Definition: DAMacroFunctions.H:68
Foam::DAModel
Definition: DAModel.H:57
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(DAFunction, 0)
Foam
Definition: checkGeometry.C:32
Foam::DAResidualSolidDisplacementFoam::DRes_
volVectorField DRes_
Definition: DAResidualSolidDisplacementFoam.H:34
Foam::DAResidualSolidDisplacementFoam::DAResidualSolidDisplacementFoam
DAResidualSolidDisplacementFoam(const word modelType, const fvMesh &mesh, const DAOption &daOption, const DAModel &daModel, const DAIndex &daIndex)
Definition: DAResidualSolidDisplacementFoam.C:19
Foam::DAResidual
Definition: DAResidual.H:36
DAResidualSolidDisplacementFoam.H
Foam::DAResidualSolidDisplacementFoam::correctBoundaryConditions
virtual void correctBoundaryConditions()
update the boundary condition for all the states in the selected solver
Definition: DAResidualSolidDisplacementFoam.C:89
Foam::DAResidualSolidDisplacementFoam::lambda_
volScalarField & lambda_
Definition: DAResidualSolidDisplacementFoam.H:37
Foam::DAResidualSolidDisplacementFoam::gradD_
volTensorField & gradD_
Definition: DAResidualSolidDisplacementFoam.H:36
Foam::DAResidualSolidDisplacementFoam::mu_
volScalarField & mu_
Definition: DAResidualSolidDisplacementFoam.H:38