engcalc 0.1.0__tar.gz
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.
- engcalc-0.1.0/.github/workflows/tests.yml +34 -0
- engcalc-0.1.0/.gitignore +31 -0
- engcalc-0.1.0/LICENSE +21 -0
- engcalc-0.1.0/PKG-INFO +164 -0
- engcalc-0.1.0/README.md +149 -0
- engcalc-0.1.0/examples/cycles_demo.py +33 -0
- engcalc-0.1.0/examples/demo.py +24 -0
- engcalc-0.1.0/examples/fluids_demo.py +42 -0
- engcalc-0.1.0/examples/heat_demo.py +41 -0
- engcalc-0.1.0/examples/materials_demo.py +46 -0
- engcalc-0.1.0/examples/units_demo.py +65 -0
- engcalc-0.1.0/pyproject.toml +27 -0
- engcalc-0.1.0/src/engcalc/__init__.py +3 -0
- engcalc-0.1.0/src/engcalc/cycles.py +148 -0
- engcalc-0.1.0/src/engcalc/data/materials.json +122 -0
- engcalc-0.1.0/src/engcalc/fluids.py +182 -0
- engcalc-0.1.0/src/engcalc/heat.py +152 -0
- engcalc-0.1.0/src/engcalc/ideal_gas.py +36 -0
- engcalc-0.1.0/src/engcalc/materials.py +133 -0
- engcalc-0.1.0/src/engcalc/units.py +253 -0
- engcalc-0.1.0/tests/test_cycles.py +67 -0
- engcalc-0.1.0/tests/test_fluids.py +94 -0
- engcalc-0.1.0/tests/test_heat.py +85 -0
- engcalc-0.1.0/tests/test_ideal_gas.py +24 -0
- engcalc-0.1.0/tests/test_materials.py +87 -0
- engcalc-0.1.0/tests/test_units.py +205 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
name: Test on ${{ matrix.os }} / Python ${{ matrix.python-version }}
|
|
12
|
+
runs-on: ${{ matrix.os }}
|
|
13
|
+
strategy:
|
|
14
|
+
fail-fast: false
|
|
15
|
+
matrix:
|
|
16
|
+
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
17
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- name: Checkout code
|
|
21
|
+
uses: actions/checkout@v4
|
|
22
|
+
|
|
23
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
24
|
+
uses: actions/setup-python@v5
|
|
25
|
+
with:
|
|
26
|
+
python-version: ${{ matrix.python-version }}
|
|
27
|
+
|
|
28
|
+
- name: Install dependencies
|
|
29
|
+
run: |
|
|
30
|
+
python -m pip install --upgrade pip
|
|
31
|
+
pip install -e ".[dev]"
|
|
32
|
+
|
|
33
|
+
- name: Run tests
|
|
34
|
+
run: pytest -v
|
engcalc-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
.Python
|
|
7
|
+
|
|
8
|
+
# Virtual environments
|
|
9
|
+
venv/
|
|
10
|
+
env/
|
|
11
|
+
ENV/
|
|
12
|
+
|
|
13
|
+
# Distribution / packaging
|
|
14
|
+
build/
|
|
15
|
+
dist/
|
|
16
|
+
*.egg-info/
|
|
17
|
+
*.egg
|
|
18
|
+
|
|
19
|
+
# Testing
|
|
20
|
+
.pytest_cache/
|
|
21
|
+
.coverage
|
|
22
|
+
htmlcov/
|
|
23
|
+
|
|
24
|
+
# IDE
|
|
25
|
+
.vscode/
|
|
26
|
+
.idea/
|
|
27
|
+
*.swp
|
|
28
|
+
|
|
29
|
+
# OS
|
|
30
|
+
.DS_Store
|
|
31
|
+
Thumbs.db
|
engcalc-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ankita Das
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
engcalc-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: engcalc
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Mechanical Engineering calculations in Python
|
|
5
|
+
Author-email: Ankita Das <ankidas687@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Requires-Dist: numpy>=1.24
|
|
10
|
+
Provides-Extra: dev
|
|
11
|
+
Requires-Dist: build>=1.0; extra == 'dev'
|
|
12
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
13
|
+
Requires-Dist: twine>=4.0; extra == 'dev'
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# engcalc
|
|
17
|
+
|
|
18
|
+
> Mechanical Engineering calculations in Python — fast, tested, and easy to use.
|
|
19
|
+
|
|
20
|
+
[](https://www.python.org/)
|
|
21
|
+
[](https://opensource.org/licenses/MIT)
|
|
22
|
+
[](https://github.com/ankidas687/engcalc/actions/workflows/tests.yml)
|
|
23
|
+
[]()
|
|
24
|
+
|
|
25
|
+
`engcalc` is a pure-Python library for common Mechanical Engineering
|
|
26
|
+
calculations — thermodynamics, fluid mechanics, heat transfer,
|
|
27
|
+
material properties, and unit conversions. Designed for students,
|
|
28
|
+
engineers, and researchers who want clean, tested formulas without
|
|
29
|
+
the spreadsheet mess.
|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
- **Thermodynamics** — ideal gas law, Carnot, Otto, Diesel, Brayton cycles
|
|
34
|
+
- **Fluid Mechanics** — Reynolds number, Bernoulli, Darcy-Weisbach, pump power
|
|
35
|
+
- **Heat Transfer** — conduction, convection, radiation, LMTD
|
|
36
|
+
- **Materials Database** — 10 common engineering materials (steel, aluminum, copper, titanium, cast iron) with 8 properties each
|
|
37
|
+
- **Unit Conversions** — 60+ units across 12 categories (length, mass, time, temperature, pressure, energy, power, force, area, volume, velocity, angle)
|
|
38
|
+
- **SI units** throughout — no unit confusion
|
|
39
|
+
- **Zero heavy dependencies** — only NumPy
|
|
40
|
+
- **Fully type-hinted** and tested (91 tests passing)
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install engcalc
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
> ⚠️ Not yet on PyPI. Install from source for now:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
git clone https://github.com/ankidas687/engcalc.git
|
|
52
|
+
cd engcalc
|
|
53
|
+
pip install -e .
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Quick Start
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from engcalc import ideal_gas, cycles, fluids, heat, materials, units
|
|
60
|
+
|
|
61
|
+
# Ideal gas law: PV = nRT
|
|
62
|
+
P = ideal_gas.pressure(n=1, T=300, V=0.024)
|
|
63
|
+
print(f"Pressure: {P:.2f} Pa") # 103930.78 Pa
|
|
64
|
+
|
|
65
|
+
# Carnot cycle efficiency
|
|
66
|
+
eta = cycles.carnot_efficiency(T_hot=800, T_cold=300)
|
|
67
|
+
print(f"Carnot efficiency: {eta * 100:.2f}%") # 62.50%
|
|
68
|
+
|
|
69
|
+
# Reynolds number
|
|
70
|
+
Re = fluids.reynolds_number(rho=1000, velocity=2, diameter=0.05, mu=0.001)
|
|
71
|
+
print(f"Re = {Re:.0f} → {fluids.flow_regime(Re)}") # 100000 → turbulent
|
|
72
|
+
|
|
73
|
+
# Heat conduction through a wall
|
|
74
|
+
Q = heat.conduction_rate(k=50, A=2, dT=100, L=0.1)
|
|
75
|
+
print(f"Heat rate: {Q:.2f} W") # 100000.00 W
|
|
76
|
+
|
|
77
|
+
# Material property lookup
|
|
78
|
+
rho = materials.get("steel_AISI_1040", "density")
|
|
79
|
+
print(f"Steel density: {rho} kg/m^3") # 7850 kg/m^3
|
|
80
|
+
|
|
81
|
+
# Unit conversion
|
|
82
|
+
temp_K = units.convert(100, "degC", "K")
|
|
83
|
+
print(f"100 °C = {temp_K:.2f} K") # 373.15 K
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Modules
|
|
87
|
+
|
|
88
|
+
| Module | Functions | Description |
|
|
89
|
+
|---|---|---|
|
|
90
|
+
| `engcalc.ideal_gas` | `pressure`, `volume`, `temperature`, `moles` | Ideal gas law (PV = nRT) |
|
|
91
|
+
| `engcalc.cycles` | `carnot_efficiency`, `otto_efficiency`, `diesel_efficiency`, `brayton_efficiency` | Thermodynamic cycle efficiencies |
|
|
92
|
+
| `engcalc.fluids` | `reynolds_number`, `flow_regime`, `bernoulli_pressure`, `darcy_weisbach_head_loss`, `pump_power` | Fluid mechanics |
|
|
93
|
+
| `engcalc.heat` | `conduction_rate`, `convection_rate`, `radiation_rate`, `lmtd` | Heat transfer |
|
|
94
|
+
| `engcalc.materials` | `get`, `get_all`, `list_materials`, `search`, `list_categories` | Material property database |
|
|
95
|
+
| `engcalc.units` | `convert`, `list_categories`, `list_units`, `find_category` | Unit conversion utilities |
|
|
96
|
+
|
|
97
|
+
## Examples
|
|
98
|
+
|
|
99
|
+
Check the [`examples/`](examples/) folder for complete demo scripts:
|
|
100
|
+
|
|
101
|
+
- `examples/demo.py` — Ideal gas law
|
|
102
|
+
- `examples/cycles_demo.py` — Thermodynamic cycles
|
|
103
|
+
- `examples/fluids_demo.py` — Fluid mechanics
|
|
104
|
+
- `examples/heat_demo.py` — Heat transfer
|
|
105
|
+
- `examples/materials_demo.py` — Materials database
|
|
106
|
+
- `examples/units_demo.py` — Unit conversions
|
|
107
|
+
|
|
108
|
+
Run any demo:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
python examples/cycles_demo.py
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Development
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
# Clone the repo
|
|
118
|
+
git clone https://github.com/ankidas687/engcalc.git
|
|
119
|
+
cd engcalc
|
|
120
|
+
|
|
121
|
+
# Create virtual environment
|
|
122
|
+
python -m venv venv
|
|
123
|
+
venv\Scripts\Activate.ps1 # Windows
|
|
124
|
+
# source venv/bin/activate # macOS/Linux
|
|
125
|
+
|
|
126
|
+
# Install with dev dependencies
|
|
127
|
+
pip install -e ".[dev]"
|
|
128
|
+
|
|
129
|
+
# Run tests
|
|
130
|
+
pytest
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Contributing
|
|
134
|
+
|
|
135
|
+
Contributions are welcome! If you find a bug or want to add a new
|
|
136
|
+
calculation, feel free to:
|
|
137
|
+
|
|
138
|
+
1. Fork the repo
|
|
139
|
+
2. Create a feature branch (`git checkout -b feature/new-formula`)
|
|
140
|
+
3. Commit your changes (`git commit -m "Add new formula"`)
|
|
141
|
+
4. Push to the branch (`git push origin feature/new-formula`)
|
|
142
|
+
5. Open a Pull Request
|
|
143
|
+
|
|
144
|
+
## Roadmap
|
|
145
|
+
|
|
146
|
+
- [x] Thermodynamics (ideal gas, cycles)
|
|
147
|
+
- [x] Fluid mechanics
|
|
148
|
+
- [x] Heat transfer
|
|
149
|
+
- [x] Materials database
|
|
150
|
+
- [x] Unit conversion utilities
|
|
151
|
+
- [ ] Mechanics of materials (stress, strain, beam)
|
|
152
|
+
- [ ] Publish to PyPI
|
|
153
|
+
|
|
154
|
+
## License
|
|
155
|
+
|
|
156
|
+
This project is licensed under the MIT License — see the [LICENSE](LICENSE) file for details.
|
|
157
|
+
|
|
158
|
+
## Author
|
|
159
|
+
|
|
160
|
+
**Ankita Das** — [@ankidas687](https://github.com/ankidas687)
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
⭐ If you find this useful, consider giving it a star!
|
engcalc-0.1.0/README.md
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# engcalc
|
|
2
|
+
|
|
3
|
+
> Mechanical Engineering calculations in Python — fast, tested, and easy to use.
|
|
4
|
+
|
|
5
|
+
[](https://www.python.org/)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[](https://github.com/ankidas687/engcalc/actions/workflows/tests.yml)
|
|
8
|
+
[]()
|
|
9
|
+
|
|
10
|
+
`engcalc` is a pure-Python library for common Mechanical Engineering
|
|
11
|
+
calculations — thermodynamics, fluid mechanics, heat transfer,
|
|
12
|
+
material properties, and unit conversions. Designed for students,
|
|
13
|
+
engineers, and researchers who want clean, tested formulas without
|
|
14
|
+
the spreadsheet mess.
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
- **Thermodynamics** — ideal gas law, Carnot, Otto, Diesel, Brayton cycles
|
|
19
|
+
- **Fluid Mechanics** — Reynolds number, Bernoulli, Darcy-Weisbach, pump power
|
|
20
|
+
- **Heat Transfer** — conduction, convection, radiation, LMTD
|
|
21
|
+
- **Materials Database** — 10 common engineering materials (steel, aluminum, copper, titanium, cast iron) with 8 properties each
|
|
22
|
+
- **Unit Conversions** — 60+ units across 12 categories (length, mass, time, temperature, pressure, energy, power, force, area, volume, velocity, angle)
|
|
23
|
+
- **SI units** throughout — no unit confusion
|
|
24
|
+
- **Zero heavy dependencies** — only NumPy
|
|
25
|
+
- **Fully type-hinted** and tested (91 tests passing)
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install engcalc
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
> ⚠️ Not yet on PyPI. Install from source for now:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
git clone https://github.com/ankidas687/engcalc.git
|
|
37
|
+
cd engcalc
|
|
38
|
+
pip install -e .
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Quick Start
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from engcalc import ideal_gas, cycles, fluids, heat, materials, units
|
|
45
|
+
|
|
46
|
+
# Ideal gas law: PV = nRT
|
|
47
|
+
P = ideal_gas.pressure(n=1, T=300, V=0.024)
|
|
48
|
+
print(f"Pressure: {P:.2f} Pa") # 103930.78 Pa
|
|
49
|
+
|
|
50
|
+
# Carnot cycle efficiency
|
|
51
|
+
eta = cycles.carnot_efficiency(T_hot=800, T_cold=300)
|
|
52
|
+
print(f"Carnot efficiency: {eta * 100:.2f}%") # 62.50%
|
|
53
|
+
|
|
54
|
+
# Reynolds number
|
|
55
|
+
Re = fluids.reynolds_number(rho=1000, velocity=2, diameter=0.05, mu=0.001)
|
|
56
|
+
print(f"Re = {Re:.0f} → {fluids.flow_regime(Re)}") # 100000 → turbulent
|
|
57
|
+
|
|
58
|
+
# Heat conduction through a wall
|
|
59
|
+
Q = heat.conduction_rate(k=50, A=2, dT=100, L=0.1)
|
|
60
|
+
print(f"Heat rate: {Q:.2f} W") # 100000.00 W
|
|
61
|
+
|
|
62
|
+
# Material property lookup
|
|
63
|
+
rho = materials.get("steel_AISI_1040", "density")
|
|
64
|
+
print(f"Steel density: {rho} kg/m^3") # 7850 kg/m^3
|
|
65
|
+
|
|
66
|
+
# Unit conversion
|
|
67
|
+
temp_K = units.convert(100, "degC", "K")
|
|
68
|
+
print(f"100 °C = {temp_K:.2f} K") # 373.15 K
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Modules
|
|
72
|
+
|
|
73
|
+
| Module | Functions | Description |
|
|
74
|
+
|---|---|---|
|
|
75
|
+
| `engcalc.ideal_gas` | `pressure`, `volume`, `temperature`, `moles` | Ideal gas law (PV = nRT) |
|
|
76
|
+
| `engcalc.cycles` | `carnot_efficiency`, `otto_efficiency`, `diesel_efficiency`, `brayton_efficiency` | Thermodynamic cycle efficiencies |
|
|
77
|
+
| `engcalc.fluids` | `reynolds_number`, `flow_regime`, `bernoulli_pressure`, `darcy_weisbach_head_loss`, `pump_power` | Fluid mechanics |
|
|
78
|
+
| `engcalc.heat` | `conduction_rate`, `convection_rate`, `radiation_rate`, `lmtd` | Heat transfer |
|
|
79
|
+
| `engcalc.materials` | `get`, `get_all`, `list_materials`, `search`, `list_categories` | Material property database |
|
|
80
|
+
| `engcalc.units` | `convert`, `list_categories`, `list_units`, `find_category` | Unit conversion utilities |
|
|
81
|
+
|
|
82
|
+
## Examples
|
|
83
|
+
|
|
84
|
+
Check the [`examples/`](examples/) folder for complete demo scripts:
|
|
85
|
+
|
|
86
|
+
- `examples/demo.py` — Ideal gas law
|
|
87
|
+
- `examples/cycles_demo.py` — Thermodynamic cycles
|
|
88
|
+
- `examples/fluids_demo.py` — Fluid mechanics
|
|
89
|
+
- `examples/heat_demo.py` — Heat transfer
|
|
90
|
+
- `examples/materials_demo.py` — Materials database
|
|
91
|
+
- `examples/units_demo.py` — Unit conversions
|
|
92
|
+
|
|
93
|
+
Run any demo:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
python examples/cycles_demo.py
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Development
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
# Clone the repo
|
|
103
|
+
git clone https://github.com/ankidas687/engcalc.git
|
|
104
|
+
cd engcalc
|
|
105
|
+
|
|
106
|
+
# Create virtual environment
|
|
107
|
+
python -m venv venv
|
|
108
|
+
venv\Scripts\Activate.ps1 # Windows
|
|
109
|
+
# source venv/bin/activate # macOS/Linux
|
|
110
|
+
|
|
111
|
+
# Install with dev dependencies
|
|
112
|
+
pip install -e ".[dev]"
|
|
113
|
+
|
|
114
|
+
# Run tests
|
|
115
|
+
pytest
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Contributing
|
|
119
|
+
|
|
120
|
+
Contributions are welcome! If you find a bug or want to add a new
|
|
121
|
+
calculation, feel free to:
|
|
122
|
+
|
|
123
|
+
1. Fork the repo
|
|
124
|
+
2. Create a feature branch (`git checkout -b feature/new-formula`)
|
|
125
|
+
3. Commit your changes (`git commit -m "Add new formula"`)
|
|
126
|
+
4. Push to the branch (`git push origin feature/new-formula`)
|
|
127
|
+
5. Open a Pull Request
|
|
128
|
+
|
|
129
|
+
## Roadmap
|
|
130
|
+
|
|
131
|
+
- [x] Thermodynamics (ideal gas, cycles)
|
|
132
|
+
- [x] Fluid mechanics
|
|
133
|
+
- [x] Heat transfer
|
|
134
|
+
- [x] Materials database
|
|
135
|
+
- [x] Unit conversion utilities
|
|
136
|
+
- [ ] Mechanics of materials (stress, strain, beam)
|
|
137
|
+
- [ ] Publish to PyPI
|
|
138
|
+
|
|
139
|
+
## License
|
|
140
|
+
|
|
141
|
+
This project is licensed under the MIT License — see the [LICENSE](LICENSE) file for details.
|
|
142
|
+
|
|
143
|
+
## Author
|
|
144
|
+
|
|
145
|
+
**Ankita Das** — [@ankidas687](https://github.com/ankidas687)
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
⭐ If you find this useful, consider giving it a star!
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""Demo script for engcalc.cycles module."""
|
|
2
|
+
|
|
3
|
+
from engcalc import cycles
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def main():
|
|
7
|
+
print("=" * 55)
|
|
8
|
+
print("engcalc demo — Thermodynamic Cycles")
|
|
9
|
+
print("=" * 55)
|
|
10
|
+
|
|
11
|
+
# Carnot
|
|
12
|
+
eta_carnot = cycles.carnot_efficiency(T_hot=800, T_cold=300)
|
|
13
|
+
print(f"\nCarnot cycle (T_hot=800K, T_cold=300K):")
|
|
14
|
+
print(f" Efficiency: {eta_carnot * 100:.2f}%")
|
|
15
|
+
|
|
16
|
+
# Otto
|
|
17
|
+
eta_otto = cycles.otto_efficiency(compression_ratio=8)
|
|
18
|
+
print(f"\nOtto cycle (r=8, petrol engine):")
|
|
19
|
+
print(f" Efficiency: {eta_otto * 100:.2f}%")
|
|
20
|
+
|
|
21
|
+
# Diesel
|
|
22
|
+
eta_diesel = cycles.diesel_efficiency(compression_ratio=18, cutoff_ratio=2)
|
|
23
|
+
print(f"\nDiesel cycle (r=18, rc=2):")
|
|
24
|
+
print(f" Efficiency: {eta_diesel * 100:.2f}%")
|
|
25
|
+
|
|
26
|
+
# Brayton
|
|
27
|
+
eta_brayton = cycles.brayton_efficiency(pressure_ratio=10)
|
|
28
|
+
print(f"\nBrayton cycle (rp=10, gas turbine):")
|
|
29
|
+
print(f" Efficiency: {eta_brayton * 100:.2f}%")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
if __name__ == "__main__":
|
|
33
|
+
main()
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""Demo script for engcalc.ideal_gas module."""
|
|
2
|
+
|
|
3
|
+
from engcalc import ideal_gas
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def main():
|
|
7
|
+
print("=" * 50)
|
|
8
|
+
print("engcalc demo — Ideal Gas Law")
|
|
9
|
+
print("=" * 50)
|
|
10
|
+
|
|
11
|
+
# Standard case
|
|
12
|
+
n = 1.0 # moles
|
|
13
|
+
T = 300.0 # Kelvin
|
|
14
|
+
V = 0.024 # m^3
|
|
15
|
+
|
|
16
|
+
P = ideal_gas.pressure(n=n, T=T, V=V)
|
|
17
|
+
print(f"\nInput: n={n} mol, T={T} K, V={V} m^3")
|
|
18
|
+
print(f"Output: P = {P:.2f} Pa")
|
|
19
|
+
print(f" P = {P / 1000:.2f} kPa")
|
|
20
|
+
print(f" P = {P / 101325:.4f} atm")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
if __name__ == "__main__":
|
|
24
|
+
main()
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Demo script for engcalc.fluids module."""
|
|
2
|
+
|
|
3
|
+
from engcalc import fluids
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def main():
|
|
7
|
+
print("=" * 55)
|
|
8
|
+
print("engcalc demo — Fluid Mechanics")
|
|
9
|
+
print("=" * 55)
|
|
10
|
+
|
|
11
|
+
# Reynolds number
|
|
12
|
+
Re = fluids.reynolds_number(rho=1000, velocity=2, diameter=0.05, mu=0.001)
|
|
13
|
+
regime = fluids.flow_regime(Re)
|
|
14
|
+
print(f"\nReynolds number (water in pipe):")
|
|
15
|
+
print(f" rho=1000, v=2 m/s, D=0.05 m, mu=0.001")
|
|
16
|
+
print(f" Re = {Re:.0f} → {regime}")
|
|
17
|
+
|
|
18
|
+
# Bernoulli
|
|
19
|
+
P2 = fluids.bernoulli_pressure(
|
|
20
|
+
P1=101325, v1=0, h1=0, v2=5, h2=0, rho=1000
|
|
21
|
+
)
|
|
22
|
+
print(f"\nBernoulli equation:")
|
|
23
|
+
print(f" P1=101325 Pa, v1=0, v2=5 m/s")
|
|
24
|
+
print(f" P2 = {P2:.2f} Pa")
|
|
25
|
+
|
|
26
|
+
# Darcy-Weisbach
|
|
27
|
+
h_f = fluids.darcy_weisbach_head_loss(
|
|
28
|
+
f=0.02, L=100, D=0.05, velocity=2
|
|
29
|
+
)
|
|
30
|
+
print(f"\nDarcy-Weisbach head loss:")
|
|
31
|
+
print(f" f=0.02, L=100 m, D=0.05 m, v=2 m/s")
|
|
32
|
+
print(f" h_f = {h_f:.4f} m")
|
|
33
|
+
|
|
34
|
+
# Pump power
|
|
35
|
+
P = fluids.pump_power(rho=1000, g=9.81, Q=0.01, head=10, efficiency=0.8)
|
|
36
|
+
print(f"\nPump power:")
|
|
37
|
+
print(f" Q=0.01 m^3/s, head=10 m, eta=0.8")
|
|
38
|
+
print(f" P = {P:.2f} W ({P/1000:.3f} kW)")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
if __name__ == "__main__":
|
|
42
|
+
main()
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Demo script for engcalc.heat module."""
|
|
2
|
+
|
|
3
|
+
from engcalc import heat
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def main():
|
|
7
|
+
print("=" * 55)
|
|
8
|
+
print("engcalc demo — Heat Transfer")
|
|
9
|
+
print("=" * 55)
|
|
10
|
+
|
|
11
|
+
# Conduction
|
|
12
|
+
Q_cond = heat.conduction_rate(k=50, A=2, dT=100, L=0.1)
|
|
13
|
+
print(f"\nConduction through wall:")
|
|
14
|
+
print(f" k=50 W/(m·K), A=2 m², ΔT=100 K, L=0.1 m")
|
|
15
|
+
print(f" Q = {Q_cond:.2f} W ({Q_cond/1000:.2f} kW)")
|
|
16
|
+
|
|
17
|
+
# Convection
|
|
18
|
+
Q_conv = heat.convection_rate(h=25, A=2, T_surface=350, T_fluid=300)
|
|
19
|
+
print(f"\nConvection from surface:")
|
|
20
|
+
print(f" h=25 W/(m²·K), A=2 m², T_s=350 K, T_f=300 K")
|
|
21
|
+
print(f" Q = {Q_conv:.2f} W")
|
|
22
|
+
|
|
23
|
+
# Radiation
|
|
24
|
+
Q_rad = heat.radiation_rate(
|
|
25
|
+
emissivity=0.9, A=1, T_surface=500, T_surroundings=300
|
|
26
|
+
)
|
|
27
|
+
print(f"\nRadiation from surface:")
|
|
28
|
+
print(f" ε=0.9, A=1 m², T_s=500 K, T_sur=300 K")
|
|
29
|
+
print(f" Q = {Q_rad:.2f} W")
|
|
30
|
+
|
|
31
|
+
# LMTD
|
|
32
|
+
lmtd_val = heat.lmtd(
|
|
33
|
+
T_hot_in=400, T_hot_out=350, T_cold_in=300, T_cold_out=330
|
|
34
|
+
)
|
|
35
|
+
print(f"\nLMTD for heat exchanger:")
|
|
36
|
+
print(f" T_hot: 400 → 350, T_cold: 300 → 330")
|
|
37
|
+
print(f" LMTD = {lmtd_val:.2f} K")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
if __name__ == "__main__":
|
|
41
|
+
main()
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""Demo script for engcalc.materials module."""
|
|
2
|
+
|
|
3
|
+
from engcalc import materials
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def main():
|
|
7
|
+
print("=" * 60)
|
|
8
|
+
print("engcalc demo — Materials Database")
|
|
9
|
+
print("=" * 60)
|
|
10
|
+
|
|
11
|
+
# List all categories
|
|
12
|
+
cats = materials.list_categories()
|
|
13
|
+
print(f"\nAvailable categories ({len(cats)}):")
|
|
14
|
+
for c in cats:
|
|
15
|
+
print(f" - {c}")
|
|
16
|
+
|
|
17
|
+
# List all materials
|
|
18
|
+
all_mats = materials.list_materials()
|
|
19
|
+
print(f"\nTotal materials: {len(all_mats)}")
|
|
20
|
+
|
|
21
|
+
# Steel list
|
|
22
|
+
steels = materials.search("steel")
|
|
23
|
+
print(f"\nSteel grades ({len(steels)}):")
|
|
24
|
+
for s in steels:
|
|
25
|
+
print(f" - {s}")
|
|
26
|
+
|
|
27
|
+
# Aluminum list
|
|
28
|
+
aluminums = materials.search("aluminum")
|
|
29
|
+
print(f"\nAluminum alloys ({len(aluminums)}):")
|
|
30
|
+
for a in aluminums:
|
|
31
|
+
print(f" - {a}")
|
|
32
|
+
|
|
33
|
+
# Detailed properties of one material
|
|
34
|
+
print("\n" + "=" * 60)
|
|
35
|
+
print("Detailed: Aluminum 6061-T6")
|
|
36
|
+
print("=" * 60)
|
|
37
|
+
props = materials.get_all("aluminum_6061_T6")
|
|
38
|
+
for key, value in props.items():
|
|
39
|
+
if isinstance(value, float) and value > 1e6:
|
|
40
|
+
print(f" {key:25s}: {value:.3e}")
|
|
41
|
+
else:
|
|
42
|
+
print(f" {key:25s}: {value}")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
if __name__ == "__main__":
|
|
46
|
+
main()
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""Demo script for engcalc.units module."""
|
|
2
|
+
|
|
3
|
+
from engcalc import units
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def main():
|
|
7
|
+
print("=" * 60)
|
|
8
|
+
print("engcalc demo — Unit Conversion Utilities")
|
|
9
|
+
print("=" * 60)
|
|
10
|
+
|
|
11
|
+
# Categories
|
|
12
|
+
cats = units.list_categories()
|
|
13
|
+
print(f"\nSupported categories ({len(cats)}):")
|
|
14
|
+
for c in cats:
|
|
15
|
+
units_in_cat = units.list_units(c)
|
|
16
|
+
print(f" {c:12s} ({len(units_in_cat)} units): {', '.join(units_in_cat)}")
|
|
17
|
+
|
|
18
|
+
# Length
|
|
19
|
+
print("\n" + "=" * 60)
|
|
20
|
+
print("Length conversions")
|
|
21
|
+
print("=" * 60)
|
|
22
|
+
print(f" 100 cm = {units.convert(100, 'cm', 'm'):.4f} m")
|
|
23
|
+
print(f" 1 m = {units.convert(1, 'm', 'mm'):.1f} mm")
|
|
24
|
+
print(f" 1 in = {units.convert(1, 'in', 'cm'):.4f} cm")
|
|
25
|
+
print(f" 1 km = {units.convert(1, 'km', 'mile'):.6f} mile")
|
|
26
|
+
|
|
27
|
+
# Temperature
|
|
28
|
+
print("\n" + "=" * 60)
|
|
29
|
+
print("Temperature conversions")
|
|
30
|
+
print("=" * 60)
|
|
31
|
+
print(f" 100 °C = {units.convert(100, 'degC', 'K'):.2f} K")
|
|
32
|
+
print(f" 100 °C = {units.convert(100, 'degC', 'degF'):.2f} °F")
|
|
33
|
+
print(f" 32 °F = {units.convert(32, 'degF', 'degC'):.2f} °C")
|
|
34
|
+
print(f" 0 K = {units.convert(0, 'K', 'degC'):.2f} °C")
|
|
35
|
+
|
|
36
|
+
# Pressure
|
|
37
|
+
print("\n" + "=" * 60)
|
|
38
|
+
print("Pressure conversions")
|
|
39
|
+
print("=" * 60)
|
|
40
|
+
print(f" 1 atm = {units.convert(1, 'atm', 'Pa'):.2f} Pa")
|
|
41
|
+
print(f" 1 atm = {units.convert(1, 'atm', 'psi'):.4f} psi")
|
|
42
|
+
print(f" 1 bar = {units.convert(1, 'bar', 'Pa'):.2f} Pa")
|
|
43
|
+
print(f" 1 MPa = {units.convert(1, 'MPa', 'psi'):.4f} psi")
|
|
44
|
+
|
|
45
|
+
# Energy & Power
|
|
46
|
+
print("\n" + "=" * 60)
|
|
47
|
+
print("Energy & Power")
|
|
48
|
+
print("=" * 60)
|
|
49
|
+
print(f" 1 kWh = {units.convert(1, 'kWh', 'J'):.2e} J")
|
|
50
|
+
print(f" 1 BTU = {units.convert(1, 'BTU', 'J'):.2f} J")
|
|
51
|
+
print(f" 1 hp = {units.convert(1, 'hp', 'W'):.2f} W")
|
|
52
|
+
print(f" 1 hp = {units.convert(1, 'hp', 'kW'):.4f} kW")
|
|
53
|
+
|
|
54
|
+
# Fluid-related
|
|
55
|
+
print("\n" + "=" * 60)
|
|
56
|
+
print("Fluid & Mechanics")
|
|
57
|
+
print("=" * 60)
|
|
58
|
+
print(f" 1 lbf = {units.convert(1, 'lbf', 'N'):.4f} N")
|
|
59
|
+
print(f" 1 kgf = {units.convert(1, 'kgf', 'N'):.4f} N")
|
|
60
|
+
print(f" 36 km/h = {units.convert(36, 'km/h', 'm/s'):.4f} m/s")
|
|
61
|
+
print(f" 1 gal = {units.convert(1, 'gal_US', 'L'):.4f} L")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
if __name__ == "__main__":
|
|
65
|
+
main()
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "engcalc"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Mechanical Engineering calculations in Python"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Ankita Das", email = "ankidas687@gmail.com" }
|
|
14
|
+
]
|
|
15
|
+
dependencies = [
|
|
16
|
+
"numpy>=1.24",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.optional-dependencies]
|
|
20
|
+
dev = [
|
|
21
|
+
"pytest>=7.0",
|
|
22
|
+
"build>=1.0",
|
|
23
|
+
"twine>=4.0",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[tool.hatch.build.targets.wheel]
|
|
27
|
+
packages = ["src/engcalc"]
|