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/)
-   -   Force on moving body (https://www.cfd-online.com/Forums/fluent-udf/150766-force-moving-body.html)

joechorn March 29, 2015 07:23

Force on moving body
 
Hi,

I want to calculate the resulting force on a body moving in a fluid with predefined speed, but I am new to the work with UDF's.

As far as I understood with the SDOF Macro the Motion resulting out of a Force can be simulated, but the Macro is of void type, so there is no output.

The CG_MOTION Macro however defines a Motion, so this is more what I want.

Is there a possibility to generate a output(for example by using the DEFINE_OUTPUT_PARAMETER Macro) of the total force acting in the body, like the Force the SDOF Macro uses to calculate the Motion?
The force resulting out of the pressure(integration over the faces) and the fictious force (F=m*(dv/dt)) are no problem to calculate, but how can the "dynamic" force, resultant of the friction of the fluid on the body be calculated in UDF, like SDOF (at least I think) does?

Is it maybe possible to export the force from the SDOF makro?

Thank you very much in advance for any sugestion!

joechorn March 31, 2015 13:34

Motion UDF
 
The UDF part for the motion should look like this:
Code:

#include "udf.h"
#include <math.h>

DEFINE_CG_MOTION(bewegung,dt,velocity,omega,time,dtime)
{
    double hub = 0.002; //[m]
    double freq = 500; //[1/s]
    NV_S(vel, =, 0.0);
    NV_S(omega, =, 0.0);
    double arg = 2*M_PI*time*freq
    // 0:x; 1:y; 2:z;
    vel[0] = (M_PI*hub*freq)*sin(arg);
}

Does anyone have suggestions how to get the force acting on the body as output parameter?

`e` March 31, 2015 18:02

Which force components do you wish to include: pressure, wall shear? Have a read of this thread because they have code for calculating the force as a sum of pressure and wall shear.

joechorn April 1, 2015 12:15

Thank you very much, did not find this thread before... :rolleyes:

So the UDF schould look like this, right?

Code:

#include "udf.h"
#include <math.h>

#define HUB 0.004;        /* [m], double amplitude */
#define FREQ 500.0;        /* [1/s], frequency, 2ms switching time */
#define MASS 1.0;        /* [kg] needs to be updated!!! */

/* predefined motion */
DEFINE_CG_MOTION(bewegung,dt,cg_velocity,cg_omega,time,dtime)
{
    double arg;

    if (!Data_Valid_P()) return;        /*end in invalid data?*/

    /* initialization */
    NV_S(cg_velocity, = , 0.0);            /* set vel to 0, so only velocity in one direction is allowed(will be set below) */
    NV_S(cg_omega, =, 0.0);                /* no angular velocity needed */

    arg = 2 * M_PI * time * freq;                /* argument of sin */
    vel[0] = (M_PI * hub * freq) * cos(arg);    /* total velocity in x direction, first devirative of position */
}

DEFINE_OUTPUT_PARAMETER(force) /*problem: returns int!*/
{           
    Thread *t;            /* pointer to thread */
    face_t f;
    real forces*;        /* 0:newton-force(F=m*a); 1:pressure force(F=p*A); 2:shear force; */
    real acc;            /* acceleration */
    real arg;            /* argument of sin */
    t = DT_THREAD(dt);                /* get the thread pointer for which this motion is defined */

    NV_S(forces, = , 0.0);

    /*if (!Data_Valid_P()) return ;*/    /*end if invalid data? */

    arg = 2 * M_PI * time * freq;                                /* argument of sin */
    acc = -1 * pow(M_PI, 2) * pow(FREQ, 2) * HUB * sin(arg);    /* second derivative of position */
    forces[0] = MASS * acc;

    begin_f_loop(f, t)
    {
        F_AREA(A, f, t);                /* "Projected area" Vector */
        forces[1] += F_P(f, t) * A[0];    /* pressure force at current face added; only pressure normal to x! */

        forces[2] += F_STORAGE_R_N3V(f, t, SV_WALL_SHEAR)[0];    /*  shear force at current face added; only force in x-direction */
    }
    end_f_loop(f, t)

    real f_tot = forces[0] + forces[1] + forces[2];
    return (int *)f_tot;
}

In the documentation it says, the return of the output parameter is int.
is there any way to get a double output?

Thanks in advance!

`e` April 1, 2015 18:38

If DEFINE_OUTPUT_PARAMETER doesn't suit your requirements, you could either print the force to the screen with Message() or save to a text file.

When are you calling this force summation, you may need to parallelise this code if running Fluent in parallel.

Kokemoor April 2, 2015 11:25

First, I see a couple minor syntax issues:
C is case sensitive. I see both 'hub' and 'freq' in several places, which need to be 'HUB' and 'FREQ'.
Check your variable declarations. C requires all variable declarations at the top, before any non-declaration code. 'f_tot' is being declared where it appears at the end, not at the top. (i.e. you should have 'real f_tot;' at the top and 'f_tot = forces...;' near the end.

I'm really not sure what's going on with the return type. It looks like that code, as written, doesn't return an int, but a pointer to an int. If you remove the '(int *)' and instead just have 'return f_tot;' it should return a real (which is a float when running fluent in single precision and a double when running in double precision).

I'm not exactly sure how the vector operations play with arrays, since your 'forces' array isn't exactly the kind of vector you'd usually use for 'NV_*' operations. Instead of 'real forces*;' and later 'NV_S(forces, =, 0.0);' it might be more robust to just have 'real forces[3]={0};'


All times are GMT -4. The time now is 20:32.