CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Moving mesh udf problem (https://www.cfd-online.com/Forums/fluent-udf/205645-moving-mesh-udf-problem.html)

vitali31 August 22, 2018 14:03

Moving mesh udf problem
 
Dear users.
I try to define flapping plate having center gravity moving.
I use the simple udf
DEFINE_CG_MOTION(foil0, dt, cg_vel, cg_omega, time, dtime)
{
cg_omega[2] = ThetAmp*ang_vel*cos(ang_vel*time);
}
The udf hooked to constant center of rotation.
However, in my problem, the rotation center is moving as well.

My question is: which way can I define move of rotation center.

Thank you a lot in advance.

blackmask August 23, 2018 03:50

You do not have to change the rotation center. Note that

\omega \times (r - r_1) = \omega \times (r - r_0) + \omega \times (r_0 - r_1)

which means you can effectively change the rotation center from r_0 to r_1 by superimpose a linear velocity \omega \times (r_0 - r_1).

vitali31 August 23, 2018 06:36

Dear blackmask.
Thank you for so quick and useful response.
wXdr = wVdT in i direction and wUdT in j direction, so i changed the udf in following manner:
cg_vel[0] = -0.7*w*sin(w*time)+w*cg_vel[1]*dtime;
cg_vel[1] = 0.7*w*cos(w*time)+w*cg_vel[0]*dtime;
just added linear component.
and
cg_omega[2] = w*0.7;
when 0.7 is r-r0.

the result was similar to snail shield.

What wrong in my view of the problem?

Thank you a lot in advance.

blackmask August 23, 2018 22:25

In my post all of r, r_0, r_1 are vectors, so it does not make sense that a vector is a scalar, i.e., 0.7 as you mentioned. The vector r_0 denotes the center of gravity (rotation) you input in the attribute page, and r_1 denotes the actual center of rotation. Can you elaborate more on the motion of center of rotation in your problem? The code should looks like:
Code:

DEFINE_CG_MOTION(foil0, dt, cg_vel, cg_omega, time, dtime)
{
real dx, dy ; /* [dx, dy] = r0 - r1 */
dx = ...; /* dx, dy can be time-dependent */
dy = ...; /* note that dx, dy is in the fixed-frame rather than in the moving frame */
        cg_omega[2] = ThetAmp*ang_vel*cos(ang_vel*time);
cg_vel[0] = -cg_omega[2]*dy;
cg_vel[1] = cg_omega[2]*dx;
}


vitali31 August 24, 2018 03:35

Dear blackmask.
First of all thank you so much for so informative help collaboration.
The general trajectory of rotation center is elliptical.
By the way the rotation center is not gravity center in this case.
But it is no matter because both of them is known, and gravity center detection is not take place in the udf.
Again, thank you a lot for the help.

blackmask August 27, 2018 01:54

Quote:

Originally Posted by vitali31 (Post 703764)
The general trajectory of rotation center is elliptical.

Is the elliptical trajectory in the stationary frame or rigid-body frame? The former is straightforward while the latter needs more work because you have to keep track of the orientation of the rigid body.

vitali31 August 27, 2018 02:31

Dear blackmask.
The body has elliptical trajectory in stationary domain, however, orientation of body is not strongly in direction of trajectory but tilted.
That a reason why i've thought to move the body relative, say, point [0,0], thereafter rotate it relative new rotation (mass center) position.
Unfortunately i can read the mass center of body each time step, but i don't know to define center rotation point via udf.

blackmask August 27, 2018 05:43

I am so sorry that I did not test before I answered your question. The method I proposed before simply does not work. I managed to modify the CoG(CoR) by modifying three (init, tmp, current) state variables at the same time. The body does change the center of rotation, however an abrupt translation of the body is observed at the same time. Below is the code for your reference. The rigid body is a two-dimensional airfoil whose leading and trailing edge point is located at (0, 0) and (1, 0), respectively. It first rotate around (0, 0) at an angular velocity of \pi/6 for one second, and then its center of rotation is changed to (\sqrt{3}/2, 1/2). Note that when this UDF is executed, the CoG(CoR) in the GUI is changed accordingly.
Code:

DEFINE_CG_MOTION(from_ori_to_cg, dt, cg_vel, cg_omega, time, dtime)
{
    const real pi = 4.0*atan(1.0);
    const real ang_vel = pi/6.0;
    const real ttt = 1.0;
   
    static int ccstep;
    int n_ts = time/dtime+0.5;
    ccstep = 1.0/dtime + 0.5;
    Message("ccstep = %d, N_TIME = %d\n", ccstep, n_ts);
   
    /*
    *  rotation and translation in the absolute reference frame
    */
    DT_NEST_LOC_ROT_P(dt) = FALSE;
    DT_NEST_LOC_TRAN_P(dt) = FALSE;
   
    /* in t = 0s, R0 = (0, 0, 0) */
    /* in ttt = 1s, the CoG will be located at */
    /* R1 = (L/2*cos theta, L/2*sin theta, 0), where theta=ang_vel*t */
    real dy = sin(ang_vel*ttt)/2.0, dx = cos(ang_vel*ttt)/2.0;
    cg_omega[2] = ang_vel;
    if (n_ts == ccstep) {
        dt->current_state.cg[0] = dx;
        dt->current_state.cg[1] = dy;
        dt->init_state.cg[0] = dx;
        dt->init_state.cg[1] = dy;
        dt->tmp_state.cg[0] = dx;
        dt->tmp_state.cg[1] = dy;
    } 
   
    Message("time: %g, CoRc = (%g, %g, %g), CoRi = (%g, %g, %g)\n",
            time,
            dt->current_state.cg[0],
            dt->current_state.cg[1],
            dt->current_state.cg[2],
            dt->init_state.cg[0],
            dt->init_state.cg[1],
            dt->init_state.cg[2],
            );
}


vitali31 August 27, 2018 06:21

Wow,that exactly what i am looking for.
Thank you so much...
Tell me pls, where do you take list of all functions, libraries,structures,sub-structures and variables for udf?
I have not found it in fluent manual and tutorials?
Thank you very much again....

vitali31 August 27, 2018 08:17

Dear blackmask

The code works perfect.
However i still have a problem.
Ones i use:
cg_vel[0] = -ang_vel*sin(ang_vel*time);
cg_vel[1] = ang_vel*cos(ang_vel*time);
with manually defined rotation center,(in my case is [0,0] i get circular translation.
Ones i use:
cg_omega[2] = ang_vel;
with manually defined rotation center,(in my case is [0.7,0] i get rotation on the place around it selves (because radius vector is 0).
What means, ones i change rotation center, translation and rotation should be independent.
However it does not happen.
I get snail shield trajectory.
The code is:

#include "udf.h"
#define freq 1
#define XAmp 0.7
#define YAmp 0.7
#define ang_vel 2*M_PI*freq

DEFINE_CG_MOTION(test, dt, cg_vel, cg_omega, time, dtime)
{
/*center rotation of body-function of time*/
dt->current_state.cg[0] =XAmp*cos(ang_vel*time);
dt->current_state.cg[1] =YAmp*sin(ang_vel*time);
dt->init_state.cg[0] = XAmp*cos(ang_vel*time);
dt->init_state.cg[1] = YAmp*sin(ang_vel*time);
dt->tmp_state.cg[0] = XAmp*cos(ang_vel*time);
dt->tmp_state.cg[1] = YAmp*sin(ang_vel*time);

/*rotation*/
cg_omega[2] = ang_vel;
/*i suppose the rotation does not have effect on body position, only on orientation*/

/*center translation definition-point [0,0]*/

dt->current_state.cg[0] = 0.0;
dt->current_state.cg[1] = 0.0;
dt->init_state.cg[0] = 0.0;
dt->init_state.cg[1] = 0.0;
dt->tmp_state.cg[0] = 0.0;
dt->tmp_state.cg[1] = 0.0;
/*translation-hase effect only on position of body but not on otientation*/
cg_vel[0] = -ang_vel*sin(ang_vel*time);
cg_vel[1] = ang_vel*cos(ang_vel*time);

}

Something incorrect there.
Thank you a lot in advance

vitali31 August 27, 2018 10:42

You can find that there is no presence of follow lines in the code:
/*
* rotation and translation in the absolute reference frame
*/
DT_NEST_LOC_ROT_P(dt) = FALSE;
DT_NEST_LOC_TRAN_P(dt) = FALSE;

Because with the lines, code do not pass compilation with next error message:

error C2106: '=' : left operand must be l-value

may be this is a problem?
Thanks

blackmask August 27, 2018 20:55

The following two lines
Quote:

Originally Posted by vitali31 (Post 704154)
DT_NEST_LOC_ROT_P(dt) = FALSE;
DT_NEST_LOC_TRAN_P(dt) = FALSE;

can be replaced by
Code:

dt->nested_local_rot_p = FALSE;
dt->nested_local_tran_p = FALSE;

However, the latter is exactly the former with macro expansion.

vitali31 August 28, 2018 07:36

Dear blackmask.
I tried the version and got response:
error C2039: 'nested_local_rot_p' : is not a member of 'dynamic_thread_struct'
error C2039: 'nested_local_tran_p' : is not a member of 'dynamic_thread_struct'
may be i should use additional header (library) and use :

DT_NEST_LOC_ROT_P(dt) = FALSE;
DT_NEST_LOC_TRAN_P(dt) = FALSE;
???
Thanks

blackmask August 28, 2018 08:15

Which version do you use? In v18 the
Code:

struct dynamic_thread_struct
is defined in header "dynamesh_tools.h".

vitali31 August 28, 2018 08:17

I use fluent 16.1

vitali31 August 28, 2018 08:22

Should i hook "dynamesh_tools.h" in some way?
Or it hooked automatically once i use #include "udf.h"

vitali31 August 28, 2018 08:32

Tried to add
#include "dynamesh_tools.h"
The problem is still....

vitali31 August 28, 2018 08:55

Ok, I have changed fluent version, so with
DT_NEST_LOC_ROT_P(dt) = FALSE;
DT_NEST_LOC_TRAN_P(dt) = FALSE;
compiling was passed, but it still snail shield trajectory....

vitali31 August 28, 2018 08:59

even with
DT_NEST_LOC_ROT_P(dt) = TRUE;
DT_NEST_LOC_TRAN_P(dt) = TRUE;

it doesn't works

blackmask August 28, 2018 21:16

They change the data structure across various versions. You can take a look at the header files and find if there is anything you can do about it.


All times are GMT -4. The time now is 06:21.