|
[Sponsors] |
February 28, 2018, 11:34 |
UDF code for a vehicle along a curvature
|
#1 |
New Member
Sam Loy
Join Date: Feb 2018
Posts: 8
Rep Power: 8 |
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; } |
|
March 1, 2018, 05:09 |
|
#2 | |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Quote:
What did you expect, and what did you get instead? |
||
March 1, 2018, 10:55 |
|
#3 |
New Member
Sam Loy
Join Date: Feb 2018
Posts: 8
Rep Power: 8 |
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.
|
|
March 1, 2018, 11:28 |
|
#4 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
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. |
|
March 1, 2018, 11:37 |
|
#5 | |
New Member
Sam Loy
Join Date: Feb 2018
Posts: 8
Rep Power: 8 |
Quote:
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 |
||
March 1, 2018, 11:55 |
|
#6 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Great. Now write an equation for this trajectory!
|
|
March 1, 2018, 12:23 |
|
#7 |
New Member
Sam Loy
Join Date: Feb 2018
Posts: 8
Rep Power: 8 |
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? |
|
March 1, 2018, 12:42 |
|
#8 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
You don't need to go searching online for equations...
Think back to your lessons on school. Did you never learn equations for circles? |
|
March 2, 2018, 05:51 |
|
#9 |
New Member
Sam Loy
Join Date: Feb 2018
Posts: 8
Rep Power: 8 |
||
March 5, 2018, 04:49 |
|
#10 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
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. |
|
March 13, 2018, 20:34 |
|
#11 |
New Member
Sam Loy
Join Date: Feb 2018
Posts: 8
Rep Power: 8 |
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; } |
|
March 14, 2018, 08:28 |
|
#12 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
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; } |
|
March 15, 2018, 03:57 |
|
#13 | |
New Member
Sam Loy
Join Date: Feb 2018
Posts: 8
Rep Power: 8 |
Quote:
|
||
March 15, 2018, 10:10 |
|
#14 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
||
March 22, 2018, 07:43 |
|
#15 |
New Member
Sam Loy
Join Date: Feb 2018
Posts: 8
Rep Power: 8 |
It's fine. I managed to understand the code. Thank you for the help!
|
|
|
|
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 |