compilation error
Why is the following UDF not being compiled as an interpreted UDF?
#include "udf.h" DEFINE_PROPERTY(cell_temperature,cell,thread) { real temp = C_T(cell,thread); face_t f; real flow_time = RP_Get_Real("flow-time"); begin_f_loop (f,thread) { if (flow_time = 0) temp = 300; else temp = 350; return temp; } Error is:line 12: invalid expression for if : float |
Re: compilation error
This error comes from unability to check equality between integer and real numbers. You could change the line
if (flow_time = 0) to if (flow_time < 1.0e-7) and this line should be OK. I don't have much experience with UDF, but i'm not sure with what you are trying to achieve with this one. Temperature is not property, why dont't you use DEFINE_PROFILE or a field function? Hope it helps |
Re: compilation error
Note that the equality operator in C is ==.
You have an assignment (setting flow_time to zero), not an equality test. |
Re: compilation error
Dear kostya, thanks for the comments. But really I am still confused about the UDF to be used. Actually I want to define an energy source from time t=0 secs to time t=60 secs (i.e. 1 minute) at the constant value of say 5 W/m3. Then I want to stop the energy source ( at t > 60 secs), and find out the temperature profile as a function of temperature and time. Following is the crude form of the program, which of course has errors, as they appear on the console window.
#include "udf.h" DEFINE_SOURCE(energy_source,cell,thread,dS,eqn) { real source; real flow_time = RP_Get_Real("flow-time"); { if (flow_time < 1.0e-7) source = 0.; for (flow_time>=1.0e-7; flow_time<=60; source = 5.0; else source = 0.; dS[eqn] = 0.0; return source; } The compilation errors that appear are as follows: Error: source.cpp: line 10: parse error. Error: source.cpp: line 11: parse error. Error: source.cpp: line 17: parse error. Here source.cpp is the relevant file. Another question that I would like to ask is about the error. What is the meaning of parse error? |
Re: compilation error
I've just started to learn to program in C and use these UDF's also. I found a parse error just to mean a format error of some type (ie the use of brackets inside your 'if' loops, if you have more than 1 line after your 'if' and 'else' statements you need to put the '{' brackets in)
cheers, Matthew. |
Re: compilation error
A parse error indicates that the code is not syntactically valid C. You are going to need to learn C to do anything effective with UDFs. Here is a version of your code that sets source to 5 if flow-time is between (0,60] and 0 otherwise. I am not familiar with the DEFINE_SOURCE hook so I can't comment on whether it is doing something useful.
#include "udf.h" DEFINE_SOURCE(energy_source,cell,thread,dS,eqn) { real source; real flow_time = RP_Get_Real("flow-time"); if (flow_time > 0.0 && flow_time <= 60.) source = 5.0; else source = 0.0; dS[eqn] = 0.0; return source; } |
All times are GMT -4. The time now is 05:31. |