CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   DPM body force to express electric forces (https://www.cfd-online.com/Forums/fluent/97603-dpm-body-force-express-electric-forces.html)

adam14qin February 21, 2012 07:22

DPM body force to express electric forces
 
I am a new user to fluent and I want to express divergence of maxwell stress tensor in UDF file. Basically, the body forces include two items, coulomb force and polyrisation stress: Div MT=Q*E-1/2*E^2*Gradient of Permittivity. I create a UDF file following a template as below:

#include "udf.h"
DEFINE_DPM_BODY_FORCE(elec,p,i)
{
real q_m = 0.013625;
real pmtvt = 0.00000000000885;
real pmtvt_r = 80.5;
cell_t c = P_CELL(p);
Thread *t = P_CELL_THREAD(p);
real eforce;
eforce = q_m * C_UDSI_G(c,t,0)[i]-0.5*C_UDSI_G(c,t,0)[i]*C_UDSI_G(c,t,0)[i]*pmtvt*(pmtvt_r-1)/P_MASS(p);
return eforce;
}

Here q_m is charge per mass, C_UDSI_G is electric field strength calculated from a UDS

I incorporate the file in fluent and get very high Global Courant Number after a few iterations, my time step is 1e-6s. May I know what is the problem with my UDF and can anyone please help me to improve the UDF file? I will be very grateful~:)

Amir February 21, 2012 08:17

Dear Adam,

There are few suggestions:
  • check the dimension of defined variable
  • you've used constant gradient of permeability; I'm not sure, is the formulation correct? (it's better to use scientific format; e.g. 8.85e-12)
  • Did you checked the UDS contour?
  • As the first step, it's better to try decouple numerical procedure even if it's not physical. (find the flow field variable and then check the particle trajectories; i.e. the UDF won't affect the flow field ....)
Bests,

adam14qin February 21, 2012 09:10

Dear Amir


It's so great to get your reply, thanks a lot~

My case is that dielectric liquid flowing under electric field to form Taylor Conejet. It is similar to VOF tutorial with e field.

1. I have checked the dimension of defined variable, they seem to be right.

2. I used constant Gradient of Permittivity because only at interface the permittivity will change. I am not sure whether this is right or not. I willl try to use scientific format.

3. The UDS contour is electric potential distribution, which seems alright.


4. Can you please provide more detailed instruction for your fourth suggestion?

Btw,
I've changed the iteration time step to a smaller value (1e-7s) and it gives a smaller Global Courant Number. But the time step prevents me from getting results quickly. Do you think it is my code's problem or what else I can do?

Amir February 21, 2012 12:57

I'm not familiar with your case details, but if it is similar to VOF flow with an external field, your UDF macro is not proper!
you're using DPM body force which exerts a defined force to the particles not the fluid elements! performing a Lagrangian approach but it doesn't seem that you have any particle in your domain, do you?!
For implementation any external field to your fluid element you have to use DEFINE_SOURCE macro which is explained in details in the manual.

Bests,

adam14qin February 22, 2012 11:56

Quote:

Originally Posted by Amir (Post 345604)
I'm not familiar with your case details, but if it is similar to VOF flow with an external field, your UDF macro is not proper!
you're using DPM body force which exerts a defined force to the particles not the fluid elements! performing a Lagrangian approach but it doesn't seem that you have any particle in your domain, do you?!
For implementation any external field to your fluid element you have to use DEFINE_SOURCE macro which is explained in details in the manual.

Bests,

================================================== =======
You are absolutely right Amir, thank you for reminding me this. I have consulted the previous UDF user and he said my case is VOF with external e field hence DPM is not suitable for the situation. I need to create my own UDF define_source. However, I checked the manual and have no confident on the new coding.
Basically I need to define the source term with Maxwell Stress Tensor and incorporate the stress in the momentum equation.
I have three questions:
1. I checked that in the boundary condition (fluent 2ddp, mine is axial symmetric mesh), there is a fluid zone for me to specify my source term, there are momentum equations such as radical momentum or axial momentum equation. Should I create two define-source macros for both the radical and axial momentum equations?
2. For the stress I need to express in define-source, there is no defined interface for surface stresses. The interface is a broad spectrum of cells containing volume fractions between 0 and 1. I think it is quite tricky to define my interface.
3. Someone advises to use FLUENT’s model for incorporating surface tension as a template for the dielectric stress. Can you please provide me a template to incorporate surface tension?

Thank you~

Amir February 22, 2012 15:10

Hi,

1) The source term of the momentum equation is obviously a vector and you have to introduce separate source terms for each direction. (it's easy by setting direction of UDS gradient)
2) Maybe you can include cell volume fraction to your source term....
3) This is not my major, it's better to ask other guys.

Bests,

adam14qin February 22, 2012 23:22

Quote:

Originally Posted by Amir (Post 345797)
Hi,

1) The source term of the momentum equation is obviously a vector and you have to introduce separate source terms for each direction. (it's easy by setting direction of UDS gradient)
2) Maybe you can include cell volume fraction to your source term....
3) This is not my major, it's better to ask other guys.

Bests,

Thanks a lot, I will try.

FDE February 27, 2012 08:59

Ehd
 
Dear Amir
I want to simulate EHD.I use uds fluent for this job,I have this problem.
I solve this equation:div(grad(V))=0 ;[V:ELECTRICAL POTENTIAL]
BUT I can't to calculate Ex,Ey with this program
#include"udf.h"
DEFINE_EXECUTE_ON_LOADING(on_loading, libname)
{
int i;
Message(
"Setting names for %s...\n",libname);
Set_User_Memory_Name(0,
"E-field");
Set_User_Memory_Name(1,
"Phi-source");
Set_User_Scalar_Name(0,
"Phi");
for (i=0;i<1;i++)
{
Message(
"Set User scalar name: %d\n",i);
}
Message(
"Done!\n");
}
/* Sets the gradient of phi (UDS-0) to equal E_x (UDS-1) and E_y (UDS-2), and sets face
values */
DEFINE_SOURCE(phi_source,c,t,dS,eqn)
{
real phi_source;
dS[eqn] = 0.0;
phi_source = 0.0;
C_UDMI(c,t,0) = phi_source;
return phi_source;
}


DEFINE_ADJUST(Calc_E_xy,d)
{
Thread *t;
cell_t c;
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,1) = C_UDSI(c,t,0) ;
C_UDMI(c,t,2) = - C_UDSI_G(c,t,0)[0] ;
C_UDMI(c,t,3) = - C_UDSI_G(c,t,0)[1] ;
C_UDMI(c,t,4) = NV_MAG(C_UDSI_G(c,t,0)) ;
}
end_c_loop(c,t)
}
}







help me please

Amir February 27, 2012 09:32

Hi,

First of all ensure that you've solved UDS_0 equation correctly. (check the contour)
Then activate the capability of retaining gradient values for further usage in TUI:
"solve/set/expert and then answer yes to the question Keep temporary solver memory from being freed?"


PS: take a look over 2nd example of DEFINE_ADJUST macro in UDF manual (ver. 6.23)

Bests,

adam14qin February 28, 2012 01:16

Quote:

Originally Posted by Amir (Post 345797)
Hi,

1) The source term of the momentum equation is obviously a vector and you have to introduce separate source terms for each direction. (it's easy by setting direction of UDS gradient)
2) Maybe you can include cell volume fraction to your source term....
3) This is not my major, it's better to ask other guys.

Bests,

Dear Amir,

I tried to create my own C file as Define Source

Basically I want to determine first whether a cell has both liquid and air phase. If so, the source will be returned to momentum equation with a defined expression of Q*E-1/2*E^2*Gradient of Permittivity (E is the gradient of UDS_0 and I calculated the contour which is correct). If not, the source will be set to 0 (cell is either liquid phase or air phase only)

Here is the code for x momentum equation:

#include "udf.h"
#include "sg_mphase.h"
#define epsilon_0 8.85e-12
#define epsilon 80.1
DEFINE_SOURCE(xmom_source,c,t,dS,eqn)
{
Thread **pt = THREAD_SUB_THREADS(t);
Thread *tp = pt[0]; /*primary phase - air*/
Thread *ts = pt[1]; /*secondary phase - liquid*/
real source;
real q =13.625;

if ((C_VOF(c,pt[1])>0)&&(C_VOF(c,pt[1])<1) )
{
source = q* C_UDSI_G(c,t,0)[0]+ 0.5* C_UDSI_G(c,t,0)[0]* C_UDSI_G(c,t,0)[0]* epsilon_0* (epsilon - 1)/C_VOLUME(c,ts);
}
else
{
source = 0;
}
dS[eqn] = q + C_UDSI_G(c,t,o)[0]* epsilon_0* (epsilon -1)/C_VOLUME(c,ts);
return source;
}

When I compile the code in Fluent, it shows error:
tcj2.c: In Function xxx xmom_source
tcj2.c:30: error: xxxoxxx undeclared (first use in the funct
tcj2.c:30: error: (Each undeclared identifier is reported only once
tcj2.c:30: error: for each function it appears in.)
tcj2.c:14: warning: unused variable xxxt
make[3]: ***[tcj2.o] Error 1

here xxx is due to some display error.

Do you have suggestions for the UDF? I really appreciate your help~

Amir February 28, 2012 02:52

Quote:

Originally Posted by adam14qin (Post 346567)
Dear Amir,

I tried to create my own C file as Define Source

Basically I want to determine first whether a cell has both liquid and air phase. If so, the source will be returned to momentum equation with a defined expression of Q*E-1/2*E^2*Gradient of Permittivity (E is the gradient of UDS_0 and I calculated the contour which is correct). If not, the source will be set to 0 (cell is either liquid phase or air phase only)

Here is the code for x momentum equation:

#include "udf.h"
#include "sg_mphase.h"
#define epsilon_0 8.85e-12
#define epsilon 80.1
DEFINE_SOURCE(xmom_source,c,t,dS,eqn)
{
Thread **pt = THREAD_SUB_THREADS(t);
Thread *tp = pt[0]; /*primary phase - air*/
Thread *ts = pt[1]; /*secondary phase - liquid*/
real source;
real q =13.625;

if ((C_VOF(c,pt[1])>0)&&(C_VOF(c,pt[1])<1) )
{
source = q* C_UDSI_G(c,t,0)[0]+ 0.5* C_UDSI_G(c,t,0)[0]* C_UDSI_G(c,t,0)[0]* epsilon_0* (epsilon - 1)/C_VOLUME(c,ts);
}
else
{
source = 0;
}
dS[eqn] = q + C_UDSI_G(c,t,o)[0]* epsilon_0* (epsilon -1)/C_VOLUME(c,ts);
return source;
}

When I compile the code in Fluent, it shows error:
tcj2.c: In Function xxx xmom_source
tcj2.c:30: error: xxxoxxx undeclared (first use in the funct
tcj2.c:30: error: (Each undeclared identifier is reported only once
tcj2.c:30: error: for each function it appears in.)
tcj2.c:14: warning: unused variable xxxt
make[3]: ***[tcj2.o] Error 1

here xxx is due to some display error.

Do you have suggestions for the UDF? I really appreciate your help~

Hi,

First of all, notice that dS[eqn] is the derivation of source term respect to x-direction velocity component! and also you've used "o" instead of "0" in this equation.

Bests,

FDE March 4, 2012 15:30

Ehd
 
Dear amir,
Thank you so much,your suggest was very good,now I can calculate grad(UDSI(C,t,0))=-Ex,....
but I have problem with ehd modeling with udf fluent,
I need help you.I want have your Email address.

best regard.

adam14qin March 28, 2012 12:50

Dear Amir,

Recently I modified my UDFs. They are doing their job only expect there is a Define_Adjust macro causing problem.
I have to run the scalar equation a few iterations before I hook the adjust macro to the case. Otherwise I'm getting 'fluent received a fatal signal(SEGMENTATION VIOLATION)' error message.
I tried to follow the UDF manual by adding 'if (! Data_Valid_P()) return;' however this does not help. I'm still getting this error message.
Here I attach my UDF, could you please provide some suggestion?

#include "udf.h"
#define epsilon_0 8.85e-12
#define epsilon 80.1
DEFINE_ADJUST(efield, domain)
{
real estress_x,estress_y,pstress_x,pstress_y;
/*gradient of maxwell stress tensor*/
real q = 0.000036;
/*volume charge density at interface*/

Thread *t;
Thread **pt;
cell_t c;

/* Do nothing if gradient isn’t allocated yet. */
if (! Data_Valid_P())
return;

mp_thread_loop_c (t,domain,pt)/* t is a mixture thread*/
if (FLUID_THREAD_P(t))
{
begin_c_loop (c,t)
{
C_UDMI(c,t,0)= sqrt(pow(C_UDSI_G(c,t,0)[0],2)+ pow(C_UDSI_G(c,t,0)[1],2));
/*efield strength*/
if ((C_VOF(c,pt[1])>0)&&(C_VOF(c,pt[1])<1) )
{
estress_x = q*C_UDSI_G(c,t,0)[0];
estress_y = q*C_UDSI_G(c,t,0)[1];
real angle = atan2(C_P_G(c,t)[0],C_P_G(c,t)[1]);
/*interface normal vector angle with y axis*/
pstress_x = 0.5*pow(C_UDMI(c,t,0),2)*epsilon_0*(epsilon-1)/0.00002*sin(angle);
pstress_y = 0.5*pow(C_UDMI(c,t,0),2)*epsilon_0*(epsilon-1)/0.00002*cos(angle);
}
else
{
estress_x=0;
estress_y=0;
pstress_x=0;
pstress_y=0;
}
C_UDMI(c,t,1)=estress_x;
C_UDMI(c,t,2)=estress_y;
C_UDMI(c,t,3)=pstress_x;
C_UDMI(c,t,4)=pstress_y;
}
end_c_loop (c,t)
}
}

Amir March 28, 2012 16:07

Quote:

Originally Posted by adam14qin (Post 351980)
Dear Amir,

Recently I modified my UDFs. They are doing their job only expect there is a Define_Adjust macro causing problem.
I have to run the scalar equation a few iterations before I hook the adjust macro to the case. Otherwise I'm getting 'fluent received a fatal signal(SEGMENTATION VIOLATION)' error message.
I tried to follow the UDF manual by adding 'if (! Data_Valid_P()) return;' however this does not help. I'm still getting this error message.
Here I attach my UDF, could you please provide some suggestion?
}

Dear Qin,

This may happen because of incomplete initialization of UDS/UDMs.
Follow this procedure:
before iteration manually initialize UDMs and UDSs in this manner:
solve->initialize->patch .... select each UDMs, assign a proper value and patch the fluid zones. (Also do that for UDSs.)

Bests,

adam14qin March 29, 2012 05:42

Quote:

Originally Posted by Amir (Post 352015)
Dear Qin,

This may happen because of incomplete initialization of UDS/UDMs.
Follow this procedure:
before iteration manually initialize UDMs and UDSs in this manner:
solve->initialize->patch .... select each UDMs, assign a proper value and patch the fluid zones. (Also do that for UDSs.)

Bests,


Dear Amir,

I tried your advice, however not very successful.
Interestingly I tried to use define_execute_at_end instead of define_adjust, there is no more such error message.
Thank you all the same.

Regards,
Qin

adam14qin May 8, 2012 09:10

Dear Amir,

I have a question again. May I know if there is a Laplace operator in Fluent? Or is there a way to calculate the divergence of a certain gradient? For example, I have UDS equation solved, and I can get UDSI_G(c,t,0). Then I want to further calculate the divergence of UDSI_G(c,t,0), something should be equal to UDSI_G_G(c,t,0)[0]+UDSI_G_G(c,t,1)[1]. Could you please suggest a way or there is a such operator in Fluent? I will appreciate this very much!

Regards,
Qin

Amir May 8, 2012 14:32

Quote:

Originally Posted by adam14qin (Post 359930)
Dear Amir,

I have a question again. May I know if there is a Laplace operator in Fluent? Or is there a way to calculate the divergence of a certain gradient? For example, I have UDS equation solved, and I can get UDSI_G(c,t,0). Then I want to further calculate the divergence of UDSI_G(c,t,0), something should be equal to UDSI_G_G(c,t,0)[0]+UDSI_G_G(c,t,1)[1]. Could you please suggest a way or there is a such operator in Fluent? I will appreciate this very much!

Regards,
Qin

Hi,

you can store gradient of a UDS in another UDS and take gradient from new ones:
UDSI(c,t,1)=UDSI_G(c,t,0)[0]
UDSI(c,t,2)=UDSI_G(c,t,0)[1]
Laplacian of (UDSI(c,t,0))=UDSI_G(c,t,1)[0]+UDSI_G(c,t,2)[1]

Don't forget to deactivate new scalar equations!
Bests,

adam14qin May 9, 2012 01:12

Quote:

Originally Posted by Amir (Post 359981)
Hi,

you can store gradient of a UDS in another UDS and take gradient from new ones:
UDSI(c,t,1)=UDSI_G(c,t,0)[0]
UDSI(c,t,2)=UDSI_G(c,t,0)[1]
Laplacian of (UDSI(c,t,0))=UDSI_G(c,t,1)[0]+UDSI_G(c,t,2)[1]

Don't forget to deactivate new scalar equations!
Bests,

Thank you so much.

Regards,
Qin Hao

adam14qin May 27, 2012 14:09

Dear Amir,

I tried to store the diffusion coefficients of a UDS to another UDS (in VOF method, there is UDS for the mixture), that is C_UDSI(c,t,1)=C_UDSI_DIFF(c,t,0), then take the gradient. However, the gradient of the diffusion coefficients seems to be incorrect. Later, I tried to store the C_UDSI_DIFF(c,t,0) to UDMI, I found the UDMI is only filled with the C_UDSI_DIFF of phase 2 fluid, not a contour of mixture C_UDSI_DIFF(c,t,0).
Do you know there is a way to calculate the gradient of C_UDSI_DIFF of a mixture? I will be grateful for the solution.

Regards,
Qin

Payam89 October 30, 2012 11:46

Mhd
 
Hi

I have a Electric field in my flow in FLUENT which it's function is

E=Q/2*pi*E0 (1/X +1/S-X )

Q=1 electric charge
pi=3.141
E0=electric permability
X= x direction
S=1.87 cm

please help me to write a UDF:(

Should i use MHD?

PLEASEEE.....:(

Amir October 30, 2012 14:20

Quote:

Originally Posted by Payam89 (Post 389318)
Hi

I have a Electric field in my flow in FLUENT which it's function is

E=Q/2*pi*E0 (1/X +1/S-X )

Q=1 electric charge
pi=3.141
E0=electric permability
X= x direction
S=1.87 cm

please help me to write a UDF:(

Should i use MHD?

PLEASEEE.....:(

Hi,

You have different options and one of them is implementation of MHD module, but it's not really necessary for such simple purpose.
All you need is to add a source term to the NS equation; for this aim, refer to the UDF manual and read the explanation and examples of DEFINE_SOURCE macro.

PS: The goal of this community is to learn you fishing not to provide a fish!

Bests,

Payam89 October 31, 2012 09:05

Electric Field
 
Quote:

Originally Posted by Amir (Post 389339)
Hi,

You have different options and one of them is implementation of MHD module, but it's not really necessary for such simple purpose.
All you need is to add a source term to the NS equation; for this aim, refer to the UDF manual and read the explanation and examples of DEFINE_SOURCE macro.

PS: The goal of this community is to learn you fishing not to provide a fish!

Bests,

Thank you:)

I didn't want a solution but I asked sb to help me to start writing my UDF. do you mean i can add a momentum source to NS equation?

I don't think it is a matter if sb could help me by wrinting a UDF for me too!

thank you Amir

Yanlong Li January 15, 2013 07:49

Dear Qin,
I want to define Body force for particles in DPM Model, F=C*(density_liquid/density_particle)*(velocity_liquid - velocity_particle)*▽*velocity_liquid. the ▽*velocity_liquid is rotation of liquid.
1.Could you help me how to calculate this value ?
2.If I defined body force for particle and hooked it, do I need to define an oppsite force for the liquid? Does the FLUENT add this force to liquid automatically with an oppsite vector ?

Raghuvir February 20, 2013 13:23

Hi,I have a similar problem. I am working on adding a body force to navier stokes equation, which is a function of voltage and charge density.
I added Voltage and charge density as two UDS,0 and 1 respectively. For UDS'0' (volt), I use poissons potential equation i.e., del^2(V) = -rho_q/enod. So,diffusivity is -1 and source term is charge_density/e_nod. For UDS'1', I use charge conservation equation. i.e., grad(charge_density*mu_constant*E) = 0 where E = -grad(V). So, I use flux equation, calculate gradv term at face by taking average of two neighbour cells or zero if its boundary.

UDS-0 :-
source = -( C_UDSI(c,t,1) ) / (8.8514e-12) ;
dS[eqn] = 0 ;
return source ;

UDS-1:-


NV_VS_VS(fluxvec, =, C_UDSI_G(c0,t0,0), * , 0.5, + , C_UDSI_G (c1,t1,0) , * , 0.5 ) ;
flux = -NV_DOT(fluxvec, A)*2e-4; /* Average flux through face */
return flux;


Model :-

two electrodes surrounded by air. one electrode with 27k volt and charge density as 0.016. another electrode with 0 volt and o charge density.

PROBLEM :-


I get Nan values for UDS-1 (charge density) when I initialise it with anything except zero. If I initialise UDS-1 with 0 then the residual monitors of UDS-1 instantly go to e-43 values. But I see changes in UDS scalars only near electrodes and near domain boundaries, rest of the domain has constant UDS values.

I Tried
initialising without udf and then adding them after some iterations....but no luck.

I am guessing its sth to do with flux equation in that UDS-1 equation. Could anyone please help me with finding the error.

adam14qin August 1, 2013 13:34

Since we can only take the gradient of a vector in FLUENT, to calculate laplacian of a vector whose value is stored in a UDS C_UDSI(c,t,0), for example two dimensional d2f/dx2+d2f/dy2, you can use one C_UDSI(c,t,1) to store df/dx (C_UDSI_G(c,t,0)[0]) and a second C_UDSI(c,t,2) to store df/dy(C_UDSI_G(c,t,0)[1]), then, take gradient of C_UDSI(c,t,1)[0] and C_UDSI(c,t,2)[1], then the laplacian = C_UDSI(c,t,1)[0]+C_UDSI(c,t,2)[1]


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