-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ravaud cuboid field #14
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
%Matthew Forbes - [email protected] | ||
|
||
%Eqn from Ravaud 2009 - MAGNETIC FIELD PRODUCED BY A PARALLELEPI- | ||
% PEDIC MAGNET OF VARIOUS AND UNIFORM POLAR- | ||
% ZATION | ||
|
||
function H = cuboid_field(sigma,phi,theta,x_m,y_m,z_m,X,Y,Z) | ||
|
||
%theta - CCW angle from the +x-axis to the polarisation vector | ||
% (XY-plane // about Z) | ||
%phi - CW angle from the +z-axis to the polarisation vector | ||
%x1,y1,z1 - reference corner of magnet | ||
%x2,y2,z2 - opposite corner of magnet, defining direction of coordinate | ||
% system and dimension of magnet | ||
% x_m = [x1,x2] ... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency with other approaches, I think the inputs into this function should be x_c,y_c,z_c for the magnet centre with d_x,d_y,d_z for the cuboid widths. Or similar. Could even be two 3x1 vectors instead. |
||
%sigma - magnetic field strength, tesla | ||
%X,Y,Z - field points | ||
|
||
%unit conversion | ||
M0 = sigma*8*10^5; % A/m | ||
|
||
%magnetic permeability of free space | ||
u0 = 4*pi*10^-7 ; %H/m | ||
|
||
%summation of function over i,j,k 1:2 | ||
[i,j,k]=meshgrid(1:2,1:2,1:2); | ||
d=size(X); | ||
|
||
%reshape index array for 8 summations and size of field array | ||
i=repmat(reshape(i,[1,1,8]),d); | ||
j=repmat(reshape(j,[1,1,8]),d); | ||
k=repmat(reshape(k,[1,1,8]),d); | ||
|
||
%reshape field array to match index array | ||
x=ones(d(1),d(2),8).*X; | ||
y=ones(d(1),d(2),8).*Y; | ||
z=ones(d(1),d(2),8).*Z; | ||
|
||
%define equation constant D | ||
D=((-1).^(i+j+k)); | ||
|
||
%define equation constant zeta | ||
zeta = sqrt((x-x_m(i)+eps).^2+(y-y_m(j)+eps).^2+(z-z_m(k)+eps).^2); | ||
zeta(isnan(zeta))=0; | ||
|
||
%calculate magnetic field strength | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does Ravaud provide the singular cases so we can get rid of the eps terms? It’s a bit ugly to hack around them like this and doesn’t entirely eliminate the problem (not out of the realm of possibility that a user would provide a displacement of eps, say.) |
||
Hx = ((M0*sin(phi)*cos(theta))/(4*pi))*sum(D.*(atan(((y-y_m(j)+eps)... | ||
.*(z-z_m(k)+eps))./((x-x_m(i)+eps).*zeta))),3)... | ||
+((M0*sin(phi)*sin(theta))/(4*pi))*sum(D.*-real(log((z-z_m(k)+eps)... | ||
+zeta)),3)... | ||
+((M0*cos(phi))/(4*pi))*sum(D.*-real(log((y-y_m(j)+eps)+zeta)),3); | ||
|
||
Hy = ((M0*sin(phi)*cos(theta))/(4*pi))*sum(D.*-real(log((z-z_m(k)+eps)... | ||
+zeta)),3)... | ||
+((M0*sin(phi)*sin(theta))/(4*pi))*sum(D.*(atan(((x-x_m(i)+eps)... | ||
.*(z-z_m(k)+eps))./((y-y_m(j)+eps).*zeta))),3)... | ||
+((M0*cos(phi))/(4*pi))*sum(D.*-real(log((x-x_m(i)+eps)+zeta)),3); | ||
|
||
Hz = ((M0*sin(phi)*cos(theta))/(4*pi))*sum(D.*-real(log((y-y_m(j)+eps)... | ||
+zeta)),3)... | ||
+((M0*sin(phi)*sin(theta))/(4*pi))*sum(D.*-real(log((x-x_m(i)+eps)... | ||
+zeta)),3)... | ||
+((M0*cos(phi))/(4*pi))*sum(D.*(atan(((x-x_m(i)+eps)... | ||
.*(y-y_m(j)+eps))./((z-z_m(k)+eps).*zeta))),3); | ||
|
||
H = cat(3,Hx,Hy,Hz); | ||
|
||
%magnetic flux density | ||
B = u0.*H; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. M0 could be removed from the Hx,Hy,Hz equations above and moved down to here. |
||
|
||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to rewrite the equations around having a magnetization vector such as Mx,My,Mz so that theta & phi don’t need to be figured out?