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

UDF: trying to implement a Kinetic Equation source term

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 23, 2013, 02:57
Default
  #21
Senior Member
 
Vaze
Join Date: Jun 2009
Posts: 172
Rep Power: 17
mvee is on a distinguished road
Yes possible, but why do you require to use adjust macro. You can directly store some variable into memory in unsteady macro itself.
mvee is offline   Reply With Quote

Old   May 23, 2013, 03:19
Default
  #22
Member
 
Shashank
Join Date: Apr 2011
Posts: 74
Rep Power: 15
shashank312 is on a distinguished road
Thanks Mahesh. I am calculating all UDMs in the adjust macro. Just wanted to know if one of them can be directly plugged in as the explicit term of the unsteady uds term.

Also one more question: I am trying to use the implicit part of the same uds to calculate one of the other UDMs. That specific UDM is hooked as a mass source term in the "vapor" phase of a VOF model. Can this be possible? All I am aware of is that the VOF equation is calculated first (which will require the vapor phase source term) and the uds equation is calculated at the last, so the coupling cannot be done if a segregated solver is used. What's your stance?
shashank312 is offline   Reply With Quote

Old   May 23, 2013, 08:55
Default
  #23
Senior Member
 
Vaze
Join Date: Jun 2009
Posts: 172
Rep Power: 17
mvee is on a distinguished road
It is possible to store all UDM through adjust macro. Do this for few iteration and check contours it it meets your expectation.
This coupling is possible. You have to be cautious about under relaxation and type of discretization scheme.

Best wishes
Mvee
mvee is offline   Reply With Quote

Old   May 23, 2013, 13:55
Default
  #24
Member
 
Shashank
Join Date: Apr 2011
Posts: 74
Rep Power: 15
shashank312 is on a distinguished road
Speaking of coupling and under relaxation factors, I have been having x-momentum divergence while running this same code. I know that in a segregated solver, first adjust macro is run, and then Fluent calculates the x-momentum equation. Divergence at this point would indicate I am doing something wrong in the adjust macro?
shashank312 is offline   Reply With Quote

Old   June 15, 2015, 16:22
Default
  #25
New Member
 
Subham Mishra
Join Date: Jun 2015
Posts: 2
Rep Power: 0
subham is on a distinguished road
hello people!!
I am working on mhd module of fluent for the simulation of m.r. fluid in magnetic field. I am facing problem in writing the udf for the magnetic body force that can be applied to the whole fluid. Also, if i am specifying any value of flux density in mhd module, how that value will be stored in the variable used for flux density in the udf.
Please help. Thanking in advance,

Subham
subham is offline   Reply With Quote

Old   June 22, 2015, 08:31
Default
  #26
Senior Member
 
Vaze
Join Date: Jun 2009
Posts: 172
Rep Power: 17
mvee is on a distinguished road
Dear Shashank

Yes, It can be possible to use UDM values. Please keep remind that you will have only cell centered values of UDM, no face values.

Best wishes
Mvee
mvee is offline   Reply With Quote

Old   June 26, 2015, 15:49
Default udf to incorporate body force in mhd module
  #27
New Member
 
Subham Mishra
Join Date: Jun 2015
Posts: 2
Rep Power: 0
subham is on a distinguished road
I actually want to apply a magnetic field on a moving magnetic fluid. We have to couple the fluid flow and the mhd model. For this , we need to incorporate a body force which we have to give through udf. The formula is as follows:

F(x) = (m*s*B(x)*(dB(x)/dx))/U
Where F(x) is the force, m is the mass of fluid, B(x) is the magnetic field strength, U is the permeability of the free space.

As the magnetic field strength will vary at every x position, how to incorporate that in the udf and how to access the value of magnetic field in the udf?

The code which we have written is as follows:

#include "udf.h"
DEFINE_DPM_BODY_FORCE(mhd_dpm_force,p,i)
/* This file needs to be "interpreted" in FLUENT before it can be used */
{
face_t f;
Thread *t;
real b_force=0;
if(i==1)
{
b_force=0.00833*1800/(4*3.14*(10^-7)*4)*F_UDSI(f,t,1)*F_UDSI_G(f,t,1);
}
return b_force;
}


please help..
subham is offline   Reply With Quote

Old   June 29, 2015, 01:06
Default
  #28
Senior Member
 
Vaze
Join Date: Jun 2009
Posts: 172
Rep Power: 17
mvee is on a distinguished road
F_UDSI_G(f,t,1) wont work. Gradient would be used on cell centered values not face values. In order to use it use adjacent cell values.
You can incorporate following in your code. For more help on it use help manual.

c0 = F_CO(),
t0 =THREAD_T0()
C_UDSI_G(c0,t0,<index of UDS>)[0]
mvee is offline   Reply With Quote

Old   June 29, 2015, 01:08
Default
  #29
Senior Member
 
Vaze
Join Date: Jun 2009
Posts: 172
Rep Power: 17
mvee is on a distinguished road
Do you want to use dBx/dx on boundaries? if yes then only use above macro otherwise you can directly use C_UDSI_G()[0]
mvee is offline   Reply With Quote

Old   March 6, 2017, 19:22
Default
  #30
ZKR
New Member
 
Zakaria AOUCHETTE
Join Date: Feb 2017
Posts: 2
Rep Power: 0
ZKR is on a distinguished road
hi, i'm working with the same case, i have trouble with creating UDF, please how to create it?
ZKR is offline   Reply With Quote

Old   March 7, 2017, 11:53
Default
  #31
Member
 
Rosario Arnau
Join Date: Feb 2017
Location: Spain
Posts: 57
Rep Power: 9
rarnaunot is on a distinguished road
Quote:
Originally Posted by ZKR View Post
hi, i'm working with the same case, i have trouble with creating UDF, please how to create it?
Hi!

I'm also new on these UDF Fluent functions but I am writing my UDF in Microsoft Visual Studio cause it is also the Fluent Compiler...

Hope I could help u....
rarnaunot is offline   Reply With Quote

Old   March 7, 2017, 11:58
Default
  #32
Member
 
Rosario Arnau
Join Date: Feb 2017
Location: Spain
Posts: 57
Rep Power: 9
rarnaunot is on a distinguished road
Quote:
Originally Posted by er.mkumar View Post
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;
	
}
Hi!

I want to now why do you mix here UDS and UDM. Is it to save in memory the value of the UDS?? Still not familiar with the difference between UDS and UDM....


DEFINE_SOURCE(uds_source,c,t,ds,eqn)
{
blablablah


C_UDMI(c,t,2)=rate;
rarnaunot is offline   Reply With Quote

Old   April 20, 2017, 11:55
Default Solved
  #33
Member
 
Rosario Arnau
Join Date: Feb 2017
Location: Spain
Posts: 57
Rep Power: 9
rarnaunot is on a distinguished road
Solved!!

Quote:
Originally Posted by rarnaunot View Post
Hi!

I want to now why do you mix here UDS and UDM. Is it to save in memory the value of the UDS?? Still not familiar with the difference between UDS and UDM....


DEFINE_SOURCE(uds_source,c,t,ds,eqn)
{
blablablah


C_UDMI(c,t,2)=rate;
rarnaunot is offline   Reply With Quote

Old   March 21, 2019, 05:36
Default problem regarding coupling
  #34
Member
 
Join Date: Oct 2017
Posts: 52
Rep Power: 9
gouravjee is on a distinguished road
Quote:
Originally Posted by rarnaunot View Post
Solved!!
HII ALL,
I have been trying to simulate heat transfer problem from liquid to solid. i have successfully run the UDS transport equation for above problem but when i add an additional to the above equation it does not show coupling. can you suggest me where might be the problem??

Thanks
gouravjee is offline   Reply With Quote

Old   March 22, 2019, 05:00
Default
  #35
Senior Member
 
Vaze
Join Date: Jun 2009
Posts: 172
Rep Power: 17
mvee is on a distinguished road
Hi Gourav

Please write more about your problem and share your UDF, then only one can suggest.

Best wishes
mvee
mvee is offline   Reply With Quote

Old   March 22, 2019, 11:20
Default problem regarding coupling
  #36
Member
 
Join Date: Oct 2017
Posts: 52
Rep Power: 9
gouravjee is on a distinguished road
Quote:
Originally Posted by mvee View Post
Hi Gourav

Please write more about your problem and share your UDF, then only one can suggest.

Best wishes
mvee
Code:
#include "udf.h"
#include "sg_mem.h"
#include "math.h"

#define solid_specific_heat 1980 /* Specific heat in J/kg.K */
#define liquid_specific_heat 1980 /* Specific heat in J/kg.K */
DEFINE_SOURCE(myfunction, c, t, dS, eqn)
{
real pos[ND_ND]; /* this will hold the position vector */
real y ;
real x ;
real lfrac ; 
real specific_heat ;
//real h ;
real r ;
real source ;
int zone_ID = THREAD_ID(t);
     

begin_c_loop(c,t)
{
C_CENTROID(pos,c,t);
x = pos[0]; 
y = pos[1];
r = sqrt(pow(x,2) + pow(y,2));
     if(zone_ID == 4)
     {
		    C_UDMI(c,t,5) = C_UDSI(c,t,0);
	  }
	  lfrac = C_UDMI(c,t,2);
specific_heat = (lfrac*liquid_specific_heat)+((1-lfrac)*solid_specific_heat);
source = -(2*(10)*(C_UDMI(c,t,5)-C_UDSI(c,t,0)))/(r*specific_heat); 
dS[eqn] = 0.0;

}
end_c_loop(c,t)
     
return source ;
}
To be more precise,
I have been solving a scalar transport equation for analyzing heat transfer in a heat exchanger and for that i need to add this additional source term to the equation for the fluid(being heated by hot fluid).
Problem :"if i solve my equaiton without this term it works fine but when i add it to the equation coupling between solid and fluid interface stops occuring and i am not able to find any reason behind this problem "

[EQUATION]
source = 2*(h/r)*(T_fluid_interface - T_fluid_cell)
[/EQUATION]
gouravjee is offline   Reply With Quote

Reply


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 Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 18:56.