CFD Online Discussion Forums

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)

mvee May 23, 2013 01:57

Yes possible, but why do you require to use adjust macro. You can directly store some variable into memory in unsteady macro itself.

shashank312 May 23, 2013 02:19

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?

mvee May 23, 2013 07:55

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

shashank312 May 23, 2013 12:55

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?

subham June 15, 2015 15:22

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

mvee June 22, 2015 07:31

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

subham June 26, 2015 14:49

udf to incorporate body force in mhd module
 
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..

mvee June 29, 2015 00:06

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 June 29, 2015 00:08

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]

ZKR March 6, 2017 18:22

hi, i'm working with the same case, i have trouble with creating UDF, please how to create it?

rarnaunot March 7, 2017 10:53

Quote:

Originally Posted by ZKR (Post 639734)
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 March 7, 2017 10:58

Quote:

Originally Posted by er.mkumar (Post 384908)
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 April 20, 2017 10:55

Solved
 
Solved!!:D:D:D:D

Quote:

Originally Posted by rarnaunot (Post 639840)
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;


gouravjee March 21, 2019 04:36

problem regarding coupling
 
Quote:

Originally Posted by rarnaunot (Post 645687)
Solved!!:D:D:D:D

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

mvee March 22, 2019 04:00

Hi Gourav

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

Best wishes
mvee

gouravjee March 22, 2019 10:20

problem regarding coupling
 
Quote:

Originally Posted by mvee (Post 728544)
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]


All times are GMT -4. The time now is 21:17.