Skip to content

Commit

Permalink
Small change to the dF structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
friedenhe committed Jul 29, 2024
1 parent 8659ca5 commit 067be92
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions dafoam/mphys/mphys_dafoam.py
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,18 @@ def compute(self, inputs, outputs):
# compute the partial derivatives of functions
def compute_jacvec_product(self, inputs, d_inputs, d_outputs, mode):

# we first check if all the seeds in d_outputs are zeros. If yes, we return without calculation anything
n_non_zero_seeds = 0
for func_name in d_outputs:
if d_outputs[func_name] != 0.0:
n_non_zero_seeds += 1
if n_non_zero_seeds == 0:
return
elif n_non_zero_seeds > 1:
if self.comm.rank == 0:
print("************* Warning *************")
print("More than one non-zero seed found! ", d_outputs)

DASolver = self.DASolver

# set the runStatus, this is useful when the actuator term is activated
Expand Down Expand Up @@ -1380,13 +1392,14 @@ def compute_jacvec_product(self, inputs, d_inputs, d_outputs, mode):

funcsBar = {}

# assign value to funcsBar. NOTE: we assign value to funcsBar even if d_outputs[func_name]
# is zero. If it is zero, we will skip the dF calculation.
# assign value to funcsBar. NOTE: we only assign seed if d_outputs has
# non-zero values! We assume OM will pass only one non-zero seed here
# therefore, funcsBar should have only one key
if self.funcs is None:
raise AnalysisError("functions not set! Forgot to call mphys_add_funcs?")
else:
for func_name in self.funcs:
if func_name in d_outputs:
if func_name in d_outputs and d_outputs[func_name] != 0.0:
funcsBar[func_name] = d_outputs[func_name][0]

# if self.comm.rank == 0:
Expand All @@ -1404,12 +1417,6 @@ def compute_jacvec_product(self, inputs, d_inputs, d_outputs, mode):

fBar = funcsBar[objFuncName]

# if fBar is zero, we skip the following calculation and continue to the next loop
if fBar == 0.0:
if self.comm.rank == 0:
print("fBar is zero for %s, the dF partial calculation is skip" % objFuncName)
continue

for inputName in list(d_inputs.keys()):

# compute dFdW * fBar
Expand Down

0 comments on commit 067be92

Please sign in to comment.