From af46e13fe4f7a17322181e1248e35bd843cdb3bb Mon Sep 17 00:00:00 2001 From: jhdark Date: Thu, 17 Apr 2025 08:38:48 -0400 Subject: [PATCH 1/4] add example usage to README --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index ef292b7..045fc9e 100644 --- a/README.md +++ b/README.md @@ -14,4 +14,19 @@ foam2dolfinx is a tool for converting OpenFOAM output files to functions that ca conda create -n my-env conda activate my-env conda install -c conda-forge fenics-dolfinx=0.9.0 pyvista +``` + +## Example usage + +> [!NOTE] +> Currently only domains with a unique cell type across the domain are supported. Furthermore, only vtk type cells 10 - tetrahedron and 12 - hexhedron are supported. + +Consider a case where you want to read the velocity and temperature fields from a domain with tetrahedron cells at a time of 100s: + +```python +from foam2dolfinx import OpenFOAMReader + +my_reader = OpenFOAMReader(filename="my_file.foam", cell_type=10) + +my_dolfinx_func = my_reader.create_dolfinx_function(t=100, name="T") ``` \ No newline at end of file From 59255ab19d3fedd6f22a4b94382ce244897ce154 Mon Sep 17 00:00:00 2001 From: jhdark Date: Thu, 17 Apr 2025 08:41:03 -0400 Subject: [PATCH 2/4] both T and U fields --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 045fc9e..059f129 100644 --- a/README.md +++ b/README.md @@ -28,5 +28,6 @@ from foam2dolfinx import OpenFOAMReader my_reader = OpenFOAMReader(filename="my_file.foam", cell_type=10) -my_dolfinx_func = my_reader.create_dolfinx_function(t=100, name="T") +my_dolfinx_T_field = my_reader.create_dolfinx_function(t=100, name="T") +my_dolfinx_U_field = my_reader.create_dolfinx_function(t=100, name="U") ``` \ No newline at end of file From d596b92227bd9904da0e553e8d38b529370d5c71 Mon Sep 17 00:00:00 2001 From: jhdark Date: Mon, 23 Jun 2025 16:05:00 -0400 Subject: [PATCH 3/4] ignore data file --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6648c3e..ef9123f 100644 --- a/.gitignore +++ b/.gitignore @@ -174,4 +174,6 @@ cython_debug/ .vscode *_version.py -*Zone.Identifier \ No newline at end of file +*Zone.Identifier + +data/ \ No newline at end of file From 1856cf8aa0b101108125db7c8e07c5c742d27b1e Mon Sep 17 00:00:00 2001 From: jhdark Date: Mon, 23 Jun 2025 16:18:13 -0400 Subject: [PATCH 4/4] more details on installation and example usage --- README.md | 72 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 63 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 059f129..d80dd53 100644 --- a/README.md +++ b/README.md @@ -10,24 +10,78 @@ foam2dolfinx is a tool for converting OpenFOAM output files to functions that ca ## Installation -```python -conda create -n my-env -conda activate my-env +```bash +conda create -n foam2dolfinx-env +conda activate foam2dolfinx-env conda install -c conda-forge fenics-dolfinx=0.9.0 pyvista ``` +Once in the created in environment: +```bash +pip install git+https://github.com/festim-dev/foam2dolfinx +``` + +# Example usage + +## Standard case + +```python +from foam2dolfinx import OpenFOAMReader +from pyvista import examples -## Example usage +# use foam data from the examples in pyvista +foam_example = examples.download_cavity(load=False) + +# instantiate reader: +my_reader = OpenFOAMReader(filename=foam_example, cell_type=10) + +# read velocity field at t=2.5s +vel = my_of_reader.create_dolfinx_function(t=2.5, name="U") +``` > [!NOTE] > Currently only domains with a unique cell type across the domain are supported. Furthermore, only vtk type cells 10 - tetrahedron and 12 - hexhedron are supported. -Consider a case where you want to read the velocity and temperature fields from a domain with tetrahedron cells at a time of 100s: +## Multiple fields + +Consider a case where in the same file there is both a temperature and velocity field to read at + +```python +from foam2dolfinx import OpenFOAMReader + +# instantiate reader: +my_reader = OpenFOAMReader(filename="my_local_file.foam") + +# read velocity and temperature fields at t=1s +vel = my_of_reader.create_dolfinx_function(t=1.0, name="U") +T = my_of_reader.create_dolfinx_function(t=1.0, name="T") +``` + +## Multiple subdomains +```python +from foam2dolfinx import OpenFOAMReader + +# instantiate reader: +my_reader =OpenFOAMReader(filename="my_local_file.foam") + +# read velocity and temperature fields at t=1s +vel1 = my_of_reader.create_dolfinx_function(t=3.0, name="U", subdomain="sub1") +vel2 = my_of_reader.create_dolfinx_function(t=3.0, name="U", subdomain="sub2") +``` + +## Tips and tricks + +If you are unaware of the time values with data within the OpenFOAM data, you can check with the `time_values` function within the 'reader' attribute of the 'OpenFOAMReader' class: ```python from foam2dolfinx import OpenFOAMReader -my_reader = OpenFOAMReader(filename="my_file.foam", cell_type=10) +# instantiate reader: +my_reader = OpenFOAMReader(filename="my_local_file.foam") -my_dolfinx_T_field = my_reader.create_dolfinx_function(t=100, name="T") -my_dolfinx_U_field = my_reader.create_dolfinx_function(t=100, name="U") -``` \ No newline at end of file +# find the time values +print(my_reader.reader.time_values) +``` +This should return a list of floats with the time values in the file: +``` +[1.0, 2.0, 3.0] +```