Skip to content

Commit eaa30d4

Browse files
committed
Added tests and fixed an issue for refDiffSquare.
1 parent dd84636 commit eaa30d4

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

src/adjoint/DAObjFunc/DAObjFunc.C

+2-2
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,11 @@ void DAObjFunc::calcRefDiffSquare(scalar& objFuncValue)
330330
{
331331
if (ref_.size() == 1)
332332
{
333-
objFuncValue = (objFuncValue - ref_) * (objFuncValue - ref_);
333+
objFuncValue = (objFuncValue - ref_[0]) * (objFuncValue - ref_[0]);
334334
}
335335
else
336336
{
337-
label idxI = runTime.timeIndex() - 1;
337+
label idxI = mesh_.time().timeIndex() - 1;
338338
objFuncValue = (objFuncValue - ref_[idxI]) * (objFuncValue - ref_[idxI]);
339339
}
340340
}

tests/refs/DAFoam_Test_DAPimpleFoamRef.txt

+26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Dictionary Key: CD
22
@value 7.747035248407224 1e-08 1e-10
3+
Dictionary Key: CMZVAR
4+
@value 41.05825112111668 1e-08 1e-10
35
Dictionary Key: fail
46
@value 0 1e-08 1e-10
57
Dictionary Key: CD
@@ -25,5 +27,29 @@ Dictionary Key: twist
2527
@value 0.5092926662504045 0.0001 1e-06
2628
Dictionary Key: uin
2729
@value 0.1887121251618032 0.0001 1e-06
30+
Dictionary Key: CMZVAR
31+
Dictionary Key: actuator
32+
@value 0.0129164206206973 0.0001 1e-06
33+
@value -0.06721779867591618 0.0001 1e-06
34+
@value 1.01218774787428e-06 0.0001 1e-06
35+
@value 0 0.0001 1e-06
36+
@value -0.03989829709014971 0.0001 1e-06
37+
@value -1.174777939902339e-05 0.0001 1e-06
38+
@value -0.01318488544862298 0.0001 1e-06
39+
@value 0.02098447283371081 0.0001 1e-06
40+
@value 7.847578532670927e-05 0.0001 1e-06
41+
@value 1.135345283703712e-06 0.0001 1e-06
42+
@value -0.00490063870041851 0.0001 1e-06
43+
@value -0.007270668470157968 0.0001 1e-06
44+
@value 0 0.0001 1e-06
45+
Dictionary Key: alpha
46+
@value 0.1694703610086252 0.0001 1e-06
47+
Dictionary Key: parameter
48+
@value 0.01322002733662093 0.0001 1e-06
49+
Dictionary Key: twist
50+
@value 2.800461713324844 0.0001 1e-06
51+
Dictionary Key: uin
52+
@value 0.5352121060453168 0.0001 1e-06
53+
2854
Dictionary Key: fail
2955
@value 0 0.0001 1e-06

tests/runTests_DAPimpleFoam.py

+16
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@
9595
"addToAdjoint": False,
9696
}
9797
},
98+
"CMZVAR": {
99+
"part1": {
100+
"type": "moment",
101+
"source": "patchToFace",
102+
"patches": ["wing"],
103+
"axis": [0.0, 0.0, 1.0],
104+
"center": [0.25, 0.0, 0.05],
105+
"scale": 1.0,
106+
"addToAdjoint": True,
107+
"calcRefDiffSquare": True,
108+
"ref": [0.1, 0.05, 0.04, 0.02, 0.02, 0.01, 0.0, -0.01, -0.01, -0.02]
109+
}
110+
}
98111
},
99112
"adjStateOrdering": "cell",
100113
"adjEqnOption": {
@@ -267,6 +280,9 @@ def regModel(val, geo):
267280
parameterNormU = np.linalg.norm(funcsSens["CD"]["parameter"])
268281
funcsSens["CD"]["parameter"] = parameterNormU
269282

283+
parameterNormM = np.linalg.norm(funcsSens["CMZVAR"]["parameter"])
284+
funcsSens["CMZVAR"]["parameter"] = parameterNormM
285+
270286
if gcomm.rank == 0:
271287
reg_write_dict(funcs, 1e-8, 1e-10)
272288
reg_write_dict(funcsSens, 1e-4, 1e-6)

0 commit comments

Comments
 (0)