|
[Sponsors] |
April 14, 2013, 08:53 |
Cannot Execute on Demand
|
#1 |
New Member
Join Date: Apr 2013
Location: Netherlands
Posts: 2
Rep Power: 0 |
Dear forum users,
I am new to Fluent and have the following problem: I compile an ON_DEMAND UDF: ===== #include "udf.h" DEFINE_ON_DEMAND(on_demand_calc) { Domain *d; Thread *t; d = Get_Domain(1); printf("Hello World\n"); } ====== It compiles without errors, then I Load it. When I go to Define-> User-Defined -> Execute on Demand, choose "on_demand_calc::libudf", and press Execute, totally nothing happens (no any new text is coming in the Fluent console). Then when I quit Fluent, the "Hello World" text appears in the console (that many times as I have pressed the Execute button) just half a second before Fluent closes. Or sometimes the text appears when I unload the "libudf" in "Manage". I have this issue for serial and parallel(3 cores) sessions of Fluent. My software and system: Ansys 14.5 Windows 8 MS Visual Studio 2010. Can anybody please give a suggestion what is going wrong? Thanks in advance! Last edited by Denis; April 14, 2013 at 15:25. |
|
April 15, 2013, 06:33 |
|
#2 |
Senior Member
Max
Join Date: Mar 2009
Posts: 133
Rep Power: 17 |
Your code is definitely ok, maybe there is something in the GUI going on.
Try Message0("Hello World\n") instead of printf and see what happens. cheers |
|
April 19, 2013, 10:19 |
|
#3 |
New Member
Join Date: Apr 2013
Location: Netherlands
Posts: 2
Rep Power: 0 |
Thank you, the Message("Hello World\n"); worked.
|
|
March 5, 2018, 05:09 |
Similar problem
|
#4 |
Member
Sai Guruprasad Jakkala
Join Date: Jan 2017
Posts: 34
Rep Power: 9 |
I am facing a similar problem while interpreting an EXECUTE_AT_END udf. I need to print values into a file at the end of each iteration, but it does not. After I close the Fluent session, it writes the values to the file in the reverse order.
Code: #include"udf.h" FILE *fout; DEFINE_EXECUTE_AT_END(trial_1) { Domain *mixture_domain; Domain *subdomain; int phase_domain_index; float t; float a; real xx,yy; float ct; cell_t cell; Thread *cell_thread; real xc[ND_ND]; mixture_domain=Get_Domain(1); t=CURRENT_TIME; fout=fopen("a.out","a"); xx=0; yy=0; ct=0; sub_domain_loop(subdomain, mixture_domain, phase_domain_index) { fprintf(fout,"\n %f \n",t); if (DOMAIN_ID(subdomain) == 3) { thread_loop_c(cell_thread,subdomain) { begin_c_loop_all(cell,cell_thread) { C_CENTROID(xc,cell,cell_thread); a=C_VOF(cell,cell_thread); xx+=a*xc[0]; yy+=+a*xc[1]; ct=ct+1; } end_c_loop_all(cell,cell_thread) } } } fprintf(fout,"%g %g \n",xx,yy); } The output appears like this(I have put only the start of the output file): 0.005000 0.005000 4233.25 4220.46 0.004000 0.004000 4233.21 4220.42 It decreases till zero timestep. How can I make it print in the correct order and after each timestep instead of closing the fluent session? |
|
March 5, 2018, 06:56 |
|
#5 |
Senior Member
Join Date: Sep 2017
Posts: 246
Rep Power: 12 |
Hi Sai Guruprasad,
It is slightly weird that you get the output in reverse order, but the outcome of your code is highly implementation-dependent, and reliant on buffering etc. See for example https://wiki.sei.cmu.edu/confluence/...s+already+open The current sequence is: (1) At the first timestep, you open the file-pointer fout and write something to it. This output is saved in a buffer. The file stays open and fout retains its pointer. (2) At the next timestep, you re-open the same file and put the new file-pointer into fout. (It is unclear, implementation-dependent, etc what happens to the old file-writing sequence that was held in fout.) Then you write something, which is saved in a new buffer. ... repeat step (2) The output to the file is only sorted out when Fluent quits, and the buffers are cleared out. One answer to all this is to fclose the file pointer at the end of each UDF (and to continue to fopen it at the start of each UDF). An alternative answer is to fopen the file pointer only at the start of a group of timesteps, and then to fclose it when you want to see the output. This is slightly more efficient -- the operating system can build up a decent buffer of text, and write to file less frequently -- but the bureaucracy is possibly not worth the effort in this case. If you do go down this route, it may be helpful to initialize fout to a definite value: Code:
FILE *fout = NULL; You should be aware that this whole method is not ready for running Fluent in parallel. Good luck! Ed |
|
March 11, 2018, 02:25 |
|
#6 |
Member
Sai Guruprasad Jakkala
Join Date: Jan 2017
Posts: 34
Rep Power: 9 |
Thank you obscureed.
Putting a fclose(fout); at the end of the program helped in printing the results at the end of every time step. |
|
June 26, 2018, 05:40 |
Define on demand(copy uds to udm) in fluent
|
#7 |
New Member
sadik
Join Date: Feb 2018
Posts: 7
Rep Power: 8 |
Hello, can someone help me on how to copy uds to udm i want to copy data from uds to udm and i use the following code. But i did not copy the data.
#include "udf.h" #include"sg.h" DEFINE_ON_DEMAND(copy_uds_to_udm) { Domain*d=Get_Domain(1); Thread*t; cell_t c; thread_loop_c(t,d) { begin_c_loop(c,t) { C_UDMI(c,t,0)=C_UDSI(c,t,0); } end_c_loop(c,t) } return; } need your help. Thanks |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
execute udf after convergence | wanghaojie | Fluent UDF and Scheme Programming | 6 | April 5, 2019 03:00 |
execute udf in ss & transient simulation | hosseinhgf | FLUENT | 0 | December 1, 2010 09:41 |
error while execute on demand | Anderson | Main CFD Forum | 4 | October 17, 2008 12:48 |
On demand UDF error | RS | FLUENT | 0 | May 10, 2007 13:54 |
execute on demand | pourak | FLUENT | 0 | April 20, 2007 07:24 |