last day (24 days later) » 

13:33
1
A: Calculating the 3D magnetic vector field of a permanent magnet, with shape given by STL File

TschibiWith the help of user21 I was able to find a solution for my problem. Anyway there is still room for improvement as it is still a little hacky in my humble opinion. The problem that user21 pointed out rightly was the Curl[] - term that takes care of the magnetization within the PDE. It evaluates ...

OK, I'll continue to look into this. For now: Here is a much more efficient way to generate the interpolating functions: {magnetInterpolX, magnetInterpolY, magnetInterpolZ} = EvaluateOnElementMesh[{x, y, z}, magnetization,mesh]. Please also see this
Yes. This function is faster. I adapted the code in my answer accordingly. Anyway I could not implement it in the way you did, because I got an error, that EvaluateOnElementMesh does not evaluate to an scalar.
Your answer brings the improvement, that we can get rid of the additional regions as well. Overall this feels much less hacky than before ...
Try this then: AbsoluteTiming[{magnetInterpolX, magnetInterpolY, magnetInterpolZ} = EvaluateOnElementMesh[{x, y, z}, If[ElementMarker == 1, #, 0] & /@ magnetization, mesh]] If you have several things to evaluate over the same mesh, the EvaluateOnElementMesh is most efficient if you call it once and give it a list of functions to evaluate.
I still struggle with what this UnitStep->appro business does.....
U are right, thats way faster :-) The UnitStep Appro comes from an answer of xzczd to this Question: mathematica.stackexchange.com/questions/230282/… He writes: "The simplest solution is to approximate the piecewise constant with a continuous function:" For me the following happens: Easy Geometrie conditions will be translated to piecewise functions. Those in return can bet transformed to a function of f[x,y,z] using PiecewiseExpand. The Appro is only used to remove the Delta functions that are brought in by that, because They may disturbe NDSolve[]
I did see that post and I am trying to understand better what the issue is. Would it help if you had a representation of Curl[ mu[x,y,z] Curl[{Ax[x,y,z], Ay[x,y,z], Az[x,y,z]}, {x,y,z}],{x,y,z}]?
 
2 hours later…
15:22
Depends on the point of view ... From Physics point of view I am not aware of a formulation of my problem, where I could utilize this construct. Although I must admit, that there are many ways to adapt the Maxwell equations in order to fit the needs of a specific simulation and I do not know them in detail.
From a Mathematica User Point of view it would be interesting if this behavior occcurs with other types of PDEs to. I dont think that the field of a permanent magnet is the only problem where a field defined by constants over different mesh regions is used. Also I why it is not affecting

  last day (24 days later) »