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
167 stars 55 forks source link

Wrong formating on 32bit windows #4

Closed AVozelj closed 9 years ago

AVozelj commented 9 years ago

I am getting (for hole in plate full example): File "...\WinPython-32bit-3.4.2.4\python-3.4.2\lib\site-packages\pycalculix\results_file.py", line 772, in __get_vals substr = float(substr)

ValueError: could not convert string to float: '0-2.22222E+0'

Reading of row 13 in .frd file is a problem (same issue on XP and Win7 32bit).

After some investigation i found out that 32bit ccx cause a problem - frd output is not consistent. (does not follow fixed format specified)

AVozelj commented 9 years ago

Maybe we should add some kind of frd cleaning function:

def editfrdline(self,line):
    num=[]
    stri=line
    if stri[1:3]=='-1':
        stri=stri[13:]
        for i in range(0,2):
            fid=stri.find('E')
            powl=4
            if stri[fid+1]=='-' or stri[fid+1]=='+':
                powl+=1
            val1=stri[:fid+powl]
            stri=stri[fid+powl:]
            num.append(float(val1))
        num.append(float(stri))
        return line[0:13]+"%12.5e" % num[0]+"%12.5e" % num[1]+"%12.5e" % num[2]

above works for reparing of displacement results and goes line by line ... a little bit time consuming, I know.

spacether commented 9 years ago

Is the error in the 32 bit formatting consistent? If so we could hard code it into the environment module.

AVozelj commented 9 years ago

No, some rows in *.frd are OK, some not. Row length differs. As I see it depends on value.

Do you now pandas? Just another idea how we can read results in database manner. I am quite fan of it. Today I implement temporary solution of how to read displacement on 32 bit. Once you read data in dataframe you can do many things, for example calculate equivalent stress.

spacether commented 9 years ago

Per the file format documentation: CGX 2.7 documentation, Results Format, Nodal Results The results using 32 bit CCX are producing 'long format' format=1 results

The formatting for displacements stress etc should be: (1X,I2,I10,6E12.5)

But we are seeing: Formatting: (1X,I2,I10,1E12.5,1E13.5,1E13.5) Fields: unused_field,unused_field, node number, data1, data2, data3, data4, data5, data6 It appears that the second and third data columns sometimes take up 13 spaces, sometimes 12 This may be a problem with all columns

Can you implement a solution in regex rather than with pandas? Pandas adds another required include, which I'd like to avoid.

AVozelj commented 9 years ago

I read about frd formats. Pandas was just a suggestion.

spacether commented 9 years ago

I fixed this issue in the below commit: https://github.com/spacether/pycalculix/commit/2f2796c68a0fcb2476ccdc87480272c64f7bb186 Frd files are now edited to have the correct fixed formatting on win32 systems.