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

UDF save data to a file!!

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   February 8, 2010, 14:48
Default UDF save data to a file!!
  #1
spk
Member
 
Join Date: Aug 2009
Posts: 67
Rep Power: 8
spk is on a distinguished road
Hi guys,

I need help!!!
I'm not familiar with UDF. I compiled the Udf of cavitation rate which is found at udf manual. I add the last line (Message...) and everything is ok.
I can see the values of cavitation mass transfer rate at fluent window. But i want to save these values in a .txt file. How can i do this?

Thanks a lot!

#include
"udf.h"
#define c_evap 1.0
#define c_con 0.1
DEFINE_CAVITATION_RATE(user_cav_rate, c, t, p, rhoV, rhoL, mafV, p_v, cigma, f_gas, m_dot)
{
real p_vapor = *p_v;
real dp, dp0, source;
p_vapor += MIN(0.195*C_R(c,t)*C_K(c,t), 5.0*p_vapor);
dp = p_vapor - ABS_P(p[c], op_pres);
dp0 = MAX(0.1, ABS(dp));
source = sqrt(2.0/3.0*rhoL[c])*dp0;
if(dp > 0.0)
*m_dot = c_evap*rhoV[c]*source;
else
*m_dot = -c_con*rhoL[c]*source;
Message("Cavitation Mass Transfer Rate: %g\n",m_dot);
}
spk is offline   Reply With Quote

Old   February 9, 2010, 08:15
Default
  #2
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 647
Rep Power: 11
dmoroian is on a distinguished road
Code:
#include"udf.h"
#define c_evap 1.0
#define c_con 0.1
DEFINE_CAVITATION_RATE(user_cav_rate, c, t, p, rhoV, rhoL, mafV, p_v, cigma, f_gas, m_dot)
{
   FILE *pf;
   real p_vapor = *p_v;
   real dp, dp0, source;
   p_vapor += MIN(0.195*C_R(c,t)*C_K(c,t), 5.0*p_vapor);
   dp = p_vapor - ABS_P(p[c], op_pres);
   dp0 = MAX(0.1, ABS(dp));
   source = sqrt(2.0/3.0*rhoL[c])*dp0;
   if(dp > 0.0)
      *m_dot = c_evap*rhoV[c]*source;
   else
      *m_dot = -c_con*rhoL[c]*source;

   Message("Cavitation Mass Transfer Rate: %g\n",m_dot);
   
   if(NULL == (pf = fopen("bubu.txt","a")))
      Error("Could not open file for append!\n");
   
   fprintf(pf,"%e\n",m_dot);
   fclose(pf);
}
dmoroian is offline   Reply With Quote

Old   February 9, 2010, 14:39
Default
  #3
spk
Member
 
Join Date: Aug 2009
Posts: 67
Rep Power: 8
spk is on a distinguished road
Thanks friend!!!
It works!!!
spk is offline   Reply With Quote

Old   May 14, 2010, 05:10
Default
  #4
Member
 
Ivan
Join Date: Aug 2009
Posts: 63
Rep Power: 8
IvanCFD is on a distinguished road
Hi dmoroian,

I'd like to use a UDF to save velocity field data on 50 cross-section planes (p-1, p-2,..., p-50) of my domain after every time step of an unsteady Fluent simulation.

Would you please let me know how?

Thanks a lot beforehand,

Ivan.
IvanCFD is offline   Reply With Quote

Old   May 14, 2010, 13:06
Default
  #5
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 647
Rep Power: 11
dmoroian is on a distinguished road
Hello Ivan,
For that purpose, I would use macros (scheme scripts) instead of udf's. You can set fluent to export the data in those planes in many different formats (my preferate is DX format for the OpenDX postprocessor).
dmoroian is offline   Reply With Quote

Old   May 14, 2010, 13:18
Default
  #6
Member
 
Ivan
Join Date: Aug 2009
Posts: 63
Rep Power: 8
IvanCFD is on a distinguished road
Hi Dragos,

I see. However, I heard that using macros Fluent overwrites the existing file so in the end what I would have stored would be the information at the last time step. I'd like to have velocity data on several planes at every time step, for me to be able to make time marching analysis.

I'd like to export the data in ASCII and then imported them into Matlab, which is what I'm familiar with.

Any suggestion?

Thanks a lot,

Ivan.
IvanCFD is offline   Reply With Quote

Old   May 14, 2010, 15:41
Default
  #7
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 647
Rep Power: 11
dmoroian is on a distinguished road
Well, one of the facilities is that you can automatically change the name of the output file every iteration or every time step.
dmoroian is offline   Reply With Quote

Old   May 14, 2010, 15:50
Default
  #8
Member
 
Ivan
Join Date: Aug 2009
Posts: 63
Rep Power: 8
IvanCFD is on a distinguished road
Really?

can you let me know how?

I mean, I want to save velocity data on 50 planes and I'd need to have every plane velocity data in one single file because that eases me a lot my life later when post-processing.

Thanks,

Ivan.
IvanCFD is offline   Reply With Quote

Old   May 14, 2010, 17:45
Default
  #9
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 647
Rep Power: 11
dmoroian is on a distinguished road
Hi Ivan,
Check chapter 4.1.7 in the user manual for automatic numbering of files, and 4.13 for exporting solution data (I think you're interested in the ASCII format).
The simplest way is to record a macro (check chap. 4.10.1) that exports data from your planes into ASCII format with automatic file naming, and run it periodically into "Calculation activities".
dmoroian is offline   Reply With Quote

Old   May 17, 2010, 04:40
Default
  #10
Member
 
Ivan
Join Date: Aug 2009
Posts: 63
Rep Power: 8
IvanCFD is on a distinguished road
Hi Dragos,

thanks a lot for that post, you explained just what I need. I've checked the sections you has recommended me and they look promising.

In section 40.10.1 the creation of transcript is explained. It says that between "start transcript" and "end transcript" everything that is done is recorder. I'm wondering if Fluent executes that transcript after every time step.

By the way, I can't find anything named as "Calculation activities" on Chapter 4.

I'll have a got up to what I've understand and let you know.

Thanks a lot,

Ivan.
IvanCFD is offline   Reply With Quote

Old   May 17, 2010, 05:15
Default
  #11
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 647
Rep Power: 11
dmoroian is on a distinguished road
Quote:
Originally Posted by IvanCFD View Post
...
I'm wondering if Fluent executes that transcript after every time step.
No it does not execute the transcript unless you tell it to. There are several ways to tell fluent to run a script:
1. In the GUI, chose from the menu: File->Read->Scheme or File->Read->Journal
This will run once the chosen script
2. In the GUI, chose from menu: Solve->Calculation Activities...
Here you can specify one or several scripts to be run periodically, on an iteration or time step basis. In version 6.3 the item "Calculation Activities..." is called "Execute Commands...".
3. In the TUI you can do the same thing as in above, both periodically and one time, but I let you the challenge to find out how.

Quote:
By the way, I can't find anything named as "Calculation activities" on Chapter 4.
You probably have a fluent release 6.3, then instead of "Calculation Activities..." try "Execute Commands..."

Dragos
dmoroian is offline   Reply With Quote

Old   May 17, 2010, 05:43
Default
  #12
Member
 
Ivan
Join Date: Aug 2009
Posts: 63
Rep Power: 8
IvanCFD is on a distinguished road
I see.

I know about the existence of Execute Commands. Actually, before you told me your solution, I was trying to create macros through the Execute Command window.

Unfortunately, I don't know what I do wrong but when I create a macro, it just doesn't want to run.

OK, following your instructions, which I've liked much, once I open the Execute Command window, what sort of command do I have to type to call the script just created?

I've been surfing on the Internet looking for some examples, but no luck.

I did a silly thing - typing in the command field the name of the file that contains my transcript, but it just didn't work.

By the way, the file auto-naming works fine.

Looking forward to hearing from you.

Ivan.
IvanCFD is offline   Reply With Quote

Old   May 17, 2010, 05:51
Default two energy equation
  #13
New Member
 
hameurlaine
Join Date: Jul 2009
Posts: 27
Rep Power: 8
louiza is on a distinguished road
Hi

I try to modeled arc burning discharge, and i didn't know how to introduce two temperature or energy equation, one for electrons and for heavey species.
if you have any suggestion answer me.
Thant's
louiza
louiza is offline   Reply With Quote

Old   May 17, 2010, 06:13
Default
  #14
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 647
Rep Power: 11
dmoroian is on a distinguished road
To Ivan:
If you check the help page for the "Execute Commands" dialog box, you'll find out that it can run commands defined using the button "Define Macro.." or text commands. In your case, the command should be something like:
Code:
   /file/read-macros Ivan_macro.scm

To Louiza:
Hi Louiza, please respect a bit of discipline on the threads. If you stump like this on a thrread with a completely different subject, and that is not finished, you will just annoy the participants.
As a suggestion for the future: if you have a question that was not asked before, put the question in a new thread or one that is related to it.
dmoroian is offline   Reply With Quote

Old   May 17, 2010, 10:05
Default
  #15
Member
 
Ivan
Join Date: Aug 2009
Posts: 63
Rep Power: 8
IvanCFD is on a distinguished road
Hi Dragos,

thanks a lot for that info.

I tried what you said and didn't work because for some reason Fluent couldn't identify my transcript file as a macro one.

Therefore I created a journal (file attached) the same way you've told me to create a transcript, and then I specified its execution through Execute Commands (file attached).

Unfortunately, when I run the simulatio and it passes from one time step to the following it gives an error message (file attached).

Strangely, when I click 'ok' on the error message, the simulation continues (it doesn't do it until I hit the 'ok') and if I cancel iterating Fluent just blows away and disappear.

I have saved the journal file in the same folder where the .cas and .dat files are and when exporting the ASCII files they also should be stored in the same folder (see journal file).

I don't know what I'm doing badly...
Attached Images
File Type: png execute_command.PNG (16.2 KB, 62 views)
File Type: png error.PNG (35.4 KB, 50 views)
Attached Files
File Type: zip save_data.zip (515 Bytes, 34 views)
IvanCFD is offline   Reply With Quote

Old   May 17, 2010, 14:03
Default
  #16
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 647
Rep Power: 11
dmoroian is on a distinguished road
You'll have to experiment with this, but for the moment try changing:
Code:
(cx-gui-do cx-set-text-entry "Select File*FilterText" "e:\3_re_fluent_with_actuator\active\1hz\\*")
(cx-gui-do cx-activate-item "Select File*Apply")
(cx-gui-do cx-set-text-entry "Select File*Text" "x1_%6t.dat")
(cx-gui-do cx-activate-item "Select File*OK")
with:

Code:
(cx-gui-do cx-set-text-entry "Select File*FilterText" "e:\3_re_fluent_with_actuator\active\1hz\*")
(cx-gui-do cx-set-text-entry "Select File*Text" "x1_%6t.dat")
(cx-gui-do cx-activate-item "Select File*OK")
dmoroian is offline   Reply With Quote

Old   May 18, 2010, 08:37
Default
  #17
Member
 
Ivan
Join Date: Aug 2009
Posts: 63
Rep Power: 8
IvanCFD is on a distinguished road
Hi Dragos,

thanks it works. Well, it works half-way...

At least I don't get that error any more. However, it doesn't behave as expected for 2 reasons:

1) Even though in the journal is clearly said (see attached file) that the data as to be saved here:

E:\3_RE_FLUENT_WITH_ACTUATOR\ACTIVE\1Hz\DATA_OUTPU T

it saves here:

E:\3_RE_FLUENT_WITH_ACTUATOR\ACTIVE\1Hz

(see attached picture)

2) Once Fluent saves the data and go for the next time step, the programme crashes due to out of memory (see attached picture).

This is curious because before, when I wasn't running the journal (and therefore not saving data files), Fluent kept working normally from one step to ther next one, over and over, without complaining about out of memory.

Do you have any clue?

Thanks a lot.

Ivan.
Attached Images
File Type: png error1.PNG (46.9 KB, 30 views)
File Type: jpg error2.jpg (71.6 KB, 36 views)
Attached Files
File Type: zip save_data.zip (405 Bytes, 18 views)
IvanCFD is offline   Reply With Quote

Old   May 19, 2010, 03:02
Default /file/export ascii data_output/bubu.txt 13 () no pressure () no
  #18
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 647
Rep Power: 11
dmoroian is on a distinguished road
Here come some comments:
1. The "Apply" line should not be removed (although it was my previous suggestion). This should fix the path for the output data.
2. In the picture you present there is a last command involving the stop of macro recording, which should not be there (and your archive doesn't contain it). I suspect this may be the cause of fluent crash (although it shouldn't).
3. I think it is time for you to go further and try the TUI instead of GUI. The whole script should be:
Code:
/file/export ascii data_output/bubu.txt 13 () no pressure () no
You can run the above command directly in the text interface, or include it in a file called e.g. "tui.jou" and run it in the text interface or "Execute Commands..." with "file rj tui.jou".
This is just a starting point, and I'm sure you can take it from here.
dmoroian is offline   Reply With Quote

Old   May 19, 2010, 05:18
Default
  #19
Member
 
Ivan
Join Date: Aug 2009
Posts: 63
Rep Power: 8
IvanCFD is on a distinguished road
Hi Dragos,

thanks for your comments.

There's something weird going on... As you say, on Fluent's screenshot it is said:

> (cx-gui-do cx-activate-item "Export*PanelButtons*PushButton2(Cancel)")
> (cx-gui-do cx-activate-item "MenuBar*WriteSubMenu*Stop Journal")


However,the actual journal file just contains:

(cx-gui-do cx-activate-item "MenuBar*FileMenu*Export...")
(cx-gui-do cx-set-toggle-button "Export*Frame1*Table1*Frame8(Delimiter)*ToggleBox8 (Delimiter)*Space" #f)
(cx-gui-do cx-activate-item "Export*Frame1*Table1*Frame8(Delimiter)*ToggleBox8 (Delimiter)*Space")
(cx-gui-do cx-set-list-selections "Export*Frame1*Table1*Frame2*List2(Surfaces)" '( 13))
(cx-gui-do cx-activate-item "Export*Frame1*Table1*Frame2*List2(Surfaces)")
(cx-gui-do cx-activate-item "Export*PanelButtons*PushButton1(OK)")
(cx-gui-do cx-set-text-entry "Select File*FilterText" "e:\3_re_fluent_with_actuator\active\1hz\data_outp ut\\*")
(cx-gui-do cx-set-text-entry "Select File*Text" "x1_%6t.dat")
(cx-gui-do cx-activate-item "Select File*OK")


Therefore, there's nothing in the journal file related to a previous version of the journal file. But I can guarantee you that I smashed the former journal file.

Besides, Fluent complains about malloc out of memory...

IvanCFD is offline   Reply With Quote

Old   May 19, 2010, 06:12
Default
  #20
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 647
Rep Power: 11
dmoroian is on a distinguished road
Most likely you run a journal file that is different from what you think it has inside. Did you try my version of script?
dmoroian is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Working directory via command line Luiz CFX 4 March 6, 2011 21:02
UDF Getting data from file jreig FLUENT 0 July 10, 2009 08:07
Smallest binary file format to save large data Zonexo Main CFD Forum 2 June 2, 2008 20:25
Axisymmetrical mesh Rasmus Gjesing (Gjesing) OpenFOAM Native Meshers: blockMesh 10 April 2, 2007 14:00
UDF (write a data file) problem lichun Dong FLUENT 2 July 29, 2005 11:39


All times are GMT -4. The time now is 11:59.