spacether/pycalculix

Post Processing Issue

thiagobach opened this issue · 11 comments

Hello,

While I am trying to run the examples I have problems after issuing the prob.solve().

for example, after the prob.solve() on multihole.py I get the following error message:

INFO: 1315 nodes
INFO: 396 CPE8 elements
INFO: 396 total elements
File: multihole.inp was written
ccx multihole
Solving done!
Reading results file: multihole.frd
Reading nodes
Traceback (most recent call last):

  File "<ipython-input-2-003dd1c5f96e>", line 1, in <module>
    runfile('/home/kronos/Desktop/pycalculix/PC.py', wdir='/home/kronos/Desktop/pycalculix')

  File "/home/kronos/miniconda3/envs/pyc/lib/python3.5/site-packages/spyder/utils/site/sitecustomize.py", line 705, in runfile
    execfile(filename, namespace)

  File "/home/kronos/miniconda3/envs/pyc/lib/python3.5/site-packages/spyder/utils/site/sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "/home/kronos/Desktop/pycalculix/PC.py", line 80, in <module>
    prob.solve()

  File "/home/kronos/miniconda3/envs/pyc/lib/python3.5/site-packages/pycalculix/problem.py", line 285, in solve
    self.rfile.load()

  File "/home/kronos/miniconda3/envs/pyc/lib/python3.5/site-packages/pycalculix/results_file.py", line 92, in load
    self.__read_frd() # read nodal results

  File "/home/kronos/miniconda3/envs/pyc/lib/python3.5/site-packages/pycalculix/results_file.py", line 1053, in __read_frd
    ','.join(base_classes.RESFIELDS[mode]))

KeyError: 'off'


I`m using Ubuntu 17.10

do you have any ideias of why I am getting this?

Kind regards,

by the way, if i read the frd file with cgx, the problem seams to be solved properly

Which version of pycalculix are you using?

Hello,
I`ve tried both 0.9.3 and 0.9.4 and am getting the same error.

I`ve got it to work by commenting out the line 1050 on the file results_file.py

                elif '1PSTEP' in line:
                    # we are in a results block

                    # next line has the time in it
                    line = infile.readline()
                    fstr = "1X,' 100','C',6A1,E12.5,I12,20A1,I2,I5,10A1,I2"
                    tmp = self.__get_vals(fstr, line)
                    #[key, code, setname, value, numnod, text, ictype, numstp, analys, format_]
                    value, format_ = tmp[3], tmp[9]

                    # set results format to short, long or binary
                    # only short and long are parsed so far
                    if format_ == 0:
                        rfstr = "1X,I2,I5,6E12.5"
                    elif format_ == 1:
                        rfstr = "1X,I2,I10,6E12.5"
                    elif format_ == 2:
                        # binary
                        pass

                    # set the time
                    time = value
                    if time not in self.__steps:
                        self.__steps.append(time)
                    if time not in self.__results:
                        self.__results[time] = {'node':{}, 'element':{}}
                        for nid in node_ids:
                            # make dict for each node
                            self.__results[time]['node'][nid] = {}

                    # get the name to determine if stress or displ
                    line = infile.readline()
                    fstr = "1X,I2,2X,8A1,2I5"
                    # [key, name, ncomps, irtype]
                    name = self.__get_vals(fstr, line)[1]

                    if name == 'DISPR':
                        mode = 'displ'
                        self.__skip_lines(infile, 4)
                    elif name == 'STRESSR':
                        mode = 'stress'
                        self.__skip_lines(infile, 6)
                    elif name == 'TOSTRAIR':
                        mode = 'strain'
                        self.__skip_lines(infile, 6)
                    elif name == 'FORCR':
                        mode = 'force'
                        self.__skip_lines(infile, 4)

                 #   print('Reading '+mode+' storing: '+(',').join(base_classes.RESFIELDS[mode]))
                    line = infile.readline()

The simulation runs and the results are written in the .frd file but if i try to use the plot functions it returns an error in the same file (results_file.py). that may be related?

#command
prob.rfile.nplot("Seqv")

#output
Results from file: __swep_0000.dat have been read.
File __swep_0000_constr.png was saved.
Traceback (most recent call last):

  File "<ipython-input-1-6024e3488358>", line 1, in <module>
    runfile('/home/kronos/Desktop/pycalculix/agent.py', wdir='/home/kronos/Desktop/pycalculix')

  File "/home/kronos/miniconda3/envs/pyc/lib/python3.5/site-packages/spyder/utils/site/sitecustomize.py", line 705, in runfile
    execfile(filename, namespace)

  File "/home/kronos/miniconda3/envs/pyc/lib/python3.5/site-packages/spyder/utils/site/sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "/home/kronos/Desktop/pycalculix/agent.py", line 34, in <module>
    env.generateHole(pos,env.index)

  File "/home/kronos/Desktop/pycalculix/PC.py", line 89, in generateHole
    prob.rfile.nplot("Seqv")

  File "/home/kronos/miniconda3/envs/pyc/lib/python3.5/site-packages/pycalculix/results_file.py", line 136, in nplot
    axi = node.y + gmult*self.__results[self.__time]['node'][node.id]['uy']

KeyError: 'uy'


Could it be related to the version of calculix? (i am using version 2.12)

Hi, I am adding unit tests to ensure that all examples run without problems. I will focus my investigation on the above multihole.py file.

I ran mutihole.py on:
Mac OS X, 64-bit
pycalculix = 0.9.4
Calculix=2.13
gmsh=3.0.6
and I did not get any errors.

From the errors, it looks like pycalcuix is not reading in the frd file correctly.
In the past there were differences between how the windows/mac/linux versions of Calculix wrote the output files.

  • What version of Ubuntu 17.10 are you running on, 32bit or 64bit?
  • Please upload your .frd file so I can figure out where pycalculix is running in to a problem.

Hi
I had the same issue even though I don´t run Ubuntu, I installed pycalculix the normal way and got version 0.9.3.
The file (dam.frd) wasn't written at first, since I run python 3.6 on a W10 machine with admin privileges I first changed mshg from a 32-bit to a 64-bit version and change the hard coded path in enviroment.py to point at it.
The next issue emerged, some parameters in the dam.frd output file had changed, DISPR had become DISP and so on, hence the error on line 1050. Fixed the issue by changing to the right parameters for 1PSTEP.
Almost immediately next occurred. one of the values generated was read like.
11-1.10389E-006-2.41243E-0060.00000E+000 -1 and after that an error for the value 6-2.41243E-0 kicked in.
The most of the values look a little different 10-1.77303E-0053.35612E-0060.00000E+000 -1.
So here the problems looks like the masking isn't working for all types of values generated since an extra "-" is included in the string.
If we look at the breakdown of the value it would look like this

"Normal value"
10-1.80800E-0058.36977E-0060.00000E+000
-1.80800E-0058.36977E-0060.00000E+000
58.36977E-0060.00000E+000

"Abnormal value"
11-1.46045E-006-1.91795E-0060.00000E+000
-1.46045E-006-1.91795E-0060.00000E+000
6-1.91795E-0060.00000E+000

Switched to 0.9.4 and still had the same issue.
Switched from calculix 2.10 to 2.8 since it seems to be an error in the output format and now everything works!

The strange thing is it looks like the output files differ for the different examples, sometimes they work with newer versions of calculix and sometimes with the older. But for sure it seems the culprit for the most of these errors is the version of calculix you run.

multihole.py works fine with:
OS: Windows10 Professional
IDE:Visual Studio 2015 Professional
Python 3.6.4
CalculiX Version 2.13
Gmsh 3.0.5

P.S
Commenting out the line att 1050 doesn´t fix the problem just makes it skip the faulty 1PSTEP parameters.

Thanks for the above investigation. I will look in to the file formatting. Pycalculix already contains code to rewrite a frd or dat file with new fixed formatting but it may not be detecting badly formatted input files. I think that I had made it os specific because it was tied to the version of Calculix.

Hi,

I ran hole-in-plate-quarter.py on:
Mac OS X 10.11.6, 64-bit
Python 3.4.5
pycalculix = 0.9.3
Calculix=2.10
gmsh=2.8.4
and I get a similar error:

File "/Users/marbre/Library/Python/3.4/lib/python/site-packages/pycalculix/results_file.py", line 1053, in __read_frd
    ','.join(base_classes.RESFIELDS[mode]))

KeyError: 'off'

v0.9.3, 'results_file.py', lines 1052-1053:

                    print('Reading '+mode+' storing: '+
                          ','.join(base_classes.RESFIELDS[mode]))

I think the problem is that it does not find a match for the names in your if/elif statements from the .frd file ('DISP', 'STRESS', 'TOSTRAIN', 'FORC'). I wonder if these were changed in Calculix at some point?

hole-in-plate-quarter(frd).pdf

Anyway, it appears v0.94 addresses this and I did not get any errors.

So there are issues with specific versions of gmsh hanging when meshing and specific versions of Calculix outputting results files with different results formats. At this point I am focusing on getting all sample files working on OS X with tri and quad meshing. After that I will focus on getting my tests working on different operating systems. A good solution is probably to blacklist certain versions of gmsh and calculix, and ensure that my installer installs usable versions.

The frd format did change in one of the newer versions of calculix since 2014. I will include code to ensure that a working version of calculix is used.

I can confirm that updating to v0.94 solved this issue for me (v0.93 showed the same key error)

  • Ubuntu 16.04 - 64bit
  • calculix-ccx v2.9-1
  • Python 3.5.2
  • gmsh 2.10.1

This issue is fixed in pycalculix v0.9.4 and later. Version 0.9.5 is now released on github.