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

UDF for mass and heat source with heat transfer

Register Blogs Community New Posts Updated Threads Search

Like Tree14Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 8, 2017, 06:03
Default
  #21
Senior Member
 
KaLium's Avatar
 
Kal-El
Join Date: Apr 2017
Location: Finland
Posts: 150
Rep Power: 9
KaLium is on a distinguished road
Quote:
Originally Posted by rajendra1 View Post
I have found rise in temperature with constant mass source input. But solution stopping after every iteration. may be I shall check the formula again. But again there is nothing stored in UDM.

I am not really sure whether I shall use DEFINE_EXECUTE_AT_END or DEFINE_ON_DEMAND. please put some light .......what I know is that former is executed at the end of time step and later in the beginning.

Can I define initial values to in C_UDMI using DEFINE_INIT macro?
DEFINE_EXECUTE_AT_END is used at the end.
DEFINE_ADJUST is used at the beginning
DEFINE_ON_DEMAND is used with manual command.

I would use a DEFINE_ON_DEMAND for initialization:

Code:
DEFINE_ON_DEMAND (udm_init)
{
  Thread *thread;
  cell_t cell;
  Node *node;
  Domain *domain = Get_Domain(1);
    
   thread_loop_c(thread,domain)
    {
      begin_c_loop(cell,thread)       
      {
      C_UDMI(cell,thread,0) = 0.0;
      C_UDMI(cell,thread,1) = 0.0;
      C_UDMI(cell,thread,2) = 0.0;
      C_UDMI(cell,thread,3) = 0.0;
      C_UDMI(cell,thread,4) = 0.0;
      }
      end_c_loop(cell,thread)

    }

}
You have to run macros like this manual: http://jullio.pe.kr/fluent6.1/help/h...-use-on-demand

You can also use fluent patch panel if you don't want to use UDF: https://www.sharcnet.ca/Software/Flu...g/node1384.htm
rajendra1 likes this.
KaLium is offline   Reply With Quote

Old   June 8, 2017, 06:22
Default
  #22
Senior Member
 
KaLium's Avatar
 
Kal-El
Join Date: Apr 2017
Location: Finland
Posts: 150
Rep Power: 9
KaLium is on a distinguished road
Quote:
Originally Posted by rajendra1 View Post
DEFINE_SOURCE(mass_source,c,t,dS,eqn)
{
dS[eqn] = C_UDMI(c,t,1);
return C_UDMI(c,t,0);
}
DEFINE_SOURCE(energy_source,c,t,dS,eqn)
{
dS[eqn] = C_UDMI(c,t,4);
return C_UDMI(c,t,3);
}
So you have non-zero mass source with this code? how is your solution stopping?
rajendra1 likes this.

Last edited by KaLium; June 8, 2017 at 09:37.
KaLium is offline   Reply With Quote

Old   June 9, 2017, 11:13
Default
  #23
New Member
 
Join Date: Jun 2017
Posts: 19
Rep Power: 9
rajendra1 is on a distinguished road
Quote:
Originally Posted by KaLium View Post
So you have non-zero mass source with this code? how is your solution stopping?
Since heat source is dependent on mass source and there is increase in temperature, so I think mass source is positive.

Thank you very much for suggestion regarding DEFINE_ON_DEMAND macro.
I have added it to my udf but again solution is stopping after every time step showing "FLUENT received fatal signal (ACCESS VIOLATION)". It proceeds if I calculate it further but only for single time step.
rajendra1 is offline   Reply With Quote

Old   June 9, 2017, 13:34
Default
  #24
Senior Member
 
KaLium's Avatar
 
Kal-El
Join Date: Apr 2017
Location: Finland
Posts: 150
Rep Power: 9
KaLium is on a distinguished road
Maybe you should replace your execute_at_end macro with adjust-macro.

Also add the thread - loop. Similar than in my define_on_demand code.
rajendra1 likes this.
KaLium is offline   Reply With Quote

Old   June 9, 2017, 15:15
Default
  #25
New Member
 
Join Date: Jun 2017
Posts: 19
Rep Power: 9
rajendra1 is on a distinguished road
Quote:
Originally Posted by KaLium View Post
Maybe you should replace your execute_at_end macro with adjust-macro.

Also add the thread - loop. Similar than in my define_on_demand code.
okay I will try it.
rajendra1 is offline   Reply With Quote

Old   June 10, 2017, 21:23
Default
  #26
New Member
 
Join Date: Jun 2017
Posts: 19
Rep Power: 9
rajendra1 is on a distinguished road
Hi KaLium,

I have finally moved forward from the error, thank you very much for your suggestions without your suggestions it would have been very difficult to move further.

I have used DEFINE_EXECUTE_AT_END, should also be possible by using DEFINE_ADJUST, I shall try it.

But again I did not find anything stored in UDM.
rajendra1 is offline   Reply With Quote

Old   June 10, 2017, 21:33
Default
  #27
New Member
 
Join Date: Jun 2017
Posts: 19
Rep Power: 9
rajendra1 is on a distinguished road
Quote:
Originally Posted by KaLium View Post
Code:
DEFINE_ON_DEMAND (udm_init)
{
  Thread *thread;
  cell_t cell;
  Node *node;
  Domain *domain = Get_Domain(1);
    
   thread_loop_c(thread,domain)
    {
      begin_c_loop(cell,thread)       
      {
      C_UDMI(cell,thread,0) = 0.0;
      C_UDMI(cell,thread,1) = 0.0;
      C_UDMI(cell,thread,2) = 0.0;
      C_UDMI(cell,thread,3) = 0.0;
      C_UDMI(cell,thread,4) = 0.0;
      }
      end_c_loop(cell,thread)
    }
}
CAN we use your suggested code in this fashion? do we need specify node?

DEFINE_ON_DEMAND (udm_init)
{
real x[ND_ND];
Thread *thread;
cell_t cell;
//Node *node;
int zone = 3;
Domain *domain = Get_Domain(1);
thread =Lookup_Thread(domain,zone);

thread_loop_c(thread,domain)
{
begin_c_loop(cell,thread)
{
C_UDMI(cell,thread,0) = 0.0;
C_UDMI(cell,thread,1) = 0.0;
C_UDMI(cell,thread,2) = 0.0;
C_UDMI(cell,thread,3) = 0.0;
C_UDMI(cell,thread,4) = 0.0;
}
end_c_loop(cell,thread)

}

}
rajendra1 is offline   Reply With Quote

Old   June 12, 2017, 07:52
Default
  #28
Senior Member
 
KaLium's Avatar
 
Kal-El
Join Date: Apr 2017
Location: Finland
Posts: 150
Rep Power: 9
KaLium is on a distinguished road
Code:
DEFINE_ON_DEMAND (udm_init)
{
  Thread *thread;
  cell_t cell;
  int zone = 3;
  Domain *domain = Get_Domain(1);
  thread =Lookup_Thread(domain,zone);
    
      begin_c_loop(cell,thread)       
      {
      C_UDMI(cell,thread,0) = 0.0;
      C_UDMI(cell,thread,1) = 0.0;
      C_UDMI(cell,thread,2) = 0.0;
      C_UDMI(cell,thread,3) = 0.0;
      C_UDMI(cell,thread,4) = 0.0;
      }
      end_c_loop(cell,thread)


}
I would try this.

You don't need the "node". I copied that from my old code as a mistake.
rajendra1 likes this.
KaLium is offline   Reply With Quote

Old   June 12, 2017, 09:10
Default
  #29
Senior Member
 
KaLium's Avatar
 
Kal-El
Join Date: Apr 2017
Location: Finland
Posts: 150
Rep Power: 9
KaLium is on a distinguished road
Code:
thread =Lookup_Thread(domain,zone);       
begin_c_loop(cell,thread)              
{
      
}
end_c_loop(cell,thread)
is enough if you are using your udf in one cellzone only.
rajendra1 likes this.
KaLium is offline   Reply With Quote

Old   June 12, 2017, 14:17
Default
  #30
New Member
 
Join Date: Jun 2017
Posts: 19
Rep Power: 9
rajendra1 is on a distinguished road
Quote:
Originally Posted by KaLium View Post
Code:
thread =Lookup_Thread(domain,zone);       
begin_c_loop(cell,thread)              
{
      
}
end_c_loop(cell,thread)
is enough if you are using your udf in one cellzone only.
interesting ..thanks for clarification.


I have tried to use DEFINE_ADJUST instead of DEFINE_EXECUTE_AT_END but not fruitful so far, however it solves problem when I use DEFINE_EXECUTE_AT_END and also storing values in UDM.
rajendra1 is offline   Reply With Quote

Old   June 12, 2017, 14:46
Default
  #31
Senior Member
 
KaLium's Avatar
 
Kal-El
Join Date: Apr 2017
Location: Finland
Posts: 150
Rep Power: 9
KaLium is on a distinguished road
Do you mean that your code is working now?
KaLium is offline   Reply With Quote

Old   June 12, 2017, 15:55
Default
  #32
New Member
 
Join Date: Jun 2017
Posts: 19
Rep Power: 9
rajendra1 is on a distinguished road
yes it is working.
KaLium likes this.
rajendra1 is offline   Reply With Quote

Old   June 13, 2017, 03:56
Default
  #33
Senior Member
 
KaLium's Avatar
 
Kal-El
Join Date: Apr 2017
Location: Finland
Posts: 150
Rep Power: 9
KaLium is on a distinguished road
Ok! Then you can forget the Define_adjust and just use the code that works.

How did you fix the code?
rajendra1 likes this.
KaLium is offline   Reply With Quote

Old   June 13, 2017, 12:47
Default
  #34
New Member
 
Join Date: Jun 2017
Posts: 19
Rep Power: 9
rajendra1 is on a distinguished road
Quote:
Originally Posted by KaLium View Post
Ok! Then you can forget the Define_adjust and just use the code that works.

How did you fix the code?
I was not using thread loop, so just added it and it worked.
rajendra1 is offline   Reply With Quote

Old   June 14, 2017, 04:15
Default
  #35
New Member
 
Join Date: Jun 2017
Posts: 19
Rep Power: 9
rajendra1 is on a distinguished road
so basically I have used DEFINE_INIT and DEFINE_EXECUTE_AT_END .........and apparently the problem was with DEFINE_EXECUTE_AT_END macro ie. the missing thread loop as I have said.
rajendra1 is offline   Reply With Quote

Old   October 13, 2017, 05:04
Default
  #36
New Member
 
maitray's Avatar
 
Maitray sharma
Join Date: Aug 2017
Posts: 7
Rep Power: 9
maitray is on a distinguished road
Quote:
Originally Posted by rajendra1 View Post
Dear Friends,

I am trying to solve heat transfer problem.
The geometry is shell and tube type. please see attachment for the picture of model.
Problem description:
heat is generation takes place in tube and it is to be transferred to the shell side through the cylinder wall. There is no problem when I am trying to solve the problem in fluent (workbench project) by giving constant heat source as input. BUT when I am trying to calculate mass generation and heat generation with the help of UDF, fluent says: fluent received fatal signal (access_violation). I have tried different ways to rectify the error but failed so far.

Boundary conditions are,
gas inlet (tube (inner) inlet) at 20e+05 Pa. pressure, 300 K temp.
gas outlet (tube (inner) outlet) adiabatic wall (so there is no outlet only inlet on tube side)
coolant inlet (shell side (annular section)) 300 K temp.
coolant outlet (shell side (annular section))
Convetive wall (inner cylinder surface)
Convetive wall Shadow (inner cylinder surface)
Adiabatic wall (outer cylinder surface)

I have coupled convective wall and its shadow in boundary conditions. Also tried to calculate heat flux on the convective wall using DEFINE_HEAT_FLUX macro.
I have tried to give initial values using DEFINE_INIT MACRO in the gas tube because I want uniform pressure in the tube.

I am trying to calculate mass source and hence heat source using DEFINE_SOURCE MACRO

I am using Interpreted UDF. It gets interpreted, in fluent initialization gets done but it again gives same error ie. "fluent received fatal signal (access_violation)".

I need help from you guys, please see the code and tell me where I am wrong, I will be very grateful for you suggestions.

UDF CODE:

/************************************************** *************
UDF for initializing flow field variables
************************************************** **********/


DEFINE_INIT(my_init_func,d)
{
cell_t c;
Thread *t;
real xc[ND_ND];

/* loop over all cell threads in the domain */
thread_loop_c(t,d)
{

/* loop over all cells */
begin_c_loop_all(c,t)
{
C_CENTROID(xc,c,t);

C_T(c,t) = 300.;
C_P(c,t) = 2000000.;
C_U(c,t) = 0.;
C_V(c,t) = 0.;
C_W(c,t) = 0.;
}
end_c_loop_all(c,t)
}
}
/************************************************** ************/

/* UDF for specifying an absorption source term in a pressure and temperature*/

DEFINE_EXECUTE_AT_END(source_calculation)
{
Domain *d;
Thread *t;
cell_t c;
real time = CURRENT_TIME;
real temp, Pg, Peqa, mab, m;
int zone=7;
d=Get_Domain(1);
t=Lookup_Thread(d,zone);
begin_c_loop(c,t)
{
temp=C_T(c,t);

Pg=C_P(c,t);

Peqa=1000*exp(Aab-Bab/temp);

mab=-Ca*exp(-Ea/(Rg*temp))*log(Pg/Peqa)*(Psat-Pemp-C_UDMI(c,t,2)); /* mass rource kg/m^3 S*/

m=mab;

C_UDMI(c,t,0) = m;

C_UDMI(c,t,1) = 0.0; /*derivative term in mass source*/

C_UDMI(c,t,2) = -C_UDMI(c,t,0)*CURRENT_TIMESTEP+C_UDMI(c,t,2);

C_UDMI(c,t,3) = C_UDMI(c,t,0)*(delta_H+temp*(C_pg-C_ps));

C_UDMI(c,t,4) = 0.0;/*derivative term in energy source*/
}
end_c_loop(c,t);
}
DEFINE_SOURCE(mass_source,c,t,dS,eqn)
{
dS[eqn] = C_UDMI(c,t,1);
return C_UDMI(c,t,0);
}
DEFINE_SOURCE(energy_source,c,t,dS,eqn)
{
dS[eqn] = C_UDMI(c,t,4);
return C_UDMI(c,t,3);
}
/************************************************** ***********/

/**************udf for Wall Heat flux on convective wall *************************** */

real h = 0.0; /* heat transfer coefficient (W/m^2 K)
*/

DEFINE_ADJUST(htc_adjust, domain)
{
/* Define the heat transfer coefficient. */

h = 120;
}

(heat_flux, f, t, c0, t0, cid, cir)
{
cid[0] = 0.;
cid[1] = h;
cid[2] = h;
cid[3] = 0.;
}

I thank you in advance.

For this metal hydride absorption problem, why are you giving initial pressure to all cell zone instead to giving the pressure at the inlet of cylinder?
maitray is offline   Reply With Quote

Reply

Tags
define_init, define_source, heat flux udf, mass source term, source energy term


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
UDF for heat transfer coeff. in porous media parvaz747 FLUENT 0 November 16, 2016 13:35
Difficulty In Setting Boundary Conditions Moinul Haque CFX 4 November 25, 2014 18:30
Problem in UDF time dependent vloumetric heat source eng_yasser_2020 Fluent UDF and Scheme Programming 0 March 30, 2014 09:07
Question about heat transfer coefficient setting for CFX Anna Tian CFX 1 June 16, 2013 07:28
UDF - Heat transfer coefficient kulasekharan FLUENT 3 August 12, 2004 08:09


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