Home

Awesome

pycalculix

pycalculix is a Python 3 library to automate and build finite element analysis (FEA) models in Calculix.

This repo is no longer actively maintained. If you want to continue further development, please fork it.

Tests Build Status
Docs Build Status

Source Code: https://github.com/spacether/pycalculix
Documentation: https://pycalculix.readthedocs.io/en/latest/index.html

Useful applications of Pycalculix

Installation

Mac OS X

  1. Install python3, pycalculix and the fea programs that it uses
brew install python3
python3 -mpip install -U numpy
python3 -mpip install -U matplotlib
pip3 install pycalculix
pycalculix-add-feaprograms
  1. You are done! See 'Usage'

Windows

  1. Install python3 for 32bit machines or 64 bit machines
  2. In a terminal run the below lines to install needed python libraries, pycalculix, and the fea programs that it uses
python -mpip install -U numpy
python -mpip install -U matplotlib
pip install pycalculix
pycalculix-add-feaprograms
  1. You are done! See 'Usage'

Linux, assumes Ubuntu 16.04

  1. Install python3-pip, numpy, matplotlib, pycalculix, and the fea programs that it uses
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
  1. You are done! See 'Sample Program' and 'Usage'

Sample Program

# 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)

Usage

  1. To run a pycalcuix file you have to have pycalulix installed, see 'Installation' above
  2. The you can then write your own pycalculix programs or run one of the example files here: https://github.com/spacether/pycalculix/tree/master/examples
  3. To run a file:

Windows

Mac/Linux

Elements Supported:

Axisymmetric, plane stress, and plane strain elements are supported.

Second order elements produce more accurate results Setting element divisions on lines is supported

Geometry Building

Loading

Files Produced

Meshing and solving are done in the background using cgx or gmsh for meshing, and Calculix ccx for solving.

Files Used:

Uninstall

Windows

pycalculix-remove-feaprograms
pip uninstall pycalculix

Mac/Linux

pycalculix-remove-feaprograms
pip3 uninstall pycalculix

Development

git clone git@github.com:spacether/pycalculix.git
python -m venv venv
pip install -e .
pycalculix-add-feaprograms

License

See LICENSE.txt (Apache 2.0)

Creator

Justin Black, justin.a.black[at-sign]gmail[dot]com Initial Release: December 2014

Changes

See the change log

Analytics