osis-python 0.1.9__tar.gz → 0.2.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.
Files changed (66) hide show
  1. {osis_python-0.1.9/src/osis_python.egg-info → osis_python-0.2.0}/PKG-INFO +6 -17
  2. {osis_python-0.1.9 → osis_python-0.2.0}/README.md +5 -16
  3. {osis_python-0.1.9 → osis_python-0.2.0/src/osis_python.egg-info}/PKG-INFO +6 -17
  4. {osis_python-0.1.9 → osis_python-0.2.0}/src/osis_python.egg-info/SOURCES.txt +7 -3
  5. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/__init__.py +1 -1
  6. osis_python-0.2.0/src/pyosis/common/interface.py +110 -0
  7. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/control/interface.py +2 -2
  8. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/core/PyInterface.pyi +6 -0
  9. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/core/all_func.py +2 -1
  10. osis_python-0.2.0/src/pyosis/core/client.py +51 -0
  11. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/core/command.py +60 -17
  12. osis_python-0.2.0/src/pyosis/core/project.py +8 -0
  13. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/element/interface.py +1 -1
  14. osis_python-0.2.0/src/pyosis/post/__init__.py +2 -0
  15. osis_python-0.2.0/src/pyosis/post/check.py +133 -0
  16. osis_python-0.2.0/src/pyosis/post/loadcase.py +96 -0
  17. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/section/common.py +2 -70
  18. osis_python-0.2.0/tests/test.py +6 -0
  19. osis_python-0.1.9/src/pyosis/core/engine.py +0 -13
  20. osis_python-0.1.9/src/pyosis/core/project.py +0 -8
  21. osis_python-0.1.9/src/pyosis/post/interface.py +0 -21
  22. {osis_python-0.1.9 → osis_python-0.2.0}/LICENSE +0 -0
  23. {osis_python-0.1.9 → osis_python-0.2.0}/pyproject.toml +0 -0
  24. {osis_python-0.1.9 → osis_python-0.2.0}/setup.cfg +0 -0
  25. {osis_python-0.1.9 → osis_python-0.2.0}/src/osis_python.egg-info/dependency_links.txt +0 -0
  26. {osis_python-0.1.9 → osis_python-0.2.0}/src/osis_python.egg-info/requires.txt +0 -0
  27. {osis_python-0.1.9 → osis_python-0.2.0}/src/osis_python.egg-info/top_level.txt +0 -0
  28. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/boundary/__init__.py +0 -0
  29. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/boundary/interface.py +0 -0
  30. {osis_python-0.1.9/src/pyosis/control → osis_python-0.2.0/src/pyosis/common}/__init__.py +0 -0
  31. {osis_python-0.1.9/src/pyosis/element → osis_python-0.2.0/src/pyosis/control}/__init__.py +0 -0
  32. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/core/__init__.py +0 -0
  33. {osis_python-0.1.9/src/pyosis/general → osis_python-0.2.0/src/pyosis/element}/__init__.py +0 -0
  34. {osis_python-0.1.9/src/pyosis/geometry → osis_python-0.2.0/src/pyosis/general}/__init__.py +0 -0
  35. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/general/interface.py +0 -0
  36. {osis_python-0.1.9/src/pyosis/material → osis_python-0.2.0/src/pyosis/geometry}/__init__.py +0 -0
  37. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/geometry/interface.py +0 -0
  38. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/live/__init__.py +0 -0
  39. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/live/analysis.py +0 -0
  40. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/live/grade.py +0 -0
  41. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/live/lane.py +0 -0
  42. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/load/__init__.py +0 -0
  43. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/load/loadcase.py +0 -0
  44. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/load/static.py +0 -0
  45. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/load/tendon.py +0 -0
  46. {osis_python-0.1.9/src/pyosis/node → osis_python-0.2.0/src/pyosis/material}/__init__.py +0 -0
  47. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/material/interface.py +0 -0
  48. {osis_python-0.1.9/src/pyosis/post → osis_python-0.2.0/src/pyosis/node}/__init__.py +0 -0
  49. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/node/interface.py +0 -0
  50. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/property/__init__.py +0 -0
  51. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/property/coordinate.py +0 -0
  52. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/property/creep_shrink.py +0 -0
  53. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/property/damping.py +0 -0
  54. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/property/pu_curve.py +0 -0
  55. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/quick_building/__init__.py +0 -0
  56. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/quick_building/interface.py +0 -0
  57. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/section/__init__.py +0 -0
  58. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/section/io.py +0 -0
  59. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/section/numeric.py +0 -0
  60. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/section/param.py +0 -0
  61. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/section/rebar.py +0 -0
  62. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/section/rib.py +0 -0
  63. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/section/steel.py +0 -0
  64. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/stage/__init__.py +0 -0
  65. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/stage/define.py +0 -0
  66. {osis_python-0.1.9 → osis_python-0.2.0}/src/pyosis/stage/overall.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: osis-python
3
- Version: 0.1.9
3
+ Version: 0.2.0
4
4
  Summary: A Python client library for Osis APDL
5
5
  Author-email: "CCCC Highway Consultant Co. Ltd." <support@osisbim.com>
6
6
  License-Expression: MIT
@@ -59,23 +59,14 @@ pip install osis-python -i https://pypi.org/simple
59
59
 
60
60
  ## Usage
61
61
 
62
- First, install the latest version of OSIS (>=5.0) and configure the Python environment variables. pyosis requires Python 3.11 or higher. You need to set PYTHONHOME in the environment variables to your Python installation directory, e.g., C:\Program Files\python, and set PYTHONIOENCODING to utf-8. Then add %PYTHONHOME% and %PYTHONHOME%\Scripts to the Path variable.
62
+ First, install the latest version of OSIS (>=5.0), which includes the required Python environment.
63
63
 
64
- Your scripts should be placed in the python folder under the OSIS installation directory, e.g., C:\Program Files\osis\python. Suppose there is a script named test_osis.py with the following content:
64
+ Switch AI assistant to command mode and send:
65
65
 
66
66
 
67
67
  ```python
68
68
  import json
69
- from pyosis.core import osis_run # Import required functions
70
- from pyosis.control import *
71
- from pyosis.general import *
72
- from pyosis.section import *
73
- from pyosis.material import *
74
- from pyosis.node import *
75
- from pyosis.element import *
76
- from pyosis.boundary import *
77
- from pyosis.load import *
78
- from pyosis.post import *
69
+ from pyosis.core.all_func import *
79
70
 
80
71
  osis_clear()
81
72
 
@@ -120,10 +111,8 @@ osis_loadcase("Custom Load Case 1", "USER", 1, "Two forces applied at nodes 3 an
120
111
  osis_load_nforce("NFORCE", "Custom Load Case 1", 3, 0, -1000000, 0, 0, 0, 0)
121
112
  osis_load_nforce("NFORCE", "Custom Load Case 1", 4, 200000, 0, 0, 0, 0, 0)
122
113
 
123
- # osis_solve()
124
-
125
- print(osis_run()) # Let OSIS execute all preprocessing commands
114
+ osis_solve()
126
115
 
127
116
  ```
128
117
 
129
- Select and run this script in OSIS. If everything is normal, you will see OSIS finish the preprocessing.
118
+ If everything is normal, you will see OSIS finish the processing.
@@ -20,23 +20,14 @@ pip install osis-python -i https://pypi.org/simple
20
20
 
21
21
  ## Usage
22
22
 
23
- First, install the latest version of OSIS (>=5.0) and configure the Python environment variables. pyosis requires Python 3.11 or higher. You need to set PYTHONHOME in the environment variables to your Python installation directory, e.g., C:\Program Files\python, and set PYTHONIOENCODING to utf-8. Then add %PYTHONHOME% and %PYTHONHOME%\Scripts to the Path variable.
23
+ First, install the latest version of OSIS (>=5.0), which includes the required Python environment.
24
24
 
25
- Your scripts should be placed in the python folder under the OSIS installation directory, e.g., C:\Program Files\osis\python. Suppose there is a script named test_osis.py with the following content:
25
+ Switch AI assistant to command mode and send:
26
26
 
27
27
 
28
28
  ```python
29
29
  import json
30
- from pyosis.core import osis_run # Import required functions
31
- from pyosis.control import *
32
- from pyosis.general import *
33
- from pyosis.section import *
34
- from pyosis.material import *
35
- from pyosis.node import *
36
- from pyosis.element import *
37
- from pyosis.boundary import *
38
- from pyosis.load import *
39
- from pyosis.post import *
30
+ from pyosis.core.all_func import *
40
31
 
41
32
  osis_clear()
42
33
 
@@ -81,10 +72,8 @@ osis_loadcase("Custom Load Case 1", "USER", 1, "Two forces applied at nodes 3 an
81
72
  osis_load_nforce("NFORCE", "Custom Load Case 1", 3, 0, -1000000, 0, 0, 0, 0)
82
73
  osis_load_nforce("NFORCE", "Custom Load Case 1", 4, 200000, 0, 0, 0, 0, 0)
83
74
 
84
- # osis_solve()
85
-
86
- print(osis_run()) # Let OSIS execute all preprocessing commands
75
+ osis_solve()
87
76
 
88
77
  ```
89
78
 
90
- Select and run this script in OSIS. If everything is normal, you will see OSIS finish the preprocessing.
79
+ If everything is normal, you will see OSIS finish the processing.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: osis-python
3
- Version: 0.1.9
3
+ Version: 0.2.0
4
4
  Summary: A Python client library for Osis APDL
5
5
  Author-email: "CCCC Highway Consultant Co. Ltd." <support@osisbim.com>
6
6
  License-Expression: MIT
@@ -59,23 +59,14 @@ pip install osis-python -i https://pypi.org/simple
59
59
 
60
60
  ## Usage
61
61
 
62
- First, install the latest version of OSIS (>=5.0) and configure the Python environment variables. pyosis requires Python 3.11 or higher. You need to set PYTHONHOME in the environment variables to your Python installation directory, e.g., C:\Program Files\python, and set PYTHONIOENCODING to utf-8. Then add %PYTHONHOME% and %PYTHONHOME%\Scripts to the Path variable.
62
+ First, install the latest version of OSIS (>=5.0), which includes the required Python environment.
63
63
 
64
- Your scripts should be placed in the python folder under the OSIS installation directory, e.g., C:\Program Files\osis\python. Suppose there is a script named test_osis.py with the following content:
64
+ Switch AI assistant to command mode and send:
65
65
 
66
66
 
67
67
  ```python
68
68
  import json
69
- from pyosis.core import osis_run # Import required functions
70
- from pyosis.control import *
71
- from pyosis.general import *
72
- from pyosis.section import *
73
- from pyosis.material import *
74
- from pyosis.node import *
75
- from pyosis.element import *
76
- from pyosis.boundary import *
77
- from pyosis.load import *
78
- from pyosis.post import *
69
+ from pyosis.core.all_func import *
79
70
 
80
71
  osis_clear()
81
72
 
@@ -120,10 +111,8 @@ osis_loadcase("Custom Load Case 1", "USER", 1, "Two forces applied at nodes 3 an
120
111
  osis_load_nforce("NFORCE", "Custom Load Case 1", 3, 0, -1000000, 0, 0, 0, 0)
121
112
  osis_load_nforce("NFORCE", "Custom Load Case 1", 4, 200000, 0, 0, 0, 0, 0)
122
113
 
123
- # osis_solve()
124
-
125
- print(osis_run()) # Let OSIS execute all preprocessing commands
114
+ osis_solve()
126
115
 
127
116
  ```
128
117
 
129
- Select and run this script in OSIS. If everything is normal, you will see OSIS finish the preprocessing.
118
+ If everything is normal, you will see OSIS finish the processing.
@@ -9,13 +9,15 @@ src/osis_python.egg-info/top_level.txt
9
9
  src/pyosis/__init__.py
10
10
  src/pyosis/boundary/__init__.py
11
11
  src/pyosis/boundary/interface.py
12
+ src/pyosis/common/__init__.py
13
+ src/pyosis/common/interface.py
12
14
  src/pyosis/control/__init__.py
13
15
  src/pyosis/control/interface.py
14
16
  src/pyosis/core/PyInterface.pyi
15
17
  src/pyosis/core/__init__.py
16
18
  src/pyosis/core/all_func.py
19
+ src/pyosis/core/client.py
17
20
  src/pyosis/core/command.py
18
- src/pyosis/core/engine.py
19
21
  src/pyosis/core/project.py
20
22
  src/pyosis/element/__init__.py
21
23
  src/pyosis/element/interface.py
@@ -36,7 +38,8 @@ src/pyosis/material/interface.py
36
38
  src/pyosis/node/__init__.py
37
39
  src/pyosis/node/interface.py
38
40
  src/pyosis/post/__init__.py
39
- src/pyosis/post/interface.py
41
+ src/pyosis/post/check.py
42
+ src/pyosis/post/loadcase.py
40
43
  src/pyosis/property/__init__.py
41
44
  src/pyosis/property/coordinate.py
42
45
  src/pyosis/property/creep_shrink.py
@@ -54,4 +57,5 @@ src/pyosis/section/rib.py
54
57
  src/pyosis/section/steel.py
55
58
  src/pyosis/stage/__init__.py
56
59
  src/pyosis/stage/define.py
57
- src/pyosis/stage/overall.py
60
+ src/pyosis/stage/overall.py
61
+ tests/test.py
@@ -7,7 +7,7 @@ A library for extending OSIS functionality.
7
7
  A library that allows users to use CAE with great flexibility.
8
8
  """
9
9
 
10
- __version__ = "0.1.9"
10
+ __version__ = "0.2.0"
11
11
  __author__ = "CCCC Highway Consultant Co. Ltd." # 中交公路规划设计院 - 工程技术研究中心
12
12
 
13
13
  # from .core import engine
@@ -0,0 +1,110 @@
1
+ from typing import Any, Dict, Literal, List, Union, Sequence
2
+ from ..core import REGISTRY, osis_run
3
+ from ..core.command import _log
4
+
5
+ def osis_matrix(matrix_name: str, matrix_data: Union[List, int, float, str]):
6
+ """
7
+ 将Python多维列表转换为OSIS DSL格式的矩阵定义和赋值语句。适用于自定义截面函数osis_section_custom、osis_section_steel_custom所需的坐标参数矩阵输入。
8
+
9
+ Args:
10
+ matrix_name: OSIS中的矩阵变量名
11
+ matrix_data: 任意维度的列表(1维/2维/3维/...)或单个数值(0维)
12
+
13
+ Returns:
14
+ OSIS DSL格式的字符串(拼接后的完整命令)
15
+
16
+ Example:
17
+ >>> # 2维矩阵示例
18
+ >>> matrix_2d = [[1, 2, 20], [2, 3, 25], [3, 4, 30], [4, 1, 25]]
19
+ >>> osis_matrix("LineMatrix", matrix_2d)
20
+ >>> # 3维矩阵示例
21
+ >>> matrix_3d = [[[1.5, 2.5], [3.5, 4.5]], [[5.5, 6.5], [7.5, 8.5]]]
22
+ >>> osis_matrix("CubeMatrix", matrix_3d)
23
+ >>> # 1维矩阵示例
24
+ >>> matrix_1d = [10, 20, 30, 40]
25
+ >>> osis_matrix("VectorMatrix", matrix_1d)
26
+ >>> # 0维矩阵示例
27
+ >>> matrix_0d = 10
28
+ >>> osis_matrix("ScalarMatrix", matrix_0d)
29
+ """
30
+ # 存储所有生成的命令
31
+ all_cmds = []
32
+
33
+ # 验证和获取矩阵维度信息
34
+ def get_dimensions_and_validate(data: Any) -> List[int]:
35
+ """递归获取矩阵维度并验证是否规则"""
36
+ dimensions = []
37
+ current = data
38
+
39
+ # 递归获取维度
40
+ while isinstance(current, list):
41
+ if not current:
42
+ dimensions.append(0)
43
+ break
44
+ dimensions.append(len(current))
45
+ # 检查当前维度下所有元素的子维度是否一致
46
+ first_sub_dim = get_dimensions_and_validate(current[0]) if isinstance(current[0], list) else []
47
+ for elem in current[1:]:
48
+ elem_sub_dim = get_dimensions_and_validate(elem) if isinstance(elem, list) else []
49
+ if elem_sub_dim != first_sub_dim:
50
+ raise ValueError(f"矩阵维度不规则:元素维度不一致,第一个元素维度={first_sub_dim},当前元素维度={elem_sub_dim}")
51
+ current = current[0]
52
+
53
+ # 处理0维(单个数值)
54
+ if not dimensions:
55
+ return [1] # 0维视为1x1矩阵
56
+
57
+ return dimensions
58
+
59
+ # 获取维度信息
60
+ try:
61
+ dims = get_dimensions_and_validate(matrix_data)
62
+ matrix_data = [matrix_data]
63
+ except Exception as e:
64
+ raise ValueError(f"矩阵验证失败:{str(e)}") from e
65
+
66
+ # 处理空矩阵
67
+ if any(d == 0 for d in dims):
68
+ raise ValueError("不支持空矩阵输入")
69
+
70
+ # 生成 *DIM 定义语句
71
+ # 如果数组元素为字符串,用charn定义
72
+ dim_type = "charn" if (isinstance(matrix_data, list) and isinstance(matrix_data[0], str)) or isinstance(matrix_data, str) else "*dim"
73
+
74
+ dim_str = ",".join(map(str, dims))
75
+ dim_cmd = f"{dim_type},{matrix_name},{dim_str}"
76
+
77
+ all_cmds.append(dim_cmd)
78
+
79
+ # 递归生成赋值语句
80
+ def generate_assignments(data: Any, indices: List):
81
+ """递归遍历矩阵并生成赋值语句"""
82
+ if isinstance(data, list):
83
+ for idx, elem in enumerate(data):
84
+ new_indices = indices + [idx]
85
+ generate_assignments(elem, new_indices)
86
+ else:
87
+ # 处理数值赋值
88
+ value = data
89
+
90
+ # 格式化数值
91
+ if isinstance(value, int) or isinstance(value, float):
92
+ val_str = str(value)
93
+ else:
94
+ # 其他类型尝试转为string
95
+ val_str = f"\"{value}\""
96
+
97
+ # 生成OSIS赋值命令
98
+ idx_str = ",".join(map(str, indices))
99
+ assign_cmd = f"{matrix_name}[{idx_str}] = {val_str}"
100
+ # _log(assign_cmd)
101
+ # osis_run(assign_cmd, "stash")
102
+ all_cmds.append(assign_cmd)
103
+
104
+ # 开始递归生成赋值语句(OSIS索引从0开始)
105
+ generate_assignments(matrix_data, [])
106
+ # osis_run()
107
+ # 返回拼接后的完整命令字符串
108
+ str_cmds = "\n".join(all_cmds)
109
+ _log(str_cmds)
110
+ return osis_run(str_cmds, "exec")
@@ -6,7 +6,7 @@ Interfaces of OSIS functions
6
6
  """
7
7
 
8
8
 
9
- from ..core import OSISEngine, REGISTRY
9
+ from ..core import REGISTRY
10
10
 
11
11
  @REGISTRY.register("Acel")
12
12
  def osis_acel(dG: float = 9.8066):
@@ -72,7 +72,7 @@ def osis_calc_creep(bFlag: int=1):
72
72
  '''
73
73
  pass
74
74
 
75
- @REGISTRY.register("CalcCreep")
75
+ @REGISTRY.register("CalcShear")
76
76
  def osis_calc_shear(bFlag: int=1):
77
77
  '''
78
78
  是否计算剪切
@@ -154,3 +154,9 @@ class PyInterface:
154
154
 
155
155
  def OSIS_QBStage(self, eBridgeType: str, stageInfo: list) -> Tuple[bool, str]:
156
156
  return True, ""
157
+
158
+ def OSIS_CheckResult(slef, eSheetType: str, eCheckItem: str, strCheckName: str) -> tuple[bool, str, str]:
159
+ return True, "", ""
160
+
161
+ def OSIS_LoadCaseResult(self, fileName:str, eType: str) -> tuple[bool, str, str]:
162
+ return True, "", ""
@@ -1,4 +1,5 @@
1
1
  from ..core import *
2
+ from ..common import *
2
3
  from ..boundary import *
3
4
  from ..control import *
4
5
  from ..element import *
@@ -6,7 +7,7 @@ from ..live import *
6
7
  from ..load import *
7
8
  from ..material import *
8
9
  from ..node import *
9
- # from ..post import *
10
+ from ..post import *
10
11
  from ..property import *
11
12
  from ..general import *
12
13
  from ..section import *
@@ -0,0 +1,51 @@
1
+ import requests
2
+ import json
3
+ from requests.adapters import HTTPAdapter
4
+ from urllib3.util.retry import Retry
5
+
6
+ # ========== 全局初始化:连接池 Session(只创建一次) ==========
7
+ # 配置重试策略
8
+ retry_strategy = Retry(
9
+ total=3, # 最多重试3次
10
+ backoff_factor=0.1, # 重试间隔:0.1, 0.2, 0.4... 秒
11
+ status_forcelist=[429, 500, 502, 503, 504] # 遇到这些状态码自动重试
12
+ )
13
+
14
+ # 配置连接池适配器
15
+ adapter = HTTPAdapter(
16
+ max_retries=retry_strategy,
17
+ pool_connections=10, # 最大连接池数
18
+ pool_maxsize=100 # 每个池最大连接数
19
+ )
20
+
21
+ # 创建全局 Session
22
+ session = requests.Session()
23
+ session.mount("http://", adapter)
24
+ session.mount("https://", adapter) # 如果你后续用HTTPS
25
+
26
+ # ========== 通用客户端函数(复用连接池) ==========
27
+ def osis_client(func_name: str, payload: dict) -> dict | tuple[bool, str]:
28
+ """
29
+ 通用 OSIS 接口客户端(复用连接池,高效批量调用)
30
+ Args:
31
+ func_name: C++ 接口名(如 "OSIS_Run", "OSIS_Run_Batch")
32
+ payload: 请求参数字典(自动序列化为 JSON)
33
+ Returns:
34
+ 异常时返回 (False, 错误信息)
35
+ """
36
+ url = f"http://localhost:8080/{func_name}"
37
+
38
+ try:
39
+ # 复用连接池发送 POST 请求
40
+ response = session.post(
41
+ url,
42
+ data=json.dumps(payload, ensure_ascii=False).encode("utf-8"),
43
+ headers={"Content-Type": "application/json; charset=utf-8"},
44
+ timeout=30 # 批量调用适当延长超时
45
+ )
46
+ response.raise_for_status() # 抛出 HTTP 状态码错误
47
+ return tuple(response.json())
48
+
49
+ except Exception as e:
50
+ # 异常时保持和 C++ 一致的返回格式
51
+ return False, f"调用失败: {str(e)}"
@@ -9,27 +9,29 @@ import datetime
9
9
  import inspect
10
10
  import functools
11
11
  from typing import Dict, Any, Tuple, Literal, Optional
12
- from .engine import OSISEngine
12
+ # from .engine import OSISEngine
13
+ from .client import osis_client
13
14
 
14
- def osis_run(strCmd: str="", mode: Literal["stash", "exec"]="exec") -> Tuple[bool, str, Any]:
15
- '''
16
- 直接以命令流的形式运行OSIS功能
17
15
 
18
- Args:
19
- strCmd: 完整的命令流
20
- mode: 运行模式,此参数为了同时执行多条命令提高效率
21
- * 使用 stash 仅会将命令流存到OSIS中,不会执行
22
- * 收到 exec 信号才会执行暂存包括当前的所有命令流。
16
+ # def osis_run(strCmd: str="", mode: Literal["stash", "exec"]="exec") -> Tuple[bool, str, Any]:
17
+ # '''
18
+ # 直接以命令流的形式运行OSIS功能
19
+
20
+ # Args:
21
+ # strCmd: 完整的命令流
22
+ # mode: 运行模式,此参数为了同时执行多条命令提高效率
23
+ # * 使用 stash 仅会将命令流存到OSIS中,不会执行
24
+ # * 收到 exec 信号才会执行暂存包括当前的所有命令流。
23
25
 
24
- Returns:
25
- tuple (bool, str, Any): 是否成功,失败原因,其他结果数据
26
- '''
27
- # # 自动判断模式:非空默认暂存,为空默认执行
28
- # if mode is None:
29
- # mode = "stash" if strCmd else "exec"
26
+ # Returns:
27
+ # tuple (bool, str, Any): 是否成功,失败原因,其他结果数据
28
+ # '''
29
+ # # # 自动判断模式:非空默认暂存,为空默认执行
30
+ # # if mode is None:
31
+ # # mode = "stash" if strCmd else "exec"
30
32
 
31
- e = OSISEngine.GetInstance()
32
- return e.OSIS_Run(strCmd, mode)
33
+ # e = OSISEngine.GetInstance()
34
+ # return e.OSIS_Run(strCmd, mode)
33
35
 
34
36
  # def _log(text, filename="pyosis.log"):
35
37
  # """简单的日志函数"""
@@ -38,6 +40,47 @@ def osis_run(strCmd: str="", mode: Literal["stash", "exec"]="exec") -> Tuple[boo
38
40
  # f.write(f"[{timestamp}] {text}\n")
39
41
  # f.close()
40
42
 
43
+ def osis_run(strCmd: str="", mode: Literal["stash", "exec"]="exec") -> tuple[bool, str]:
44
+ """
45
+ http 模拟 C++ 原生 OSIS_Run 函数
46
+ Args:
47
+ strCmd: 完整的命令流
48
+ mode: 运行模式,此参数为了同时执行多条命令提高效率
49
+ * 使用 stash 仅会将命令流存到OSIS中,不会执行
50
+ * 收到 exec 信号才会执行暂存包括当前的所有命令流。
51
+
52
+ Returns:
53
+ tuple (bool, str): 是否成功,失败原因
54
+ """
55
+ return osis_client("OSIS_Run", locals())
56
+ # # 1. 配置 C++ 服务地址
57
+ # url = "http://localhost:8080/OSIS_Run"
58
+
59
+ # # 2. 构造请求参数(JSON 格式,UTF-8 编码)
60
+ # payload = {
61
+ # "strCmd": strCmd,
62
+ # "mode": mode
63
+ # }
64
+
65
+ # # 3. 发送 POST 请求(自动处理中文编码)
66
+ # try:
67
+ # response = requests.post(
68
+ # url,
69
+ # data=json.dumps(payload, ensure_ascii=False).encode("utf-8"),
70
+ # headers={"Content-Type": "application/json; charset=utf-8"},
71
+ # timeout=10
72
+ # )
73
+ # response.raise_for_status() # 抛出 HTTP 错误
74
+
75
+ # # 4. 解析返回值,还原为 C++ 原生返回格式
76
+ # resp_data = response.json()
77
+ # return resp_data["success"], resp_data["message"]
78
+
79
+ # except Exception as e:
80
+ # # 异常时返回和 C++ 一致的格式
81
+ # return False, f"调用失败:{str(e)}"
82
+
83
+
41
84
  def _log(text, log_dir="pyosis_logs"):
42
85
  """
43
86
  同一轮执行(<1秒间隔)的代码追加到同一文件,
@@ -0,0 +1,8 @@
1
+ # --- project相关的函数
2
+
3
+ from typing import Tuple
4
+ # from .engine import OSISEngine
5
+ from .client import osis_client
6
+
7
+ def get_project_directory() -> Tuple[bool, str]:
8
+ return osis_client("GetProjectDirectory", {})
@@ -7,7 +7,7 @@ Interfaces of OSIS functions
7
7
 
8
8
 
9
9
  from typing import Any, Dict, Literal
10
- from ..core import OSISEngine, REGISTRY
10
+ from ..core import REGISTRY
11
11
 
12
12
 
13
13
  # @REGISTRY.register("Element")
@@ -0,0 +1,2 @@
1
+ from .loadcase import *
2
+ from .check import *
@@ -0,0 +1,133 @@
1
+ from pathlib import Path
2
+ from typing import Literal, Any
3
+ from ..core import project, command
4
+ import json
5
+
6
+ # /output,D:\\temp\\Temp1\\Check\\频遇组合包络.txt,echk,混凝土_PC腹板斜截面抗裂验算_频遇组合包络
7
+ _CMD = "/output,{out_file_path}.txt,echk,{check_file_name}"
8
+ _CHECK_FILE_PATH = "Temperary"
9
+ _CHECK_TXT_PATH = "Temperary"
10
+
11
+ def osis_check_result(
12
+ eSheetType: Literal["一般", "混凝土"],
13
+ eCheckItem: Literal["正截面抗弯验算",
14
+ "斜截面抗剪验算",
15
+ "正截面抗压验算",
16
+ "PC抗扭验算",
17
+ "PS正截面短期抗裂验算",
18
+ "PC正截面长期抗裂验算",
19
+ "PC顶底板斜截面抗裂验算",
20
+ "PC腹板斜截面抗裂验算",
21
+ "裂缝宽度验算",
22
+ "挠度验算",
23
+ "PC正截面压应力验算",
24
+ "PC斜截面主压应力验算",
25
+ "PC钢束拉应力验算",
26
+ "PC施工阶段正截面压应力验算",
27
+ "PC施工阶段正截面拉应力验算"],
28
+ strCheckName: str) -> tuple[bool, str, Any]:
29
+ '''
30
+ 验算
31
+
32
+ Args:
33
+ eSheetType (str):
34
+ * "一般"
35
+ * "混凝土"
36
+ eCheckItem (Literal["正截面抗弯验算",
37
+ "斜截面抗剪验算",
38
+ "正截面抗压验算",
39
+ "PC抗扭验算",
40
+ "PS正截面短期抗裂验算",
41
+ "PC正截面长期抗裂验算",
42
+ "PC顶底板斜截面抗裂验算",
43
+ "PC腹板斜截面抗裂验算",
44
+ "裂缝宽度验算",
45
+ "挠度验算",
46
+ "PC正截面压应力验算",
47
+ "PC斜截面主压应力验算",
48
+ "PC钢束拉应力验算",
49
+ "PC施工阶段正截面压应力验算",
50
+ "PC施工阶段正截面拉应力验算"
51
+ ])
52
+ strCheckName (str): 文件名称
53
+
54
+ Returns:
55
+ tuple (bool, str):
56
+ - bool: 操作是否成功
57
+ - str: 失败原因(如果操作失败)
58
+ '''
59
+ # e = OSISEngine.GetInstance()
60
+ # # return e.OSIS_CheckResult(base_path, middle_path, end_path)
61
+ # isok, error, result_txt_path = e.OSIS_CheckResult(eSheetType, eCheckItem, strCheckName)
62
+ # if isok:
63
+ # data = read_ansi_file_to_json(result_txt_path)
64
+ # return isok, error, json.dumps(data, indent=2, ensure_ascii=False)
65
+ # else:
66
+ # return isok, error, None
67
+ # 1 获取项目目录
68
+ is_ok, project_path = project.get_project_directory()
69
+ if not is_ok:
70
+ return False, "获取文件夹失败", ""
71
+
72
+ project_path = Path(project_path)
73
+ check_name = eSheetType + "_" + eCheckItem + "_" + strCheckName
74
+
75
+ # 2 工况文件路径
76
+ check_file_path = project_path / _CHECK_FILE_PATH / check_name
77
+
78
+ # 3 生成命令
79
+ str_cmd = _CMD.format(out_file_path=check_file_path, check_file_name=check_name)
80
+
81
+ # 4 执行命令
82
+ is_ok, error = command.osis_run(str_cmd, mode="exec")
83
+ if not is_ok:
84
+ return False, error, ""
85
+
86
+ # 5 读取结果
87
+ txt_file_path = project_path / _CHECK_TXT_PATH / check_name
88
+ txt_file_path = txt_file_path.with_suffix(".txt")
89
+ data = read_check_txt_file_to_json(str(txt_file_path))
90
+
91
+ return True, "", data
92
+
93
+
94
+ def read_check_txt_file_to_json(file_path):
95
+
96
+ with open(file_path, 'r', encoding='gbk') as f:
97
+ lines = f.readlines()
98
+
99
+ # 查找实际数据开始的位置
100
+ start_index = 0
101
+ for i, line in enumerate(lines):
102
+ if "单元" in line and "验算位置" in line: # 查找包含表头的行
103
+ start_index = i
104
+ break
105
+
106
+ if start_index == 0 and len(lines) < 2:
107
+ return []
108
+
109
+ # 解析表头
110
+ headers = lines[start_index].strip().split('\t')
111
+
112
+ # 处理数据行
113
+ result = []
114
+ for line in lines[start_index + 1:]:
115
+ line = line.strip()
116
+ if not line: # 跳过空行
117
+ continue
118
+
119
+ values = line.split('\t')
120
+ if len(values) != len(headers):
121
+ continue # 跳过不完整行
122
+
123
+ # 创建字典对象
124
+ row_dict = {}
125
+ for i, header in enumerate(headers):
126
+ header = header.replace(' ','')
127
+ value = values[i].replace(' ','')
128
+
129
+ row_dict[header] = value
130
+
131
+ result.append(row_dict)
132
+
133
+ return result
@@ -0,0 +1,96 @@
1
+ from pathlib import Path
2
+ from typing import Literal, Any
3
+ from ..core import project, command
4
+ import json
5
+
6
+ # 将工况结果转换为txt的命令
7
+ _CMD = "/output,{out_file_path}.txt,{e_type},{check_file_name}"
8
+ _LOAD_CASE_FILE_PATH = "Temperary"
9
+ _LOAD_CASE_TXT_PATH = "Temperary"
10
+
11
+ # def osis_elem_force(strLCName: str, eDataItem: Literal['EF'], eElementType: Literal["BEAM3D", "TRUSS", "SPRING", "CABLE", "SHELL"]):
12
+ # '''
13
+ # 提取内力结果
14
+ #
15
+ # Args:
16
+ # strLCName (str): 工况名称
17
+ # eDataItem (str): 数据类型,不区分大小写。EF = 内力
18
+ # eElementType (str): 单元类型,不区分大小写。BEAM3D = 梁柱单元,TRUSS = 桁架单元,SPRING = 弹簧单元,CABLE = 拉索单元,SHELL = 壳单元
19
+ #
20
+ # Returns:
21
+ # tuple (bool, str):
22
+ # - bool: 操作是否成功
23
+ # - str: 失败原因(如果操作失败)
24
+ # '''
25
+ # e = OSISEngine.GetInstance()
26
+ # eDataItem = eDataItem.upper()
27
+ # eElementType = eElementType.upper()
28
+ # return e.OSIS_ElemForce(strLCName, eDataItem, eElementType)
29
+
30
+ def osis_loadcase_result(fileName:str, eType: Literal['LCEF','LCED','LCND','LCBF','LCTL','LCS']) -> tuple[bool, str, Any]:
31
+ """
32
+ 提取荷载工况结果
33
+ Args:
34
+ fileName (str): 文件名字
35
+ eType (str): 荷载工况结果名
36
+ * LCEF = 荷载工况结果的单元内力;
37
+ * LCED = 荷载工况结果的单元位移;
38
+ * LCND = 荷载工况结果的节点位移;
39
+ * LCBF = 荷载工况结果的边界反力;
40
+ * LCTL = 荷载工况结果的钢束损失;
41
+ * LCS = 荷载工况结果的单元应力;
42
+ Returns:
43
+ tuple (bool, str): 是否成功,失败原因
44
+
45
+ """
46
+ # 1 获取项目目录
47
+ is_ok, project_path = project.get_project_directory()
48
+ if not is_ok:
49
+ return False, "获取文件夹失败", ""
50
+
51
+ project_path = Path(project_path)
52
+
53
+ # 2 工况文件路径
54
+ load_case_file_path = project_path / _LOAD_CASE_FILE_PATH / fileName
55
+
56
+ # 3 生成命令
57
+ str_cmd = _CMD.format(out_file_path=load_case_file_path,e_type=eType,check_file_name=fileName)
58
+
59
+ # 4 执行命令
60
+ is_ok, error = command.osis_run(str_cmd, mode="exec")
61
+ if not is_ok:
62
+ return False, error, ""
63
+
64
+ # 5 读取结果
65
+ txt_file_path = project_path / _LOAD_CASE_TXT_PATH / fileName
66
+ txt_file_path = txt_file_path.with_suffix(".txt")
67
+ data = read_loadcase_txt_file_to_json(str(txt_file_path))
68
+
69
+ return True, "", data
70
+
71
+ def read_loadcase_txt_file_to_json(file_path)-> list[dict]:
72
+ with open(file_path, 'r', encoding='gbk') as f:
73
+ lines = [line.rstrip('\n') for line in f if line.strip()]
74
+
75
+ # 提取表头(第一行)
76
+ headers = lines[0].split()
77
+ num_cols = len(headers)
78
+
79
+ # 初始化结果列表
80
+ result = []
81
+
82
+ # 处理数据行
83
+ for line in lines[1:]:
84
+ # 按空白分割,但最多分割 num_cols - 1 次,防止 Rw 列缺失导致错位
85
+ parts = line.split(maxsplit=num_cols - 1)
86
+
87
+ # 如果列数不足,用空字符串补齐到 num_cols
88
+ while len(parts) < num_cols:
89
+ parts.append("")
90
+
91
+ # 构建字典,所有值保持为字符串
92
+ row_dict = {headers[i]: parts[i].strip() for i in range(num_cols)}
93
+ result.append(row_dict)
94
+ # json_result = json.dumps(result, ensure_ascii=False)
95
+ # 打印结果
96
+ return result
@@ -2,76 +2,8 @@
2
2
  pyosis.section.interface 的 Docstring
3
3
  '''
4
4
 
5
- from typing import Any, Dict, Literal, List, Union, Sequence
6
- from ..core import REGISTRY, osis_run
7
- from ..core.command import _log
8
-
9
- def osis_matrix(matrix_name: str, matrix_data: List[List[Union[int, float]]]):
10
- """
11
- 将Python矩阵转换为OSIS DSL格式的矩阵定义和赋值语句。适用于自定义截面函数osis_section_custom、osis_section_steel_custom所需的坐标参数矩阵输入。
12
-
13
- Args:
14
- matrix_name: OSIS中的矩阵变量名
15
- matrix_data: 二维列表(List[List[int|float]])
16
-
17
- Returns:
18
- OSIS DSL格式的字符串
19
-
20
- Example:
21
- >>> matrix = [[1, 2, 20], [2, 3, 25], [3, 4, 30], [4, 1, 25]]
22
- >>> osis_matrix("LineMatrix", matrix)
23
- >>> osis_section_custom(1,"三角形截面","CUSTOM","LineMatrix")
24
- """
25
- # 验证输入
26
- if not matrix_data or not isinstance(matrix_data, list):
27
- raise ValueError("输入必须是二维列表且不能为空")
28
-
29
- if not all(isinstance(row, list) for row in matrix_data):
30
- raise ValueError("输入必须是二维列表")
31
-
32
- rows = len(matrix_data)
33
- cols = len(matrix_data[0]) if rows > 0 else 0
34
-
35
- # 检查矩阵是否规则(所有行列数一致)
36
- for i, row in enumerate(matrix_data):
37
- if len(row) != cols:
38
- raise ValueError(f"第{i}行长度({len(row)})与首行长度({cols})不一致")
39
-
40
- lines = []
41
-
42
- # 生成 *DIM 定义语句
43
- cmd = f"*dim,{matrix_name},{rows},{cols}"
44
- _log(cmd)
45
- osis_run(cmd, "stash")
46
- # 生成赋值语句
47
- for i in range(rows):
48
- for j in range(cols):
49
- value = matrix_data[i][j]
50
-
51
- # 格式化数值
52
- if isinstance(value, int):
53
- val_str = str(value)
54
- elif isinstance(value, float):
55
- if value.is_integer():
56
- val_str = str(int(value))
57
- else:
58
- val_str = f"{value:.6g}"
59
- else:
60
- # 其他类型尝试转为float
61
- try:
62
- fval = float(value)
63
- if fval.is_integer():
64
- val_str = str(int(fval))
65
- else:
66
- val_str = f"{fval:.6g}"
67
- except (TypeError, ValueError):
68
- raise ValueError(f"位置[{i},{j}]的值'{value}'不是有效数字")
69
- cmd = f"{matrix_name}[{i},{j}] = {val_str}"
70
- _log(cmd)
71
- osis_run(cmd, "stash")
72
-
73
- return
74
-
5
+ from typing import Any, Dict, Literal
6
+ from ..core import REGISTRY
75
7
 
76
8
  @REGISTRY.register('Section')
77
9
  def osis_section_Lshape(nSec: int, strName: str, eSectionType: Literal["LSHAPE"]="LSHAPE", nDir: Literal[0, 1]=1, H: float=0.1, B: float=0.1, Tf1: float=0.016, Tf2: float=0.016):
@@ -0,0 +1,6 @@
1
+ from pyosis.core.all_func import *
2
+ from pyosis.post import osis_check_result, osis_loadcase_result
3
+
4
+ if __name__ == '__main__':
5
+ osis_check_result("混凝土","PC腹板斜截面抗裂验算","频遇组合包络")
6
+ osis_loadcase_result("_钢束二次_CS1_主梁预制、张拉预应力", "lcef")
@@ -1,13 +0,0 @@
1
- import os
2
- import sys
3
-
4
- # 查找dll路径
5
- current_dir =os.path.dirname(os.path.abspath(__file__))
6
- # dll_dir= os.path.abspath(os.path.join(current_dir, "../../../../bin64"))
7
-
8
- if os.path.exists(os.path.join(current_dir, "PyInterface.pyi")):
9
- from PyInterface import PyInterface as OSISEngine # 如果有pyi,认为pyd已经被找到了,直接导入就行
10
- else:
11
- from .PyInterface import PyInterface as OSISEngine # 如果没有pyi,认为只是简单实验下能不能跑,不用打开pyd
12
-
13
-
@@ -1,8 +0,0 @@
1
- # --- project相关的函数
2
-
3
- from typing import Tuple
4
- from .engine import OSISEngine
5
-
6
- def get_project_directory() -> Tuple[bool, str]:
7
- e = OSISEngine.GetInstance()
8
- return e.GetProjectDirectory()
@@ -1,21 +0,0 @@
1
- from typing import Literal
2
- from ..core import OSISEngine
3
-
4
- def osis_elem_force(strLCName: str, eDataItem: Literal['EF'], eElementType: Literal["BEAM3D", "TRUSS", "SPRING", "CABLE", "SHELL"]):
5
- '''
6
- 提取内力结果
7
-
8
- Args:
9
- strLCName (str): 工况名称
10
- eDataItem (str): 数据类型,不区分大小写。EF = 内力
11
- eElementType (str): 单元类型,不区分大小写。BEAM3D = 梁柱单元,TRUSS = 桁架单元,SPRING = 弹簧单元,CABLE = 拉索单元,SHELL = 壳单元
12
-
13
- Returns:
14
- tuple (bool, str):
15
- - bool: 操作是否成功
16
- - str: 失败原因(如果操作失败)
17
- '''
18
- e = OSISEngine.GetInstance()
19
- eDataItem = eDataItem.upper()
20
- eElementType = eElementType.upper()
21
- return e.OSIS_ElemForce(strLCName, eDataItem, eElementType)
File without changes
File without changes
File without changes