CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

how to write file from udf

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By pakk

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 9, 2014, 09:44
Post how to write file from udf
  #1
New Member
 
ashish
Join Date: Dec 2014
Posts: 24
Rep Power: 12
ashish_kumar388 is on a distinguished road
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);


}
ashish_kumar388 is offline   Reply With Quote

Old   December 9, 2014, 09:56
Default
  #2
Senior Member
 
Cees Haringa
Join Date: May 2013
Location: Delft
Posts: 607
Rep Power: 0
CeesH is on a distinguished road
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.
CeesH is offline   Reply With Quote

Old   December 10, 2014, 07:49
Post
  #3
New Member
 
ashish
Join Date: Dec 2014
Posts: 24
Rep Power: 12
ashish_kumar388 is on a distinguished road
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
ashish_kumar388 is offline   Reply With Quote

Old   December 10, 2014, 08:54
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
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.
pakk is offline   Reply With Quote

Old   December 10, 2014, 10:23
Post
  #5
New Member
 
ashish
Join Date: Dec 2014
Posts: 24
Rep Power: 12
ashish_kumar388 is on a distinguished road
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...
ashish_kumar388 is offline   Reply With Quote

Old   December 10, 2014, 10:40
Default
  #6
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
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 likes this.
pakk is offline   Reply With Quote

Old   December 13, 2014, 10:11
Post
  #7
New Member
 
ashish
Join Date: Dec 2014
Posts: 24
Rep Power: 12
ashish_kumar388 is on a distinguished road
Dear,
I want X-component.... Plz help i'm stuck ...
Thank u
ashish_kumar388 is offline   Reply With Quote

Old   December 14, 2014, 09:48
Default
  #8
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
After the comments already given in this thread, what is the current version of your UDF?
pakk is offline   Reply With Quote

Old   December 15, 2014, 07:19
Post
  #9
New Member
 
ashish
Join Date: Dec 2014
Posts: 24
Rep Power: 12
ashish_kumar388 is on a distinguished road
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);

}
ashish_kumar388 is offline   Reply With Quote

Old   December 16, 2014, 10:38
Default
  #10
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
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?
pakk is offline   Reply With Quote

Old   December 16, 2014, 11:05
Post
  #11
New Member
 
ashish
Join Date: Dec 2014
Posts: 24
Rep Power: 12
ashish_kumar388 is on a distinguished road
Dear,
Sorry But the present code is showing ACCESS_VIOLATION........
ashish_kumar388 is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 15:41.