CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

Move two zones at the same time, like a single unit

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 4, 2018, 07:17
Default Move two zones at the same time, like a single unit
  #1
Member
 
South Yorkshire
Join Date: May 2018
Posts: 33
Rep Power: 7
asking is on a distinguished road
Hi,

I am trying to move two mesh zones at the same time per time step. I used the DEFINE_CG_MOTION, which moves a zone as a rigid body (no internal deformation), and I prescribed a sinusoidal velocity to move both mesh zones.

Here is my code:

Code:
#include "udf.h"
#include "mem.h"

static real vy = 0.0;

DEFINE_CG_MOTION(rigid,dt,vel,omega,time,dtime)
{

/*Define variables*/
real cg[3], vcg[3];
int i;
NV_S(vel, =, 0.0);
NV_S(omega, =, 0.0);
Thread *thread;
Domain *d = Get_Domain(1);
face_t f;
thread = Lookup_Thread(d,zoneID);

real ctime = RP_Get_Real("flow-time");

for (i=0;i<3;i++)
{
cg[i]=DT_CG(dt)[i];
vcg[i] = DT_VEL_CG(dt)[i];
}

vy = 0.1*sin(31.41*ctime);

vel[0] = 0.0;
vel[1] = vy;
}

DEFINE_CG_MOTION(follower,fdt,fvel,fomega,time,dtime)
{

/*Define variables*/
NV_S(fvel, =, 0.0);
NV_S(fomega, =, 0.0);
real fcg[3], fvcg[3];
real fctime = RP_Get_Real("flow-time");
int i;

Thread *thread;
Domain *d = Get_Domain(1);
thread = DT_THREAD(fdt);

for (i=0;i<3;i++)
{
fcg[i]=DT_CG(fdt)[i];
fvcg[i] = DT_VEL_CG(fdt)[i];
}

fvel[0] = 0.0;
fvel[1] = vy;
}
And here are the results of the position of the centre of gravity in both mesh zones. Notice that they both start at the same position (0,0).

time - vel_rigid - vel_follower
0.0000 - 0.00000 - 0.00000
0.0010 - 0.00314 - 0.00000
0.0020 - 0.00628 - 0.00314
0.0020 - 0.01253 - 0.00628
... etc

As you can see, there is a delay in the "follower" velocity compared to the "rigid" one. Thus, both zones are not moving as a block.

Any ideas / suggestions on how to move both zones at the same time?

Thank you,
asking is offline   Reply With Quote

Old   September 4, 2018, 09:28
Default
  #2
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 21
blackmask will become famous soon enough
You use the static variable to transport information between functions but how could you be sure that "follower" is actually called after "rigid"? You need to assign the variable upon first call at each time step. A conceptual code looks like:
Code:
int cur_time_step = -1;

func_rigid() {
if (cur_time_step < N_TIME) { cur_time_step = N_TIME;vy = ...}

vel[1] = vy;
}

func_follower() {
if (cur_time_step < N_TIME) { cur_time_step = N_TIME;vy = ...}

vel[1] = vy;
}
blackmask is offline   Reply With Quote

Old   September 5, 2018, 04:56
Default
  #3
Member
 
South Yorkshire
Join Date: May 2018
Posts: 33
Rep Power: 7
asking is on a distinguished road
Quote:
Originally Posted by blackmask View Post
You use the static variable to transport information between functions but how could you be sure that "follower" is actually called after "rigid"? You need to assign the variable upon first call at each time step. A conceptual code looks like:
Code:
int cur_time_step = -1;

func_rigid() {
if (cur_time_step < N_TIME) { cur_time_step = N_TIME;vy = ...}

vel[1] = vy;
}

func_follower() {
if (cur_time_step < N_TIME) { cur_time_step = N_TIME;vy = ...}

vel[1] = vy;
}
Thank you very much. You were absolutely right. Your code also prevents the calculation of the velocity when the UDF its called multiple times within one timestep, which fixed another UDF I am implementing.
asking is offline   Reply With Quote

Reply

Tags
delay, udf


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
High Courant Number @ icoFoam Artex85 OpenFOAM Running, Solving & CFD 11 February 16, 2017 13:40
Floating point exception error lpz_michele OpenFOAM Running, Solving & CFD 53 October 19, 2015 02:50
How to write k and epsilon before the abnormal end xiuying OpenFOAM Running, Solving & CFD 8 August 27, 2013 15:33
same geometry,structured and unstructured mesh,different behaviour. sharonyue OpenFOAM Running, Solving & CFD 13 January 2, 2013 22:40
plot over time fferroni OpenFOAM Post-Processing 7 June 8, 2012 07:56


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