CFD Online URL
[Sponsors]
Home > Forums > Fluent UDF and Scheme Programming

DEFINE_CG_MOTION vs DEFINE_GRID_MOTION

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   August 28, 2012, 12:02
Default DEFINE_CG_MOTION vs DEFINE_GRID_MOTION
  #1
Senior Member
 
Join Date: Mar 2011
Posts: 402
Rep Power: 10
cfd seeker is on a distinguished road
I am trying to simulate the flapping motion of simple wing using a UDF. I came across two types of UDF's for the said purpose. I would like to know the difference between the two types and which one is better if we want to simulate flapping/pitching/twisting/rolling motion of the wing. Thanks in advance

Regards
cfd seeker is offline   Reply With Quote

Old   August 30, 2012, 02:46
Default
  #2
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Shiraz, Iran
Posts: 738
Blog Entries: 1
Rep Power: 13
Amir is on a distinguished road
Dear friend,

DEFINE_GRID_MOTION macro is more general than DEFINE_CG_MOTION. with DEFINE_CG_MOTION macro you can just define a rigid body motion but with DEFINE_GRID_MOTION macro you can describe the motion of each computational node.

Bests,
__________________
Amir
Amir is offline   Reply With Quote

Old   September 3, 2012, 15:20
Default
  #3
Senior Member
 
Join Date: Mar 2011
Posts: 402
Rep Power: 10
cfd seeker is on a distinguished road
Thanks Amir for your reply. I am currently doing CFD analysis of flapping wing for which I have a UDF but there are some problems in that and its not working properly. I will share my UDF here in a day or two and will need your help to remove errors from it. Thanks
cfd seeker is offline   Reply With Quote

Old   September 7, 2012, 12:49
Default
  #4
Senior Member
 
Join Date: Mar 2011
Posts: 402
Rep Power: 10
cfd seeker is on a distinguished road
Hi guys I am back with my UDF I want to simulate flapping motion of wing. The wing goes up from the mean position, comes back to the mean position and completes the half cycle in opposite direction. Here instead of going up, it again goes down and keep on flapping between mean position and downward direction which ofcourse is wrong. I am not able to figure out the mistake in the UDF. Kindly I need the help to correct it. Thanks in advance

#include "udf.h"
DEFINE_GRID_MOTION(s1020, domain, dt, time, dtime)
{
Thread *tf = DT_THREAD (dt);
face_t f;
Node *v;
real NV_VEC(omega), NV_VEC(axis), NV_VEC(dp);
real NV_VEC(origin), NV_VEC(rvec);
real sign, terma, PI;
int n;
/* set deforming flag on adjacent cell zone */
SET_DEFORMING_THREAD_FLAG(THREAD_T0(tf));
terma = 26.178*time;
sign = -1 * sin (26.178 * time);
Message (" terma = %10.7f\n",terma);
Message (" time = %10.5f, sign = %10.5f \n", time, sign);
PI = 3.141592654;
/* if ( terma>PI )
{
sign = -sign;
}
*/
NV_S(omega, =, 0.0);
NV_D(axis, =, 1.0, 0.0, 0.0);
NV_D(origin, =, 0.5, 0.0, 0.0);
Message (" axis = %10.5f, origin = %10.5f \n", axis, origin);
begin_f_loop(f, tf)
{
f_node_loop(f, tf, n)
{
v = F_NODE(f, tf, n);
/* update node if z position is greater than 0.02 and that the current node */
/* has not been previously visited when looping through previous faces */
if (NODE_Z(v) > 0.02 && NODE_POS_NEED_UPDATE (v))
{
/* indicate that node position has been update so taht it's not */
/* updated more than once */
NODE_POS_UPDATED(v);
omega [0] = sign * pow (NODE_Z(v)/4, 0.5);
NV_VV(rvec, =, NODE_COORD(v), -, origin);
NV_CROSS(dp, omega, rvec);
NV_S(dp, *=, dtime);
if ( terma>(2.*PI) )
NV_V(NODE_COORD(v), -=, dp);
else
NV_V(NODE_COORD(v), +=, dp);
}
}
}
end_f_loop(f, tf);
}
cfd seeker is offline   Reply With Quote

Old   September 7, 2012, 12:52
Default
  #5
Senior Member
 
Join Date: Mar 2011
Posts: 402
Rep Power: 10
cfd seeker is on a distinguished road
I am attaching the txt file of the UDF in case any body wants to open it in C
Attached Files
File Type: txt s1020.txt (1.8 KB, 34 views)
cfd seeker is offline   Reply With Quote

Old   September 8, 2012, 04:47
Default
  #6
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Shiraz, Iran
Posts: 738
Blog Entries: 1
Rep Power: 13
Amir is on a distinguished road
Hi,

If just the direction is the issue, I solved it for my previous UDFs in this manner:
Suppose you know the magnitude of omega, A and the period is T; so you can do something like this:


Code:
dd=T/4;
time1=time;
time=time1/dd;
time=time1-((int)time)*dd;
if (time1<=dd)
{
	dtheta=A*dtime
}
else
{
	time2=(time1-dd)/(2.0*dd);
	m=((int)time2)+1;
	dtheta=pow(-1,m)*A*dtime;
}
i.e., you need to generate this sequence: +1,-1,-1,+1,+1,-1,-1,....

Hope that help.

Bests,
__________________
Amir
Amir is offline   Reply With Quote

Old   September 8, 2012, 11:11
Default
  #7
Senior Member
 
Join Date: Mar 2011
Posts: 402
Rep Power: 10
cfd seeker is on a distinguished road
Quote:
Originally Posted by Amir View Post
Hi,

If just the direction is the issue, I solved it for my previous UDFs in this manner:
Suppose you know the magnitude of omega, A and the period is T; so you can do something like this:


Code:
dd=T/4;
time1=time;
time=time1/dd;
time=time1-((int)time)*dd;
if (time1<=dd)
{
	dtheta=A*dtime
}
else
{
	time2=(time1-dd)/(2.0*dd);
	m=((int)time2)+1;
	dtheta=pow(-1,m)*A*dtime;
}
i.e., you need to generate this sequence: +1,-1,-1,+1,+1,-1,-1,....

Hope that help.

Bests,
Thanks Amir for your reply. I am just a beginner in UDF's and some one helped me to modify the UDF in the current shape. So i don't know much about UDF's and C, can you kindly suggest me where I am going wrong in my UDF and where to incorporate the lines suggested by you . Thanks
cfd seeker is offline   Reply With Quote

Old   September 8, 2012, 18:11
Default
  #8
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Shiraz, Iran
Posts: 738
Blog Entries: 1
Rep Power: 13
Amir is on a distinguished road
Quote:
Originally Posted by cfd seeker View Post
Thanks Amir for your reply. I am just a beginner in UDF's and some one helped me to modify the UDF in the current shape. So i don't know much about UDF's and C, can you kindly suggest me where I am going wrong in my UDF and where to incorporate the lines suggested by you . Thanks
It seems the problem is here:
Code:
if ( terma>(2.*PI) )
NV_V(NODE_COORD(v), -=, dp);
else
NV_V(NODE_COORD(v), +=, dp);
These conditions are not appropriate to model your movement properly.
To correct your code, you have to change your code in this manner:
Code:
period=2.0*PI/(26.178);
if (time<=(period/4.0))
{
	NV_CROSS(dp, abs(omega), rvec);
}
else
{
	time2=(time-(period/4.0))/(period/2.0);
	m=((int)time2)+1;
        NV_CROSS(dp, abs(omega)*pow(-1,m), rvec);
}
Substitute it in proper lines. (It may need additional changes in its format)

P.S. : We're here to help you figure out and eliminate the issues by yourself not to give you the final answer.

Bests,
__________________
Amir
Amir is offline   Reply With Quote

Old   September 12, 2012, 11:50
Default
  #9
Senior Member
 
Join Date: Mar 2011
Posts: 402
Rep Power: 10
cfd seeker is on a distinguished road
nclude "udf.h"
DEFINE_GRID_MOTION(s1020, domain, dt, time, dtime)
{
Thread *tf = DT_THREAD (dt);
face_t f;
Node *v;
real NV_VEC(omega), NV_VEC(axis), NV_VEC(dp);
real NV_VEC(origin), NV_VEC(rvec);
real sign, terma, PI,period;
int n,time2,m;
/* set deforming flag on adjacent cell zone */
SET_DEFORMING_THREAD_FLAG(THREAD_T0(tf));
terma = 26.178*time;
sign = -1 * sin (26.178 * time);
Message (" terma = %10.7f\n",terma);
Message (" time = %10.5f, sign = %10.5f \n", time, sign);
PI = 3.141592654;
/* if ( terma>PI )
{
sign = -sign;
}
*/
NV_S(omega, =, 0.0);
NV_D(axis, =, 1.0, 0.0, 0.0);
NV_D(origin, =, 0.5, 0.0, 0.0);
Message (" axis = %10.5f, origin = %10.5f \n", axis, origin);
begin_f_loop(f, tf)
{
f_node_loop(f, tf, n)
{
v = F_NODE(f, tf, n);
/* update node if z position is greater than 0.02 and that the current node */
/* has not been previously visited when looping through previous faces */

if (NODE_Z(v) > 0.02 && NODE_POS_NEED_UPDATE (v))
{
/* indicate that node position has been update so taht it's not */
/* updated more than once */

NODE_POS_UPDATED(v);
omega [0] = sign * pow (NODE_Z(v)/4, 0.5);




NV_VV(rvec, =, NODE_COORD(v), -, origin);

/*NV_CROSS(dp, omega, rvec);
NV_S(dp, *=, dtime);
if ( terma>(2.0*PI) )
NV_V(NODE_COORD(v), -=, dp);
else
NV_V(NODE_COORD(v), +=, dp);*/
period=2*PI/(26.178);

if (time<=(period/4.0))
{
NV_CROSS(dp,omega, rvec);
NV_V(NODE_COORD(v), +=, dp);
}
else
{
time2=(time-(period/4.0))/(period/2.0);
m=((int)time2)+1;

NV_S(omega,*=,pow(-1,m));

NV_CROSS(dp,omega), rvec);
NV_V(NODE_COORD(v), +=, dp);
}



}
}
}
end_f_loop(f, tf);
}

I have made the fallowing changes but UDF still not working, kindly take out sometime and have a look at it and suggest something.....
cfd seeker is offline   Reply With Quote

Old   September 12, 2012, 16:26
Default
  #10
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Shiraz, Iran
Posts: 738
Blog Entries: 1
Rep Power: 13
Amir is on a distinguished road
int time2!!!
__________________
Amir
Amir is offline   Reply With Quote

Old   September 12, 2012, 23:07
Default
  #11
Senior Member
 
Join Date: Mar 2011
Posts: 402
Rep Power: 10
cfd seeker is on a distinguished road
sorry Amir the mistake you pointed out was corrected in the original UDF but still its not working....I dont know what's happening in the changed version but the amplitude of the wing becomes so high that it becomes almost vertical and never comes back
cfd seeker is offline   Reply With Quote

Old   September 13, 2012, 05:07
Default
  #12
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Shiraz, Iran
Posts: 738
Blog Entries: 1
Rep Power: 13
Amir is on a distinguished road
Quote:
Originally Posted by cfd seeker View Post
sorry Amir the mistake you pointed out was corrected in the original UDF but still its not working....I dont know what's happening in the changed version but the amplitude of the wing becomes so high that it becomes almost vertical and never comes back
Maybe it's better to write the amplitude or omega in file to see where to change the code.

Bests,
__________________
Amir
Amir is offline   Reply With Quote

Old   September 13, 2012, 06:57
Default
  #13
Senior Member
 
Join Date: Mar 2011
Posts: 402
Rep Power: 10
cfd seeker is on a distinguished road
Quote:
Originally Posted by Amir View Post
Maybe it's better to write the amplitude or omega in file to see where to change the code.

Bests,
Sorry didn't get the point? please explain.....
Quote:
period=2.0*PI/(26.178); if (time<=(period/4.0)) { NV_CROSS(dp, abs(omega), rvec); } else { time2=(time-(period/4.0))/(period/2.0); m=((int)time2)+1; NV_CROSS(dp, abs(omega)*pow(-1,m), rvec); }
In the above commands I am not able to use "abs" with omega to get the absolute value of omega, every time I use the command "abs" fluent gives error....so is this thing causing problem or what else?
cfd seeker is offline   Reply With Quote

Old   September 13, 2012, 06:59
Default
  #14
Senior Member
 
Join Date: Mar 2011
Posts: 402
Rep Power: 10
cfd seeker is on a distinguished road
So instead of "abs(omega)" I am only using "omega"...is this thing causing problem or what else?
cfd seeker is offline   Reply With Quote

Old   September 13, 2012, 11:15
Default
  #15
New Member
 
Frederik
Join Date: Apr 2010
Posts: 8
Rep Power: 6
fchan is on a distinguished road
Quote:
Originally Posted by cfd seeker View Post
So instead of "abs(omega)" I am only using "omega"...is this thing causing problem or what else?
Did you include math.h?
fchan is offline   Reply With Quote

Old   September 13, 2012, 11:30
Default
  #16
Senior Member
 
Join Date: Mar 2011
Posts: 402
Rep Power: 10
cfd seeker is on a distinguished road
Quote:
Originally Posted by fchan View Post
Did you include math.h?
no i didn't....is it necessary?
cfd seeker is offline   Reply With Quote

Old   September 13, 2012, 12:41
Default
  #17
New Member
 
Frederik
Join Date: Apr 2010
Posts: 8
Rep Power: 6
fchan is on a distinguished road
Quote:
Originally Posted by cfd seeker View Post
no i didn't....is it necessary?
Yes! Also, use fabs() instead of abs() for float/double variables.

Quick google: http://www-control.eng.cam.ac.uk/~pc...h_details.html

TL;DR: add #include <math.h>

Good luck.
fchan is offline   Reply With Quote

Old   September 13, 2012, 22:47
Default
  #18
Senior Member
 
Join Date: Mar 2011
Posts: 402
Rep Power: 10
cfd seeker is on a distinguished road
Thanks fchan for your help. Have you seen my UDF? is everything ok except this?
cfd seeker is offline   Reply With Quote

Old   September 14, 2012, 02:52
Default
  #19
Senior Member
 
Join Date: Mar 2011
Posts: 402
Rep Power: 10
cfd seeker is on a distinguished road
Quote:
Originally Posted by fchan View Post
Yes! Also, use fabs() instead of abs() for float/double variables.

Quick google: http://www-control.eng.cam.ac.uk/~pc...h_details.html

TL;DR: add #include <math.h>

Good luck.
its not necessary to include <math.h> in UDF's. I read it today. It is necessary to include math.h IN "C" but its not necessary in UDF. Something else is wrong with my UDF.....
cfd seeker is offline   Reply With Quote

Old   September 14, 2012, 10:24
Default
  #20
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Shiraz, Iran
Posts: 738
Blog Entries: 1
Rep Power: 13
Amir is on a distinguished road
Quote:
Originally Posted by cfd seeker View Post
Sorry didn't get the point? please explain.....
Store the value of omega/amplitude in a file in different times and check where the issue is.
Quote:
Originally Posted by cfd seeker View Post
In the above commands I am not able to use "abs" with omega to get the absolute value of omega, every time I use the command "abs" fluent gives error....so is this thing causing problem or what else?
That's the general idea and it may need changes in its format; I'm not sure, maybe using functions in NV commands are not allowed; store abs(...) in a temporary variable and use that in NV command instead.

Bests,
__________________
Amir
Amir is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 13:10.