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*E1/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_r1)/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 1e6s. 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~:) 
Dear Adam,
There are few suggestions:

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 (1e7s) 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? 
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, 
Quote:
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 definesource macros for both the radical and axial momentum equations? 2. For the stress I need to express in definesource, 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~ 
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, 
Quote:

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,"Efield"); Set_User_Memory_Name(1,"Phisource"); 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 (UDS0) to equal E_x (UDS1) and E_y (UDS2), 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 
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, 
Quote:
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*E1/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.85e12 #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~ 
Quote:
First of all, notice that dS[eqn] is the derivation of source term respect to xdirection velocity component! and also you've used "o" instead of "0" in this equation. Bests, 
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. 
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.85e12 #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*(epsilon1)/0.00002*sin(angle); pstress_y = 0.5*pow(C_UDMI(c,t,0),2)*epsilon_0*(epsilon1)/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) } } 
Quote:
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, 
Quote:
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 
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 
Quote:
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, 
Quote:
Regards, Qin Hao 
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 
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/SX ) 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.....:( 
All times are GMT 4. The time now is 19:14. 