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

Getting KeyError: 'ERROR' when running hole-in-plate-quarter #56

Closed mbrethen closed 4 years ago

mbrethen commented 5 years ago

Hi,

I ran hole-in-plate-quarter.py on: Mac OS X 10.12.6, 64-bit Python 3.6 pycalculix = 1.1.1 Calculix=2.14 gmsh=4.04

It solves and loads nodal data but then quits:

Solving done!
Using Calculix ccx version=2.14 (trailing characters like the p in 2.8p are omitted)
Loading nodal results from file: hole-in-plate-quarter.frd
Reading displ storing: ux,uy,uz,utot
Reading stress storing: Sx,Sy,Sz,Sxy,Syz,Szx,Seqv,S1,S2,S3
Reading strain storing: ex,ey,ez,exy,eyz,ezx,eeqv,e1,e2,e3
Reading force storing: fx,fy,fz
Traceback (most recent call last):

  File "<ipython-input-5-b8083df1f74b>", line 1, in <module>
    runfile('/Users/marbre/Documents/Spyder/hole-in-plate-quarter/hole-in-plate-quarter.py', wdir='/Users/marbre/Documents/Spyder/hole-in-plate-quarter')

  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/spyder_kernels/customize/spydercustomize.py", line 668, in runfile
    execfile(filename, namespace)

  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/spyder_kernels/customize/spydercustomize.py", line 108, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "/Users/marbre/Documents/Spyder/hole-in-plate-quarter/hole-in-plate-quarter.py", line 67, in <module>
    prob.solve()

  File "/Users/marbre/Library/Python/3.6/lib/python/site-packages/pycalculix/problem.py", line 285, in solve
    self.rfile.load()

  File "/Users/marbre/Library/Python/3.6/lib/python/site-packages/pycalculix/results_file.py", line 97, in load
    self.__read_frd() # read nodal results

  File "/Users/marbre/Library/Python/3.6/lib/python/site-packages/pycalculix/results_file.py", line 1150, in __read_frd
    arr = self.__modearr_nresults(infile)

  File "/Users/marbre/Library/Python/3.6/lib/python/site-packages/pycalculix/results_file.py", line 1022, in __modearr_nresults
    mode = mode_by_name[name]

KeyError: 'ERROR'
mbrethen commented 5 years ago

I also tried the dam.py example:

runfile('/Users/marbre/Documents/Spyder/dam/dam.py', wdir='/Users/marbre/Documents/Spyder/dam')
Reloaded modules: pycalculix, pycalculix.version, pycalculix.feamodel, pycalculix.environment, pycalculix.base_classes, pycalculix.geometry, pycalculix.material, pycalculix.components, pycalculix.connectors, pycalculix.loads, pycalculix.mesh, pycalculix.partmodule, pycalculix.problem, pycalculix.results_file, pycalculix.selector, pycalculix.cadimporter, dxfgrabber, dxfgrabber.const, dxfgrabber.tags, dxfgrabber.codepage, dxfgrabber.color
================================================
Units have been set to m_N
For dist use m
For force use N
For stress use Pa
For temp use K
For density use kg/(m^3)
For time use s
For displ use m
================================================
File dam_geom.png was saved.


File: dam.geo was written
/opt/local/bin/gmsh dam.geo -2 -o dam.inp
Traceback (most recent call last):

  File "<ipython-input-3-c8b5aab09767>", line 1, in <module>
    runfile('/Users/marbre/Documents/Spyder/dam/dam.py', wdir='/Users/marbre/Documents/Spyder/dam')

  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/spyder_kernels/customize/spydercustomize.py", line 668, in runfile
    execfile(filename, namespace)

  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/spyder_kernels/customize/spydercustomize.py", line 108, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "/Users/marbre/Documents/Spyder/dam/dam.py", line 84, in <module>
    model.mesh(0.5, 'gmsh')

  File "/Users/marbre/Library/Python/3.6/lib/python/site-packages/pycalculix/feamodel.py", line 1634, in mesh
    self.__mesh_gmsh(size, meshmode)

  File "/Users/marbre/Library/Python/3.6/lib/python/site-packages/pycalculix/feamodel.py", line 1806, in __mesh_gmsh
    subprocess.check_call(runstr, timeout=timeout, shell=True)

  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 286, in check_call
    retcode = call(*popenargs, **kwargs)

  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 269, in call
    return p.wait(timeout=timeout)

  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 1449, in wait
    raise TimeoutExpired(self.args, timeout)

TimeoutExpired: Command '/opt/local/bin/gmsh dam.geo -2 -o dam.inp' timed out after 20 seconds

It's not clear how one overrides the default 20 sec for the timeout arg in __mesh_gmsh from dam.py.

spacether commented 5 years ago

Thanks for letting me know about this issue. You are using versions of calculix (ccx) and gmsh which appear to not have been installed with pycalculix. When I install from scratch on Mac OS X 10.13.6 64bit I get: python 3.7.0 pycalculix 1.1.1 calculix (ccx) 2.13 gmsh 3.0.5

What happens when you uninstall your system calculix and gmsh and install them with the command? pycalculix-add-feaprograms?

mbrethen commented 5 years ago

My last setup worked just fine: Mac OS X 10.11.6, 64-bit Python 3.4.5 pycalculix = 0.9.4 Calculix=2.10 gmsh=2.8.4

On this current setup it appears to be failing in __modearr_nresults, either when it's reading the nodal forces or at the 'node_data_saver' line 1159 in 'results_file.py'. However I compared the frd files from both setups and didn't find any anomalies. I suspect this may have something to do with python 3.6.

pycalculix-add-feaprograms installs homebrew, which I'd prefer not to do, since I have macports installed. I can however match your setup, if you think it's merited.

spacether commented 5 years ago

The homebrew installation is not necessary. In the past I have gotten problems from having different versions of gmsh and calculix installed.

So you should only focus on the calculix and gmsh versions. My Azure tests on Python 3.6 mac 64 bit work, so I don't think that it is the Python version.

mbrethen commented 5 years ago

BTW I'm building ccx 2.14 in macports with gcc5 and gfortran. Could that cause any problems that you're aware of?

spacether commented 5 years ago

Not that I am aware of specifically but I have never attempted a calculix build.

From your explanation it sounds like something is different with the nodal results file.

mbrethen commented 5 years ago

The frd for version 2.14 now includes convergence error output, appended after force results.

hole-in-plate-quarter.frd.txt

jchkoch commented 4 years ago

Just installed pycalculix. Looks like a great package. However, I have a similar issue when I tried to run the hole-in-plate-quarter example. The error I get seems to be quite similar to what has previously been reported.

Traceback (most recent call last):
  File "hole-in-plate-quarter.py", line 64, in <module>
    prob.solve()
  File "/home/jkoch/anaconda3/envs/thesis/lib/python3.7/site-packages/pycalculix/problem.py", line 285, in solve
    self.rfile.load()
  File "/home/jkoch/anaconda3/envs/thesis/lib/python3.7/site-packages/pycalculix/results_file.py", line 97, in load
    self.__read_frd() # read nodal results
  File "/home/jkoch/anaconda3/envs/thesis/lib/python3.7/site-packages/pycalculix/results_file.py", line 1150, in __read_frd
    arr = self.__modearr_nresults(infile)
  File "/home/jkoch/anaconda3/envs/thesis/lib/python3.7/site-packages/pycalculix/results_file.py", line 1022, in __modearr_nresults
    mode = mode_by_name[name]
KeyError: 'ERROR'

I am using the following versions: python 3.7.6 pycalculix 1.1.4 calculix (ccx) 2.16 gmsh 4.5.2

From looking at the code in line 1018 to 1022 of results_file.py in pycalculix where the mode names are defined and searching for the mode names within the frd file for these mode names I cannot find any reference to displ, 'stress,strain, andforce. I do find reference toDISP,STRESS,TOSTRAIN, and 'FORC. I am still more of a novice in Python development (use it mainly for scientific purposes) so any advice would be helpful. Thanks so much in advance.

James

jchkoch commented 4 years ago

I have fixed my issue and submitted a pull request with the code changes I undertook to fix this issue. The versions of the programs I am using are the most recent commit of pycalculix and the following:

python 3.7.6 calculix (ccx) 2.16 gmsh 4.5.2