You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: paper.bib
+11Lines changed: 11 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -17,6 +17,17 @@ @misc{mypy
17
17
url = {https://github.com/python/mypy}
18
18
}
19
19
20
+
@article{numpy,
21
+
author = {Harris, Charles R and Millman, K Jarrod and Van Der Walt, St{\'e}fan J and Gommers, Ralf and Virtanen, Pauli and Cournapeau, David and Wieser, Eric and Taylor, Julian and Berg, Sebastian and Smith, Nathaniel J and others},
22
+
title = {Array programming with NumPy},
23
+
journal = {Nature},
24
+
volume = {585},
25
+
number = {7825},
26
+
pages = {357--362},
27
+
year = {2020},
28
+
doi = {10.1038/s41586-020-2649-2}
29
+
}
30
+
20
31
@misc{openfoam-app,
21
32
author = {Gerlero, Gabriel S.},
22
33
title = {{OpenFOAM.app}: Native {OpenFOAM} for {macOS}},
Copy file name to clipboardExpand all lines: paper.md
+19-16Lines changed: 19 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -101,7 +101,7 @@ Besides its obvious use to orchestrate parallel optimization loops, `AsyncFoamCa
101
101
102
102
The `FoamFile` class offers high-level facilities for reading and writing OpenFOAM files, providing an interface similar to that of a Python `dict`. `FoamFile` fully understands OpenFOAM's file formats, and is able to edit file contents in place without disrupting formatting and comments. All types of OpenFOAM files are supported, meaning that `FoamFile` can be used for both and pre- and post-processing tasks.
103
103
104
-
OpenFOAM data types stored in files are mapped to built-in Python types as much as possible, making it easy to work with OpenFOAM data in Python. \autoref{datatypes} shows the mapping of OpenFOAM data types to Python data types with `foamlib`. We note that NumPy arrays are accepted as values for fields, even though NumPy is not a required dependency. Also, disambiguation between Python data types that may represent different OpenFOAM data types (e.g. a scalar value and a uniform scalar field) is resolved by `foamlib` at the time of writing by considering their contextual location within the file. The major exception to this preference for built-ins is posed by the `FoamFile.SubDict` class, which is returned for sub-dictionaries contained in `FoamFile`s, and allows for one-step modification of entries in nested dictionary structures—as is commonly required when configuring OpenFOAM cases.
104
+
OpenFOAM data types stored in files are mapped to built-in Python or NumPy [@numpy]types as much as possible, making it easy to work with OpenFOAM data in Python. \autoref{datatypes} shows the mapping of OpenFOAM data types to Python data types with `foamlib`. Also, disambiguation between Python data types that may represent different OpenFOAM data types (e.g. a scalar value and a uniform scalar field) is resolved by `foamlib` at the time of writing by considering their contextual location within the file. The major exception to this preference for built-ins is posed by the `FoamFile.SubDict` class, which is returned for sub-dictionaries contained in `FoamFile`s, and allows for one-step modification of entries in nested dictionary structures—as is commonly required when configuring OpenFOAM cases.
105
105
106
106
For clarity and additional efficiency, `FoamFile` objects can be used as context managers to make multiple reads and writes to the same file while minimizing the number of filesystem and parsing operations required.
107
107
@@ -110,21 +110,22 @@ Finally, we note that all OpenFOAM file formats are transparently supported by `
110
110
111
111
: Mapping of OpenFOAM data types to Python data types with `foamlib`. \label{datatypes}
112
112
113
-
| OpenFOAM |`foamlib` (accepts and returns) |`foamlib` (also accepts) |
| uniform field |`float`\|`np.ndarray`|`Sequence[float]`|
126
+
| non-uniform field |`numpy.ndarray`|`Sequence[float]`\|`Sequence[Sequence[float]]`|
127
+
| dimension set |`FoamFile.DimensionSet`|`Sequence[float]`\|`numpy.ndarray`|
128
+
| dimensioned |`FoamFile.Dimensioned`||
128
129
129
130
130
131
### `FoamFieldFile` class
@@ -145,6 +146,8 @@ Examples of `foamlib` usage are provided in the [README file](https://github.com
145
146
146
147
`foamlib` contains a full parser for OpenFOAM files, which is able to understand and write to the different types of files used by OpenFOAM. The parser is implemented using the `pyparsing`[@pyparsing] library, which provides a powerful and flexible way to define parsing grammars.
147
148
149
+
A special case parser is internally used for non-uniform OpenFOAM fields, which can commonly contain very large amounts of data in either ASCII or binary formats. The specialized parser uses the regular expressions to extract these data, which results in greatly improved parsing performance—a more than 25x speedup versus PyFoam—, while not sacrificing any of the generality of the parsing grammar. For extra efficiency and convenience, these fields map to NumPy arrays in Python.
150
+
148
151
## Asynchronous support
149
152
150
153
Methods of `FoamCase` and `AsyncFoamCase` have been carefully implemented in a way that greatly avoids duplication of code between the synchronous and asynchronous versions, by factoring out the common logic into a helper intermediate class.
0 commit comments