Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the RegPar derivs for v3. #585

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions dafoam/mphys/mphys_dafoam.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,9 @@ def setup(self):
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"])
elif dvType == "RegPar":
nParameters = self.DASolver.solver.getNRegressionParameters()
self.add_input(dvName, distributed=False, shape=nParameters, tags=["mphys_coupling"])
else:
raise AnalysisError("designVarType %s not supported! " % dvType)

Expand Down Expand Up @@ -893,6 +896,19 @@ def apply_linear(self, inputs, outputs, d_inputs, d_outputs, d_residuals, mode):
fieldBar = DASolver.vec2Array(prodVec)
d_inputs[inputName] += fieldBar

elif self.dvType[inputName] == "RegPar":
volCoords = DASolver.vec2Array(DASolver.xvVec)
states = outputs["%s_states" % self.discipline]
parameters = inputs[inputName]
product = np.zeros_like(parameters)
seeds = d_residuals["%s_states" % self.discipline]

DASolver.solverAD.calcdRdRegParTPsiAD(volCoords, states, parameters, seeds, product)

# reduce to make sure all procs get the same product
product = self.comm.allreduce(product, op=MPI.SUM)

d_inputs[inputName] += product
else:
raise AnalysisError("designVarType %s not supported! " % self.dvType[inputName])

Expand Down Expand Up @@ -1205,6 +1221,9 @@ def setup(self):
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"])
elif dvType == "RegPar":
nParameters = self.DASolver.solver.getNRegressionParameters()
self.add_input(dvName, distributed=False, shape=nParameters, tags=["mphys_coupling"])
else:
raise AnalysisError("designVarType %s not supported! " % dvType)

Expand Down Expand Up @@ -1405,6 +1424,18 @@ def compute_jacvec_product(self, inputs, d_inputs, d_outputs, mode):
fieldBar = DASolver.vec2Array(dFdField)
d_inputs[inputName] += fieldBar * fBar

elif self.dvType[inputName] == "RegPar":
volCoords = DASolver.vec2Array(DASolver.xvVec)
states = inputs["%s_states" % self.discipline]
parameters = inputs[inputName]
product = np.zeros_like(parameters)

DASolver.solverAD.calcdFdRegParAD(
volCoords, states, parameters, objFuncName.encode(), inputName.encode(), product
)

d_inputs[inputName] += product * fBar

else:
raise AnalysisError("designVarType %s not supported! " % self.dvType[inputName])

Expand Down
Loading