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

Force on moving body

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   March 29, 2015, 07:23
Question Force on moving body
  #1
New Member
 
Joe Chorn
Join Date: Mar 2015
Posts: 4
Rep Power: 3
joechorn is on a distinguished road
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 is offline   Reply With Quote

Old   March 31, 2015, 13:34
Default Motion UDF
  #2
New Member
 
Joe Chorn
Join Date: Mar 2015
Posts: 4
Rep Power: 3
joechorn is on a distinguished road
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?
joechorn is offline   Reply With Quote

Old   March 31, 2015, 18:02
Default
  #3
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 758
Rep Power: 9
`e` is on a distinguished road
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.
`e` is offline   Reply With Quote

Old   April 1, 2015, 12:15
Default
  #4
New Member
 
Joe Chorn
Join Date: Mar 2015
Posts: 4
Rep Power: 3
joechorn is on a distinguished road
Thank you very much, did not find this thread before...

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!
joechorn is offline   Reply With Quote

Old   April 1, 2015, 18:38
Default
  #5
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 758
Rep Power: 9
`e` is on a distinguished road
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.
`e` is offline   Reply With Quote

Old   April 2, 2015, 11:25
Default
  #6
Senior Member
 
Andrew Kokemoor
Join Date: Aug 2013
Posts: 121
Rep Power: 6
Kokemoor is on a distinguished road
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};'
Kokemoor is offline   Reply With Quote

Reply

Tags
cg_motion, force, motion simulation, sdof, udf

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
BC for measuring force on blunt body letthe OpenFOAM Pre-Processing 4 December 9, 2013 19:20
Problems with SUPG body force term FEM question Main CFD Forum 0 January 21, 2006 18:51
UDF for lift force on a bluff body sawa FLUENT 2 April 11, 2005 03:06
how to add body force in a duct jane FLUENT 0 March 28, 2004 00:13
Body force Jacob FLUENT 0 August 4, 2003 16:38


All times are GMT -4. The time now is 05:37.