This is the web version of EJS interface
EJS version 4.2
  1. Title=Magnetic Bar Field
  2. Author=Wolfgang Chrisitan, Francisco Esquembre - Universidad de Murcia, Spain
  3. Keywords=magnetic field, dipole, bar magnet
  4. Level=introductory
  5. Abstract=e-mail: fem@um.es
  6. CaptureTools=true
  7. DataTools=false
  8. LanguageTools=true
  9. AuxiliaryFiles=./MagneticBarField/;./Magnetic2BarFieldFKH_pkg/Magnetic2BarFieldFKH_zh.properties;
  10. DetectedFiles=./MagneticBarField/MagneticBarField.html;./MagneticBarField/circle.gif;./MagneticBarField/magnet.gif;
    NameValueTypeDimension
    NameValueTypeDimension
    NameValueTypeDimension
    NameValueTypeDimension
    NameValueTypeDimension

    Init Page

    double dx=1.0/(nd-1); //set up dipoles under bar magnet for(int i=0; i<nd; i+=2) { dipoles[i][0]=-0.5+i*dx; // x position dipoles[i][1]=-.04; // y position dipoles[i+1][0]=-0.5+i*dx; // x position dipoles[i+1][1]=0.04; // y position } computeField(); cs=Math.cos(c);//FKH sc=Math.sin(c);//FKH

    Evol Page

    Indep. Var. Increment
    d theta /dt=omega
    d omega /dt=-k*(Math.sin(deltaTheta))-b*omega
    SolverRungeKuttaFehlberg AbsoluteTolerance=0.00001

    FixRel Page

    bf1=getB((xCompass-xMagnet)*cs+(yCompass-yMagnet)*sc,-(xCompass-xMagnet)*sc+(yCompass-yMagnet)*cs);//FKH bf2=getB((xCompass-xMagnet2)*cs2+(yCompass-yMagnet2)*sc2,-(xCompass-xMagnet2)*sc2+(yCompass-yMagnet2)*cs2);//FKH bxField = lcst*(bf1[0]*cs-bf1[1]*sc)+rcst*(bf2[0]*cs2-bf2[1]*sc2);//FKH byField = lcst*(bf1[0]*sc+bf1[1]*cs)+rcst*(bf2[0]*sc2+bf2[1]*cs2);//FKH equilibriumTheta=Math.atan2(byField,bxField);//b[3]; fieldValue="B="+_view.format(Math.sqrt(bxField*bxField+byField*byField),"0.00"); if(omega>0)omega=Math.min(omega,Math.PI); // keeps compass from spinning wildly else omega=Math.max(omega,-Math.PI);
    public void computeField () { for (int i=0; i<nx; i++) { double x=_view.vectorField2D.indexToX(i); for (int j=0; j<ny; j++) { double y=_view.vectorField2D.indexToY(j); bf1=getB((x-xMagnet)*cs+(y-yMagnet)*sc,-(x-xMagnet)*sc+(y-yMagnet)*cs);//FKH bf2=getB((x-xMagnet2)*cs2+(y-yMagnet2)*sc2,-(x-xMagnet2)*sc2+(y-yMagnet2)*cs2);//FKH xField[i][j] = lcst*(bf1[0]*cs-bf1[1]*sc)+rcst*(bf2[0]*cs2-bf2[1]*sc2);//FKH yField[i][j] = lcst*(bf1[0]*sc+bf1[1]*cs)+rcst*(bf2[0]*sc2+bf2[1]*cs2);//FKH magField[i][j]=Math.sqrt(xField[i][j]*xField[i][j]+yField[i][j]*yField[i][j]); } } }
    public double[] getB(double xm,double ym) { double[] b=new double[2]; for(int i=0; i<nd; i++) { double dx=xm-dipoles[i][0];//-xm;////(xMagnet*cs+yMagnet*sc);//FKH double dy=ym-dipoles[i][1];//-ym;//(-xMagnet*sc+yMagnet*cs);//FKH double r2=dx*dx+dy*dy; double r=Math.sqrt(r2); double r3=r2*r; double cos=dx/r; double sin=dy/r; b[0]+=m*(3*cos*cos-1)/r3; //x component b[1]+=m*3*sin*cos/r3; //y component if(r2==0) { b[0]=b[1]=0; } } //// b[2] = Math.sqrt(b[0]*b[0]+b[1]*b[1]); // magnitude //// b[3] = Math.atan2(b[1],b[0]); // angle return b; } /* Dipole field: B=mu/4/pi/r^3[(m*rhat)rhat-m] //vector form K=mu*M/4/pi alpha=0 Bx=K*[(3*cos(theta)^2-1)*cos(alpha)+3*sin(theta)cos(theta)*sin(alpha)]/r^3 By=K*[(3*sin(theta)^2-1)*sin(alpha)+3*sin(theta)cos(theta)*cos(alpha)]/r^3 */
    public void setLocation () { //move magnet to random location if(randomMagnetLocation){ xMagnet = (-xmax + 2*xmax*Math.random()); yMagnet = (-ymax + 2*ymax*Math.random()); xMagnet2 = (-xmax + 2*xmax*Math.random()); yMagnet2 = (-ymax + 2*ymax*Math.random()); } computeField(); }
    EJSVIEW: Click link to view it's content
    Control variables:(testing)
    int,int
    title="Bar Magnet"
    layout=border
    visible=true
    location="11,12"
    size="962,609"
    position=center
    autoscaleX=false
    autoscaleY=false
    minimumX=-xmax
    maximumX=xmax
    minimumY=-ymax
    maximumY=ymax
    square=true
    majorTicksX=false
    majorTicksY=false
    fixedGutters=false
    interiorBackground=BLACK
    minimumX=-xmax
    maximumX=xmax
    minimumY=-ymax
    maximumY=ymax
    xcomponent=xField
    ycomponent=yField
    length=0.1
    visible=!hideField
    style=RHOMBUS
    elementposition=CENTERED
    colormode=RED
    magnitude=magField
    autoscale=true
    minimum=0
    maximum=4
    x=xd1
    y=yd1
    visible=hideField && L
    x=-0.28*cs
    y=-0.28*sc
    sizeX=.56
    sizeY=.22
    transformation=c
    style=ROUND_RECTANGLE
    lineColor=GRAY
    fillColor=CYAN
    lineWidth=2
    x=0.28*cs
    y=0.28*sc
    sizeX=.56
    sizeY=.22
    transformation=c
    style=ROUND_RECTANGLE
    lineColor=GRAY
    fillColor=MAGENTA
    lineWidth=2
    x=0
    y=0
    sizeX=.56
    sizeY=.22
    transformation=c
    enabledPosition=true
    movesGroup=true
    sensitivity=0
    style=RECTANGLE
    lineColor=GRAY
    fillColor=GRAY
    lineWidth=2
    pixelSize=true
    text="Drag Me"
    font=Dialog,BOLD,12
    elementposition=SOUTH
    lineColor=YELLOW
    fillColor=YELLOW
    pixelSize=true
    text="(To Magnet Location)"
    font=Dialog,BOLD,10
    elementposition=NORTH
    lineColor=YELLOW
    fillColor=YELLOW
    x=xMagnet
    y=yMagnet
    sizeX=1.08
    sizeY=0.22
    transformation=c
    visible=!hideField && L
    enabledPosition=true
    sensitivity=0
    dragAction=computeField()
    imageFile="./MagneticBarField/magnet.gif"
    x=xMagnet
    y=yMagnet
    pixelSize=true
    visible=!hideField && L
    text="Drag me"
    font=Dialog,BOLD,14
    lineColor=YELLOW
    fillColor=YELLOW
    x=xCompass
    y=yCompass
    sizeX=0.35
    sizeY=0.35
    fillColor=192,192,192,64
    x=0
    trueSize=false
    sizeX=0.4
    sizeY=0.4
    visible=true
    imageFile="./MagneticBarField/circle.gif"
    x=0
    y=0
    sizeX=1
    sizeY=0
    scalex=0.24
    scaley=0.24
    transformation=theta
    style=RHOMBUS
    elementposition=CENTERED
    fillColor=RED
    extraColor=BLUE
    x=0
    y=0
    sizeX=0.028
    sizeY=0.028
    enabledPosition=true
    movesGroup=true
    sensitivity=15
    lineColor=BLACK
    fillColor=BLACK
    y=-.21
    sizeX=0.25
    sizeY=0.08
    visible=!hideField
    style=ROUND_RECTANGLE
    fillColor=YELLOW
    x=0
    y=-0.22
    pixelSize=true
    visible=!hideField
    text=%fieldValue%
    elementposition=CENTERED
    x=xMagnet2
    y=yMagnet2
    sizeX=1.08
    sizeY=0.22
    transformation=c2
    visible=!hideField && R
    enabledPosition=true
    sensitivity=0
    dragAction=computeField()
    imageFile="./MagneticBarField/magnet.gif"
    x=xMagnet2
    y=yMagnet2
    pixelSize=true
    visible=!hideField && R
    text="Drag me2"
    font=Dialog,BOLD,14
    lineColor=YELLOW
    fillColor=YELLOW
    x=xd2
    y=yd2
    visible=hideField && R
    x=-0.28*cs2
    y=-0.28*sc2
    sizeX=.56
    sizeY=.22
    transformation=c2
    style=ROUND_RECTANGLE
    lineColor=GRAY
    fillColor=CYAN
    lineWidth=2
    x=0.28*cs2
    y=0.28*sc2
    sizeX=.56
    sizeY=.22
    transformation=c2
    style=ROUND_RECTANGLE
    lineColor=GRAY
    fillColor=MAGENTA
    lineWidth=2
    x=0
    y=0
    sizeX=.56
    sizeY=.22
    transformation=c2
    enabledPosition=true
    movesGroup=true
    sensitivity=0
    style=RECTANGLE
    lineColor=GRAY
    fillColor=GRAY
    lineWidth=2
    pixelSize=true
    text="Drag Me"
    font=Dialog,BOLD,12
    elementposition=SOUTH
    lineColor=YELLOW
    fillColor=YELLOW
    pixelSize=true
    text="(To Magnet Location)"
    font=Dialog,BOLD,10
    elementposition=NORTH
    lineColor=YELLOW
    fillColor=YELLOW
    position=south
    layout=BORDER:0,0
    borderType=LOWERED_ETCHED
    position=east
    layout=GRID:0,1,0,0
    variable=!hideField
    tooltip="Hide magnet and field."
    textOn="Hide Field"
    actionOn=hideField=true; setLocation();
    textOff="Show Field"
    actionOff=hideField=false; computeField();
    image="/org/opensourcephysics/resources/controls/images/reset.gif"
    action=_reset()
    size="33,25"
    tooltip="Reset button."
    position=west
    layout=GRID:0,1,0,0
    visible=!hideField
    variable=randomMagnetLocation
    text="Randomize"
    layout=HBOX
    variable=L
    text="Lon"
    action=if(L)lcst=1; else lcst=0; computeField ();
    variable=R
    text="Ron"
    action=if(R)rcst=1; else rcst=0; computeField ();
    position=center
    layout=HBOX
    position=center
    variable=ca
    minimum=-180
    maximum=180
    format="rotate magnet by c=0"
    dragaction=c=ca*a2c; cs=Math.cos(c); sc=Math.sin(c); computeField();
    variable=ca2
    minimum=-180
    maximum=180
    format="rotate magnet2 by c2=0"
    dragaction=c2=ca2*a2c; cs2=Math.cos(c2); sc2=Math.sin(c2); computeField();