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/)
-   -   how to write case and data with DEFINE_EXECUTE_AT_END (http://www.cfd-online.com/Forums/fluent-udf/108304-how-write-case-data-define_execute_at_end.html)

macfly October 18, 2012 22:02

how to write case and data with DEFINE_EXECUTE_AT_END
 
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????":D

Thanks,
Regards,
François

gearboy October 18, 2012 22:47

same as the C language. Use fopen, fprintf, fclose

Quote:

Originally Posted by macfly (Post 387423)
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????":D

Thanks,
Regards,
François


macfly October 18, 2012 22:53

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 October 21, 2012 22:06

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 (Post 387427)
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 October 21, 2012 22:34

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 October 22, 2012 05:18

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



Quote:

Originally Posted by macfly (Post 387803)
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 October 22, 2012 07:49

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.


All times are GMT -4. The time now is 02:50.