Order Matlab not to continue until the external run is completed

19 visualizzazioni (ultimi 30 giorni)
Dear all,
I am runing Ansys Fluent in Matlab by the system command and using journal file. I want Matlab to wait until the Fluent run is finished and the results are ready then go to other sections and manipulate data. However, when I run the code it just run fluent and go to the other sections afterward without hesitation. how I can define for Matlab wait until the run is completed then go to the other sections?
BR
  4 Commenti
zeinab seifi
zeinab seifi il 7 Lug 2022
Thank you walter. I used that but it wasnt what I wanted. :(
zeinab seifi
zeinab seifi il 8 Lug 2022
Dear Walter it is not -gr it was -hidden. Thank you it helped me so much

Accedi per commentare.

Risposta accettata

Bruno Luong
Bruno Luong il 7 Lug 2022
% delete the 'result.csv'
system('remove result.csv') % add the appropiate path to csv file
% launch your fluent software
system('F:\"Program Files"\"ANSYS Inc"\v195\fluent\ntbin\win64\fluent.exe 2ddp -t4 -i filename.jou'); % RUN ANSYS
% ...
% then do this to wait
while true
if exist('result.csv', 'file') > 0 % add the appropiate path to csv file
break
end
pause(1); % check every second
end
% you might want to wait more until the csv file is fully written by fluent

Più risposte (1)

Karim
Karim il 7 Lug 2022
Asuming you are using windows. You can can just add the
[~,~]
as output to the system command, this way matlab will wait until the process is finished. The last of the two outputs would normally gather the command output.
I'm not familiair with the calling fluent from matlab. But in the case of nastran it looks like this:
NastranExec = "C:\Program Files\NXNASTRAN\bin\nastran.exe";
InputFile = "C:\Data\TestFile.bdf";
[~,~] = system([NastranExec,' "',InputFile,'" out="C:\MyRes\" sdir="C:\ScratchDir\" scr=yes old=yes']);
  5 Commenti
Walter Roberson
Walter Roberson il 7 Lug 2022
When you call system(), whether you use any outputs for the call or not, system() follows these rules:
  • if the command ends in & then the process is run in the background and system() returns as soon as the process starts. This is handled by MATLAB examining the command, regardless of what shell is being used
  • if you are using MacOS or Linux, then some command forms result in the process running in the background. For example system('ls & > ~/MyOutput.txt') would (probably) not have the & detected by MATLAB itself (since the & is not at the end) but Unix-type shells would interpret it as a background request
  • otherwise, MATLAB waits for the command itself to finish. However... if the command causes a graphic program to start, then that graphic program is probably going to be a different process than the command itself, and the command itself would return immediately after starting the graphic program. For example, if you were to start Microsoft Word, then that would launch the graphic user interface and return, and system() would believe that the command is finished (because in a sense it is finished.) It would be a technical challenge to program system() to be able to detect such cases and not return until all the spawned processes were finished.
That last point is why I was talking about the -gr option: if a graphic window is permitted to start, then the graphic window would likely be disconnected from the command that started it, but if you tell the ANSYS not to start graphics then it should operate in "batch mode" and wait for the journal to finish.

Accedi per commentare.

Categorie

Scopri di più su Programming in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by