Sử dụng ngôn ngữ lập trình trên nền phần mềm ANSYS công nghiệp để phân tích kết cấu

  • Thread starter Lethuy_hvkt
  • Ngày mở chủ đề
U

umy

Author
Bài tập 01 Ansys APDL cho SV tự học
https://sites.ualberta.ca/~wmoussa/AnsysTutorial/AT/APDL/APDL.html

This tutorial will cover the preprocessing stage of constructing a truss geometry. Variables including length, height and number of divisions of the truss will be requested and the APDL code will construct the geometry.



Preprocessing: Use of APDL
Shown below is the APDL code used to construct the truss shown above, using a length of 200 m, a height of 10 m and 20 divisions. The following discussion will attempt to explain the commands used in the code. It is assumed the user has been exposed to basic coding and can follow the logic.

finish
/clear
/prep7
*ask,LENGTH,How long is the truss,100
*ask,HEIGHT,How tall is the truss,20
*ask,DIVISION,How many cross supports even number,2
DELTA_L = (LENGTH/(DIVISION/2))/2
NUM_K = DIVISION + 1
COUNT = -1
X_COORD = 0
*do,i,1,NUM_K,1
COUNT = COUNT + 1
OSCILATE = (-1)**COUNT
X_COORD = X_COORD + DELTA_L
*if,OSCILATE,GT,0,THEN
k,i,X_COORD,0
*else
k,i,X_COORD,HEIGHT
*endif
*enddo
KEYP = 0
*do,j,1,DIVISION,1
KEYP = KEYP + 1
L,KEYP,(KEYP+1)
*if,KEYP,LE,(DIVISION-1),THEN
L,KEYP,(KEYP+2)
*endif
*enddo
et,1,link1
r,1,100
mp,ex,1,200000
mp,prxy,1,0.3
esize,,1
lmesh,all
________________________________________________
TL lưu giử
https://sites.ualberta.ca/~wmoussa/AnsysTutorial/CL/CAT/APDL/print.pdf

________________________________________
Tạo mô hình trong /prep7 với APDL
https://de.scribd.com/document/61608095/ANSYS-Examples-by-APDL-Hani-Aziz-Ameen
 
Last edited by a moderator:
U

umy

Author
Bài tập 02 Ansys APDL cho KS tự học
https://pyansys.readthedocs.io/ansys_examples.html

Torsional Load on a Bar using SURF154 Elements
This ANSYS APDL script builds a bar and applies torque to it using SURF154 elements. This is a static analysis example.

Script Initialization
Beginning of ANSYS script:

!----------------------------------------
! Input torque applied (moment)
! Input radius, height, element size...
!----------------------------------------
TORQUE = 100
RADIUS = 2
H_TIP = 2
HEIGHT = 20
ELEMSIZE = 1
PI = acos(-1)
FORCE = 100/RADIUS
PRESSURE = FORCE/(H_TIP*2*PI*RADIUS)

Corresponding pyansys script including the initialization of pyansys:

import numpy as np
import os
import pyansys

# start ANSYS in the current working directory with default jobname "file"
ansys = pyansys.ANSYS(run_location=os.getcwd(), interactive_plotting=True)

# define cylinder and mesh parameters
torque = 100
radius = 2
h_tip = 2
height = 20
elemsize = 0.5
pi = np.arccos(-1)
force = 100/radius
pressure = force/(h_tip*2*np.pi*radius)

Model Creation
APDL Script:

!----------------------------------------
! Define higher-order SOLID186
! Define surface effect elements SURF154
! which is used to apply torque
! as a tangential pressure
!----------------------------------------
/prep7
et, 1, 186
et, 2, 154
r,1,
r,2,

!----------------------------------------
! Aluminum properties (or something)
!----------------------------------------
mp,ex,1,10e6
mp,nuxy,1,.3
mp,dens,1,.1/386.1
mp,dens,2,0

!----------------------------------------
! Simple cylinder
!----------------------------------------
*do, ICOUNT, 1, 4
cylind,RADIUS,,HEIGHTH_TIP,HEIGHT,90*(ICOUNT-1),90*ICOUNT
*enddo

nummrg,kp
lsel,s,loc,x,0

lsel,r,loc,y,0
lsel,r,loc,z,0,HEIGHT-H_TIP
lesize,all,ELEMSIZE*2
mshape,0
mshkey,1
esize,ELEMSIZE
allsel,all
VSWEEP, ALL
csys,1
asel,s,loc,z,HEIGHT-H_TIP+0.0001,HEIGHT0.0001
asel,r,loc,x,RADIUS
local,11,1
csys,0
aatt,2,2,2,11
amesh,all
finish

Corresponding pyansys script:

# Define higher-order SOLID186
# Define surface effect elements SURF154 to apply torque
# as a tangential pressure
ansys.Prep7()
ansys.Et(1, 186)
ansys.Et(2, 154)
ansys.R(1)
ansys.R(2)

# Aluminum properties (or something)
ansys.Mp('ex', 1, 10e6)
ansys.Mp('nuxy', 1, 0.3)
ansys.Mp('dens', 1, 0.1/386.1)
ansys.Mp('dens', 2, 0)

# Simple cylinder
for i in range(4):
ansys.Cylind(radius, '', '', height, 90*(i-1), 90*i)

ansys.Nummrg('kp')

# non-interactive volume plot (optional)
ansys.Show()
ansys.Menu('grph')
ansys.View(1, 1, 1, 1)
ansys.Vplot()
ansys.Wait(1)

# mesh cylinder
ansys.Lsel('s', 'loc', 'x', 0)
ansys.Lsel('r', 'loc', 'y', 0)
ansys.Lsel('r', 'loc', 'z', 0, height - h_tip)
ansys.Lesize('all', elemsize*2)
ansys.Mshape(0)
ansys.Mshkey(1)
ansys.Esize(elemsize)
ansys.Allsel('all')
ansys.Vsweep('ALL')
ansys.Csys(1)
ansys.Asel('s', 'loc', 'z', '', height - h_tip + 0.0001)
ansys.Asel('r', 'loc', 'x', radius)
ansys.Local(11, 1)
ansys.Csys(0)
ansys.Aatt(2, 2, 2, 11)
ansys.Amesh('all')
ansys.Finish()

# plot elements and wait one second (optional)
ansys.Eplot()
ansys.Wait(1)


Element plot from pyansys using matplotlib

Solution
APDL script:

/solu
antype,static,new
eqslv,pcg,1e-8

!----------------------------------------
! Apply tangential pressure
!----------------------------------------
esel,s,type,,2
sfe,all,2,pres,,PRESSURE

!----------------------------------------
! Constrain bottom of cylinder/rod
!----------------------------------------
asel,s,loc,z,0
nsla,s,1
d,all,all
allsel,all
/psf,pres,,2
/pbc,u,1
/title, Simple torsional example
solve
finish
/post1
set,last
fsum
esel,u,type,,2
SAVE

Corresponding pyansys script:

# new solution
ansys.Slashsolu() # Using Slash instead of / due to duplicate SOLU command
# ansys('/solu') # could also use this line
ansys.Antype('static', 'new')
ansys.Eqslv('pcg', 1e-8)

# Apply tangential pressure
ansys.Esel('s', 'type', '', 2)
ansys.Sfe('all', 2, 'pres', '', pressure)

# Constrain bottom of cylinder/rod
ansys.Asel('s', 'loc', 'z', 0)
ansys.Nsla('s', 1)

ansys.D('all', 'all')
ansys.Allsel()
ansys.Psf('pres', '', 2)
ansys.Pbc('u', 1)
ansys.Solve()
ansys.Exit() # Finishes, saves, and exits

Access and plot the results within python using pyansys:

# open the result file using the path used in ANSYS
resultfile = os.path.join(ansys.path, 'file.rst')
result = pyansys.ResultReader(resultfile)

# access element results as arrays
nnum, stress = result.NodalStress(0)
element_stress, elemnum, enode = result.ElementStress(0)
nodenum, stress = result.NodalStress(0)

# plot interactively
result.PlotNodalResult(0, colormap='bwr')
result.PlotNodalStress(0, 'Sx', colormap='bwr')
result.PlotPrincipalNodalStress(0, 'SEQV', colormap='bwr')

# plot and save non-interactively
cpos = [(20.992831318277517, 9.78629316586435, 31.905115108541928),
(0.35955395443745797, -1.4198191001571547, 10.346158032932495),
(-0.10547549888485548, 0.9200673323892437, -0.377294345312956)]

result.PlotNodalResult(0, interactive=False, cpos=cpos,
screenshot=os.path.join(path, 'cylinder_disp.png'))

result.PlotNodalStress(0, 'Sx', colormap='bwr', interactive=False, cpos=cpos,
screenshot=os.path.join(path, 'cylinder_sx.png'))

result.PlotPrincipalNodalStress(0, 'SEQV', colormap='bwr', interactive=False, cpos=cpos,
screenshot=os.path.join(path, 'cylinder_vonmises.png'))


Non-interactive Screenshot of Displacement from pyansys


Non-interactive Screenshot of X Stress from pyansys


Non-interactive Screenshot of von Mises Stress from pyansys
 
U

umy

Author
Bài học 03 Ansys APDL cho KS có nghề rồi, hiểu được để áp dụng thực hành

3.1 - ANSYS Mechanical-APDL Harmonic Analysis Example and Comparison to ANSYS Mechanical results
http://engr.bd.psu.edu/ansysug/ANSYS M-APDL Harmonic Analysis Example and Comparison to WB.pdf

>> TL mới 2017 tính động: modal và harmonic Analysis; so sánh kết quả của các phương pháp tính của Ansys.

Xem kỷ phần /solu và /Post26. ở trang 23 sau cuối.
>> (KS-Cơ khí và KS-XD) Áp dụng tính Giãm chấn cho Xe tải quân sự, Máy rung động, Cầu bộ hành ...

3.2 - Writing Text files with *VWRITE

http://www.padtinc.com/blog/the-focus/writing-text-files-with-vwrite
>> cách lập trình viết codes tợ như Fortran, tạo Marcros ...
 
Last edited by a moderator:
U

umy

Author
Trích VUDSE:
https://www.facebook.com/groups/vudse/
Tien Cao:
Việc hiển thị trong Ansys APDLkhác nhau giữa Power Graphics và Full Graphics. Khác nhau như thế nào thì bạn đọc slide sau là dễ hiểu nhất (có cả minh họa):
https://caeai.com/sites/default/files/pg_summ.pdf(
(ANSYS PostProcessing: Full Graphics vs. PowerGraphics)
Bạn coi slide 6 và 7 ("If average nodal solution is requested, data is NOT averaged across material and geometric discontinuities by default"). Vậy lý do stress ko liên tục là do "geometry discontinuities".
Nếu muốn khác phục, bạn có thể dùng Full Graphics hoặc thêm dòng sau AVRES,,FULL.

Ngoài ra, ở slide cuối, bạn sẽ thấy tóm tắt khi nào nên dùng 2 chế độ hiển thị trên.
Lý do chính: extrapolate stress rồi average tại node (đây là 1 vấn đề không đơn giản).
Tham khảo thêm: https://www.sharcnet.ca/.../ds_Unaveraged_Results.html

Đáp ngắn: (quà tết kỷ Hợi ;))
Mô hình với Solid elements, khi dùng Power Graphics (nội suy các nút bao quanh mô hinh) đưa kết quả hình ảnh nhanh, có phần lớn hơn đôi chút . Vẫn chấp nhận được !

.Full Graphics (được nội suy tất cả các nút) có kết quả tương đối chính xác hơn. Nếu mô hình quá lớn (trên khoãng 200.000 Nút) thì đưa Hình ảnh kết quả chậm chạp lắm.
 
U
Author
Luận văn TS ở Đức, dùng COUPLE FIELD TRANSIENT tính cho Seals (tiếng Việt?) , có cho mã nguồn !
NUMERICAL SIMULATION OF MECHANICAL AND THERMAL FLUID–STRUCTURE INTERACTION IN LABYRINTH SEALS
https://d-nb.info/1005791864/34
...
B.2 Excerpts from the APDL File
Start a new solution:
/UNITS,SI
/PREP7
...
FINISH
/SOL
ANTYPE,4
TRNOPT,FULL
NLGEOM,ON
*SET,fsidt,0.001
DELTIM,fsidt,fsidt,fsidt
AUTOTS,0
KBC,0
TINTP,,0.3,0.6
TIMINT,ON
...
ASEL,S,,,3
ASEL,A,,,5
ASEL,A,,,6
SFA,ALL,,FSIN,1
ALLSEL,ALL
!************* Multifield Settings ******************
MFAN,ON
MFPS,GROUP1,ANSYS
MFPS,GROUP2,CFX
MFSO,GROUP1,GROUP2
!*
MFLC,SURF,ANSYS,1,DISP,CFX,fsi,Total Mesh Displacement,NONC
MFLC,SURF,CFX,fsi,Total Force,ANSYS,1,FORC,CPP
!*
MFTI,5
MFDT,fsidt,fsidt,fsidt,0
AUTOTS,OFF
MFRS,0,SING
!*
MFIT,100,1,1
MFCO,ALL,0.001
MFCO,UZ,1.0
MFCO,FZ,1.0
MFRE,DISP,0.1,RELX
MFRE,FORC,0.75,RELX
!*
/GST,ON,ON
TIME,5.0
SOLVE
SAVE
FINISH
...

Ngoài ra cho biết thêm, để lập trình trong ANSYS ngoài APDL, có thể dùng các ngôn ngữ lập trình khác đưa vào! thí dụ như sau

Trích VUDSE ( https://www.facebook.com/groups/vudse/)
Khoa Luat
Cái quan trọng nhất là bạn muốn áp dụng vào công việc gì?.
Để học theo kiểu đơn giản, chỉ cần có ngay kết quả thì Python, Matlab/Octave, Mathematica
Để học lập trình bài bản, tổng quát, đi theo hướng OOP, thì Java là lựa chọn số 1 vì cấu trúc rất chặt chẽ và trong sáng, hiệu năng ổn.
Java an toàn và ít phức tạp hơn C++ trong khi tính chặt chẽ, dễ bảo trì tốt hơn Python.
Để học ngôn ngữ hiện đại, an toàn, thanh lịch thì dùng Swift (mã nguồn mở, phát triển bởi Apple) hoặc Kotlin (officially supported by Google).
Fortran, C không còn phổ biến nữa, người ta thường gọi các packages viết bằng các ngôn ngữ này để tận dụng về mặt tốc độ thông từ các ngôn ngữ khác (Python, Java, Matlab)
 
U

umy

Author
Trích dựa theo bài viết

Thanh Binh Do (VUDSE: https://www.facebook.com/groups/vudse/ )
Một tip rất hữu ích cho ai cần nó

ANSYS APDL Tutorial

https://cax.vn/ansys-apdl-tutorial/
Được sự cho phép của tác giả bộ video này là anh Đặng Hoàng Mình, giảng viên khoa cơ khí, Đại học Công nghiệp thành phố Hồ Chí Minh, [Cax.vn] giới thiệu bộ video hướng dẫn học Ansys APDL cho người mới bắt đầu.

Bộ video được anh Minh làm với mục đích hướng dẫn cho sinh viên của trường giải quyết các bài thí nghiệm, thực hành cho môn học “Phương pháp phần tử hữu hạn“. Chính vì vậy nên nó hướng đến các ví dụ cụ thể với mức độ khó tăng dần và hoàn toàn phù hợp với người mới làm quen với Ansys ADPL.

Kết nối Matlab với Ansys APDL
https://cax.vn/ket-noi-matlab-voi-ansys-apdl/
Matlab có thể thay đổi thông số đầu vào của chương trình (code) Ansys APDL để đưa ra các kết quả tính toán khác nhau dựa trên sự thay đổi đó. Nói cách khác, ta có thể khảo sát sự phụ thuộc của kết quả vào các tham số đầu vào. Để hiểu rõ hơn vấn đề này, chúng ta cùng giải quyết
 
U

umy

Author
Last edited by a moderator:
U

umy

Author
Таким Образом сформировалось, то что города москвы абсолютно всех государств общества постоянно сформированы в процедура, но в таком случае также в 2 больше, нежели другие мегаполиса. Данное также очевидно. В в таком случае возлюбленная также москва, для того чтобы демонстрировать образец с целью воспроизведения также являться предлогом с целью гордыни из-за государство. Столица – равно как один раз единственный с подобных населенных пунктов-столиц.
https://2gay.ru/
Реферат
Для зaдaч c cннгyляpнocтями, oчeнь чacтo пpнвoдитcя кoнтpoль cкopocтн cxoдимocти мeтoдa кoнeчнoгo злeмeнтa, нyтeм нccлeдoвaния xapaктepa peщeния вблизи тoчeк cингyляpнocти. Для нe тoчнo oбpaщeнныx cннгyляpнocтeй, peгyляpный элeмeнт, o тaк нaзывaeмoй бoльщoй тoчнocти, нe мoжeт пoвыщaть cкopocти cxoднмocти.
 
Top