Skip to content

Commit 1856cf8

Browse files
committed
more details on installation and example usage
1 parent d596b92 commit 1856cf8

1 file changed

Lines changed: 63 additions & 9 deletions

File tree

README.md

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +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
1717
```
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
1830

19-
## Example usage
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+
```
2040

2141
> [!NOTE]
2242
> 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.
2343
24-
Consider a case where you want to read the velocity and temperature fields from a domain with tetrahedron cells at a time of 100s:
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:
2574

2675
```python
2776
from foam2dolfinx import OpenFOAMReader
2877

29-
my_reader = OpenFOAMReader(filename="my_file.foam", cell_type=10)
78+
# instantiate reader:
79+
my_reader = OpenFOAMReader(filename="my_local_file.foam")
3080

31-
my_dolfinx_T_field = my_reader.create_dolfinx_function(t=100, name="T")
32-
my_dolfinx_U_field = my_reader.create_dolfinx_function(t=100, name="U")
33-
```
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)