spacether / pycalculix

Python 3 library to automate and build finite element analysis (FEA) models in Calculix. Meshing uses Calculix or GMSH.
http://justinablack.com/pycalculix/
Apache License 2.0
170 stars 56 forks source link

Can't define top/bottom on imported DXF #36

Closed joeborrello closed 6 years ago

joeborrello commented 6 years ago

Working with a rectangular part (which should have a perfectly flat, horizontal upper line) I tried to define constraints using part.top and part.bottom but I got the following error: AttributeError: 'list' object has no attribute 'bottom'

The part variable in this case is coming from the importer.load() function to import the DXF.

Screencap of the part is included here and the DXF is attached. circle-hole.zip

image

spacether commented 6 years ago

Hi @joeborrello. This is happening because you are trying to access a property on a list and not a part. The load function returns a list of parts, then you need to access the first part and use .top .bottom .left and .right on that part. See my below code which works:

#!/usr/bin/env python3
import os
import sys

import pycalculix as pyc

model_name = 'circle-hole'
model = pyc.FeaModel(model_name)
model.set_units('m')

# set whether or not to show gui plots
show_gui = True
if '-nogui' in sys.argv:
    show_gui = False
# set element shape
eshape = 'quad'
if '-tri' in sys.argv:
    eshape = 'tri'

abs_path = os.path.dirname(os.path.abspath(__file__))
fname = os.path.join(abs_path, '%s.dxf' % model_name)
importer = pyc.CadImporter(model, fname, swapxy=True)
parts = importer.load()
model.plot_geometry(model_name+'_imported', display=show_gui)
#parts[0].chunk()
model.plot_geometry(model_name+'_areas', pnum=False,
                    lnum=False, display=show_gui)
model.plot_geometry(model_name+'_lines', anum=False,
                    pnum=False, display=show_gui)
model.plot_geometry(model_name+'_points', anum=False,
                    lnum=False, display=show_gui)

model.set_etype('axisym', parts)
model.set_eshape(eshape, 2)
model.mesh(1.0, 'gmsh')
model.plot_elements(model_name+'_elements', display=show_gui)

part = parts[0]
model.set_constr('fix', part.top, 'x')
model.set_constr('fix', part.bottom, 'x')
model.plot_constraints(model_name+'_constr', display=show_gui)
joeborrello commented 6 years ago

Awesome, I'll give this a go tomorrow