# pycphy
**Python: Computational Physics**
A comprehensive Python package for computational physics simulations and tools, with a focus on OpenFOAM case development and management.
**Author:** Sanjeev Bashyal
**Repository:** [https://github.com/SanjeevBashyal/pycphy](https://github.com/SanjeevBashyal/pycphy)
## Overview
`pycphy` is a Python package designed to provide tools and utilities for computational physics simulations. The package currently includes the `foamCaseDeveloper` module, which offers comprehensive tools for creating and managing OpenFOAM CFD simulation cases.
## Features
### foamCaseDeveloper Module
The `foamCaseDeveloper` module provides:
- **BlockMesh Generation**: Create OpenFOAM blockMeshDict files with custom geometries
- **Control Dictionary Setup**: Configure solver settings, time control, and output parameters
- **Turbulence Model Configuration**: Set up RAS, LES, and laminar turbulence models
- **Complete Case Management**: Automatically create complete OpenFOAM case directories
- **Validation and Error Checking**: Built-in validation for all configuration parameters
## Installation
### From Source
```bash
git clone https://github.com/SanjeevBashyal/pycphy.git
cd pycphy
pip install -e .
```
### Development Installation
```bash
git clone https://github.com/SanjeevBashyal/pycphy.git
cd pycphy
pip install -e ".[dev]"
```
## Quick Start
### Using the Command Line Interface
```bash
# Create an example case
pycphy-foam --example
# Create a custom case from configuration files
pycphy-foam --case myCase --geometry configBlockMesh.py --control configControl.py --turbulence configTurbulence.py
```
### Using Python API
```python
from pycphy.foamCaseDeveloper import FoamCaseManager, BlockMeshConfig, ControlConfig, TurbulenceConfig
# Create a case manager
case_manager = FoamCaseManager("myCase")
# Set up geometry
geometry_config = BlockMeshConfig(
p0=(0.0, 0.0, 0.0),
p1=(1.0, 1.0, 1.0),
cells=(50, 50, 50),
patch_names={
'minX': 'inlet',
'maxX': 'outlet',
'minY': 'frontWall',
'maxY': 'backWall',
'minZ': 'floor',
'maxZ': 'ceiling'
}
)
case_manager.setup_geometry(
p0=geometry_config.p0,
p1=geometry_config.p1,
cells=geometry_config.cells,
patch_names=geometry_config.patch_names
)
# Set up control
control_config = ControlConfig()
control_config.set_solver("interFoam")
control_config.set_time_control(start_time=0, end_time=1.0, delta_t=0.001)
case_manager.setup_control(control_config.get_parameters())
# Set up turbulence
turbulence_config = TurbulenceConfig("RAS")
turbulence_config.set_ras_model("kOmegaSST")
case_manager.setup_turbulence(
simulation_type=turbulence_config.get_simulation_type(),
model_properties=turbulence_config.get_model_properties()
)
# Create the complete case
case_manager.create_full_case()
```
## Package Structure
```
pycphy/
├── __init__.py
└── foamCaseDeveloper/
├── __init__.py
├── main.py # Command-line interface
├── core/ # Core functionality
│ ├── __init__.py
│ ├── foam_case_manager.py # Main case management class
│ ├── block_mesh_developer.py # BlockMesh generation
│ ├── control_dict_writer.py # Control dictionary writer
│ └── turbulence_properties_writer.py # Turbulence properties writer
├── writers/ # OpenFOAM dictionary writers
│ ├── __init__.py
│ ├── foam_writer.py # Base writer class
│ ├── block_mesh_writer.py # BlockMesh dictionary writer
│ ├── control_dict_writer.py # Control dictionary writer
│ └── turbulence_properties_writer.py # Turbulence properties writer
└── config/ # Configuration classes
├── __init__.py
├── block_mesh_config.py # Geometry configuration
├── control_config.py # Control configuration
└── turbulence_config.py # Turbulence configuration
```
## Configuration
### Geometry Configuration (BlockMesh)
```python
from pycphy.foamCaseDeveloper import BlockMeshConfig
config = BlockMeshConfig(
p0=(0.0, 0.0, 0.0), # Minimum corner
p1=(1.0, 1.0, 1.0), # Maximum corner
cells=(50, 50, 50), # Number of cells
patch_names={ # Boundary patch names
'minX': 'inlet',
'maxX': 'outlet',
'minY': 'frontWall',
'maxY': 'backWall',
'minZ': 'floor',
'maxZ': 'ceiling'
}
)
```
### Control Configuration
```python
from pycphy.foamCaseDeveloper import ControlConfig
config = ControlConfig()
config.set_solver("interFoam")
config.set_time_control(start_time=0, end_time=1.0, delta_t=0.001)
config.set_write_control(write_interval=0.05)
config.set_courant_control(max_co=1)
```
### Turbulence Configuration
```python
from pycphy.foamCaseDeveloper import TurbulenceConfig
# RAS configuration
ras_config = TurbulenceConfig("RAS")
ras_config.set_ras_model("kOmegaSST")
# LES configuration
les_config = TurbulenceConfig("LES")
les_config.set_les_model("kEqn")
les_config.set_delta_model("smooth")
# Laminar configuration
laminar_config = TurbulenceConfig("laminar")
```
## Examples
### Channel Flow Case
```python
from pycphy.foamCaseDeveloper import FoamCaseManager, BlockMeshConfig, ControlConfig, TurbulenceConfig
# Create channel flow case
case_manager = FoamCaseManager("channelFlow")
# Channel geometry: 0.5m x 0.2m x 0.1m
geometry = BlockMeshConfig(
p0=(0.0, 0.0, 0.0),
p1=(0.5, 0.2, 0.1),
cells=(50, 20, 50),
patch_names={
'minX': 'inlet',
'maxX': 'outlet',
'minY': 'frontWall',
'maxY': 'backWall',
'minZ': 'floor',
'maxZ': 'ceiling'
}
)
case_manager.setup_geometry(
p0=geometry.p0, p1=geometry.p1, cells=geometry.cells,
patch_names=geometry.patch_names
)
# Set up solver
control = ControlConfig()
control.set_solver("interFoam")
control.set_time_control(start_time=0, end_time=1.0, delta_t=0.001)
case_manager.setup_control(control.get_parameters())
# Set up turbulence
turbulence = TurbulenceConfig("RAS")
turbulence.set_ras_model("kOmegaSST")
case_manager.setup_turbulence(
simulation_type=turbulence.get_simulation_type(),
model_properties=turbulence.get_model_properties()
)
# Create the case
case_manager.create_full_case()
```
## Requirements
- Python >= 3.7
- NumPy >= 1.19.0
- SciPy >= 1.6.0
- Matplotlib >= 3.3.0
## Development
### Running Tests
```bash
pytest
```
### Code Formatting
```bash
black pycphy/
flake8 pycphy/
```
### Building Documentation
```bash
sphinx-build docs/ docs/_build/
```
## Contributing
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/new-feature`)
3. Commit your changes (`git commit -am 'Add new feature'`)
4. Push to the branch (`git push origin feature/new-feature`)
5. Create a Pull Request
## License
This project is licensed under the MIT License - see the LICENSE file for details.
## Citation
If you use pycphy in your research, please cite:
```bibtex
@software{bashyal2025pycphy,
title={pycphy: Python Computational Physics},
author={Bashyal, Sanjeev},
year={2025},
url={https://github.com/SanjeevBashyal/pycphy}
}
```
## Support
For questions, issues, or contributions, please visit the [GitHub repository](https://github.com/SanjeevBashyal/pycphy).
Raw data
{
"_id": null,
"home_page": "https://github.com/SanjeevBashyal/pycphy",
"name": "pycphy",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "Sanjeev Bashyal <sanjeev.bashyal@example.com>",
"keywords": "computational physics, simulation, openfoam, cfd, physics",
"author": "Sanjeev Bashyal",
"author_email": "Sanjeev Bashyal <sanjeev.bashyal@example.com>",
"download_url": "https://files.pythonhosted.org/packages/44/83/e57c59cc1ab75128b300b6f26a61a1dfccd004a68b218adb581b47c69fd2/pycphy-0.1.0.tar.gz",
"platform": null,
"description": "# pycphy\r\n\r\n**Python: Computational Physics**\r\n\r\nA comprehensive Python package for computational physics simulations and tools, with a focus on OpenFOAM case development and management.\r\n\r\n**Author:** Sanjeev Bashyal \r\n**Repository:** [https://github.com/SanjeevBashyal/pycphy](https://github.com/SanjeevBashyal/pycphy)\r\n\r\n## Overview\r\n\r\n`pycphy` is a Python package designed to provide tools and utilities for computational physics simulations. The package currently includes the `foamCaseDeveloper` module, which offers comprehensive tools for creating and managing OpenFOAM CFD simulation cases.\r\n\r\n## Features\r\n\r\n### foamCaseDeveloper Module\r\n\r\nThe `foamCaseDeveloper` module provides:\r\n\r\n- **BlockMesh Generation**: Create OpenFOAM blockMeshDict files with custom geometries\r\n- **Control Dictionary Setup**: Configure solver settings, time control, and output parameters\r\n- **Turbulence Model Configuration**: Set up RAS, LES, and laminar turbulence models\r\n- **Complete Case Management**: Automatically create complete OpenFOAM case directories\r\n- **Validation and Error Checking**: Built-in validation for all configuration parameters\r\n\r\n## Installation\r\n\r\n### From Source\r\n\r\n```bash\r\ngit clone https://github.com/SanjeevBashyal/pycphy.git\r\ncd pycphy\r\npip install -e .\r\n```\r\n\r\n### Development Installation\r\n\r\n```bash\r\ngit clone https://github.com/SanjeevBashyal/pycphy.git\r\ncd pycphy\r\npip install -e \".[dev]\"\r\n```\r\n\r\n## Quick Start\r\n\r\n### Using the Command Line Interface\r\n\r\n```bash\r\n# Create an example case\r\npycphy-foam --example\r\n\r\n# Create a custom case from configuration files\r\npycphy-foam --case myCase --geometry configBlockMesh.py --control configControl.py --turbulence configTurbulence.py\r\n```\r\n\r\n### Using Python API\r\n\r\n```python\r\nfrom pycphy.foamCaseDeveloper import FoamCaseManager, BlockMeshConfig, ControlConfig, TurbulenceConfig\r\n\r\n# Create a case manager\r\ncase_manager = FoamCaseManager(\"myCase\")\r\n\r\n# Set up geometry\r\ngeometry_config = BlockMeshConfig(\r\n p0=(0.0, 0.0, 0.0),\r\n p1=(1.0, 1.0, 1.0),\r\n cells=(50, 50, 50),\r\n patch_names={\r\n 'minX': 'inlet',\r\n 'maxX': 'outlet',\r\n 'minY': 'frontWall',\r\n 'maxY': 'backWall',\r\n 'minZ': 'floor',\r\n 'maxZ': 'ceiling'\r\n }\r\n)\r\n\r\ncase_manager.setup_geometry(\r\n p0=geometry_config.p0,\r\n p1=geometry_config.p1,\r\n cells=geometry_config.cells,\r\n patch_names=geometry_config.patch_names\r\n)\r\n\r\n# Set up control\r\ncontrol_config = ControlConfig()\r\ncontrol_config.set_solver(\"interFoam\")\r\ncontrol_config.set_time_control(start_time=0, end_time=1.0, delta_t=0.001)\r\n\r\ncase_manager.setup_control(control_config.get_parameters())\r\n\r\n# Set up turbulence\r\nturbulence_config = TurbulenceConfig(\"RAS\")\r\nturbulence_config.set_ras_model(\"kOmegaSST\")\r\n\r\ncase_manager.setup_turbulence(\r\n simulation_type=turbulence_config.get_simulation_type(),\r\n model_properties=turbulence_config.get_model_properties()\r\n)\r\n\r\n# Create the complete case\r\ncase_manager.create_full_case()\r\n```\r\n\r\n## Package Structure\r\n\r\n```\r\npycphy/\r\n\u251c\u2500\u2500 __init__.py\r\n\u2514\u2500\u2500 foamCaseDeveloper/\r\n \u251c\u2500\u2500 __init__.py\r\n \u251c\u2500\u2500 main.py # Command-line interface\r\n \u251c\u2500\u2500 core/ # Core functionality\r\n \u2502 \u251c\u2500\u2500 __init__.py\r\n \u2502 \u251c\u2500\u2500 foam_case_manager.py # Main case management class\r\n \u2502 \u251c\u2500\u2500 block_mesh_developer.py # BlockMesh generation\r\n \u2502 \u251c\u2500\u2500 control_dict_writer.py # Control dictionary writer\r\n \u2502 \u2514\u2500\u2500 turbulence_properties_writer.py # Turbulence properties writer\r\n \u251c\u2500\u2500 writers/ # OpenFOAM dictionary writers\r\n \u2502 \u251c\u2500\u2500 __init__.py\r\n \u2502 \u251c\u2500\u2500 foam_writer.py # Base writer class\r\n \u2502 \u251c\u2500\u2500 block_mesh_writer.py # BlockMesh dictionary writer\r\n \u2502 \u251c\u2500\u2500 control_dict_writer.py # Control dictionary writer\r\n \u2502 \u2514\u2500\u2500 turbulence_properties_writer.py # Turbulence properties writer\r\n \u2514\u2500\u2500 config/ # Configuration classes\r\n \u251c\u2500\u2500 __init__.py\r\n \u251c\u2500\u2500 block_mesh_config.py # Geometry configuration\r\n \u251c\u2500\u2500 control_config.py # Control configuration\r\n \u2514\u2500\u2500 turbulence_config.py # Turbulence configuration\r\n```\r\n\r\n## Configuration\r\n\r\n### Geometry Configuration (BlockMesh)\r\n\r\n```python\r\nfrom pycphy.foamCaseDeveloper import BlockMeshConfig\r\n\r\nconfig = BlockMeshConfig(\r\n p0=(0.0, 0.0, 0.0), # Minimum corner\r\n p1=(1.0, 1.0, 1.0), # Maximum corner\r\n cells=(50, 50, 50), # Number of cells\r\n patch_names={ # Boundary patch names\r\n 'minX': 'inlet',\r\n 'maxX': 'outlet',\r\n 'minY': 'frontWall',\r\n 'maxY': 'backWall',\r\n 'minZ': 'floor',\r\n 'maxZ': 'ceiling'\r\n }\r\n)\r\n```\r\n\r\n### Control Configuration\r\n\r\n```python\r\nfrom pycphy.foamCaseDeveloper import ControlConfig\r\n\r\nconfig = ControlConfig()\r\nconfig.set_solver(\"interFoam\")\r\nconfig.set_time_control(start_time=0, end_time=1.0, delta_t=0.001)\r\nconfig.set_write_control(write_interval=0.05)\r\nconfig.set_courant_control(max_co=1)\r\n```\r\n\r\n### Turbulence Configuration\r\n\r\n```python\r\nfrom pycphy.foamCaseDeveloper import TurbulenceConfig\r\n\r\n# RAS configuration\r\nras_config = TurbulenceConfig(\"RAS\")\r\nras_config.set_ras_model(\"kOmegaSST\")\r\n\r\n# LES configuration\r\nles_config = TurbulenceConfig(\"LES\")\r\nles_config.set_les_model(\"kEqn\")\r\nles_config.set_delta_model(\"smooth\")\r\n\r\n# Laminar configuration\r\nlaminar_config = TurbulenceConfig(\"laminar\")\r\n```\r\n\r\n## Examples\r\n\r\n### Channel Flow Case\r\n\r\n```python\r\nfrom pycphy.foamCaseDeveloper import FoamCaseManager, BlockMeshConfig, ControlConfig, TurbulenceConfig\r\n\r\n# Create channel flow case\r\ncase_manager = FoamCaseManager(\"channelFlow\")\r\n\r\n# Channel geometry: 0.5m x 0.2m x 0.1m\r\ngeometry = BlockMeshConfig(\r\n p0=(0.0, 0.0, 0.0),\r\n p1=(0.5, 0.2, 0.1),\r\n cells=(50, 20, 50),\r\n patch_names={\r\n 'minX': 'inlet',\r\n 'maxX': 'outlet',\r\n 'minY': 'frontWall',\r\n 'maxY': 'backWall',\r\n 'minZ': 'floor',\r\n 'maxZ': 'ceiling'\r\n }\r\n)\r\n\r\ncase_manager.setup_geometry(\r\n p0=geometry.p0, p1=geometry.p1, cells=geometry.cells,\r\n patch_names=geometry.patch_names\r\n)\r\n\r\n# Set up solver\r\ncontrol = ControlConfig()\r\ncontrol.set_solver(\"interFoam\")\r\ncontrol.set_time_control(start_time=0, end_time=1.0, delta_t=0.001)\r\n\r\ncase_manager.setup_control(control.get_parameters())\r\n\r\n# Set up turbulence\r\nturbulence = TurbulenceConfig(\"RAS\")\r\nturbulence.set_ras_model(\"kOmegaSST\")\r\n\r\ncase_manager.setup_turbulence(\r\n simulation_type=turbulence.get_simulation_type(),\r\n model_properties=turbulence.get_model_properties()\r\n)\r\n\r\n# Create the case\r\ncase_manager.create_full_case()\r\n```\r\n\r\n## Requirements\r\n\r\n- Python >= 3.7\r\n- NumPy >= 1.19.0\r\n- SciPy >= 1.6.0\r\n- Matplotlib >= 3.3.0\r\n\r\n## Development\r\n\r\n### Running Tests\r\n\r\n```bash\r\npytest\r\n```\r\n\r\n### Code Formatting\r\n\r\n```bash\r\nblack pycphy/\r\nflake8 pycphy/\r\n```\r\n\r\n### Building Documentation\r\n\r\n```bash\r\nsphinx-build docs/ docs/_build/\r\n```\r\n\r\n## Contributing\r\n\r\n1. Fork the repository\r\n2. Create a feature branch (`git checkout -b feature/new-feature`)\r\n3. Commit your changes (`git commit -am 'Add new feature'`)\r\n4. Push to the branch (`git push origin feature/new-feature`)\r\n5. Create a Pull Request\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License - see the LICENSE file for details.\r\n\r\n## Citation\r\n\r\nIf you use pycphy in your research, please cite:\r\n\r\n```bibtex\r\n@software{bashyal2025pycphy,\r\n title={pycphy: Python Computational Physics},\r\n author={Bashyal, Sanjeev},\r\n year={2025},\r\n url={https://github.com/SanjeevBashyal/pycphy}\r\n}\r\n```\r\n\r\n## Support\r\n\r\nFor questions, issues, or contributions, please visit the [GitHub repository](https://github.com/SanjeevBashyal/pycphy).\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python: Computational Physics - Tools for physics dynamics simulation",
"version": "0.1.0",
"project_urls": {
"Bug Tracker": "https://github.com/SanjeevBashyal/pycphy/issues",
"Documentation": "https://github.com/SanjeevBashyal/pycphy#readme",
"Homepage": "https://github.com/SanjeevBashyal/pycphy",
"Repository": "https://github.com/SanjeevBashyal/pycphy"
},
"split_keywords": [
"computational physics",
" simulation",
" openfoam",
" cfd",
" physics"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "e81ee75745c777207d3f48fbebce8f1647fee0b34106a88af8a50e2ed1105924",
"md5": "0c2d3600b6c89cbf5b4410f72b509db2",
"sha256": "2b0d89c4d6cc611ef0943b9dbe31d212d1c333b9ac2c085e1b4808d8788db1ad"
},
"downloads": -1,
"filename": "pycphy-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0c2d3600b6c89cbf5b4410f72b509db2",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 28432,
"upload_time": "2025-09-16T18:34:20",
"upload_time_iso_8601": "2025-09-16T18:34:20.810579Z",
"url": "https://files.pythonhosted.org/packages/e8/1e/e75745c777207d3f48fbebce8f1647fee0b34106a88af8a50e2ed1105924/pycphy-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "4483e57c59cc1ab75128b300b6f26a61a1dfccd004a68b218adb581b47c69fd2",
"md5": "36d3a8f872a212449d29615b4b0799e1",
"sha256": "b88eee5afeec720c72c0bb7e4f081c80b3aa16feb1cf8a3c61dc5d277b410ea0"
},
"downloads": -1,
"filename": "pycphy-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "36d3a8f872a212449d29615b4b0799e1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 24872,
"upload_time": "2025-09-16T18:34:22",
"upload_time_iso_8601": "2025-09-16T18:34:22.775936Z",
"url": "https://files.pythonhosted.org/packages/44/83/e57c59cc1ab75128b300b6f26a61a1dfccd004a68b218adb581b47c69fd2/pycphy-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-16 18:34:22",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "SanjeevBashyal",
"github_project": "pycphy",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "numpy",
"specs": [
[
">=",
"1.19.0"
]
]
},
{
"name": "scipy",
"specs": [
[
">=",
"1.6.0"
]
]
},
{
"name": "matplotlib",
"specs": [
[
">=",
"3.3.0"
]
]
}
],
"lcname": "pycphy"
}