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/)
-   -   UDF for body force in DPM (https://www.cfd-online.com/Forums/fluent-udf/85719-udf-body-force-dpm.html)

elah599 March 5, 2011 04:16

UDF for body force in DPM
 
I want to write a udf for body force that included (fluid velocity minus particle velocity) in x direction.[du/dt-dv/dt].
can anybody help me how to write du/dt?

Amir March 5, 2011 07:58

first you should specify the cell index that contains particle, then you can use:
du=C_U(c,t)-C_U_M1(c,t)

elah599 March 5, 2011 08:15

this formula that you wrote,was just for du/dt? I read in help of fluent that the velocity of particle is shown with P_VEL(P)[i] that p is particle tracked and i represnts the coordinate. can you explain the terms that you wrote for that formula?

Amir March 5, 2011 08:29

Quote:

Originally Posted by elah599 (Post 298011)
can anybody help me how to write du/dt?

Hi iman,
first I think that you mean acceleration difference?am I right?
yes it's for the flow field part:
Code:

du/dt=(C_U(c,t)-C_U_M1(c,t))/CURRENT_TIMESTEP;
for particle part, you can implement user scalars for particles.

elah599 March 5, 2011 11:51

Hi Amir
thanks for your answering. yes, I mean relative acceleration between fluid and particle. I know that c_u(c,t) is u(cell,thread). but what is U_M1(c,t)? and I have to duplicate exactly "CURRENT_TIMESTEP" to my udf? I owe you lot!!thank you very much Amir:)

Amir March 5, 2011 15:07

Quote:

Originally Posted by elah599 (Post 298048)
Hi Amir
thanks for your answering. yes, I mean relative acceleration between fluid and particle. I know that c_u(c,t) is u(cell,thread). but what is U_M1(c,t)? and I have to duplicate exactly "CURRENT_TIMESTEP" to my udf? I owe you lot!!thank you very much Amir:)

Hi iman,
C_U_M1(c,t) : flow x-velocity in previous one time step
CURRENT_TIMESTEP : flow time step, you should use that to make your UDF independent of FLUENT changes in time step.

regards,

Amir

elah599 March 8, 2011 04:07

Hi amir
what is your comment aboat this udf?
# include "udf.h"
/* this udf insert a body force on particle in DPM model(A(du/dt-dv/dt)),A is a constant
that is known*/
DEFINE_DPM_BODY_FORCE(particle_body_fprce,cell,thr ead,p)
{
real bforce;
bforce= A((((C_U(cell,thread)-C_U_M1(cell,thread))/CURRENT_TIMESTEP)-((P_VEL(P)[0]-P_VEL_M1(P)[0])/CURRENT_TIMESTEP)));
return bforce;
}

Amir March 8, 2011 09:35

Hi Iman,
I'm not sure that P_VEL_M1(p) exists in dpm.h library!
if it exist, that's true else you can implement user scalars for particles.

elah599 March 9, 2011 07:00

Hi amir
I implemented the udf and fluent took this error:
line 7: non-integer subscript expression: pointer to structure.
do you know what that means?

Amir March 9, 2011 08:00

Hi,
it means that something is wrong in variables storage. i.e. you have stored a pointer parameter in a structure kind one.
in above UDF, use A*(...) syntax, also check the validity of P_VEL_M1 function.

regards,

Amir

elah599 March 9, 2011 08:36

my udf:
# include "udf.h"
/* this udf insert a body force on particle in DPM model(A(du/dt-dv/dt)),A is a constant
that is known*/
DEFINE_DPM_BODY_FORCE(particle_body_fprce,cell,thr ead,p)
{
real bforce;
bforce= (0.000000000000000000015)*((((C_U(cell,thread)-C_U_M1(cell,thread))/CURRENT_TIMESTEP)-((P_VEL(p)[0]-P_VEL_M1(p)[0])/CURRENT_TIMESTEP)));
return bforce;
}
how can I check the validity of P_VEL_M1?
regards

Amir March 9, 2011 11:59

you can check the validity a function by viewing it's header in src folder, I checked that and it didn't exist so you should use particle scalar array for your purpose as follow:
first you should specify the No. of scalar array in model->discrete phase->UDF tab->user variables -> increase to 1.
use this code. I didn't check that before:
Code:

# include "udf.h"
int n=0;
DEFINE_DPM_BODY_FORCE(particle_body_force,p,i)
{
Thread *t=P_CELL_THREAD(p);
cell_t c=P_CELL(p);
real bforce;
if(n==0) p->user[0]=0.0;
bforce= (1.5e-20)*((C_U(c,t)-C_U_M1(c,t))/CURRENT_TIMESTEP-(P_VEL(p)[0]-p->user[0])/CURRENT_TIMESTEP);
p->user[0]=P_VEL(p)[0];
n+=1;
return bforce;
}


elah599 March 12, 2011 04:31

Hi amir,
Thanks for your help,
when I interpret your code there is a error:
line 5: P_CELL_THREAD: undeclared variable

Amir March 12, 2011 10:17

Hi Iman,
I checked that as a compiled one, it didn't have any error!
compile your UDF instead.

elah599 March 14, 2011 09:28

Hi amir
I dont know but something is wrong.I couldent compile that code. I use fluent 12. does it affect? I think there shouldnt be many different between interpret & compile a udf?the version of visual studio is important?

Amir March 14, 2011 10:40

Hi Iman,
you can't interpret this UDF because P_CELL and P_CELL_THREAD need FLUENT solution, so you should compile that.
for compiling you need visual C++ 2000 or newer(at least ver 6.) installed on your PC. and ensure that VC++ is linked with FLUENT and your file name doesn't have any space... .
I've checked that before as compiled one. if you post the errors during compilation, I may help you.

elah599 March 15, 2011 08:15

hi amir
when I compile udf the fluent gives the following error:
(chdir "libudf")()
(chdir "win64\2ddp")()
'nmake' is not recognized as an internal or external command,
operable program or batch file.
'nmake' is not recognized as an internal or external command,
operable program or batch file.
Done.

Amir March 15, 2011 08:41

Hi,
you don't have linked FLUENT with VC++.
for more information refer to:
http://www.cfd-online.com/Forums/flu...iling-udf.html

elah599 March 15, 2011 14:49

hi amir
I have run fluent from VC command prompt, but again i recieved these errors,I'm totally confused!
(system "copy "C:\PROGRA~1\ANSYSI~1\v120\fluent"\fluent12.0.16\s rc\makefile_nt.udf libudf\win64\2ddp\makefile")
1 file(s) copied.
(chdir "libudf")()
(chdir "win64\2ddp")()
# Generating ud_io1.h
vmp.c
c:\program files\ansys inc\v120\fluent\fluent12.0.16\src\config.h(110) : error C2143: syntax error : missing '{' before ':'
c:\program files\ansys inc\v120\fluent\fluent12.0.16\src\config.h(110) : error C2059: syntax error : ':'
C:\PROGRA~1\ANSYSI~1\v120\fluent\fluent12.0.16\cor tex\src\dll.h(64) : error C2061: syntax error : identifier 'CX_DLL_GetProc'
C:\PROGRA~1\ANSYSI~1\v120\fluent\fluent12.0.16\cor tex\src\dll.h(64) : error C2059: syntax error : ';'
C:\PROGRA~1\ANSYSI~1\v120\fluent\fluent12.0.16\cor tex\src\dll.h(64) : error C2059: syntax error : 'type'
..\..\src\vmp.c(6) : warning C4047: 'initializing' : 'Thread *' differs in levels of indirection from 'int'
Done.

elah599 March 16, 2011 04:12

Quote:

Originally Posted by elah599 (Post 299548)
hi amir
I have run fluent from VC command prompt, but again i recieved these errors,I'm totally confused!
(system "copy "C:\PROGRA~1\ANSYSI~1\v120\fluent"\fluent12.0.16\s rc\makefile_nt.udf libudf\win64\2ddp\makefile")
1 file(s) copied.
(chdir "libudf")()
(chdir "win64\2ddp")()
# Generating ud_io1.h
vmp.c
c:\program files\ansys inc\v120\fluent\fluent12.0.16\src\config.h(110) : error C2143: syntax error : missing '{' before ':'
c:\program files\ansys inc\v120\fluent\fluent12.0.16\src\config.h(110) : error C2059: syntax error : ':'
C:\PROGRA~1\ANSYSI~1\v120\fluent\fluent12.0.16\cor tex\src\dll.h(64) : error C2061: syntax error : identifier 'CX_DLL_GetProc'
C:\PROGRA~1\ANSYSI~1\v120\fluent\fluent12.0.16\cor tex\src\dll.h(64) : error C2059: syntax error : ';'
C:\PROGRA~1\ANSYSI~1\v120\fluent\fluent12.0.16\cor tex\src\dll.h(64) : error C2059: syntax error : 'type'
..\..\src\vmp.c(6) : warning C4047: 'initializing' : 'Thread *' differs in levels of indirection from 'int'
Done.

there is no difference which udf I want to compile. every udf that I want to compile,fluent gives that error.

elah599 March 16, 2011 05:05

hi amir
when I launched fluent from visual studio x64 win64 command prompt (2010) the above problem was solved!
thank you for your honesty supporting

Amir March 16, 2011 09:04

I proposed you to check the UDF for a simple case(validate it). I didn't check it's accuracy before.:)

elah599 April 30, 2011 07:02

Dear Amir
I compiled this udf without any error. but when I run the program I get this error:
FLUENT received fatal signal (ACCESS_VIOLATION)
1. Note exact events leading to error.
2. Save case/data under new name.
3. Exit program and restart to continue.
4. Report error to your distributor.
Error Object: #f
do you know what should I do?

Amir April 30, 2011 15:20

Hi Iman,
before running your problem with this UDF, you have to set the number of user variables in DPM panel. (you have used one user variable)
Define->models->DPM->UDF-> set the No. of scalars to 1

elah599 May 1, 2011 10:18

hi amir
I did it, but it doesn't work!again I got this error.

Amir May 2, 2011 07:25

Hi,
in addition to above settings, try this code:
Quote:

# include "udf.h"
int n=0;
DEFINE_DPM_BODY_FORCE(particle_body_force,p,i)
{
Thread *t=P_CELL_THREAD(p);
cell_t c=P_CELL(p);
real bforce;
if(n==0) p->user[0]=0.0;
if (CURRENT_TIME>1.5*CURRENT_TIMESTEP)
{
bforce= (1.5e-20)*((C_U(c,t)-C_U_M1(c,t))/CURRENT_TIMESTEP-(P_VEL(p)[0]-p->user[0])/CURRENT_TIMESTEP);
}
else
{
bforce=0.0;
}
p->user[0]=P_VEL(p)[0];
n+=1;
return bforce;
}

elah599 May 2, 2011 08:39

hi amir
did you compile this udf?when I build it, it's ok,but when I load this udf I have this error:
open_udf_library: The system cannot find the file specified.
I tried to consider all above things.

Amir May 2, 2011 15:54

Hi,
yes of course; I also track particles with it !!!
when this error appears, it means that the libudf file is not created, so notice your compiling procedure or check that in different case files.

elah599 May 14, 2011 10:11

hi amir
this udf works for steady particle tracking, but when I want to apply it for unsteady particle tracking, after 2 or 3 iteration,I have this error again.do you know what's wrong?

Amir May 15, 2011 02:32

Hey Iman,
I've checked that for 10 time step and it worked ! ensure that you've done this:
Define->models->DPM->UDF-> set the No. of scalars to 1

elah599 August 7, 2011 06:17

Dear amir
thanks for your support
I am concerned with new case that I need to write a new UDF for Drag force, but I received several errors. Please compile this udf to see what can we do with these errors. I enclosed my udf.
thank you so much.

#include "udf.h"
#define dp 50e-9
#define sigma_square 1.35305239e-19
#define ambpress 101325
#define Boltzmann 1.3806505e-23
#define PI 3.14159265358979323846
#define SQRT_2 1.414213566237309504880


DEFINE_DPM_DRAG(particle_drag_force,Re,p)
{

real drag_force,MeanFreePath,Nu,W;

face_t face;
cell_t cell;
Thread *c_thread;
Thread *f_thread;

MeanFreePath=Boltzmann*F_T(face,f_thread)/(
sigma_square*(F_P(face,f_thread)+ambpress)*
PI*SQRT_2);

Nu=MeanFreePath/dp;

W=-0.1695-0.3881*(double log (double Re))+1.1722/(double sqrt (double Re))+(-0.1389)/Re+1.7637*(double exp (double (-Nu));

particle_drag_force=(double exp (double W));

return (drag_force);

}

Amir August 7, 2011 06:57

Hi,
you were trying to set real value to string one!
try this:
Code:

#include "udf.h"
#define dp 50e-9
#define sigma_square 1.35305239e-19
#define ambpress 101325
#define Boltzmann 1.3806505e-23
#define PI 3.14159265358979323846
#define SQRT_2 1.414213566237309504880


DEFINE_DPM_DRAG(particle_drag_force,Re,p)
{

real drag_force,MeanFreePath,Nu,W;

face_t face;
cell_t cell;
Thread *c_thread;
Thread *f_thread;

MeanFreePath=Boltzmann*F_T(face,f_thread)/(
sigma_square*(F_P(face,f_thread)+ambpress)*
PI*SQRT_2);

Nu=MeanFreePath/dp;

W=-0.1695-0.3881*log(Re)+1.1722/sqrt(Re)+(-0.1389)/Re+1.7637*exp(-Nu);

drag_force=exp(W);

return (drag_force);

}


elah599 August 14, 2011 02:17

Hi Amir
I compiled this code, it has no error but it has two warnings:
uninitialized local variable 'f_thread' used
uninitialized local variable 'face' used
but when I want to initialize my case I have ACCESS_VIOLATION error. does it relate to initialize them?
thank you for your help

Amir August 14, 2011 03:26

Quote:

Originally Posted by elah599 (Post 320017)
Hi Amir
I compiled this code, it has no error but it has two warnings:
uninitialized local variable 'f_thread' used
uninitialized local variable 'face' used
but when I want to initialize my case I have ACCESS_VIOLATION error. does it relate to initialize them?
thank you for your help

No, your algorithm is not right; in your previous post, I just corrected your bad assignment but I didn't notice to other parts.(maybe that's my fault) :o
Anyway, you have used some unreferenced parameters such as:
Code:

face_t face;
cell_t cell;
Thread *c_thread;
Thread *f_thread;

you have to express how these parameters related to particle pointer (p). Also it's not obvious that why did you use face values instead of cell values?
If it's true to use cell values physically, first assign cell index and it's thread via these commands (and omit 2 face references):
Code:

c=P_CELL(p)
c_thread=P_CELL_THREAD(p)


Bests,

elah599 August 16, 2011 10:22

Dear Amir
thank you very much for your supporting every time:)
I have two questions:
1. have you ever worked with mixture model in fluent. Can I use it for solid-liquid mixture? according to fluent tutorial, I defined a case but my results in heat transfer is overstimate. I guess maybe second phase volume fraction affect results. my total volume fraction is 1%, so, should I insert 0.01 for second phase volume fraction?
2. in DPM model, I don't get the meaning of particle flow rate, in injection tab. when we insert the number of particles, diameter and velocity of particles, what is particle flow rate?I remember one time you told me that it express the different between real particle and computational particle, when we have lots of particles. but I don't know, how compute particle flow rate.
sorry for long text:(

Amir August 16, 2011 11:37

Quote:

Originally Posted by elah599 (Post 320306)
1. have you ever worked with mixture model in fluent. Can I use it for solid-liquid mixture? according to fluent tutorial, I defined a case but my results in heat transfer is overstimate. I guess maybe second phase volume fraction affect results. my total volume fraction is 1%, so, should I insert 0.01 for second phase volume fraction?

I recommend you not to use mixture model for your case; it's more than that you really need:D
Note, this is eulerian multi-phase model used for larger volume fractions. As you know, brownian motion of particles play role of diffusion; so, if you want to use eulerian method instead of lagrangian one, I recommend you to use UDS instead of mixture model which is much more simpler and without restriction of volume fraction! Here, you just need to choose proper diffusion coefficient which obtained from brownian motion concepts. But, before switching to eulerian method, note whether this model is proper for your case or not. Indeed, eulerian method is better for nano particle modelling.

Quote:

Originally Posted by elah599 (Post 320306)
2. in DPM model, I don't get the meaning of particle flow rate, in injection tab. when we insert the number of particles, diameter and velocity of particles, what is particle flow rate?I remember one time you told me that it express the different between real particle and computational particle, when we have lots of particles. but I don't know, how compute particle flow rate.
sorry for long text:(

Look, when you view a particle path in fluent, it's not related to just 1 particle, it assumes that some other particles follow the 1st one but it doesn't have any effect on solver; i.e., you are seeing a chain of particles which pass the same path. Consequently, the computational number of particles are the number of paths, but the number of real particles are (paths*No per path). This parameter is not used in path finding but it is used for fining particle concentration. You have to set it from your physical model.

elah599 August 21, 2011 05:31

[QUOTE=Amir;320324]I recommend you not to use mixture model for your case; it's more than that you really need:D
Note, this is eulerian multi-phase model used for larger volume fractions. As you know, brownian motion of particles play role of diffusion; so, if you want to use eulerian method instead of lagrangian one, I recommend you to use UDS instead of mixture model which is much more simpler and without restriction of volume fraction! Here, you just need to choose proper diffusion coefficient which obtained from brownian motion concepts. But, before switching to eulerian method, note whether this model is proper for your case or not. Indeed, eulerian method is better for nano particle modelling.


Hi Amir
this model is part of my project.because low volume fraction, lagrange approach is best for nano particles, but I have to use mixture model for comparison with lagrange model. I read different tutorials and it doesn't seem to be complicated!but my results are over estimate. is there any special point that I should consider?or do you think my flow is granular?
Also, I didn't hear anything about UDS model. is it a part of multiphase modeling?
thanks alot

elah599 August 21, 2011 05:34

also, I know about real and computational particles in DPM. I want to know how calculate flow rate in injection particle inlet?
thank you very much.

Amir August 21, 2011 09:35

Quote:

Originally Posted by elah599 (Post 320879)
Hi Amir
this model is part of my project.because low volume fraction, lagrange approach is best for nano particles, but I have to use mixture model for comparison with lagrange model. I read different tutorials and it doesn't seem to be complicated!but my results are over estimate. is there any special point that I should consider?or do you think my flow is granular?
Also, I didn't hear anything about UDS model. is it a part of multiphase modeling?
thanks alot

Dear Iman,
I've done many projects concerning nano particle distribution and confidently say that UDS is the best way of modelling it because it's applicable to both low and high volume fraction; i.e., I don't agree with you that lagrangian approach is the best tool for nano particle cases! :eek:
contrarily, it's the worst tool because of its bugs in computing deposition and dispersion!
Note that UDS (user defined scalar) is just a scalar conservation equation which can be used to evaluate particle concentration in your case (more info in user manual), so if you want to implement eulerian method as a part of your project, you can also use UDS instead of multiphase models.

Quote:

Originally Posted by elah599 (Post 320882)
also, I know about real and computational particles in DPM. I want to know how calculate flow rate in injection particle inlet?
thank you very much.

You can find particle flow rate form your realistic case; e.g., you may know inlet particle flux or ..... Note that in some lagrangian models, the flow rate which you determined is considered as whole flow rate but in some other considered for each trajectory; I say again that this data won't affect particle trajectories.

Bests,

elah599 August 23, 2011 06:21

Dear Amir
I read the help of fluent for UDS and unfortunately I didn't get what should I do. do I have to solve the flow for multiphase flow or single phase flow? is just enough to consider coefficient of diffusion in material tab? if you have a simple case file, it would be great if you can send me that until I know what should I do. because I didn't find a proper tutorial for this concept.
thanks for your support:)


All times are GMT -4. The time now is 11:12.