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/)
-   -   PB with DEFINE_RW_FILE (https://www.cfd-online.com/Forums/fluent-udf/88127-pb-define_rw_file.html)

saclu May 9, 2011 10:39

PB with DEFINE_RW_FILE
 
Hi all,

I am using a sliding mesh with the 6dof solver to simulate the rotation of a turbine.
I wrote this UDF to write the angular velocity of my cg at each time step but i keep having mistakes, does anyone would know what's wrong with this file?

---------------------------------------------------------------------
#include"udf.h"
#include"dynamesh_tools.h"
int ZONE_ID = 7; DEFINE_RW_FILE(writer, fp)

{

real omega_Z;
/* declaration of the variable to be written*/
Domain *domain; /* domain is declared as a variable */

domain = Get_Domain(1); /* returns fluid domain pointer */
Thread *t = Lookup_Thread(domain,ZONE_ID);

Dynamic_Thread *dt = THREAD_DT(t);
omega_Z = DT_OMEGA_CG(dt);

printf(
"Writing UDF data to data file...\n");
fprintf(fp,
"%d",omega_Z); /* write out omega_Z to a data file */

}
---------------------------------------------------------------------

Tobard May 13, 2011 14:19

Hi!

I am not an expert but I feel like your function is too complicated for what you need to do.

If you want to define the angular velocity of your CG at each time step, I suggest you write something like that:

---------------------------------------------------------
#include"udf.h"
DEFINE_CG_MOTION(rot_cg, dt, velocity, omega, time, dtime)
{
NV_S(omega, =, 0.0);

omega[2]=150; /*for 150 rad/s around z axis*/
}
---------------------------------------------------------

I hope it helps. I encounter difficulties with transition from a time step to the next one (solution is not the one that is expected despite the fact that motion is well defined) so maybe something is missing in this function. It works but be careful!

Tobard May 13, 2011 15:52

Ooooooops! I am sorry: my answer was out of context...(cannot delete it)

Concerning your issue I suggest you write your code outside of your DEFINE function, using something like:

static
void write_data(FILE *fp)
{
<your code>
}

Then you can call 'write_data' in your DEFINE function. It is done so in valve.c, the UDF used in Fluent tutorial 13.

saclu May 16, 2011 05:05

Hi!

Thanks for your reply, I had a look to the valve.c and followed your advice. However I still have some errors when I'm trying to compile the udf. The main problem comes for this line:

Thread *t = Lookup_Thread(domain,zone_id);

It says that the use of *t not conform.

Tobard May 16, 2011 10:07

Hi!

Have you tried to split the command into two parts?

------------------------
Thread *t;
t = Lookup_Thread(domain,ZONE_ID);
------------------------

I am not sure that "Thread" works like "real"...

saclu May 16, 2011 10:47

Hi!
Thanks a lot for your help, I got it working with:

#include"udf.h"
#define DYNAMIC_ZONE_ID 7
DEFINE_RW_FILE(writer, fp)
{
real cg_omega[3];
Domain *d = Get_Domain(1);
Thread *t = Lookup_Thread(d, DYNAMIC_ZONE_ID);
Dynamic_Thread *t_box = THREAD_DT(t);

cg_omega[2] = DT_OMEGA_CG(t_box)[2];
printf(
"Writing UDF data to data file...\n");
fprintf(fp,
"%f",cg_omega); /* write out omega_Z to a data file */
}


I thing the problem what in the definition of cg_omega.


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