CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (http://www.cfd-online.com/Forums/fluent-udf/)
-   -   UDF save data to a file!! (http://www.cfd-online.com/Forums/fluent-udf/72509-udf-save-data-file.html)

spk February 8, 2010 14:48

UDF save data to a file!!
 
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);
}

dmoroian February 9, 2010 08:15

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);
}


spk February 9, 2010 14:39

Thanks friend!!!
It works!!!
:)

IvanCFD May 14, 2010 05:10

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.

dmoroian May 14, 2010 13:06

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).

IvanCFD May 14, 2010 13:18

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.

dmoroian May 14, 2010 15:41

Well, one of the facilities is that you can automatically change the name of the output file every iteration or every time step.

IvanCFD May 14, 2010 15:50

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.

dmoroian May 14, 2010 17:45

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".

IvanCFD May 17, 2010 04:40

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.

dmoroian May 17, 2010 05:15

Quote:

Originally Posted by IvanCFD (Post 259046)
...
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

IvanCFD May 17, 2010 05:43

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.

louiza May 17, 2010 05:51

two energy equation
 
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

dmoroian May 17, 2010 06:13

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.

IvanCFD May 17, 2010 10:05

3 Attachment(s)
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...

dmoroian May 17, 2010 14:03

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")


IvanCFD May 18, 2010 08:37

3 Attachment(s)
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.

dmoroian May 19, 2010 03:02

/file/export ascii data_output/bubu.txt 13 () no pressure () no
 
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.

IvanCFD May 19, 2010 05:18

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...

:confused:

dmoroian May 19, 2010 06:12

Most likely you run a journal file that is different from what you think it has inside. Did you try my version of script?


All times are GMT -4. The time now is 18:29.