lima-lasercalc 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.
- lima_lasercalc-0.1.0/LICENSE +21 -0
- lima_lasercalc-0.1.0/PKG-INFO +153 -0
- lima_lasercalc-0.1.0/README.md +135 -0
- lima_lasercalc-0.1.0/lasercalc/__init__.py +38 -0
- lima_lasercalc-0.1.0/lasercalc/__main__.py +6 -0
- lima_lasercalc-0.1.0/lasercalc/_units.py +37 -0
- lima_lasercalc-0.1.0/lasercalc/cli.py +62 -0
- lima_lasercalc-0.1.0/lasercalc/energy.py +79 -0
- lima_lasercalc-0.1.0/lasercalc/gaussian.py +79 -0
- lima_lasercalc-0.1.0/lasercalc/pulse.py +61 -0
- lima_lasercalc-0.1.0/lima_lasercalc.egg-info/PKG-INFO +153 -0
- lima_lasercalc-0.1.0/lima_lasercalc.egg-info/SOURCES.txt +17 -0
- lima_lasercalc-0.1.0/lima_lasercalc.egg-info/dependency_links.txt +1 -0
- lima_lasercalc-0.1.0/lima_lasercalc.egg-info/entry_points.txt +2 -0
- lima_lasercalc-0.1.0/lima_lasercalc.egg-info/requires.txt +3 -0
- lima_lasercalc-0.1.0/lima_lasercalc.egg-info/top_level.txt +1 -0
- lima_lasercalc-0.1.0/pyproject.toml +28 -0
- lima_lasercalc-0.1.0/setup.cfg +4 -0
- lima_lasercalc-0.1.0/tests/test_all.py +122 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 LIMA
|
|
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.
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lima-lasercalc
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: 激光加工常用参数计算库(高斯光束 / 能量密度 / 脉冲参数)
|
|
5
|
+
Author: LIMA
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: laser,gaussian beam,energy density,laser processing
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
12
|
+
Requires-Python: >=3.9
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Provides-Extra: test
|
|
16
|
+
Requires-Dist: pytest>=7; extra == "test"
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# lasercalc
|
|
20
|
+
|
|
21
|
+
激光加工常用参数计算库 —— 高斯光束、能量密度、脉冲参数。
|
|
22
|
+
|
|
23
|
+
纯 Python 标准库实现,无第三方依赖。面向激光焊接、切割、打孔、熔覆、表面处理等工艺场景,以及激光光学光路设计。
|
|
24
|
+
|
|
25
|
+
## 完整版:LIMA-Tools 微信小程序
|
|
26
|
+
|
|
27
|
+
本库是 **LIMA-Tools 激光智造工程计算器** 的核心计算内核(开源版)。完整版本已作为微信小程序上线,包含 10 个工程计算器,覆盖从光路设计到工艺参数的全流程,支持原理图实时渲染、能量密度云图、扫描轨迹可视化。
|
|
28
|
+
|
|
29
|
+

|
|
30
|
+
|
|
31
|
+
**小程序功能覆盖**:
|
|
32
|
+
|
|
33
|
+
| 模块 | 说明 |
|
|
34
|
+
|---|---|
|
|
35
|
+
| 光路设计 | 从光纤到聚焦光斑,准直镜 / 扩束镜 / 聚焦镜实时渲染 |
|
|
36
|
+
| 能量密度 | 综合仿真与高斯云图(峰值 / 平均值 / 光斑面积) |
|
|
37
|
+
| 脉冲特性 | 单脉冲与搭接率(脉宽、重频、占空比、峰值功率) |
|
|
38
|
+
| 光斑计算 | 离焦光斑 w(z)、瑞利长度、发散角 |
|
|
39
|
+
| 工艺模式 | 连续 / 脉冲工艺参数换算 |
|
|
40
|
+
| 扫描轨迹 | 直线 / 圆形 / 8 字 / 正弦摆动与能量沉积 |
|
|
41
|
+
| 行业资讯 | 激光智造每日前沿速递 |
|
|
42
|
+
| 实时能量监测 | 工艺参数实时推算 |
|
|
43
|
+
|
|
44
|
+
特性:本地计算(无需联网)、工程级精度(科学可靠)、实时渲染(所见即所得)、随时随地(产线 / 会议 / 出差)。
|
|
45
|
+
|
|
46
|
+
> 微信搜索小程序「**LIMA-Tools**」或「**激光智造工程计算器**」即可使用;关注公众号「激光智造应用 LIMA」获取更新。
|
|
47
|
+
|
|
48
|
+
## 安装
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install lima-lasercalc
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
或从源码:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
git clone https://github.com/zhangyang99719-collab/lasercalc.git
|
|
58
|
+
cd lasercalc
|
|
59
|
+
pip install -e .
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## 快速开始
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from lasercalc import gaussian, energy, pulse
|
|
66
|
+
|
|
67
|
+
# 高斯光束:腰斑 10um,波长 1064nm,离焦 0.5mm 处的光斑半径
|
|
68
|
+
zr = gaussian.rayleigh_length(10, 1064e-9, unit="um") # 295.3 um
|
|
69
|
+
wz = gaussian.beam_radius(10, 500, 1064e-9, unit="um") # 19.67 um
|
|
70
|
+
|
|
71
|
+
# 能量密度:单脉冲 1mJ,光斑半径 100um
|
|
72
|
+
f0 = energy.peak_fluence(1e-3, 100, unit="um") # 6.37 J/cm²
|
|
73
|
+
|
|
74
|
+
# 脉冲参数:平均功率 200W,重频 50kHz,脉宽 100ns
|
|
75
|
+
e = pulse.pulse_energy(200, 50, freq_unit="kHz") # 4 mJ
|
|
76
|
+
pp = pulse.peak_power(e, 100, time_unit="ns") # 40 kW
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
命令行:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
lasercalc gaussian --w0 10 --z 0.5 --wl 1064
|
|
83
|
+
lasercalc energy --pulse-energy 1 --w0 100
|
|
84
|
+
lasercalc pulse --power 200 --rep-rate 50 --width 100
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## API 与公式
|
|
88
|
+
|
|
89
|
+
长度类函数统一通过 `unit=` 指定输入输出单位,返回与输入相同的单位。
|
|
90
|
+
支持 `m / mm / um / nm / cm`;时间 `s / ms / us / ns / ps / fs`;
|
|
91
|
+
功率 `W / kW / mW`;能量 `J / mJ / uJ / nJ`;频率 `Hz / kHz / MHz`。
|
|
92
|
+
|
|
93
|
+
### gaussian —— 高斯光束
|
|
94
|
+
|
|
95
|
+
采用 1/e² 强度半径定义(w0 为束腰半径)。
|
|
96
|
+
|
|
97
|
+
| 函数 | 公式 | 说明 |
|
|
98
|
+
|---|---|---|
|
|
99
|
+
| `rayleigh_length(w0, wl, m2, unit)` | z_R = π·w0² / (M²·λ) | 瑞利长度 |
|
|
100
|
+
| `beam_radius(w0, z, wl, m2, unit)` | w(z) = w0·√(1+(z/z_R)²) | 离焦光斑半径 |
|
|
101
|
+
| `peak_intensity(P, w0, unit)` | I0 = 2P/(π·w0²) | 峰值光强 W/m² |
|
|
102
|
+
| `average_intensity(P, w0, unit)` | I_avg = P/(π·w0²) | 平均光强 W/m² |
|
|
103
|
+
| `confocal_parameter(...)` | b = 2·z_R | 焦深范围 |
|
|
104
|
+
| `divergence_half_angle(w0, wl, m2, unit)` | θ = M²·λ/(π·w0) | 远场发散半角 rad |
|
|
105
|
+
| `M_squared(w0, θ, wl, unit)` | M² = π·w0·θ/λ | 光束质量因子 |
|
|
106
|
+
|
|
107
|
+
### energy —— 能量密度
|
|
108
|
+
|
|
109
|
+
高斯分布 F(r) = F0·exp(-2r²/w0²),单脉冲能量 E = F0·π·w0²/2。
|
|
110
|
+
|
|
111
|
+
| 函数 | 公式 | 说明 |
|
|
112
|
+
|---|---|---|
|
|
113
|
+
| `peak_fluence(E, w0, unit)` | F0 = 2E/(π·w0²) | 峰值能量密度 J/m² |
|
|
114
|
+
| `average_fluence(E, w0, unit)` | F_avg = E/(π·w0²) = F0/2 | 面积平均 |
|
|
115
|
+
| `pulse_energy_from_fluence(F0, w0, unit)` | E = F0·π·w0²/2 | 反算脉冲能量 |
|
|
116
|
+
| `line_energy_density(P, v, ...)` | E_lin = P/v | 线能量密度 J/m |
|
|
117
|
+
| `pulse_overlap(D, f, v, ...)` | η = 1 - v/(f·D) | 脉冲重叠率 |
|
|
118
|
+
| `spot_area(w0, unit)` | A = π·w0² | 光斑面积 m² |
|
|
119
|
+
|
|
120
|
+
### pulse —— 脉冲参数
|
|
121
|
+
|
|
122
|
+
| 函数 | 公式 | 说明 |
|
|
123
|
+
|---|---|---|
|
|
124
|
+
| `average_power(E, f, ...)` | P_avg = E·f | 平均功率 W |
|
|
125
|
+
| `pulse_energy(P, f, ...)` | E = P/f | 单脉冲能量 J |
|
|
126
|
+
| `peak_power(E, τ, shape, ...)` | P_peak = E/τ(矩形)或 0.94E/τ(高斯 FWHM) | 峰值功率 W |
|
|
127
|
+
| `duty_cycle(f, τ, ...)` | D = f·τ | 占空比 |
|
|
128
|
+
| `rep_rate_from_duty(D, τ, ...)` | f = D/τ | 反算重频 |
|
|
129
|
+
|
|
130
|
+
## 工程注意事项
|
|
131
|
+
|
|
132
|
+
1. **1/e² 与 FWHM 的区别**:本库光斑半径均按 1/e² 强度定义。若你的测量设备给的是 FWHM 光斑直径,需先换算:w_1/e² ≈ FWHM/1.699。
|
|
133
|
+
2. **峰值 vs 平均**:高斯光斑的峰值能量密度是面积平均值的 2 倍,烧蚀阈值判断应使用峰值。
|
|
134
|
+
3. **脉宽与峰值功率**:`shape="rect"` 为方波近似;超短脉冲激光建议用 `shape="gauss"`(0.94 系数,τ 取 FWHM)。
|
|
135
|
+
4. **单位一致性**:所有 `unit` 参数同时作用于该函数的长度输入与返回值;波长 `wl` 始终以米传入。
|
|
136
|
+
|
|
137
|
+
## 测试
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
pip install -e ".[test]"
|
|
141
|
+
pytest tests/ -q
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
17 个单元测试覆盖解析值、单位换算、边界与异常输入。
|
|
145
|
+
|
|
146
|
+
## 关联项目
|
|
147
|
+
|
|
148
|
+
- **LIMA-Tools 微信小程序**:本库的完整图形化版本(10 个工程计算器 + 实时原理图 + 能量云图),微信搜索「LIMA-Tools」。
|
|
149
|
+
- **激光智造应用 LIMA**:技术公众号,激光制造行业应用资讯与工艺干货。
|
|
150
|
+
|
|
151
|
+
## License
|
|
152
|
+
|
|
153
|
+
MIT © 2026 LIMA
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# lasercalc
|
|
2
|
+
|
|
3
|
+
激光加工常用参数计算库 —— 高斯光束、能量密度、脉冲参数。
|
|
4
|
+
|
|
5
|
+
纯 Python 标准库实现,无第三方依赖。面向激光焊接、切割、打孔、熔覆、表面处理等工艺场景,以及激光光学光路设计。
|
|
6
|
+
|
|
7
|
+
## 完整版:LIMA-Tools 微信小程序
|
|
8
|
+
|
|
9
|
+
本库是 **LIMA-Tools 激光智造工程计算器** 的核心计算内核(开源版)。完整版本已作为微信小程序上线,包含 10 个工程计算器,覆盖从光路设计到工艺参数的全流程,支持原理图实时渲染、能量密度云图、扫描轨迹可视化。
|
|
10
|
+
|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
**小程序功能覆盖**:
|
|
14
|
+
|
|
15
|
+
| 模块 | 说明 |
|
|
16
|
+
|---|---|
|
|
17
|
+
| 光路设计 | 从光纤到聚焦光斑,准直镜 / 扩束镜 / 聚焦镜实时渲染 |
|
|
18
|
+
| 能量密度 | 综合仿真与高斯云图(峰值 / 平均值 / 光斑面积) |
|
|
19
|
+
| 脉冲特性 | 单脉冲与搭接率(脉宽、重频、占空比、峰值功率) |
|
|
20
|
+
| 光斑计算 | 离焦光斑 w(z)、瑞利长度、发散角 |
|
|
21
|
+
| 工艺模式 | 连续 / 脉冲工艺参数换算 |
|
|
22
|
+
| 扫描轨迹 | 直线 / 圆形 / 8 字 / 正弦摆动与能量沉积 |
|
|
23
|
+
| 行业资讯 | 激光智造每日前沿速递 |
|
|
24
|
+
| 实时能量监测 | 工艺参数实时推算 |
|
|
25
|
+
|
|
26
|
+
特性:本地计算(无需联网)、工程级精度(科学可靠)、实时渲染(所见即所得)、随时随地(产线 / 会议 / 出差)。
|
|
27
|
+
|
|
28
|
+
> 微信搜索小程序「**LIMA-Tools**」或「**激光智造工程计算器**」即可使用;关注公众号「激光智造应用 LIMA」获取更新。
|
|
29
|
+
|
|
30
|
+
## 安装
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install lima-lasercalc
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
或从源码:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
git clone https://github.com/zhangyang99719-collab/lasercalc.git
|
|
40
|
+
cd lasercalc
|
|
41
|
+
pip install -e .
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 快速开始
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from lasercalc import gaussian, energy, pulse
|
|
48
|
+
|
|
49
|
+
# 高斯光束:腰斑 10um,波长 1064nm,离焦 0.5mm 处的光斑半径
|
|
50
|
+
zr = gaussian.rayleigh_length(10, 1064e-9, unit="um") # 295.3 um
|
|
51
|
+
wz = gaussian.beam_radius(10, 500, 1064e-9, unit="um") # 19.67 um
|
|
52
|
+
|
|
53
|
+
# 能量密度:单脉冲 1mJ,光斑半径 100um
|
|
54
|
+
f0 = energy.peak_fluence(1e-3, 100, unit="um") # 6.37 J/cm²
|
|
55
|
+
|
|
56
|
+
# 脉冲参数:平均功率 200W,重频 50kHz,脉宽 100ns
|
|
57
|
+
e = pulse.pulse_energy(200, 50, freq_unit="kHz") # 4 mJ
|
|
58
|
+
pp = pulse.peak_power(e, 100, time_unit="ns") # 40 kW
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
命令行:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
lasercalc gaussian --w0 10 --z 0.5 --wl 1064
|
|
65
|
+
lasercalc energy --pulse-energy 1 --w0 100
|
|
66
|
+
lasercalc pulse --power 200 --rep-rate 50 --width 100
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## API 与公式
|
|
70
|
+
|
|
71
|
+
长度类函数统一通过 `unit=` 指定输入输出单位,返回与输入相同的单位。
|
|
72
|
+
支持 `m / mm / um / nm / cm`;时间 `s / ms / us / ns / ps / fs`;
|
|
73
|
+
功率 `W / kW / mW`;能量 `J / mJ / uJ / nJ`;频率 `Hz / kHz / MHz`。
|
|
74
|
+
|
|
75
|
+
### gaussian —— 高斯光束
|
|
76
|
+
|
|
77
|
+
采用 1/e² 强度半径定义(w0 为束腰半径)。
|
|
78
|
+
|
|
79
|
+
| 函数 | 公式 | 说明 |
|
|
80
|
+
|---|---|---|
|
|
81
|
+
| `rayleigh_length(w0, wl, m2, unit)` | z_R = π·w0² / (M²·λ) | 瑞利长度 |
|
|
82
|
+
| `beam_radius(w0, z, wl, m2, unit)` | w(z) = w0·√(1+(z/z_R)²) | 离焦光斑半径 |
|
|
83
|
+
| `peak_intensity(P, w0, unit)` | I0 = 2P/(π·w0²) | 峰值光强 W/m² |
|
|
84
|
+
| `average_intensity(P, w0, unit)` | I_avg = P/(π·w0²) | 平均光强 W/m² |
|
|
85
|
+
| `confocal_parameter(...)` | b = 2·z_R | 焦深范围 |
|
|
86
|
+
| `divergence_half_angle(w0, wl, m2, unit)` | θ = M²·λ/(π·w0) | 远场发散半角 rad |
|
|
87
|
+
| `M_squared(w0, θ, wl, unit)` | M² = π·w0·θ/λ | 光束质量因子 |
|
|
88
|
+
|
|
89
|
+
### energy —— 能量密度
|
|
90
|
+
|
|
91
|
+
高斯分布 F(r) = F0·exp(-2r²/w0²),单脉冲能量 E = F0·π·w0²/2。
|
|
92
|
+
|
|
93
|
+
| 函数 | 公式 | 说明 |
|
|
94
|
+
|---|---|---|
|
|
95
|
+
| `peak_fluence(E, w0, unit)` | F0 = 2E/(π·w0²) | 峰值能量密度 J/m² |
|
|
96
|
+
| `average_fluence(E, w0, unit)` | F_avg = E/(π·w0²) = F0/2 | 面积平均 |
|
|
97
|
+
| `pulse_energy_from_fluence(F0, w0, unit)` | E = F0·π·w0²/2 | 反算脉冲能量 |
|
|
98
|
+
| `line_energy_density(P, v, ...)` | E_lin = P/v | 线能量密度 J/m |
|
|
99
|
+
| `pulse_overlap(D, f, v, ...)` | η = 1 - v/(f·D) | 脉冲重叠率 |
|
|
100
|
+
| `spot_area(w0, unit)` | A = π·w0² | 光斑面积 m² |
|
|
101
|
+
|
|
102
|
+
### pulse —— 脉冲参数
|
|
103
|
+
|
|
104
|
+
| 函数 | 公式 | 说明 |
|
|
105
|
+
|---|---|---|
|
|
106
|
+
| `average_power(E, f, ...)` | P_avg = E·f | 平均功率 W |
|
|
107
|
+
| `pulse_energy(P, f, ...)` | E = P/f | 单脉冲能量 J |
|
|
108
|
+
| `peak_power(E, τ, shape, ...)` | P_peak = E/τ(矩形)或 0.94E/τ(高斯 FWHM) | 峰值功率 W |
|
|
109
|
+
| `duty_cycle(f, τ, ...)` | D = f·τ | 占空比 |
|
|
110
|
+
| `rep_rate_from_duty(D, τ, ...)` | f = D/τ | 反算重频 |
|
|
111
|
+
|
|
112
|
+
## 工程注意事项
|
|
113
|
+
|
|
114
|
+
1. **1/e² 与 FWHM 的区别**:本库光斑半径均按 1/e² 强度定义。若你的测量设备给的是 FWHM 光斑直径,需先换算:w_1/e² ≈ FWHM/1.699。
|
|
115
|
+
2. **峰值 vs 平均**:高斯光斑的峰值能量密度是面积平均值的 2 倍,烧蚀阈值判断应使用峰值。
|
|
116
|
+
3. **脉宽与峰值功率**:`shape="rect"` 为方波近似;超短脉冲激光建议用 `shape="gauss"`(0.94 系数,τ 取 FWHM)。
|
|
117
|
+
4. **单位一致性**:所有 `unit` 参数同时作用于该函数的长度输入与返回值;波长 `wl` 始终以米传入。
|
|
118
|
+
|
|
119
|
+
## 测试
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
pip install -e ".[test]"
|
|
123
|
+
pytest tests/ -q
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
17 个单元测试覆盖解析值、单位换算、边界与异常输入。
|
|
127
|
+
|
|
128
|
+
## 关联项目
|
|
129
|
+
|
|
130
|
+
- **LIMA-Tools 微信小程序**:本库的完整图形化版本(10 个工程计算器 + 实时原理图 + 能量云图),微信搜索「LIMA-Tools」。
|
|
131
|
+
- **激光智造应用 LIMA**:技术公众号,激光制造行业应用资讯与工艺干货。
|
|
132
|
+
|
|
133
|
+
## License
|
|
134
|
+
|
|
135
|
+
MIT © 2026 LIMA
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""lasercalc - 激光加工常用参数计算库.
|
|
2
|
+
|
|
3
|
+
子模块:
|
|
4
|
+
gaussian : 高斯光束(腰斑、瑞利长度、离焦光斑、峰值光强)
|
|
5
|
+
energy : 能量密度(高斯面能量密度、线能量密度、脉冲重叠率)
|
|
6
|
+
pulse : 脉冲参数(平均/峰值功率、重频、占空比、单脉冲能量)
|
|
7
|
+
|
|
8
|
+
所有函数只依赖 Python 标准库。长度默认单位 m,功率 W,能量 J,时间 s,
|
|
9
|
+
角度 rad。函数均提供 unit= 参数以切换常用工程单位。
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from . import gaussian, energy, pulse
|
|
13
|
+
from .gaussian import (
|
|
14
|
+
beam_radius,
|
|
15
|
+
rayleigh_length,
|
|
16
|
+
peak_intensity,
|
|
17
|
+
confocal_parameter,
|
|
18
|
+
)
|
|
19
|
+
from .energy import (
|
|
20
|
+
peak_fluence,
|
|
21
|
+
average_fluence,
|
|
22
|
+
line_energy_density,
|
|
23
|
+
pulse_overlap,
|
|
24
|
+
)
|
|
25
|
+
from .pulse import (
|
|
26
|
+
average_power,
|
|
27
|
+
peak_power,
|
|
28
|
+
pulse_energy,
|
|
29
|
+
duty_cycle,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
__version__ = "0.1.0"
|
|
33
|
+
__all__ = [
|
|
34
|
+
"gaussian", "energy", "pulse",
|
|
35
|
+
"beam_radius", "rayleigh_length", "peak_intensity", "confocal_parameter",
|
|
36
|
+
"peak_fluence", "average_fluence", "line_energy_density", "pulse_overlap",
|
|
37
|
+
"average_power", "peak_power", "pulse_energy", "duty_cycle",
|
|
38
|
+
]
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""内部单位换算工具(相对 SI 的倍率)。"""
|
|
2
|
+
|
|
3
|
+
# 长度 -> m
|
|
4
|
+
LENGTH = {
|
|
5
|
+
"m": 1.0,
|
|
6
|
+
"mm": 1e-3,
|
|
7
|
+
"um": 1e-6, "µm": 1e-6, "micron": 1e-6,
|
|
8
|
+
"nm": 1e-9,
|
|
9
|
+
"cm": 1e-2,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
# 时间 -> s
|
|
13
|
+
TIME = {
|
|
14
|
+
"s": 1.0,
|
|
15
|
+
"ms": 1e-3,
|
|
16
|
+
"us": 1e-6, "µs": 1e-6, "ns": 1e-9,
|
|
17
|
+
"ps": 1e-12, "fs": 1e-15,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
# 功率 -> W
|
|
21
|
+
POWER = {"W": 1.0, "kW": 1e3, "mW": 1e-3, "MW": 1e6}
|
|
22
|
+
|
|
23
|
+
# 能量 -> J
|
|
24
|
+
ENERGY = {"J": 1.0, "mJ": 1e-3, "uJ": 1e-6, "µJ": 1e-6, "nJ": 1e-9}
|
|
25
|
+
|
|
26
|
+
# 频率 -> Hz
|
|
27
|
+
FREQ = {"Hz": 1.0, "kHz": 1e3, "MHz": 1e6, "GHz": 1e9}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def factor(table: dict, unit: str, kind: str) -> float:
|
|
31
|
+
"""返回单位换算倍率,未知单位抛出 ValueError 并给出可用选项。"""
|
|
32
|
+
try:
|
|
33
|
+
return table[unit]
|
|
34
|
+
except KeyError:
|
|
35
|
+
raise ValueError(
|
|
36
|
+
f"未知{kind}单位 {unit!r};可用: {', '.join(table)}"
|
|
37
|
+
) from None
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""命令行入口:python -m lasercalc 或安装后的 lasercalc 命令。"""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
|
|
5
|
+
from . import gaussian, energy, pulse
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def build_parser():
|
|
9
|
+
p = argparse.ArgumentParser(
|
|
10
|
+
prog="lasercalc",
|
|
11
|
+
description="激光加工参数计算器(高斯光束 / 能量密度 / 脉冲参数)",
|
|
12
|
+
)
|
|
13
|
+
sub = p.add_subparsers(dest="cmd")
|
|
14
|
+
|
|
15
|
+
g = sub.add_parser("gaussian", help="高斯光束计算")
|
|
16
|
+
g.add_argument("--w0", type=float, required=True, help="束腰半径 1/e² (um)")
|
|
17
|
+
g.add_argument("--z", type=float, default=0.0, help="离焦距离 (mm)")
|
|
18
|
+
g.add_argument("--wl", type=float, default=1064, help="波长 (nm)")
|
|
19
|
+
g.add_argument("--m2", type=float, default=1.0, help="光束质量因子 M²")
|
|
20
|
+
|
|
21
|
+
e = sub.add_parser("energy", help="能量密度计算")
|
|
22
|
+
e.add_argument("--pulse-energy", type=float, required=True, help="单脉冲能量 (mJ)")
|
|
23
|
+
e.add_argument("--w0", type=float, required=True, help="光斑半径 1/e² (um)")
|
|
24
|
+
|
|
25
|
+
q = sub.add_parser("pulse", help="脉冲参数计算")
|
|
26
|
+
q.add_argument("--power", type=float, required=True, help="平均功率 (W)")
|
|
27
|
+
q.add_argument("--rep-rate", type=float, required=True, help="重复频率 (kHz)")
|
|
28
|
+
q.add_argument("--width", type=float, default=0.0, help="脉宽 (ns),给出则算峰值功率")
|
|
29
|
+
|
|
30
|
+
return p
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def main(argv=None):
|
|
34
|
+
args = build_parser().parse_args(argv)
|
|
35
|
+
if args.cmd == "gaussian":
|
|
36
|
+
w0_um, z_mm = args.w0, args.z
|
|
37
|
+
wl = args.wl * 1e-9
|
|
38
|
+
z_um = z_mm * 1e3 # CLI 输入 z 用 mm,内部统一 um
|
|
39
|
+
zr_um = gaussian.rayleigh_length(w0_um, wl, args.m2, unit="um")
|
|
40
|
+
wz = gaussian.beam_radius(w0_um, z_um, wl, args.m2, unit="um") if z_mm else w0_um
|
|
41
|
+
theta = gaussian.divergence_half_angle(w0_um, wl, args.m2, unit="um")
|
|
42
|
+
print(f"瑞利长度 z_R : {zr_um*1e-3:10.3f} mm")
|
|
43
|
+
print(f"离焦光斑 w(z): {wz:10.3f} um (z={z_mm} mm)")
|
|
44
|
+
print(f"发散半角 θ : {theta*1e3:10.3f} mrad")
|
|
45
|
+
elif args.cmd == "energy":
|
|
46
|
+
f0 = energy.peak_fluence(args.pulse_energy * 1e-3, args.w0, unit="um")
|
|
47
|
+
favg = energy.average_fluence(args.pulse_energy * 1e-3, args.w0, unit="um")
|
|
48
|
+
print(f"峰值能量密度 F0 : {f0/1e4:10.3f} J/cm²")
|
|
49
|
+
print(f"面积平均能量密度 : {favg/1e4:10.3f} J/cm²")
|
|
50
|
+
elif args.cmd == "pulse":
|
|
51
|
+
ep = pulse.pulse_energy(args.power, args.rep_rate,
|
|
52
|
+
freq_unit="kHz")
|
|
53
|
+
print(f"单脉冲能量 E : {ep*1e3:10.4f} mJ")
|
|
54
|
+
if args.width:
|
|
55
|
+
pp = pulse.peak_power(ep, args.width, time_unit="ns")
|
|
56
|
+
print(f"峰值功率 P_peak: {pp/1e3:10.3f} kW (矩形近似)")
|
|
57
|
+
else:
|
|
58
|
+
build_parser().print_help()
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
if __name__ == "__main__":
|
|
62
|
+
main()
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""能量密度计算。
|
|
2
|
+
|
|
3
|
+
约定:激光加工中"能量密度"通常指峰值能量密度(脉冲能量/1/e² 光斑面积)。
|
|
4
|
+
本模块同时提供峰值与面积平均值,避免混淆。
|
|
5
|
+
|
|
6
|
+
高斯能量密度分布:F(r) = F0·exp(-2r²/w0²)
|
|
7
|
+
单脉冲能量 E = ∫F dA = F0·(π·w0²/2) => F0 = 2E / (π·w0²)
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import math
|
|
11
|
+
|
|
12
|
+
from ._units import LENGTH, POWER, factor
|
|
13
|
+
|
|
14
|
+
_DEF_WAVELENGTH = 1064e-9
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def peak_fluence(pulse_energy, w0, unit="m"):
|
|
18
|
+
"""峰值能量密度 F0(J/m²)= 2E / (π·w0²)。
|
|
19
|
+
|
|
20
|
+
pulse_energy 单脉冲能量(J),w0 为 1/e² 光斑半径。
|
|
21
|
+
"""
|
|
22
|
+
w0m = w0 * factor(LENGTH, unit, "长度")
|
|
23
|
+
if w0m <= 0:
|
|
24
|
+
raise ValueError("w0 必须为正数")
|
|
25
|
+
return 2 * pulse_energy / (math.pi * w0m ** 2)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def average_fluence(pulse_energy, w0, unit="m"):
|
|
29
|
+
"""面积平均能量密度(J/m²)= E / (π·w0²) = F0/2。"""
|
|
30
|
+
w0m = w0 * factor(LENGTH, unit, "长度")
|
|
31
|
+
if w0m <= 0:
|
|
32
|
+
raise ValueError("w0 必须为正数")
|
|
33
|
+
return pulse_energy / (math.pi * w0m ** 2)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def pulse_energy_from_fluence(fluence, w0, unit="m"):
|
|
37
|
+
"""由峰值能量密度 F0 反求单脉冲能量 E(J)= F0·π·w0²/2。"""
|
|
38
|
+
w0m = w0 * factor(LENGTH, unit, "长度")
|
|
39
|
+
if w0m <= 0:
|
|
40
|
+
raise ValueError("w0 必须为正数")
|
|
41
|
+
return fluence * math.pi * w0m ** 2 / 2
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def line_energy_density(power, speed, power_unit="W", speed_unit="m/s"):
|
|
45
|
+
"""线能量密度(J/m)= P / v。典型用于激光焊接/切割/熔覆。
|
|
46
|
+
|
|
47
|
+
speed 可为扫描速度(m/s、mm/s 等)。
|
|
48
|
+
"""
|
|
49
|
+
p = power * factor(POWER, power_unit, "功率")
|
|
50
|
+
SPEED = {"m/s": 1.0, "mm/s": 1e-3, "cm/s": 1e-2, "m/min": 1 / 60}
|
|
51
|
+
v = speed * factor(SPEED, speed_unit, "速度")
|
|
52
|
+
if v <= 0:
|
|
53
|
+
raise ValueError("speed 必须为正数")
|
|
54
|
+
return p / v
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def pulse_overlap(spot_diameter, rep_rate, speed,
|
|
58
|
+
spot_unit="m", speed_unit="m/s", freq_unit="Hz"):
|
|
59
|
+
"""相邻脉冲重叠率 = 1 - v / (f·D)。
|
|
60
|
+
|
|
61
|
+
其中 D 为光斑直径(2·w0),f 为重复频率,v 为扫描速度。
|
|
62
|
+
speed >= f·D 时返回 0(无重叠)。返回值 0~1。
|
|
63
|
+
"""
|
|
64
|
+
SPEED = {"m/s": 1.0, "mm/s": 1e-3, "cm/s": 1e-2, "m/min": 1 / 60}
|
|
65
|
+
d = spot_diameter * factor(LENGTH, spot_unit, "长度")
|
|
66
|
+
v = speed * factor(SPEED, speed_unit, "速度")
|
|
67
|
+
f = rep_rate * factor({"Hz": 1.0, "kHz": 1e3, "MHz": 1e6}, freq_unit, "频率")
|
|
68
|
+
if d <= 0 or f <= 0 or v < 0:
|
|
69
|
+
raise ValueError("spot_diameter、rep_rate 必须为正,speed 非负")
|
|
70
|
+
pitch = v / f
|
|
71
|
+
return max(0.0, 1.0 - pitch / d)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def spot_area(w0, unit="m"):
|
|
75
|
+
"""1/e² 光斑圆面积(m²)= π·w0²。"""
|
|
76
|
+
w0m = w0 * factor(LENGTH, unit, "长度")
|
|
77
|
+
if w0m <= 0:
|
|
78
|
+
raise ValueError("w0 必须为正数")
|
|
79
|
+
return math.pi * w0m ** 2
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""高斯光束计算(基于 1/e² 强度半径定义)。
|
|
2
|
+
|
|
3
|
+
约定:
|
|
4
|
+
* w0 为束腰半径(1/e² 强度处),单位由 ``unit`` 指定,默认 m。
|
|
5
|
+
* 波长 wavelength 默认 1064 nm(Nd:YAG / 光纤激光常用)。
|
|
6
|
+
* M² = 1 表示理想基模高斯光束;实际光束 M² > 1。
|
|
7
|
+
* 瑞利长度 z_R = π·w0² / (M²·λ);离焦光斑 w(z) = w0·sqrt(1+(z/z_R)²)。
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import math
|
|
11
|
+
|
|
12
|
+
from ._units import LENGTH, factor
|
|
13
|
+
|
|
14
|
+
_DEF_WAVELENGTH = 1064e-9 # m
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def rayleigh_length(w0, wavelength=_DEF_WAVELENGTH, m2=1.0, unit="m"):
|
|
18
|
+
"""瑞利长度 z_R,返回与 ``unit`` 相同的单位。z_R = π·w0² / (M²·λ)。"""
|
|
19
|
+
f = factor(LENGTH, unit, "长度")
|
|
20
|
+
w0m = w0 * f
|
|
21
|
+
if w0m <= 0 or wavelength <= 0 or m2 <= 0:
|
|
22
|
+
raise ValueError("w0、wavelength、m2 必须为正数")
|
|
23
|
+
return math.pi * w0m ** 2 / (m2 * wavelength) / f
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def beam_radius(w0, z, wavelength=_DEF_WAVELENGTH, m2=1.0, unit="m"):
|
|
27
|
+
"""离焦 z 处的 1/e² 光斑半径,返回与输入相同的单位。
|
|
28
|
+
|
|
29
|
+
w(z) = w0·sqrt(1 + (z/z_R)²)
|
|
30
|
+
"""
|
|
31
|
+
f = factor(LENGTH, unit, "长度")
|
|
32
|
+
w0m, zm = w0 * f, z * f
|
|
33
|
+
if w0m <= 0 or wavelength <= 0 or m2 <= 0:
|
|
34
|
+
raise ValueError("w0、wavelength、m2 必须为正数")
|
|
35
|
+
zr = math.pi * w0m ** 2 / (m2 * wavelength)
|
|
36
|
+
return (w0m * math.sqrt(1 + (zm / zr) ** 2)) / f
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def peak_intensity(power, w0, unit="m"):
|
|
40
|
+
"""束腰处峰值光强 I0(W/m²)—— I(r)=I0·exp(-2r²/w0²)。
|
|
41
|
+
|
|
42
|
+
I0 = 2P / (π·w0²)
|
|
43
|
+
"""
|
|
44
|
+
w0m = w0 * factor(LENGTH, unit, "长度")
|
|
45
|
+
if w0m <= 0:
|
|
46
|
+
raise ValueError("w0 必须为正数")
|
|
47
|
+
return 2 * power / (math.pi * w0m ** 2)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def average_intensity(power, w0, unit="m"):
|
|
51
|
+
"""光斑圆形面积(π·w0²)上的平均光强 I_avg(W/m²)= P / (π·w0²)。
|
|
52
|
+
|
|
53
|
+
注意:因高斯分布,I_avg = I0 / 2。
|
|
54
|
+
"""
|
|
55
|
+
w0m = w0 * factor(LENGTH, unit, "长度")
|
|
56
|
+
if w0m <= 0:
|
|
57
|
+
raise ValueError("w0 必须为正数")
|
|
58
|
+
return power / (math.pi * w0m ** 2)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def confocal_parameter(w0, wavelength=_DEF_WAVELENGTH, m2=1.0, unit="m"):
|
|
62
|
+
"""共焦参数 b = 2·z_R(m),即焦深范围。"""
|
|
63
|
+
return 2 * rayleigh_length(w0, wavelength, m2, unit)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def divergence_half_angle(w0, wavelength=_DEF_WAVELENGTH, m2=1.0, unit="m"):
|
|
67
|
+
"""远场发散半角 θ(rad)= M²·λ / (π·w0)。"""
|
|
68
|
+
w0m = w0 * factor(LENGTH, unit, "长度")
|
|
69
|
+
if w0m <= 0 or wavelength <= 0 or m2 <= 0:
|
|
70
|
+
raise ValueError("w0、wavelength、m2 必须为正数")
|
|
71
|
+
return m2 * wavelength / (math.pi * w0m)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def M_squared(w0, divergence, wavelength=_DEF_WAVELENGTH, unit="m"):
|
|
75
|
+
"""由束腰半径和远场发散半角反求光束质量因子 M²。"""
|
|
76
|
+
w0m = w0 * factor(LENGTH, unit, "长度")
|
|
77
|
+
if w0m <= 0 or divergence <= 0 or wavelength <= 0:
|
|
78
|
+
raise ValueError("w0、divergence、wavelength 必须为正数")
|
|
79
|
+
return math.pi * w0m * divergence / wavelength
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""脉冲激光参数计算:平均功率、峰值功率、单脉冲能量、占空比。
|
|
2
|
+
|
|
3
|
+
基本关系:E = P_avg / f,P_peak ≈ E / τ(矩形脉冲近似)。
|
|
4
|
+
若按高斯时间脉冲,峰值功率需乘形状系数 ≈ 0.94(FWHM 定义)。
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from ._units import ENERGY, FREQ, POWER, TIME, factor
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def average_power(pulse_energy, rep_rate, energy_unit="J", freq_unit="Hz"):
|
|
11
|
+
"""平均功率 P_avg(W)= E · f。"""
|
|
12
|
+
e = pulse_energy * factor(ENERGY, energy_unit, "能量")
|
|
13
|
+
f = rep_rate * factor(FREQ, freq_unit, "频率")
|
|
14
|
+
if e < 0 or f <= 0:
|
|
15
|
+
raise ValueError("pulse_energy 非负,rep_rate 必须为正")
|
|
16
|
+
return e * f
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def pulse_energy(average_power, rep_rate, power_unit="W", freq_unit="Hz"):
|
|
20
|
+
"""单脉冲能量 E(J)= P_avg / f。"""
|
|
21
|
+
p = average_power * factor(POWER, power_unit, "功率")
|
|
22
|
+
f = rep_rate * factor(FREQ, freq_unit, "频率")
|
|
23
|
+
if p <= 0 or f <= 0:
|
|
24
|
+
raise ValueError("average_power、rep_rate 必须为正")
|
|
25
|
+
return p / f
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def peak_power(pulse_energy, pulse_width, energy_unit="J",
|
|
29
|
+
time_unit="s", shape="rect"):
|
|
30
|
+
"""峰值功率 P_peak(W)。
|
|
31
|
+
|
|
32
|
+
shape="rect" -> E / τ
|
|
33
|
+
shape="gauss" -> 0.94 · E / τ (τ 为 FWHM 脉宽)
|
|
34
|
+
"""
|
|
35
|
+
e = pulse_energy * factor(ENERGY, energy_unit, "能量")
|
|
36
|
+
t = pulse_width * factor(TIME, time_unit, "时间")
|
|
37
|
+
if t <= 0:
|
|
38
|
+
raise ValueError("pulse_width 必须为正数")
|
|
39
|
+
k = {"rect": 1.0, "gauss": 0.94}.get(shape)
|
|
40
|
+
if k is None:
|
|
41
|
+
raise ValueError("shape 只能是 'rect' 或 'gauss'")
|
|
42
|
+
return k * e / t
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def duty_cycle(rep_rate, pulse_width, freq_unit="Hz", time_unit="s", percent=False):
|
|
46
|
+
"""占空比 = f · τ,默认返回 0~1 的小数;percent=True 返回百分数。"""
|
|
47
|
+
f = rep_rate * factor(FREQ, freq_unit, "频率")
|
|
48
|
+
t = pulse_width * factor(TIME, time_unit, "时间")
|
|
49
|
+
d = f * t
|
|
50
|
+
if d > 1:
|
|
51
|
+
raise ValueError("占空比大于 1:脉宽与重频不匹配")
|
|
52
|
+
return d * 100 if percent else d
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def rep_rate_from_duty(duty, pulse_width, time_unit="s", percent=False):
|
|
56
|
+
"""由占空比与脉宽反求重复频率(Hz)。"""
|
|
57
|
+
t = pulse_width * factor(TIME, time_unit, "时间")
|
|
58
|
+
d = duty / 100 if percent else duty
|
|
59
|
+
if t <= 0 or d <= 0:
|
|
60
|
+
raise ValueError("duty、pulse_width 必须为正")
|
|
61
|
+
return d / t
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lima-lasercalc
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: 激光加工常用参数计算库(高斯光束 / 能量密度 / 脉冲参数)
|
|
5
|
+
Author: LIMA
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: laser,gaussian beam,energy density,laser processing
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
12
|
+
Requires-Python: >=3.9
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Provides-Extra: test
|
|
16
|
+
Requires-Dist: pytest>=7; extra == "test"
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# lasercalc
|
|
20
|
+
|
|
21
|
+
激光加工常用参数计算库 —— 高斯光束、能量密度、脉冲参数。
|
|
22
|
+
|
|
23
|
+
纯 Python 标准库实现,无第三方依赖。面向激光焊接、切割、打孔、熔覆、表面处理等工艺场景,以及激光光学光路设计。
|
|
24
|
+
|
|
25
|
+
## 完整版:LIMA-Tools 微信小程序
|
|
26
|
+
|
|
27
|
+
本库是 **LIMA-Tools 激光智造工程计算器** 的核心计算内核(开源版)。完整版本已作为微信小程序上线,包含 10 个工程计算器,覆盖从光路设计到工艺参数的全流程,支持原理图实时渲染、能量密度云图、扫描轨迹可视化。
|
|
28
|
+
|
|
29
|
+

|
|
30
|
+
|
|
31
|
+
**小程序功能覆盖**:
|
|
32
|
+
|
|
33
|
+
| 模块 | 说明 |
|
|
34
|
+
|---|---|
|
|
35
|
+
| 光路设计 | 从光纤到聚焦光斑,准直镜 / 扩束镜 / 聚焦镜实时渲染 |
|
|
36
|
+
| 能量密度 | 综合仿真与高斯云图(峰值 / 平均值 / 光斑面积) |
|
|
37
|
+
| 脉冲特性 | 单脉冲与搭接率(脉宽、重频、占空比、峰值功率) |
|
|
38
|
+
| 光斑计算 | 离焦光斑 w(z)、瑞利长度、发散角 |
|
|
39
|
+
| 工艺模式 | 连续 / 脉冲工艺参数换算 |
|
|
40
|
+
| 扫描轨迹 | 直线 / 圆形 / 8 字 / 正弦摆动与能量沉积 |
|
|
41
|
+
| 行业资讯 | 激光智造每日前沿速递 |
|
|
42
|
+
| 实时能量监测 | 工艺参数实时推算 |
|
|
43
|
+
|
|
44
|
+
特性:本地计算(无需联网)、工程级精度(科学可靠)、实时渲染(所见即所得)、随时随地(产线 / 会议 / 出差)。
|
|
45
|
+
|
|
46
|
+
> 微信搜索小程序「**LIMA-Tools**」或「**激光智造工程计算器**」即可使用;关注公众号「激光智造应用 LIMA」获取更新。
|
|
47
|
+
|
|
48
|
+
## 安装
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install lima-lasercalc
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
或从源码:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
git clone https://github.com/zhangyang99719-collab/lasercalc.git
|
|
58
|
+
cd lasercalc
|
|
59
|
+
pip install -e .
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## 快速开始
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from lasercalc import gaussian, energy, pulse
|
|
66
|
+
|
|
67
|
+
# 高斯光束:腰斑 10um,波长 1064nm,离焦 0.5mm 处的光斑半径
|
|
68
|
+
zr = gaussian.rayleigh_length(10, 1064e-9, unit="um") # 295.3 um
|
|
69
|
+
wz = gaussian.beam_radius(10, 500, 1064e-9, unit="um") # 19.67 um
|
|
70
|
+
|
|
71
|
+
# 能量密度:单脉冲 1mJ,光斑半径 100um
|
|
72
|
+
f0 = energy.peak_fluence(1e-3, 100, unit="um") # 6.37 J/cm²
|
|
73
|
+
|
|
74
|
+
# 脉冲参数:平均功率 200W,重频 50kHz,脉宽 100ns
|
|
75
|
+
e = pulse.pulse_energy(200, 50, freq_unit="kHz") # 4 mJ
|
|
76
|
+
pp = pulse.peak_power(e, 100, time_unit="ns") # 40 kW
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
命令行:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
lasercalc gaussian --w0 10 --z 0.5 --wl 1064
|
|
83
|
+
lasercalc energy --pulse-energy 1 --w0 100
|
|
84
|
+
lasercalc pulse --power 200 --rep-rate 50 --width 100
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## API 与公式
|
|
88
|
+
|
|
89
|
+
长度类函数统一通过 `unit=` 指定输入输出单位,返回与输入相同的单位。
|
|
90
|
+
支持 `m / mm / um / nm / cm`;时间 `s / ms / us / ns / ps / fs`;
|
|
91
|
+
功率 `W / kW / mW`;能量 `J / mJ / uJ / nJ`;频率 `Hz / kHz / MHz`。
|
|
92
|
+
|
|
93
|
+
### gaussian —— 高斯光束
|
|
94
|
+
|
|
95
|
+
采用 1/e² 强度半径定义(w0 为束腰半径)。
|
|
96
|
+
|
|
97
|
+
| 函数 | 公式 | 说明 |
|
|
98
|
+
|---|---|---|
|
|
99
|
+
| `rayleigh_length(w0, wl, m2, unit)` | z_R = π·w0² / (M²·λ) | 瑞利长度 |
|
|
100
|
+
| `beam_radius(w0, z, wl, m2, unit)` | w(z) = w0·√(1+(z/z_R)²) | 离焦光斑半径 |
|
|
101
|
+
| `peak_intensity(P, w0, unit)` | I0 = 2P/(π·w0²) | 峰值光强 W/m² |
|
|
102
|
+
| `average_intensity(P, w0, unit)` | I_avg = P/(π·w0²) | 平均光强 W/m² |
|
|
103
|
+
| `confocal_parameter(...)` | b = 2·z_R | 焦深范围 |
|
|
104
|
+
| `divergence_half_angle(w0, wl, m2, unit)` | θ = M²·λ/(π·w0) | 远场发散半角 rad |
|
|
105
|
+
| `M_squared(w0, θ, wl, unit)` | M² = π·w0·θ/λ | 光束质量因子 |
|
|
106
|
+
|
|
107
|
+
### energy —— 能量密度
|
|
108
|
+
|
|
109
|
+
高斯分布 F(r) = F0·exp(-2r²/w0²),单脉冲能量 E = F0·π·w0²/2。
|
|
110
|
+
|
|
111
|
+
| 函数 | 公式 | 说明 |
|
|
112
|
+
|---|---|---|
|
|
113
|
+
| `peak_fluence(E, w0, unit)` | F0 = 2E/(π·w0²) | 峰值能量密度 J/m² |
|
|
114
|
+
| `average_fluence(E, w0, unit)` | F_avg = E/(π·w0²) = F0/2 | 面积平均 |
|
|
115
|
+
| `pulse_energy_from_fluence(F0, w0, unit)` | E = F0·π·w0²/2 | 反算脉冲能量 |
|
|
116
|
+
| `line_energy_density(P, v, ...)` | E_lin = P/v | 线能量密度 J/m |
|
|
117
|
+
| `pulse_overlap(D, f, v, ...)` | η = 1 - v/(f·D) | 脉冲重叠率 |
|
|
118
|
+
| `spot_area(w0, unit)` | A = π·w0² | 光斑面积 m² |
|
|
119
|
+
|
|
120
|
+
### pulse —— 脉冲参数
|
|
121
|
+
|
|
122
|
+
| 函数 | 公式 | 说明 |
|
|
123
|
+
|---|---|---|
|
|
124
|
+
| `average_power(E, f, ...)` | P_avg = E·f | 平均功率 W |
|
|
125
|
+
| `pulse_energy(P, f, ...)` | E = P/f | 单脉冲能量 J |
|
|
126
|
+
| `peak_power(E, τ, shape, ...)` | P_peak = E/τ(矩形)或 0.94E/τ(高斯 FWHM) | 峰值功率 W |
|
|
127
|
+
| `duty_cycle(f, τ, ...)` | D = f·τ | 占空比 |
|
|
128
|
+
| `rep_rate_from_duty(D, τ, ...)` | f = D/τ | 反算重频 |
|
|
129
|
+
|
|
130
|
+
## 工程注意事项
|
|
131
|
+
|
|
132
|
+
1. **1/e² 与 FWHM 的区别**:本库光斑半径均按 1/e² 强度定义。若你的测量设备给的是 FWHM 光斑直径,需先换算:w_1/e² ≈ FWHM/1.699。
|
|
133
|
+
2. **峰值 vs 平均**:高斯光斑的峰值能量密度是面积平均值的 2 倍,烧蚀阈值判断应使用峰值。
|
|
134
|
+
3. **脉宽与峰值功率**:`shape="rect"` 为方波近似;超短脉冲激光建议用 `shape="gauss"`(0.94 系数,τ 取 FWHM)。
|
|
135
|
+
4. **单位一致性**:所有 `unit` 参数同时作用于该函数的长度输入与返回值;波长 `wl` 始终以米传入。
|
|
136
|
+
|
|
137
|
+
## 测试
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
pip install -e ".[test]"
|
|
141
|
+
pytest tests/ -q
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
17 个单元测试覆盖解析值、单位换算、边界与异常输入。
|
|
145
|
+
|
|
146
|
+
## 关联项目
|
|
147
|
+
|
|
148
|
+
- **LIMA-Tools 微信小程序**:本库的完整图形化版本(10 个工程计算器 + 实时原理图 + 能量云图),微信搜索「LIMA-Tools」。
|
|
149
|
+
- **激光智造应用 LIMA**:技术公众号,激光制造行业应用资讯与工艺干货。
|
|
150
|
+
|
|
151
|
+
## License
|
|
152
|
+
|
|
153
|
+
MIT © 2026 LIMA
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
lasercalc/__init__.py
|
|
5
|
+
lasercalc/__main__.py
|
|
6
|
+
lasercalc/_units.py
|
|
7
|
+
lasercalc/cli.py
|
|
8
|
+
lasercalc/energy.py
|
|
9
|
+
lasercalc/gaussian.py
|
|
10
|
+
lasercalc/pulse.py
|
|
11
|
+
lima_lasercalc.egg-info/PKG-INFO
|
|
12
|
+
lima_lasercalc.egg-info/SOURCES.txt
|
|
13
|
+
lima_lasercalc.egg-info/dependency_links.txt
|
|
14
|
+
lima_lasercalc.egg-info/entry_points.txt
|
|
15
|
+
lima_lasercalc.egg-info/requires.txt
|
|
16
|
+
lima_lasercalc.egg-info/top_level.txt
|
|
17
|
+
tests/test_all.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
lasercalc
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "lima-lasercalc"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "激光加工常用参数计算库(高斯光束 / 能量密度 / 脉冲参数)"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "LIMA" }]
|
|
13
|
+
keywords = ["laser", "gaussian beam", "energy density", "laser processing"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Topic :: Scientific/Engineering :: Physics",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.optional-dependencies]
|
|
22
|
+
test = ["pytest>=7"]
|
|
23
|
+
|
|
24
|
+
[tool.setuptools]
|
|
25
|
+
packages = ["lasercalc"]
|
|
26
|
+
|
|
27
|
+
[project.scripts]
|
|
28
|
+
lasercalc = "lasercalc.cli:main"
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"""lasercalc 单元测试(标准库 unittest,零依赖)。"""
|
|
2
|
+
|
|
3
|
+
import math
|
|
4
|
+
import sys
|
|
5
|
+
import os
|
|
6
|
+
import unittest
|
|
7
|
+
|
|
8
|
+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
9
|
+
|
|
10
|
+
from lasercalc import gaussian, energy, pulse # noqa: E402
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class TestGaussian(unittest.TestCase):
|
|
14
|
+
def test_rayleigh_length_ideal(self):
|
|
15
|
+
# w0=10um, λ=1064nm, M²=1 -> z_R = π*(1e-5)^2/1.064e-6 ≈ 0.2953mm = 295.3um
|
|
16
|
+
zr_um = gaussian.rayleigh_length(10, 1064e-9, 1.0, unit="um")
|
|
17
|
+
self.assertAlmostEqual(zr_um, 295.3, places=0)
|
|
18
|
+
self.assertAlmostEqual(zr_um * 1e-6, math.pi * (10e-6) ** 2 / 1064e-9, places=9)
|
|
19
|
+
zr_m = gaussian.rayleigh_length(10e-6, 1064e-9, 1.0, unit="m")
|
|
20
|
+
self.assertAlmostEqual(zr_m, 0.0002953, places=6)
|
|
21
|
+
|
|
22
|
+
def test_rayleigh_scales_inverse_m2(self):
|
|
23
|
+
z1 = gaussian.rayleigh_length(10, 1064e-9, 1.0, unit="um")
|
|
24
|
+
z2 = gaussian.rayleigh_length(10, 1064e-9, 2.0, unit="um")
|
|
25
|
+
self.assertAlmostEqual(z1, 2 * z2, places=9)
|
|
26
|
+
|
|
27
|
+
def test_beam_radius_at_rayleigh(self):
|
|
28
|
+
# z = z_R 时 w = sqrt(2)·w0
|
|
29
|
+
w0 = 10 # um
|
|
30
|
+
zr_um = gaussian.rayleigh_length(w0, 1064e-9, unit="um")
|
|
31
|
+
wz = gaussian.beam_radius(w0, zr_um, 1064e-9, unit="um")
|
|
32
|
+
self.assertAlmostEqual(wz, w0 * math.sqrt(2), places=6)
|
|
33
|
+
|
|
34
|
+
def test_beam_radius_zero_defocus(self):
|
|
35
|
+
self.assertAlmostEqual(
|
|
36
|
+
gaussian.beam_radius(15, 0, 1064e-9, unit="um"), 15, places=9)
|
|
37
|
+
|
|
38
|
+
def test_peak_average_intensity_ratio(self):
|
|
39
|
+
i0 = gaussian.peak_intensity(100, 20, unit="um")
|
|
40
|
+
iavg = gaussian.average_intensity(100, 20, unit="um")
|
|
41
|
+
self.assertAlmostEqual(i0, 2 * iavg, places=3)
|
|
42
|
+
# 光斑内积分应等于总功率
|
|
43
|
+
self.assertAlmostEqual(iavg * math.pi * (20e-6) ** 2, 100, places=6)
|
|
44
|
+
|
|
45
|
+
def test_divergence_m2(self):
|
|
46
|
+
th = gaussian.divergence_half_angle(10, 1064e-9, unit="um")
|
|
47
|
+
m2 = gaussian.M_squared(10, th, 1064e-9, unit="um")
|
|
48
|
+
self.assertAlmostEqual(m2, 1.0, places=9)
|
|
49
|
+
|
|
50
|
+
def test_invalid_input(self):
|
|
51
|
+
with self.assertRaises(ValueError):
|
|
52
|
+
gaussian.rayleigh_length(0)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class TestEnergy(unittest.TestCase):
|
|
56
|
+
def test_peak_fluence(self):
|
|
57
|
+
# E=1mJ, w0=100um -> F0 = 2e-3 / (π·(1e-4)^2) ≈ 63662 J/m² = 6.366 J/cm²
|
|
58
|
+
f0 = energy.peak_fluence(1e-3, 100, unit="um")
|
|
59
|
+
self.assertAlmostEqual(f0 / 1e4, 6.3662, places=3)
|
|
60
|
+
self.assertAlmostEqual(f0, 2 * energy.average_fluence(1e-3, 100, unit="um"))
|
|
61
|
+
|
|
62
|
+
def test_fluence_roundtrip(self):
|
|
63
|
+
e = 0.5e-3
|
|
64
|
+
f0 = energy.peak_fluence(e, 50, unit="um")
|
|
65
|
+
self.assertAlmostEqual(energy.pulse_energy_from_fluence(f0, 50, unit="um"), e)
|
|
66
|
+
|
|
67
|
+
def test_line_energy_density(self):
|
|
68
|
+
# P=200W, v=100mm/s -> 200 / 0.1 = 2000 J/m = 2 J/mm
|
|
69
|
+
led = energy.line_energy_density(200, 100, power_unit="W", speed_unit="mm/s")
|
|
70
|
+
self.assertAlmostEqual(led, 2000, places=6)
|
|
71
|
+
led2 = energy.line_energy_density(200, 6, power_unit="W", speed_unit="m/min")
|
|
72
|
+
self.assertAlmostEqual(led2, 2000, places=6)
|
|
73
|
+
|
|
74
|
+
def test_pulse_overlap(self):
|
|
75
|
+
# D=100um, f=100kHz, v=500mm/s -> pitch=5um, overlap=0.95
|
|
76
|
+
ov = energy.pulse_overlap(100, 100, 500,
|
|
77
|
+
spot_unit="um", speed_unit="mm/s", freq_unit="kHz")
|
|
78
|
+
self.assertAlmostEqual(ov, 0.95, places=9)
|
|
79
|
+
# 无重叠情况
|
|
80
|
+
ov0 = energy.pulse_overlap(10, 1, 100,
|
|
81
|
+
spot_unit="um", speed_unit="mm/s", freq_unit="kHz")
|
|
82
|
+
self.assertEqual(ov0, 0.0)
|
|
83
|
+
|
|
84
|
+
def test_spot_area(self):
|
|
85
|
+
self.assertAlmostEqual(energy.spot_area(1, unit="mm"), math.pi * 1e-6)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class TestPulse(unittest.TestCase):
|
|
89
|
+
def test_average_power(self):
|
|
90
|
+
# 1mJ @ 20kHz = 20W
|
|
91
|
+
self.assertAlmostEqual(
|
|
92
|
+
pulse.average_power(1, 20, energy_unit="mJ", freq_unit="kHz"), 20)
|
|
93
|
+
|
|
94
|
+
def test_pulse_energy_roundtrip(self):
|
|
95
|
+
p = pulse.average_power(2.5, 100, energy_unit="mJ", freq_unit="kHz")
|
|
96
|
+
self.assertAlmostEqual(pulse.pulse_energy(p, 100, freq_unit="kHz"), 2.5e-3)
|
|
97
|
+
|
|
98
|
+
def test_peak_power(self):
|
|
99
|
+
# 1mJ / 100ns = 10kW
|
|
100
|
+
self.assertAlmostEqual(
|
|
101
|
+
pulse.peak_power(1, 100, energy_unit="mJ", time_unit="ns"), 1e4)
|
|
102
|
+
# 高斯形状系数 0.94
|
|
103
|
+
self.assertAlmostEqual(
|
|
104
|
+
pulse.peak_power(1, 100, energy_unit="mJ", time_unit="ns", shape="gauss"),
|
|
105
|
+
0.94e4)
|
|
106
|
+
|
|
107
|
+
def test_duty_cycle(self):
|
|
108
|
+
# 100kHz × 100ns = 0.01 = 1%
|
|
109
|
+
d = pulse.duty_cycle(100, 100, freq_unit="kHz", time_unit="ns")
|
|
110
|
+
self.assertAlmostEqual(d, 0.01, places=9)
|
|
111
|
+
d2 = pulse.duty_cycle(100, 100, freq_unit="kHz", time_unit="ns", percent=True)
|
|
112
|
+
self.assertAlmostEqual(d2, 1.0, places=9)
|
|
113
|
+
f = pulse.rep_rate_from_duty(0.01, 100, time_unit="ns")
|
|
114
|
+
self.assertAlmostEqual(f, 1e5, places=6)
|
|
115
|
+
|
|
116
|
+
def test_invalid_shape(self):
|
|
117
|
+
with self.assertRaises(ValueError):
|
|
118
|
+
pulse.peak_power(1e-3, 1e-9, shape="triangle")
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
if __name__ == "__main__":
|
|
122
|
+
unittest.main()
|