File tree 18 files changed +60
-65
lines changed
18 files changed +60
-65
lines changed Original file line number Diff line number Diff line change @@ -59,7 +59,7 @@ DAObjFunc::DAObjFunc(
59
59
calcRefDiffSquare_ = objFuncDict_ .lookupOrDefault < label > ("calcRefDiffSquare" , 0 );
60
60
if (calcRefDiffSquare_ )
61
61
{
62
- objFuncDict_ .readEntry < scalar > ("ref" , ref_ );
62
+ objFuncDict_ .readEntry < scalarList > ("ref" , ref_ );
63
63
}
64
64
}
65
65
@@ -318,6 +318,29 @@ scalar DAObjFunc::getObjFuncValue()
318
318
return objFuncValue_ ;
319
319
}
320
320
321
+ void DAObjFunc ::calcRefDiffSquare (scalar & objFuncValue )
322
+ {
323
+ /*
324
+ Description:
325
+ Call the variable difference with respect to a given reference and take a square of it.
326
+ This can be used in FIML. This function is for calcRefDiffSquare_ == 1
327
+ */
328
+
329
+ if (calcRefDiffSquare_ )
330
+ {
331
+ if (ref_ .size () == 1 )
332
+ {
333
+ objFuncValue = (objFuncValue - ref_ ) * (objFuncValue - ref_ );
334
+ }
335
+ else
336
+ {
337
+ label idxI = runTime .timeIndex () - 1 ;
338
+ objFuncValue = (objFuncValue - ref_ [idxI ]) * (objFuncValue - ref_ [idxI ]);
339
+ }
340
+ }
341
+
342
+ }
343
+
321
344
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
322
345
323
346
} // End namespace Foam
Original file line number Diff line number Diff line change @@ -95,9 +95,8 @@ protected:
95
95
// / whether to calculate (obj-ref)^2
96
96
label calcRefDiffSquare_;
97
97
98
- // / if calcRefDiffSquare_ is True, set the reference value
99
- scalar ref_;
100
-
98
+ // / if calcRefDiffSquare_ is True, set the reference value list
99
+ scalarList ref_;
101
100
102
101
public:
103
102
// / Runtime type information
@@ -243,6 +242,9 @@ public:
243
242
244
243
// / whether to compute reference coefficients for special objFunc treatment such as totalPressureRatio
245
244
label calcRefCoeffs = 1 ;
245
+
246
+ // / calculate the varDiffSquare
247
+ void calcRefDiffSquare (scalar& objFuncValue);
246
248
};
247
249
248
250
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Original file line number Diff line number Diff line change @@ -128,10 +128,8 @@ void DAObjFuncCenterOfPressure::calcObjFunc(
128
128
129
129
objFuncValue = scale_ * (weightedPressure / totalPressure + (center_ & axis_ ));
130
130
131
- if (calcRefDiffSquare_ )
132
- {
133
- objFuncValue = (objFuncValue - ref_ ) * (objFuncValue - ref_ );
134
- }
131
+ // check if we need to calculate refDiffSquare.
132
+ this -> calcRefDiffSquare (objFuncValue );
135
133
136
134
return ;
137
135
}
Original file line number Diff line number Diff line change @@ -191,10 +191,8 @@ void DAObjFuncForce::calcObjFunc(
191
191
// need to reduce the sum of force across all processors
192
192
reduce (objFuncValue , sumOp < scalar > ( ));
193
193
194
- if (calcRefDiffSquare_ )
195
- {
196
- objFuncValue = (objFuncValue - ref_ ) * (objFuncValue - ref_ );
197
- }
194
+ // check if we need to calculate refDiffSquare.
195
+ this -> calcRefDiffSquare (objFuncValue );
198
196
199
197
return ;
200
198
}
Original file line number Diff line number Diff line change @@ -219,10 +219,8 @@ void DAObjFuncLocation::calcObjFunc(
219
219
<< abort (FatalError );
220
220
}
221
221
222
- if (calcRefDiffSquare_ )
223
- {
224
- objFuncValue = (objFuncValue - ref_ ) * (objFuncValue - ref_ );
225
- }
222
+ // check if we need to calculate refDiffSquare.
223
+ this -> calcRefDiffSquare (objFuncValue );
226
224
227
225
return ;
228
226
}
Original file line number Diff line number Diff line change @@ -96,10 +96,8 @@ void DAObjFuncMass::calcObjFunc(
96
96
// need to reduce the sum of force across all processors
97
97
reduce (objFuncValue , sumOp < scalar > ( ));
98
98
99
- if (calcRefDiffSquare_ )
100
- {
101
- objFuncValue = (objFuncValue - ref_ ) * (objFuncValue - ref_ );
102
- }
99
+ // check if we need to calculate refDiffSquare.
100
+ this -> calcRefDiffSquare (objFuncValue );
103
101
104
102
return ;
105
103
}
Original file line number Diff line number Diff line change @@ -119,10 +119,8 @@ void DAObjFuncMassFlowRate::calcObjFunc(
119
119
// need to reduce the sum of force across all processors
120
120
reduce (objFuncValue , sumOp < scalar > ( ));
121
121
122
- if (calcRefDiffSquare_ )
123
- {
124
- objFuncValue = (objFuncValue - ref_ ) * (objFuncValue - ref_ );
125
- }
122
+ // check if we need to calculate refDiffSquare.
123
+ this -> calcRefDiffSquare (objFuncValue );
126
124
127
125
return ;
128
126
}
Original file line number Diff line number Diff line change @@ -219,10 +219,8 @@ void DAObjFuncMeshQualityKS::calcObjFunc(
219
219
220
220
objFuncValue = log (objFuncValue ) / coeffKS_ ;
221
221
222
- if (calcRefDiffSquare_ )
223
- {
224
- objFuncValue = (objFuncValue - ref_ ) * (objFuncValue - ref_ );
225
- }
222
+ // check if we need to calculate refDiffSquare.
223
+ this -> calcRefDiffSquare (objFuncValue );
226
224
227
225
return ;
228
226
}
Original file line number Diff line number Diff line change @@ -165,10 +165,8 @@ void DAObjFuncMoment::calcObjFunc(
165
165
// need to reduce the sum of force across all processors
166
166
reduce (objFuncValue , sumOp < scalar > ( ));
167
167
168
- if (calcRefDiffSquare_ )
169
- {
170
- objFuncValue = (objFuncValue - ref_ ) * (objFuncValue - ref_ );
171
- }
168
+ // check if we need to calculate refDiffSquare.
169
+ this -> calcRefDiffSquare (objFuncValue );
172
170
173
171
return ;
174
172
}
Original file line number Diff line number Diff line change @@ -132,10 +132,8 @@ void DAObjFuncPatchMean::calcObjFunc(
132
132
// need to reduce the sum of force across all processors
133
133
reduce (objFuncValue , sumOp < scalar > ( ));
134
134
135
- if (calcRefDiffSquare_ )
136
- {
137
- objFuncValue = (objFuncValue - ref_ ) * (objFuncValue - ref_ );
138
- }
135
+ // check if we need to calculate refDiffSquare.
136
+ this -> calcRefDiffSquare (objFuncValue );
139
137
140
138
return ;
141
139
}
Original file line number Diff line number Diff line change @@ -168,10 +168,8 @@ void DAObjFuncPower::calcObjFunc(
168
168
// need to reduce the sum of force across all processors
169
169
reduce (objFuncValue , sumOp < scalar > ( ));
170
170
171
- if (calcRefDiffSquare_ )
172
- {
173
- objFuncValue = (objFuncValue - ref_ ) * (objFuncValue - ref_ );
174
- }
171
+ // check if we need to calculate refDiffSquare.
172
+ this -> calcRefDiffSquare (objFuncValue );
175
173
176
174
return ;
177
175
}
Original file line number Diff line number Diff line change @@ -132,10 +132,8 @@ void DAObjFuncTotalPressure::calcObjFunc(
132
132
// need to reduce the sum of force across all processors
133
133
reduce (objFuncValue , sumOp < scalar > ( ));
134
134
135
- if (calcRefDiffSquare_ )
136
- {
137
- objFuncValue = (objFuncValue - ref_ ) * (objFuncValue - ref_ );
138
- }
135
+ // check if we need to calculate refDiffSquare.
136
+ this -> calcRefDiffSquare (objFuncValue );
139
137
140
138
return ;
141
139
}
Original file line number Diff line number Diff line change @@ -217,10 +217,8 @@ void DAObjFuncTotalPressureRatio::calcObjFunc(
217
217
}
218
218
}
219
219
220
- if (calcRefDiffSquare_ )
221
- {
222
- objFuncValue = (objFuncValue - ref_ ) * (objFuncValue - ref_ );
223
- }
220
+ // check if we need to calculate refDiffSquare.
221
+ this -> calcRefDiffSquare (objFuncValue );
224
222
225
223
return ;
226
224
}
Original file line number Diff line number Diff line change @@ -207,10 +207,8 @@ void DAObjFuncTotalTemperatureRatio::calcObjFunc(
207
207
}
208
208
}
209
209
210
- if (calcRefDiffSquare_ )
211
- {
212
- objFuncValue = (objFuncValue - ref_ ) * (objFuncValue - ref_ );
213
- }
210
+ // check if we need to calculate refDiffSquare.
211
+ this -> calcRefDiffSquare (objFuncValue );
214
212
215
213
return ;
216
214
}
Original file line number Diff line number Diff line change @@ -167,10 +167,8 @@ void DAObjFuncVariableVolSum::calcObjFunc(
167
167
168
168
objFuncValue /= totalVol ;
169
169
170
- if (calcRefDiffSquare_ )
171
- {
172
- objFuncValue = (objFuncValue - ref_ ) * (objFuncValue - ref_ );
173
- }
170
+ // check if we need to calculate refDiffSquare.
171
+ this -> calcRefDiffSquare (objFuncValue );
174
172
175
173
return ;
176
174
}
Original file line number Diff line number Diff line change @@ -121,10 +121,8 @@ void DAObjFuncVonMisesStressKS::calcObjFunc(
121
121
122
122
objFuncValue = log (objValTmp ) / coeffKS_ ;
123
123
124
- if (calcRefDiffSquare_ )
125
- {
126
- objFuncValue = (objFuncValue - ref_ ) * (objFuncValue - ref_ );
127
- }
124
+ // check if we need to calculate refDiffSquare.
125
+ this -> calcRefDiffSquare (objFuncValue );
128
126
129
127
return ;
130
128
}
Original file line number Diff line number Diff line change @@ -246,10 +246,8 @@ void DAObjFuncWallHeatFlux::calcObjFunc(
246
246
// need to reduce the sum of force across all processors
247
247
reduce (objFuncValue , sumOp < scalar > ( ));
248
248
249
- if (calcRefDiffSquare_ )
250
- {
251
- objFuncValue = (objFuncValue - ref_ ) * (objFuncValue - ref_ );
252
- }
249
+ // check if we need to calculate refDiffSquare.
250
+ this -> calcRefDiffSquare (objFuncValue );
253
251
254
252
return ;
255
253
}
Original file line number Diff line number Diff line change 131
131
"scale" : 1.0 / (0.5 * U0 * U0 * A0 * 1.0 ),
132
132
"addToAdjoint" : True ,
133
133
"calcRefDiffSquare" : True ,
134
- "ref" : 0.1
134
+ "ref" : [ 0.1 ]
135
135
}
136
136
},
137
137
},
You can’t perform that action at this time.
0 commit comments