[Getdp] Calculation the mechnical force between magnets.

Sebastian sjardi at telefonica.net
Tue Jul 22 13:45:37 CEST 2008


Dear friends:

Here do you have a 2D magnetostatic simulation.

The question is. How can I obtain the mechanical force in N, produced 
by one magnet over the other ?

Thanks.

Sebastian Jardi Estadella
sjardi at telefonica.net
http://www.tinet.org/~sje/index_en.htm
-------------- next part --------------
/* Drawing a magnet */

/* Defining some parameters */

MagX = 10;	/* Magnet1 Dimensions */
MagY = 8;

MagPX = 0;	/* Center Magnet1 Position */
MagPY = 0;
MagPZ = 0;


Mag2X = MagX;	/* Magnet2 Dimensions */
Mag2Y = MagY;

Mag2PX = 0;		/* Try don't overlap magnets */
Mag2PY = 10;
Mag2PZ = 0;


NumDiv = 10;	/* Number of Divisions */

AirX = MagX*4;	/* Air Zone Dimensions */
AirY = MagY*8;  /* Greater than Magnet */

CML = MagX/NumDiv;		/* Computation of Charasteristic Mesh Length */

/* Points */
/* Magnet 1 */
Point(1)={MagX/2+MagPX,MagY/2+MagPY,0+MagPZ,CML};
Point(2)={MagX/2+MagPX,-MagY/2+MagPY,0+MagPZ,CML};
Point(3)={-MagX/2+MagPX,-MagY/2+MagPY,0+MagPZ,CML};
Point(4)={-MagX/2+MagPX,MagY/2+MagPY,0+MagPZ,CML};

/* Magnet 2 */
Point(5)={Mag2X/2+Mag2PX,Mag2Y/2+Mag2PY,0+Mag2PZ,CML};
Point(6)={Mag2X/2+Mag2PX,-Mag2Y/2+Mag2PY,0+Mag2PZ,CML};
Point(7)={-Mag2X/2+Mag2PX,-Mag2Y/2+Mag2PY,0+Mag2PZ,CML};
Point(8)={-Mag2X/2+Mag2PX,Mag2Y/2+Mag2PY,0+Mag2PZ,CML};


/* AirZone Points */
Point(10)={AirX/2,AirY/2,0,CML};
Point(20)={AirX/2,-AirY/2,0,CML};
Point(30)={-AirX/2,-AirY/2,0,CML};
Point(40)={-AirX/2,AirY/2,0,CML};


/* Lines */
/* Magnet1 */
Line(12)={1,2};
Line(23)={2,3};
Line(34)={3,4};
Line(41)={4,1};

/* Magnet2 */
Line(56)={5,6};
Line(67)={6,7};
Line(78)={7,8};
Line(85)={8,5};


/* Air */
Line(1020)={10,20};
Line(2030)={20,30};
Line(3040)={30,40};
Line(4010)={40,10};

/* Surfaces */
/* Magnet1 */
Line Loop(100)={12,23,34,41};
Plane Surface(100)={100};
Physical Surface(100)={100};

/* Magnet2 */
Line Loop(110)={56,67,78,85};
Plane Surface(110)={110};
Physical Surface(110)={110};


/* Air */
Line Loop(200)={1020,2030,3040,4010};
Plane Surface(200)={200,100,110};	/* Air - Magnet1 - Magnet2 */
Physical Surface(200)={200};





-------------- next part --------------
/* 2D Magnet Simulation */

/* To run getdp 2Dmagnet -pre MagSta_phi -cal -pos phi */

Group {
	Magnet1=Region[100];
	Magnet2=Region[110];
	Air=Region[200];

	Domain = Region[{Air,Magnet1,Magnet2}];
	Domain_M1 = Region[Magnet1];
	Domain_M2 = Region[Magnet2];
}

Function {
	mu0 = 4.e-7 * Pi;
	murMag = 1.;

	nu[ Air ]    = 1. / mu0;
	nu[ Magnet1 ] = 1. / murMag * mu0;
	nu[ Magnet2 ] = 1. / murMag * mu0;
	
	mu[ Air ]    = mu0;
	mu[ Magnet1 ] = murMag * mu0;
	mu[ Magnet2 ] = murMag * mu0;

	/* Magnetic Field Vector  in [A/m] */
	hc[ Magnet1 ] = Vector[0. ,920000., 0.];
	hc[ Magnet2 ] = Vector[950000. , 0., 0.];
}

/* Resolution */

/* Input

  Groups :
  --------
    Domain         Whole magnetic domain
    Domain_M1      Permanent magnet1 regions 
    Domain_M2      Permanent magnet2 regions 
		 
  Functions :	 
  -----------	 
    mu[]           Magnetic permeability
    nu[]           Magnetic reluctivity
    hc[]           Coercitive magnetic field
    
  Constraint :	 
  ----------	 
    phi            Fixed magnetic scalar potential
    a              Fixed magnetic vector potential (2D)

*/


Jacobian {
  { Name JVol ;
    Case { 
      { Region All ;        Jacobian Vol ; }
    }
  }
}


Integration {
  { Name I1 ;
    Case { 
      { Type Gauss ;
        Case { 
	  { GeoElement Triangle    ; NumberOfPoints  4 ; }
	  { GeoElement Quadrangle  ; NumberOfPoints  4 ; }
	}
      }
    }
  }
}

/* --------------------------------------------------------------------------
   MagSta_phi : Magnetic scalar potential phi formulation 
   -------------------------------------------------------------------------- */

FunctionSpace {
  { Name Hgrad_phi ; Type Form0 ;
    BasisFunction {
      { Name sn ; NameOfCoef phin ; Function BF_Node ;
        Support Domain ; Entity NodesOf[ All ] ; }
    }
    Constraint {
      { NameOfCoef phin ; EntityType NodesOf ; NameOfConstraint phi ; }
    }
  }
}


Formulation {
  { Name MagSta_phi ; Type FemEquation ;
    Quantity { 
      { Name phi ; Type Local ; NameOfSpace Hgrad_phi ; }
    }
    Equation {
      Galerkin { [ - mu[] * Dof{d phi} , {d phi} ] ;  
                 In Domain ; Jacobian JVol ; Integration I1 ; }
      Galerkin { [ - mu[] * hc[], {d phi} ];
                 In Domain_M1 ; Jacobian JVol ; Integration I1 ; }
      Galerkin { [ - mu[] * hc[], {d phi} ];
                 In Domain_M2 ; Jacobian JVol ; Integration I1 ; }           
    }
  }
}


Resolution {
  { Name MagSta_phi ;
    System {
      { Name A ; NameOfFormulation MagSta_phi ; }
    }
    Operation { 
      Generate[A] ; Solve[A] ; SaveSolution[A] ; 
    }
  }
}


PostProcessing {
  { Name MagSta_phi ; NameOfFormulation MagSta_phi ;
    Quantity {
      { Name b  ; Value { Local { [ - mu[] * {d phi} ] ; In Domain ; Jacobian JVol ; } 
                          Local { [ - mu[] * hc[] ]    ; In Domain_M1 ; Jacobian JVol ; }
                          Local { [ - mu[] * hc[] ]    ; In Domain_M2 ; Jacobian JVol ; } } }
      { Name h  ; Value { Local { [ - {d phi} ]        ; In Domain ; Jacobian JVol ; } } }
      { Name phi; Value { Local { [ { phi } ]          ; In Domain ; Jacobian JVol ; } } }
    }
  }
}


eps = 1.e-5;

PostOperation {
	{Name phi; NameOfPostProcessing MagSta_phi;
	 	Operation {
			Print[ phi, OnElementsOf Domain, File "phi.pos"];
			Print[ h,   OnElementsOf Domain, File "h_phi.pos", Depth 0 ] ;
			Print[ b,   OnElementsOf Domain, File "b_phi.pos", Depth 0 ] ;
		}
	}
}