/************************************************************************* * * * This program creates magnetic field data for plotting using line * * segments for currents. The analytical formula is derived using * * a parametric form for the line segment and integrating the * * (J x r)/r^2 for each point along the line segment. In principle the * * entire array should be symmetric, but for simplicity I compute the * * full field. * * * * Author = Mike Rosing * * date = June 1, 2008 * * * ************************************************************************/ #include #include #include #define MAXDIM 256 //#define MAXDIM 16 typedef struct { double x, y, z; } VECTOR; VECTOR Bfield[MAXDIM][MAXDIM][MAXDIM]; main() { struct { int start, end; } list[12]; VECTOR location, direction[12], endpoint[6]; int i, ix, iy, iz, start; double x, y, z, xp, yp, zp, rp2, k, sq, t1, t2; FILE *saveb; endpoint[0].x = 0.0; endpoint[0].y = 0.0; endpoint[0].z = 1.0; endpoint[1].x = 1.0; endpoint[1].y = 0.0; endpoint[1].z = 0.0; endpoint[2].x = 0.0; endpoint[2].y = 1.0; endpoint[2].z = 0.0; endpoint[3].x = -1.0; endpoint[3].y = 0.0; endpoint[3].z = 0.0; endpoint[4].x = 0.0; endpoint[4].y = -1.0; endpoint[4].z = 0.0; endpoint[5].x = 0.0; endpoint[5].y = 0.0; endpoint[5].z = -1.0; list[0].start = 0; list[0].end = 1; list[1].start = 1; list[1].end = 4; list[2].start = 4; list[2].end = 5; list[3].start = 5; list[3].end = 1; list[4].start = 1; list[4].end = 2; list[5].start = 2; list[5].end = 0; list[6].start = 0; list[6].end = 3; list[7].start = 3; list[7].end = 2; list[8].start = 2; list[8].end = 5; list[9].start = 5; list[9].end = 3; list[10].start = 3; list[10].end = 4; list[11].start = 4; list[11].end = 0; /* generate direction vectors of line segments */ for(i=0; i<12; i++) { direction[i].x = endpoint[list[i].end].x - endpoint[list[i].start].x; direction[i].y = endpoint[list[i].end].y - endpoint[list[i].start].y; direction[i].z = endpoint[list[i].end].z - endpoint[list[i].start].z; printf("direction[%d] x = %f y = %f z = %f\n", i,direction[i].x, direction[i].y, direction[i].z); } /* assume all line segments are same length. Sweep over whole volume and add field from each line segement to the volume element. */ for(ix=0; ix