Skip to content

Commit 4acfe5d

Browse files
authored
Merge pull request #20 from festim-dev/example-usage
add example usage to README
2 parents 754e3c4 + 1856cf8 commit 4acfe5d

2 files changed

Lines changed: 77 additions & 5 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,6 @@ cython_debug/
174174
.vscode
175175
*_version.py
176176

177-
*Zone.Identifier
177+
*Zone.Identifier
178+
179+
data/

README.md

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,78 @@ foam2dolfinx is a tool for converting OpenFOAM output files to functions that ca
1010
1111
## Installation
1212

13-
```python
14-
conda create -n my-env
15-
conda activate my-env
13+
```bash
14+
conda create -n foam2dolfinx-env
15+
conda activate foam2dolfinx-env
1616
conda install -c conda-forge fenics-dolfinx=0.9.0 pyvista
17-
```
17+
```
18+
Once in the created in environment:
19+
```bash
20+
pip install git+https://github.com/festim-dev/foam2dolfinx
21+
```
22+
23+
# Example usage
24+
25+
## Standard case
26+
27+
```python
28+
from foam2dolfinx import OpenFOAMReader
29+
from pyvista import examples
30+
31+
# use foam data from the examples in pyvista
32+
foam_example = examples.download_cavity(load=False)
33+
34+
# instantiate reader:
35+
my_reader = OpenFOAMReader(filename=foam_example, cell_type=10)
36+
37+
# read velocity field at t=2.5s
38+
vel = my_of_reader.create_dolfinx_function(t=2.5, name="U")
39+
```
40+
41+
> [!NOTE]
42+
> 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.
43+
44+
## Multiple fields
45+
46+
Consider a case where in the same file there is both a temperature and velocity field to read at
47+
48+
```python
49+
from foam2dolfinx import OpenFOAMReader
50+
51+
# instantiate reader:
52+
my_reader = OpenFOAMReader(filename="my_local_file.foam")
53+
54+
# read velocity and temperature fields at t=1s
55+
vel = my_of_reader.create_dolfinx_function(t=1.0, name="U")
56+
T = my_of_reader.create_dolfinx_function(t=1.0, name="T")
57+
```
58+
59+
## Multiple subdomains
60+
```python
61+
from foam2dolfinx import OpenFOAMReader
62+
63+
# instantiate reader:
64+
my_reader =OpenFOAMReader(filename="my_local_file.foam")
65+
66+
# read velocity and temperature fields at t=1s
67+
vel1 = my_of_reader.create_dolfinx_function(t=3.0, name="U", subdomain="sub1")
68+
vel2 = my_of_reader.create_dolfinx_function(t=3.0, name="U", subdomain="sub2")
69+
```
70+
71+
## Tips and tricks
72+
73+
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:
74+
75+
```python
76+
from foam2dolfinx import OpenFOAMReader
77+
78+
# instantiate reader:
79+
my_reader = OpenFOAMReader(filename="my_local_file.foam")
80+
81+
# find the time values
82+
print(my_reader.reader.time_values)
83+
```
84+
This should return a list of floats with the time values in the file:
85+
```
86+
[1.0, 2.0, 3.0]
87+
```

0 commit comments

Comments
 (0)