CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   Can you check if my attached UDF is correct?? (https://www.cfd-online.com/Forums/fluent/83405-can-you-check-if-my-attached-udf-correct.html)

gandesk December 27, 2010 14:29

Can you check if my attached UDF is correct??
 
Hi,

I am running a multiphase simulation with VOF model which has a droplet spreading on a solid substrate. In order to account for the transient surface tension effects of added surfactant to the droplet, I have written a UDF which defines the above effect and hooked it after compiling. Now my question is that why am I getting my results as if it is having very less surface tension than the defined trend in UDF. I want to make sure if fluent is using values defined from the UDF and is there a way to create a file while the case is running about the values of surface tension being used while the case is running? I hope my question is clear and really sorry to bother you with such a lengthy question. Please look at the UDF defined below:


#include "udf.h"
DEFINE_PROPERTY(dyn_surf_tension, cell, thread)
{
double dst;
double c_t = CURRENT_TIME;
if (c_t >= 0 || c_t < 5.000000e-002)
dst = 7.145500e-002;
if (c_t >= 5.000000e-002 || c_t < 7.050000e-001)
dst = 4.017570e-002;
if (c_t >= 7.050000e-002 || c_t < 9.950000e-002)
dst = 3.862980e-002;
if (c_t >= 9.950000e-002 || c_t < 1.000000e-001)
dst = 3.862690e-002;
else
dst = 3.862410e-002;
return dst;
}

Thanks and Regards
Sandeep K Gande

ComputerGuy December 28, 2010 10:11

Gandesk,

If you're hooking the UDF to the surface tension property box, found under phase--->interaction, you should be OK. I've changed your "double" variable definition to "real," changed the syntax slightly, and posted below. See if it works for you:

Code:

#include "udf.h"
DEFINE_PROPERTY(dyn_surf_tension, cell, thread)
{
        real dst;
        real c_t = CURRENT_TIME;
       
        dst = 3.862410e-002;
        if (c_t >= 0 && c_t < 5.000000e-002)
        {
                dst = 7.145500e-002;
        }
        if (c_t >= 5.000000e-002 && c_t < 7.050000e-001)
        {
                dst = 4.017570e-002;
        }
        if (c_t >= 7.050000e-002 && c_t < 9.950000e-002)
        {
                dst = 3.862980e-002;
        }
        if (c_t >= 9.950000e-002 && c_t < 1.000000e-001)
        {
                dst = 3.862690e-002;
        }
        return dst;
}

Your function for surface tension is not smooth; that is, surface tension is being given a number of discrete values, rather than interpolating between known points over time. You might think about interpolating to see if that helps.

Otherwise, to check the value of UDF-controlled surface tension (or any other UDF-controlled value), simply add a user-defined memory and examine it. Steps:
1) Define--->User-Defined--->Memory. Change the number to 1
2) In the code above, add
Code:

C_UDMI(cell,thread,0)=dst;
before the return statement.
3) Run a few time steps in your simulation, stop it, then examine the contours of the User-Defined-Memory location 0 to see if the surface tension matches what you expect.

ComputerGuy

gandesk December 28, 2010 18:36

Hi computerguy,

Thank you very much for your reply. It looks like the code is working good now. I will mail back you after the complete simulation. I hope it works perfectly.

I have another quesion wrt define--> memory. Can we include the same code with different numbers if we use more than one udf and want to extract all those values.

Thanks

Sandeep

gandesk December 28, 2010 18:45

Hi computer guy,

I forgot to mention about this following thing in my previous reply. I just have the surface tension values at thoses descrete points. How can i interpolate function. I did not understand what you meant. Could u pls explain me??

Thanks
Sandeep

ComputerGuy December 28, 2010 18:46

Sandeep,

If I recall correctly, you can define up to 500 user defined memory locations. As such, if you have variables you want to track from UDF's, I find UDMI's a better way of getting the status of such variables instead of writing to console.

You address them as
Code:

C_UDMI(cell,thread,XXX)=your_value;
Where XXX is the memory location, and your_value is what you'd like to assign.

Glad it's working.

ComputerGuy

ComputerGuy December 28, 2010 18:54

Sandeep,

Interpolating is simply choosing values in between your discrete points. If you were given two points which make up a line (y=m*x+b), you could figure out the equation which describes the line, and thus describe, for any value of x, the value of y.

By the way, I think there is a typo in the original code, which I've propagated in my code. The actual code (I think) should be:
Code:

#include "udf.h"
DEFINE_PROPERTY(dyn_surf_tension, cell, thread)
{
        real dst;
        real c_t = CURRENT_TIME;
       
        dst = 3.862410e-002;
        if (c_t >= 0 && c_t < 5.000000e-002)
        {
                dst = 7.145500e-002;
        }
        if (c_t >= 5.000000e-002 && c_t < 7.050000e-002)
        {
                dst = 4.017570e-002;
        }
        if (c_t >= 7.050000e-002 && c_t < 9.950000e-002)
        {
                dst = 3.862980e-002;
        }
        if (c_t >= 9.950000e-002 && c_t < 1.000000e-001)
        {
                dst = 3.862690e-002;
        }
        return dst;
}


gandesk December 28, 2010 20:17

Computer guy,

thanks for correcting me once again and really appreciate for your inputs. I have another question running a job which has UDF s in it parallelly. When I try to run it parallelly the follwing message is popping up in the log file.

Opening library "libudf"...
Primitive Error at Node 0: open_udf_library: No such file or directory


Could you help me what could be the reason

Actuallty I am try to run on a high performance linux cluster and I have used the following qsub commands

#PBS -N test21
#PBS -l walltime=90:00:00
#PBS -l nodes=4:ppn=4
#PBS -l software=fluent:fluentpar+16
#PBS -m abe
#PBS -S /bin/bash
#PBS -o /nfs/03/ucn0987/FLUENT/Test21/1.out
#PBS -j oe
set echo on
hostname
module load fluent
cd /nfs/03/ucn0987/FLUENT/Test21
rm -f pnodes
cat $PBS_NODEFILE | sort > pnodes
export ncpus=`cat pnodes | wc -l`
fluent 2ddp -t$ncpus -pinfiniband.ofed -cnf=pnodes -g < 3input



Thanks

Sandeep

Sandeep

ComputerGuy December 29, 2010 10:05

Sandeep,

I don't believe there's anything in the code I've written which is incompatible with parallel usage. Are you compiling or interpreting the code?

The steps you should go through are:
1) Define --> User-defined --> Functions --> Compiled
2) Source files --> Add --> Your_Udf.c
3) Click "Build"
4) If there are no errors, click "Load"

If you already have a libudf loaded, go to:
1) Define --> User-defined --> Functions --> Managed
2) Select libudf
3) Click unload, then repeat steps 1-4 above

If your udf compiles OK, and the steps I've laid out don't throw an error, I'm not sure what the problem is.

ComputerGuy

osamaajaz March 6, 2017 13:57

kindly check UDF and suggest better one
 
1 Attachment(s)
The two UDF below are for dynamic mesh in which BODY A will move from POINT 1 to POINT 2 and then back to POINT 1, picture for that is attached here.
kindly check and tell me errors. Suggest the better one with faster speed
if wrong! how can i correct it?

UDF 1
#include "udf.h"
DEFINE_CG_MOTION(move,dt,vel,omega,time,dtime)
{
vel[1] = 0.0315*sin(0.21*time);

}

DEFINE_CG_MOTION(ball1,dt,vel,omega,time,dtime)
{
if (time>0 && time<1)
vel[1]=0;
else if (time>1 && time<2)
vel[1]=0.009;
else if (time>15 && time<16)
vel[1]=-0.0005;
else if (time>16 && time<17)
vel[1]=-0.0137;
else
vel[1]=-0.00;

}

DEFINE_CG_MOTION(ball2,dt,vel,omega,time,dtime)
{
if (time>0 && time<1)
vel[1]=-0.005;
else if (time>1 && time<16)
vel[1]=0.0315*sin(0.21*time);
else if (time>16 && time<17.58)
vel[1]=0.007;
else
vel[1]=0.0315*sin(0.21*time);
}



UDF 2
#include "udf.h"
DEFINE_CG_MOTION(move,dt,vel,omega,time,dtime)
{
vel[1] = 0.0942*sin(0.628*time);
}

DEFINE_CG_MOTION(ball1,dt,vel,omega,time,dtime)
{
if (time>0 && time<1)
vel[1]=0.018*time;
else if (time>5 && time<5.1)
vel[1]=-0.0005;
else if (time>5.1 && time<5.5)
vel[1]=-0.035;
else

vel[1]=-0.00;
}

DEFINE_CG_MOTION(ball2,dt,vel,omega,time,dtime)
{
if (time>0 && time<0.4)
vel[1]=-0.01;
else if (time>0.4 && time<5.5)
vel[1]=0.0942*sin(0.628*time);
else if (time>5.5 && time<6.17)
vel[1]=-0.0028;
else

vel[1]=0.0942*sin(0.628*time);
}


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