ANSYS WORKBENCH mechanical 应力面积分后处理教程

ANSYS WORKBENCH由于界面的友好性,所以目前使用的用户越来越多,但是良好的界面操作也会带来一定的问题,就是进行复杂的后处理就比较麻烦了,比如进行机电耦合分析时会用到应力的面积分,在ANSYS WORKBENCH中很难进行处理,本文提供一种复杂后处理的思路。

1、将ANSYS WORKBENCH mechanical的结果转换为vtk格式

1.1 在solution中insert Commands(APDL)
ANSYS WORKBENCH mechanical 应力面积分后处理教程_第1张图片
1.png
1.2 在Commands中粘贴下面的代码并根据自己的需求进行相应的修改
arg1='S,Y' ! *get,my_results(j),NODE,n_j,...
n=1100
time=n*0.0005
kk=CHRVAL(n)
/post1
set,NEAR, , , ,time ! Needed to load node-and-element model in Ansys Workbench.

esel,all
nsle,s,CORNER
 
*get,e_cou,ELEM,,count
*get,n_cou,NODE,,count
*get,e_min,ELEM,,num,min
*get,n_min,NODE,,num,min
*get,n_max,NODE,,num,max
 
*dim,e_nodes,,e_cou,20
*dim,e_nodes_mat,CHAR,e_cou,21
*dim,e_nodes_count,,e_cou
*dim,e_types,,e_cou
*dim,e_types_name,,e_cou
*dim,e_types_VTK,,e_cou
*dim,node_id,,n_max
*dim,n_x,,n_max
*dim,n_y,,n_max
*dim,n_z,,n_max
*dim,my_results,,n_max
*dim,cell_str,STRING,e_cou
*dim,e_types_Ansys_to_VTK,,300
 
e_types_Ansys_to_VTK(5)=12     ! SOLID5 (3-D Coupled-Field Solid)
e_types_Ansys_to_VTK(11)=3     ! LINK11 (Linear Actuator)
e_types_Ansys_to_VTK(13)=9     ! PLANE13 (2-D Coupled-Field Solid)
e_types_Ansys_to_VTK(14)=3     ! COMBIN14 (Spring-Damper)
e_types_Ansys_to_VTK(21)=1     ! MASS21 (Structural Mass)
e_types_Ansys_to_VTK(25)=9     ! PLANE25 (Axisymmetric-Harmonic 4-Node Structural Solid)
e_types_Ansys_to_VTK(27)=3     ! MATRIX27 (Stiffness, Damping, or Mass Matrix)
e_types_Ansys_to_VTK(29)=9     ! FLUID29 (2-D Axisymmetric Harmonic Acoustic Fluid)
e_types_Ansys_to_VTK(30)=12    ! FLUID30 (3-D Acoustic Fluid)
e_types_Ansys_to_VTK(31)=3     ! LINK31 (Radiation Link)
e_types_Ansys_to_VTK(33)=3     ! LINK33 (3-D Conduction Bar)
e_types_Ansys_to_VTK(34)=3     ! LINK34 (Convection Link)
e_types_Ansys_to_VTK(35)=5     ! PLANE35 (2-D 6-Node Triangular Thermal Solid)
e_types_Ansys_to_VTK(36)=5     ! SOURC36 (Current Source)
e_types_Ansys_to_VTK(37)=4     ! COMBIN37 (Control)
e_types_Ansys_to_VTK(38)=3     ! FLUID38 (Dynamic Fluid Coupling)
e_types_Ansys_to_VTK(39)=3     ! COMBIN39 (Nonlinear Spring)
e_types_Ansys_to_VTK(40)=3     ! COMBIN40 (Combination)
e_types_Ansys_to_VTK(47)=9     ! INFIN47 (3-D Infinite Boundary)
e_types_Ansys_to_VTK(50)=-1000 ! MATRIX50 (Superelement (or Substructure))
e_types_Ansys_to_VTK(55)=9     ! PLANE55 (2-D Thermal Solid)
e_types_Ansys_to_VTK(61)=3     ! SHELL61 (Axisymmetric-Harmonic Structural Shell)
e_types_Ansys_to_VTK(65)=12    ! SOLID65 (3-D Reinforced Concrete Solid)
e_types_Ansys_to_VTK(68)=3     ! LINK68 (Coupled Thermal-Electric Line)
e_types_Ansys_to_VTK(70)=12    ! SOLID70 (3-D Thermal Solid)
e_types_Ansys_to_VTK(71)=1     ! MASS71 (Thermal Mass)
e_types_Ansys_to_VTK(75)=9     ! PLANE75 (Axisymmetric-Harmonic 4-Node Thermal Solid)
e_types_Ansys_to_VTK(77)=9     ! PLANE77 (2-D 8-Node Thermal Solid)
e_types_Ansys_to_VTK(78)=9     ! PLANE78 (Axisymmetric-Harmonic 8-Node Thermal Solid)
e_types_Ansys_to_VTK(83)=9     ! PLANE83 (Axisymmetric-Harmonic 8-Node Structural Solid)
e_types_Ansys_to_VTK(87)=10    ! SOLID87 (3-D 10-Node Tetrahedral Thermal Solid)
e_types_Ansys_to_VTK(90)=12    ! SOLID90 (3-D 20-Node Thermal Solid)
e_types_Ansys_to_VTK(94)=4     ! CIRCU94 (Piezoelectric Circuit)
e_types_Ansys_to_VTK(96)=12    ! SOLID96 (3-D Magnetic Scalar Solid)
e_types_Ansys_to_VTK(98)=10    ! SOLID98 (Tetrahedral Coupled-Field Solid)
e_types_Ansys_to_VTK(110)=9    ! INFIN110 (2-D Infinite Solid)
e_types_Ansys_to_VTK(111)=12   ! INFIN111 (3-D Infinite Solid)
e_types_Ansys_to_VTK(116)=3    ! FLUID116 (Coupled Thermal-Fluid Pipe)
e_types_Ansys_to_VTK(121)=9    ! PLANE121 (2-D 8-Node Electrostatic Solid)
e_types_Ansys_to_VTK(122)=12   ! SOLID122 (3-D 20-Node Electrostatic Solid)
e_types_Ansys_to_VTK(123)=10   ! SOLID123 (3-D 10-Node Tetrahedral Electrostatic Solid)
e_types_Ansys_to_VTK(124)=4    ! CIRCU124 (Electric Circuit)
e_types_Ansys_to_VTK(125)=4    ! CIRCU125 (Diode)
e_types_Ansys_to_VTK(126)=3    ! TRANS126 (Electromechanical Transducer)
e_types_Ansys_to_VTK(129)=3    ! FLUID129 (2-D Infinite Acoustic)
e_types_Ansys_to_VTK(130)=9    ! FLUID130 (3-D Infinite Acoustic)
e_types_Ansys_to_VTK(131)=9    ! SHELL131 (4-Node Thermal Shell)
e_types_Ansys_to_VTK(132)=9    ! SHELL132 (8-Node Thermal Shell)
e_types_Ansys_to_VTK(136)=9    ! FLUID136 (3-D Squeeze Film Fluid Element)
e_types_Ansys_to_VTK(138)=3    ! FLUID138 (3-D Viscous Fluid Link Element)
e_types_Ansys_to_VTK(139)=4    ! FLUID139 (3-D Slide Film Fluid Element)
e_types_Ansys_to_VTK(144)=4    ! ROM144 (Reduced Order Electrostatic-Structural)
e_types_Ansys_to_VTK(151)=3    ! SURF151 (2-D Thermal Surface Effect)
e_types_Ansys_to_VTK(152)=9    ! SURF152 (3-D Thermal Surface Effect)
e_types_Ansys_to_VTK(153)=3    ! SURF153 (2-D Structural Surface Effect)
e_types_Ansys_to_VTK(154)=9    ! SURF154 (3-D Structural Surface Effect)
e_types_Ansys_to_VTK(155)=3    ! SURF155 (3-D Thermal Surface Effect)
e_types_Ansys_to_VTK(156)=3    ! SURF156 (3-D Structural Surface Line Load Effect)
e_types_Ansys_to_VTK(157)=9    ! SHELL157 (Thermal-Electric Shell)
e_types_Ansys_to_VTK(159)=-1000! SURF159 (General Axisymmetric Surface)
e_types_Ansys_to_VTK(160)=5    ! LINK160 (Explicit 3-D Spar (or Truss))
e_types_Ansys_to_VTK(161)=5    ! BEAM161 (Explicit 3-D Beam)
e_types_Ansys_to_VTK(162)=9    ! PLANE162 (Explicit 2-D Structural Solid)
e_types_Ansys_to_VTK(163)=9    ! SHELL163 (Explicit Thin Structural Shell)
e_types_Ansys_to_VTK(164)=12   ! SOLID164 (Explicit 3-D Structural Solid)
e_types_Ansys_to_VTK(165)=3    ! COMBI165 (Explicit Spring-Damper)
e_types_Ansys_to_VTK(166)=1    ! MASS166 (Explicit 3-D Structural Mass)
e_types_Ansys_to_VTK(167)=5    ! LINK167 (Explicit Tension-Only Spar)
e_types_Ansys_to_VTK(168)=10   ! SOLID168 (Explicit 3-D 10-Node Tetrahedral Structural Solid)
e_types_Ansys_to_VTK(169)=3    ! TARGE169 (2-D Target Segment)
e_types_Ansys_to_VTK(170)=9    ! TARGE170 (3-D Target Segment)
e_types_Ansys_to_VTK(171)=3    ! CONTA171 (2-D 2-Node Surface-to-Surface Contact)
e_types_Ansys_to_VTK(172)=3    ! CONTA172 (2-D 3-Node Surface-to-Surface Contact )
e_types_Ansys_to_VTK(173)=9    ! CONTA173 (3-D 4-Node Surface-to-Surface Contact)
e_types_Ansys_to_VTK(174)=9    ! CONTA174 (3-D 8-Node Surface-to-Surface Contact)
e_types_Ansys_to_VTK(175)=1    ! CONTA175 (2-D/3-D Node-to-Surface Contact)
e_types_Ansys_to_VTK(176)=3    ! CONTA176 (3-D Line-to-Line Contact)
e_types_Ansys_to_VTK(177)=3    ! CONTA177 (3-D Line-to-Surface Contact)
e_types_Ansys_to_VTK(178)=3    ! CONTA178 (3-D Node-to-Node Contact)
e_types_Ansys_to_VTK(179)=5    ! PRETS179 (Pretension)
e_types_Ansys_to_VTK(180)=3    ! LINK180 (3-D Spar (or Truss))
e_types_Ansys_to_VTK(181)=9    ! SHELL181 (4-Node Structural Shell)
e_types_Ansys_to_VTK(182)=9    ! PLANE182 (2-D 4-Node Structural Solid)
e_types_Ansys_to_VTK(183)=9    ! PLANE183 (2-D 8-Node or 6-Node Structural Solid)
e_types_Ansys_to_VTK(184)=4    ! MPC184 (Multipoint Constraint Element)
e_types_Ansys_to_VTK(184)=4    ! MPC184-Link/Beam (Multipoint Constraint Element: Rigid Link or Rigid Beam)
e_types_Ansys_to_VTK(184)=4    ! MPC184-Slider (Multipoint Constraint Element: Slider)
e_types_Ansys_to_VTK(184)=4    ! MPC184-Revolute (Multipoint Constraint Element: Revolute Joint)
e_types_Ansys_to_VTK(184)=4    ! MPC184-Universal (Multipoint Constraint Element: Universal Joint)
e_types_Ansys_to_VTK(184)=4    ! MPC184-Slot (Multipoint Constraint Element: Slot Joint)
e_types_Ansys_to_VTK(184)=4    ! MPC184-Point (Multipoint Constraint Element: Point-in-plane Joint)
e_types_Ansys_to_VTK(184)=4    ! MPC184-Translational (Multipoint Constraint Element: Translational Joint)
e_types_Ansys_to_VTK(184)=4    ! MPC184-Cylindrical (Multipoint Constraint Element: Cylindrical Joint)
e_types_Ansys_to_VTK(184)=4    ! MPC184-Planar (Multipoint Constraint Element: Planar Joint)
e_types_Ansys_to_VTK(184)=4    ! MPC184-Weld (Multipoint Constraint Element: Weld Joint)
e_types_Ansys_to_VTK(184)=4    ! MPC184-Orient (Multipoint Constraint Element: Orient Joint)
e_types_Ansys_to_VTK(184)=4    ! MPC184-Spherical (Multipoint Constraint Element: Spherical Joint)
e_types_Ansys_to_VTK(184)=4    ! MPC184-General (Multipoint Constraint Element: General Joint)
e_types_Ansys_to_VTK(184)=4    ! MPC184-Screw (Multipoint Constraint Element: Screw Joint)
e_types_Ansys_to_VTK(185)=12   ! SOLID185 (3-D 8-Node Structural Solid)
e_types_Ansys_to_VTK(186)=12   ! SOLID186 (3-D 20-Node Structural Solid)
e_types_Ansys_to_VTK(187)=10   ! SOLID187 (3-D 10-Node Tetrahedral Structural Solid)
e_types_Ansys_to_VTK(188)=5    ! BEAM188 (3-D 2-Node Beam)
e_types_Ansys_to_VTK(189)=9    ! BEAM189 (3-D 3-Node Beam)
e_types_Ansys_to_VTK(190)=12   ! SOLSH190 (3-D 8-Node Structural Solid Shell)
e_types_Ansys_to_VTK(192)=9    ! INTER192 (2-D 4-Node Gasket)
e_types_Ansys_to_VTK(193)=9    ! INTER193 (2-D 6-Node Gasket)
e_types_Ansys_to_VTK(194)=12   ! INTER194 (3-D 16-Node Gasket)
e_types_Ansys_to_VTK(195)=12   ! INTER195 (3-D 8-Node Gasket)
e_types_Ansys_to_VTK(200)=-1000! MESH200 (Meshing Facet)
e_types_Ansys_to_VTK(201)=1    ! FOLLW201 (Follower Load)
e_types_Ansys_to_VTK(202)=9    ! INTER202 (2-D 4-Node Cohesive)
e_types_Ansys_to_VTK(203)=7    ! INTER203 (2-D 6-Node Cohesive)
e_types_Ansys_to_VTK(204)=-1000! INTER204 (3-D 16-Node Cohesive)
e_types_Ansys_to_VTK(205)=12   ! INTER205 (3-D 8-Node Cohesive)
e_types_Ansys_to_VTK(208)=3    ! SHELL208 (2-Node Axisymmetric Shell)
e_types_Ansys_to_VTK(209)=3    ! SHELL209 (3-Node Axisymmetric Shell)
e_types_Ansys_to_VTK(212)=9    ! CPT212 (2-D 4-Node Coupled Pore-Pressure Mechanical Solid)
e_types_Ansys_to_VTK(213)=9    ! CPT213 (2-D 8-Node Coupled Pore-Pressure Mechanical Solid)
e_types_Ansys_to_VTK(214)=3    ! COMBI214 (2-D Spring-Damper Bearing)
e_types_Ansys_to_VTK(215)=12   ! CPT215 (3-D 8-Node Coupled Pore-Pressure Mechanical Solid)
e_types_Ansys_to_VTK(216)=12   ! CPT216 (3-D 20-Node Coupled Pore-Pressure Mechanical Solid )
e_types_Ansys_to_VTK(217)=10   ! CPT217 (3-D 10-Node Coupled Pore-Pressure Mechanical Solid)
e_types_Ansys_to_VTK(218)=9    ! FLUID218 (3-D Hydrodynamic Bearing Element)
e_types_Ansys_to_VTK(220)=12   ! FLUID220 (3-D Acoustic Fluid 20-Node Solid Element)
e_types_Ansys_to_VTK(221)=10   ! FLUID221 (3-D Acoustic Fluid 10-Node Solid Element)
e_types_Ansys_to_VTK(223)=9    ! PLANE223 (2-D 8-Node Coupled-Field Solid)
e_types_Ansys_to_VTK(226)=12   ! SOLID226 (3-D 20-Node Coupled-Field Solid)
e_types_Ansys_to_VTK(227)=10   ! SOLID227 (3-D 10-Node Coupled-Field Solid)
e_types_Ansys_to_VTK(230)=9    ! PLANE230 (2-D 8-Node Electric Solid)
e_types_Ansys_to_VTK(231)=12   ! SOLID231 (3-D 20-Node Electric Solid)
e_types_Ansys_to_VTK(232)=10   ! SOLID232 (3-D 10-Node Tetrahedral Electric Solid)
e_types_Ansys_to_VTK(233)=9    ! PLANE233 (2-D 8-Node Electromagnetic Solid )
e_types_Ansys_to_VTK(236)=12   ! SOLID236 (3-D 20-Node Electromagnetic Solid)
e_types_Ansys_to_VTK(237)=10   ! SOLID237 (3-D 10-Node Electromagnetic Solid)
e_types_Ansys_to_VTK(238)=9    ! PLANE238 (2-D 8-Node Diffusion Solid)
e_types_Ansys_to_VTK(239)=12   ! SOLID239 (3-D 20-Node Diffusion Solid)
e_types_Ansys_to_VTK(240)=10   ! SOLID240 (3-D 10-Node Tetrahedral Diffusion Solid)
e_types_Ansys_to_VTK(241)=9    ! HSFLD241 (2-D Hydrostatic Fluid)
e_types_Ansys_to_VTK(242)=-1000! HSFLD242 (3-D Hydrostatic Fluid)
e_types_Ansys_to_VTK(251)=3    ! SURF251 (2-D Radiosity Surface)
e_types_Ansys_to_VTK(252)=9    ! SURF252 (3-D Radiosity Surface)
e_types_Ansys_to_VTK(257)=12   ! INFIN257 (Structural Infinite Solid)
e_types_Ansys_to_VTK(263)=9    ! REINF263 (2-D Smeared Reinforcing)
e_types_Ansys_to_VTK(264)=12   ! REINF264 (3-D Discrete Reinforcing)
e_types_Ansys_to_VTK(265)=-1000! REINF265 (3-D Smeared Reinforcing)
e_types_Ansys_to_VTK(272)=-1000! SOLID272 (General Axisymmetric Solid with 4 Base Nodes)
e_types_Ansys_to_VTK(273)=-1000! SOLID273 (General Axisymmetric Solid with 8 Base Nodes)
e_types_Ansys_to_VTK(278)=12   ! SOLID278 (3-D 8-Node Thermal Solid)
e_types_Ansys_to_VTK(279)=12   ! SOLID279 (3-D 20-Node Thermal Solid)
e_types_Ansys_to_VTK(281)=9    ! SHELL281 (8-Node Structural Shell)
e_types_Ansys_to_VTK(285)=10   ! SOLID285 (3-D 4-Node Tetrahedral Structural Solid with Nodal Pressures)
e_types_Ansys_to_VTK(288)=3    ! PIPE288 (3-D 2-Node Pipe)
e_types_Ansys_to_VTK(289)=3    ! PIPE289 (3-D 3-Node Pipe )
e_types_Ansys_to_VTK(290)=3    ! ELBOW290 (3-D 3-Node Elbow)
e_types_Ansys_to_VTK(300)=-1000! USER300 (User-Defined Element)
 
result_name=''
n_chars=STRLENG(arg1)
*do,i,1,n_chars
    char=STRSUB(arg1,i,1)
    *if,char,EQ,',',THEN
        char='_'
    *endif
    result_name=STRCAT(result_name,char)
*enddo
 
*cfopen,my_results,txt
*vwrite,arg1
('*get,my_results(j),NODE,n_j,',A8)
*cfclos
 
n_j=n_min
*do,j,1,n_cou
    node_id(n_j)=j-1
    n_x(j)=nx(n_j)
    n_y(j)=ny(n_j)
    n_z(j)=nz(n_j)
    /input,my_results,txt
    n_j=ndnext(n_j)
*enddo
/DELETE, my_results.txt
 
cells_size=0
e_i=e_min
*do,i,1,e_cou
    cells_size=cells_size+1
    e_nodes_count(i)=0
    cellstr=''
    *do,j,1,20
        n_j=nelem(e_i,j)
        *if,NSEL(n_j),NE,-1,THEN
            e_nodes_count(i)=e_nodes_count(i)+1
            e_nodes(i,j)=node_id(n_j)
            e_nodes_mat(i,j+1)=CHRVAL(node_id(n_j))
            cells_size=cells_size+1
        *else
            *exit
        *endif
    *enddo
    e_nodes_mat(i,1)=CHRVAL(e_nodes_count(i))
    *get,e_types(i),ELEM,e_i,ATTR,TYPE
    *get,e_types_name(i),ETYP,e_types(i),ATTR,ENAM
    e_types_VTK(i)=e_types_Ansys_to_VTK(e_types_name(i))
    e_i=elnext(e_i)
*enddo
output='sy-'
output=STRCAT(output,kk)
*cfopen,output,vtk
 
*vwrite,
('# vtk DataFile Version 2.0')
*vwrite,
('Unstructured Grid')
*vwrite,
('ASCII')
*vwrite,
('DATASET UNSTRUCTURED_GRID')
*vwrite,n_cou
('POINTS ',F0.0,TL1,' float')
 
*vwrite,n_x(1),n_y(1),n_z(1)
(1PE12.5,' ',1PE12.5,' '1PE12.5)
 
*vwrite,e_cou,cells_size
('CELLS ',F0.0,TL1,' ',F0.0,TL1,' ')
 
*cfclose
 
 
/NOPR
/output,output,vtk,,append
*mwrite,e_nodes_mat(1,1)
(21(A8,' '))
/output
/GOPR
 
 
*cfopen,output,vtk,,APPEND
 
*vwrite,e_cou
('CELL_TYPES ',F0.0,TL1,' ')
 
*vwrite,e_types_VTK(1)
(F0.0,TL1,' ')
 
*vwrite,n_cou
('POINT_DATA ',F0.0,TL1,' ')
 
*vwrite,result_name
('SCALARS ',A8,' float 1')
 
*vwrite
('LOOKUP_TABLE default')
 
*vwrite,my_results(1)
(1PE12.5)
*cfclose

代码中的arg1为要提取的变量,这些变量的名称可以在下面的链接中进行查找:https://www.sharcnet.ca/Software/Ansys/17.2/en-us/help/ans_cmd/Hlp_C_GET.html#get.post.node
代码中的n为时间步数,可以根据自己的需求输出相应时刻的变量值。
注:目前该代码每次只能输出一个时刻的变量值,不能一次输出所有时刻的变量值
输出的文件名为“sy-n”,n为输入的时间步数,输出路径为:work_dir/dp0/SYS/MECH,work_dir为目前的工作目录。

2、使用paraview批量读取vtk文件并进行后处理

当导出很多不同时刻的vtk文件之后,需要paraview自动把这些vtk文件识别成不同时刻的数据,需要对这些文件的名称进行一定的处理。
只有类似于下面这几种命名形式才能够被paraview自动识别为不同时刻的数据:

  • fooN.vtk
  • foo_N.vtk
  • foo-N.vtk
  • foo.N.vtk
  • Nfoo.vtk
  • N.foo.vtk
  • foo.vtk.N
  • foo.vtk-sN

我们可以在第1步输出时就将输出文件的名称规定成这种形式,如果在第1步中没有命名成这种形式,可以通过matlab对文件名称进行批量处理。

2.1 matlab对文件名进行批量处理
file = dir('*.vtk');
len = length(file);
for i = 1 : len
    oldname = file(i).name;
    str1 = 'sy-';
    str2 = num2str(i);
    newname = strcat(str1,str2);
    eval(['!rename' 32 oldname 32 newname]);
end
2.2 paraview对应力进行面积分处理
  • 批量打开vtk文件:File->Open


    2.png
  • 使用Slice功能提取你想进行面积分的面:Filters->Alphabetical->Slice


    3.png
  • 使用Integrate Variabies对变量进行面积分:Filters->Alphabetical->Integrate Variabies


    4.png
  • 使用Plot Data Over Time绘制该变量的面积分随时间的变化曲线:Filters->Alphabetical->Plot Data Over Time


    5.png

    该变量的面积分随时间的变化曲线:


    6.png

参考资料:
[1] https://stackoverflow.com/questions/41722822/how-to-read-ansys-data-files-in-paraview/53617777#53617777
[2] https://www.paraview.org/Wiki/Animating_legacy_VTK_file_series
[3] https://blog.csdn.net/rs_huangzs/article/details/56674181
[4] https://blog.csdn.net/u013457167/article/details/48805217/

你可能感兴趣的:(ANSYS WORKBENCH mechanical 应力面积分后处理教程)