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/)
-   -   how to write file from udf (https://www.cfd-online.com/Forums/fluent-udf/145631-how-write-file-udf.html)

ashish_kumar388 December 9, 2014 08:44

how to write file from udf
 
I'm unable to write anything from UDF which inside the cell thread loop





#include "udf.h"
#include "mem.h"
# include <stdio.h>
#define filename "temperature23.out"

FILE *temp_file;
real p;

DEFINE_ON_DEMAND(Temp_grad_ondemand)

{
Thread *t;

cell_t c;

Domain *d;

d = Get_Domain(1);






temp_file = fopen(filename, "w");
fprintf(temp_file,"fine");
/*thread_loop_c(t,d)*/


begin_c_loop(c,t)
{
p= NV_MAG(C_T_G(c,t)[0]);
C_UDMI(c,t,0) = p;
fprintf(temp_file,"p");

}


end_c_loop(c,t)

fclose(temp_file);


}

CeesH December 9, 2014 08:56

shouldn't the declarations

Code:

FILE *temp_file;
real p;

be inside the function?

Also, are you running your code in serial or parallel?
what exactly is the error you get? is the file created and nothing written, or is the file not created?

Also, it should be

Code:

fprintf(temp_file,"%f ", p);
Where %f writes a float, and may be changed accordingly for other formatting. Also, don't forget to add spaces, commas or newline characters otherwise all numbers will be printed side-by-side, which makes post-processing bit of a hell.

ashish_kumar388 December 10, 2014 06:49

i'm using in serial. Actually i want to calculate temperature gratient. but when i use NV_MAG(c,t)[0] fluent is showing access violation. now i'm using Adjust macro but the problem is same. plz help. I'm very new in UDF

pakk December 10, 2014 07:54

This makes no sense:
Code:

p= NV_MAG(C_T_G(c,t)[0]);
C_T_G(c,t) is an array with 3 elements (if you run 3D).
C_T_G(c,t)[0] is the first element of that array, so a float.
NV_MAG() calculates the length of a vector, and expects an array (vector) as input. But the input that you give, is not an array, but only the first element of that vector. I don't understand what your goal is in that line, and Fluent also does not understand.

ashish_kumar388 December 10, 2014 09:23

Dear,
actually I want to extract temperature gradient at every flow time from my geometry. and i'm beginner in udf an in c. so plz help me out to write udf to get temp. gradient...

pakk December 10, 2014 09:40

What do you want? x-component of gradient? y-component of gradient? z-component of gradient? magnitude of gradient? I can not figure that out.

ashish_kumar388 December 13, 2014 09:11

Dear,
I want X-component.... Plz help i'm stuck ...
Thank u

pakk December 14, 2014 08:48

After the comments already given in this thread, what is the current version of your UDF?

ashish_kumar388 December 15, 2014 06:19

Dear
[0] is used for dt/dx
and current version of code is this. but i think i must use ADJUST macro so that i can take the temperature gradient at every iteration.

#include "udf.h"
#include "mem.h"
# include <stdio.h>
#define filename "temperature23.out"


DEFINE_ON_DEMAND(Temp_grad_ondemand)

{
Domain *d;
Thread *t;
cell_t c;

FILE *temp_file;
real p;
d = Get_Domain(3);

temp_file = fopen(filename, "w");
fprintf(temp_file,"ok");
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
p= NV_MAG(C_T_G(c,t)[0]);
C_UDMI(c,t,0) = p;
fprintf(temp_file,"%f", p);
}
end_c_loop(c,t)
}
fclose(temp_file);

}

pakk December 16, 2014 09:38

If you want an answer to your question, then please write a question.

The original question was that you wanted to know how to write anything from inside the cell thread loop. That has been solved now, or not? What is the question you still have? Why do you send personal messages that you need help, when it is not clear what you need to be helped with?

ashish_kumar388 December 16, 2014 10:05

Dear,
Sorry But the present code is showing ACCESS_VIOLATION........:confused:


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