CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > CFX

Integrating/Interfacing cfx with Matlab

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree3Likes

Reply
 
LinkBack Thread Tools Display Modes
Old   April 3, 2011, 19:27
Default Integrating/Interfacing cfx with Matlab
  #1
Member
 
Darren Leong
Join Date: Dec 2010
Posts: 64
Rep Power: 6
Darren Leong is on a distinguished road
Hi guys,

I need help from you all on whether using Matlab to control ANSYS CFX simulation is possible. The immediate goal of my work is to setup MATLAB to write the input files for CFX and then read the output data when the simulation has finished. The work then progresses into using MATLAB to initiate the simulations. I have looked through the forum, ansys help&tutorials, & google with no clear findings on how this is achieved, with Fluent being the exception.

Highly appreciate if someone can shed more light on this matter and i'll ask more questions as we go. If it's vaguely possible, I'm happy to work on it and share my work with the forum community. I am familiar with Ansys CFX.

To give a bit more detail, the simulation involves moving 2 bodies in respect to one another.

Warmest Regards,
Darren

Last edited by Darren Leong; April 3, 2011 at 20:12.
Darren Leong is offline   Reply With Quote

Old   April 4, 2011, 19:16
Default
  #2
Super Moderator
 
Glenn Horrocks
Join Date: Mar 2009
Location: Sydney, Australia
Posts: 10,647
Rep Power: 84
ghorrocks has a spectacular aura aboutghorrocks has a spectacular aura aboutghorrocks has a spectacular aura about
CFX can be run from the command line, so can be put in as part of a script. So if matlab can call a command line then this should be possible.
ghorrocks is online now   Reply With Quote

Old   April 4, 2011, 22:20
Default
  #3
Member
 
Darren Leong
Join Date: Dec 2010
Posts: 64
Rep Power: 6
Darren Leong is on a distinguished road
Thx, Glenn.

Ran some batch files from cmd and that worked, but i've yet to try it on MATLAB. Haven't used MATLAB to run external programs before so I thought to post a question here 1st for reference as the work progresses.

I'm trying to get 3D mesh deformation & remeshing to work in CFX at the moment. I'll start another post on that topic when I have some results or questions since it's still a beta feature in v13.

Best wishes,
Darren
Darren Leong is offline   Reply With Quote

Old   April 27, 2011, 22:02
Default
  #4
Member
 
Darren Leong
Join Date: Dec 2010
Posts: 64
Rep Power: 6
Darren Leong is on a distinguished road
Hi again,

I've got a batch of remesh simulations running in CFX through Matlab. I've only been able to use the 'edit' function in Matlab to modify the input (.CCL) files directly so far though.

I'm struggling to figure out how to get Matlab to plot the results; forces and moments from transient runs. If anyone's done it before, i'll be very grateful if some guidance can be given.

Best wishes,
Darren
Darren Leong is offline   Reply With Quote

Old   April 28, 2011, 18:27
Default
  #5
Super Moderator
 
Glenn Horrocks
Join Date: Mar 2009
Location: Sydney, Australia
Posts: 10,647
Rep Power: 84
ghorrocks has a spectacular aura aboutghorrocks has a spectacular aura aboutghorrocks has a spectacular aura about
CFX V13 has built in mesh deformation and remeshing stuff. Should be no need to couple with matlab. Have you looked at that?

CFX can output forces, moments and lots of other stuff easily by outputting it to a monitor point and then you can either manually export it from the solver manager or automatically parse it from the mon file.
ghorrocks is online now   Reply With Quote

Old   May 1, 2011, 20:52
Default
  #6
Member
 
Darren Leong
Join Date: Dec 2010
Posts: 64
Rep Power: 6
Darren Leong is on a distinguished road
I'm using Matlab only to execute CFX-solver as an external program, e.g. changing the input variable once the setup (remeshing config and .cfx) is stable and reading the results while being handoff as possible from ANSYS interface. The only reason i'm using CFX is that it's the most familiar package to me. Alternative solvers considered are Fluent or Openfoam once the capabilities have been developed.

It would nice if I could preset to collate/process them in cfx-pre without going into solver manager and exporting it manually from there. I was hoping there might be a suffix command i can used in the batch file for this.

I'm not sure of and can't locate the 'mon' file, do i need to setup for it to be created at the end of solution?

The monitor plot values for transient runs are stored as individual files (.trn) for each timestep. That's about 500+ files to read just get the values out for Matlab to plot. I've not parse that many files before in Matlab. I'll work on this if there's no shortcut to it.

Last edited by Darren Leong; May 2, 2011 at 09:19.
Darren Leong is offline   Reply With Quote

Old   May 2, 2011, 07:44
Default
  #7
Super Moderator
 
Glenn Horrocks
Join Date: Mar 2009
Location: Sydney, Australia
Posts: 10,647
Rep Power: 84
ghorrocks has a spectacular aura aboutghorrocks has a spectacular aura aboutghorrocks has a spectacular aura about
The mon file is a temporary file which is generated in the CFX temporary folder when the simulation is running. It is deleted when the simulation completes. You can also use a cfx command - I forget which one, cfx5monitor or something like that - to extract monitor point info.
ghorrocks is online now   Reply With Quote

Old   May 2, 2011, 09:25
Default
  #8
Member
 
Darren Leong
Join Date: Dec 2010
Posts: 64
Rep Power: 6
Darren Leong is on a distinguished road
That's a relief to know ^_^!

Will post the findings when I get everything to work. Thanks, Glenn!!

Last edited by Darren Leong; May 2, 2011 at 09:48.
Darren Leong is offline   Reply With Quote

Old   May 2, 2011, 19:13
Default
  #9
Super Moderator
 
Glenn Horrocks
Join Date: Mar 2009
Location: Sydney, Australia
Posts: 10,647
Rep Power: 84
ghorrocks has a spectacular aura aboutghorrocks has a spectacular aura aboutghorrocks has a spectacular aura about
Found the command - cfx5mondata. Should do the trick for you.
ghorrocks is online now   Reply With Quote

Old   May 26, 2011, 00:35
Default
  #10
Member
 
Darren Leong
Join Date: Dec 2010
Posts: 64
Rep Power: 6
Darren Leong is on a distinguished road
Thanks, Glenn =)

The following is what i used and seems to be working well.

!"C:\Program Files\ANSYS Inc\v130\CFX\bin\cfx5mondata" Spheresim_001.res -varrule "CATEGORY = USER POINT" -output Analysis_Results_001.dat
Darren Leong is offline   Reply With Quote

Old   July 26, 2011, 11:33
Default could u help
  #11
New Member
 
lisa
Join Date: Apr 2009
Posts: 13
Rep Power: 8
lisa is on a distinguished road
I am new to CFX and Fortran, I am trying to read a Matlab file in a text format in CFX carry out simulation and pass the result to Matlab and do the calculation and read back it.

Is it possible in CFX. Kindly let me know.

Thanks
with regards
sesan
lisa is offline   Reply With Quote

Old   July 26, 2011, 18:50
Default
  #12
Super Moderator
 
Glenn Horrocks
Join Date: Mar 2009
Location: Sydney, Australia
Posts: 10,647
Rep Power: 84
ghorrocks has a spectacular aura aboutghorrocks has a spectacular aura aboutghorrocks has a spectacular aura about
Yes, this is possible. You can either code it in fortran yourself or use MPCCI to handle the coupling. I think CFX still has MPCCI handles in it. Up to you.
ghorrocks is online now   Reply With Quote

Old   July 27, 2011, 04:39
Default
  #13
New Member
 
lisa
Join Date: Apr 2009
Posts: 13
Rep Power: 8
lisa is on a distinguished road
Hi Glenn,

Thanks for your reply. I am also new in Fortran programming and MPCCI, Could you kindly tell me on how exactly i do or give me some tips.

Thanks
lisa is offline   Reply With Quote

Old   July 27, 2011, 06:01
Default
  #14
Super Moderator
 
Glenn Horrocks
Join Date: Mar 2009
Location: Sydney, Australia
Posts: 10,647
Rep Power: 84
ghorrocks has a spectacular aura aboutghorrocks has a spectacular aura aboutghorrocks has a spectacular aura about
I think some of the CFX examples use fortran. Otherwise contact CFX support for examples. MPCCI is a separate piece of commercial software designed to interface between simulation codes. Google it.
ghorrocks is online now   Reply With Quote

Old   September 10, 2011, 04:46
Default
  #15
Member
 
Darren Leong
Join Date: Dec 2010
Posts: 64
Rep Power: 6
Darren Leong is on a distinguished road
Hi Sessan,

Follow up to your PM, I thought i post the m files here:
http://www.2shared.com/file/3A-LkWtc/CFXMatlab.html

They're pretty basic at the moment as I haven't looked much into it since my last post. However, I'll be working on it in the coming months and it would be great if we can as much help as possible in getting this working =)
Darren Leong is offline   Reply With Quote

Old   September 22, 2011, 06:53
Default hi
  #16
New Member
 
lisa
Join Date: Apr 2009
Posts: 13
Rep Power: 8
lisa is on a distinguished road
Hi Darren

Thanks for the reply and sorry i culdnt get back earlier.

The link in which u had sent the files is no longer valid, culd you kindly send the file again. In between could you also share your mail id for contact .

Thanks in adavance for the help.
Wih regards
Sesan.
lisa is offline   Reply With Quote

Old   October 4, 2011, 01:45
Default
  #17
Member
 
Darren Leong
Join Date: Dec 2010
Posts: 64
Rep Power: 6
Darren Leong is on a distinguished road
http://www.2shared.com/file/z2WErPbu/CFXMatlab.html
Lionel Trébuchon likes this.
Darren Leong is offline   Reply With Quote

Old   October 4, 2011, 05:13
Default
  #18
New Member
 
lisa
Join Date: Apr 2009
Posts: 13
Rep Power: 8
lisa is on a distinguished road
Thanks for sharing the files.
lisa is offline   Reply With Quote

Old   February 14, 2012, 02:04
Default
  #19
Member
 
Darren Leong
Join Date: Dec 2010
Posts: 64
Rep Power: 6
Darren Leong is on a distinguished road
For Lisa and others,

From where the previous script left off, we have the following example

______________________________________________
!"C:\Program Files\ANSYS Inc\v130\CFX\bin\cfx5solve" -def Simulation.def -ccl Simulation.ccl

copyfile ('*.res','results\'); %Backup current result

% To maintain the filename format for looping; easiest way is to remove the
% suffix '_00#' from current result file and so on
delete ('Simulation.res'); %remove previous run result
!ren *.res Simulation.res

% Extract data from result file to csv format
!"C:\Program Files\ANSYS Inc\v130\CFX\bin\cfx5mondata" Simulation.res -varrule "CATEGORY = USER POINT" -output CFXResult.dat


% Reads the most recent CFX timestep results
ResultData = csvread ('CFXResult.dat',1,0);
[m,n]=size(ResultData);
ResultData = csvread ('CFXResult.dat',m,0);

% You can now assign names to the variables to be computed by your MATLAB code
Accumulated_Time =ResultData(1,1);
Force_X = ResultData(1,2);

% compute the new states
<Your code> % For example, it computes
Inlet_Speed = 5 % in m/s


% Opens the .ccl file and format it into cell arrays
A = fopen('Simulation.ccl','rt+');
B = textscan(A,'%s %s %s %s %s %s %s');
% number of '%s' depends on the number of space delimited columns

%combines the arrays into one matrix of cell arrays
C = horzcat(B{1,1},B{1,2},B{1,3},B{1,4},B{1,5},B{1,6}, B{1,7});

% you can now replace the variables of the .ccl file easily since their
% position should always be the same in the matrix

C{6,3} = num2str(Inlet_Speed);
% assuming 6,3 is the position of the variable.
%'num2str' is needed or else it'll introduce '[]' into your text file

%To reconstruct your .ccl text file with the new variables
[nrows,ncols]= size(C);
filename='SimulationNew.ccl';
fid=fopen(filename,'W');
for row=1:nrows;
fprintf(fid,'%s %s %s %s %s %s %s\r\n',C{row,:});
end

delete ('Simulation.ccl');
!ren SimulationNew.ccl Simulation.ccl
fclose all;

% You can now continue your simulation from the previous result
% with the new input variable
!"C:\Program Files\ANSYS Inc\v130\CFX\bin\cfx5solve" -def Simulation.def -ccl Simulation.ccl -cont-from-file Simulation.res
echo off

_________________________________________

Hope it works for you all.

Best wishes,
Leong
happy and samane_81 like this.

Last edited by Darren Leong; February 14, 2012 at 19:04.
Darren Leong is offline   Reply With Quote

Old   December 22, 2012, 12:39
Default
  #20
New Member
 
hi
Join Date: Dec 2012
Posts: 19
Rep Power: 4
alikhube is on a distinguished road
Hi
I'm working on optimization problem
pleas help me how to call cfx from matlab for solving and post processing?
Is this problem have specific setting at CFX and matlab code?
Pleas help me
Thank Everyone

Last edited by alikhube; December 25, 2012 at 15:53.
alikhube is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cfx - matlab camilo_costa CFX 15 October 14, 2013 17:18
Matlab & CFX Meri CFX 1 March 16, 2006 01:39
CFX 7.1 and Matlab Juan G. CFX 1 March 5, 2006 22:37
CFX & MatLab Walid CFX 4 March 8, 2005 17:30
How to make data file for matlab from CFX? cfxbeginner CFX 4 October 19, 2002 07:56


All times are GMT -4. The time now is 08:33.