diff --git a/festim/exports/surface_flux.py b/festim/exports/surface_flux.py index 96403b8c6..c21db46ba 100644 --- a/festim/exports/surface_flux.py +++ b/festim/exports/surface_flux.py @@ -41,11 +41,3 @@ def compute(self, n, ds): ) ) self.data.append(self.value) - - def initialise_export(self): - title = "Flux surface {}: {}".format(self.surface.id, self.field.name) - - if self.filename is not None: - with open(self.filename, mode="w", newline="") as file: - writer = csv.writer(file) - writer.writerow(["t(s)", f"{title}"]) diff --git a/festim/exports/surface_quantity.py b/festim/exports/surface_quantity.py index c03e2bfc2..3ff9b6a56 100644 --- a/festim/exports/surface_quantity.py +++ b/festim/exports/surface_quantity.py @@ -1,5 +1,6 @@ import festim as F import csv +import os class SurfaceQuantity: @@ -63,6 +64,14 @@ def field(self, value): self._field = value def write(self, t): + if not os.path.isfile(self.filename): + title = "Flux surface {}: {}".format(self.surface.id, self.field.name) + + if self.filename is not None: + with open(self.filename, mode="w", newline="") as file: + writer = csv.writer(file) + writer.writerow(["t(s)", f"{title}"]) + with open(self.filename, mode="a", newline="") as file: writer = csv.writer(file) writer.writerow([t, self.value]) diff --git a/festim/hydrogen_transport_problem.py b/festim/hydrogen_transport_problem.py index 5681a9e7e..7307ab7f1 100644 --- a/festim/hydrogen_transport_problem.py +++ b/festim/hydrogen_transport_problem.py @@ -250,8 +250,6 @@ def initialise_exports(self): export.define_writer(MPI.COMM_WORLD) if isinstance(export, F.XDMFExport): export.writer.write_mesh(self.mesh.mesh) - elif isinstance(export, F.SurfaceQuantity): - export.initialise_export() # compute diffusivity function for surface fluxes