Skip to content

Commit 7d32447

Browse files
authored
Added the targetThrust as the actuator DV (#354)
* Added the targetThrust as the DV. * Fixed an issue in the test. * Updated the codecov script.
1 parent 0cdfcf1 commit 7d32447

17 files changed

+79
-35
lines changed

.github/workflows/code_coverage.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,6 @@ jobs:
6464
docker exec -i regtest /bin/bash -c ". ${{env.DOCKER_ENV_FILE}} && cd ${{env.DOCKER_WORKING_DIR}}/tests && coverage combine && coverage xml && echo dafoamuser | sudo -S cp -r coverage.xml ${{env.DOCKER_MOUNT_DIR}}/"
6565
docker exec -i regtest /bin/bash -c ". ${{env.DOCKER_ENV_FILE}} && cd ${{env.DOCKER_WORKING_DIR}}/src/adjoint && cp -r ../include ./Make/linux*/DASolver/ && cp -r ../include ./Make/linux*/ && echo dafoamuser | sudo -S cp -r ../adjoint ${{env.DOCKER_MOUNT_DIR}}/"
6666
docker exec -i regtest /bin/bash -c ". ${{env.DOCKER_ENV_FILE}} && cd ${{env.DOCKER_WORKING_DIR}}/src/adjointAD && cp -r ../include ./Make/linux*/DASolver/ && cp -r ../include ./Make/linux*/ && echo dafoamuser | sudo -S cp -r ../adjointAD ${{env.DOCKER_MOUNT_DIR}}/"
67-
bash <(curl -s https://codecov.io/bash)
67+
curl -Os https://uploader.codecov.io/latest/linux/codecov
68+
chmod +x codecov
69+
./codecov

dafoam/mphys/mphys_dafoam.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ def setup(self):
520520
elif dvType == "BC": # add boundary conditions
521521
self.add_input(dvName, distributed=False, shape_by_conn=True, tags=["mphys_coupling"])
522522
elif dvType == "ACTD": # add actuator parameter variables
523-
self.add_input(dvName, distributed=False, shape=9, tags=["mphys_coupling"])
523+
self.add_input(dvName, distributed=False, shape=10, tags=["mphys_coupling"])
524524
elif dvType == "Field": # add field variables
525525
self.add_input(dvName, distributed=True, shape_by_conn=True, tags=["mphys_coupling"])
526526
else:
@@ -681,7 +681,7 @@ def apply_linear(self, inputs, outputs, d_inputs, d_outputs, d_residuals, mode):
681681
# compute [dRdActD]^T*Psi using reverse mode AD
682682
elif self.dvType[inputName] == "ACTD":
683683
prodVec = PETSc.Vec().create(self.comm)
684-
prodVec.setSizes((PETSc.DECIDE, 9), bsize=1)
684+
prodVec.setSizes((PETSc.DECIDE, 10), bsize=1)
685685
prodVec.setFromOptions()
686686
DASolver.solverAD.calcdRdActTPsiAD(
687687
DASolver.xvVec, DASolver.wVec, resBarVec, inputName.encode(), prodVec
@@ -956,7 +956,7 @@ def setup(self):
956956
elif dvType == "BC": # add boundary conditions
957957
self.add_input(dvName, distributed=False, shape_by_conn=True, tags=["mphys_coupling"])
958958
elif dvType == "ACTD": # add actuator parameter variables
959-
self.add_input(dvName, distributed=False, shape=9, tags=["mphys_coupling"])
959+
self.add_input(dvName, distributed=False, shape=10, tags=["mphys_coupling"])
960960
elif dvType == "Field": # add field variables
961961
self.add_input(dvName, distributed=True, shape_by_conn=True, tags=["mphys_coupling"])
962962
else:
@@ -1113,7 +1113,7 @@ def compute_jacvec_product(self, inputs, d_inputs, d_outputs, mode):
11131113
# compute dFdActD
11141114
elif self.dvType[inputName] == "ACTD":
11151115
dFdACTD = PETSc.Vec().create(self.comm)
1116-
dFdACTD.setSizes((PETSc.DECIDE, 9), bsize=1)
1116+
dFdACTD.setSizes((PETSc.DECIDE, 10), bsize=1)
11171117
dFdACTD.setFromOptions()
11181118
DASolver.solverAD.calcdFdACTAD(
11191119
DASolver.xvVec, DASolver.wVec, objFuncName.encode(), inputName.encode(), dFdACTD
@@ -1534,15 +1534,15 @@ def setup(self):
15341534
self.fvSourceDict = self.DASolver.getOption("fvSource")
15351535

15361536
for fvSource, _ in self.fsiDict["fvSource"].items():
1537-
self.add_input("dv_actuator_%s" % fvSource, shape=(6), distributed=False, tags=["mphys_coupling"])
1537+
self.add_input("dv_actuator_%s" % fvSource, shape=(7), distributed=False, tags=["mphys_coupling"])
15381538
self.add_input("x_prop_%s" % fvSource, shape_by_conn=True, distributed=True, tags=["mphys_coupling"])
15391539

1540-
self.add_output("actuator_%s" % fvSource, shape_by_conn=(9), distributed=False, tags=["mphys_coupling"])
1540+
self.add_output("actuator_%s" % fvSource, shape_by_conn=(10), distributed=False, tags=["mphys_coupling"])
15411541

15421542
def compute(self, inputs, outputs):
15431543
# Loop over all actuator disks
15441544
for fvSource, _ in self.fsiDict["fvSource"].items():
1545-
actuator = np.zeros(9)
1545+
actuator = np.zeros(10)
15461546
# Update variables on root proc
15471547
if self.comm.rank == 0:
15481548
actuator[3:] = inputs["dv_actuator_%s" % fvSource][:]

dafoam/pyDAFoam.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
1212
"""
1313

14-
__version__ = "3.0.1"
14+
__version__ = "3.0.2"
1515

1616
import subprocess
1717
import os
@@ -2253,7 +2253,7 @@ def solveAdjoint(self):
22532253
elif designVarDict[designVarName]["designVarType"] in ["ACTL", "ACTP", "ACTD"]:
22542254
if self.getOption("useAD")["mode"] == "fd":
22552255
designVarType = designVarDict[designVarName]["designVarType"]
2256-
nDVTable = {"ACTP": 9, "ACTD": 9, "ACTL": 11}
2256+
nDVTable = {"ACTP": 9, "ACTD": 10, "ACTL": 11}
22572257
nDVs = nDVTable[designVarType]
22582258
# calculate dRdACT
22592259
dRdACT = PETSc.Mat().create(PETSc.COMM_WORLD)
@@ -2293,7 +2293,7 @@ def solveAdjoint(self):
22932293
dRdACT.destroy()
22942294
elif self.getOption("useAD")["mode"] == "reverse":
22952295
designVarType = designVarDict[designVarName]["designVarType"]
2296-
nDVTable = {"ACTP": 9, "ACTD": 9, "ACTL": 11}
2296+
nDVTable = {"ACTP": 9, "ACTD": 10, "ACTL": 11}
22972297
nDVs = nDVTable[designVarType]
22982298
# loop over all objectives
22992299
for objFuncName in objFuncDict:

src/adjoint/DAFvSource/DAFvSource.C

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void DAFvSource::syncDAOptionToActuatorDVs()
144144
diskSubDict.readEntry<scalarList>("center", centerList);
145145

146146
// we have 9 design variables for each disk
147-
scalarList dvList(9);
147+
scalarList dvList(10);
148148
dvList[0] = centerList[0];
149149
dvList[1] = centerList[1];
150150
dvList[2] = centerList[2];
@@ -154,6 +154,7 @@ void DAFvSource::syncDAOptionToActuatorDVs()
154154
dvList[6] = diskSubDict.getScalar("POD");
155155
dvList[7] = diskSubDict.getScalar("expM");
156156
dvList[8] = diskSubDict.getScalar("expN");
157+
dvList[9] = diskSubDict.getScalar("targetThrust");
157158

158159
// set actuatorDiskDVs_
159160
actuatorDiskDVs_.set(diskName, dvList);

src/adjoint/DAFvSource/DAFvSourceActuatorDisk.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ void DAFvSourceActuatorDisk::calcFvSource(volVectorField& fvSource)
310310
tmpThrustSumAll += fAxial * mesh_.V()[cellI];
311311
}
312312
reduce(tmpThrustSumAll, sumOp<scalar>());
313-
scalar targetThrust = diskSubDict.getScalar("targetThrust");
313+
scalar targetThrust = actuatorDiskDVs_[diskName][9];
314314
scale = targetThrust / tmpThrustSumAll;
315315
}
316316
else

src/adjoint/DAPartDeriv/DAPartDerivdFdACTD.C

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ void DAPartDerivdFdACTD::calcPartDerivMat(
134134
scalar scale = diskModelSubDict.getScalar("scale");
135135
scalar expM = diskModelSubDict.getScalar("expM");
136136
scalar expN = diskModelSubDict.getScalar("expN");
137+
scalar targetThrust = diskModelSubDict.getScalar("targetThrust");
137138

138139
DAFvSource& fvSource = const_cast<DAFvSource&>(
139140
mesh_.thisDb().lookupObject<DAFvSource>("DAFvSource"));
@@ -195,6 +196,11 @@ void DAPartDerivdFdACTD::calcPartDerivMat(
195196
expN += delta;
196197
diskModelSubDict.set("expN", expN);
197198
}
199+
else if (i == 9)
200+
{
201+
targetThrust += delta;
202+
diskModelSubDict.set("targetThrust", targetThrust);
203+
}
198204

199205
// we need to synchronize the DAOption to actuatorDVs
200206
fvSource.syncDAOptionToActuatorDVs();
@@ -258,6 +264,11 @@ void DAPartDerivdFdACTD::calcPartDerivMat(
258264
expN -= delta;
259265
diskModelSubDict.set("expN", expN);
260266
}
267+
else if (i == 9)
268+
{
269+
targetThrust -= delta;
270+
diskModelSubDict.set("targetThrust", targetThrust);
271+
}
261272

262273
// we need to synchronize the DAOption to actuatorDVs
263274
fvSource.syncDAOptionToActuatorDVs();

src/adjoint/DAPartDeriv/DAPartDerivdFdACTD.H

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class DAPartDerivdFdACTD
3030
protected:
3131

3232
/// number of design variables for actuator disk
33-
label nActDVs_ = 9;
33+
label nActDVs_ = 10;
3434

3535
public:
3636
TypeName("dFdACTD");

src/adjoint/DAPartDeriv/DAPartDerivdRdACTD.C

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ void DAPartDerivdRdACTD::calcPartDerivMat(
129129
scalar scale = diskModelSubDict.getScalar("scale");
130130
scalar expM = diskModelSubDict.getScalar("expM");
131131
scalar expN = diskModelSubDict.getScalar("expN");
132+
scalar targetThrust = diskModelSubDict.getScalar("targetThrust");
132133

133134
DAFvSource& fvSource = const_cast<DAFvSource&>(
134135
mesh_.thisDb().lookupObject<DAFvSource>("DAFvSource"));
@@ -191,6 +192,11 @@ void DAPartDerivdRdACTD::calcPartDerivMat(
191192
expN += delta;
192193
diskModelSubDict.set("expN", expN);
193194
}
195+
else if (i == 9)
196+
{
197+
targetThrust += delta;
198+
diskModelSubDict.set("targetThrust", targetThrust);
199+
}
194200

195201
// we need to synchronize the DAOption to actuatorDVs
196202
fvSource.syncDAOptionToActuatorDVs();
@@ -255,6 +261,11 @@ void DAPartDerivdRdACTD::calcPartDerivMat(
255261
expN -= delta;
256262
diskModelSubDict.set("expN", expN);
257263
}
264+
else if (i == 9)
265+
{
266+
targetThrust -= delta;
267+
diskModelSubDict.set("targetThrust", targetThrust);
268+
}
258269

259270
// we need to synchronize the DAOption to actuatorDVs
260271
fvSource.syncDAOptionToActuatorDVs();

src/adjoint/DAPartDeriv/DAPartDerivdRdACTD.H

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class DAPartDerivdRdACTD
3030
protected:
3131

3232
/// number of design variables for actuator disk
33-
label nActDVs_ = 9;
33+
label nActDVs_ = 10;
3434

3535
public:
3636
TypeName("dRdACTD");

src/adjoint/DASolver/DASolver.C

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3728,8 +3728,8 @@ void DASolver::calcdFdACTAD(
37283728
objFuncSubDictPart));
37293729

37303730
// get the design variable vals
3731-
scalarList actDVList(9);
3732-
for (label i = 0; i < 9; i++)
3731+
scalarList actDVList(10);
3732+
for (label i = 0; i < 10; i++)
37333733
{
37343734
actDVList[i] = fvSource.getActuatorDVs(diskName, i);
37353735
}
@@ -3739,12 +3739,12 @@ void DASolver::calcdFdACTAD(
37393739
// activate tape, start recording
37403740
this->globalADTape_.setActive();
37413741
// register the input
3742-
for (label i = 0; i < 9; i++)
3742+
for (label i = 0; i < 10; i++)
37433743
{
37443744
this->globalADTape_.registerInput(actDVList[i]);
37453745
}
37463746
// set dv values to fvSource obj for all procs
3747-
for (label i = 0; i < 9; i++)
3747+
for (label i = 0; i < 10; i++)
37483748
{
37493749
fvSource.setActuatorDVs(diskName, i, actDVList[i]);
37503750
}
@@ -3780,7 +3780,7 @@ void DASolver::calcdFdACTAD(
37803780
VecDuplicate(dFdACT, &dFdACTPart);
37813781
VecZeroEntries(dFdACTPart);
37823782

3783-
for (label i = 0; i < 9; i++)
3783+
for (label i = 0; i < 10; i++)
37843784
{
37853785
PetscScalar valIn = actDVList[i].getGradient();
37863786
// we need to do ADD_VALUES to get contribution from all procs
@@ -3878,22 +3878,22 @@ void DASolver::calcdRdActTPsiAD(
38783878
this->updateOFField(wVec);
38793879
this->updateOFMesh(xvVec);
38803880

3881-
scalarList actDVList(9);
3882-
for (label i = 0; i < 9; i++)
3881+
scalarList actDVList(10);
3882+
for (label i = 0; i < 10; i++)
38833883
{
38843884
actDVList[i] = fvSource.getActuatorDVs(diskName, i);
38853885
}
38863886

38873887
this->globalADTape_.reset();
38883888
this->globalADTape_.setActive();
38893889

3890-
for (label i = 0; i < 9; i++)
3890+
for (label i = 0; i < 10; i++)
38913891
{
38923892
this->globalADTape_.registerInput(actDVList[i]);
38933893
}
38943894

38953895
// set dv values to fvSource obj for all procs
3896-
for (label i = 0; i < 9; i++)
3896+
for (label i = 0; i < 10; i++)
38973897
{
38983898
fvSource.setActuatorDVs(diskName, i, actDVList[i]);
38993899
}
@@ -3915,7 +3915,7 @@ void DASolver::calcdRdActTPsiAD(
39153915
this->assignVec2ResidualGradient(psi);
39163916
this->globalADTape_.evaluate();
39173917

3918-
for (label i = 0; i < 9; i++)
3918+
for (label i = 0; i < 10; i++)
39193919
{
39203920
PetscScalar valIn = actDVList[i].getGradient();
39213921
// we need to do ADD_VALUES to get contribution from all procs

0 commit comments

Comments
 (0)