Materials dialogue problem

About the development of the FEM module/workbench.

Moderator: bernd

HoWil
Veteran
Posts: 1279
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Materials dialogue problem

Post by HoWil »

Values change in the dialogue boxes of a FluidMaterial in FEM-wb after I confirm with OK. When I check the values in python console (see below) or when I reopening the material-dialogue I see that the values are not the one I entered (see also the two screenshots below).
Some values are scaled (maybe converted wrongly) others are reseted to e.g. 1m^2/s.
Screenshots_material_dialogue.svg.png
Screenshots_material_dialogue.svg.png (310.57 KiB) Viewed 3659 times

Code: Select all

App.ActiveDocument.FluidMaterial.Material
{'Name': u'Air', 'Density': u'12.0 kg/m^3', 'MolarMass': u'28.965', 'KinematicViscosity': u'1000.0 m^2/s', 'ThermalExpansionCoefficient': u'0 um/m/K', 'SpecificHeat': u'1005.0 J/kg/K', 'VolumetricThermalExpansionCoefficient': u'1.0 m/m/K', 'DynamicViscosity': u'1.80e-5 kg/m/s', 'ThermalConductivity': u'257.0 W/m/K', 'PrandtlNumber': u'0.7', 'Description': u'Standard air properties at 20 Degrees Celsius and 1 atm'}
A similar but slightly different behavior can be observed with the SolidMaterial dialogue. When I change the Expansion Coefficient of e.g. Calculix-Stell form 12,00 µm/m/K to 12,5µm/m/K, press OK and reopen the dialogue then the values change to 125 µm/m/K. The values are not only displayed this way... they are also stored as can be seen in the python-console:

Code: Select all

App.ActiveDocument.SolidMaterial.Material
{'Name': u'CalculiX-Steel', 'Density': u'7850.0 kg/m^3', 'ThermalExpansionCoefficient': u'125.0 um/m/K', 'YoungsModulus': u'21000000.0 kPa', 'Father': u'Metal', 'SpecificHeat': u'590.0 J/kg/K', 'ThermalConductivity': u'43.0 W/m/K', 'PoissonRatio': u'0.32', 'Description': u'Standard steel material for CalculiX sample calculations'}
A working material library is necessary to showcase the results of the GSoC-Projekt of Markus. Any hints how this could be fixed or where to start?

BR,
HoWil

OS: Ubuntu 16.04.3 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.11797 (Git)
Build type: None
Branch: master
Hash: a5080329d8da6653495df686efbda62e73ac950a
Python version: 2.7.12
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.1.0
Locale: English/UnitedStates (en_US)
UR_
Veteran
Posts: 1354
Joined: Tue Jan 03, 2017 8:42 pm

Re: Materials dialogue problem

Post by UR_ »

HoWil wrote: Tue Aug 22, 2017 7:09 pm When I change the Expansion Coefficient of e.g. Calculix-Stell form 12,00 µm/m/K to 12,5µm/m/K, press OK and reopen the dialogue then the values change to 125 µm/m/K
Same on win 10. :(
In case of expansion coefficient, behaviour can be avoided by using "u" instead of geek char "µ". :?
(dialog display is wrong, but console App.ActiveDocument.SolidMaterial.Material is ok)
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Materials dialogue problem

Post by bernd »

https://github.com/FreeCAD/FreeCAD/blob ... #L224-L311

But I can not have a look at this ATM. All my spare time I'm on the new solver framework. Bernd
HoWil
Veteran
Posts: 1279
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: Materials dialogue problem

Post by HoWil »

bernd wrote: Wed Aug 23, 2017 5:10 am https://github.com/FreeCAD/FreeCAD/blob ... #L224-L311

But I can not have a look at this ATM. All my spare time I'm on the new solver framework. Bernd
I know.
Any other volunteers :D who are able look into this.
It is really a showstopper and is frustrating for new users creating multiphysics simulations. This did cost markus and myself days when testing the new framework with elmer and calculix :?.
I will open a ticket to keep this in mind. Will set the priority relatively high.
BR
Howil
BTW.: In my opinion should the two material dialogues be united. I also saw that there is e.g. the dynamic and the kinematic viscosity stored inside the material dictionary. This is problematic as both values are related via the density and one alway has to update the other one when changing a value, what will for sure be forgotten some time.
HoWil
Veteran
Posts: 1279
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: Materials dialogue problem

Post by HoWil »

Created issue #3167
HoWil
Veteran
Posts: 1279
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: Materials dialogue problem

Post by HoWil »

oliveroxtoby posted here some information which should help solving the above problem....
https://forum.freecadweb.org/viewtopic. ... 1a#p189664
So the problem was that we were setting the value into the input box as a string in the 'C' locale (I think - the default way that python prints it) whereas the input box needs to interpret it in the user's locale. You *do* want to store quantities in the C locale in the material database in order to have a canonical storage format, but before entering it into the text box it needs to be converted to the user's locale. I had some problems using python's locale.str() function for this, as it doesn't seems to have the same interpretation of language versus input locale as FreeCAD. Thus I used the Quantity.UserString function to achieve the same effect. So for example where you set the density at https://github.com/FreeCAD/FreeCAD/blob ... al.py#L364
I think you could rather do
q = FreeCAD.Units.Quantity("{} {}".format(density_with_new_unit, density_new_unit))
self.form.input_fd_density.setText(q.UserString)

Hope that helps!
HoWil
Veteran
Posts: 1279
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: Materials dialogue problem

Post by HoWil »

some thoughts I want to save here for me and maybe others interested in this topic:
I looked into '_TaskPanelFemMaterial.py' and played a bit with solid- and fluid- materials in FC-python-console.
I think that the problem arises from two things:
  • First, there is maybe still a problem with locals; When I load a material like air into the fluidic-material-dialouge I see a decimal point e.g. for the density I get '1.2 kg/m^3'. And after reopening the dialogue I see '12,00 kg/m^3'. Now with different decimal-separator and different value.
  • Second, I think there is some problem with small values like the kinematic viscosity of air of originally '1.511e-05 m^2/s' which changes to '1000,00 mm^2/s' after reopening. This is maybe related to the 'comparison' (which I do not understand :oops: ) with 'variation' as seen below.

    Code: Select all

        def kinematic_viscosity_changed(self, value):
            old_nu = Units.Quantity(self.material['KinematicViscosity']).getValueAs("m^2/s")
            variation = 0.000001
            if value:
                if not (1 - variation < float(old_nu) / value < 1 + variation):
                    # KinematicViscosity has changed
                    material = self.material
                    value_in_m2_per_second = value
                    material['KinematicViscosity'] = unicode(value_in_m2_per_second) + " m^2/s"
                    self.material = material
For relatively large values seen in solid material like '7900,00 kg/m^3' for the density of steel both above described problem will not arise.
lambda
Posts: 91
Joined: Sat Feb 25, 2017 3:10 pm
Contact:

Re: Materials dialogue problem

Post by lambda »

I think there is at least a third problem involving units. The following is with the "C" locale, so locales shouldn't be an issue.

If I set the thermal conductivity to a value >= 1.00 W/m/K everything works fine.
If I set the thermal conducitvity to eg 0.9 W/m/K, the correct value is shown in the python console. However when I open the dialog again, it shows 0.00 W/mm/K. Since 0.9 W/m/K is 0.0009 W/mm/K this is actually correct within display precision. OTOH this is pretty unhelpful.

Looks like FreeCAD tries to do something smart but confuses itself. I haven't figured out which code handles this fancy switching of display units.

This is with recent git d4769e70237147d80174284e28e337d3c3cdf4d6

Harald
lambda
Posts: 91
Joined: Sat Feb 25, 2017 3:10 pm
Contact:

Re: Materials dialogue problem

Post by lambda »

One step further. Looks like this is a general problem of the units system:

Code: Select all

>>> from Units import Unit,Quantity
>>> Quantity('0.9 W/m/K').UserString
u'0.00 W/mm/K'
>>> Quantity('0.9 W/m/K').getUserPreferred()
(u'0.00 W/mm/K', 1000000.0, u'W/mm/K')
>>> Quantity('1.1 W/m/K').UserString
u'1.10 W/m/K'
>>> Quantity('1.1 W/m/K').getUserPreferred()
(u'1.10 W/m/K', 1000.0, u'W/m/K')
lambda
Posts: 91
Joined: Sat Feb 25, 2017 3:10 pm
Contact:

Re: Materials dialogue problem

Post by lambda »

The bug is in 'src/Base/UnitsSchemaInternal.cpp':

Code: Select all

5cb8873794 (wmayer        2016-08-05 10:00:12 +0200 116)     else if (unit == Unit::ThermalConductivity) {
5cb8873794 (wmayer        2016-08-05 10:00:12 +0200 117)         if (UnitValue < 1000) {
1c89c566c9 (wmayer        2016-08-04 17:26:12 +0200 118)             unitString = QString::fromLatin1("W/mm/K");
7ab8a9996d (wmayer        2017-07-24 16:52:03 +0200 119)             factor = 1000000.0;
5cb8873794 (wmayer        2016-08-05 10:00:12 +0200 120)         }
5cb8873794 (wmayer        2016-08-05 10:00:12 +0200 121)         else {
1c89c566c9 (wmayer        2016-08-04 17:26:12 +0200 122)             unitString = QString::fromLatin1("W/m/K");
1c89c566c9 (wmayer        2016-08-04 17:26:12 +0200 123)             factor = 1000.0;
1c89c566c9 (wmayer        2016-08-04 17:26:12 +0200 124)         }
5cb8873794 (wmayer        2016-08-05 10:00:12 +0200 125)     }
I think the test should be

Code: Select all

if(UnitValue > 1000000)
I will prepare a PR and also check if some of the other issues discussed in this thread, have the same kind of root cause.
Post Reply