[report] implementation of electrodynamics

About the development of the FEM module/workbench.

Moderator: bernd

User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

[report] implementation of electrodynamics

Post by uwestoehr »

I am kindly sponsored by the OpenToolchain foundation to implement electrodynamics simulations to FreeCAD's FEM workbench.
The grant was given on January 27th and will ran until begin of March.

Update:
The project is over and here is what I achieved:

1. implemented support for the basic Electromagnetic solver equation of Elmer in 3D and 2D:
* https://wiki.freecad.org/FEM_EquationMagnetodynamic
* https://wiki.freecad.org/FEM_EquationMagnetodynamic2D

This includes new necessary constraints:
* https://wiki.freecad.org/FEM_ConstraintCurrentDensity
* https://wiki.freecad.org/FEM_ConstraintMagnetization
* the extension of https://wiki.freecad.org/FEM_Constraint ... cPotential for vector fields

2. implement a new result filter to display field lines in 2D and 3D:
* https://wiki.freecad.org/FEM_PostFilterContours

3. since the simulation requires a lot of CPU power, it is more or less mandatory to perform the calculations using several CPU cores.
The existing multi-CPU support had some issues in visualizing the results. These could be resolved by the new implemented result filtering:
* https://wiki.freecad.org/FEM_Preferences#Elmer

4. the FEM examples (https://wiki.freecad.org/FEM_Examples) received new example analyses, demonstrating the new capabilities of the Elmer support:
* 2 examples of electrodynamics
* an example of magnetostatics
* an example of air that is heated while flowing
* an example of potential and heat flux

5. for practical usage it is important to quickly setup analyses. Existing issues in the Material handling made this hard (depending on the language settings in FreeCAD).
I was able to fix all remaining Material handling issues: viewtopic.php?p=489666#p489666

To test the new features, you need a version of FreeCAD master from February 27th or newer.
Here is a Windows build: https://github.com/FreeCAD/FreeCAD-Bund ... taller.exe
For Linux and Mac, check the next Weekly build released after February 27th: https://github.com/FreeCAD/FreeCAD-Bund ... kly-builds

------------------------------

Here is the report what I have done and will do:

Refactorings
- At first there were some under-the-hood changes necessary to prepare FreeCAD for the feature additions. For example the Elmer writer had to be refactored, which in sum took a full day.
- the material cards can now hold the property "Magnetic permeability".
- FreeCAD can now handle the quantity "current density"

Additions:
- there is a new constraint to specify current densities: https://wiki.freecad.org/FEM_ConstraintCurrentDensity
- the Elmer writer got the info about the vacuum magnetic permeability (magnetic field constant)
- as first milestone the equation "Magnetodynamic 2D" was added: https://wiki.freecad.org/FEM_EquationMagnetodynamic2D
With this, it is possible to perform simulations, as in Elmer's tutorial number 16 (https://www.nic.funet.fi/index/elmer/do ... orials.pdf)

To test the additions, I created a Windows build:
https://github.com/FreeCAD/FreeCAD-Bund ... taller.exe
(the next regular weekly will contain the additions as well)

Here is a FreeCAD file that is Elmer's tutorial number 16: https://github.com/FreeCAD/FreeCAD/file ... eating.zip

Done but not yet merged:
- Since harmonically driven forces result in complex outputs, I added additional result fields, that show the absolute values of the complex results. This saves manual work to compute it out of the real and imaginary parts.
- equation "Magnetodynamic" With this it is possible to perform simulations like in Elmer's tutorial number 14 (https://www.nic.funet.fi/index/elmer/do ... orials.pdf)
- to specify electric potential vector fields, the electrostatic potential constraint was extended accordingly.

ToDo:
- new constraint to specify the magnetization
- handle the Elmer results of elementary fields. FreeCAD cannot deal with them at the moment and sometimes even crashes when attempting to display them.
- check if Elmer's tutorial number 15 can be done now as well 8should be the case already)
- add Elmer's tutorial 14, 15 and 16 o the FEM examples
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: [report] implementation of electrodynamics

Post by uwestoehr »

The next milestone was achieved: electromagnetics in 3D

- first, to support magnetostatics using the 2D equation implemented in the first milestone, magnetization must be specified. This is now possible using the magnetization constraint: https://wiki.freecad.org/FEM_ConstraintMagnetization

- for 3D, the material editor had to be extended to accept vectorial inputs, the https://wiki.freecad.org/FEM_Constraint ... cPotential had to be extended to specify the components of a vector potential. The same was with the https://wiki.freecad.org/FEM_ConstraintCurrentDensity that was also extended to 3D

- eventually the new https://wiki.freecad.org/FEM_EquationMagnetodynamic could be added

To test the new feature, I created a Windows build of FreeCAD's current master: https://github.com/FreeCAD/FreeCAD-Bund ... taller.exe
It is also recommended to use the latest nightly build from Elmer. See the installation links given in https://wiki.freecad.org/FEM_SolverElmer#Installation

results:
- it is now possible to perform magnetostatics analyses like the magnetic horseshoe in Elmer's tutorial number 15. Here is a FreeCAD file for this tutorial: https://github.com/FreeCAD/FreeCAD/file ... seshoe.zip
FreeCAD_0lZe3214G2.png
FreeCAD_0lZe3214G2.png (73.57 KiB) Viewed 17200 times
- it is now possible to perform electromagnetics/magnetodynamics in 3D. For example to calculate the electromagnetic fields around a wire as in Elmer's tutorial number 14. Here is a FreeCAD file for this tutorial: https://github.com/FreeCAD/FreeCAD/file ... ldWire.zip
Image

Todo:
- electromagnetics fields are best viszualized using the field lines. This feature is missing in FreeCAD. I already implemented an iso-contour filter:
FreeCAD_Wpx1Eq05Cj.png
FreeCAD_Wpx1Eq05Cj.png (16.21 KiB) Viewed 17200 times
However, the work to make this nicely work will need more time.
- besides iso-contours, one also needs this feature for 3D - iso-surfaces
- there is also some fine-tuning to be done (adapting e.g. the data point result filter for electromagnetics results)
- FreeCAD needs to handle the elementary field results
- Since 3D analyses need a lot of CPU power, it is important to use the multi-CPU core feature I already implemented previously: https://wiki.freecad.org/Release_notes_ ... _Workbench
missing is hereby to merge the result volumes to one for nice visualizations

Thanks:
many thanks go to @raback and the whole Elmer team for their bugfixing.
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: [report] implementation of electrodynamics

Post by uwestoehr »

uwestoehr wrote: Sat Feb 11, 2023 9:10 pm - electromagnetics fields are best viszualized using the field lines. This feature is missing in FreeCAD.
However, the work to make this nicely work will need more time.
- besides iso-contours, one also needs this feature for 3D - iso-surfaces
Both is now ready to be merged, see there the catchy images :) :
https://github.com/FreeCAD/FreeCAD/pull/8462
User avatar
saso
Veteran
Posts: 1920
Joined: Fri May 16, 2014 1:14 pm
Contact:

Re: [report] implementation of electrodynamics

Post by saso »

awesome! :D
MitjaN
Posts: 11
Joined: Sat Apr 03, 2021 3:30 pm

Re: [report] implementation of electrodynamics

Post by MitjaN »

Is there any chance to expand your work to include also static current equation? Upstreaming HoWil's work viewtopic.php?t=48867 would be really great.
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: [report] implementation of electrodynamics

Post by uwestoehr »

MitjaN wrote: Mon Feb 13, 2023 7:44 am Is there any chance to expand your work to include also static current equation?
Unfortunately no. The project time is too short and I also have a real life and a job.

The challenge on the static current is not adding the equation but the text input. As you can read in the thread you linked, this is not an easy task.
I had similar issues with the magnetodynamics equations - every new equation requires some under-the-hood changes in FreeCAD. This costs a lot of time, also for testing because such changes affect many parts of FreeCAD.
MitjaN
Posts: 11
Joined: Sat Apr 03, 2021 3:30 pm

Re: [report] implementation of electrodynamics

Post by MitjaN »

Thanks for the prompt reply and the background information.
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: [report] implementation of electrodynamics

Post by uwestoehr »

The last project milestone was achieved: There is now a filter to create iso-surfaces and iso-contours.

So e.g. electric/magnetic field lines can be visualized:
Image

Of course the new filter can be used for any analysis, also for CalculiX results.

- all new features are already properly documented, here is the one for the new filter: https://wiki.freecad.org/FEM_PostFilterContours

- the previously mentioned necessary fine-tuning was meanwhile done (registering the new possible results to the DataAtPoint filter etc.)

- I extended the project a bit, because in order to do real-life analyses, one must use more than one CPU core. I already implemented support for this last year: viewtopic.php?p=610617#p610617
For proper visualizations of the results, it is a problem that the borders of the volumes calculated by each CPU is always visible.
I spent some time to find a solution. The issue is independent of FreeCAD and Elmer, is is a property of the *.pvtu file format. The solution is to filter the mesh using VTK's extractor filter. This works if the FEM mesh is 2nd (which is the default in FreeCAD). The solution is a ready to merge PR, I would only test it some more before merging.
For 1st order meshes, there is apparently no way to get rid of the visible volume borders. Note that not all Elmer equations can handle 2nd order meshes. See for example the magnetodynamic equation that needs the special option "Quadratic Approximation" to allow this: https://wiki.freecad.org/FEM_EquationMa ... etodynamic

Many thanks to @RichB2k for his help in the Elmer forum and his bugfix to Elmer.
david69
Veteran
Posts: 1773
Joined: Wed Jan 01, 2014 7:48 pm

Re: [report] implementation of electrodynamics

Post by david69 »

thanks for the progress and reporting.

on Crowdin,
https://crowdin.com/translate/freecad/559/en-fr#6610741 --> typo
https://crowdin.com/translate/freecad/559/en-fr#6611303 --> typo

https://crowdin.com/translate/freecad/559/en-fr#6610749 seems to be stuck
https://crowdin.com/translate/freecad/559/en-fr#6611295 seems to be stuck

I keep an eye on that one https://crowdin.com/translate/freecad/559/en-fr#6611301 as it was translated 6 days ago, but may be too early to see it on the GUI.

I don't see "Contours filter" in crowdin for translation.
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: [report] implementation of electrodynamics

Post by uwestoehr »

Thanks, this is now fixed for the next Crowdin update: https://github.com/FreeCAD/FreeCAD/pull/8551
I don't know. the source code seems correct.
david69 wrote: Sun Feb 19, 2023 3:59 pm I don't see "Contours filter" in crowdin for translation.
It seems the feature was added after the last Crowdin sync.
Post Reply