CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT

for loop inside a cell_loop?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 26, 2007, 22:24
Default for loop inside a cell_loop?
  #1
MHDWill
Guest
 
Posts: n/a
Hi all,

I was wondering if there's something I have to keep in mind when I'm doing a for loop inside a predefined loop macro for FLUENT. Basically I'm trying to generate a magnetic field by adding up magnetic field contribution from multiple sources. I create these multiple sources through a for loop inside a cell loop. All constants are defined at the beginning of the code using #define, int, and/or real (#define isn't shown in the code below).

Basically, I have a lot of helmholtz coil in the system located along the z-axis. At each cell centroid, I want to calculate the magnetic field contribution from all the coils, hence I use the for loop inside the cell_loop macro. I calculate the contribution of i'th coil and add them up. bix, biy, biz is the magnetic field contribution at each cell due to all the coil.

So, after the iteration is done, I assign C_UDMI(c,t,0)=bix, C_UDMI(c,t,1)=biy, C_UDMI(c,t,2)=biz to define the magnetic field strength at each cell centroid.

But when I do this and generate a contour plot, the magnetic field is somewhat uniform rather than what we expect to see in a helmholtz coil.

Is there a problem how I define the variables in int and real?

The code is shown below.

DEFINE_INIT(Define_B_Field,d) {

int i;

real dx, theta, phi, px, p, x[ND_ND],r, rx,

rhomag, themag, ci, ct, co, bix,biy,biz ;

Thread *t;

cell_t c;

ci = ri*ri/fabs(nix); constant

co = ro*ro/fabs(nox); constant

ct = (pow(ci*nix,0.5)-rt)/(nix*nix); constant

dx=lsys/nc; /*increment between coils in meters */

/*Now calculating magnetic field @ each cell centroid*/

thread_loop_c(t,d)

{

begin_c_loop(c,t)

{

C_CENTROID(x,c,t);

bix=0.0;

biy=0.0;

biz=0.0;

for (i;i<=nc;i++)

{

rx= -lsys/2 + (i-1)*dx;

if (rx < cp)

{

r = pow(ci*fabs(rx),0.5);

}

else if (rx > cp & rx < dp)

{

r=ct*rx*rx+tzp;

}

else if (rx > dp)

{

r = pow(co*fabs(rx),0.5);

}

px=x[0]-rx; /*x-coordinate of the cell centroid with respect to the current (i'th) coil center*/

p=pow(px*px + x[1]*x[1] + x[2]*x[2],0.5); /*Position vector magnitude of cell center from center of the "i'th" Helmholz coil*/

theta=atan2((pow(px*px+x[1]*x[1],0.5)),x[2]);/*Longitudinal angle from z-axis*/

phi = atan2(x[1],px); /*Azimuthal angle in the xy-plane with respect to z-axis*/

rhomag= pow( cos(theta)*cos(phi)*cos(theta)*cos(phi) + sin(theta)*sin(phi)*sin(theta)*sin(phi)+cos(theta) *cos(theta),0.5);

themag= pow( p*p*(sin(theta)*sin(phi)*sin(theta)*sin(phi) + cos(theta)*sin(phi)*cos(theta)*sin(phi)+sin(theta) *sin(theta)),.5);

bix +=permeability*(I/2*r*r*cos(theta)*(1+(15*r*r*p*p*sin(theta)*sin(the ta))/(4*pow(r*r+p*p,2)))/(pow(r*r+p*p,3/2))*cos(theta)*sin(phi)/rhomag-I/4*sin(theta)*(2*r*r - p*p +(15*r*r*p*p*sin(theta)*sin(theta)*(4*r*r - 3*p*p)/(8*pow(r*r + p*p,2))))/(pow(r*r + p*p,5/2))*p*sin(theta)*sin(phi)/themag); /*x-component of magnetic field for each helmholtz coil*/

biy +=permeability*(I/2*r*r*cos(theta)*(1+(15*r*r*p*p*sin(theta)*sin(the ta))/(4*pow(r*r+p*p,2)))/(pow(r*r+p*p,3/2))*sin(theta)*sin(phi)/rhomag-I/4*sin(theta)*(2*r*r - p*p +(15*r*r*p*p*sin(theta)*sin(theta)*(4*r*r - 3*p*p)/(8*pow(r*r + p*p,2))))/(pow(r*r + p*p,5/2))*p*cos(theta)*sin(phi)/themag); /*y-component of magnetic field for each helmholtz coil*/

biz +=permeability*(I/2*r*r*cos(theta)*(1+(15*r*r*p*p*sin(theta)*sin(the ta))/(4*pow(r*r+p*p,2)))/(pow(r*r+p*p,3/2))*cos(theta)/rhomag+I/4*sin(theta)*(2*r*r - p*p +(15*r*r*p*p*sin(theta)*sin(theta)*(4*r*r - 3*p*p)/(8*pow(r*r + p*p,2))))/(pow(r*r + p*p,5/2))*sin(theta)*p/themag); /*z-component of magnetic field for each helmholtz coil*/

}

C_UDMI(c,t,0)=bix;

C_UDMI(c,t,1)=biy;

C_UDMI(c,t,2)=biz;

}

end_c_loop(c,t)

} }

  Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Patch a bubble inside turbulent flow Helmi FLUENT 0 February 4, 2011 05:54
tecplot 3D velocity contours inside a channel vetnav Tecplot 4 July 14, 2010 21:03
OpenFOAM on MinGW crosscompiler hosted on Linux allenzhao OpenFOAM Installation 127 January 30, 2009 20:08
Modelling the Heat flow inside the curing oven Marios Vlad CFX 1 February 6, 2008 08:11
meshing F1 front wing Steve FLUENT 0 April 17, 2003 13:37


All times are GMT -4. The time now is 15:15.