trying to calculate the magnetic field of a permanent magnet using the finite element method I struggle setting up the equation system properly. In the end I want to be able to calculate the magnetic fields for any kind of shapes but I started with the easy system described bellow:
Needs["NDSolve`FEM`"]
(*Generate Geometry*)
pts = {{0, 0, 0}, {0, 1, 0}, {1, 1, 0}, {1, 0, 0}, {0, 0, 1}, {0, 1,
1}, {1, 1, 1}, {1, 0, 1}};
pts1 = ScalingTransform[{3, 3, 3}][pts];
pts2 = TranslationTransform[{1, 1, 1}][pts];
hex = {{2, 3, 4, 1}, {1, 4, 8, 5}, {4, 3, 7, 8}, {3, 2, 6, 7}, {2, 1,
5, 6}, {5, 8, 7, 6}};
bmesh = BoundaryMeshRegion[Join[pts1, pts2], Polygon[hex],
Polygon[hex + 8], MeshCellStyle -> Opacity[0.3]];
HighlightMesh[bmesh, Labeled[0, "Index"]]
bmesh = bmesh = ToBoundaryMesh[bmesh]
To generate the following output:
According to the documentation (Wolfram Documentation) I continued defining markers for the different parts of the region
(*Generate Markers*)
cuboidCoordinates = {{1.5, 1.5, 1.5}};
airCoordinates = {0.5, 0.5, 0.5};
markerColors = {Red, Blue};
markerCoordinates = {{cuboidCoordinates}, {airCoordinates}};
Show[bmesh["Wireframe"],
Graphics3D[
MapThread[{PointSize[0.02], #1, Point /@ #2} &, {markerColors,
markerCoordinates}]
]
]
Before I started the meshing process:
markerSpecification = {{airCoordinates, 1 }, {cuboidCoordinates[[1]],
2}}
mesh = ToElementMesh[bmesh, "RegionMarker" -> markerSpecification]
mesh["Wireframe"]
When I now start to set up the differential equation I always run into errors:
I use:
\[Mu]Air = 4 \[Pi]*10^-7;
u = {ux[x, y, z], uy[x, y, z], uz[x, y, z]};
M = Piecewise[{{{1, 0, 0}, ElementMarker == 2}}, {0, 0, 0}];
pde = Inactive[Curl][
Inactive[Dot][1/[Mu]Air, Inactive[Curl][u, {x, y, z}]] - M, {x,
y, z}] == {0, 0, 0};
bcs = DirichletCondition[
u[x, y, z] == { 0, 0, 0}, {x, y, z} [NotElement] mesh];
usol = NDSolveValue[{bcs, pde}, u, {x, y, z} [Element] mesh]
Where M should be the magnetization of the permanent magnet and get the following error message:

I compared my solution to the Wolfram documentation as well as the answers in the following Question 3D FEM Vector Potential and unfortunately I can not see my mistake. So my questions are:
- How can I make this code work?
- Is my approach suitable for this type of problems?
**UPDATE: For a more advances approach to the computation of magnetic field, please have a look at the question follow up question over here **
Thanks in advance.
Best regards Tschibi2000







Thread[Equal[{ux[..].uy[],..},{0,0,0}]]– user21 Nov 19 '21 at 15:02