
[Sponsors] 
October 1, 2012, 09:44 
UDF: trying to implement a Kinetic Equation source term

#1 
New Member
Mukesh
Join Date: Sep 2012
Posts: 28
Rep Power: 7 
Hello All,
kindly help in writing a UDF for the the equation in the picture. Regards, Mukesh Last edited by er.mkumar; November 12, 2012 at 04:52. 

October 3, 2012, 04:43 

#2 
Member
Join Date: Mar 2011
Posts: 64
Rep Power: 8 
It is time consuming.
__________________
Saeed Sadeghi Ansys Fluent CFD Consultant 

October 4, 2012, 01:55 

#3 
Senior Member
Vaze
Join Date: Jun 2009
Posts: 155
Rep Power: 10 
Dear er.mkumar
You start writing your code. If you stuck in between raise your thread, you will get help from forum. Best wishes Mvee 

October 4, 2012, 08:35 
Help required in post processing

#4 
New Member
Mukesh
Join Date: Sep 2012
Posts: 28
Rep Power: 7 
I tried to write the code, here it is. Problem is I am not getting the exact results I expect (may be some numerical values need change).
Also I want to track both Temperature (K) and Concentration ratio H/M (x) with flow time. While tracking temperature is simple from solve/monitors/volume integral... I'm yet to figure out how to track concentration(x) (a) with time and (B) spatially as contour (I mean how to plot variation of x in different section of domain( i.e. 05 mm, 510 mm, 1015 mm....) with distance both radially and axially. FINALLY: Is there any MACRO using which FLUENT stops executing the UDF once 'x' reaches its upper limit. Awaiting guidance on the subject. Code:
#include"udf.h" /* Input Boundary Conditions */ #define T_i 300.0 /* Inlet temp in K */ #define T_f 298.0 /* Coolant fluid temp in Kelvin [K] */ #define P_i 20e5 /* Inlet pressure in pascals */ #define h_o 1000 /* Heat transfer coeff in W/m^2K */ #define x_i 0 /* Initial value of H/M for reaction to START */ #define x_f 1.0 /* Final value of H/M for reaction to STOP @ saturation */ /* Properties of Misc Metal */ #define rho_m 8400 /* Density in kg/m^3 */ #define C_pm 419 /* Sp heat in J/kgK */ #define K_m 1.6 /* Thermal conductivity in W/mK */ #define por 0.5 /* Porosity */ #define rho_ss 8518 /* Density of MH @ saturation kg/m^3 */ #define rho_s 8400 /* Density of MH kg/m^3 */ #define E_a 21170 /* Activation energy in J/mol H2 */ #define per 1e8 /* Permeability */ #define DELTA_S 107.2 /* Entropy of Formation J/mol H2K */ #define DELTA_H 28000 /* Enthalpy of Formation J/mol H2 */ /* Properties of Hydrogen */ #define K_g 0.1272 /* Thermal Conductivity in W/mK */ #define C_pg 14283 /* Sp heat in J/kgK */ #define rho_g 0.0838 /* Density in kg/m^3 */ #define M_g 2.0158e3 /* Molecular weight in kg/mol */ /* CONSTANTS */ #define R_u 8.314 /* Universal gas Constant J/molK */ #define k_a 75 /* Reaction Constant for absorption in (sec)^1 */ /* Initialization of cell property */ DEFINE_INIT(my_init_fuc,d) { cell_t c; Thread*t; thread_loop_c(t,d) { begin_c_loop_all(c,t) { C_UDSI(c,t,0)= 0; } end_c_loop_all(c,t) } } /* Energy Equation HEAT SOURCE term */ DEFINE_SOURCE(heat_generation,c,t,ds,eqn) { real q_a; real physical_dt; physical_dt = RP_Get_Real("physicaltimestep"); q_a= rho_m*(1por)*(DELTA_H/M_g)*(C_UDSI(c,t,0)C_UDSI_M1(c,t,0))/physical_dt; C_UDMI(c,t,0)=q_a; return q_a; } /* UDS for solving Kinetic equation i.e. dx/dt eqn */ DEFINE_UDS_UNSTEADY(uds_time,c,t,i,apu,su) { real physical_dt; real vol; real rho; real phi_old; physical_dt = RP_Get_Real("physicaltimestep"); vol = C_VOLUME(c,t); rho = 1; *apu = rho*vol/physical_dt; phi_old = C_STORAGE_R(c,t,SV_UDSI_M1(0)); *su = rho*vol*phi_old/physical_dt; } /* Kinetic Equation SOURCE term */ /* Convection & Diffusion part are zero */ DEFINE_SOURCE(uds_source,c,t,ds,eqn) { real tp; real rate; real P_eq; real cond; real x_now; tp = C_T(c,t); P_eq = pow(2.72,((DELTA_S/R_u)(DELTA_H/(R_u*tp))))*pow(10,5); cond = (P_iP_eq)/P_eq; if(cond>0) rate = k_a*pow(2.72,(E_a/(R_u*tp)))*((P_iP_eq)/P_eq)*((C_UDSI_M1(c,t,0)  x_f)/(x_i  x_f)); else rate = 0; C_UDMI(c,t,2)=rate; return rate; } 

October 5, 2012, 00:26 

#5 
Senior Member
Vaze
Join Date: Jun 2009
Posts: 155
Rep Power: 10 
Hi
I have not thoroughly checked your UDF but looking to the equations you should follow following steps: 1. define UDS with only unsteady term. 2. unsteady term = source term 3. solving step 2, you will get updated value of x which you overwrite and store in user memory for post processing and termination process (limiting value of x). 4. solve energy source term and p_eq Quick scanning of your UDF revealed: have you properly implemented all the equations of your interest? Please check this. Once all values stored in memory you can have monitor points to observe their variations. Best wishes 

October 5, 2012, 02:28 

#6  
New Member
Mukesh
Join Date: Sep 2012
Posts: 28
Rep Power: 7 
Quote:
Thank You very much for your reply. I have done exactly what you have mentioned in steps 1,2 & 4. Regarding step 3, I believe you mean to say to use UDMI like C_UDMI(c,t,i) = C_UDMI(c,t,i) + rate * CURRENT_TIMESTEP; in the UDS source . But there is an option in plotting UDS0 (in post processing panel) which I feel is same as 'x' what exactly I need. Awaiting your guidance. Regards, mukesh 

October 5, 2012, 07:36 

#7 
Senior Member
Vaze
Join Date: Jun 2009
Posts: 155
Rep Power: 10 

October 5, 2012, 08:28 

#8  
New Member
Mukesh
Join Date: Sep 2012
Posts: 28
Rep Power: 7 
Quote:
That's exactly is the form of my scalar equation if you see the picture I posted as my problem statement. Thanks for clarification. But I'm still in darkness how to plot these variations in particular regions (i.e. 05 mm, 510 mm, 1015 mm......) both radially and axially. I mean the monitors do give average value (volume avg, mass avg methods) in the entire domain but what I need is the avg values in small sections (radially and axially) of 5 mm each (say). Thanks ! Mukesh 

October 6, 2012, 00:14 

#9 
Senior Member
Vaze
Join Date: Jun 2009
Posts: 155
Rep Power: 10 
if you are talking from location point of view (for monitoring) then you will have to use mark option adapt tab.


October 6, 2012, 15:21 

#10  
New Member
Mukesh
Join Date: Sep 2012
Posts: 28
Rep Power: 7 
Quote:
Thanks for that clue. I did went through the Aapt/mark ....option; But even after reading the manual I could not use that option for my need. It basically talked about registers(regions marked for coarsening/refining). Manipulation part was not clear. Had there been an example things would have been easier. I wish if you could explain little bit on that. Regards, Mukesh 

October 8, 2012, 00:06 

#11 
Senior Member
Vaze
Join Date: Jun 2009
Posts: 155
Rep Power: 10 
Hi Mukesh
No need to adapt as it coarsen/refine your mesh, only perform mark option. this will mark the number of cells in the region of your choice. Good luck Mvee 

October 11, 2012, 12:43 

#12 
New Member
Mukesh
Join Date: Sep 2012
Posts: 28
Rep Power: 7 
Thanks Mvee, got it. But the marked registers are not available as separate regions for plotting contours or property plot [transient].
I'm sure something is missing on my part but couldnot figure it out. Regards, Mukesh 

October 11, 2012, 23:24 

#13 
Senior Member
Vaze
Join Date: Jun 2009
Posts: 155
Rep Power: 10 
I believe adapt option is only for monitoring / initialization / specific properties. You may post process based on the marked field. In that case you can have iso contours and other surface contours.
Best wishes Mvee 

October 15, 2012, 12:46 
MHD program

#14 
Member

hello my dear!
I have a magnetic field in my flow and I read a lot of MHD tutorials but I am not able that in which format I should write this in c/c++ ....please if you have a similar c program me help. regards 

October 16, 2012, 23:54 

#15 
Senior Member
Vaze
Join Date: Jun 2009
Posts: 155
Rep Power: 10 
All the UDF codes are in C language with the known functions defined specifically for certain types of operations.
Please go through the UDF basics! 

October 27, 2012, 14:13 
Mhd

#16 
Member

I have write it.but i don't know what i am doing?
#include "udf.h" #define Q 1.0; #define e0 1.0; #define er 3.0; #define pi 3.14159; #define s 0.0187; DEFINE_SOURCE(mhd_phi_source,c,t,eqn) { eqn = (Q/(2*pi*e0))*((1/x)+(1/(sx))); printf(eqn) return } 

November 6, 2012, 04:32 

#17 
Senior Member
Vaze
Join Date: Jun 2009
Posts: 155
Rep Power: 10 
This represent volume source which goes in energy eq. This source is a function of spatial coordinate (x axis) while other variables seem to be constants.


November 6, 2012, 12:25 
Electric Field

#18 
Member

I have an electric field which it's function is E=Q/2pie0(1/x +1/sx) .I don't know how should i write it in mhd


November 9, 2012, 02:23 

#19 
Senior Member
Vaze
Join Date: Jun 2009
Posts: 155
Rep Power: 10 
You have to search in UDF manual and header file udf.h. udf.h will give you the function name and required definition of parameters.


May 22, 2013, 18:16 

#20 
Member
Shashank
Join Date: Apr 2011
Posts: 74
Rep Power: 8 
Mahesh,
Could you use a UDM calculated in DEFINE_ADJUST and use it as the "explicit" value in DEFINE_UDS_UNSTEADY? Thanks, Shashank 

Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
what is swap4foam ??  AB08  OpenFOAM  28  February 2, 2016 02:22 
Adding solvers from DensityBasedTurbo to foamextend 3.0  Seroga  OpenFOAM Installation  9  June 12, 2015 17:18 
centOS 5.6 : paraFoam not working  yossi  OpenFOAM Installation  2  October 9, 2013 01:41 
UDF source term  Rajani Kanth.B  Fluent UDF and Scheme Programming  4  May 1, 2013 09:31 
UDF Scalar Code: HT 1  Greg Perkins  FLUENT  8  October 20, 2000 12:40 