Elmer electrostatics FEM

About the development of the FEM module/workbench.

Moderator: bernd

Post Reply
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Elmer electrostatics FEM

Post by bernd »

start FreeCAD run the unit test will fail ...

Code: Select all

import Test, femtest.app.test_object
Test.runTestsFromModule(femtest.app.test_object)

Code: Select all

Python 3.7.3 (default, Dec 20 2019, 18:57:59) 
[GCC 8.3.0] on linux
Type 'help', 'copyright', 'credits' or 'license' for more information.
>>> 
>>> import Test, femtest.app.test_object
>>> Test.runTestsFromModule(femtest.app.test_object)
test_00print (femtest.app.test_object.TestObjectCreate) ... ok
test_femobjects_make (femtest.app.test_object.TestObjectCreate) ... FAIL
test_00print (femtest.app.test_object.TestObjectType) ... ok
test_femobjects_derivedfromfem (femtest.app.test_object.TestObjectType) ... FAIL
test_femobjects_derivedfromstd (femtest.app.test_object.TestObjectType) ... FAIL
test_femobjects_isoftype (femtest.app.test_object.TestObjectType) ... FAIL
test_femobjects_type (femtest.app.test_object.TestObjectType) ... FAIL

======================================================================
FAIL: test_femobjects_make (femtest.app.test_object.TestObjectCreate)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/hugo/Documents/dev/freecad/freecadbhb_dev/build/Mod/Fem/femtest/app/test_object.py", line 134, in test_femobjects_make
    self.assertEqual(len(analysis.Group), count_defmake - 1)
AssertionError: 50 != 51

======================================================================
FAIL: test_femobjects_derivedfromfem (femtest.app.test_object.TestObjectType)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/hugo/Documents/dev/freecad/freecadbhb_dev/build/Mod/Fem/femtest/app/test_object.py", line 1290, in test_femobjects_derivedfromfem
    self.assertEqual(len(doc.Objects), testtools.get_defmake_count(False))
AssertionError: 46 != 47

======================================================================
FAIL: test_femobjects_derivedfromstd (femtest.app.test_object.TestObjectType)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/hugo/Documents/dev/freecad/freecadbhb_dev/build/Mod/Fem/femtest/app/test_object.py", line 1538, in test_femobjects_derivedfromstd
    self.assertEqual(len(doc.Objects), testtools.get_defmake_count(False))
AssertionError: 46 != 47

======================================================================
FAIL: test_femobjects_isoftype (femtest.app.test_object.TestObjectType)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/hugo/Documents/dev/freecad/freecadbhb_dev/build/Mod/Fem/femtest/app/test_object.py", line 575, in test_femobjects_isoftype
    self.assertEqual(len(doc.Objects), testtools.get_defmake_count(False))
AssertionError: 46 != 47

======================================================================
FAIL: test_femobjects_type (femtest.app.test_object.TestObjectType)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/hugo/Documents/dev/freecad/freecadbhb_dev/build/Mod/Fem/femtest/app/test_object.py", line 372, in test_femobjects_type
    self.assertEqual(len(doc.Objects), testtools.get_defmake_count(False))
AssertionError: 46 != 47

----------------------------------------------------------------------
Ran 7 tests in 0.769s

FAILED (failures=5)

this will give you an idea what is needed:
https://github.com/FreeCAD/FreeCAD/comm ... 0e1280a097
HoWil
Veteran
Posts: 1279
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: Elmer electrostatics FEM

Post by HoWil »

bernd wrote: Fri Mar 20, 2020 5:54 am start FreeCAD run the unit test will fail ...
gives

Code: Select all

import Test
>>> import femtest.app.test_object
Traceback (most recent call last):
  File "<input>", line 1, in <module>
ModuleNotFoundError: No module named 'femtest'
Since FEM is not available (from dropdown-Start-Menu) maybe femtest also isn't.
HoWil
Veteran
Posts: 1279
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: Elmer electrostatics FEM

Post by HoWil »

bernd wrote: Fri Mar 20, 2020 5:48 am you mixed electricforcesolver and electricforce.
You are right. Added all your changes to my branch but still have no success. Will clear all all build files and try again.
I will try your branch if this does not help.
bernd wrote: Fri Mar 20, 2020 5:48 am Should it be named equation electricforcesolver or equation electricforce?
Since it is a equation object it may make the user feel unsecure if the equation is called solver but not a solver object?
We should decide to use either name of them and use this name overall.
You are right.
In FreeCAD:
Elmer is the solver
electric force is the equation

The confusion comes from the side of Elmer where the related section in the solver-output-file reads like :shock: :D .... after Solver1 and Solver2 :

Code: Select all

Solver 3
Equation = Electric Force
Procedure = "ElectricForce" "StatElecForce"
End
...
Equation 3
  Active Solvers(2) = Integer 1 2 3
End
raback
Posts: 75
Joined: Fri May 08, 2020 4:02 pm
Location: Finland
Contact:

Re: Elmer electrostatics FEM

Post by raback »

Hi

Has anybody tried to create magnetostatics cases with Elmer under FreeCAD? Electrostatics results to the canonical Poisson equation easily solvable with standard nodal elements. Magnetostatics in 3D needs Hcurl conforming elements (a.k.a. edge elements) for the vector potential, at least if one wants to model properly the interfaces between materials of different permeabilities. There is a plethora of FE solvers that can deal with the Poisson equation but only a few that can solve the 3D magnetostatics. Hence implementing this interface for Elmer could have great marginal utility.

Often these two equations may be also weakly coupled. Elecrostatics is used to compute the currents in conductors and magnetostatics the resulting magnetic fields in the surrounding volume. There are certainly some good example to start from to be found.

-Peter
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Elmer electrostatics FEM

Post by bernd »

FYI:

From git commit 6e0e7580fd it should be possible ro read all old FEM files from the FEM forum.
HoWil
Veteran
Posts: 1279
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: Elmer electrostatics FEM

Post by HoWil »

raback wrote: Sat May 09, 2020 1:01 pm Hi

Has anybody tried to create magnetostatics cases with Elmer under FreeCAD? Electrostatics results to the canonical Poisson equation easily solvable with standard nodal elements. Magnetostatics in 3D needs Hcurl conforming elements (a.k.a. edge elements) for the vector potential, at least if one wants to model properly the interfaces between materials of different permeabilities. There is a plethora of FE solvers that can deal with the Poisson equation but only a few that can solve the 3D magnetostatics. Hence implementing this interface for Elmer could have great marginal utility.

Often these two equations may be also weakly coupled. Elecrostatics is used to compute the currents in conductors and magnetostatics the resulting magnetic fields in the surrounding volume. There are certainly some good example to start from to be found.

-Peter
No, I am not aware of any magnetostatic simulation in FC-Elmer yet. I try to implement all necessary adoptions to support electrostatics because I have interest in running electrostatics simulations not because they are generally easier to compute.
If the support for force calculation is implemented (see https://github.com/HoWilgh/FreeCAD/tree/femelmeresforce) than we will be able to ship at least two tutorial examples for electrostatics with FC.
BTW: is there a way to calculate more than one force in one simulation? If I use "Calculate Electric Force = True" on several boundaries than the forces on these boundaries are summed up, or?

Hopefully this can be done with/before 0.19! Help on implementing the FC-side (which is basically only tedious detail work) is for sure very much appreciated 8-) .
After that magnetics is for sure on the plan.
BR
raback
Posts: 75
Joined: Fri May 08, 2020 4:02 pm
Location: Finland
Contact:

Re: Elmer electrostatics FEM

Post by raback »

Hi

About the ElectricForce:

Could you give a pointer to the sif file that you want to implement?

There are two different strategies to do electrostatic coupling. In the 1st you create force distributed force fields and in the second you compute nodal loads (Elmer test cases ElastElstatBeam vs. ElastElstatBeamNodal). The latter could be generalized with little work so that one would not need to activate BCs at all.

Yes, if the solver is active on many BCs the forces will be summed up.

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

Re: Elmer electrostatics FEM

Post by HoWil »

raback wrote: Mon May 18, 2020 8:33 am Hi

About the ElectricForce:

Could you give a pointer to the sif file that you want to implement?
I will prepare a simple 3D and a equivalent 2D model of a parallel plate capacitor. EDIT: I am also happy if you have some simple 2D/3D models you can share and which we can easily doublecheck analytically.
raback wrote: Mon May 18, 2020 8:33 am There are two different strategies to do electrostatic coupling. In the 1st you create force distributed force fields and in the second you compute nodal loads (Elmer test cases ElastElstatBeam vs. ElastElstatBeamNodal). The latter could be generalized with little work so that one would not need to activate BCs at all.
Yes, if the solver is active on many BCs the forces will be summed up.
Why not using something similar to the calculation of the capacitance where I can specify different 'ports' and the capacitance is given between all different pairs of ports. I am sure the mathematics behind the calculation of the capacitance and the forces is completely different but It is much simpler for the user to specify a boundary and get the total force on this boundary without running a integration on the nodes of the boundary afterwards.
HoWil
Veteran
Posts: 1279
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: Elmer electrostatics FEM

Post by HoWil »

Found a (self-inflicted :?) bug related to the definition of the permittivity of vacuum in Elmer-Writer.
The units for the epsilon_0 is F/m which is in pythonish SI base units `A**2 * s**4 * kg**−1 * m**−3 = A**2 * s**4 / (kg * m**3)` which can be expressed as `T^4 * I^2 / (L^3 * M) where e.g. L is the length-unit. See also https://en.wikipedia.org/wiki/Vacuum_permittivity .

Therefore, in 'https://github.com/FreeCAD/FreeCAD/blob ... /writer.py' in line 343 one has to change

Code: Select all

            getConstant("PermittivityOfVacuum", "T^4*I^2/(L*M)"))
to

Code: Select all

            getConstant("PermittivityOfVacuum", "T^4*I^2/(L^3*M)"))
and im 'https://github.com/FreeCAD/FreeCAD/blob ... nstants.py' line 44

Code: Select all

    return "8.8542e-12 s^4*A^2/(m*kg)"
has to be changed into:

Code: Select all

    return "8.8542e-12 s^4*A^2 / (m^3 * kg)"
EDIT: changed m**3 into m^3
Anyone willing to double-check that?

BTW just for documentation: if I use the python quantities package:
for meters

Code: Select all

import quantities as pq
epsilon_0 = 8.854E-12 * (pq.A**2 * pq.s**4 / (pq.kg*pq.m**3))
print("Permittivity of Vacuum in F/m : " + str(epsilon_0.rescale(pq.F/pq.m)))
I get "Permittivity of Vacuum in F/m : 8.854e-12 F/m" which is the same when I use FC-based mm with prior scaling
for mm

Code: Select all

import quantities as pq
epsilon_0 = 8.854E-12 * (1/1000)**3 * (pq.A**2 * pq.s**4 / (pq.kg*pq.mm**3))
print("Permittivity of Vacuum in F/m : " + str(epsilon_0.rescale(pq.F/pq.m)))
EDIT:

Code: Select all

print("Permittivity of Vacuum in mm-based units : " + str(epsilon_0.rescale((pq.A**2 * pq.s**4 / (pq.kg*pq.mm**3)))))
gives
Permittivity of Vacuum in mm-based units : 8.853999999999999e-21 s**4*A**2/(kg*mm**3)
Last edited by HoWil on Thu Jun 04, 2020 6:29 pm, edited 2 times in total.
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Elmer electrostatics FEM

Post by bernd »

Post Reply