Skip to content

Commit

Permalink
Added an option to use non-distributed Field DVs.
Browse files Browse the repository at this point in the history
  • Loading branch information
friedenhe committed Apr 8, 2024
1 parent a8b8f33 commit 152a299
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions dafoam/mphys/mphys_dafoam.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,11 @@ def setup(self):
nACTDVars = len(designVariables[dvName]["comps"])
self.add_input(dvName, distributed=False, shape=nACTDVars, tags=["mphys_coupling"])
elif dvType == "Field": # add field variables
self.add_input(dvName, distributed=True, shape_by_conn=True, tags=["mphys_coupling"])
# user can prescribe whether the field var is distributed. Default is True
distributed = True
if "distributed" in designVariables[dvName]:
distributed = designVariables[dvName]["distributed"]
self.add_input(dvName, distributed=distributed, shape_by_conn=True, tags=["mphys_coupling"])
elif dvType == "RegPar":
nParameters = self.DASolver.solver.getNRegressionParameters()
self.add_input(dvName, distributed=False, shape=nParameters, tags=["mphys_coupling"])
Expand Down Expand Up @@ -893,7 +897,15 @@ def apply_linear(self, inputs, outputs, d_inputs, d_outputs, d_residuals, mode):
DASolver.solverAD.calcdRdFieldTPsiAD(
DASolver.xvVec, DASolver.wVec, resBarVec, inputName.encode(), prodVec
)
fieldBar = DASolver.vec2Array(prodVec)
# user can prescribe whether the field var is distributed. Default is True
distributed = True
if "distributed" in designVariables[inputName]:
distributed = designVariables[inputName]["distributed"]

if distributed:
fieldBar = DASolver.vec2Array(prodVec)
else:
fieldBar = DASolver.convertMPIVec2SeqArray(prodVec)
d_inputs[inputName] += fieldBar

elif self.dvType[inputName] == "RegPar":
Expand Down Expand Up @@ -1220,7 +1232,11 @@ def setup(self):
nACTDVars = len(designVariables[dvName]["comps"])
self.add_input(dvName, distributed=False, shape=nACTDVars, tags=["mphys_coupling"])
elif dvType == "Field": # add field variables
self.add_input(dvName, distributed=True, shape_by_conn=True, tags=["mphys_coupling"])
# user can prescribe whether the field var is distributed. Default is True
distributed = True
if "distributed" in designVariables[dvName]:
distributed = designVariables[dvName]["distributed"]
self.add_input(dvName, distributed=distributed, shape_by_conn=True, tags=["mphys_coupling"])
elif dvType == "RegPar":
nParameters = self.DASolver.solver.getNRegressionParameters()
self.add_input(dvName, distributed=False, shape=nParameters, tags=["mphys_coupling"])
Expand Down Expand Up @@ -1421,7 +1437,17 @@ def compute_jacvec_product(self, inputs, d_inputs, d_outputs, mode):
DASolver.solverAD.calcdFdFieldAD(
DASolver.xvVec, DASolver.wVec, objFuncName.encode(), inputName.encode(), dFdField
)
fieldBar = DASolver.vec2Array(dFdField)

# user can prescribe whether the field var is distributed. Default is True
distributed = True
if "distributed" in designVariables[inputName]:
distributed = designVariables[inputName]["distributed"]

if distributed:
fieldBar = DASolver.vec2Array(dFdField)
else:
fieldBar = DASolver.convertMPIVec2SeqArray(dFdField)

d_inputs[inputName] += fieldBar * fBar

elif self.dvType[inputName] == "RegPar":
Expand Down

0 comments on commit 152a299

Please sign in to comment.