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); } |
shouldn't the declarations
Code:
FILE *temp_file; 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); |
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
|
This makes no sense:
Code:
p= NV_MAG(C_T_G(c,t)[0]); 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. |
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... |
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.
|
Dear,
I want X-component.... Plz help i'm stuck ... Thank u |
After the comments already given in this thread, what is the current version of your UDF?
|
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); } |
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? |
Dear,
Sorry But the present code is showing ACCESS_VIOLATION........:confused: |
All times are GMT -4. The time now is 20:27. |