Error while setting material

About the development of the FEM module/workbench.

Moderator: bernd

usbhub
Posts: 194
Joined: Tue Apr 02, 2019 8:22 pm
Location: Earth

Error while setting material

Postby usbhub » Sat Aug 24, 2019 7:40 pm

Hello
I hope this is not a duplicate, but I can't find any similar bug.

If you click on "Creates a FEM material for solid" then you get this error in the output window, but you get a material, but if you try to start the calculation, you get an error message ("No YoungsModulus defined for at least one material.
No PoissonRatio defined for at least one material."):

Code: Select all

Traceback (most recent call last):
  File "/usr/share/freecad/Mod/Fem/femguiobjects/_ViewProviderFemMaterial.py", line 71, in setEdit
    taskd = _TaskPanelFemMaterial(self.Object)
  File "/usr/share/freecad/Mod/Fem/femguiobjects/_ViewProviderFemMaterial.py", line 151, in __init__
    self.import_materials()
  File "/usr/share/freecad/Mod/Fem/femguiobjects/_ViewProviderFemMaterial.py", line 574, in import_materials
    self.import_solid_materials()
  File "/usr/share/freecad/Mod/Fem/femguiobjects/_ViewProviderFemMaterial.py", line 581, in import_solid_materials
    self.add_cards_from_a_dir(system_mat_dir, ":/icons/freecad.svg")
  File "/usr/share/freecad/Mod/Fem/femguiobjects/_ViewProviderFemMaterial.py", line 620, in add_cards_from_a_dir
    self.materials[a_path] = Material.importFCMat(a_path)
  File "/usr/share/freecad/Mod/Material/Material.py", line 65, in importFCMat
    Config.read(fileName, encoding='utf-8') # respect unicode filenames
<type 'exceptions.TypeError'>: read() got an unexpected keyword argument 'encoding'
I wanted to try the example with the cube and one force on it. I have used the FEM workbench already, but with another version. I wanted to try out the new functions, e.g. the beam on the right side. In the annex you find the fcstd file.

usbhub

PS: OS: Linux Mint 19
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.3.
Build type: Release
Python version: 2.7.15+
Qt version: 5.9.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: German/Germany (de_DE)
Attachments
bug.FCStd
(19.18 KiB) Downloaded 10 times
UR_
Posts: 1102
Joined: Tue Jan 03, 2017 8:42 pm

Re: Error while setting material

Postby UR_ » Sun Aug 25, 2019 5:35 am

Just can't say anything about version 0.18.3, because I'm using 0.19

version:
OS: Windows 10 (10.0)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.17876 (Git)
Build type: Release
Branch: master
Hash: c4e34ed9bea1eec2376be1520b427c84cbd7595a
Python version: 3.7.3
Qt version: 5.9.7
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: German/Germany (de_DE)


But can't reproduce here.


Ensure settings by Edit->Preferences->FEM->Material

Screenshot 002.png
Screenshot 002.png (35.96 KiB) Viewed 306 times

select a material from drop down menu (of course with appropriate Young's and Poisson values)

Screenshot 003.png
Screenshot 003.png (45.47 KiB) Viewed 306 times

nice results

Screenshot 004.png
Screenshot 004.png (20.44 KiB) Viewed 306 times
Syres
Posts: 416
Joined: Thu Aug 09, 2018 11:14 am

Re: Error while setting material

Postby Syres » Sun Aug 25, 2019 8:09 am

usbhub wrote:
Sat Aug 24, 2019 7:40 pm
If you click on "Creates a FEM material for solid" then you get this error in the output window, but you get a material, but if you try to start the calculation, you get an error message ("No YoungsModulus defined for at least one material.
No PoissonRatio defined for at least one material."):

Code: Select all

Traceback (most recent call last):
  File "/usr/share/freecad/Mod/Fem/femguiobjects/_ViewProviderFemMaterial.py", line 71, in setEdit
    taskd = _TaskPanelFemMaterial(self.Object)
  File "/usr/share/freecad/Mod/Fem/femguiobjects/_ViewProviderFemMaterial.py", line 151, in __init__
    self.import_materials()
  File "/usr/share/freecad/Mod/Fem/femguiobjects/_ViewProviderFemMaterial.py", line 574, in import_materials
    self.import_solid_materials()
  File "/usr/share/freecad/Mod/Fem/femguiobjects/_ViewProviderFemMaterial.py", line 581, in import_solid_materials
    self.add_cards_from_a_dir(system_mat_dir, ":/icons/freecad.svg")
  File "/usr/share/freecad/Mod/Fem/femguiobjects/_ViewProviderFemMaterial.py", line 620, in add_cards_from_a_dir
    self.materials[a_path] = Material.importFCMat(a_path)
  File "/usr/share/freecad/Mod/Material/Material.py", line 65, in importFCMat
    Config.read(fileName, encoding='utf-8') # respect unicode filenames
<type 'exceptions.TypeError'>: read() got an unexpected keyword argument 'encoding'
This is generated because the script hasn't got a Python version check therefore to make it compatible with both I would suggest changing src\Mod\Material\Material.py around line 64 from:

Code: Select all

    Config.optionxform = str
    Config.read(fileName, encoding='utf-8') # respect unicode filenames
    dict1 = {}
to:

Code: Select all

    Config.optionxform = str
    import sys
    if sys.version_info.major >= 3:
        Config.read(fileName, encoding='utf-8') # respect unicode filenames
    else:
        Config.read(fileName)
    dict1 = {}
This will mean if you upgrade your Python (recommended) in the future it will still work.
usbhub
Posts: 194
Joined: Tue Apr 02, 2019 8:22 pm
Location: Earth

Re: Error while setting material

Postby usbhub » Sun Aug 25, 2019 7:42 pm

UR_ wrote:
Sun Aug 25, 2019 5:35 am
Just can't say anything about version 0.18.3, because I'm using 0.19

version:
OS: Windows 10 (10.0)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.17876 (Git)
Build type: Release
Branch: master
Hash: c4e34ed9bea1eec2376be1520b427c84cbd7595a
Python version: 3.7.3
Qt version: 5.9.7
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: German/Germany (de_DE)


But can't reproduce here.


Ensure settings by Edit->Preferences->FEM->Material


Screenshot 002.png


select a material from drop down menu (of course with appropriate Young's and Poisson values)


Screenshot 003.png


nice results


Screenshot 004.png
I have not all settings that you have, maybe because the different versions.

With me the dialogue does not open, so I cant choose a material. But I will try it with the 0.19 version.
User avatar
bernd
Posts: 8733
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Error while setting material

Postby bernd » Mon Aug 26, 2019 6:35 am

was fixed in early 0.19 development git commit 6a8f6e2

git commit 1e9f9fa backports this to 0.18