From 1b9688e5e5d453f99f7686caac8309e856fa67ed Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Fri, 13 Oct 2023 14:11:31 -0400 Subject: [PATCH] first implementation --- festim/exports/__init__.py | 0 festim/exports/vtx.py | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 festim/exports/__init__.py create mode 100644 festim/exports/vtx.py diff --git a/festim/exports/__init__.py b/festim/exports/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/festim/exports/vtx.py b/festim/exports/vtx.py new file mode 100644 index 000000000..d920e78a7 --- /dev/null +++ b/festim/exports/vtx.py @@ -0,0 +1,40 @@ +from dolfinx.io import VTXWriter +import mpi4py + +class VTXExport: + """Export functions to VTX file + + Args: + filename (str): the name of the output file + + Attributes: + filename (str): the name of the output file + writer (dolfinx.io.VTXWriter): the VTX writer + + Usage: + >>> u = dolfinx.fem.Function(V) + >>> my_export = festim.VTXExport("my_export.bp") + >>> my_export.define_writer(mesh.comm, [u]) + >>> for t in range(10): + ... u.interpolate(lambda x: t * (x[0] ** 2 + x[1] ** 2 + x[2] ** 2)) + ... my_export.write(t) + """ + def __init__(self, filename: str) -> None: + self.filename = filename + + def define_writer(self, comm: mpi4py.MPI.Intracomm, functions: list) -> None: + """Define the writer + + Args: + comm (mpi4py.MPI.Intracomm): the MPI communicator + functions (list): the list of functions to export + """ + self.writer = VTXWriter(comm, self.filename, functions, "BP4") + + def write(self, t:float): + """Write functions to VTX file + + Args: + t (float): the time of export + """ + self.writer.write(t) \ No newline at end of file