|
[Sponsors] |
Having difficulties writing UDF program for calculating the source term |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
December 6, 2015, 02:22 |
Having difficulties writing UDF program for calculating the source term
|
#1 |
New Member
Join Date: Dec 2015
Posts: 11
Rep Power: 10 |
Good morning,
Please help me to write a UDF program for calculate the source term If Temperature at time (t) > Temperature at time (t-1) and If Temperature at time (t) > 30 and Temperature at time (t-1) < 20 S= 5*rho* T/delta t If Temperature at time (t) > Temperature at time (t-1) and Temperature at time (t) <30 and Temperature at time (t-1) < 5 S= 2*rho* T/delta t If Temperature at time (t) < Temperature at time (t-1) and Temperature at time (t) = 30 and Temperature at time (t-1) < 5 S= rho* T/delta t If Temperature at time (t) = Temperature at time (t-1) S = S at (t-1) Where: delta t = time at (t) – time at (t-1) and T is temperature Calculated by Fluent. Thank you. My program is : #include "udf.h" #define S_0 #define rho 100 DEFINE_SOURCE(terme_source, cell, thread, dS, eqn); { real T_t = C_T(c,t); reat T_t_1 = C_T_M1(c,t); real delta_time = CURRENT_TIMESTEP; reat prev_time = PREVIOUS_TIME; time = CURRENT_TIME; real source; If (T_t > T_t_1 && T_t > 30 && T_t_1 < 20) { source = 5*rho*T_t/ CURRENT_TIMESTEP; } else if (T_t >T_t_1 && T_t < 30 && T_t_1 < 5) { source = 2*rho*T_t/ CURRENT_TIMESTEP; } else if (T_t<T_t_1 && T_t = 30 && T_t_1 < 5) { source = rho*T_t/ CURRENT_TIMESTEP; } else T_t = T_t_1; { source = S_previous } return source; } Last edited by fersim; December 6, 2015 at 03:00. Reason: correction |
|
December 7, 2015, 08:02 |
|
#2 |
Senior Member
Bruno
Join Date: Mar 2009
Location: Brazil
Posts: 277
Rep Power: 21 |
All you have are small C errors which the compiler will show you.
|
|
December 7, 2015, 08:33 |
Udf
|
#3 |
New Member
Join Date: Dec 2015
Posts: 11
Rep Power: 10 |
Thank you for your reply, but I have other problem. how to program C_T(c,t) >C_T_M1(c,t) in any program UDF, like DEFINE_SOURCE(terme_source, c, t, dS, eqn). Thank you.
|
|
December 7, 2015, 08:44 |
|
#4 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26 |
In the way that you did, but with the changes that brunoc suggested. If this is not what you need, please be more detailed in what your question really is...
|
|
December 7, 2015, 11:24 |
udf
|
#5 |
New Member
Join Date: Dec 2015
Posts: 11
Rep Power: 10 |
I rephrase the problem as follows:
If Temperature at time (t) > Temperature at time (t-delta t) Source(t) = 50000 If Temperature at time (t) > Temperature at time (t-delta t) Source(t) = 10000 If Temperature at time (t) = Temperature at time (t-delta t) Source(t)= Source_previous(t-dt) If Temperature at time (t) = Temperature at time (t-delta t) Source (t) = S (t - delta t) #include "udf.h" DEFINE_SOURCE(terme_source, c, t, dS, eqn) { real source; real sourrce_previous; /*sourrce_previous= source at t=t-delta t */ if (C_T(c,t)>C_T_M1(c,t)) source = 50000; else if (C_T(c,t)<C_T_M1(c,t)) source = 10000; else source = sourrce_previous; dS[eqn]=0; return source; } |
|
December 7, 2015, 11:35 |
|
#6 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26 |
If you want to explain what your problem is, you need to write a little bit more text, not just a set of equations and some code.
Your set of equations more or less describe what you want to have. (But you mixed up some signs like > and <. Be careful, I can understand what it should be, but if you make such mistakes when you talk to Fluent, Fluent will misunderstand.) And then you put some code. What is that? You give the code without warning or explanation. I have to guess it is your attempt at a solution. But you don't say anything about it... Does it work? Does it compile? Do you get warnings? Does it run? Do you get results? Do you get good results? Do you get bad results? Which part is giving you the problems? Turning the equations into program code? Coupling this code to Fluent? Compiling? Running? Give us some context to work with... |
|
December 7, 2015, 14:16 |
udf
|
#7 |
New Member
Join Date: Dec 2015
Posts: 11
Rep Power: 10 |
Good evening,
I'll write the details of my project. This source code calculation value of the source term to account for the phase change phenomenon of a material. As the temperature increases (T (t) > T (t-delta t) the material absorbs heat, so the source term is negative. And decreasing temperature (T (t) <T (t-delta t) the material releases heat, so the source term is positive and finally if the temperature remains constant (T (t) = T (t-delta t) the source term equal to the previous value (source at t - delta t). This code takes into account the hysteresis of a no pure phase change material. That is to say, the source term is different during the heat absorption and release of heat. This source term is written as a polynomial equation (Source = A * T + B). I inform you that I code is compiled during simulation but there is the following error: Error: FLUENT received fatal signal (ACCESS_VIOLATION) 1. Note exact events leading to error. 2. Save case/data under new name. 3. Exit program and restart to continue. 4. Report error to your distributor. Error Object: () This error is caused that this problem does not recognize the temperature at time t delta-t. #include "udf.h" DEFINE_SOURCE(terme_source, c, t, dS, eqn) { real source; real sourrce_previous; /*sourrce_previous= source at t-delta t */ if (C_T(c,t)>C_T_M1(c,t)) source = -5*C_T(c,t)-25; else if (C_T(c,t)<C_T_M1(c,t)) source = 8*C_T(c,t)+15; else source = sourrce_previous; dS[eqn]=0; return source; } Last edited by fersim; December 8, 2015 at 04:18. |
|
December 9, 2015, 09:51 |
|
#8 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26 |
One problem is that you never define what "sourrce_previous" is... If your temperature happens to be the same as the time step before, Fluent tries to access this value but does not know what it is. But for that the solution is simple: if you don't want to change the source, do nothing!
Code:
#include "udf.h" DEFINE_SOURCE(terme_source, c, t, dS, eqn) { real source; if (C_T(c,t)>C_T_M1(c,t)) { source = -5*C_T(c,t)-25; } else if (C_T(c,t)<C_T_M1(c,t)) { source = 8*C_T(c,t)+15; } /* no else here: do nothing if they are equal */ dS[eqn]=0; return source; } |
|
December 9, 2015, 14:05 |
|
#9 |
Senior Member
Bruno
Join Date: Mar 2009
Location: Brazil
Posts: 277
Rep Power: 21 |
One possible problem is that C_T_M1 might not exist at t=0. Maybe your UDF should check if t=0 and take care of that.
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
UDF Source term problem | natantyt | FLUENT | 2 | May 15, 2018 21:40 |
[foam-extend.org] problem when installing foam-extend-1.6 | Thomas pan | OpenFOAM Installation | 7 | September 9, 2015 21:53 |
[swak4Foam] Error bulding swak4Foam | sfigato | OpenFOAM Community Contributions | 18 | August 22, 2013 12:41 |
[swak4Foam] funkySetFields compilation error | tayo | OpenFOAM Community Contributions | 39 | December 3, 2012 05:18 |
source term udf | tas38 | FLUENT | 1 | August 14, 2009 10:44 |