pycalculix是一个Python 3库,用于在Calculix中自动建立有限元分析(FEA)模型
网址: http://justinablack.com/pycalculix/
源码: https://github.com/spacether/pycalculix
文档: https://pycalculix.readthedocs.io/en/latest/index.html
Pycalculix应用
安装
Mac OS X
1.安装python3、pycalculix和它使用的fea程序
brew install python3
python3 -mpip install -U numpy
python3 -mpip install -U matplotlib
pip3 install pycalculix
pycalculix-add-feaprograms
2.安装完成查看‘使用手册’
Windows
1.在32位或64位机器上安装python3
2.在终端中运行以下几行来安装所需的python库、pycalculix和它使用的fea程序
python -mpip install -U numpy
python -mpip install -U matplotlib
pip install pycalculix
pycalculix-add-feaprograms
3.安装完成查看‘使用手册’
Linux, assumes Ubuntu 16.04
1.安装python3-pip、numpy、matplotlib、pycalculix和它使用的fea程序
sudo apt-get install python3-pip python3-tk
pip3 install --upgrade pip
python3 -mpip install -U numpy
sudo python3 -mpip install -U matplotlib
pip3 install pycalculix
pycalculix-add-feaprograms
2.安装完成查看‘使用手册’
程序案例
# this is from examples/hole-in-plate-full.py
import pycalculix as pyc
# Vertical hole in plate model, make model
proj_name = 'hole-in-plate-full'
model = pyc.FeaModel(proj_name)
model.set_units('m') # this sets dist units to meters
# Define variables we'll use to draw part geometry
diam = 2.0 # hole diam
ratio = 0.45
width = diam/ratio #plate width
print('D=%f, H=%f, D/H=%f' % (diam, width, diam/width))
length = 2*width #plate length
# Draw part geometry, you must draw the part CLOCKWISE, x, y = radial, axial
part = pyc.Part(model)
part.goto(length*0.5, -width*0.5)
part.draw_line_ax(width)
part.draw_line_rad(-length)
part.draw_line_ax(-width)
part.draw_line_rad(length)
hole_lines = part.draw_hole(0, 0, diam*0.5, filled=False)
model.set_ediv(hole_lines, 10)
part.chunk()
model.plot_geometry(proj_name+'_geom') # view the geometry
# set loads and constraints
pressure = -1000
model.set_load('press', part.top, pressure)
model.set_load('press', part.bottom, pressure)
model.set_constr('fix', ['P6', 'P8'], 'y')
model.set_constr('fix', ['P4', 'P7'], 'x')
# set part material
mat = pyc.Material('steel')
mat.set_mech_props(7800, 210*(10**9), 0.3)
model.set_matl(mat, part)
# set the element type and mesh database
model.set_eshape('quad', 2)
model.set_etype('plstress', part, 0.1)
model.mesh(1.0, 'gmsh') # mesh 1.0 fineness, smaller is finer
model.plot_elements(proj_name+'_elem') # plot part elements
model.plot_pressures(proj_name+'_press')
model.plot_constraints(proj_name+'_constr')
# make and solve the model
prob = pyc.Problem(model, 'struct')
prob.solve()
# view and query results
sx = prob.rfile.get_nmax('Sx')
print('Sx_max: %f' % sx)
# Plot results
fields = 'Sx,Sy,S1,S2,S3,Seqv,ux,uy,utot,ex' # store the fields to plot
fields = fields.split(',')
for field in fields:
fname = proj_name+'_'+field
prob.rfile.nplot(field, fname, display=False)
使用手册
1.要运行pycalcuix文件,必须安装pycalulix,请参见上面的“安装”
2.然后,你可以编写自己的pycalculix程序或运行这里的一个示例文件:https://github.com/spacether/pycalculix/tree/master/examples
3.运行文件:
Windows
python the_program.py
其中the_program.py是您正在运行的文件的名称,前提是已经正确安装python3并激活
Mac/Linux
python the_program.py
其中the_program.py是您正在运行的文件的名称
单元支持:
支持轴对称、平面应力、平面应变单元.
二阶单元计算结果更精确,支持对线进行划分
几何建模
part.fillet_lines (L1, L2, arc_radius)
载荷施加
结果文件
在后台用cgx或gmsh进行网格划分,用Calculix ccx进行求解
需要的文件:
卸载
Windows
pycalculix-remove-feaprograms
pip uninstall pycalculix
Mac/Linux
pycalculix-remove-feaprograms
pip3 uninstall pycalculix
开发
git clone git@github.com:spacether/pycalculix.git
python -m venv venv
venv\scripts\activate
source venv/bin/activate
pip install -e .
pycalculix-add-feaprograms
许可
参照 LICENSE.txt (Apache 2.0) https://github.com/spacether/pycalculix
Copyright © 2021 .长沙麦涛网络科技有限公司 All rights reserved.
湘ICP备20015126号-2
联系我们