赞
踩
from ansys.mapdl.core import launch_mapdl from ansys.mapdl.core import Mapdl import numpy as np # 启动 ANSYS MAPDL mapdl = launch_mapdl(run_location='D:\\20Program Files\\ANSYS Inc\\v202\\ansys\\bin\\winx64', override=True) # 设置 ANSYS MAPDL 参数 mapdl.prep7() mapdl.units('SI') # 定义一个四边形 mapdl.block(0, 1, 0, 1, 0, 0.1) print('1') # 网格划分 mapdl.et(1, "SOLID186") mapdl.esize(0.05) mapdl.vmesh("all") mapdl.eplot() mapdl.enorm("all") mapdl.allsel() print('2') # 应用荷载和约束 mapdl.nsel("s", "loc", "z", 0) mapdl.d("all", "uz") mapdl.nsel("s", "loc", "z", 1) mapdl.f("all", "fy", 10) print('3') # 求解并输出结果 mapdl.solve(allow_ignore=True) mapdl.finish() mapdl.post1() mapdl.set(1, 1) # 打印节点数和单元数 print("The number of nodes is: ", mapdl.mesh.n_node) print("The number of elements is: ", mapdl.mesh.n_elem) # 打印位移和应力 max_displacement = np.max(mapdl.nodal_displacement(1)[:, 2]) max_stress = np.max(mapdl.principal_stress(1)) max_node_displacement = np.max(np.abs(mapdl.nodal_displacement(1))) print("The maximum displacement in the z-direction is: ", max_displacement) print("The maximum stress is: ", max_stress) print("The maximum nodal displacement is: ", max_node_displacement)
SPECIFIED NODAL LOAD FZ FOR SELECTED NODES 1 TO 1 BY 1
REAL= 27750.8000 IMAG= 0.00000000
SPECIFIED NODAL LOAD FZ FOR SELECTED NODES 2 TO 2 BY 1
REAL= 14035.4500 IMAG= 0.00000000
"SPECIFIED NODAL LOAD FZ FOR SELECTED NODES"表示在特定节点上施加的指定节点负载,其中"FZ"代表沿Z轴的力,正值表示向下,负值表示向上。在这个描述中,"FOR SELECTED NODES 1 TO 1 BY 1"表示该负载被施加在节点1上,节点编号从1到1,间隔为1,实际上是指单个节点1。
"REAL="后面的数值表示实际施加在节点上的力的大小。在这个例子中,节点1上沿Z轴的实际力为27750.8单位。而"IMAG="后面的数值表示力的虚部,通常在复数表示中使用。在这里的情况下,虚部值为0,这表示在这个分析中没有虚部力的成分。
mapdl.r(100, 1256, Pre_stress_1)
其中,编号为100的实常数集被创建,面积为1256,并将预应力值设置为Pre_stress_1。
nodal_displacements = mapdl.post_processing.nodal_displacement('ALL')
的含义是什么?nodal_displacements
变量中,以供后续分析或可视化使用。这些位移数据通常包括节点的 X、Y、Z
方向的位移值。!钢管截面定义
!325X12
Sectype,1,beam,ctube
secdata,150.5,162.5
上面代码从哪里可以看到secdata后面参数,查找官网也没有解释说明。
Type: BEAM, Subtype: CTUBE
This subtype is similar to type PIPE. However, elements using PIPE account for internal or external pressures, whereas elements using CTUBE do not.
```165×6.0
尝试运行`a = mapdl.secdata(165, 6.0)
```go
⚠ 发生异常:
Error in instance GRPC_127.0.0.1:50052
*** ERROR *** CP = 0.625 TIME= 22:16:39
For a Circular Tube section, the inner radius must be less than the
outer radius. Please check the input.
正确方式:'20': 'Φ325×20.0'
a = mapdl.secdata(inner_radius, outer_radius)
print(a)
import math
D = 325.0 # diameter of the annulus
t = 20.0 # wall thickness
# Calculate the outer and inner radii
R = D / 2
r = R - t # Corrected multiplication operation
# Calculate the area
area = math.pi * (R**2 - r**2)
print(area)
D:\ProgramData\Anaconda3\python.exe "D:\.SXY\.Project1SQD\Code\ANSYS\6.预应力 2\text_d_r.py"
19163.715186897738
Process finished with exit code 0
以上代码验证面积近似等于输出结果Area = 19149.
Beam Section is offset to CENTROID of cross section SECTION ID NUMBER IS: 20 BEAM SECTION TYPE IS: Circular Tube BEAM SECTION NAME IS: COMPUTED BEAM SECTION DATA SUMMARY: Area = 19149. Iyy = 0.22333E+09 Iyz = 0.93132E-09 Izz = 0.22333E+09 Warping Constant = 0.77961E-18 Torsion Constant = 0.44667E+09 Centroid Y =-0.22798E-14 Centroid Z = 0.14059E-13 Shear Center Y =-0.72668E-15 Shear Center Z = 0.70993E-13 Shear Correction-xy = 0.50307 Shear Correction-yz = 0.34887E-13 Shear Correction-xz = 0.50307
secid Section identification number. type_ BEAM BEAM - Defines a beam section. TAPER - Defines a tapered beam or pipe section. The sections at the end points must be topologically identical. GENB - Defines a nonlinear general (temperature-dependent) beam section. COMB - Defines a composite (temperature-dependent) beam section. PIPE - Defines a pipe section. LINK - Defines a link section. AXIS - Define the axis for a general axisymmetric section. SHELL - Defines a shell section. GENS - Defines a preintegrated general (temperature-dependent) shell section. PRETENSION - Defines a pretension section. JOINT - Defines a joint section. REINF - Defines a reinforcing section. CONTACT - Defines a contact section. subtype When Type = BEAM, the possible beam sections that can be defined for Subtype are: name An eight-character name for the section. Name can be a string such as “W36X210” or “HP13X73” for beam sections. Section name can consist of letters and numbers, but cannot contain punctuation, special characters, or spaces. refinekey Sets mesh refinement level for thin-walled beam sections. Valid values are 0 (the default - no mesh refinement) through 5 (high level of mesh refinement). This value has meaning only when Type = BEAM.
mapdl.sectype(5, ‘LINK’, ‘’)
不需要用于’LINK’类型:对于一些截面类型,如’LINK’,subtype可能不是必要的或不适用。在这种情况下,通常会传递一个空字符串或默认值。
LINK180元素支持"cable"选项,这使得在有限元分析中可以模拟仅受拉力作用的结构
KEYOPT(2)
Cross-section scaling (applies only when large-deflection effects (NLGEOM,ON) are specified):
0 --
Enforce incompressibility; cross section is scaled as a function of axial stretch (default).
1 --
Section is assumed to be rigid.
老版本(KEYOPT(3)):
张力和/或压缩选项:
0 – 同时考虑张力和压缩(默认设置)。
1 – 仅考虑张力。
2 – 仅考虑压缩。
最新版2023-2024往后(KEYOPT(2)):
横截面缩放(仅适用于指定了大变形效应NLGEOM,ON的情况):
0 – 强制不可压缩;横截面根据轴向伸长的函数进行缩放(默认设置)。
1 – 假定横截面是刚性的。
这两个版本中都提供了关于元素行为的选项,但在最新版中,KEYOPT参数已更改为KEYOPT(2),并且增加了有关横截面缩放的选项。这些选项用于控制元素在大变形效应下的行为和横截面变化。
LINK180元素的输入数据包括以下内容: 节点信息:元素由两个节点(I和J)定义。
横截面积(A):通过SECTYPE和SECDATA命令输入。 单位长度附加质量(ADDMAS):通过SECCONTROL命令输入。
材料属性:使用TB命令和MP命令定义材料属性,包括弹性模量、泊松比、密度、塑性参数等。
温度:可以通过T(I)和T(J)来定义节点的温度,用于考虑温度效应。
特殊选项:可以通过KEYOPT来设置一些特殊选项,如横截面缩放、海洋加载等。
LINK10单元的关键项哪里查看?
专业人士解答:目前无法查看。新的版本已经删除,但是可以调用。
定义了一个只受压的杆件,施加了边界条件和荷载,并进行了求解?
比如桁架、索穹顶的撑杆,类似这样的结构,需要定义只受压的杆件,可以采用LINK180进行定义
from ansys.mapdl.core import launch_mapdl # 启动MAPDL实例 mapdl = launch_mapdl() # 清除任何之前的定义 mapdl.clear() # 定义材料属性(以常见的钢材为例) mapdl.prep7() # 进入PREP7模式 mapdl.mp('EX', 1, 210E9) # 弹性模量 210 GPa mapdl.mp('NUXY', 1, 0.3) # 泊松比 0.3 # 选择LINK180单元类型并设置只承受压缩 mapdl.et(1, 'LINK180') mapdl.keyopt(1, 3, 2) # 设置单元只承受压缩 # 定义实体属性(假设截面面积为1e-4 m^2) mapdl.r(1, 1e-4) # 定义节点 mapdl.n(1, 0, 0, 0) mapdl.n(2, 0, 0, -1) # 假设杆件长度为1m # 创建单元 mapdl.e(1, 2) # 定义边界条件 mapdl.d(1, 'ALL') # 约束节点1的所有自由度 mapdl.f(2, 'FZ', -1000) # 在节点2施加-1000N的压缩力(沿Z方向) # 求解 mapdl.run('/SOLU') # 进入求解模式 mapdl.antype('STATIC') # 静态分析 mapdl.solve() # 开始求解 # 后处理 mapdl.finish() # 完成后处理 # 获取结果(根据需要) displacement = mapdl.result.nodal_displacement(0) # 获取节点1的位移 print(displacement) # 关闭MAPDL实例 mapdl.exit()
运行结果:
D:\ProgramData\Anaconda3\python.exe "D:\.SXY\.Project1SQD\Code\ANSYS\6.预应力 2\text_element.py"
(array([1, 2]), array([[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
[ 0.00000000e+00, 0.00000000e+00, -4.76190476e-05]]))
Process finished with exit code 0
# 创建单元
rw = mapdl.e(1, 2)
print(rw)
1
displacement = mapdl.result.nodal_displacement(1) # 获取节点1的位移
出现报错CRITICAL - pymapdl_global - logging - handle_exception - Uncaught exception
Traceback (most recent call last):
File "D:\.SXY\.Project1SQD\Code\ANSYS\6.预应力 2\text_element.py", line 41, in <module>
displacement = mapdl.result.nodal_displacement(1) # 获取节点1的位移
File "C:\Users\SXY\AppData\Roaming\Python\Python39\site-packages\ansys\mapdl\reader\rst.py", line 1633, in nodal_displacement
return self.nodal_solution(*args, **kwargs)
File "C:\Users\SXY\AppData\Roaming\Python\Python39\site-packages\ansys\mapdl\reader\rst.py", line 1386, in nodal_solution
return self._nodal_solution_result(rnum, "NSL", in_nodal_coord_sys, nodes)
File "C:\Users\SXY\AppData\Roaming\Python\Python39\site-packages\ansys\mapdl\reader\rst.py", line 1517, in _nodal_solution_result
rnum = self.parse_step_substep(rnum) # convert to cumulative index
File "C:\Users\SXY\AppData\Roaming\Python\Python39\site-packages\ansys\mapdl\reader\rst.py", line 3657, in parse_step_substep
raise ValueError(
ValueError: There are only 1 result(s) in the result file.
关于报错的解释和原因:
在ANSYS中,结果集通常按照载荷步或子步排序,0通常代表最后一个结果集,即最终的分析结果。
*** WARNING *** CP = 0.375 TIME= 20:15:42
For element type = 1 (LINK180), KEYOPT(3) = 2 is an undocumented
option.
ELEMENT TYPE 1 IS LINK180 3-D COMPRESSION-ONLY SPAR
KEYOPT( 1- 6)= 0 0 2 0 0 0
KEYOPT( 7-12)= 0 0 0 0 0 0
KEYOPT(13-18)= 0 0 0 0 0 0
CURRENT NODAL DOF SET IS UX UY UZ
THREE-DIMENSIONAL MODEL
ELEMENT TYPE 1 IS LINK180 3-D COMPRESSION-ONLY SPAR: 这确认了元素类型1是LINK180,且被设置为只能承受压缩(3-D compression-only)。
KEYOPT( 1- 6)= 0 0 2 0 0 0等:这些是你为LINK180单元设置的关键选项(KEYOPT)值。特别是KEYOPT(3)=2,这意味着单元被设置为只承受压缩。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。