DAInputFieldUnsteady.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2 
3  DAFoam : Discrete Adjoint with OpenFOAM
4  Version : v4
5 
6 \*---------------------------------------------------------------------------*/
7 
8 #include "DAInputFieldUnsteady.H"
9 
10 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
11 
12 namespace Foam
13 {
14 
15 defineTypeNameAndDebug(DAInputFieldUnsteady, 0);
16 addToRunTimeSelectionTable(DAInput, DAInputFieldUnsteady, dictionary);
17 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
18 
20  const word inputName,
21  const word inputType,
22  fvMesh& mesh,
23  const DAOption& daOption,
24  const DAModel& daModel,
25  const DAIndex& daIndex)
26  : DAInput(
27  inputName,
28  inputType,
29  mesh,
30  daOption,
31  daModel,
32  daIndex)
33 {
34  const dictionary& subDict = daOption_.getAllOptions().subDict("inputInfo").subDict(inputName);
35  fieldName_ = subDict.getWord("fieldName");
36  fieldType_ = subDict.getWord("fieldType");
37  stepInterval_ = subDict.getLabel("stepInterval");
38  interpolationMethod_ = subDict.getWord("interpolationMethod");
39 
40  scalar endTime = mesh.time().endTime().value();
41  scalar deltaT = mesh.time().deltaT().value();
42  label nSteps = round(endTime / deltaT);
43  if (nSteps % stepInterval_ != 0)
44  {
45  FatalErrorIn("DAInputFieldUnsteady") << "Total number of time steps "
46  << nSteps << "is not divisible by stepInterval "
47  << stepInterval_ << exit(FatalError);
48  }
49 
50  if (interpolationMethod_ == "linear")
51  {
52  // the parameter is the field at the interpolation point itself, here we include the field at t=0
53  nParameters_ = nSteps / stepInterval_ + 1;
54  }
55  else if (interpolationMethod_ == "rbf")
56  {
57  // the parameters are weights and sigma for each interpolation point, so we have two parameter for each point at each step
58  nParameters_ = 2 * (nSteps / stepInterval_ + 1);
59  }
60 }
61 
62 void DAInputFieldUnsteady::run(const scalarList& input)
63 {
64  /*
65  Description:
66  Assign the input array to OF's field variables. Note that we need different treatment for distributed and
67  non-distributed field inputs
68 
69  For linear interpolation, the filed u are saved in this format
70 
71  ------ t = 0 ------|---- t=1interval ---|---- t=2interval ---
72  u1, u2, u3, ... un | u1, u2, u3, ... un | u1, u2, u3, ... un
73 
74  For rbf interpolation, the data are saved in this format, here w and s are the parameters for rbf
75 
76  ------ t = 0 ------|---- t=1interval ---|---- t=2interval ---|------ t = 0 ------|---- t=1interval ---|---- t=2interval --
77  w1, w2, w3, ... wn | w1, w2, w3, ... wn | w1, w2, w3, ... wn |s1, s2, s3, ... sn |s1, s2, s3, ... sn | s1, s2, s3, ... sn|
78  */
79 
80  if (input.size() != this->size())
81  {
82  FatalErrorIn("DAInputFieldUnsteady::run") << "the input size is not valid. " << exit(FatalError);
83  }
84 
85  DAGlobalVar& globalVar =
86  const_cast<DAGlobalVar&>(mesh_.thisDb().lookupObject<DAGlobalVar>("DAGlobalVar"));
87 
88  if (this->distributed())
89  {
90  forAll(globalVar.inputFieldUnsteady[inputName_], idxI)
91  {
92  globalVar.inputFieldUnsteady[inputName_][idxI] = input[idxI];
93  }
94  }
95  else
96  {
97  // here input is a global array with multiple fields, while
98  // globalVar.inputFieldUnsteady is a local array with same number of fields
99  if (fieldType_ == "scalar")
100  {
101  forAll(input, idxI)
102  {
103  label globalCellI = idxI % daIndex_.nGlobalCells;
104  if (daIndex_.globalCellNumbering.isLocal(globalCellI))
105  {
106  label localCellI = daIndex_.globalCellNumbering.toLocal(globalCellI);
107  label idxJ = idxI / daIndex_.nGlobalCells * daIndex_.nLocalCells + localCellI;
108  globalVar.inputFieldUnsteady[inputName_][idxJ] = input[idxI];
109  }
110  }
111  }
112  else
113  {
114  FatalErrorIn("DAInputFieldUnsteady::run") << "fieldType not valid" << exit(FatalError);
115  }
116  }
117 }
118 
119 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
120 
121 } // End namespace Foam
122 
123 // ************************************************************************* //
Foam::DAInput::daIndex_
const DAIndex & daIndex_
DAIndex object.
Definition: DAInput.H:57
Foam::DAInputFieldUnsteady::fieldType_
word fieldType_
field type, can be either scalar or vector
Definition: DAInputFieldUnsteady.H:38
Foam::DAInput::inputName_
const word inputName_
name of the input
Definition: DAInput.H:42
Foam::DAOption
Definition: DAOption.H:29
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(DAFunction, DAFunctionForce, dictionary)
DAInputFieldUnsteady.H
Foam::DAIndex::nLocalCells
label nLocalCells
local cell size
Definition: DAIndex.H:83
Foam::DAOption::getAllOptions
const dictionary & getAllOptions() const
return a reference of allOptions_ dictionary
Definition: DAOption.H:56
mesh
fvMesh & mesh
Definition: createRefsHeatTransfer.H:4
Foam::DAIndex::globalCellNumbering
globalIndex globalCellNumbering
Definition: DAIndex.H:168
Foam::DAInputFieldUnsteady::DAInputFieldUnsteady
DAInputFieldUnsteady(const word inputName, const word inputType, fvMesh &mesh, const DAOption &daOption, const DAModel &daModel, const DAIndex &daIndex)
Definition: DAInputFieldUnsteady.C:19
Foam::DAIndex
Definition: DAIndex.H:32
Foam::DAInput::daOption_
const DAOption & daOption_
DAOption object.
Definition: DAInput.H:51
Foam::DAGlobalVar::inputFieldUnsteady
HashTable< List< scalar > > inputFieldUnsteady
the unsteady field inputs with the key being the fieldName
Definition: DAGlobalVar.H:77
Foam::DAIndex::nGlobalCells
label nGlobalCells
global cell size
Definition: DAIndex.H:129
Foam::DAModel
Definition: DAModel.H:57
Foam::DAInputFieldUnsteady::nParameters_
label nParameters_
how many parameters to interpolate along the time, they could be the field it self
Definition: DAInputFieldUnsteady.H:44
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(DAFunction, 0)
Foam
Definition: checkGeometry.C:32
Foam::DAInputFieldUnsteady::interpolationMethod_
word interpolationMethod_
interpolation method
Definition: DAInputFieldUnsteady.H:47
Foam::DAInputFieldUnsteady::stepInterval_
label stepInterval_
how many time step interval to use, 1 means updating the field every time step
Definition: DAInputFieldUnsteady.H:41
Foam::DAInput
Definition: DAInput.H:30
forAll
forAll(nuTilda1, cellI)
Definition: nuTilda1EqnIrkPimple.H:19
Foam::DAInputFieldUnsteady::distributed
virtual label distributed()
Definition: DAInputFieldUnsteady.H:89
Foam::DAInputFieldUnsteady::run
virtual void run(const scalarList &input)
Definition: DAInputFieldUnsteady.C:62
Foam::DAGlobalVar
Definition: DAGlobalVar.H:26
Foam::DAInput::mesh_
fvMesh & mesh_
fvMesh
Definition: DAInput.H:48
Foam::DAInputFieldUnsteady::fieldName_
word fieldName_
name of the field
Definition: DAInputFieldUnsteady.H:35