DAResidualSolidDisplacementFoam.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2 
3  DAFoam : Discrete Adjoint with OpenFOAM
4  Version : v3
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  sigmaD_(const_cast<volSymmTensorField&>(
32  mesh.thisDb().lookupObject<volSymmTensorField>("sigmaD"))),
33  divSigmaExp_(const_cast<volVectorField&>(
34  mesh.thisDb().lookupObject<volVectorField>("divSigmaExp"))),
35  lambda_(const_cast<volScalarField&>(
36  mesh.thisDb().lookupObject<volScalarField>("solid:lambda"))),
37  mu_(const_cast<volScalarField&>(
38  mesh.thisDb().lookupObject<volScalarField>("solid:mu")))
39 {
40 
41  IOdictionary thermalProperties(
42  IOobject(
43  "thermalProperties",
44  mesh.time().constant(),
45  mesh,
46  IOobject::MUST_READ,
47  IOobject::NO_WRITE));
48 
49  Switch thermalStress(thermalProperties.lookup("thermalStress"));
50  if (thermalStress)
51  {
52  FatalErrorIn("") << "thermalStress=true not supported" << abort(FatalError);
53  }
54 
55  const dictionary& stressControl = mesh.solutionDict().subDict("stressAnalysis");
56 
57  Switch compactNormalStress(stressControl.lookup("compactNormalStress"));
58 
59  if (!compactNormalStress)
60  {
61  FatalErrorIn("") << "compactNormalStress=false not supported" << abort(FatalError);
62  }
63 
65  forAll(D_.boundaryField(), patchI)
66  {
67  if (D_.boundaryField()[patchI].type() == "tractionDisplacement")
68  {
70  }
71  }
72 }
73 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
74 
76 {
77  /*
78  Description:
79  Clear all members to avoid memory leak because we will initalize
80  multiple objects of DAResidual. Here we need to delete all members
81  in the parent and child classes
82  */
83  DRes_.clear();
84 }
85 
86 void DAResidualSolidDisplacementFoam::calcResiduals(const dictionary& options)
87 {
88  /*
89  Description:
90  This is the function to compute residuals.
91 
92  Input:
93  options.isPC: 1 means computing residuals for preconditioner matrix.
94  This essentially use the first order scheme for div(phi,U), div(phi,e)
95 
96  p_, T_, U_, phi_, etc: State variables in OpenFOAM
97 
98  Output:
99  URes_, pRes_, TRes_, phiRes_: residual field variables
100  */
101 
102  fvVectorMatrix DEqn(
103  fvm::d2dt2(D_)
104  == fvm::laplacian(2 * mu_ + lambda_, D_, "laplacian(DD,D)")
105  + divSigmaExp_);
106 
107  DRes_ = DEqn & D_;
108  normalizeResiduals(DRes);
109 }
110 
112 {
113  /*
114  Description:
115  Update D and gradD.
116 
117  NOTE: we need to update D boundary conditions iteratively if tractionDisplacement BC
118  is used this is because tractionDisplacement BC is dependent on gradD, while gradD
119  is dependent on the D bc values.
120  */
121 
122  // this will be called after doing perturbStates
124  {
125  for (label i = 0; i < daOption_.getOption<label>("maxTractionBCIters"); i++)
126  {
127  D_.correctBoundaryConditions();
128  gradD_ = fvc::grad(D_);
129  }
130  }
131  else
132  {
133  D_.correctBoundaryConditions();
134  gradD_ = fvc::grad(D_);
135  }
136 }
137 
139 {
140  /*
141  Description:
142  Update the intermediate variables that depend on the state variables
143  */
144 
145  this->updateDAndGradD();
146 
147  sigmaD_ = mu_ * twoSymm(gradD_) + (lambda_ * I) * tr(gradD_);
148 
149  divSigmaExp_ = fvc::div(sigmaD_ - (2 * mu_ + lambda_) * gradD_, "div(sigmaD)");
150 }
151 
153 {
154  /*
155  Description:
156  Update the boundary condition for all the states in the selected solver
157  */
158 
159  D_.correctBoundaryConditions();
160 }
161 
162 } // End namespace Foam
163 
164 // ************************************************************************* //
Foam::DAResidualSolidDisplacementFoam::D_
volVectorField & D_
Definition: DAResidualSolidDisplacementFoam.H:33
forAll
forAll(pseudoP.boundaryField(), patchI)
Definition: solvePseudoPEqn.H:10
D
volVectorField & D
Definition: createRefsSolidDisplacement.H:8
Foam::DAResidualSolidDisplacementFoam::clear
virtual void clear()
clear the members
Definition: DAResidualSolidDisplacementFoam.C:75
Foam::DAOption
Definition: DAOption.H:29
Foam::DAResidualSolidDisplacementFoam::updateIntermediateVariables
virtual void updateIntermediateVariables()
update any intermediate variables that are dependent on state variables and are used in calcResiduals
Definition: DAResidualSolidDisplacementFoam.C:138
daOption
DAOption daOption(mesh, pyOptions_)
Foam::DAResidualSolidDisplacementFoam::calcResiduals
virtual void calcResiduals(const dictionary &options)
compute residual
Definition: DAResidualSolidDisplacementFoam.C:86
normalizeResiduals
#define normalizeResiduals(resName)
Definition: DAMacroFunctions.H:28
Foam::DAOption::getOption
classType getOption(const word key) const
get an option from subDict and key
Definition: DAOption.H:92
Foam::DAResidual::daOption_
const DAOption & daOption_
DAOption object.
Definition: DAResidual.H:50
mesh
fvMesh & mesh
Definition: createRefsHeatTransfer.H:4
Foam::DAResidualSolidDisplacementFoam::updateDAndGradD
void updateDAndGradD()
Definition: DAResidualSolidDisplacementFoam.C:111
Foam::DAIndex
Definition: DAIndex.H:32
setResidualClassMemberVector
#define setResidualClassMemberVector(stateName, stateUnit)
Definition: DAMacroFunctions.H:68
Foam::DAModel
Definition: DAModel.H:59
Foam
Definition: multiFreqScalarFvPatchField.C:144
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:35
Foam::DAResidualSolidDisplacementFoam::sigmaD_
volSymmTensorField & sigmaD_
Definition: DAResidualSolidDisplacementFoam.H:38
DAResidualSolidDisplacementFoam.H
Foam::DAResidualSolidDisplacementFoam::isTractionDisplacementBC_
label isTractionDisplacementBC_
Definition: DAResidualSolidDisplacementFoam.H:43
Foam::DAResidualSolidDisplacementFoam::correctBoundaryConditions
virtual void correctBoundaryConditions()
update the boundary condition for all the states in the selected solver
Definition: DAResidualSolidDisplacementFoam.C:152
Foam::DAResidualSolidDisplacementFoam::divSigmaExp_
volVectorField & divSigmaExp_
Definition: DAResidualSolidDisplacementFoam.H:39
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(DAFvSource, 0)
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(DAFvSource, DAFvSourceActuatorDisk, dictionary)
Foam::DAResidualSolidDisplacementFoam::lambda_
volScalarField & lambda_
Definition: DAResidualSolidDisplacementFoam.H:40
Foam::DAResidualSolidDisplacementFoam::gradD_
volTensorField & gradD_
Definition: DAResidualSolidDisplacementFoam.H:37
Foam::DAResidualSolidDisplacementFoam::mu_
volScalarField & mu_
Definition: DAResidualSolidDisplacementFoam.H:41
daModel
DAModel daModel(mesh, daOption)
stressControl
const dictionary & stressControl
Definition: createControlsSolidDisplacement.H:1
daIndex
DAIndex daIndex(mesh, daOption, daModel)