pycphy 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pycphy/__init__.py +24 -0
- pycphy/foamCaseDeveloper/__init__.py +41 -0
- pycphy/foamCaseDeveloper/config/__init__.py +26 -0
- pycphy/foamCaseDeveloper/config/block_mesh_config.py +90 -0
- pycphy/foamCaseDeveloper/config/control_config.py +168 -0
- pycphy/foamCaseDeveloper/config/global_config.py +83 -0
- pycphy/foamCaseDeveloper/config/turbulence_config.py +187 -0
- pycphy/foamCaseDeveloper/core/__init__.py +18 -0
- pycphy/foamCaseDeveloper/core/block_mesh_developer.py +101 -0
- pycphy/foamCaseDeveloper/core/control_dict_writer.py +55 -0
- pycphy/foamCaseDeveloper/core/foam_case_manager.py +195 -0
- pycphy/foamCaseDeveloper/core/turbulence_properties_writer.py +68 -0
- pycphy/foamCaseDeveloper/main.py +260 -0
- pycphy/foamCaseDeveloper/writers/__init__.py +18 -0
- pycphy/foamCaseDeveloper/writers/block_mesh_writer.py +113 -0
- pycphy/foamCaseDeveloper/writers/control_dict_writer.py +54 -0
- pycphy/foamCaseDeveloper/writers/foam_writer.py +73 -0
- pycphy/foamCaseDeveloper/writers/turbulence_properties_writer.py +78 -0
- pycphy-0.1.0.dist-info/METADATA +335 -0
- pycphy-0.1.0.dist-info/RECORD +24 -0
- pycphy-0.1.0.dist-info/WHEEL +5 -0
- pycphy-0.1.0.dist-info/entry_points.txt +2 -0
- pycphy-0.1.0.dist-info/licenses/LICENSE +21 -0
- pycphy-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,113 @@
|
|
1
|
+
# block_mesh_writer.py
|
2
|
+
|
3
|
+
from .foam_writer import FoamWriter
|
4
|
+
|
5
|
+
class BlockMeshWriter(FoamWriter):
|
6
|
+
"""
|
7
|
+
A class to write OpenFOAM blockMeshDict files.
|
8
|
+
|
9
|
+
It takes Python data structures (lists, dicts) and formats them
|
10
|
+
into a valid blockMeshDict file.
|
11
|
+
"""
|
12
|
+
|
13
|
+
def __init__(self, file_path, scale, vertices, blocks, edges, boundary, merge_patch_pairs=None):
|
14
|
+
"""
|
15
|
+
Initializes the BlockMeshWriter.
|
16
|
+
|
17
|
+
Args:
|
18
|
+
file_path (str): The full path to the output file 'blockMeshDict'.
|
19
|
+
scale (float): The scaling factor.
|
20
|
+
vertices (list): A list of tuples, where each tuple is a vertex (x, y, z).
|
21
|
+
blocks (list): A list of block definitions. Each definition is a tuple/list,
|
22
|
+
e.g., ('hex', [0,1,2,3,4,5,6,7], [10,10,1], 'simpleGrading', [1,1,1]).
|
23
|
+
edges (list): A list of edge definitions (e.g., arc definitions).
|
24
|
+
boundary (list): A list of dictionaries, where each dict defines a boundary patch.
|
25
|
+
e.g., {'name': 'inlet', 'type': 'patch', 'faces': [[...], [...]]}
|
26
|
+
merge_patch_pairs (list, optional): List of pairs to merge. Defaults to an empty list.
|
27
|
+
"""
|
28
|
+
super().__init__(file_path, foam_class="dictionary", foam_object="blockMeshDict")
|
29
|
+
self.scale = scale
|
30
|
+
self.vertices = vertices
|
31
|
+
self.blocks = blocks
|
32
|
+
self.edges = edges
|
33
|
+
self.boundary = boundary
|
34
|
+
self.merge_patch_pairs = merge_patch_pairs if merge_patch_pairs is not None else []
|
35
|
+
|
36
|
+
def _format_list_of_tuples(self, tuples):
|
37
|
+
"""Helper to format a list of tuples like vertices or faces."""
|
38
|
+
return "\n".join([f" ({ ' '.join(map(str, v)) })" for v in tuples])
|
39
|
+
|
40
|
+
def _write_scale(self):
|
41
|
+
"""Writes the scale entry."""
|
42
|
+
self.file_handle.write(f"scale {self.scale};\n\n")
|
43
|
+
|
44
|
+
def _write_vertices(self):
|
45
|
+
"""Writes the vertices section."""
|
46
|
+
self.file_handle.write("vertices\n(\n")
|
47
|
+
self.file_handle.write(self._format_list_of_tuples(self.vertices))
|
48
|
+
self.file_handle.write("\n);\n\n")
|
49
|
+
|
50
|
+
def _write_blocks(self):
|
51
|
+
"""Writes the blocks section."""
|
52
|
+
self.file_handle.write("blocks\n(\n")
|
53
|
+
for block in self.blocks:
|
54
|
+
shape = block[0]
|
55
|
+
verts = ' '.join(map(str, block[1]))
|
56
|
+
cells = f"({ ' '.join(map(str, block[2])) })"
|
57
|
+
grading_type = block[3]
|
58
|
+
grading_vals = f"({ ' '.join(map(str, block[4])) })"
|
59
|
+
self.file_handle.write(f" {shape} ({verts}) {cells} {grading_type} {grading_vals}\n")
|
60
|
+
self.file_handle.write(");\n\n")
|
61
|
+
|
62
|
+
def _write_edges(self):
|
63
|
+
"""Writes the edges section."""
|
64
|
+
self.file_handle.write("edges\n(\n")
|
65
|
+
# Logic for formatting different edge types (e.g., arc) would go here
|
66
|
+
# For now, we assume it's simple or empty.
|
67
|
+
for edge in self.edges:
|
68
|
+
self.file_handle.write(f" {edge}\n")
|
69
|
+
self.file_handle.write(");\n\n")
|
70
|
+
|
71
|
+
def _write_boundary(self):
|
72
|
+
"""Writes the boundary section."""
|
73
|
+
self.file_handle.write("boundary\n(\n")
|
74
|
+
for patch in self.boundary:
|
75
|
+
self.file_handle.write(f" {patch['name']}\n")
|
76
|
+
self.file_handle.write(" {\n")
|
77
|
+
self.file_handle.write(f" type {patch['type']};\n")
|
78
|
+
self.file_handle.write(" faces\n")
|
79
|
+
self.file_handle.write(" (\n")
|
80
|
+
self.file_handle.write(self._format_list_of_tuples(patch['faces']).replace(" ", " "))
|
81
|
+
self.file_handle.write("\n );\n")
|
82
|
+
self.file_handle.write(" }\n")
|
83
|
+
self.file_handle.write(");\n\n")
|
84
|
+
|
85
|
+
def _write_merge_patch_pairs(self):
|
86
|
+
"""Writes the mergePatchPairs section."""
|
87
|
+
self.file_handle.write("mergePatchPairs\n(\n")
|
88
|
+
for pair in self.merge_patch_pairs:
|
89
|
+
self.file_handle.write(f" ({pair[0]} {pair[1]})\n")
|
90
|
+
self.file_handle.write(");\n")
|
91
|
+
|
92
|
+
def write(self):
|
93
|
+
"""
|
94
|
+
Writes the complete blockMeshDict file by calling the section-specific methods.
|
95
|
+
"""
|
96
|
+
print(f"Writing blockMeshDict to: {self.file_path}")
|
97
|
+
with open(self.file_path, 'w') as f:
|
98
|
+
self.file_handle = f
|
99
|
+
self._write_header()
|
100
|
+
self._write_foamfile_dict()
|
101
|
+
self._write_separator()
|
102
|
+
|
103
|
+
# Write blockMeshDict specific content
|
104
|
+
self._write_scale()
|
105
|
+
self._write_vertices()
|
106
|
+
self._write_blocks()
|
107
|
+
self._write_edges()
|
108
|
+
self._write_boundary()
|
109
|
+
self._write_merge_patch_pairs()
|
110
|
+
|
111
|
+
self._write_footer()
|
112
|
+
self.file_handle = None
|
113
|
+
print("...Done")
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# control_dict_writer.py
|
2
|
+
|
3
|
+
from .foam_writer import FoamWriter
|
4
|
+
|
5
|
+
class ControlDictWriter(FoamWriter):
|
6
|
+
"""
|
7
|
+
A class to write an OpenFOAM controlDict file.
|
8
|
+
|
9
|
+
It takes a dictionary of control parameters and formats them
|
10
|
+
into a valid controlDict file.
|
11
|
+
"""
|
12
|
+
|
13
|
+
def __init__(self, file_path, params):
|
14
|
+
"""
|
15
|
+
Initializes the ControlDictWriter.
|
16
|
+
|
17
|
+
Args:
|
18
|
+
file_path (str): The full path to the output file 'controlDict'.
|
19
|
+
params (dict): A dictionary containing the key-value pairs for the controlDict.
|
20
|
+
e.g., {'application': 'icoFoam', 'deltaT': 0.001}
|
21
|
+
"""
|
22
|
+
super().__init__(file_path, foam_class="dictionary", foam_object="controlDict")
|
23
|
+
self.params = params
|
24
|
+
|
25
|
+
def _write_parameters(self):
|
26
|
+
"""Writes the control parameters from the dictionary."""
|
27
|
+
# Find the longest key for alignment purposes to make the file pretty
|
28
|
+
max_key_len = max(len(key) for key in self.params.keys()) if self.params else 0
|
29
|
+
padding = max_key_len + 4 # Add some extra space
|
30
|
+
|
31
|
+
for key, value in self.params.items():
|
32
|
+
# The format string left-aligns the key in a padded field
|
33
|
+
line = f"{key:<{padding}} {value};\n"
|
34
|
+
self.file_handle.write(line)
|
35
|
+
self.file_handle.write("\n")
|
36
|
+
|
37
|
+
|
38
|
+
def write(self):
|
39
|
+
"""
|
40
|
+
Writes the complete controlDict file.
|
41
|
+
"""
|
42
|
+
print(f"Writing controlDict to: {self.file_path}")
|
43
|
+
with open(self.file_path, 'w') as f:
|
44
|
+
self.file_handle = f
|
45
|
+
self._write_header()
|
46
|
+
self._write_foamfile_dict()
|
47
|
+
self._write_separator()
|
48
|
+
|
49
|
+
# Write controlDict specific content
|
50
|
+
self._write_parameters()
|
51
|
+
|
52
|
+
self._write_footer()
|
53
|
+
self.file_handle = None
|
54
|
+
print("...Done")
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# foam_writer.py
|
2
|
+
|
3
|
+
import os
|
4
|
+
from datetime import datetime
|
5
|
+
|
6
|
+
class FoamWriter:
|
7
|
+
"""
|
8
|
+
A base class for writing OpenFOAM dictionary files.
|
9
|
+
|
10
|
+
This class handles the creation of the standard OpenFOAM header,
|
11
|
+
FoamFile dictionary, and footer comments. It is intended to be
|
12
|
+
inherited by more specific writer classes.
|
13
|
+
"""
|
14
|
+
|
15
|
+
def __init__(self, file_path, foam_class, foam_object):
|
16
|
+
"""
|
17
|
+
Initializes the FoamWriter.
|
18
|
+
|
19
|
+
Args:
|
20
|
+
file_path (str): The full path to the output file.
|
21
|
+
foam_class (str): The 'class' entry for the FoamFile dictionary (e.g., 'dictionary').
|
22
|
+
foam_object (str): The 'object' entry for the FoamFile dictionary (e.g., 'blockMeshDict').
|
23
|
+
"""
|
24
|
+
self.file_path = file_path
|
25
|
+
self.foam_class = foam_class
|
26
|
+
self.foam_object = foam_object
|
27
|
+
self.file_handle = None
|
28
|
+
|
29
|
+
# Ensure the directory exists
|
30
|
+
dir_name = os.path.dirname(self.file_path)
|
31
|
+
if dir_name:
|
32
|
+
os.makedirs(dir_name, exist_ok=True)
|
33
|
+
|
34
|
+
def _write_header(self):
|
35
|
+
"""Writes the standard C++ style OpenFOAM header."""
|
36
|
+
header = """/*--------------------------------*- C++ -*----------------------------------*\\
|
37
|
+
| ========= | |
|
38
|
+
| \\\\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
39
|
+
| \\\\ / O peration | Version: v{version} |
|
40
|
+
| \\\\ / A nd | Website: www.openfoam.com |
|
41
|
+
| \\\\/ M anipulation | |
|
42
|
+
\\*---------------------------------------------------------------------------*/
|
43
|
+
""".format(version=datetime.now().strftime("%y%m")) # e.g., v2312
|
44
|
+
self.file_handle.write(header)
|
45
|
+
|
46
|
+
def _write_foamfile_dict(self):
|
47
|
+
"""Writes the FoamFile dictionary section."""
|
48
|
+
foam_dict = f"""FoamFile
|
49
|
+
{{
|
50
|
+
version 2.0;
|
51
|
+
format ascii;
|
52
|
+
class {self.foam_class};
|
53
|
+
object {self.foam_object};
|
54
|
+
}}
|
55
|
+
"""
|
56
|
+
self.file_handle.write(foam_dict)
|
57
|
+
|
58
|
+
def _write_separator(self):
|
59
|
+
"""Writes a standard separator line."""
|
60
|
+
self.file_handle.write("//" + "*" * 79 + "//\n\n")
|
61
|
+
|
62
|
+
def _write_footer(self):
|
63
|
+
"""Writes the standard footer line."""
|
64
|
+
self.file_handle.write("\n//" + "*" * 79 + "//\n")
|
65
|
+
|
66
|
+
def write(self):
|
67
|
+
"""
|
68
|
+
Main writing method. This should be overridden by child classes.
|
69
|
+
|
70
|
+
This method sets up the file and writes the common header and footer,
|
71
|
+
but the main content writing is left to the inheriting class.
|
72
|
+
"""
|
73
|
+
raise NotImplementedError("The 'write' method must be implemented by a subclass.")
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# turbulence_properties_writer.py
|
2
|
+
|
3
|
+
from .foam_writer import FoamWriter
|
4
|
+
|
5
|
+
class TurbulencePropertiesWriter(FoamWriter):
|
6
|
+
"""
|
7
|
+
A class to write an OpenFOAM turbulenceProperties file.
|
8
|
+
|
9
|
+
This writer can handle the nested dictionary structures required for
|
10
|
+
RAS and LES turbulence models.
|
11
|
+
"""
|
12
|
+
|
13
|
+
def __init__(self, file_path, simulation_type, model_properties):
|
14
|
+
"""
|
15
|
+
Initializes the TurbulencePropertiesWriter.
|
16
|
+
|
17
|
+
Args:
|
18
|
+
file_path (str): The full path to the output file 'turbulenceProperties'.
|
19
|
+
simulation_type (str): The top-level simulation type (e.g., 'RAS', 'LES', 'laminar').
|
20
|
+
model_properties (dict): A dictionary containing the properties for the chosen model.
|
21
|
+
This dictionary can be nested.
|
22
|
+
"""
|
23
|
+
super().__init__(file_path, foam_class="dictionary", foam_object="turbulenceProperties")
|
24
|
+
self.simulation_type = simulation_type
|
25
|
+
self.model_properties = model_properties
|
26
|
+
|
27
|
+
def _write_dict_recursively(self, data_dict, indent_level):
|
28
|
+
"""
|
29
|
+
Recursively writes a dictionary's contents, handling nested dictionaries.
|
30
|
+
|
31
|
+
Args:
|
32
|
+
data_dict (dict): The dictionary to write.
|
33
|
+
indent_level (int): The current level of indentation.
|
34
|
+
"""
|
35
|
+
indent = " " * indent_level
|
36
|
+
# Calculate padding for alignment within the current dictionary level
|
37
|
+
max_key_len = max((len(k) for k in data_dict.keys()), default=0)
|
38
|
+
|
39
|
+
for key, value in data_dict.items():
|
40
|
+
if isinstance(value, dict):
|
41
|
+
# If the value is another dictionary, start a new block
|
42
|
+
self.file_handle.write(f"{indent}{key}\n")
|
43
|
+
self.file_handle.write(f"{indent}{{\n")
|
44
|
+
self._write_dict_recursively(value, indent_level + 1)
|
45
|
+
self.file_handle.write(f"{indent}}}\n\n")
|
46
|
+
else:
|
47
|
+
# Otherwise, it's a simple key-value pair
|
48
|
+
padded_key = f"{key:<{max_key_len}}"
|
49
|
+
self.file_handle.write(f"{indent}{padded_key} {value};\n")
|
50
|
+
|
51
|
+
def _write_properties(self):
|
52
|
+
"""Writes the main content of the turbulenceProperties file."""
|
53
|
+
self.file_handle.write(f"simulationType {self.simulation_type};\n\n")
|
54
|
+
|
55
|
+
# Start the main model block (e.g., RAS, LES)
|
56
|
+
# For laminar, this block is often omitted, but writing an empty one is also valid.
|
57
|
+
if self.model_properties or self.simulation_type != "laminar":
|
58
|
+
self.file_handle.write(f"{self.simulation_type}\n")
|
59
|
+
self.file_handle.write("{\n")
|
60
|
+
self._write_dict_recursively(self.model_properties, indent_level=1)
|
61
|
+
self.file_handle.write("}\n")
|
62
|
+
|
63
|
+
def write(self):
|
64
|
+
"""
|
65
|
+
Writes the complete turbulenceProperties file.
|
66
|
+
"""
|
67
|
+
print(f"Writing turbulenceProperties to: {self.file_path}")
|
68
|
+
with open(self.file_path, 'w') as f:
|
69
|
+
self.file_handle = f
|
70
|
+
self._write_header()
|
71
|
+
self._write_foamfile_dict()
|
72
|
+
self._write_separator()
|
73
|
+
|
74
|
+
self._write_properties()
|
75
|
+
|
76
|
+
self._write_footer()
|
77
|
+
self.file_handle = None
|
78
|
+
print("...Done")
|
@@ -0,0 +1,335 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: pycphy
|
3
|
+
Version: 0.1.0
|
4
|
+
Summary: Python: Computational Physics - Tools for physics dynamics simulation
|
5
|
+
Home-page: https://github.com/SanjeevBashyal/pycphy
|
6
|
+
Author: Sanjeev Bashyal
|
7
|
+
Author-email: Sanjeev Bashyal <sanjeev.bashyal@example.com>
|
8
|
+
Maintainer-email: Sanjeev Bashyal <sanjeev.bashyal@example.com>
|
9
|
+
License: MIT
|
10
|
+
Project-URL: Homepage, https://github.com/SanjeevBashyal/pycphy
|
11
|
+
Project-URL: Repository, https://github.com/SanjeevBashyal/pycphy
|
12
|
+
Project-URL: Documentation, https://github.com/SanjeevBashyal/pycphy#readme
|
13
|
+
Project-URL: Bug Tracker, https://github.com/SanjeevBashyal/pycphy/issues
|
14
|
+
Keywords: computational physics,simulation,openfoam,cfd,physics
|
15
|
+
Classifier: Development Status :: 3 - Alpha
|
16
|
+
Classifier: Intended Audience :: Science/Research
|
17
|
+
Classifier: Operating System :: OS Independent
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
19
|
+
Classifier: Programming Language :: Python :: 3.7
|
20
|
+
Classifier: Programming Language :: Python :: 3.8
|
21
|
+
Classifier: Programming Language :: Python :: 3.9
|
22
|
+
Classifier: Programming Language :: Python :: 3.10
|
23
|
+
Classifier: Programming Language :: Python :: 3.11
|
24
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
25
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
26
|
+
Requires-Python: >=3.7
|
27
|
+
Description-Content-Type: text/markdown
|
28
|
+
License-File: LICENSE
|
29
|
+
Requires-Dist: numpy>=1.19.0
|
30
|
+
Requires-Dist: scipy>=1.6.0
|
31
|
+
Requires-Dist: matplotlib>=3.3.0
|
32
|
+
Provides-Extra: dev
|
33
|
+
Requires-Dist: pytest>=6.0; extra == "dev"
|
34
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
35
|
+
Requires-Dist: black; extra == "dev"
|
36
|
+
Requires-Dist: flake8; extra == "dev"
|
37
|
+
Requires-Dist: mypy; extra == "dev"
|
38
|
+
Provides-Extra: docs
|
39
|
+
Requires-Dist: sphinx; extra == "docs"
|
40
|
+
Requires-Dist: sphinx-rtd-theme; extra == "docs"
|
41
|
+
Dynamic: author
|
42
|
+
Dynamic: home-page
|
43
|
+
Dynamic: license-file
|
44
|
+
Dynamic: requires-python
|
45
|
+
|
46
|
+
# pycphy
|
47
|
+
|
48
|
+
**Python: Computational Physics**
|
49
|
+
|
50
|
+
A comprehensive Python package for computational physics simulations and tools, with a focus on OpenFOAM case development and management.
|
51
|
+
|
52
|
+
**Author:** Sanjeev Bashyal
|
53
|
+
**Repository:** [https://github.com/SanjeevBashyal/pycphy](https://github.com/SanjeevBashyal/pycphy)
|
54
|
+
|
55
|
+
## Overview
|
56
|
+
|
57
|
+
`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.
|
58
|
+
|
59
|
+
## Features
|
60
|
+
|
61
|
+
### foamCaseDeveloper Module
|
62
|
+
|
63
|
+
The `foamCaseDeveloper` module provides:
|
64
|
+
|
65
|
+
- **BlockMesh Generation**: Create OpenFOAM blockMeshDict files with custom geometries
|
66
|
+
- **Control Dictionary Setup**: Configure solver settings, time control, and output parameters
|
67
|
+
- **Turbulence Model Configuration**: Set up RAS, LES, and laminar turbulence models
|
68
|
+
- **Complete Case Management**: Automatically create complete OpenFOAM case directories
|
69
|
+
- **Validation and Error Checking**: Built-in validation for all configuration parameters
|
70
|
+
|
71
|
+
## Installation
|
72
|
+
|
73
|
+
### From Source
|
74
|
+
|
75
|
+
```bash
|
76
|
+
git clone https://github.com/SanjeevBashyal/pycphy.git
|
77
|
+
cd pycphy
|
78
|
+
pip install -e .
|
79
|
+
```
|
80
|
+
|
81
|
+
### Development Installation
|
82
|
+
|
83
|
+
```bash
|
84
|
+
git clone https://github.com/SanjeevBashyal/pycphy.git
|
85
|
+
cd pycphy
|
86
|
+
pip install -e ".[dev]"
|
87
|
+
```
|
88
|
+
|
89
|
+
## Quick Start
|
90
|
+
|
91
|
+
### Using the Command Line Interface
|
92
|
+
|
93
|
+
```bash
|
94
|
+
# Create an example case
|
95
|
+
pycphy-foam --example
|
96
|
+
|
97
|
+
# Create a custom case from configuration files
|
98
|
+
pycphy-foam --case myCase --geometry configBlockMesh.py --control configControl.py --turbulence configTurbulence.py
|
99
|
+
```
|
100
|
+
|
101
|
+
### Using Python API
|
102
|
+
|
103
|
+
```python
|
104
|
+
from pycphy.foamCaseDeveloper import FoamCaseManager, BlockMeshConfig, ControlConfig, TurbulenceConfig
|
105
|
+
|
106
|
+
# Create a case manager
|
107
|
+
case_manager = FoamCaseManager("myCase")
|
108
|
+
|
109
|
+
# Set up geometry
|
110
|
+
geometry_config = BlockMeshConfig(
|
111
|
+
p0=(0.0, 0.0, 0.0),
|
112
|
+
p1=(1.0, 1.0, 1.0),
|
113
|
+
cells=(50, 50, 50),
|
114
|
+
patch_names={
|
115
|
+
'minX': 'inlet',
|
116
|
+
'maxX': 'outlet',
|
117
|
+
'minY': 'frontWall',
|
118
|
+
'maxY': 'backWall',
|
119
|
+
'minZ': 'floor',
|
120
|
+
'maxZ': 'ceiling'
|
121
|
+
}
|
122
|
+
)
|
123
|
+
|
124
|
+
case_manager.setup_geometry(
|
125
|
+
p0=geometry_config.p0,
|
126
|
+
p1=geometry_config.p1,
|
127
|
+
cells=geometry_config.cells,
|
128
|
+
patch_names=geometry_config.patch_names
|
129
|
+
)
|
130
|
+
|
131
|
+
# Set up control
|
132
|
+
control_config = ControlConfig()
|
133
|
+
control_config.set_solver("interFoam")
|
134
|
+
control_config.set_time_control(start_time=0, end_time=1.0, delta_t=0.001)
|
135
|
+
|
136
|
+
case_manager.setup_control(control_config.get_parameters())
|
137
|
+
|
138
|
+
# Set up turbulence
|
139
|
+
turbulence_config = TurbulenceConfig("RAS")
|
140
|
+
turbulence_config.set_ras_model("kOmegaSST")
|
141
|
+
|
142
|
+
case_manager.setup_turbulence(
|
143
|
+
simulation_type=turbulence_config.get_simulation_type(),
|
144
|
+
model_properties=turbulence_config.get_model_properties()
|
145
|
+
)
|
146
|
+
|
147
|
+
# Create the complete case
|
148
|
+
case_manager.create_full_case()
|
149
|
+
```
|
150
|
+
|
151
|
+
## Package Structure
|
152
|
+
|
153
|
+
```
|
154
|
+
pycphy/
|
155
|
+
├── __init__.py
|
156
|
+
└── foamCaseDeveloper/
|
157
|
+
├── __init__.py
|
158
|
+
├── main.py # Command-line interface
|
159
|
+
├── core/ # Core functionality
|
160
|
+
│ ├── __init__.py
|
161
|
+
│ ├── foam_case_manager.py # Main case management class
|
162
|
+
│ ├── block_mesh_developer.py # BlockMesh generation
|
163
|
+
│ ├── control_dict_writer.py # Control dictionary writer
|
164
|
+
│ └── turbulence_properties_writer.py # Turbulence properties writer
|
165
|
+
├── writers/ # OpenFOAM dictionary writers
|
166
|
+
│ ├── __init__.py
|
167
|
+
│ ├── foam_writer.py # Base writer class
|
168
|
+
│ ├── block_mesh_writer.py # BlockMesh dictionary writer
|
169
|
+
│ ├── control_dict_writer.py # Control dictionary writer
|
170
|
+
│ └── turbulence_properties_writer.py # Turbulence properties writer
|
171
|
+
└── config/ # Configuration classes
|
172
|
+
├── __init__.py
|
173
|
+
├── block_mesh_config.py # Geometry configuration
|
174
|
+
├── control_config.py # Control configuration
|
175
|
+
└── turbulence_config.py # Turbulence configuration
|
176
|
+
```
|
177
|
+
|
178
|
+
## Configuration
|
179
|
+
|
180
|
+
### Geometry Configuration (BlockMesh)
|
181
|
+
|
182
|
+
```python
|
183
|
+
from pycphy.foamCaseDeveloper import BlockMeshConfig
|
184
|
+
|
185
|
+
config = BlockMeshConfig(
|
186
|
+
p0=(0.0, 0.0, 0.0), # Minimum corner
|
187
|
+
p1=(1.0, 1.0, 1.0), # Maximum corner
|
188
|
+
cells=(50, 50, 50), # Number of cells
|
189
|
+
patch_names={ # Boundary patch names
|
190
|
+
'minX': 'inlet',
|
191
|
+
'maxX': 'outlet',
|
192
|
+
'minY': 'frontWall',
|
193
|
+
'maxY': 'backWall',
|
194
|
+
'minZ': 'floor',
|
195
|
+
'maxZ': 'ceiling'
|
196
|
+
}
|
197
|
+
)
|
198
|
+
```
|
199
|
+
|
200
|
+
### Control Configuration
|
201
|
+
|
202
|
+
```python
|
203
|
+
from pycphy.foamCaseDeveloper import ControlConfig
|
204
|
+
|
205
|
+
config = ControlConfig()
|
206
|
+
config.set_solver("interFoam")
|
207
|
+
config.set_time_control(start_time=0, end_time=1.0, delta_t=0.001)
|
208
|
+
config.set_write_control(write_interval=0.05)
|
209
|
+
config.set_courant_control(max_co=1)
|
210
|
+
```
|
211
|
+
|
212
|
+
### Turbulence Configuration
|
213
|
+
|
214
|
+
```python
|
215
|
+
from pycphy.foamCaseDeveloper import TurbulenceConfig
|
216
|
+
|
217
|
+
# RAS configuration
|
218
|
+
ras_config = TurbulenceConfig("RAS")
|
219
|
+
ras_config.set_ras_model("kOmegaSST")
|
220
|
+
|
221
|
+
# LES configuration
|
222
|
+
les_config = TurbulenceConfig("LES")
|
223
|
+
les_config.set_les_model("kEqn")
|
224
|
+
les_config.set_delta_model("smooth")
|
225
|
+
|
226
|
+
# Laminar configuration
|
227
|
+
laminar_config = TurbulenceConfig("laminar")
|
228
|
+
```
|
229
|
+
|
230
|
+
## Examples
|
231
|
+
|
232
|
+
### Channel Flow Case
|
233
|
+
|
234
|
+
```python
|
235
|
+
from pycphy.foamCaseDeveloper import FoamCaseManager, BlockMeshConfig, ControlConfig, TurbulenceConfig
|
236
|
+
|
237
|
+
# Create channel flow case
|
238
|
+
case_manager = FoamCaseManager("channelFlow")
|
239
|
+
|
240
|
+
# Channel geometry: 0.5m x 0.2m x 0.1m
|
241
|
+
geometry = BlockMeshConfig(
|
242
|
+
p0=(0.0, 0.0, 0.0),
|
243
|
+
p1=(0.5, 0.2, 0.1),
|
244
|
+
cells=(50, 20, 50),
|
245
|
+
patch_names={
|
246
|
+
'minX': 'inlet',
|
247
|
+
'maxX': 'outlet',
|
248
|
+
'minY': 'frontWall',
|
249
|
+
'maxY': 'backWall',
|
250
|
+
'minZ': 'floor',
|
251
|
+
'maxZ': 'ceiling'
|
252
|
+
}
|
253
|
+
)
|
254
|
+
|
255
|
+
case_manager.setup_geometry(
|
256
|
+
p0=geometry.p0, p1=geometry.p1, cells=geometry.cells,
|
257
|
+
patch_names=geometry.patch_names
|
258
|
+
)
|
259
|
+
|
260
|
+
# Set up solver
|
261
|
+
control = ControlConfig()
|
262
|
+
control.set_solver("interFoam")
|
263
|
+
control.set_time_control(start_time=0, end_time=1.0, delta_t=0.001)
|
264
|
+
|
265
|
+
case_manager.setup_control(control.get_parameters())
|
266
|
+
|
267
|
+
# Set up turbulence
|
268
|
+
turbulence = TurbulenceConfig("RAS")
|
269
|
+
turbulence.set_ras_model("kOmegaSST")
|
270
|
+
|
271
|
+
case_manager.setup_turbulence(
|
272
|
+
simulation_type=turbulence.get_simulation_type(),
|
273
|
+
model_properties=turbulence.get_model_properties()
|
274
|
+
)
|
275
|
+
|
276
|
+
# Create the case
|
277
|
+
case_manager.create_full_case()
|
278
|
+
```
|
279
|
+
|
280
|
+
## Requirements
|
281
|
+
|
282
|
+
- Python >= 3.7
|
283
|
+
- NumPy >= 1.19.0
|
284
|
+
- SciPy >= 1.6.0
|
285
|
+
- Matplotlib >= 3.3.0
|
286
|
+
|
287
|
+
## Development
|
288
|
+
|
289
|
+
### Running Tests
|
290
|
+
|
291
|
+
```bash
|
292
|
+
pytest
|
293
|
+
```
|
294
|
+
|
295
|
+
### Code Formatting
|
296
|
+
|
297
|
+
```bash
|
298
|
+
black pycphy/
|
299
|
+
flake8 pycphy/
|
300
|
+
```
|
301
|
+
|
302
|
+
### Building Documentation
|
303
|
+
|
304
|
+
```bash
|
305
|
+
sphinx-build docs/ docs/_build/
|
306
|
+
```
|
307
|
+
|
308
|
+
## Contributing
|
309
|
+
|
310
|
+
1. Fork the repository
|
311
|
+
2. Create a feature branch (`git checkout -b feature/new-feature`)
|
312
|
+
3. Commit your changes (`git commit -am 'Add new feature'`)
|
313
|
+
4. Push to the branch (`git push origin feature/new-feature`)
|
314
|
+
5. Create a Pull Request
|
315
|
+
|
316
|
+
## License
|
317
|
+
|
318
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
319
|
+
|
320
|
+
## Citation
|
321
|
+
|
322
|
+
If you use pycphy in your research, please cite:
|
323
|
+
|
324
|
+
```bibtex
|
325
|
+
@software{bashyal2025pycphy,
|
326
|
+
title={pycphy: Python Computational Physics},
|
327
|
+
author={Bashyal, Sanjeev},
|
328
|
+
year={2025},
|
329
|
+
url={https://github.com/SanjeevBashyal/pycphy}
|
330
|
+
}
|
331
|
+
```
|
332
|
+
|
333
|
+
## Support
|
334
|
+
|
335
|
+
For questions, issues, or contributions, please visit the [GitHub repository](https://github.com/SanjeevBashyal/pycphy).
|
@@ -0,0 +1,24 @@
|
|
1
|
+
pycphy/__init__.py,sha256=Mm71OUIMs3Eex9oxoNeLft7189a-eHollog8-JomGlc,544
|
2
|
+
pycphy/foamCaseDeveloper/__init__.py,sha256=gzvozQIRG8Zktkd9snAPfJhV28Qg8yazh0rZOX6et40,874
|
3
|
+
pycphy/foamCaseDeveloper/main.py,sha256=CsAkeZzNREGRcsSDqPgP9tlTAtz7QnPkkB59T1QfkT8,8932
|
4
|
+
pycphy/foamCaseDeveloper/config/__init__.py,sha256=6_sGyfn-lC9QYXHSdmRS2F6ObfU5okh_uioaiK6jf6w,816
|
5
|
+
pycphy/foamCaseDeveloper/config/block_mesh_config.py,sha256=9QfcdXxPMtazwjgv4Twjp0fp-hder-fSXV0KQXi4kM8,3694
|
6
|
+
pycphy/foamCaseDeveloper/config/control_config.py,sha256=LMsB9KG7yniOfKiMnF7ZVtMYZ9v9lXnObxWnuumIkns,7799
|
7
|
+
pycphy/foamCaseDeveloper/config/global_config.py,sha256=RgUUYCidlzuTRMgiswDQ69OSQgler9Rz3QZzSP1vw2g,2988
|
8
|
+
pycphy/foamCaseDeveloper/config/turbulence_config.py,sha256=oOmVYHX6A30CSZbb3ichQVnnWRs0krkRRP1UhX_5f1Q,8845
|
9
|
+
pycphy/foamCaseDeveloper/core/__init__.py,sha256=rxxMmWuPtfLfGdQvjNK7lDVzNoYZ-E57zucwv-NSiPg,552
|
10
|
+
pycphy/foamCaseDeveloper/core/block_mesh_developer.py,sha256=17u-OLrVzFMM9LshdMusLCfyIh3ICgFpvYBolLuJliw,3602
|
11
|
+
pycphy/foamCaseDeveloper/core/control_dict_writer.py,sha256=ae91vhJ5dIzgozMjADHxWWmJoqXTgRgfGQEDsOAfML0,2067
|
12
|
+
pycphy/foamCaseDeveloper/core/foam_case_manager.py,sha256=tvSStP7F27e8su8FM_MyjvL1iBWiwUS71yeVkArZIJw,7315
|
13
|
+
pycphy/foamCaseDeveloper/core/turbulence_properties_writer.py,sha256=7XnDUqhNu5XTdXN1thvVjGV-yuTlStCpegc73FM4t-c,2938
|
14
|
+
pycphy/foamCaseDeveloper/writers/__init__.py,sha256=GNcGirRv_HBosXMmatN78i5pI5_kaMt1ewwXiJMq2fA,508
|
15
|
+
pycphy/foamCaseDeveloper/writers/block_mesh_writer.py,sha256=lirGHOBlCjX_aaSCsCkWDPAjkki7QJBemPz6yVA7Q-g,4877
|
16
|
+
pycphy/foamCaseDeveloper/writers/control_dict_writer.py,sha256=gaDls-kvqfv_KzG6Ac_2IbIByQ45-6Sn1ylcfIVHiig,1908
|
17
|
+
pycphy/foamCaseDeveloper/writers/foam_writer.py,sha256=KMfQ-338UUg6mEIyW_-55DbcK5UHVihqOXYT0BSsA1M,2854
|
18
|
+
pycphy/foamCaseDeveloper/writers/turbulence_properties_writer.py,sha256=gdUqC_snJLEt8PSwC6TNEUYXCFIneVwm9W4fH8LEqLY,3331
|
19
|
+
pycphy-0.1.0.dist-info/licenses/LICENSE,sha256=SO-nbkWPNmUErH6Zw-SxD-3bGgO9j9euAnYU8K6Gjeo,1093
|
20
|
+
pycphy-0.1.0.dist-info/METADATA,sha256=iOkI2_8BNtIteOj1iKUR16kZ2j3VrAJxEOOKYjdef1o,9698
|
21
|
+
pycphy-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
22
|
+
pycphy-0.1.0.dist-info/entry_points.txt,sha256=i_F-4TnLFt1X-jvnQgRbStMs-pZY5oXlfnc6Nr3wI_k,67
|
23
|
+
pycphy-0.1.0.dist-info/top_level.txt,sha256=w2z-jwGibnt6eh8y4z7LvsPL6I2196b8m_Jxl0XB3PM,7
|
24
|
+
pycphy-0.1.0.dist-info/RECORD,,
|