how can my UDF write output files with the flow time as part of the file name


A common request from users is for the name of output files written from a UDF to be appended with the flow time. This may be confusing for someone who has no formal training in C-programming, but it is relatively easy to do, as seen in the example below. The format of the output file name and the programming itself may not be particularly elegant, but it is quick and effective. The DEFINE_ON_DEMAND macro in the example below can be automatically executed once per time step (or once every N time steps) by opening the Execute Commands panel (Solve > Execute Commands), increasing the number of commands by one, selecting "Time Step" instead of "Iteration" below "When" and entering the following command in the Command field

de ud eod "test"

The command above is shorthand for the TUI command to execute a DEFINE_ON_DEMAND function. In your own problem, "test" would be replaced with the name of your own function
/* Example of UDF to append output file with current flow time */

#include "udf.h"

DEFINE_ON_DEMAND(test)
{
Domain *d = Get_Domain(1);
real sol_flow_time;
char buf[64];
char str2[64];

FILE *fout;

strcpy(buf,"temperatureoutput");

sol_flow_time = CURRENT_TIME;
/* Programmer is responsible for making sure that str2 has enough space to hold
solution flow time and buf has enough space so it can be concatenated with
str2 */

sprintf(str2,"%f",sol_flow_time);

strcat(buf,str2);

fout = fopen(buf,"a");
fprintf(fout,"testn");
}





Show Form
No comments yet. Be the first to add a comment!