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

UDF resulting in slower temperature and mass source the more cores i use

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 27, 2023, 10:19
Default UDF resulting in slower temperature and mass source the more cores i use
  #1
New Member
 
Join Date: Jan 2023
Posts: 2
Rep Power: 0
tavinho12345 is on a distinguished road
Hello,

My energy and mass source descibed by my UDF bellow has the porblem described in the title which is a slower heating up and masss creation process the more cores i use. And i cannot discover what is wrong with my paralelization code.

I am modelling the heat up process of a cylinder and alpha is reaction degree and dalpha is the reaction rate.

#include "udf.h"
#include <math.h>
real dalpha;
real alpha;
real m_source;
real e_source;
real T_cell;
real dalpha1;
real dalpha2;
real dalpha3;
real dalpha4;
real n;


DEFINE_INIT(start_alpha, d)
{
alpha = 0;
dalpha = 0;
T_cell = 430;
n = 0;

int ID = 65; /*this is the ID of the face that I want to get the temperature from*/
Thread *t;
cell_t c;
int zone_ID;

t = Lookup_Thread(d, ID);

#if !RP_HOST
begin_c_loop_int(c, t)
{
C_UDMI(c, t, 0) = 0;
C_UDMI(c, t, 1) = 0;

}
end_c_loop_int(c, t)
#endif

#if RP_HOST

Message("degree of conversion: %g\n", alpha);
Message("rate of conversion : %g\n", dalpha);


#endif
}


DEFINE_ADJUST(STORE_DALPHA, d)
{
/*Domain *d;*/


#if !RP_HOST /* Compile this section for computing processes only (serial
and node) since these variables are not available
on the host */


int ID = 65; /*this is the ID of the face that I want to get the temperature from*/
Thread *t;
cell_t c;

int zone_ID;
t = Lookup_Thread(d, ID);

begin_c_loop_int(c, t)
{
C_UDMI(c, t, 0) = alpha;
C_UDMI(c, t, 1) = dalpha;
}
end_c_loop_int(c, t)

#endif

}




DEFINE_ON_DEMAND(alpha_correction)
{
/*data recovery*/



alpha = 0.00580686;
dalpha = 0.000646044;



#if RP_HOST

Message("degree of conversion: %g\n", alpha);
Message("rate of conversion : %g\n", dalpha);

#endif

}



DEFINE_EXECUTE_AT_END(iterate_alpha)
{

#if !RP_HOST /* Compile this section for computing processes only (serial
and node) since these variables are not available
on the host */

int ID = 65; /*this is the ID of the cell region that I want to get the temperature from*/
Thread *t;
Domain *d;
cell_t c;

real temper = 0.0;
real totvol = 0.0;
real dT_cell;
real al1;
real al2;
real al3;
real al4;
real T1;
real T2;
real T3;
real T4;
real dT2;
real dT3;
real dT4;
real time;


d = Get_Domain(1);

int zone_ID;

t = Lookup_Thread(d, ID);

PRF_GSYNC()

begin_c_loop_int(c, t)
{
totvol += C_VOLUME(c, t);
temper += C_T(c, t)*C_VOLUME(c, t);
}
end_c_loop_int(c, t)

PRF_GSYNC()

totvol = PRF_GRSUM1(totvol);
temper = PRF_GRSUM1(temper);
T_cell = temper / totvol;

time = CURRENT_TIMESTEP;

#endif


#if !RP_HOST

/*K1 e L1*/
dalpha1 = pow((1 - alpha), (0.25))*5.76e18 * exp(-1.83e5 / (8.314 * T_cell))*exp(-27.5*(alpha));

dT_cell = (1960000000 * dalpha1) / (2750 * 1000);

al1 = alpha + dalpha1*0.5*time;

T1 = T_cell + dT_cell*0.5*time;

/*K2 e L2*/

dalpha2 = pow((1 - al1), (0.25))*5.76e18 * exp(-1.83e5 / (8.314 * T1))*exp(-27.5*(al1));

dT2 = (1960000000 * dalpha2) / (2750 * 1000);

al2 = alpha + dalpha2*0.5*time;

T2 = T_cell + dT2*0.5*time;

/*K3 e L3*/

dalpha3 = pow((1 - al2), (0.25))*5.76e18 * exp(-1.83e5 / (8.314 * T2))*exp(-27.5*(al2));

dT3 = (1960000000 * dalpha3) / (2750 * 1000);

al3 = alpha + dalpha3*time;

T3 = T_cell + dT3*time;

/*K4 e L4*/

dalpha4 = pow((1 - al3), (0.25))*5.76e18 * exp(-1.83e5 / (8.314 * T3))*exp(-27.5*(al3));

dT4 = (1960000000 * dalpha4) / (2750 * 1000);

al4 = alpha + dalpha4*time;

T4 = T_cell + dT4*time;

PRF_GSYNC()

dalpha = (dalpha1 + 2 * (dalpha2 + dalpha3) + dalpha4) / 6;

dalpha = PRF_GRHIGH1(dalpha);

if (dalpha>0.35)
{
dalpha = 0.35;
}


alpha += dalpha*time;

alpha = PRF_GRHIGH1(alpha);

PRF_GSYNC()
#endif

node_to_host_real_3(T_cell, alpha, dalpha);

#if RP_HOST

Message("temp = %g\n", T_cell);
Message("degree of conversion: %g\n", alpha);
Message("rate of conversion : %g\n", dalpha);
Message("massource = %g\n", m_source);
Message("energysource = %g\n", e_source);


#endif

n = 0;

PRF_GSYNC()

host_to_node_real_2(alpha, dalpha);

}


DEFINE_SOURCE(heat_source, c, t, dS, eqn)
{


real x[ND_ND];
C_CENTROID(x, c, t);
dS[eqn] = 0;
e_source = 1.96e9 * dalpha;


return e_source;


}

DEFINE_SOURCE(mass_source, c, t, dS, eqn)
{


real x[ND_ND];
C_CENTROID(x, c, t);
dS[eqn] = 0;
m_source = 0.436e3 * dalpha;


if (n < 1) {
Message("mass-source = %g\n", m_source);
n += 1;
}


return m_source;

}
tavinho12345 is offline   Reply With Quote

Old   March 6, 2023, 12:06
Default
  #2
New Member
 
Join Date: Jan 2023
Posts: 2
Rep Power: 0
tavinho12345 is on a distinguished road
I have solved my problem even though the solution is still confusing.
If i make the convergence criteria stricter, the source terms come back to normal due to the extra iterations.

But still, the number of processors should not intefere with the results of the simulation


Anyway if anyone is having a similar trouble that is how i solved my case
tavinho12345 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
Error message: Insufficient Catalogue Size Paresh Jain CFX 33 August 16, 2024 06:09
Specify Temperature of Inflowing Mass Source JeffAnon OpenFOAM Running, Solving & CFD 1 September 1, 2018 12:04
Ansys CFX problem: unexpected very high temperatures in premix laminar combustion faizan_habib7 CFX 4 February 1, 2016 18:00
Issues with mass source macros in a multiphase system cp703 Fluent UDF and Scheme Programming 6 October 17, 2015 01:59
Water subcooled boiling Attesz CFX 7 January 5, 2013 04:32


All times are GMT -4. The time now is 14:48.