Units of user defined equation in FEM result

About the development of the FEM module/workbench.

Moderator: bernd

reox
Posts: 717
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Units of user defined equation in FEM result

Post by reox » Tue Jan 14, 2020 1:47 pm

I wanted to show Strain Energy Density (SED) for all elements, so I plugged in this formular into the "User defined equation":

Code: Select all

1.0/2.0 * (sxx*exx + syy*eyy + szz*ezz + 2*sxy*exy + 2*sxz*exz + 2*syz*eyz)
I noticed that the information about the units is lost in the result view, i.e. I see the value without the Unit (I expected to see something like MPa).
Would it be possible to get the unit as well for the user defined equations? How do I know in which unit the values are? (I hope that if I have the setting as Standard I will get N/mm² hence MPa)

And another question: is it possible to save such user defined equations for later? Is there some python interface? I looked at the python console but could not see any output.
UR_
Posts: 1149
Joined: Tue Jan 03, 2017 8:42 pm

Re: Units of user defined equation in FEM result

Post by UR_ » Tue Jan 14, 2020 2:54 pm

Nothing prevents you from using fanciful equations like: np.sqrt(x)+sxx


ATM, there is no units handling:

Code: Select all

...
userdefined_eq = self.form.user_def_eq.toPlainText()  # Get equation to be used
UserDefinedFormula = eval(userdefined_eq).tolist()
...
userdefined_eq could be saved, perhaps in a property from result object.
But it's get lost if result object is deleted.
reox
Posts: 717
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: Units of user defined equation in FEM result

Post by reox » Tue Jan 14, 2020 3:58 pm

UR_ wrote:
Tue Jan 14, 2020 2:54 pm
Nothing prevents you from using fanciful equations like: np.sqrt(x)+sxx
the fanciful equation would be to use the tensor form directly :P

I also noticed that there seems to be no check if you enter garbage. The only indication that you messed up is, if the result is always 0.
reox
Posts: 717
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: Units of user defined equation in FEM result

Post by reox » Wed Jan 15, 2020 8:11 am

Here is an example:
Bildschirmfoto vom 2020-01-15 09-08-38.png
Bildschirmfoto vom 2020-01-15 09-08-38.png (23.14 KiB) Viewed 331 times
In this case, the equation worked - no units are available.
Bildschirmfoto vom 2020-01-15 09-09-34.png
Bildschirmfoto vom 2020-01-15 09-09-34.png (23.66 KiB) Viewed 331 times
Now, I added the syntax error, I get no information that something is wrong. The only indication is, that I have the units again and all fields are zero.

Code: Select all

OS: CentOS Linux 7 (Core) (XFCE/xfce)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.19242 (Git) AppImage
Build type: Release
Branch: master
Hash: 2d752745c298108a1d7ec756bd0ca57818c7a174
Python version: 3.7.6
Qt version: 5.12.5
Coin version: 4.0.0a
OCC version: 7.4.0
Locale: German/Germany (de_DE)
User avatar
bernd
Posts: 8997
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Units of user defined equation in FEM result

Post by bernd » Wed Jan 15, 2020 11:15 am

UR_ wrote:
Tue Jan 14, 2020 2:54 pm
userdefined_eq could be saved, perhaps in a property from result object.
But it's get lost if result object is deleted.
No ATM it can not be saved.
User avatar
bernd
Posts: 8997
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Units of user defined equation in FEM result

Post by bernd » Wed Jan 15, 2020 11:16 am

reox wrote:
Wed Jan 15, 2020 8:11 am
Here is an example:
Bildschirmfoto vom 2020-01-15 09-08-38.png
In this case, the equation worked - no units are available.

Bildschirmfoto vom 2020-01-15 09-09-34.png
Now, I added the syntax error, I get no information that something is wrong. The only indication is, that I have the units again and all fields are zero.
https://github.com/FreeCAD/FreeCAD/blob ... #L500-L502 feel free to improve the handling on bad user input and go for a PR ...
reox
Posts: 717
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: Units of user defined equation in FEM result

Post by reox » Wed Jan 15, 2020 12:15 pm

bernd wrote:
Wed Jan 15, 2020 11:16 am
feel free to improve the handling on bad user input and go for a PR
I'll see what I can do! The use of eval feels a little bit bad - especially if one wants to save the userinput in the file... This would probably only lead to malicious files which delete everything on opening. So this is mitigated right now by not saving the user input in the fc file.
User avatar
bernd
Posts: 8997
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Units of user defined equation in FEM result

Post by bernd » Wed Jan 15, 2020 1:39 pm

If we would like to save it we need to have the security in mind! One should not be able to use it to do danger things ...
reox
Posts: 717
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: Units of user defined equation in FEM result

Post by reox » Wed Jan 15, 2020 6:56 pm

I guess the safest would be to use some sort of parser, but this always means you would have to implement all functions in the parser itself...
Sympy has some functionality like this: https://docs.sympy.org/1.5.1/modules/co ... re.sympify
maybe there are equivalents for numpy as well

On the other hand, if there is an easy way to do this from a macro, I would probably go the macro way. For example with the SED, I would also like to calculate mean values of the elements etc. This can not be done from the GUI anyways.
User avatar
bernd
Posts: 8997
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Units of user defined equation in FEM result

Post by bernd » Wed Jan 15, 2020 8:02 pm

teading result values of the element integration points and store them in vtk result is on the todo. there is some script of fandaL which can do this already with the current result data structure.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest