|
[Sponsors] |
December 9, 2014, 09:44 |
how to write file from udf
|
#1 |
New Member
ashish
Join Date: Dec 2014
Posts: 24
Rep Power: 12 |
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); } |
|
December 9, 2014, 09:56 |
|
#2 |
Senior Member
Cees Haringa
Join Date: May 2013
Location: Delft
Posts: 607
Rep Power: 0 |
shouldn't the declarations
Code:
FILE *temp_file; real p; 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); |
|
December 10, 2014, 07:49 |
|
#3 |
New Member
ashish
Join Date: Dec 2014
Posts: 24
Rep Power: 12 |
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
|
|
December 10, 2014, 08:54 |
|
#4 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
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. |
|
December 10, 2014, 10:23 |
|
#5 |
New Member
ashish
Join Date: Dec 2014
Posts: 24
Rep Power: 12 |
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... |
|
December 10, 2014, 10:40 |
|
#6 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
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.
|
|
December 13, 2014, 10:11 |
|
#7 |
New Member
ashish
Join Date: Dec 2014
Posts: 24
Rep Power: 12 |
Dear,
I want X-component.... Plz help i'm stuck ... Thank u |
|
December 14, 2014, 09:48 |
|
#8 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
After the comments already given in this thread, what is the current version of your UDF?
|
|
December 15, 2014, 07:19 |
|
#9 |
New Member
ashish
Join Date: Dec 2014
Posts: 24
Rep Power: 12 |
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); } |
|
December 16, 2014, 10:38 |
|
#10 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
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? |
|
December 16, 2014, 11:05 |
|
#11 |
New Member
ashish
Join Date: Dec 2014
Posts: 24
Rep Power: 12 |
Dear,
Sorry But the present code is showing ACCESS_VIOLATION........ |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[swak4Foam] swak4foam building problem | GGerber | OpenFOAM Community Contributions | 54 | April 24, 2015 17:02 |
[swak4Foam] Swak4FOAM 0.2.3 / OF2.2.x installation error | FerdiFuchs | OpenFOAM Community Contributions | 27 | April 16, 2014 16:14 |
Trouble compiling utilities using source-built OpenFOAM | Artur | OpenFOAM Programming & Development | 14 | October 29, 2013 11:59 |
friction forces icoFoam | ofslcm | OpenFOAM | 3 | April 7, 2012 11:57 |
ParaView Compilation | jakaranda | OpenFOAM Installation | 3 | October 27, 2008 12:46 |