CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   Parallelisation UDF (https://www.cfd-online.com/Forums/fluent/38831-parallelisation-udf.html)

mAx December 5, 2005 01:38

Parallelisation UDF
 
Hi, I have a problem with my UDF. It runs well under serial, but not under parallel. And I need to run it under parallel. I paste, the UDF below. Could someone tell me what's wrong? Thank you very much. ******* #include <stdio.h> #include "udf.h"

#if !RP_NODE # define UDF_FILENAME "udf_loc_velo" # define UDF_DATA "data.dat"

# define K_SPRING 1605 /*spring constant/2 (N/m)*/ # define m 0.0365 /*mass of piston/2 (kg)*/ # define init_disp 0.008 /*initial displacement of spring (m)*/

/* read current location and velocity from file */ static void read_loc_velo_file (real *loc, real *velo) { FILE *fp = fopen(UDF_FILENAME, "r");

if (fp != NULL)

{

float read_loc, read_velo;

fscanf (fp, "%e %e", &read_loc, &read_velo);

fclose (fp);

*loc = (real) read_loc;

*velo = (real) read_velo;

} else

{

*loc = 0.0;

*velo = 0.0;

} }

/* write current location and velocity in file */ static void write_loc_velo_file (real loc, real velo) { FILE *fp = fopen(UDF_FILENAME, "w");

if (fp != NULL)

{

fprintf (fp, "%e %e", loc, velo);

fclose (fp);

} else

Message ("\nWarning: cannot write %s file", UDF_FILENAME); }

/* write current location and velocity in datafile */ static void write_data_file (real time, real loc, real velo, real force) { FILE *fp = fopen(UDF_DATA, "a+");

fprintf (fp, "%e %e %e %e \n", time, loc, velo, force); fclose (fp);

}

#endif /* !RP_NODE */

DEFINE_ON_DEMAND(reset_velocity) { #if !RP_NODE real loc, velo;

read_loc_velo_file (&loc, &velo); write_loc_velo_file (loc, 0.0);

Message ("\nUDF reset_velocity called:"); #endif }

DEFINE_CG_MOTION(valve, dt, cg_vel, cg_omega, time, dtime) { #if RP_NODE Thread *t = DT_THREAD (dt); face_t f; #endif real loc,velo,force;

/* reset velocities */ NV_S (cg_vel, =, 0.0); NV_S (cg_omega, =, 0.0);

if (!Data_Valid_P ())

return;

#if RP_NODE /* compute force on piston wall */ force = 0.0;

begin_f_loop (f, t)

{

real *AA;

AA = F_AREA_CACHE (f, t);

force += F_P (f, t) * AA[2];

} end_f_loop (f, t) #endif

#if PARALLEL force = PRF_GRSUM1(force); node_to_host_real_1 (force); #endif

# if RP_2D if (rp_axi)

force *= 2.0 * M_PI; # endif

#if !RP_NODE read_loc_velo_file (&loc, &velo);

/* add in spring force */ {

real s_force = K_SPRING * (loc + init_disp);

force = force - s_force; }

/* compute change in velocity */ {

real dv = dtime * force / m ;

velo += dv;

loc += velo * dtime; }

Message ("\nUDF valve: time(s)= %f, z_vel(m/s)= %f, force(N)= %f, loc(m)= %f\n",

time, velo, force, loc); write_loc_velo_file (loc, velo); write_data_file (time,loc,velo,force); #endif /* !RP_NODE */

#if PARALLEL host_to_node_real_1 (velo); #endif

cg_vel[2] = velo; }

DEFINE_CG_MOTION(moving_fluid, dt, cg_vel, cg_omega, time, dtime) { #if !RP_NODE Thread *t = DT_THREAD (dt); face_t f; real force, loc; #endif real velo;

/* reset velocities */ NV_S (cg_vel, =, 0.0); NV_S (cg_omega, =, 0.0);

if (!Data_Valid_P ())

return;

#if !RP_NODE read_loc_velo_file (&loc, &velo); #endif /* !RP_NODE */

#if PARALLEL host_to_node_real_1 (velo); #endif

cg_vel[2] = velo; }



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