From b78f72b3ae06243a22a92a34cf50246aed9ccf04 Mon Sep 17 00:00:00 2001 From: seanfireball1 Date: Wed, 1 Nov 2023 20:40:04 -0400 Subject: [PATCH] add full precision entry into functions file --- funtofem/driver/funtofem_shape_driver.py | 2 +- funtofem/model/funtofem_model.py | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/funtofem/driver/funtofem_shape_driver.py b/funtofem/driver/funtofem_shape_driver.py index 554efc33..6a154338 100644 --- a/funtofem/driver/funtofem_shape_driver.py +++ b/funtofem/driver/funtofem_shape_driver.py @@ -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 diff --git a/funtofem/model/funtofem_model.py b/funtofem/model/funtofem_model.py index 6739733d..234bc99b 100644 --- a/funtofem/model/funtofem_model.py +++ b/funtofem/model/funtofem_model.py @@ -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 @@ -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)