Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/mcgoldba/pyFoamd into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mcgoldba committed Feb 10, 2024
2 parents 2e1e13d + 623ca6a commit 3cfcc67
Show file tree
Hide file tree
Showing 17 changed files with 195 additions and 853 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,21 @@ jobs:
url: https://pypi.org/p/pyfoamd
steps:
# retrieve your distributions here
- name: Checkout source
uses: actions/checkout@v2

- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8

- name: Install build dependencies
run: python -m pip install build wheel

- name: Build distributions
shell: bash -l {0}
run: python -m build --sdist --wheel

- name: Publish package distributions to PyPI
if: github.repository == 'mcgoldba/pyfoamd' && github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
Expand Down
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
## v0.0.8 (2023-10-04)

### Fix

- correct package imports

## 0.0.7 (2023-10-04)

### Fix

- broken import for rich

## 0.0.6 (2023-10-03)

### Fix

- Auto distribution build workflow
- Auto distribution build workflow
- Auto distribution build workflow

## 0.0.5 (2023-10-03)

## 0.0.3 (2023-10-02)

### Fix
Expand Down
40 changes: 0 additions & 40 deletions _setup.py

This file was deleted.

145 changes: 113 additions & 32 deletions pyFoamd.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: pyfoamd
Version: 0.0.2
Version: 0.0.7
Author-email: Marc Goldbach <[email protected]>
License: GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Expand Down Expand Up @@ -691,66 +691,147 @@ pyFoamd

Pythonic modification of OpenFOAM dictionaries and case files.

Features
--------

* Load OpenFOAM cases as Python objects
* Read and edit OpenFOAM dictionary entries
* Manipulated OpenFOAM cases from command line using the integrated iPython console
* Manipulate OpenFOAM cases from a Python script file.
* Support for most OpenFOAM naitive types including:
* dictonary entries, lists, scalars, vectors, tensors, dimensioned types, tables, coded objects, and more
* Run OpenFOAM case Allrun scripts
* Easily setup and execute parametric OpenFOAM studies with many simulations

Installation
------------

.. code-block:: bash

python -m pip install pyfoamd
```bash
#terminal
python -m pip install pyfoamd
```

Basic Usage
-----------

Copy a template case and load as a python object
```bash
#terminal
cp $FOAM_TUTORIALS/incompressible/simpleFoam/pitzDaily .
cd pitzDaily
pf init
```

.. code-block:: bash
View case variables
```bash
#terminal
pf edit
```

cp $FOAM_TUTORIALS/incompressible/simpleFoam/pitzDaily .
cd pitzDaily
pf init
```python
#Python console
>>> case.constant.turbulenceProperties.RAS.RASModel
kEpsilon
```
Change case dictionary entries

View case variables
```python
#Python console
>>> case.constant.case.constant.turbulenceProperties.RAS.RASModel = kOmega
```

Write the updated case to file

```python
#Python console
>>> case.write()
```

.. code-block:: bash
Run the Allrun script
```python
#Python console
>>> case.run()
```

pf edit
Scripting
---------

.. code-block:: python
PyFoamd can also be imported into a python script to allow for manipultion of OpenFOAM cases. This is useful, for example, when performing parameteric studies to run multiple simulations with varibale parameters (e.g. different turbulence models):

>>> case.constant.turbulenceProperties.RAS.RASModel
kEpsilon
```bash
#terminal
#- Setup the OpenFOAM study directory
cd ~
mkdir ofStudy
cd ofStudy
cp $FOAM_TEMPLATES/incompressible/simpleFoam/pitzDaily of.template
touch runStudy.py
```

Change case dictionary entries
runStudy.py
```python
import pyfoamd.functions as pf
import pyfoamd.types as pt
import pamdas as pd

.. code-block:: python
turbulenceModels = [kEpsilon, realizableKE, kOmega, kOmegaSST]
parameterNames = ['Turbulence Model']

>>> case.constant.case.constant.turbulenceProperties.RAS.RASModel = kOmega
samples = pd.DataFrame(
[[model] for model in turbulenceModels],
columns = parameterNames
)

Write the updated case to file
def updateCase(case, values):
"""
This function is called from the ofStudy.

.. code-block:: python
Parameters
----------
case [pyfoamd.ofCase]:
The OpenFOAM case which is to be updated.
values [list]:
Sample point as a list of dictionary values to be updated for the current simulation

>>> case.write()
Return
------
case [pyfoamd.ofCase]:
The updated OpenFOAM case.

"""
turbModel = values[0]

Run the Allrun script
case.constant.case.constant.turbulenceProperties.RAS.RASModel = turbModel

return case

.. code-block:: python
#- Create the OpenFOAM study
study = pt.ofStudy('of.template', parameterNames, sample, updateCase)

>>> case.run()
#- Run all 4 simulations
study.run()

```

```bash
#terminal
# Run the study
python runStudy.py
```

Releasing
---------

Releases are published automatically when a tag is pushed to GitHub.

.. code-block:: bash

# Set next version number
export RELEASE=x.x.x
```bash
# Set next version number
export RELEASE=x.x.x

# Create tags
git commit --allow-empty -m "Release $RELEASE"
git tag -a $RELEASE -m "Version $RELEASE"
# Create tags
git commit --allow-empty -m "Release $RELEASE"
git tag -a $RELEASE -m "Version $RELEASE"

# Push
git push upstream --tags
# Push
git push upstream --tags
```
6 changes: 6 additions & 0 deletions pyFoamd.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
bash
bin
build
dist
pyfoamd
scripts
templates
26 changes: 12 additions & 14 deletions pyfoamd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import sys

import logging
# logger = logging.getLogger('pf')


from rich import print

from rich.traceback import install
install()

from .richLogger import logger
logger = logging.getLogger('pf')

try:
FOAM_VERSION = os.environ['WM_PROJECT_VERSION']
Expand All @@ -20,28 +20,26 @@
print("OpenFOAM not found!")

def getPyFoamdConfig(param):
configPath = None
if (Path('.pyfoamd') / 'config.ini').is_file():
configPath = Path('.pyfoamd') / 'config.ini'
elif (Path.home() / '.pyfoamd' / 'config.ini').is_file():
configPath = Path.home() / '.pyfoamd' / 'config.ini'

if configPath is not None:

def getParam(param, configPath):
parser = ConfigParser()
parser.read(configPath)

print(f"config.ini path: {Path(__file__).parent / 'config.ini'}")
print(f"parser sections: {parser.sections()}")

if parser.has_section('user'):
param_ = parser.get('user', param.lower(), fallback=None)
if param_ is None:
param_ = parser.get('default', param.lower(), fallback=None)
else:
param_ = parser.get('default', param.lower(), fallback=None)
return param_

else:
param_ = None
if (Path('.pyfoamd') / 'config.ini').is_file():
param_ = getParam(param, Path('.pyfoamd') / 'config.ini')
if param_ is None and (Path.home() / '.pyfoamd' / 'config.ini').is_file():
param_ = getParam(param, Path.home() / '.pyfoamd' / 'config.ini')
if param_ is None and (Path(__file__) / 'config.ini').is_file():
param_ = getParam(param, Path(__file__) / 'config.ini')
if param_ is None:
if param.lower() == 'debug':
param_ = False
if param.lower() == 'dict_filesize_limit':
Expand Down
2 changes: 1 addition & 1 deletion pyfoamd/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def main():

debug = getPyFoamdConfig('debug')

setLoggerLevel("DEBUG" if debug.lower()=='true' else "INFO")
setLoggerLevel("DEBUG" if debug else "INFO")

logger.debug(f"debug: {debug}")

Expand Down
Loading

0 comments on commit 3cfcc67

Please sign in to comment.