CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Average Temperature (https://www.cfd-online.com/Forums/fluent-udf/184066-average-temperature.html)

FRibeiro February 21, 2017 13:34

Average Temperature
 
Hi,

I am simulating a sub-channel flow (in a nuclear reactor), so I have 4 domains (fuel, gap, clad and fluid).
I have a volumetric heat generation into the fuel and I and to calculate the fluid average temperature by using a UDF.

I wrote something like that:

#include "udf.h"

DEFINE_TEMPERATURA(temp_ave_fluid)

{
Domain *d;
cell_t c;
Thread *tc;
ind ID = 30; */ ID of the domain fluid
d = Get_Domain(1);
real volume = 0.0;
real temper = 0.0;
real temperature_fluid;
tc = Lookup_Thread(d,ID);

begin_c_loop(c,tc)
{
volume = C_VOLUME(c,tc);
temper += C_T(c,tc)*C_VOLUME(c,tc);
vol_tot += volume;
tsum += temper
}
end_c_loop(c,tc)

temperature_fluid=tsum/vol_tot;

printf("\n Temperature sonde: %e K \n , temperature_fluid);

}

But I can not interpret the UDF, Fluent says:
"unterminated string or character constant"
"possible real start of unterminated constant"
"line 7: parse error"

Could someone helps me? Please

Thanks

KevinZ09 February 22, 2017 07:53

Not sure what line 7 is in your code, but a couple of things:

1: I've never heard of the DEFINE_TEMPERATURA macro. Not sure what it is or what it does, if it even exists.
2: If you want to just calculate and print a variable, I'd suggest using DEFINE_ADJUST.
3: There's a spelling error in "Ind ID = 30;". It should read "Int ID = 30;".
4: Are you trying to calculate a volume-weighted average temperature? If so, don't need a UDF for that, you can just create a monitor for it.
5: If you do absolutely want a UDF for it, I think you're making a calculation error, as you're summing C_T(c,ct)*C_VOLUME(c,ct) twice. I'd suggest to just write "volume += C_VOLUME(c,ct) and delete the vol_tot and tsum calculations/variables.

But perhaps these suggestions are irrelevant as it could be that I misunderstand what you're trying to do. I understand it's a nuclear reactor, but I figure your fluid is in a separate domain/volume from the fuel rod and cladding, right? So is it the coolant's average temperature you want?

FRibeiro February 22, 2017 14:47

Dear Kevin,

Thank you for your response.

Actually I did some mistakes, thanks.

I really need to calculate the average temperature by UDF to use the information to perform a feedback to the fuel.

I am a little lost in UDF, I don't find a lot o material on internet to learn.

If I try to use DEFINE_ADJUST, Fluent says that I have only one argument, but it's not a error, and I also tried with DEFINE_ADJUST (temp_ave_fluid, domain).

Today my code is:

#include "udf.h"

DEFINE_EXECUTE_AT_END(temp_ave_fluid)
{
Domain *d;
cell_t c;
Thread *tc;
Int ID = 30;
d = Get_Domain(1);
real volume = 0.0;
real temper = 0.0;
real temperature_fluid;
tc = Lookup_Thread(d,ID);

begin_c_loop(c,tc)
{
volume += C_VOLUME(c,tc);
temper += C_T(c,tc)*C_VOLUME(c,tc);
}
end_c_loop(c,tc)

temperature_fluid=tsum/vol_tot;
printf("\n Temperature sonde: %e K \n , temperature_fluid);
}

But I keep having the same problems.

Thanks one again,
Felipe

KevinZ09 February 23, 2017 07:18

Well, you need to close the string in your printf statement, as now you've only got the opening quotation mark ", but no accompanying closing one. So put a " after the second \n in the printf statement.

Also, I noticed in your old code you used */, but that signals end of comments. Start of comments is indicated by /*.

But outside of the syntax, what is it you're really trying to do? Because the macro to use depends on what you want to accomplish. I suggested DEFINE_ADJUST for just outputting information, but perhaps you need another one if you want to feed your volume weighted average temperature back to your simulation.

FRibeiro March 7, 2017 06:28

Kevin,

Thank you very much for your corrections.

But it still not working...

"#include "udf.h"

DEFINE_ADJUST(temp_ave_fluid)
{
Domain = Get_Domain(1);
cell_t c;
Thread *tc;
real volume = 0;
real temper = 0;
real temperature_fluid;
tc = Lookup_Thread(domain,fluid);

begin_c_loop(c,tc)
{
volume += C_VOLUME(c,tc);
temper += C_T(c,tc)*C_VOLUME(c,tc);

}
end_c_loop(c,tc)

temperature_fluid=temper/volume;
printf("\n Temperature sonde: %e K \n , temperature_fluid");

}"

And actually I have serious problems when Fluent try ti read it:


"cpp -I"C:\PROGRA~1\ANSYSI~1\v150\fluent\fluent15.0.7/src" -I"C:\PROGRA~1\ANSYSI~1\v150\fluent\fluent15.0.7/cortex/src" -I"C:\PROGRA~1\ANSYSI~1\v150\fluent\fluent15.0.7/client/src" -I"C:\PROGRA~1\ANSYSI~1\v150\fluent\fluent15.0.7/multiport/src" -I. -DUDF
ONFIG_H="<udfconfig-host.h>" "C:\Documents and Settings\Lasme\Desktop\UDF_Tmedio_fluido\qv_cos_03 _copia\Tmedio_fluido3.c"
C:\\Documents and Settings\\Lasme\\Desktop\\UDF_Tmedio_fluido\\qv_co s_03_copia\\Tmedio_fluido3.c:3: macro `DEFINE_ADJUST' used with just one arg
Error: C:\\Documents and Settings\\Lasme\\Desktop\\UDF_Tmedio_fluido\\qv_co s_03_copia\\Tmedio_fluido3.c: line 5: parse error.
Error: C:\\Documents and Settings\\Lasme\\Desktop\\UDF_Tmedio_fluido\\qv_co s_03_copia\\Tmedio_fluido3.c: line 6: parse error.
Error: C:\\Documents and Settings\\Lasme\\Desktop\\UDF_Tmedio_fluido\\qv_co s_03_copia\\Tmedio_fluido3.c: line 7: parse error.
Error: C:\\Documents and Settings\\Lasme\\Desktop\\UDF_Tmedio_fluido\\qv_co s_03_copia\\Tmedio_fluido3.c: line 8: parse error.
Error: C:\\Documents and Settings\\Lasme\\Desktop\\UDF_Tmedio_fluido\\qv_co s_03_copia\\Tmedio_fluido3.c: line 9: parse error.
Error: C:\\Documents and Settings\\Lasme\\Desktop\\UDF_Tmedio_fluido\\qv_co s_03_copia\\Tmedio_fluido3.c: line 10: parse error.
Error: C:\\Documents and Settings\\Lasme\\Desktop\\UDF_Tmedio_fluido\\qv_co s_03_copia\\Tmedio_fluido3.c: line 11: tc: undeclared variable
MPI Application rank 0 exited before MPI_Finalize() with status -1073741819
The fl process could not be started."

Do you not what it's wrong now? Please

Thanks,
Felipe

h0rst May 7, 2017 09:40

Did you try to go over the look up function directly?


All times are GMT -4. The time now is 20:55.