|
[Sponsors] |
May 9, 2011, 11:39 |
PB with DEFINE_RW_FILE
|
#1 |
New Member
Join Date: Mar 2011
Posts: 20
Rep Power: 15 |
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 */ } --------------------------------------------------------------------- |
|
May 13, 2011, 15:19 |
|
#2 |
New Member
Join Date: Mar 2011
Posts: 28
Rep Power: 15 |
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! |
|
May 13, 2011, 16:52 |
|
#3 |
New Member
Join Date: Mar 2011
Posts: 28
Rep Power: 15 |
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. |
|
May 16, 2011, 06:05 |
|
#4 |
New Member
Join Date: Mar 2011
Posts: 20
Rep Power: 15 |
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. |
|
May 16, 2011, 11:07 |
|
#5 |
New Member
Join Date: Mar 2011
Posts: 28
Rep Power: 15 |
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"... |
|
May 16, 2011, 11:47 |
|
#6 |
New Member
Join Date: Mar 2011
Posts: 20
Rep Power: 15 |
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. |
|
|
|