|
[Sponsors] | |||||
UDF: trying to implement a Kinetic Equation source term |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|
|
#1 |
|
New Member
Mukesh
Join Date: Sep 2012
Posts: 28
Rep Power: 15 ![]() |
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. |
|
|
|
|
|
|
|
|
#2 |
|
Member
Join Date: Mar 2011
Posts: 64
Rep Power: 16 ![]() |
It is time consuming.
__________________
Saeed Sadeghi Ansys Fluent CFD Consultant |
|
|
|
|
|
|
|
|
#3 |
|
Senior Member
Vaze
Join Date: Jun 2009
Posts: 172
Rep Power: 18 ![]() |
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 |
|
|
|
|
|
|
|
|
#4 |
|
New Member
Mukesh
Join Date: Sep 2012
Posts: 28
Rep Power: 15 ![]() |
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. 0-5 mm, 5-10 mm, 10-15 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^2-K */
#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/kg-K */
#define K_m 1.6 /* Thermal conductivity in W/m-K */
#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 1e-8 /* Permeability */
#define DELTA_S 107.2 /* Entropy of Formation J/mol H2-K */
#define DELTA_H 28000 /* Enthalpy of Formation J/mol H2 */
/* Properties of Hydrogen */
#define K_g 0.1272 /* Thermal Conductivity in W/m-K */
#define C_pg 14283 /* Sp heat in J/kg-K */
#define rho_g 0.0838 /* Density in kg/m^3 */
#define M_g 2.0158e-3 /* Molecular weight in kg/mol */
/* CONSTANTS */
#define R_u 8.314 /* Universal gas Constant J/mol-K */
#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("physical-time-step");
q_a= rho_m*(1-por)*(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("physical-time-step");
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_i-P_eq)/P_eq;
if(cond>0)
rate = k_a*pow(2.72,(-E_a/(R_u*tp)))*((P_i-P_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;
}
|
|
|
|
|
|
|
|
|
#5 |
|
Senior Member
Vaze
Join Date: Jun 2009
Posts: 172
Rep Power: 18 ![]() |
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 |
|
|
|
|
|
|
|
|
#6 | |
|
New Member
Mukesh
Join Date: Sep 2012
Posts: 28
Rep Power: 15 ![]() |
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 UDS-0 (in post processing panel) which I feel is same as 'x' what exactly I need. Awaiting your guidance. Regards, mukesh |
||
|
|
|
||
|
|
|
#7 |
|
Senior Member
Vaze
Join Date: Jun 2009
Posts: 172
Rep Power: 18 ![]() |
||
|
|
|
|
|
|
|
#8 | |
|
New Member
Mukesh
Join Date: Sep 2012
Posts: 28
Rep Power: 15 ![]() |
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. 0-5 mm, 5-10 mm, 10-15 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 |
||
|
|
|
||
|
|
|
#9 |
|
Senior Member
Vaze
Join Date: Jun 2009
Posts: 172
Rep Power: 18 ![]() |
if you are talking from location point of view (for monitoring) then you will have to use mark option adapt tab.
|
|
|
|
|
|
|
|
|
#10 | |
|
New Member
Mukesh
Join Date: Sep 2012
Posts: 28
Rep Power: 15 ![]() |
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 |
||
|
|
|
||
|
|
|
#11 |
|
Senior Member
Vaze
Join Date: Jun 2009
Posts: 172
Rep Power: 18 ![]() |
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 |
|
|
|
|
|
|
|
|
#12 |
|
New Member
Mukesh
Join Date: Sep 2012
Posts: 28
Rep Power: 15 ![]() |
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 |
|
|
|
|
|
|
|
|
#13 |
|
Senior Member
Vaze
Join Date: Jun 2009
Posts: 172
Rep Power: 18 ![]() |
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 |
|
|
|
|
|
|
|
|
#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 |
|
|
|
|
|
|
|
|
#15 |
|
Senior Member
Vaze
Join Date: Jun 2009
Posts: 172
Rep Power: 18 ![]() |
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! |
|
|
|
|
|
|
|
|
#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/(s-x))); printf(eqn) return } |
|
|
|
|
|
|
|
|
#17 |
|
Senior Member
Vaze
Join Date: Jun 2009
Posts: 172
Rep Power: 18 ![]() |
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.
|
|
|
|
|
|
|
|
|
#18 | |
|
Member
|
Quote:
|
||
|
|
|
||
|
|
|
#19 |
|
Senior Member
Vaze
Join Date: Jun 2009
Posts: 172
Rep Power: 18 ![]() |
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.
|
|
|
|
|
|
|
|
|
#20 |
|
Member
Shashank
Join Date: Apr 2011
Posts: 74
Rep Power: 16 ![]() |
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 | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| what is swap4foam ?? | AB08 | OpenFOAM | 28 | February 2, 2016 02:22 |
| [Other] Adding solvers from DensityBasedTurbo to foam-extend 3.0 | Seroga | OpenFOAM Community Contributions | 9 | June 12, 2015 18:18 |
| centOS 5.6 : paraFoam not working | yossi | OpenFOAM Installation | 2 | October 9, 2013 02:41 |
| UDF source term | Rajani Kanth.B | Fluent UDF and Scheme Programming | 4 | May 1, 2013 10:31 |
| UDF Scalar Code: HT 1 | Greg Perkins | FLUENT | 8 | October 20, 2000 13:40 |