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

Error when using part.left but not part.right #57

Closed joeborrello closed 5 years ago

joeborrello commented 5 years ago

I'm trying to perform an FE analysis on the DXF file attached but running into a problem in the constraints step. I can apply constraints to the right side of the model by using part.right, but get the following error when I try to apply constraints using part.left:

IndexError Traceback (most recent call last)

in () 1 part = parts[0] 2 #model.set_constr('fix', part.bottom, 'x') ----> 3 model.set_constr('fix', part.left, 'x') 4 model.set_constr('fix', part.left, 'y') 5 model.set_constr('disp', part.right, 'y', displacement) ~/anaconda3/lib/python3.5/site-packages/pycalculix/feamodel.py in set_constr(self, ltype, items, axis, val) 1259 """ 1260 items = self.get_items(items) -> 1261 cname = self.__get_cname(items) 1262 ctype = 'nodes' 1263 ~/anaconda3/lib/python3.5/site-packages/pycalculix/feamodel.py in __get_cname(items) 953 cname = items[0].get_name() 954 else: --> 955 cname = items[0].get_name()+'-'+items[-1].get_name() 956 return cname 957 IndexError: list index out of range

To my knowledge, both the left and right portions of the model are perfectly vertical, so I'm not sure why one side works and the other doesn't. REHexSkew_simple.zip

joeborrello commented 5 years ago

Quick update: I'm getting the same issue with a modified DXF where I added vertical lines to the left and right sides: REHexSkew_simple_bars.zip

spacether commented 5 years ago

Hi Joe, I see what you are saying. Your part has multiple lines on each side. So part.left and part.right should each contain a list of signLine items. Attached is an image of your part. rehexskew_simple_areas I see from my code here: https://github.com/spacether/pycalculix/blob/master/pycalculix/partmodule.py#L158 That I am doing a strict match looking for lines which have exactly the left or rightmost value for the start and end point of the line. This means that your model geometry is slightly off. I will re-write this code to use a pycalculix geometry accuracy constant so it will by default capture the almost there lines too.

If it doesn't capture the part lines, then to fix your issue you could:

joeborrello commented 5 years ago

Thanks for that info. The DXF is being imported from OpenSCAD so, in theory at least, the vertical lines should all be perfectly straight and in the same position, but I know that's not always the case.

Where is the geometry accuracy constant specified in the code? I think that may be the quicker fix if I can get it to work by just adjusting the number.

spacether commented 5 years ago

Hi Joe, I just added a new branch which uses the accuracy constant when setting part.left/right/top/bottom. If you uninstall your pycalculix and reinstall it from: https://github.com/spacether/pycalculix/tree/bug/issue_57_part_left_not_detected you will have the fix.

The accuracy constant is pycalculix.geometry.ACC so if you set it to a new value after importing the pycalculix module, then import your geometry, it should use your new accuracy value. For example:

import pycalculix as pyc
pyc.geometry.ACC = 1
# import cad file here after setting ACC

If the left side is skewed so it is almost vertical and both of its points are captured within the left-1 zone, then that line will be set as part.left

I will merge my branch into master after I have added test demonstrating that it works. I already tested it on your file and it works.

joeborrello commented 5 years ago

I tried running the part again with the pycalculix installed from the updated branch, but I still get the same error. Do I need to specify the geometry accuracy constant?

spacether commented 5 years ago

Hey Joe. The accuracy constant starts out at a very small value. Try setting it to something like 0.1 then import your cad geometry.

joeborrello commented 5 years ago

Setting the ACC after import did it - wasn't sure if the branch had changed the constant or not. Thanks!

spacether commented 5 years ago

Master branch now has the fix for this issue in it.