Skip to content

Commit

Permalink
add full precision entry into functions file
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-engelstad committed Nov 2, 2023
1 parent 029f9ea commit b78f72b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion funtofem/driver/funtofem_shape_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ def solve_adjoint(self):
if self.is_remote and self.is_paired:
print("Writing funtofem.out file", flush=True)
self.model.write_functions_file(
self.comm, self.remote.functions_file, optim=True
self.comm, self.remote.functions_file, full_precision=False, optim=True
)

return
Expand Down
16 changes: 13 additions & 3 deletions funtofem/model/funtofem_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,9 @@ def read_functions_file(self, comm, filename, root=0, **kwargs):

return

def write_functions_file(self, comm, filename, root=0, **kwargs):
def write_functions_file(
self, comm, filename, root=0, full_precision=True, **kwargs
):
"""
Write the functions file funtofem.out
Expand Down Expand Up @@ -914,10 +916,18 @@ def write_functions_file(self, comm, filename, root=0, **kwargs):
for n, func in enumerate(funcs):
# Print the function name
func_value = func.value.real if func.value is not None else None
data += f"func {func.full_name} = {func_value:.5e}\n"
if full_precision:
data += f"func {func.full_name} = {func_value}\n"
else:
data += f"func {func.full_name} = {func_value:.5e}\n"

for var in variables:
data += f"\t{var.full_name} = {func.derivatives[var]}\n"
if full_precision:
data += f"\t{var.full_name} = {func.derivatives[var].real}\n"
else:
data += (
f"\t{var.full_name} = {func.derivatives[var].real:.5e}\n"
)

with open(filename, "w") as fp:
fp.write(data)
Expand Down

0 comments on commit b78f72b

Please sign in to comment.