|
[Sponsors] |
April 6, 2016, 07:10 |
Define_CG_Motion
|
#1 |
New Member
' w '
Join Date: Apr 2015
Posts: 6
Rep Power: 11 |
hi all,
really i would be appreciate if u help me because i am not familiar with c++ and coding to change this udf to 3 degree of freedom in x,y and z. /************************************************** ********** * 1-degree of freedom equation of motion (X direction) * compiled UDF ************************************************** **********/ #include "udf.h" static real v_prev = 0.0; DEFINE_CG_MOTION(piston,dt,vel,omega,time,dtime) { Thread *t; face_t f; real NV_VEC(A); real force, dv; /* reset velocities */ NV_S(vel, =, 0.0); NV_S(omega, =, 0.0); if (!Data_Valid_P()) return; /* get the thread pointer for which this motion is defined */ t = DT_THREAD(dt); /* compute pressure force on body by looping through all faces */ force = 0.0; begin_f_loop(f,t) { F_AREA(A,f,t); force += F_P(f,t) * NV_MAG(A); } end_f_loop(f,t) /* compute change in velocity, that is, dv = F * dt / mass velocity update using explicit Euler formula */ dv = dtime * force / 50.0; v_prev += dv; Message ("time = %f, x_vel = %f, force = %f\n", time, v_prev, force); /* set x-component of velocity */ vel[0] = v_prev; } Thanks in advance |
|
April 15, 2016, 06:45 |
|
#2 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
This user-defined function (UDF) uses vector macros (including NV_VEC and NV_S) which should generally scale well for 3-D. Could you explain your problem in detail, including what this UDF currently does and what you're hoping to achieve by modifying it?
|
|
April 15, 2016, 12:43 |
|
#3 |
New Member
' w '
Join Date: Apr 2015
Posts: 6
Rep Power: 11 |
Thank you `e`, I am doing simulation of 3D moving of an object, i have tried to compile this UDF and then the motion of the object was restricted in one dimension which is stated in definition of UDF in X-direction, therefore i would like to see the movement also in other direction Y and Z. is there any way to modify it? really i don't know how and i am still studying about it and no progress achieved.
|
|
April 16, 2016, 21:50 |
|
#4 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
The UDF is currently modifying the velocity in the x-direction with this code segment:
Code:
/* set x-component of velocity */ vel[0] = v_prev; Code:
/* set y-component of velocity */ vel[1] = v_prev; Code:
/* set x-, y- and z-components of velocity (all equal in magnitude) */ vel[0] = v_prev; vel[1] = v_prev; vel[2] = v_prev; |
|
|
|