CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   UDF: trying to implement a Kinetic Equation source term (https://www.cfd-online.com/Forums/fluent-udf/107568-udf-trying-implement-kinetic-equation-source-term.html)

 er.mkumar October 1, 2012 09:44

UDF: trying to implement a Kinetic Equation source term

Hello All,

kindly help in writing a UDF for the the equation in the picture.

Regards,
Mukesh

It is time consuming.

 mvee October 4, 2012 01:55

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

 er.mkumar October 4, 2012 08:35

Help required in post processing

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;         }

 mvee October 5, 2012 00:26

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

 er.mkumar October 5, 2012 02:28

Quote:
 Originally Posted by mvee (Post 385005) 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
Dear Mahesh,

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.

Regards,
mukesh

 mvee October 5, 2012 07:36

You are right - "But there is an option in plotting UDS-0 (in post processing panel) which I feel is same as 'x' what exactly I need."

But this is required to have control over 'x' and to update the value of 'x' as =f(x). IS that correct?

 er.mkumar October 5, 2012 08:28

Quote:
 Originally Posted by mvee (Post 385067) You are right - "But there is an option in plotting UDS-0 (in post processing panel) which I feel is same as 'x' what exactly I need." But this is required to have control over 'x' and to update the value of 'x' as =f(x). IS that correct?
Dear Mahesh,

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

 mvee October 6, 2012 00:14

if you are talking from location point of view (for monitoring) then you will have to use mark option adapt tab.

 er.mkumar October 6, 2012 15:21

Quote:
 Originally Posted by mvee (Post 385168) if you are talking from location point of view (for monitoring) then you will have to use mark option adapt tab.
Dear Mahesh,

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

 mvee October 8, 2012 00:06

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

 er.mkumar October 11, 2012 12:43

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

 mvee October 11, 2012 23:24

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

 Payam89 October 15, 2012 12:46

MHD program

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

 mvee October 16, 2012 23:54

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!

 Payam89 October 27, 2012 14:13

Mhd

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
}

 mvee November 6, 2012 04:32

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.

 Payam89 November 6, 2012 12:25

Electric Field

Quote:
 Originally Posted by mvee (Post 390503) 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.
I have an electric field which it's function is E=Q/2pie0(1/x +1/s-x) .I don't know how should i write it in mhd:(

 mvee November 9, 2012 02:23

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.

 shashank312 May 22, 2013 18:16

Mahesh,

Could you use a UDM calculated in DEFINE_ADJUST and use it as the "explicit" value in DEFINE_UDS_UNSTEADY?

Thanks,
Shashank

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