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/)
-   -   Help: the output of DPM (https://www.cfd-online.com/Forums/fluent-udf/75487-help-output-dpm.html)

zhaoxinyu April 27, 2010 10:16

Help: the output of DPM
 
Hi!
In unsteady DPM model, how to output the position and velocities of particles in a cell at a certain time using UDF?

Bernhard April 27, 2010 12:08

I once obtained this from Fluent support desk. Good luck :)
Code:

/********************************************************************/
/* */
/* Hook on the DPM panel under DPM Scalar Update */
/* */
/********************************************************************/

#include "udf.h"
#include "dpm.h"

DEFINE_DPM_SCALAR_UPDATE(track_dpm_particles,c,t,initialize,p)
{
if (RP_Get_Boolean("dpm/unsteady-tracking?"))
{

if (initialize)
{

float time = RP_Get_Real("flow-time");
float x = p->state.pos[0];
float y = p->state.pos[1];
float u = p->state.V[0];
float v = p->state.V[1];
#if RP_3D
float z = p->state.pos[2];
float w = p->state.V[2];
#endif

FILE *fd;
int id = p->part_id;
char whoru[80];
sprintf(whoru,"dpm_positions%f.out",time);
fd = fopen(whoru, "a");
#if RP_3D
fprintf(fd, "%i %f %e %e %e %e %e %e %e %e %e \n", id, time, x, y, z, u, v, w, P_T(p), P_MASS(p), P_RHO(p));
#else
fprintf(fd, "%i %f %e %e %e %e %e %e %e \n", id, time, x, y, u, v, P_T(p), P_MASS(p), P_RHO(p));
#endif
fclose(fd);

}
}

else
{
float time = RP_Get_Real("flow-time");
float x = p->state.pos[0];
float y = p->state.pos[1];
float u = p->state.V[0];
float v = p->state.V[1];
#if RP_3D
float z = p->state.pos[2];
float w = p->state.V[2];
#endif

FILE *fd;
int id = p->part_id;
char whoru[80];
sprintf(whoru,"dpm_positions%f.out",time);
fd = fopen(whoru, "a");
#if RP_3D
fprintf(fd, "%i %f %e %e %e %e %e %e %e %e %e \n", id, time, x, y, z, u, v, w, P_T(p), P_MASS(p), P_RHO(p));
#else
fprintf(fd, "%i %f %e %e %e %e %e %e %e \n", id, time, x, y, u, v, P_T(p), P_MASS(p), P_RHO(p));
#endif
fclose(fd);
}

}


zhaoxinyu April 27, 2010 19:07

Quote:

Originally Posted by Bernhard (Post 256511)
I once obtained this from Fluent support desk. Good luck :)
Code:

/********************************************************************/
/* */
/* Hook on the DPM panel under DPM Scalar Update */
/* */
/********************************************************************/
 
#include "udf.h"
#include "dpm.h"
 
DEFINE_DPM_SCALAR_UPDATE(track_dpm_particles,c,t,initialize,p)
{
if (RP_Get_Boolean("dpm/unsteady-tracking?"))
{
 
if (initialize)
{
 
float time = RP_Get_Real("flow-time");
float x = p->state.pos[0];
float y = p->state.pos[1];
float u = p->state.V[0];
float v = p->state.V[1];
#if RP_3D
float z = p->state.pos[2];
float w = p->state.V[2];
#endif
 
FILE *fd;
int id = p->part_id;
char whoru[80];
sprintf(whoru,"dpm_positions%f.out",time);
fd = fopen(whoru, "a");
#if RP_3D
fprintf(fd, "%i %f %e %e %e %e %e %e %e %e %e \n", id, time, x, y, z, u, v, w, P_T(p), P_MASS(p), P_RHO(p));
#else
fprintf(fd, "%i %f %e %e %e %e %e %e %e \n", id, time, x, y, u, v, P_T(p), P_MASS(p), P_RHO(p));
#endif
fclose(fd);
 
}
}
 
else
{
float time = RP_Get_Real("flow-time");
float x = p->state.pos[0];
float y = p->state.pos[1];
float u = p->state.V[0];
float v = p->state.V[1];
#if RP_3D
float z = p->state.pos[2];
float w = p->state.V[2];
#endif
 
FILE *fd;
int id = p->part_id;
char whoru[80];
sprintf(whoru,"dpm_positions%f.out",time);
fd = fopen(whoru, "a");
#if RP_3D
fprintf(fd, "%i %f %e %e %e %e %e %e %e %e %e \n", id, time, x, y, z, u, v, w, P_T(p), P_MASS(p), P_RHO(p));
#else
fprintf(fd, "%i %f %e %e %e %e %e %e %e \n", id, time, x, y, u, v, P_T(p), P_MASS(p), P_RHO(p));
#endif
fclose(fd);
}
 
}


Thanks for you help!

orland August 3, 2011 07:40

when I tried to use that code, all the particle id's get the value zero
has this also happened to you?

arctan April 25, 2016 02:52

The code works fine except that it writes duplicated data for me, the positions and velocities are repeated 4 times in the .out file, why? and how to fix it?

pakk April 25, 2016 03:50

Are you working in parallel mode with four processes? In that case, the reason that you get four lines is that this code is not meant for parallel computing.

This can be fixed by parallelizing the code (putting the correct macro's in the right position, see Fluent manual for more info). But if you are not familiar with this, it might be better to just ignore the extra output you get.

arctan April 25, 2016 04:50

The thing is that I'm working in serial, so it's weird that I'm getting four lines. My computer has four cores though, I'm not sure if it has anything to do with four cores.


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