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 pause a simulation

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By ASimonsen

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 6, 2017, 03:26
Default [SOLVED] How to pause a simulation
  #1
New Member
 
Anders Simonsen
Join Date: Sep 2013
Posts: 18
Rep Power: 13
ASimonsen is on a distinguished road
RESOLVED!

Hi.

Do anyone know any way to pause a simulation through UDF's? The pause should be around 10 second. I'm using ANSYS Fluent 18.0.

I'm running my code in parallel, and I've tried to make a while-loop on the host, but this requires a lot of computational power, which is not acceptable for my application, as other calculation are executed externally in other programs in the pause-time.

Kind regards Anders


I figured it out - I simply had to sleep/pause on all nodes+host:


http://imgur.com/2kZegMK

Correct:
Code:
#include "udf.h"
#include <stdlib.h>

DEFINE_ON_DEMAND(WaitPause)
{
	Message("Start...");
	sleep(10);
	Message("stop!\n");
}
Incorrect:
Code:
#include "udf.h"
#include <stdlib.h>

DEFINE_ON_DEMAND(WaitPause)
{
#if !RP_NODE
	Message("Start...");
	sleep(10);
	Message("stop!\n");
#endif
}
Kind regards Anders

Last edited by ASimonsen; February 6, 2017 at 10:25. Reason: Resolved the problem
ASimonsen is offline   Reply With Quote

Old   February 6, 2017, 11:10
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Although your solution does what you want, and is probably the easiest, it is not the nicest solution.

You stop the simulation for 10 seconds to let another program do a calculation. But what if, for some reason, the other program takes 11 seconds to produce a result? Or does it take 1 second to calculate it, and do you wait 9 extra seconds just in case?

A better way is to send a signal between Fluent and the external program, to tell each other whose turn it is. The signal can be many things, but I think a file is easiest to code. If the file exists, Fluent should wait, if the file does not exist, Fluent should run.

In Pseudo-code: Fluent should do:
Code:
[after a time step]
 fsignal=fopen("signal.txt","w");fclose(fsignal);
 while (file_exists("signal.txt")) {
   /* do nothing */
 }
[continue with the next time step]
And your external program should do this:
Code:
 while (!file_exists("signal.txt")) {
   /* do nothing */
 }
 do_the_things_you_need_done();
 repeat_this_code;
The code above is only intended to explain the concept, and is not meant to compile. If you want to use this, you have to implement this concept yourself.

As long as your (ASimonsen's) simulation does what you want, just keep it the way it is. I put the text above mainly for somebody else in the future that has a similar question and ends up on this page.
pakk is offline   Reply With Quote

Old   February 6, 2017, 11:35
Default
  #3
New Member
 
Anders Simonsen
Join Date: Sep 2013
Posts: 18
Rep Power: 13
ASimonsen is on a distinguished road
Hi pakk

Thanks for your reply. The 10s pause was only an example, and it'll be implemented differently. Both programs are allowed to be paused at the same time, but I'll limit this "downtime" to 1s by implementing it as:

Fluent:
Code:
while (1) {
    FileExists <- "Check for file existence - fopen("File.txt","r") or something."
    if (FileExists)
        break;
    sleep(1);
}
// Do 5-20 Fluent iterations and return to the above.
If I implement it without the sleep(1) command, Fluent takes up all available CPU power, and the external program (Matlab in my case) will execute slowly.

Anders
pakk likes this.
ASimonsen is offline   Reply With Quote

Reply

Tags
pause, sleep, wait


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 pause a transient simulation and resume without time step advancement? aleisia Main CFD Forum 33 June 12, 2017 12:41
Simulation of high pressure diesel injector - all phases compressible with cavitation fivos CFX 4 July 30, 2015 07:48
mass flow rate issue in supersonic nozzle simulation xkang FLUENT 0 July 31, 2014 17:06
Simulation of a complex wing in solidworks flow simulation niels1900 FloEFD, FloWorks & FloTHERM 6 April 20, 2011 11:44
Continuous vs interrupted simulation sega OpenFOAM Running, Solving & CFD 4 November 3, 2008 15:29


All times are GMT -4. The time now is 16:15.