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

udf pow error

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 24, 2018, 10:52
Default udf pow error
  #1
New Member
 
saosao
Join Date: Dec 2018
Posts: 4
Rep Power: 7
saosao is on a distinguished road
Hi
I am new in udf and I want to exponentiate the "C_U_RG(c,t)[1]" to 2.5. But the fluent gives this error:
Error: Divergence detected in AMG solver: uds-0
Error Object: #f

when I want
to exponentiate the "C_U_RG(c,t)[1]" to 2.0, it works very well.
what is wrong about my udf? my udf is as follows:

#include "udf.h"
enum
{
T22,
N_REQUIRED_UDS
};
real y;
real z;


DEFINE_SOURCE(T22_source, c, t, dS, eqn)
{
y=C_U_RG(c,t)[1];
z= pow(y,2.5);
dS[eqn] = -1;
return z - C_UDSI(c, t, T22);
/*Source*/

}

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

dS[eqn] = 0.;
return C_UDSI(c, t, T22);

}

saosao is offline   Reply With Quote

Old   December 25, 2018, 19:43
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
You UDF seems correct to me, most likely this is model problem, change convergence criteria, under-relaxation factors, time step, mesh.
your code
Code:
DEFINE_SOURCE(T22_source, c, t, dS, eqn) 
{ 
y=C_U_RG(c,t)[1];
z= pow(y,2.5);
dS[eqn] = -1; 
return z - C_UDSI(c, t, T22); 
/*Source*/ 

}
how did you get dS[eqn] = -1; ???
try to change to dS[eqn] = 0;

best regards
AlexanderZ is offline   Reply With Quote

Old   December 26, 2018, 16:27
Default
  #3
New Member
 
saosao
Join Date: Dec 2018
Posts: 4
Rep Power: 7
saosao is on a distinguished road
the problem seems to be related to float number 2.5 in "pow(y,2.5)". when the power is changed to 2.0 (pow(y,2.0)) the code is working very good.
saosao is offline   Reply With Quote

Old   December 28, 2018, 07:02
Default
  #4
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 12
obscureed is on a distinguished road
Hi Saosao,

I think to use pow, you need to put
Code:
#include "math.h"
at the start of the UDF.

It surprises me that pow(x,2.0) is OK, but it is just about possible that the compiler automatically simplifies pow(x,2.0) into (x*x).

The manual explains that C_U_RG(c,t) is not necessarily available -- but presumably you have followed the instructions about "solve/set/expert...Keep temporary solver memory from being freed".

In any case like this, you can try to debug the problem just by printing to the terminal window, using Message. If the case is large, so that printing a message for every cell would be overwhelming, I tend to select one in every 1000 cells (or even 100000 etc), by an arbitrary test on the integer c -- please see below.

Good luck!
Ed


Code:
#include "udf.h"
enum
{
   T22,
   N_REQUIRED_UDS
};

DEFINE_SOURCE(T22_source, c, t, dS, eqn)
{
  real y; /* Declare variables inside function where possible. */
   real z;

   y=C_U_RG(c,t)[1];
   z= pow(y,2.5);
   dS[eqn] = -1;
   if(c%1000==37) /* Select ~1 in 1000 cells; 37 is arbitrary */
     Message("In T22_source: y=%12g z=%12g T22=%12g\n",
       y,z,C_UDSI(c,t,T22));

   return z - C_UDSI(c, t, T22);
}
obscureed is offline   Reply With Quote

Old   December 28, 2018, 14:41
Default
  #5
New Member
 
saosao
Join Date: Dec 2018
Posts: 4
Rep Power: 7
saosao is on a distinguished road
It does not work.
I think the error related to the power 2.5, which causes divergence in the begining of the solution. Is there any way to substitude pow(y,2.5)?
saosao is offline   Reply With Quote

Old   December 29, 2018, 07:46
Default
  #6
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 12
obscureed is on a distinguished road
Hi Saosao,


Try the Message command (and the include) that I suggested, and check that the pow function is working as intended.


Note that pow(x,2.5) will fail if x is negative (which pow(x,2.0) might not). So, if x could ever be negative, you need to provide some safeguards.


Once you have pow working, then any divergence etc is related to the wider problem, as AlexanderZ has already pointed out.


Good luck!
Ed
obscureed is offline   Reply With Quote

Old   December 30, 2018, 06:59
Default
  #7
New Member
 
saosao
Join Date: Dec 2018
Posts: 4
Rep Power: 7
saosao is on a distinguished road
Thank you very much
The problem was solved. As you mentioned, the error is related to negative form of x.
saosao is offline   Reply With Quote

Reply

Tags
exponentiate, udf


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 DPM particle deposition modelingpa haghshenasfard Fluent UDF and Scheme Programming 10 September 15, 2019 03:03
Undeclared Identifier Errof UDF SteveGoat Fluent UDF and Scheme Programming 7 October 15, 2014 08:11
CGNS lib and Fortran compiler manaliac Main CFD Forum 2 November 29, 2010 07:25
Installation OF1.5-dev ttdtud OpenFOAM Installation 46 May 5, 2009 03:32
Problem with compile the setParabolicInlet ivanyao OpenFOAM Running, Solving & CFD 6 September 5, 2008 21:50


All times are GMT -4. The time now is 16:06.