From 0803a56becd621da1ff454b8f2541cf22eb639cd Mon Sep 17 00:00:00 2001 From: olender Date: Mon, 29 Jul 2024 16:23:25 -0300 Subject: [PATCH] adding functional file --- spyro/solvers/inversion.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spyro/solvers/inversion.py b/spyro/solvers/inversion.py index 38643991..75ad64ec 100644 --- a/spyro/solvers/inversion.py +++ b/spyro/solvers/inversion.py @@ -380,7 +380,11 @@ def get_functional(self, c=None): self.functional_history.append(Jm) self.functional = Jm - print(f"Functional: {Jm} at iteration: {self.current_iteration}", flush=True) + # Save the functional value to a text file + if self.comm.ensemble_comm.rank == 0 and self.comm.comm.rank == 0: + print(f"Functional: {Jm} at iteration: {self.current_iteration}", flush=True) + with open("functional_values.txt", "a") as file: + file.write(f"Iteration: {self.current_iteration}, Functional: {Jm}\n") return Jm