|
[Sponsors] |
December 24, 2018, 10:52 |
udf pow error
|
#1 |
New Member
saosao
Join Date: Dec 2018
Posts: 4
Rep Power: 7 |
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); } |
|
December 25, 2018, 19:43 |
|
#2 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
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*/ } try to change to dS[eqn] = 0; best regards |
|
December 26, 2018, 16:27 |
|
#3 |
New Member
saosao
Join Date: Dec 2018
Posts: 4
Rep Power: 7 |
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.
|
|
December 28, 2018, 07:02 |
|
#4 |
Senior Member
Join Date: Sep 2017
Posts: 246
Rep Power: 12 |
Hi Saosao,
I think to use pow, you need to put Code:
#include "math.h" 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); } |
|
December 28, 2018, 14:41 |
|
#5 |
New Member
saosao
Join Date: Dec 2018
Posts: 4
Rep Power: 7 |
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)? |
|
December 29, 2018, 07:46 |
|
#6 |
Senior Member
Join Date: Sep 2017
Posts: 246
Rep Power: 12 |
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 |
|
December 30, 2018, 06:59 |
|
#7 |
New Member
saosao
Join Date: Dec 2018
Posts: 4
Rep Power: 7 |
Thank you very much
The problem was solved. As you mentioned, the error is related to negative form of x. |
|
Tags |
exponentiate, udf |
|
|
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 |