Units of user defined equation in FEM result

About the development of the FEM module/workbench.

Moderator: bernd

wmayer
Founder
Posts: 20309
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Units of user defined equation in FEM result

Post by wmayer »

reox wrote: Thu Feb 13, 2020 6:56 pm
wmayer wrote: Thu Feb 13, 2020 4:19 pm A much better way is to use a Python parser like ply (Python-Lex-Yacc)
that one looks promising! Seems like it looked into the wrong direction. I thought there might be some numpy equation solver.
Actually, we don't have an equation here but an assignment of an expression to a variable.
wmayer
Founder
Posts: 20309
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Units of user defined equation in FEM result

Post by wmayer »

git commit 53bbf09bf implements the grammar for the ply parser.

Currently the code inside _ViewProviderFemResultMechanical.py is disabled because it requires the Python ply package.
To test the code activate it and comment out the call of eval().
reox
Posts: 929
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: Units of user defined equation in FEM result

Post by reox »

But you can not use numpy now?

Note sure if I find some time today, but maybe I can try that on the weekend!
wmayer
Founder
Posts: 20309
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Units of user defined equation in FEM result

Post by wmayer »

But you can not use numpy now?
I don't think that numpy includes an expression parser and that's what we need here.

See also:
https://stackoverflow.com/questions/412 ... py-ndarray
this uses a hand-written parser https://github.com/Axiacore/py-expression-eval

https://numexpr.readthedocs.io/projects ... index.html
This implements a specialized parser tailored for numpy but it's all in C and thus more difficult to use. At least for Debian & co there are official packages available but for Windows we then have to upgrade the LibPack again.

Therefore using ply is the easiest because there is also a package for Debian and for Windows devs with an older LibPack they can easily upgrade it. All what they have to do is adding the ply directory from the link above to the site-packages directory of the LibPack.
reox
Posts: 929
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: Units of user defined equation in FEM result

Post by reox »

wmayer wrote: Fri Feb 14, 2020 12:24 am git commit 53bbf09bf implements the grammar for the ply parser.

Currently the code inside _ViewProviderFemResultMechanical.py is disabled because it requires the Python ply package.
To test the code activate it and comment out the call of eval().
I had to regenerate the FEM result, because I got this error:

Code: Select all

Traceback (most recent call last):
  File "/usr/lib/freecad-daily/Mod/Fem/femguiobjects/_ViewProviderFemResultMechanical.py", line 465, in calculate
    rx = np.array(self.result_obj.ReinforcementRatio_x)
AttributeError: 'FeaturePython' object has no attribute 'ReinforcementRatio_x'
However, after regeneration I get this error:

Code: Select all

WARNING: Couldn't open 'parser.out'. [Errno 13] Keine Berechtigung: '/usr/lib/freecad-daily/Mod/Fem/femtools/parser.out'
WARNING: Token 'COMMENT' defined, but not used
WARNING: There is 1 unused token
Generating LALR tables
WARNING: Couldn't create 'femtools.parsetab'. [Errno 13] Keine Berechtigung: '/usr/lib/freecad-daily/Mod/Fem/femtools/parsetab.py'
Maybe the grammar file should be generated in the ~/.FreeCAD folder?
But it looks like the result is written into the fields min,avg and max and also the nodes are colored correctly I think.

If you enter some illegal input, like np.sqrt(x), then you just get the error message on the python console. But other than that it looks quite good!
wmayer
Founder
Posts: 20309
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Units of user defined equation in FEM result

Post by wmayer »

Traceback (most recent call last):
File "/usr/lib/freecad-daily/Mod/Fem/femguiobjects/_ViewProviderFemResultMechanical.py", line 465, in calculate
rx = np.array(self.result_obj.ReinforcementRatio_x)
AttributeError: 'FeaturePython' object has no attribute 'ReinforcementRatio_x'
There was recently a PR that changed a property name. Maybe this caused the problem.
WARNING: Couldn't open 'parser.out'. [Errno 13] Keine Berechtigung: '/usr/lib/freecad-daily/Mod/Fem/femtools/parser.out'
WARNING: Token 'COMMENT' defined, but not used
WARNING: There is 1 unused token
Generating LALR tables
WARNING: Couldn't create 'femtools.parsetab'. [Errno 13] Keine Berechtigung: '/usr/lib/freecad-daily/Mod/Fem/femtools/parsetab.py'
On my system I couldn't see that it wants to create such a file. I wonder what happens if you try to open an OpenSCAD file? Therefore ply is also used.
Maybe the grammar file should be generated in the ~/.FreeCAD folder?
Whenever I modified the grammar file and imported it I got a message "Generating LALR tables" but I don't know where things are stored.
If you enter some illegal input, like np.sqrt(x), then you just get the error message on the python console. But other than that it looks quite good!
The question is how to handle this? The example I used catches exceptions when an unknown identifier is used, prints a message but then sets the identifier to 0. We can leave it like this or remove the exception handling from the grammar file and let the application code handle it.
reox
Posts: 929
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: Units of user defined equation in FEM result

Post by reox »

wmayer wrote: Sat Feb 15, 2020 7:05 pm
WARNING: Couldn't open 'parser.out'. [Errno 13] Keine Berechtigung: '/usr/lib/freecad-daily/Mod/Fem/femtools/parser.out'
WARNING: Token 'COMMENT' defined, but not used
WARNING: There is 1 unused token
Generating LALR tables
WARNING: Couldn't create 'femtools.parsetab'. [Errno 13] Keine Berechtigung: '/usr/lib/freecad-daily/Mod/Fem/femtools/parsetab.py'
On my system I couldn't see that it wants to create such a file. I wonder what happens if you try to open an OpenSCAD file? Therefore ply is also used.
I converted some file to CSG and then I get this error message:

Code: Select all

WARNING: Token 'DOT' defined, but not used
WARNING: Token 'WORD' defined, but not used
WARNING: There are 2 unused tokens
WARNING: Couldn't create 'parsetab'. [Errno 13] Keine Berechtigung: '/usr/lib/freecad-daily/Mod/OpenSCAD/parsetab.py'
End processing CSG file
So this seems to be an issue with ply?
wmayer wrote: Sat Feb 15, 2020 7:05 pm There was recently a PR that changed a property name. Maybe this caused the problem.
I'm using this version:

Code: Select all

OS: Debian GNU/Linux bullseye/sid (i3/i3)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.19603 (Git)
Build type: Release
Branch: master
Hash: 62251e3b398ce7d46aba6c84d68da990bfb8b0f9
Python version: 3.8.2rc1
Qt version: 5.12.5
Coin version: 4.0.0
OCC version: 7.3.0
Locale: German/Austria (de_AT)
Which i build today using debian experimental pyside2.
wmayer
Founder
Posts: 20309
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Units of user defined equation in FEM result

Post by wmayer »

I converted some file to CSG and then I get this error message:
Do you get it each time or only once?
wmayer
Founder
Posts: 20309
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Units of user defined equation in FEM result

Post by wmayer »

wmayer wrote: Sat Feb 15, 2020 8:03 pm
I converted some file to CSG and then I get this error message:
Do you get it each time or only once?
In case it happens all the time there is a way to fix it. The function yacc() provides a keyword argument outputdir where an arbitrary path can be passed to write out the parsetab.py file.
reox
Posts: 929
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: Units of user defined equation in FEM result

Post by reox »

I tried to open the csg file from the list of recent files, but this gives me this error:

Code: Select all

<string>(26)<class 'SyntaxError'>: ('invalid syntax', ('<string>', 1, 8, 'import \n'))
The csg file does not open from this list...

However, opening it via the File menu still works, but I get this output every time (opened the file three consecutive times):

Code: Select all

WARNING: Token 'DOT' defined, but not used
WARNING: Token 'WORD' defined, but not used
WARNING: There are 2 unused tokens
WARNING: Couldn't create 'parsetab'. [Errno 13] Keine Berechtigung: '/usr/lib/freecad-daily/Mod/OpenSCAD/parsetab.py'
End processing CSG file
WARNING: Token 'DOT' defined, but not used
WARNING: Token 'WORD' defined, but not used
WARNING: There are 2 unused tokens
WARNING: Couldn't create 'parsetab'. [Errno 13] Keine Berechtigung: '/usr/lib/freecad-daily/Mod/OpenSCAD/parsetab.py'
End processing CSG file
WARNING: Token 'DOT' defined, but not used
WARNING: Token 'WORD' defined, but not used
WARNING: There are 2 unused tokens
WARNING: Couldn't create 'parsetab'. [Errno 13] Keine Berechtigung: '/usr/lib/freecad-daily/Mod/OpenSCAD/parsetab.py'
End processing CSG file
Post Reply