CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > FLUENT

DPM body force to express electric forces

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

Like Tree2Likes

Reply
 
LinkBack Thread Tools Display Modes
Old   February 21, 2012, 08:22
Default DPM body force to express electric forces
  #1
New Member
 
Qin
Join Date: Feb 2012
Posts: 15
Rep Power: 6
adam14qin is on a distinguished road
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~
adam14qin is offline   Reply With Quote

Old   February 21, 2012, 09:17
Default
  #2
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 739
Blog Entries: 1
Rep Power: 15
Amir is on a distinguished road
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,
nayn likes this.
__________________
Amir
Amir is offline   Reply With Quote

Old   February 21, 2012, 10:10
Default
  #3
New Member
 
Qin
Join Date: Feb 2012
Posts: 15
Rep Power: 6
adam14qin is on a distinguished road
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?
adam14qin is offline   Reply With Quote

Old   February 21, 2012, 13:57
Default
  #4
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 739
Blog Entries: 1
Rep Power: 15
Amir is on a distinguished road
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,
__________________
Amir
Amir is offline   Reply With Quote

Old   February 22, 2012, 12:56
Default
  #5
New Member
 
Qin
Join Date: Feb 2012
Posts: 15
Rep Power: 6
adam14qin is on a distinguished road
Quote:
Originally Posted by Amir View Post
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~
adam14qin is offline   Reply With Quote

Old   February 22, 2012, 16:10
Default
  #6
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 739
Blog Entries: 1
Rep Power: 15
Amir is on a distinguished road
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,
__________________
Amir
Amir is offline   Reply With Quote

Old   February 23, 2012, 00:22
Default
  #7
New Member
 
Qin
Join Date: Feb 2012
Posts: 15
Rep Power: 6
adam14qin is on a distinguished road
Quote:
Originally Posted by Amir View Post
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.
adam14qin is offline   Reply With Quote

Old   February 27, 2012, 09:59
Default Ehd
  #8
FDE
New Member
 
FDE
Join Date: Feb 2012
Posts: 2
Rep Power: 0
FDE is on a distinguished road
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
FDE is offline   Reply With Quote

Old   February 27, 2012, 10:32
Default
  #9
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 739
Blog Entries: 1
Rep Power: 15
Amir is on a distinguished road
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,
__________________
Amir
Amir is offline   Reply With Quote

Old   February 28, 2012, 02:16
Default
  #10
New Member
 
Qin
Join Date: Feb 2012
Posts: 15
Rep Power: 6
adam14qin is on a distinguished road
Quote:
Originally Posted by Amir View Post
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~
adam14qin is offline   Reply With Quote

Old   February 28, 2012, 03:52
Default
  #11
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 739
Blog Entries: 1
Rep Power: 15
Amir is on a distinguished road
Quote:
Originally Posted by adam14qin View Post
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,
__________________
Amir
Amir is offline   Reply With Quote

Old   March 4, 2012, 16:30
Default Ehd
  #12
FDE
New Member
 
FDE
Join Date: Feb 2012
Posts: 2
Rep Power: 0
FDE is on a distinguished road
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.
FDE is offline   Reply With Quote

Old   March 28, 2012, 12:50
Default
  #13
New Member
 
Qin
Join Date: Feb 2012
Posts: 15
Rep Power: 6
adam14qin is on a distinguished road
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)
}
}
adam14qin is offline   Reply With Quote

Old   March 28, 2012, 16:07
Default
  #14
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 739
Blog Entries: 1
Rep Power: 15
Amir is on a distinguished road
Quote:
Originally Posted by adam14qin View Post
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,
__________________
Amir
Amir is offline   Reply With Quote

Old   March 29, 2012, 05:42
Default
  #15
New Member
 
Qin
Join Date: Feb 2012
Posts: 15
Rep Power: 6
adam14qin is on a distinguished road
Quote:
Originally Posted by Amir View Post
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 is offline   Reply With Quote

Old   May 8, 2012, 09:10
Default
  #16
New Member
 
Qin
Join Date: Feb 2012
Posts: 15
Rep Power: 6
adam14qin is on a distinguished road
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
adam14qin is offline   Reply With Quote

Old   May 8, 2012, 14:32
Default
  #17
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 739
Blog Entries: 1
Rep Power: 15
Amir is on a distinguished road
Quote:
Originally Posted by adam14qin View Post
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,
__________________
Amir
Amir is offline   Reply With Quote

Old   May 9, 2012, 01:12
Default
  #18
New Member
 
Qin
Join Date: Feb 2012
Posts: 15
Rep Power: 6
adam14qin is on a distinguished road
Quote:
Originally Posted by Amir View Post
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 is offline   Reply With Quote

Old   May 27, 2012, 14:09
Default
  #19
New Member
 
Qin
Join Date: Feb 2012
Posts: 15
Rep Power: 6
adam14qin is on a distinguished road
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
adam14qin is offline   Reply With Quote

Old   October 30, 2012, 12:46
Default Mhd
  #20
Member
 
payamfadaei
Join Date: Oct 2012
Location: Mashhad/Iran
Posts: 32
Rep Power: 5
Payam89 is on a distinguished road
Send a message via Skype™ to Payam89
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.....
Payam89 is offline   Reply With Quote

Reply

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
UDF for body force in DPM elah599 Fluent UDF and Scheme Programming 52 June 17, 2012 07:38
Step-by-Step Procedure for DPM body force wwt650420 FLUENT 8 January 6, 2012 21:06
Force can not converge colopolo CFX 13 October 4, 2011 22:03
DPM Body Force Sandilya Garimella FLUENT 1 April 8, 2008 03:30
DPM body force Doubt Sandilya FLUENT 0 May 21, 2007 13:32


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