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

UDF code for a vehicle along a curvature

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 28, 2018, 11:34
Default UDF code for a vehicle along a curvature
  #1
New Member
 
Sam Loy
Join Date: Feb 2018
Posts: 8
Rep Power: 8
loyhj94 is on a distinguished road
Dear readers,

I am currently trying to get my vehicle to travel in the centre of my curvature domain. It is a 2D simulation with dynamic meshing. However, I am not able to get the angle of motion accurately. My domain is a constant radius of 300m. I have attached my current UDF file below. Please advice. Thank you.

#include"udf.h"

DEFINE_CG_MOTION(velocity, dt, cg_vel, cg_omega, time, dtime)
{
real omega;

omega = 0.4*time;

cg_vel[0] = 0.0; /* x-velocity*/
cg_vel[1] = 70.0*time;
cg_vel[2] = 0.0;

cg_omega[0] = 0.0; /* angular motion*/
cg_omega[1] = 0.0;
cg_omega[2] = omega;

}
loyhj94 is offline   Reply With Quote

Old   March 1, 2018, 05:09
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Quote:
However, I am not able to get the angle of motion accurately
Can you be more specific?
What did you expect, and what did you get instead?
pakk is offline   Reply With Quote

Old   March 1, 2018, 10:55
Default
  #3
New Member
 
Sam Loy
Join Date: Feb 2018
Posts: 8
Rep Power: 8
loyhj94 is on a distinguished road
Quote:
Originally Posted by pakk View Post
Can you be more specific?
What did you expect, and what did you get instead?
I expect my vehicle to travel in the centre of my domain consistently. However, the vehicle tends to get too close to the left or the right side or touch the sides of the domain, causing the simulation to fail.
loyhj94 is offline   Reply With Quote

Old   March 1, 2018, 11:28
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Let me rephrase my question. Which trajectory do you want your vehicle to follow (mathematically)?

What you wrote now are equations for a vehicle that is speeding up in y-direction, and rotating faster and faster around the z-axis, I think.

Your problem is not in the coding of the UDF, but in writing down the correct equations for you problem.
pakk is offline   Reply With Quote

Old   March 1, 2018, 11:37
Default
  #5
New Member
 
Sam Loy
Join Date: Feb 2018
Posts: 8
Rep Power: 8
loyhj94 is on a distinguished road
Quote:
Originally Posted by pakk View Post
Let me rephrase my question. Which trajectory do you want your vehicle to follow (mathematically)?

What you wrote now are equations for a vehicle that is speeding up in y-direction, and rotating faster and faster around the z-axis, I think.

Your problem is not in the coding of the UDF, but in writing down the correct equations for you problem.

I have attached a link to my picture. My vehicle will be moving from the starting point to the end of the domain which curves to the left.

https://ibb.co/e8pAOH
loyhj94 is offline   Reply With Quote

Old   March 1, 2018, 11:55
Default
  #6
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Great. Now write an equation for this trajectory!
pakk is offline   Reply With Quote

Old   March 1, 2018, 12:23
Default
  #7
New Member
 
Sam Loy
Join Date: Feb 2018
Posts: 8
Rep Power: 8
loyhj94 is on a distinguished road
Quote:
Originally Posted by pakk View Post
Great. Now write an equation for this trajectory!
I have tried some equations I found online like:
omega = (2.0*asin(Chord/(2.0*Radius)))*time and
omega = atan((pow(cg_vel[1],2))/(g*r))
However, none of these equations as well as the current one works. Perhaps you will be aware of an equation that I may use?
loyhj94 is offline   Reply With Quote

Old   March 1, 2018, 12:42
Default
  #8
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
You don't need to go searching online for equations...

Think back to your lessons on school. Did you never learn equations for circles?
pakk is offline   Reply With Quote

Old   March 2, 2018, 05:51
Default
  #9
New Member
 
Sam Loy
Join Date: Feb 2018
Posts: 8
Rep Power: 8
loyhj94 is on a distinguished road
Quote:
Originally Posted by pakk View Post
You don't need to go searching online for equations...

Think back to your lessons on school. Did you never learn equations for circles?
Is it possible to set the centre of the circle for me to use the equation of circle?
loyhj94 is offline   Reply With Quote

Old   March 5, 2018, 04:49
Default
  #10
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Let me tell you what is possible.

- It is possible that you think a bit about which equation to put in. This is movement on a circle, you surely had something about it in school. Think back to those lessons about sine and cosine...
- It is possible that you then put your equation here, and we will help you to fix small mistakes that you might have made.
- It is possible that you then try to translate this mathematical equation into UDF code. Read what I write: "try". You might fail, but at least make an attempt.
- It is possible that we then help you to fix small mistakes in that attempt.
- It is possible that you can then use that code to run your simulation.

But all of that is only possible if you cooperate.

If you want to learn how to do it, I can be your teacher for free.
If you don't care about learning, and only want a solution for your problem, then you can hire me. US$2200,-- please.
pakk is offline   Reply With Quote

Old   March 13, 2018, 20:34
Default
  #11
New Member
 
Sam Loy
Join Date: Feb 2018
Posts: 8
Rep Power: 8
loyhj94 is on a distinguished road
I have tried using equation of circle to run my vehicle and it seems to work. However, towards the middle of the domain, my vehicle started to drift off from the centre of the domain. I believe it is the value of my radius that is wrong. Do you know how to find the correct value of my radius? Please advise.

#include"udf.h"

DEFINE_CG_MOTION(velocity, dt, cg_vel, cg_omega, time, dtime)
{
real omega;
real x,y;

y = time;
x = -sqrt(20.16-(pow(2.0,y)));
omega = -0.0607;

cg_vel[0] = x; /* x-velocity*/;
cg_vel[1] = 19.444;
cg_vel[2] = 0.0;

cg_omega[0] = 0.0; /* angular motion*/
cg_omega[1] = 0.0;
cg_omega[2] = omega;

}
loyhj94 is offline   Reply With Quote

Old   March 14, 2018, 08:28
Default
  #12
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
You have used an equation for the circle that fails if y becomes larger than the radius.

I would have used equations with sine and cosine. If your car drives with constant velocity magnitude, then the position is:

x_pos = R * cos(omega * time)
y_pos = R * sin(omega * time)

So the velocity becomes the derivative:

x_vel = -omega * R * sin(omega * time)
y_vel = omega * R * cos(omega * time)

Code:
#include"udf.h"

DEFINE_CG_MOTION(velocity, dt, cg_vel, cg_omega, time, dtime)
{
    real omega = -0.0607;
real R = 300;

cg_vel[0] = -omega * R * sin(omega * time);
cg_vel[1] = omega * R * cos(omega * time);
cg_vel[2] = 0.0;

cg_omega[0] = 0.0; /* angular motion*/
cg_omega[1] = 0.0;
cg_omega[2] = omega;

}
pakk is offline   Reply With Quote

Old   March 15, 2018, 03:57
Default
  #13
New Member
 
Sam Loy
Join Date: Feb 2018
Posts: 8
Rep Power: 8
loyhj94 is on a distinguished road
Quote:
Originally Posted by pakk View Post
You have used an equation for the circle that fails if y becomes larger than the radius.

I would have used equations with sine and cosine. If your car drives with constant velocity magnitude, then the position is:

x_pos = R * cos(omega * time)
y_pos = R * sin(omega * time)

So the velocity becomes the derivative:

x_vel = -omega * R * sin(omega * time)
y_vel = omega * R * cos(omega * time)

Code:
#include"udf.h"

DEFINE_CG_MOTION(velocity, dt, cg_vel, cg_omega, time, dtime)
{
    real omega = -0.0607;
real R = 300;

cg_vel[0] = -omega * R * sin(omega * time);
cg_vel[1] = omega * R * cos(omega * time);
cg_vel[2] = 0.0;

cg_omega[0] = 0.0; /* angular motion*/
cg_omega[1] = 0.0;
cg_omega[2] = omega;

}
Thank you for the help. But I don't understand the code fully. Do you mind explaining the code to me in detail? I really appreciate the help you offer.
loyhj94 is offline   Reply With Quote

Old   March 15, 2018, 10:10
Default
  #14
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Quote:
Originally Posted by loyhj94 View Post
Thank you for the help. But I don't understand the code fully. Do you mind explaining the code to me in detail? I really appreciate the help you offer.
What is the part that is giving you problems to understand?
pakk is offline   Reply With Quote

Old   March 22, 2018, 07:43
Default
  #15
New Member
 
Sam Loy
Join Date: Feb 2018
Posts: 8
Rep Power: 8
loyhj94 is on a distinguished road
It's fine. I managed to understand the code. Thank you for the help!
loyhj94 is offline   Reply With Quote

Reply


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
Who can fix the error on this UDF code??? NPs Fluent UDF and Scheme Programming 4 June 2, 2017 07:58
udf code azer FLUENT 0 April 20, 2017 18:16
UDF code help solve reaction rate equation palm oil zirkov Fluent UDF and Scheme Programming 0 February 13, 2017 11:34
write code UDF Fluent solve kinetic reaction rate equation palm oil zirkov FLUENT 0 February 13, 2017 11:16
How to transfer a 2D UDF code into 3D? Jo_vivian_lee Fluent UDF and Scheme Programming 0 August 26, 2012 04:36


All times are GMT -4. The time now is 18:55.