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 case and data with DEFINE_EXECUTE_AT_END

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 18, 2012, 23: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: Canada
Posts: 392
Rep Power: 17
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, 23:47
Default
  #2
Senior Member
 
Join Date: Feb 2010
Posts: 164
Rep Power: 17
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, 23:53
Default
  #3
Senior Member
 
François Grégoire
Join Date: Jan 2010
Location: Canada
Posts: 392
Rep Power: 17
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, 23:06
Default
  #4
Senior Member
 
Join Date: Feb 2010
Posts: 164
Rep Power: 17
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, 23:34
Default
  #5
Senior Member
 
François Grégoire
Join Date: Jan 2010
Location: Canada
Posts: 392
Rep Power: 17
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, 06:18
Default
  #6
Senior Member
 
Join Date: Feb 2010
Posts: 164
Rep Power: 17
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, 08:49
Default
  #7
Senior Member
 
François Grégoire
Join Date: Jan 2010
Location: Canada
Posts: 392
Rep Power: 17
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

Old   October 23, 2018, 11:18
Default save case and data by udf
  #8
Member
 
Join Date: Nov 2017
Posts: 54
Rep Power: 9
Saman95 is on a distinguished road
hello dear

I want to save my case and data in some time step not every time step

the method that u told by scheme programming save case and data every time step?

how can save my case and data by udf when I want?
Saman95 is offline   Reply With Quote

Old   October 23, 2018, 11:19
Default
  #9
Member
 
Join Date: Nov 2017
Posts: 54
Rep Power: 9
Saman95 is on a distinguished road
Quote:
Originally Posted by gearboy View Post
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

Attachment 16308

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

hello dear

I want to save my case and data in some time step not every time step

the method that u told by scheme programming save case and data every time step?

how can save my case and data by udf when I want?
Saman95 is offline   Reply With Quote

Old   November 15, 2018, 01:46
Default a problem
  #10
Member
 
Join Date: Nov 2017
Posts: 54
Rep Power: 9
Saman95 is on a distinguished road
Quote:
Originally Posted by gearboy View Post
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

Attachment 16308

Then, Fluent will auto save your case and data at 100s and do nothing at other time.
hello
your method for serial version is not work for me and I receive an error:
Error: eval: unbound variable Error Object: write-case-data


can you help me?
what can i do?
Saman95 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
How to read or write case by commands during simulation with Fluent lzgwhy FLUENT 4 April 20, 2011 23: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 20: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 12:40.