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

how to write case and data with DEFINE_EXECUTE_AT_END

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

Reply
 
LinkBack Thread Tools Display Modes
Old   October 18, 2012, 22:02
Default how to write case and data with DEFINE_EXECUTE_AT_END
  #1
Senior Member
 
François Grégoire
Join Date: Jan 2010
Location: Laval University, Canada
Posts: 366
Rep Power: 8
macfly is on a distinguished road
For example:

DEFINE_EXECUTE_AT_END(timetosave)
{
real t = CURRENT_TIME;
if (t==10)
????save the case and data file for future postprocessing????
}


What is the command for "????save the case and data file for future postprocessing????"

Thanks,
Regards,
François
macfly is offline   Reply With Quote

Old   October 18, 2012, 22:47
Default
  #2
Senior Member
 
Ji Junjie
Join Date: Feb 2010
Location: Shanghai, China
Posts: 106
Rep Power: 7
gearboy is on a distinguished road
same as the C language. Use fopen, fprintf, fclose

Quote:
Originally Posted by macfly View Post
For example:

DEFINE_EXECUTE_AT_END(timetosave)
{
real t = CURRENT_TIME;
if (t==10)
????save the case and data file for future postprocessing????
}


What is the command for "????save the case and data file for future postprocessing????"

Thanks,
Regards,
François
gearboy is offline   Reply With Quote

Old   October 18, 2012, 22:53
Default
  #3
Senior Member
 
François Grégoire
Join Date: Jan 2010
Location: Laval University, Canada
Posts: 366
Rep Power: 8
macfly is on a distinguished road
Hi Ji,

I'm familiar with fopen, fprintf and fclose in Matlab, and I understand your answer, but this is not what I'm looking for. I have dozens of variables to save in multiple 3D domains, there must be an elegant way to simply write ALL the data just as we do in the GUI via File\Write\Data...

So, again, what would be the UDF command for "File\Write\Data..." and modify filename each time?

François
macfly is offline   Reply With Quote

Old   October 21, 2012, 22:06
Default
  #4
Senior Member
 
Ji Junjie
Join Date: Feb 2010
Location: Shanghai, China
Posts: 106
Rep Power: 7
gearboy is on a distinguished road
Sorry for my error. If you want to save case and data at each iteration, you can "File->Write->Autosave" menu to save case and data and set the auto save frequency as "1".




Quote:
Originally Posted by macfly View Post
Hi Ji,

I'm familiar with fopen, fprintf and fclose in Matlab, and I understand your answer, but this is not what I'm looking for. I have dozens of variables to save in multiple 3D domains, there must be an elegant way to simply write ALL the data just as we do in the GUI via File\Write\Data...

So, again, what would be the UDF command for "File\Write\Data..." and modify filename each time?

François
gearboy is offline   Reply With Quote

Old   October 21, 2012, 22:34
Default
  #5
Senior Member
 
François Grégoire
Join Date: Jan 2010
Location: Laval University, Canada
Posts: 366
Rep Power: 8
macfly is on a distinguished road
Ji,

I know about the autosave option. I have good reasons for wanting to save at specific 'flow times' only : my timestep changes with time and I only want to save at every 24h of 'flow time'.

An example: Let's say my timestep is 10 s during the first 5 h of flow time, and then my timestep is 5 min for the next 3 days of flow time, what will autosave at every 10 simulations do? It will save at every 100 s of flow time for the first 5 hours, and then it will save at every 50 min for the rest of simulation... Not what I want. I want to tell Fluent : at every 24 hours of flow time (for example), save all data, REGARDLESS OF TIME STEP.

I can't believe it's not possible to do that elegantly (without the use of endless fprintf commands throughout all my domains...), there must be a way!
macfly is offline   Reply With Quote

Old   October 22, 2012, 05:18
Default
  #6
Senior Member
 
Ji Junjie
Join Date: Feb 2010
Location: Shanghai, China
Posts: 106
Rep Power: 7
gearboy is on a distinguished road
Ok, I got your point. Then you can use the following code in UDF.


char* file_name="example-100s.cas";
char scheme_command[1000];
if(CURRENT_TIME==100)
{
sprintf(scheme_command,"(write-case-data \"%s\")", file_name);
CX_Interpret_String(scheme_command);
}

But as I know, it only works in serial version.

If you want to realize the function in parallel version, I think you should program with scheme language. Here is an example of writing case and data at 100s.


(if (= 100 (rpgetvar 'flow-time)) (write-case-data "example-100s.cas") (display "not 100s, do nothing\n"))

Copy the above source into the command input box from "solve->Execute Commands..." menu

temp.png

Then, Fluent will auto save your case and data at 100s and do nothing at other time.



Quote:
Originally Posted by macfly View Post
Ji,

I know about the autosave option. I have good reasons for wanting to save at specific 'flow times' only : my timestep changes with time and I only want to save at every 24h of 'flow time'.

An example: Let's say my timestep is 10 s during the first 5 h of flow time, and then my timestep is 5 min for the next 3 days of flow time, what will autosave at every 10 simulations do? It will save at every 100 s of flow time for the first 5 hours, and then it will save at every 50 min for the rest of simulation... Not what I want. I want to tell Fluent : at every 24 hours of flow time (for example), save all data, REGARDLESS OF TIME STEP.

I can't believe it's not possible to do that elegantly (without the use of endless fprintf commands throughout all my domains...), there must be a way!
gearboy is offline   Reply With Quote

Old   October 22, 2012, 07:49
Default
  #7
Senior Member
 
François Grégoire
Join Date: Jan 2010
Location: Laval University, Canada
Posts: 366
Rep Power: 8
macfly is on a distinguished road
Now you are talking! The 2nd option that you propose is fine with me since I want to save at a couple of flow times only => I will define a couple of 'Execute commands'.

Thanks a lot Ji.
macfly 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
How to read or write case by commands during simulation with Fluent lzgwhy FLUENT 4 April 20, 2011 22:02
Unable to write case and data...! sushii FLUENT 4 December 7, 2007 02:12
fluent case n data files not exporting to tecplot krishna FLUENT 2 February 18, 2007 00:24
how to save case data and data during iteration? JOHN FLUENT 3 October 10, 2006 19:40
How to update polyPatchbs localPoints liu OpenFOAM Running, Solving & CFD 6 December 30, 2005 18:27


All times are GMT -4. The time now is 14:04.