CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   magneticFoam (https://www.cfd-online.com/Forums/openfoam-solving/95146-magneticfoam.html)

latvietis January 13, 2012 10:10

1 Attachment(s)
Hello again FOAMers!

I have payed a bit with magneticFoam and I'm almost sure that it works, just want to check with some PROs and also have few questions, that I hope will be answered.

1) http://img444.imageshack.us/img444/9207/scaleds.png

You see B lines from magnet. It looks kinda OK, if you ignore those 4 massive vectors from corners of magnet. What could be the reason for this kind of error? This image is scaled.

2) http://img441.imageshack.us/img441/5590/errorup.png

Again B lines, but picture isn't scaled so we can see vectors in all air field. But again an error: mesh is generated using something like this:

http://www.freewebs.com/mypicturesandsht/trapezoid.png

Then the largest facet (b2xL) is one boundry and smallest (b1xl) is side of magnet and together as you can imagine there are 6 'blocks'. This construction was chosen because of possibility of grading mesh (closer to magnet more cells).

The errors are circled in picture. The vectors are like sliding where 2 of these 'blocks' (or patches, don't know how to call them) meet. Is this a problem of mesh and there is a need for a different approach?

Sincelery,
latvietis

P.S. And of course - case file Attachment 10837 of all this.

wyldckat January 15, 2012 07:28

1 Attachment(s)
Hi latvietis,

This is looking very nice and very good indeed! And I would also like to hear/read from the PROs on this subject as well...

Here's my perspective on this:

Attached is a snapshot with streamlines instead of glyphs. The steps to achieve this were:
  1. Run paraFoam and then in ParaView, open the case file a second time. On the second opened file, select the patches and walls instead of the mesh volume.
  2. Then select the first file and go to Filters -> Alphabetical -> Stream Tracer with Custom Source. A dialog box appears:
    1. With the radio button on the left at Input, select on the right the first file.
    2. With the radio button on the left at Source, select the second file on the right.
    3. Press OK.
  3. Press apply. Now we have the streamlines originating from the patches and walls.
  4. Now Filters->Alphabetical->Tube. Change radius to one tenth of the value shown and Apply.

There is an interesting detail here: since it's a single iteration of calculating field equations, the zone representing the magnet is empty inside it, but the field is still calculated as if there were cells inside the magnet!

As for the concentrated glyphs/lines on the corners of the magnet - my guess is this is due to two reasons:
  1. Because the mesh is formed by cube-like cells, making it very complicated to calculate anything meaningful over the corners of the cells. This problem can happen with normal fluid flow as well.
  2. Because of the shape of the magnet... although a real magnet should probably have a more intense or weaker field on those corners, due to the stresses resulting from the manufacturing process.
Basically, it's like trying to calculate the tangent of 90 degrees: http://www.wolframalpha.com/input/?i=tan%2890%29

If you could generate a mesh that isn't so homogeneous, then it could be possible to determine if this is an error introduced by the mesh... which would still be very complicated, given the sharp corners of the magnet.

One thing that is bothering me is that this magnetic field doesn't feel very real when compared to that picture on wikipedia (on the magnet page): http://en.wikipedia.org/wiki/File:Magnet0873.png - I think this is because the side wall of the magnet is being disregarded as a magnetic source.

I tried merging the two N-S and even the 3 patches of the magnet into a single magnet, but the solver crashed on both tries.
I then added a third magnet and associated it to the side wall of the magnet, but there was not effect. My guess is because "mag_side" has a zero gradient boundary condition for the "psi" field.

I don't know enough about this to even try to give a hint in the right direction. My hunch is simply that the current boundary conditions are what they are: a North patch and a South patch sources, with no magnet in between them :(
If it is meant to represent a single N-S magnet, then the streamlines near the body of the magnet should have different angles.

The other detail is that bounds of the surrounding mesh seem to affect the magnetic field itself.

This could really use the help of someone with more experience on magnetic field simulation ;)

Best regards,
Bruno

latvietis February 22, 2012 09:08

3 Attachment(s)
Greetings!

I'm spending a lot of time to find out what magneticFoam is capable of.

Firstly, thanks Bruno for meshing solution, Blender+enGrid works kinda nice though enGrid is a bit buggy and often quits without saying why. Maybe I need to find some other conversation between Blender and BlockMesh for example.

Secondly, I managed to make nice (at least I think so) images with 2 magnets. Do you think they are ok? In the end I think I also managed to fill magnets with cells and it still works (it isn't showed in these pics though).

But now the part where I have stopped. The thing I want to find is how magnetic field is affected by some kind of material, e.g. iron rod/wire. I also want to see how magnetic field behaves in this rod. So I have set up 2 magnet system with a plate. In image it is possible to see the outcome and it doesn't look good. I guess there are things I don't know how to define:
1) The volume inside the magnets/rod. I don't know how to define relativePermeability and remanence (from transport properties) in all volume. That means I can't define magnetic properties of my objects. I tried using boxToCell in topoSet, but I don't think it works as I want.
2) Another thing is boundary condtions of surfaces. How should I define the boundaries of my wire? zeroGradient doesn't look as the best choice, but I can't think of anything else.

Yours sincerely,
Martin

P.S. In last image I hope you can see the 2 magnets and my rod (the largest box) perpendicular to them.

wyldckat February 25, 2012 18:17

Hi Martin,

Quote:

Originally Posted by latvietis (Post 345741)
Firstly, thanks Bruno for meshing solution, Blender+enGrid works kinda nice though enGrid is a bit buggy and often quits without saying why. Maybe I need to find some other conversation between Blender and BlockMesh for example.

You're welcome! There is another way for easier generation of meshes... well, if the geometries are relatively simple:
  1. Make the volume mesh, without defining the magnets and/or obstacles.
  2. Then use setSet and subsetMesh to remove the cells where the magnets and/obstacles should go! I usually go to the following tutorial for reference: http://openfoamwiki.net/index.php/SetSet
Basically, the idea is to draw the total volume with blockMesh; then with setSet, select the cells that the wall will occupy and then invert the selection, in order to have the remaining mesh. After having the cells you want to keep selected, you can use subsetMesh to write those cells as the new mesh!
Er... wait, maybe this is already being done with topoSet...

Quote:

Originally Posted by latvietis (Post 345741)
Secondly, I managed to make nice (at least I think so) images with 2 magnets. Do you think they are ok? In the end I think I also managed to fill magnets with cells and it still works (it isn't showed in these pics though).

Looks very nice indeed! I can't see any flaws in those two images.

Quote:

Originally Posted by latvietis (Post 345741)
But now the part where I have stopped. The thing I want to find is how magnetic field is affected by some kind of material, e.g. iron rod/wire. I also want to see how magnetic field behaves in this rod. So I have set up 2 magnet system with a plate. In image it is possible to see the outcome and it doesn't look good.

I don't think I've got very good news for you: magneticFoam is a simple solver that simply solves one or two equations and gives the solution pretty much in a single go.
By what I can understand, it assumes the surrounding environment is either air or (most likely) vacuum. It allows you to calculate how the magnetic fields interact between magnets, but I think that you can't go any further without doing some coding of additional terms on the equations or even adding a few more equations.

Quote:

Originally Posted by latvietis (Post 345741)
I guess there are things I don't know how to define:
1) The volume inside the magnets/rod. I don't know how to define relativePermeability and remanence (from transport properties) in all volume. That means I can't define magnetic properties of my objects. I tried using boxToCell in topoSet, but I don't think it works as I want.

You can check the two other solvers that exist in the folder "$FOAM_APP/solvers/electromagnetics/", namely:
  • electrostaticFoam - this should be a solver somewhat similar to magneticFoam, but meant for electrostatic fields.
  • mhdFoam - from here you can get some info on how magnetic fields can interact with fluids.
You should be able to get more information for what you need by examining other solvers that OpenFOAM has. Also, seeing the following wiki tutorials should help you a bit more in understanding how things work in OpenFOAM:
Quote:

Originally Posted by latvietis (Post 345741)
2) Another thing is boundary condtions of surfaces. How should I define the boundaries of my wire? zeroGradient doesn't look as the best choice, but I can't think of anything else.

The closest scenario I can remember from what I've seen in OpenFOAM, would be the chtMultiRegion*Foam solvers, which transfer heat from solid regions to fluid regions. The mhdFoam tutorial "hartmann" should also give you a bit more info.
Mmmm... maybe the "calculated" boundary condition might work...

Quote:

Originally Posted by latvietis (Post 345741)
P.S. In last image I hope you can see the 2 magnets and my rod (the largest box) perpendicular to them.

Yes, I can see it. Indeed something bad/wrong is going on there. It could be a problem with not enough mesh resolution on that zone with the crooked magnetic lines, or the problem is starting to go into an area where a more complex solver will be required, in order to smoothen those crooked lines.

Best regards,
Bruno

latvietis February 26, 2012 22:36

Yes, the modification of solver has started, but with not much progress at the moment.

I thought about usage of "calculated" BC, but it usually just drops error message:

"You are probably trying to solve for a field with a default boundary condition."

I think I understand the meaning of this error, but I don't know the workaround. I believe it says that I'm solving for a field where I have defined the value of "internalField". Or something like that... How does this "calculated" BC actually work? I was looking in forums etc., but I couldn't find a simple explanation/usage of this (or maybe I lack some skills of searching).

Thanks for reminding to look in other electromagnetic solvers - at least they have proper examples that could help.

Best regards,
Martin

wyldckat February 28, 2012 16:55

Hi Martin,

Quote:

Originally Posted by latvietis (Post 346384)
I thought about usage of "calculated" BC, but it usually just drops error message:

"You are probably trying to solve for a field with a default boundary condition."

I think I understand the meaning of this error, but I don't know the workaround.

I've only used it properly once or twice. If I remember correctly, it only works if the boundary condition can be calculated based on all other boundaries. For example, if the velocity U is fixed, then p can be calculated for the same patch... or something like that.

As for searching, check the tutorials:
Code:

cd $FOAM_TUTORIALS
find . | xargs grep 'calculated' -sl

This will give a list of all of the files that mention the word "calculated" :)

Best regards,
Bruno

latvietis March 11, 2012 21:11

Please delete this post, found my answer.

latvietis March 18, 2012 16:01

3 Attachment(s)
Greetings!

I'm having really hard time to find a way how to tell magneticFoam that there is also volume of magnet. I believe all my problems are in solver functions

Code:

solve(fvm::laplacian(murf, psi) + fvc::div(murf*Mrf));

fvc::reconstruct(fvc::snGrad(psi)*mesh.magSf())

constant::electromagnetic::mu0*fvc::reconstruct(murf*fvc::snGrad(psi)*mesh.magSf() + murf*Mrf)

I have tried different ways to change surfaceScalarField to volScalarField, but it just doesn't work.

Do you have any suggestions what to add to solver so I could define volume of magnet not just its poles?

There is another thing:
since I can't define volume of magnet (I believe that is reason why), magneticFoam solves bad B-field values. They should be like the 3rd attached picture, but instead B is solved similar to H (1st and 2nd picture, they are the same though different fields are drawn).



Any hints how to get proper field lines?

Sincerely,
Martin

wyldckat March 18, 2012 16:13

Hi Martin,

I ended up not having any spare time to look into this :(

But I've remembered something that perhaps might help: porous solvers!
Code:

find $FOAM_SOLVERS -iname "*porous*"
There is always a limited zone of the mesh that is defined as being porous, thus having a different way to solve things there.

Another question: I didn't see the equations you posted here in detail, but I'm wondering where exactly you placed them!?

edit: About the first two pictures: how about showing in streamlines as well ;)

Best regards,
Bruno

latvietis March 18, 2012 16:45

1 Attachment(s)
Oh, those equations are in magneticFoam.C file. First is to solve psi, second for H-field and last for B-field. I haven't changed them. I have tried different approaches in changing things in createfields.H. For example, I changed all face to cell so I would define one magnet in transportproperties and it should have same permeability and remanence in all volume. I could compile solver this way, but I didn't get the images I wanted.

There is another thing. I added these lines in magneticFoam.C so I could check values that I give from transportProperties:
Code:

    murf.write();
    Mrf.write();

I got really confused because it defined boundary patches (magnet poles) with default values (that is 1 and 0). Why is that? Also, I noticed that when I change values to transportproperties it actually doesn't affect result. I could set permeability to 100 or 100000 or whatever and the B/psi/H results would be the same. Any ideas why is that?

I attached streamline pic below (only B lines, but I can tell you that I got the same pic with H lines). Color is by psi.

Ok, I'll look to that porus solver!

Martin

wyldckat May 31, 2012 14:20

Hi Martin,

I was browsing the web for info on any leak about "OpenFOAM 2.2" and I picked up on this report: OpenFOAM Simulation for Electromagnetic Problems
It seems to be waaaaaaaaaaaay better documented than magneticFoam ;)

I've added this reference to the wiki page: http://openfoamwiki.net/index.php/MagneticFoam

Best regards,
Bruno

latvietis May 31, 2012 15:18

Yeah, I'm working with this solver for some time now, it doesn't actually work that simple as explained there. Problem is with boundary conditions (that is why I have written in many threads about mapped or cyclic BCs).

Martin

veshapa February 20, 2014 10:18

Hi Latvietis,

Did you succeed in producing the boundary conditions that would make the magnetic lines in magneticFoam look reasonable? If so, could you please share?

Best regards,
Goga

bklose August 28, 2014 08:51

Quote:

Originally Posted by latvietis (Post 350110)
Oh, those equations are in magneticFoam.C file. First is to solve psi, second for H-field and last for B-field. I haven't changed them. I have tried different approaches in changing things in createfields.H. For example, I changed all face to cell so I would define one magnet in transportproperties and it should have same permeability and remanence in all volume. I could compile solver this way, but I didn't get the images I wanted.

There is another thing. I added these lines in magneticFoam.C so I could check values that I give from transportProperties:
Code:

    murf.write();
    Mrf.write();

I got really confused because it defined boundary patches (magnet poles) with default values (that is 1 and 0). Why is that? Also, I noticed that when I change values to transportproperties it actually doesn't affect result. I could set permeability to 100 or 100000 or whatever and the B/psi/H results would be the same. Any ideas why is that?

I attached streamline pic below (only B lines, but I can tell you that I got the same pic with H lines). Color is by psi.

Ok, I'll look to that porus solver!

Martin

Hello everyone,

I've been working a lot with magneticFoam during the last weeks and I figured out, why remanence and relative permeability do not change.
Both working examples provided in this thread use the following topoSetDict command:
Code:

    {
        name    magnet1;
        type    faceZoneSet;
        action  new;
        source  patchToFace;
        sourceInfo
        {
            name mag_north;
        }
    }

Even though faceZones are generated, they are empty (check constant/polyMesh/faceZones). So, the last loop in the createFileds.H file is skipped and only pre-set values are taken. By changing the topoSetDict code to
Code:

    {
        name    magnet1;
        type    faceSet;
        action  new;
        source  patchToFace;
        sourceInfo
        {
            name mag_north;
        }
    }
    {
        name    magnet1;
        type    faceZoneSet;
        action  new;
        source  setToFaceZone;
        sourceInfo
        {
            faceSet magnet1;
        }
    }

faceZones are generated. Oddly, error massages occur in some cases. They seem to depend on the geometry of the working case. But it works in a lot of computations I've made.

Greets, Björn

james.heis@durham.ac.uk December 3, 2015 10:37

James
 
Hey, thanks for this tutorial - very useful.
However, when I try to run it I get an error message 'Cannot find faceZone for magnet magnet1'
Do you know why this is? I am very new to this kind of thing.

bklose December 3, 2015 11:21

3 Attachment(s)
Quote:

Originally Posted by james.heis@durham.ac.uk (Post 576077)
Hey, thanks for this tutorial - very useful.
However, when I try to run it I get an error message 'Cannot find faceZone for magnet magnet1'
Do you know why this is? I am very new to this kind of thing.

Hey,

I wrote a more comprehensive tutorial some time ago. I posted the relevant passage below:

The magnetic field of a cylindrical magnet with the following specifications is computed.
  • Magnetization M = 860 kA/m
  • Length L = 20 mm
  • Radius R = 10 mm
Firstly, a bounding volume has to be defined. This can easily be done by using blockMesh. The volume must be large enough, so the boundaries have little influence on the magnetic field near the magnet. Here, a box with the dimensions of 200mm × 200mm × 200mm is created.
The next step is to define the geometry of the magnet itself. To this end the volume of the magnet has to be set as a faceZone via topoSet:
Code:

actions
 (
    {
        name    magnet1;
        type    cellSet;
        action  new;
        source  cylinderToCell;
        sourceInfo
        {
            p1 (-0.01 0 0); // start point on cylinder axis
            p2 (0.01 0 0); // end point on cylinder axis
            radius 0.01;
        }
    }
    {
        name    magnet1;
        type    cellZoneSet;
        action  new;
        source  setToCellZone;
        sourceInfo
        {
            set magnet1;
        }
    }
    {
        name    magnet1;
        type    faceSet;
        action  new;
        source  cellToFace;
        sourceInfo
        {
            set    magnet1;
            option  all;
        }
    }
    {
        name    magnet1;
        type    faceZoneSet;
        action  new;
        source  setToFaceZone;
        sourceInfo
        {
            faceSet magnet1;
        }
    }
 

 );

The permanent magnet consists of cells selected by cylinderToCell in the topoSetDict and have specific properties that are defined in the transportProperties, i.e. name, relative permeability, remanent magnetization and direction:

Code:

magnets
 (
  (magnet1 1 860000 (1 0 0))
 );

The 0 directory contains only the file for the boundary conditions of the magnetic scalar potential psi:

Code:

dimensions      [0 0 0 0 0 1 0];
 
 internalField  uniform 0;
 

 boundaryField
 {
    walls
    {
        type            zeroGradient;
    }
 }

It is important to note that the magnet itself is not considered to be a solid in magneticFoam. The solver needs to compute the inner material of the magnet so that the magnet material is exclusively defined via topoSet.

The first image shows the cells that are selected by cylinderToCell. The other two pictures illustrate the magnetic field (H and B) right in the middle of the geometry.

Best, Bjoern

james.heis@durham.ac.uk December 5, 2015 11:19

Thanks for this response, have you got the link to the more comprehensive tutorial? I'd like to give it a go in its entirety.

james.heis@durham.ac.uk February 9, 2016 08:04

Hey

Has anybody managed to write a code for the surrounding area of the magnets? I want to be able to see their flux lines through metal as well as through free space.

Cheers
James

flowgeek February 20, 2019 12:31

cannot find murf?!?
 
hi all,


trying to use magneticFoam... and failing ;-) so you might can help me...


i'm just trying to run the example case with openfoam v1806 - and i get the following error message:


--> FOAM FATAL ERROR

cannot find file ".../0/murf"


as far as i understand the code the murf and the Mrf fields should be created by the solver?


has anybody tried to run magnetFoam on a recent openfoam version?

cjessup37 March 3, 2020 15:03

Quote:

Originally Posted by bklose (Post 576080)
Hey,

I wrote a more comprehensive tutorial some time ago. I posted the relevant passage below:

The magnetic field of a cylindrical magnet with the following specifications is computed.
  • Magnetization M = 860 kA/m
  • Length L = 20 mm
  • Radius R = 10 mm
Firstly, a bounding volume has to be defined. This can easily be done by using blockMesh. The volume must be large enough, so the boundaries have little influence on the magnetic field near the magnet. Here, a box with the dimensions of 200mm × 200mm × 200mm is created.
The next step is to define the geometry of the magnet itself. To this end the volume of the magnet has to be set as a faceZone via topoSet:
Code:

actions
 (
    {
        name    magnet1;
        type    cellSet;
        action  new;
        source  cylinderToCell;
        sourceInfo
        {
            p1 (-0.01 0 0); // start point on cylinder axis
            p2 (0.01 0 0); // end point on cylinder axis
            radius 0.01;
        }
    }
    {
        name    magnet1;
        type    cellZoneSet;
        action  new;
        source  setToCellZone;
        sourceInfo
        {
            set magnet1;
        }
    }
    {
        name    magnet1;
        type    faceSet;
        action  new;
        source  cellToFace;
        sourceInfo
        {
            set    magnet1;
            option  all;
        }
    }
    {
        name    magnet1;
        type    faceZoneSet;
        action  new;
        source  setToFaceZone;
        sourceInfo
        {
            faceSet magnet1;
        }
    }
 

 );

The permanent magnet consists of cells selected by cylinderToCell in the topoSetDict and have specific properties that are defined in the transportProperties, i.e. name, relative permeability, remanent magnetization and direction:

Code:

magnets
 (
  (magnet1 1 860000 (1 0 0))
 );

The 0 directory contains only the file for the boundary conditions of the magnetic scalar potential psi:

Code:

dimensions      [0 0 0 0 0 1 0];
 
 internalField  uniform 0;
 

 boundaryField
 {
    walls
    {
        type            zeroGradient;
    }
 }

It is important to note that the magnet itself is not considered to be a solid in magneticFoam. The solver needs to compute the inner material of the magnet so that the magnet material is exclusively defined via topoSet.

The first image shows the cells that are selected by cylinderToCell. The other two pictures illustrate the magnetic field (H and B) right in the middle of the geometry.

Best, Bjoern

Hi Bjorn. Do you have a link to your comprehensive tutorial on magneticFoam with a cylindrical magnet that I may access? Your example would me understand the basics of using magneticFoam. Thanks!


All times are GMT -4. The time now is 06:49.