DAResidualScalarTransportFoam.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(DAResidualScalarTransportFoam, 0);
16 addToRunTimeSelectionTable(DAResidual, DAResidualScalarTransportFoam, 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  setResidualClassMemberScalar(T, dimensionSet(0, 0, -1, 1, 0, 0, 0)),
28  phi_(const_cast<surfaceScalarField&>(
29  mesh_.thisDb().lookupObject<surfaceScalarField>("phi")))
30 
31 {
32  IOdictionary transportProperties(
33  IOobject(
34  "transportProperties",
35  mesh_.time().constant(),
36  mesh_,
37  IOobject::MUST_READ,
38  IOobject::NO_WRITE));
39 
40  dimensionedScalar DT("DT", dimViscosity, transportProperties);
41 
42  DT_ = DT.value();
43 }
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
47 {
48  /*
49  Description:
50  Clear all members to avoid memory leak because we will initalize
51  multiple objects of DAResidual. Here we need to delete all members
52  in the parent and child classes
53  */
54  TRes_.clear();
55 }
56 
57 void DAResidualScalarTransportFoam::calcResiduals(const dictionary& options)
58 {
59  /*
60  Description:
61  This is the function to compute residuals.
62 
63  Input:
64  options.isPC: 1 means computing residuals for preconditioner matrix.
65  This essentially use the first order scheme for div(phi,U), div(phi,e)
66 
67  p_, T_, U_, phi_, etc: State variables in OpenFOAM
68 
69  Output:
70  URes_, pRes_, TRes_, phiRes_: residual field variables
71  */
72 
73  dimensionedScalar DT("DT", dimViscosity, DT_);
74 
75  fvScalarMatrix TEqn(
76  fvm::ddt(T_)
77  + fvm::div(phi_, T_)
78  - fvm::laplacian(DT, T_));
79 
80  TEqn.relax();
81 
82  TRes_ = TEqn & T_;
83  normalizeResiduals(TRes);
84 }
85 
87 {
88  /*
89  Description:
90  Update the intermediate variables that depend on the state variables
91  */
92  // do nothing
93 }
94 
96 {
97  /*
98  Description:
99  Update the boundary condition for all the states in the selected solver
100  */
101 
102  T_.correctBoundaryConditions();
103 }
104 
105 } // End namespace Foam
106 
107 // ************************************************************************* //
DAResidualScalarTransportFoam.H
Foam::DAResidualScalarTransportFoam::calcResiduals
virtual void calcResiduals(const dictionary &options)
compute residual
Definition: DAResidualScalarTransportFoam.C:57
Foam::DAResidualScalarTransportFoam::DT_
scalar DT_
Definition: DAResidualScalarTransportFoam.H:38
Foam::DAResidualScalarTransportFoam::TRes_
volScalarField TRes_
Definition: DAResidualScalarTransportFoam.H:34
TEqn
fvScalarMatrix TEqn(fvm::div(phi, T) - fvm::laplacian(alphaEff, T))
Foam::DAResidual::mesh_
const fvMesh & mesh_
fvMesh
Definition: DAResidual.H:47
Foam::DAOption
Definition: DAOption.H:29
DT
dimensionedScalar & DT
Definition: createRefsLaplacian.H:6
daOption
DAOption daOption(mesh, pyOptions_)
normalizeResiduals
#define normalizeResiduals(resName)
Definition: DAMacroFunctions.H:28
mesh
fvMesh & mesh
Definition: createRefsHeatTransfer.H:4
Foam::DAResidualScalarTransportFoam::updateIntermediateVariables
virtual void updateIntermediateVariables()
update any intermediate variables that are dependent on state variables and are used in calcResiduals
Definition: DAResidualScalarTransportFoam.C:86
Foam::DAResidualScalarTransportFoam::clear
virtual void clear()
clear the members
Definition: DAResidualScalarTransportFoam.C:46
Foam::DAIndex
Definition: DAIndex.H:32
Foam::DAResidualScalarTransportFoam::DAResidualScalarTransportFoam
DAResidualScalarTransportFoam(const word modelType, const fvMesh &mesh, const DAOption &daOption, const DAModel &daModel, const DAIndex &daIndex)
Definition: DAResidualScalarTransportFoam.C:19
Foam::DAModel
Definition: DAModel.H:59
Foam
Definition: multiFreqScalarFvPatchField.C:144
T
volScalarField & T
Definition: createRefsHeatTransfer.H:5
Foam::DAResidualScalarTransportFoam::correctBoundaryConditions
virtual void correctBoundaryConditions()
update the boundary condition for all the states in the selected solver
Definition: DAResidualScalarTransportFoam.C:95
Foam::DAResidualScalarTransportFoam::phi_
surfaceScalarField & phi_
Definition: DAResidualScalarTransportFoam.H:35
Foam::DAResidual
Definition: DAResidual.H:35
Foam::DAResidualScalarTransportFoam::T_
volScalarField & T_
Definition: DAResidualScalarTransportFoam.H:33
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(DAFvSource, 0)
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(DAFvSource, DAFvSourceActuatorDisk, dictionary)
daModel
DAModel daModel(mesh, daOption)
daIndex
DAIndex daIndex(mesh, daOption, daModel)
setResidualClassMemberScalar
#define setResidualClassMemberScalar(stateName, stateUnit)
Definition: DAMacroFunctions.H:53