CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Writing Particle Data (https://www.cfd-online.com/Forums/fluent-udf/129603-writing-particle-data.html)

sayan_bose February 8, 2014 23:38

Writing Particle Data
 
I want to write particle variables in a separate text file, but the basic C code for writing a text file is not working under my DPM_BODY_FORCE macro. Fluent stops working at the time of particle update. Though the txt files are created they are completely blank. Can any one suggest anything.

pakk February 9, 2014 06:04

I can suggest that you share your udf. If you want problems with your code to be solved, you have to share the code.

sayan_bose February 10, 2014 12:40

This is the code....the dots basically is the mats of magnetic force which is important.........important is the code for the writing file.......which is making fluent exit during the particle update. How to resolve dis.





#include "udf.h"/* must be at the beginning of every UDF you write */
#include <stdio.h>

#define PI 3.14159265 /*Assighned value for Pie */
#define Kieff 3 /*Effective succeptibility */
#define xmag 12 /* x-loc of the magnet */
#define ymag 12 /* y-loc of the magnet */
#define zmag 12 /*z-loc of the magnet*/
#define lx 1.2 /*unit vector along x-for mag*/
#define ly 1.2 /*unit vector along y-for mag*/
#define lz 0 /*unit vector along z-for mag*/
#define I 1e5 /*current */
#define a 1e-6

DEFINE_DPM_BODY_FORCE(particle_body_force,p,i)
{
real muzero,Mag_const,vp,Mag_force,ax,ay,az;
real x,y,z,modr,rdotl,sqrs,s,sx,sy,sz,sxmod,symod,szmod ;
real numer,Denom01,Denom02,Denomx,Denom11,Denom12,Denom y,smod,unitsx,unitsy,unitsz;
real bforce,bforcex,bforcey,bforcez;

FILE *particle_data;
x=P_POS(p)[0]-xmag;
y=P_POS(p)[1]-ymag;
z=P_POS(p)[2]-zmag;
......................................
.......................................
............................................
...........................................
.....................................
............
particle_data=fopen("particle.txt","a");

if(i==0.)

{
bforcex=bforce*unitsx;
ax=bforcex/P_MASS(p);

}
else if(i==1.)
{
bforcey=bforce*unitsy;
ay=bforcey/P_MASS(p);

}
else if(i==2.)
{
bforcez=bforce*unitsz;
az=bforcez/P_MASS(p);

}
return((bforce)/P_MASS(p));
fprintf(particle_data,"%g\t %g\t %g\t %g\t %g\t \n",x[i],y[j],ax,ay,az);
fclose(particle_data);
}

pakk February 10, 2014 14:05

Create an empty file named "particle.txt" in the same folder, and see what happens.

(My hypothesis is that Fluent wants to add lines to this file, but cannot find it, does not know what to do and runs away screaming.)


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