CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Fluent UDF and Scheme Programming

UDF: trying to implement a Kinetic Equation source term

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

Like Tree2Likes

Reply
 
LinkBack Thread Tools Display Modes
Old   October 1, 2012, 09:44
Default UDF: trying to implement a Kinetic Equation source term
  #1
New Member
 
Mukesh
Join Date: Sep 2012
Posts: 28
Rep Power: 5
er.mkumar is on a distinguished road
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.
er.mkumar is offline   Reply With Quote

Old   October 3, 2012, 04:43
Default
  #2
Member
 
eng_s_sadeghi's Avatar
 
Join Date: Mar 2011
Posts: 64
Rep Power: 6
eng_s_sadeghi is on a distinguished road
It is time consuming.
sircorp likes this.
__________________
Saeed Sadeghi
Ansys Fluent CFD Consultant
eng_s_sadeghi is offline   Reply With Quote

Old   October 4, 2012, 01:55
Default
  #3
Senior Member
 
Vaze
Join Date: Jun 2009
Posts: 133
Rep Power: 8
mvee is on a distinguished road
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
mvee is offline   Reply With Quote

Old   October 4, 2012, 08:35
Default Help required in post processing
  #4
New Member
 
Mukesh
Join Date: Sep 2012
Posts: 28
Rep Power: 5
er.mkumar is on a distinguished road
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;
	
}
er.mkumar is offline   Reply With Quote

Old   October 5, 2012, 00:26
Default
  #5
Senior Member
 
Vaze
Join Date: Jun 2009
Posts: 133
Rep Power: 8
mvee is on a distinguished road
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
mvee is offline   Reply With Quote

Old   October 5, 2012, 02:28
Default
  #6
New Member
 
Mukesh
Join Date: Sep 2012
Posts: 28
Rep Power: 5
er.mkumar is on a distinguished road
Quote:
Originally Posted by mvee View Post
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,

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
er.mkumar is offline   Reply With Quote

Old   October 5, 2012, 07:36
Default
  #7
Senior Member
 
Vaze
Join Date: Jun 2009
Posts: 133
Rep Power: 8
mvee is on a distinguished road
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 \frac{\partial x}{\partial t}=f(x). IS that correct?
mvee is offline   Reply With Quote

Old   October 5, 2012, 08:28
Default
  #8
New Member
 
Mukesh
Join Date: Sep 2012
Posts: 28
Rep Power: 5
er.mkumar is on a distinguished road
Quote:
Originally Posted by mvee View Post
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 \frac{\partial x}{\partial t}=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
er.mkumar is offline   Reply With Quote

Old   October 6, 2012, 00:14
Default
  #9
Senior Member
 
Vaze
Join Date: Jun 2009
Posts: 133
Rep Power: 8
mvee is on a distinguished road
if you are talking from location point of view (for monitoring) then you will have to use mark option adapt tab.
mvee is offline   Reply With Quote

Old   October 6, 2012, 15:21
Default
  #10
New Member
 
Mukesh
Join Date: Sep 2012
Posts: 28
Rep Power: 5
er.mkumar is on a distinguished road
Quote:
Originally Posted by mvee View Post
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
er.mkumar is offline   Reply With Quote

Old   October 8, 2012, 00:06
Default
  #11
Senior Member
 
Vaze
Join Date: Jun 2009
Posts: 133
Rep Power: 8
mvee is on a distinguished road
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
mvee is offline   Reply With Quote

Old   October 11, 2012, 12:43
Default
  #12
New Member
 
Mukesh
Join Date: Sep 2012
Posts: 28
Rep Power: 5
er.mkumar is on a distinguished road
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
er.mkumar is offline   Reply With Quote

Old   October 11, 2012, 23:24
Default
  #13
Senior Member
 
Vaze
Join Date: Jun 2009
Posts: 133
Rep Power: 8
mvee is on a distinguished road
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
mvee is offline   Reply With Quote

Old   October 15, 2012, 12:46
Default MHD program
  #14
Member
 
payamfadaei
Join Date: Oct 2012
Location: Mashhad/Iran
Posts: 32
Rep Power: 4
Payam89 is on a distinguished road
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
Payam89 is offline   Reply With Quote

Old   October 16, 2012, 23:54
Default
  #15
Senior Member
 
Vaze
Join Date: Jun 2009
Posts: 133
Rep Power: 8
mvee is on a distinguished road
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 likes this.
mvee is offline   Reply With Quote

Old   October 27, 2012, 14:13
Default Mhd
  #16
Member
 
payamfadaei
Join Date: Oct 2012
Location: Mashhad/Iran
Posts: 32
Rep Power: 4
Payam89 is on a distinguished road
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
}
Payam89 is offline   Reply With Quote

Old   November 6, 2012, 04:32
Default
  #17
Senior Member
 
Vaze
Join Date: Jun 2009
Posts: 133
Rep Power: 8
mvee is on a distinguished road
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.
mvee is offline   Reply With Quote

Old   November 6, 2012, 12:25
Default Electric Field
  #18
Member
 
payamfadaei
Join Date: Oct 2012
Location: Mashhad/Iran
Posts: 32
Rep Power: 4
Payam89 is on a distinguished road
Quote:
Originally Posted by mvee View Post
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
Payam89 is offline   Reply With Quote

Old   November 9, 2012, 02:23
Default
  #19
Senior Member
 
Vaze
Join Date: Jun 2009
Posts: 133
Rep Power: 8
mvee is on a distinguished road
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.
mvee is offline   Reply With Quote

Old   May 22, 2013, 18:16
Default
  #20
Member
 
Shashank
Join Date: Apr 2011
Posts: 70
Rep Power: 6
shashank312 is on a distinguished road
Mahesh,

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

Thanks,
Shashank
shashank312 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
Adding solvers from DensityBasedTurbo to foam-extend 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
what is swap4foam ?? AB08 OpenFOAM 27 July 1, 2013 09:17
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


All times are GMT -4. The time now is 03:24.