CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM (
-   -   orientationi & Sf[facei] - magneticFoam (

latvietis April 2, 2012 09:35

orientationi & Sf[facei] - magneticFoam

I have spent a lot of time in doing all kinds of manipulations with magneticFoam and finally I have almost come to the end. There is only one totally unclear line for me in createFields.H


const surfaceVectorField& Sf = mesh.Sf();

Mrf[facei] = Mri*(orientationi & Sf[facei]);

I guess my problem is more about C language not about magnetic field physics.

My questions:
What should I get out when these lines are compiled? I get surfaceScalarField in output, but shouldn't there be VectorField? What the first line defines, where information about this mesh.Sf will be taken from?

Mri is a constant, what should happen when I multiply a constant with those parameters in brackets? Also, there is orientation (that is some kind of vector) and then there is '&' symbol. Does it mean Mri is multiplied with orientationi and Sf[facei] in the same time?

Yours sincerely,

winden April 2, 2012 10:05

Hi Martin.

It is correct that you get a scalar if orientationi is a vector. the "&" means inner product, (vector & vector) gives a scalar inside the brackets which are then multiplied using scalar multiplication (*) with another scalar Mri.

As for Sf. The first line defines a new vectorfield Sf which is given the values of the face area normals of the mesh.


latvietis April 2, 2012 13:30

Thank you so much. It actually finally starts to make sense. Sad my C skills aren't so good yet to understand this by myself.

About face area - so I have defined all faces in a volume. That means if normals are taken and my mesh consists of tetrahedrons then from one cell I get 4 faces and every face would have its normal in different direction?

What should (and is that even possible?) I change so that output stays the same surfaceScalarField when I multiply orientation with something else? I mean, I want to use my tetrahedrons as volume elements, but now it seems their face normal orientation is the problem.


winden April 3, 2012 12:07


Not sure what the problem with the face normals is. If you post the expression you are trying to replicate, maybe we can figure out how to write it.


latvietis April 3, 2012 19:24

1 Attachment(s)
I'll try to explain as best I can.

At first here is full source code:

As I understand then this solver is capable of solving a magnetic field only if there are defined faces of magnet, it doesn't take in calculation the volume of magnet (because of usage of faces/surfaceFields). Still I somehow managed to include a volume of a bar magnet using topoSet. From what you said I guess I included all faces in this volume.

I added picture how my bar looks like. Its volume is filled with tetrahedrons. When solver defines your mentioned Sf field, as I can understand, it then takes every face inside this volume and draws a normal from it. And here comes the problem.

The mentioned constant Mrf is now multiplied with this normal. It is a small number, lets say it is 0.6 for some iron alloys (more info

So using transportPropoerties I define these constants. Permeability (the first constant of material) is read almost correctly, but when it comes to Mrf (remanence)... uhh. For example, I put Mrf as 0.6, but if I check if solver has kept this value (by using Mrf.write command), then it hasn't. Below I little copy-paste from file (that is what is written as Mrf in magnet):

PHP Code:


So I find this wrong because of surface normals that are in different directions (and I believe also different length) in volume.

My question then - is there a possible workaround? I need to see the magnetic field inside this magnet bar so I need to define properties of a material in all volume.

Oh, and there is another important thing. The calculations are done by using scalar potential - psi. I define it on the boundaries (magnet poles), for example 100 and -100. After the calculations are done, these values become higher, for example 130 and -120. Shouldn't this defined 'maximum' stay? What could be the cause of rising of psi value.

I hope I explained my problem.


winden April 4, 2012 05:18



Mrf[facei] = Mri*(orientationi & Sf[facei]);
This sets the value of Mrf only on the faces included in the faceZone as found by


label magnetZonei = mesh.faceZones().findZoneID(magnets[i].name());
And not every face in the mesh.

As for the values of Mrf: don't you mean that you put Mri to 0.6, this seems to be read from somewhere and then Mrf is calculated based on that value, the orientation and area of each face and the orientation of the magnet. I'm sorry I can't really help you with any magnet-related problems since I don't know anything about it.


All times are GMT -4. The time now is 00:46.