DAMacroFunctions.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2 
3  DAFoam : Discrete Adjoint with OpenFOAM
4  Version : v3
5 
6  Description:
7  Macro functions for DAFoam
8 
9 \*---------------------------------------------------------------------------*/
10 
11 #ifndef DAMacroFunctions_H
12 #define DAMacroFunctions_H
13 
14 // make state
15 #define makeState(regState, fieldType, db) \
16  const word stateName = regState; \
17  fieldType& state( \
18  const_cast<fieldType&>( \
19  db.lookupObject<fieldType>(stateName)));
20 
21 #define makeStateRes(regState, fieldType, db) \
22  const word stateName = regState; \
23  const word stateResName = stateName + "Res"; \
24  fieldType& stateRes( \
25  const_cast<fieldType&>( \
26  db.lookupObject<fieldType>(stateResName)));
27 
28 #define normalizeResiduals(resName) \
29  if (!DAUtility::isInList<word>(#resName, daOption_.getOption<wordList>("normalizeResiduals"))) \
30  { \
31  forAll(resName##_, cellI) \
32  { \
33  resName##_[cellI] *= mesh_.V()[cellI]; \
34  } \
35  }
36 
37 #define normalizePhiResiduals(resName) \
38  if (DAUtility::isInList<word>(#resName, daOption_.getOption<wordList>("normalizeResiduals"))) \
39  { \
40  forAll(resName##_, faceI) \
41  { \
42  resName##_[faceI] /= mesh_.magSf()[faceI]; \
43  } \
44  forAll(resName##_.boundaryField(), patchI) \
45  { \
46  forAll(resName##_.boundaryField()[patchI], faceI) \
47  { \
48  resName##_.boundaryFieldRef()[patchI][faceI] /= mesh_.magSf().boundaryField()[patchI][faceI]; \
49  } \
50  } \
51  }
52 
53 #define setResidualClassMemberScalar(stateName, stateUnit) \
54  stateName##_( \
55  const_cast<volScalarField&>( \
56  mesh.thisDb().lookupObject<volScalarField>(#stateName))), \
57  stateName##Res_( \
58  IOobject( \
59  #stateName "Res", \
60  mesh.time().timeName(), \
61  mesh, \
62  IOobject::NO_READ, \
63  IOobject::NO_WRITE), \
64  mesh, \
65  dimensionedScalar(#stateName "Res", stateUnit, 0.0), \
66  zeroGradientFvPatchField<scalar>::typeName)
67 
68 #define setResidualClassMemberVector(stateName, stateUnit) \
69  stateName##_( \
70  const_cast<volVectorField&>( \
71  mesh.thisDb().lookupObject<volVectorField>(#stateName))), \
72  stateName##Res_( \
73  IOobject( \
74  #stateName "Res", \
75  mesh.time().timeName(), \
76  mesh, \
77  IOobject::NO_READ, \
78  IOobject::NO_WRITE), \
79  mesh, \
80  dimensionedVector(#stateName "Res", stateUnit, vector::zero), \
81  zeroGradientFvPatchField<vector>::typeName)
82 
83 #define setResidualClassMemberPhi(stateName) \
84  stateName##_( \
85  const_cast<surfaceScalarField&>( \
86  mesh.thisDb().lookupObject<surfaceScalarField>(#stateName))), \
87  stateName##Res_( \
88  IOobject( \
89  #stateName "Res", \
90  mesh.time().timeName(), \
91  mesh, \
92  IOobject::NO_READ, \
93  IOobject::NO_WRITE), \
94  mesh.thisDb().lookupObject<surfaceScalarField>(#stateName))
95 
96 #endif
97 
98 // If AD is used, do valA=valB.getValue(), otherwise, do valA=valB
99 #if defined(CODI_AD_FORWARD) || defined(CODI_AD_REVERSE)
100 #define assignValueCheckAD(valA, valB) \
101  valA = valB.getValue();
102 #else
103 #define assignValueCheckAD(valA, valB) \
104  valA = valB;
105 #endif