how to export every data w.r.t time to txt file
Hello. I would like to ask you a question regariding export method. Actually, I did transient simulation to see the temperature change w.r.t time at every node. I tried to find the way to export all data at every node to txt or xls file in cfx-post. If I use a chart, then I could just export only data as many as point's no. that I defined (not all points). Also, if I use the export (file -> export)in cfx-post , I am able to get the temperature values at every point but these temperatures are only the values at the last time step (not all time steps). Could you please let me know how to export every datum (temp.) for every point at all time steps (or each time step)? Thank you so much for your concern. Have a great day~!
|
Re: how to export every data w.r.t time to txt fil
Firstly, why? I ask because there may be a better way to do what you are ultimately trying to do.
You can write a macro to loop through all of the trn files and export the data at each timestep. Start by recording a small session where you load a trn file and export the results. You can then put a PERL loop around this and subsitute PERL variables for the timestep number. Before you do this or ask more details on how (to which I'll refer you to past discussion on this forum, user documentation and tech tips on the ANSYS customer portal), please answer my first question. -CycLone |
Re: how to export every data w.r.t time to txt fil
Dear CycLone,
Thank you for your kind answer. CycLone, actually I am a notice CFX user. Unfortunately, I don't know about macro and PERL variable... Also, I have to hurry up to solve this problem because of meeting with Prof... If you don't mind, could you please explain this in detain or take an simple exampe if possible? Thanks again. Have a good day, CycLone. -Jaho |
Re: how to export every data w.r.t time to txt fil
Answer the first question: Why do you need this data? What do you intend to do with it?
|
Re: how to export every data w.r.t time to txt fil
Sorry about that. Let me explain about this. Let's say that the total simulation time is 50 sec. By the way, at the end of every 1 sec, I changed input conditions. Thus, what I need is not the final output at the end step time but the output at every second. So, each datum is important. These gathered all data points will be used for fiding optimum condition. If you need the explanation in detail, please let me know. Thank you, CycLone.
- Jaho |
Re: how to export every data w.r.t time to txt fil
How did you change, at the end of every 1 sec, your input conditions?
If you are using a few points, u can use "monitor points" on CFX-Pre. You must enter each point (x;y;z) for monitoring (checking) the temperatures! Can you send me your .cfx file? I use CFX-v5.6. |
Re: how to export every data w.r.t time to txt fil
Hi, you can create such data sets using cel interpolation... Thank you.
|
Re: how to export every data w.r.t time to txt fil
Hi Jaho,
It sound like you forgot to set the transient output up before the run. The results file only contains the solution at the last timestep. If you need intermediate results, you need to set up the transient output in the Output Control panel in CFX-Pre. There is way to recover this information after the fact. If you are running version 11 and had payed attention to the warnings, you would have seen that this is missing. You might want to run through a transient tutorial before continuing, just in case there is more you are missing. Sorry to be the bearer of bad news, but you'll have to run your analysis again. -CycLone |
Re: how to export every data w.r.t time to txt fil
Hi, CycLone. Thank you for your kind answer. For my transient simulation, I set up the transient output in the output Control panel in CFX-Pre. So, I have 'trn' files as many as total step time number. In this case, how can I solve my problem? (The only solution is what you said already (i.e., macro))? Thank you again, CycLone.
|
Re: how to export every data w.r.t time to txt fil
So, back to my original question. What do you want to calculate from the transient results, i.e. what would you do with the text files you want to export?
|
Re: how to export every data w.r.t time to txt fil
These gathered all data points will be used for designing obtimized neural network strucure of the system. Thank you...
|
Re: how to export every data w.r.t time to txt fil
So you're planning to train the neural network based on the results at each node? Interesting.
|
Re: how to export every data w.r.t time to txt fil
Here's a crude session that will do the trick. Copy and paste it into your command window in Post and substitute your starting and finishing iteration numbers as well as your desire filename. Leave the "$i" in the name, as I have done below; Post will substitute the current value of the PERL variable $i into the name when it writes the file. You should first do a manual export to select the variables you want.
!$start = 0; !$finish = 100; !for($i=$start,$i<=$finish,$i++) { > load timestep=$i EXPORT: Export File = export_$i.csv END >export !} -CycLone |
Re: how to export every data w.r.t time to txt fil
Thank you so much for your kind answer, CycLone. Have a great day~!
|
CycLone,
can you check the code again? because when I used that code to export the data the ERROR Overwrite not allowed: export_2.dat how can i solve it? thanks Hung |
Just out of curiosity, have you read the error message?
" ERROR Overwrite not allowed: export_2.dat" You're not allowed to overwrite the file, so just simply manually delete the file and run the PERL script again? I am sure that will work. |
Hi Lance
I tried many times but it doesn't work. the error still appear. Can you check it again. thanks Hung |
For example i leave the state
!$start = 0; !$finish = 33; the error will be ExportExecutor::invoke - Overwrite not allowed: export_1.csv when i chang the start to 1 the error will be export_2.csv thanks Hung |
I have the same problem as you, Hung. I've tried to delete the file in order to overcoming the overwrite but it doesn't work. Does anyone may help us?
Regards Carlitos |
Hi,
I tried to do the manual way first. overwrite the file and then tried with the code. the error message did not appear, but the export is only for 1 step. it doesnot work for the next step can someone check and give me the right code. thanks Hung |
Hi
it works by change the comma to the semicolon. cheer |
I have a similar problem:
I have a transient simulation with 100 timesteps. I recorded the .trn files for each timestep. Now I want to calculate the time averaged temperature and pressure at a certain plane (with MATLAB). How can I extract data files that contain the x,y,z coordinates and the temperature, pressure at a specific plane? and this for each timestep??? What do I have to do? Which command do I need to write into the comand editor? Where can I find helpers for the command editor language??? Thank you very much!!! |
Hello
For CFD-Post Does anybody have a macro that loads all the timesteps in a loop automatically and gives out a calculation funtion: massflowAve T_tot and P_tot at inlet and outlet.... or even better the total-to-total efficiency of a turbine at each timestep... THANK YOU VERY MUCH I only have a macro where I can export the variables at a plane (at every node).... but i would need to export the results of a macro calculator ar a function calculator... |
Hi
Sorry, I have posted below to extract variables using function calculator.
|
Hi
OK, to use function calculator and extract variables at inlet, out let or some plane
if you have trn files at different time steps lets say, case2_2.trn case2_3.trn # where 2 & 3 refers to time in sec then replace the file name in loadfilename with this and also change the increment in for loop. #************************************************* ********************* ! open(OFH, " >> file.dat"); # writing to a file # for loop start ! for ($i=1; $i <= 3; $i++) { COMMAND FILE: CFX Post Version = 11.0 END DATA READER: Clear All Objects = false Append Results = false Apply X Offset = false Apply Y Offset = false Apply Z Offset = false Keep Camera Position = true Load Particle Tracks = true END > load filename=/home/cfx5run/Ns200/var03_gvo24_full_$i.trn ! $total_temp = areaAve("Total Temperature","inlet"); ! printf (OFH "1.8f\n",$total_temp); !} ! close(OFH); > quit #************************************************* ********* Note: you can execute this in both Windows command line or UNIX command line: eg: cfx5post -batch test.cse |
Dear Blackbody,
Would you mind writing in this forum your macro about exporting variables in several timesteps?.It would be very kind. I've tried to use the code that appears in this threat above but it doesn't work. This macro would make easier my way of working with CFX. Thanks in advance Carlitos |
Hey, i'm currently working on it.... if i manage to let it run i will post it here of course!
cu |
@Carlitos
By the way: What do you need to export? Do you need to export variables (e.g. Temperature) at each node of a plane (e.g. Inlet) including x, y, z coordinates? or do you have the same problem like me that you want to export a functioncalculator value at each timestep? for the first one i have a very nice macro... let me know |
Hi
Quote:
! open(OFH, " >> file.dat"); # for loop for time steps lets say 3 time steps ! for ($i=1; $i <= 3; $i++) { COMMAND FILE: CFX Post Version = 12.0 END DATA READER: Clear All Objects = false Append Results = false Edit Case Names = false Open to Compare = false Multi Configuration File Load Option = Last Case Open in New View = true Keep Camera Position = true Load Particle Tracks = true Files to Compare = END DATA READER: Domains to Load = DT, GV, RUN, RUN OUT, SP, SV END > load filename=/home/bpl/RAMPUR/Grid1/GRID1_$i.trn, force_reload=true # "change the path and Result file name" ! $total_temp = areaAve("Total Temperature","inflow"); # "my inlet boundary, I name it as inflow in pre" accordingly call the boundaries as you named it in pre ! printf (OFH "1.8f\n",$total_temp); !} ! close(OFH); > quit Hi carlitos, the first macro which i have posted has been updated with some changes, have a look at that. if you are Executing this and error pops up, can you tell me what error is prompted. |
if I run your programm my outfile looks like following:
1.8f 1.8f 1.8f 1.8f 1.8f ... what shall I do? Thank you! and by the way, how can i modify the sessionfile so that it writes out also AreaAve Temperature at outlet and AreaAve pessure at inlet and outlet.. (total of 4 variables per timestep) is this possible? thanx ps: i'm using version12 my .trn results look like that: 200.trn, 201.trn,... and this is the session file i played: -------------------------------------- ! open(OFH, " >> T_tot_export.csv"); # for loop for time steps lets say 3 time steps ! for ($i=200; $i <= 203; $i++) { COMMAND FILE: CFX Post Version = 12.0 END DATA READER: Clear All Objects = false Append Results = false Edit Case Names = false Open to Compare = false Multi Configuration File Load Option = Last Case Open in New View = true Keep Camera Position = true Load Particle Tracks = true Files to Compare = END DATA READER: Domains to Load = S1, S2 END > load filename=K:\80Efficiency00\Model_trnres_62_001\$i. trn, force_reload=true ! $total_temp = massFlowAve("Total Temperature","Inlet"); ! printf (OFH "1.8f\n",$total_temp); !} ! close(OFH); > quit ---------------------------------------------------- |
1. we need to write "%1.8f"
2. we can output 4 variables per timestep following is the edited macro -------------------------------------- ! open(OFH, " >> T_tot_export.dat"); # for loop for time steps lets say 3 time steps ! for ($i=200; $i <= 203; $i++) { COMMAND FILE: CFX Post Version = 12.0 END DATA READER: Clear All Objects = false Append Results = false Edit Case Names = false Open to Compare = false Multi Configuration File Load Option = Last Case Open in New View = true Keep Camera Position = true Load Particle Tracks = true Files to Compare = END DATA READER: Domains to Load = S1, S2 END > load filename=K:\80Efficiency00\Model_trnres_62_001\$i. trn, force_reload=true ! print "Case $i\n"; # line 100 ! $tot_temp_in = massFlowAve("Total Temperature","Inlet"); ! $tot_temp_out = massFlowAve("Total Temperature","Outlet"); ! $pr_in = areaAve("Pressure","Inlet"); ! $pr_out = areaAve("Pressure","Outlet"); ! printf (OFH "%1.8f %1.8f %1.8f %1.8f\n",$tot_temp_in,$tot_temp_out,$pr_in,$pr_out ); !} ! close(OFH); > quit ----------------------------------------------------[/QUOTE] # line 100 displays the present case which is in the loop, on the screen you can also do mathematical operations, like calculating Cp, Efficiency. This macro can be made more generic if integrated with Bash scripts in UNIX. |
Thank you, in the meantime i was able to solve it myself ;)
but thanx!!! HERE ARE SOME HELPFUL MACROS: --------------------------------------------------------------------------------------------------------------------------------------------- 1.) If you want to export data of a plane (like "File" -> "Export" in CFD-POST) # A CFX-Post session file for output of Transient Calculation # Results for file export, can be adapted to any other output ## COPY THIS FILE INTO YOUR WORKING DIRECTORY, WHERE YOUR .res FILE is!## ################################################## ###################### #### Name convention ################################################## ###################### ! $PathSeparator = "/"; ! $ResFileName = getValue("DATA READER", "Current Results File"); ! $ResPos = index($ResFileName, ".res"); ! $ResFileLength = length($ResFileName); ! if ($ResPos == ($ResFileLength - 4)){ ! $FileBase = substr($ResFileName, 0, $ResFileLength-4); ! } ! else { ! $FileBase = $ResFileName ; ! } ! $DirName = $FileBase . "_EXPORT1"; ##################### ADJUST THIS ! mkdir ($DirName, 0777); ! $DirName = $DirName . $PathSeparator; ################################################## ###################### #### Start postprocessing loop ################################################## ###################### ! $count = 200; ##################### ADJUST THIS (number of the start imestep) ! @tlistt = (200, 201, 202, 203, 204, 205, 206, …, 300); ##################### ADJUST THIS ! foreach $tlist (@tlistt){ DATA READER:DATA READER Current Timestep = $tlist END > load ! $dummyfile = $DirName . "t" . $count.".csv"; EXPORT: #ANSYS Export Data = Element Pressure #ANSYS Export Locator = wallmeshcdb #ANSYS Fluid Selection = All Fluids #ANSYS Reference Temperature = 0.0 [C] #ANSYS Specify Reference Temperature = Off Export Type = Generic #BC Profile Type = Inlet Velocity Export Connectivity = Off Export Coord Frame = Global Export File = $dummyfile Export Geometry = On Export Node Numbers = Off Export Null Data = Off Export Units System = Current #Export Variable Type = Hybrid Include File Information = Off Include Header = On Location List = Plane 1 ##################### ADJUST THIS (Inlet, Outlet, Plane1,…) (only one allowed!!!) Null Token = 0 Overwrite = On Precision = 10 Separator = ", " Spatial Variables = X,Y,Z Variable List = Total Temperature, Total Pressure, … ##################### ADJUST THIS (you can specify more than one variable) Vector Brackets = () Vector Display = Scalar END >export ! $count = $count + 1; ############################# ! } # # Ende der Sub-Definition ---------------------------------------------------------------------------------------------------------------- 2.) If you want to give out alculations at a plane, for example massFlowAve value at inlet and outlet.... # A CFX-Post session file for output of Transient Calculation # Results for file export, can be adapted to any other output ## COPY THIS FILE INTO YOUR WORKING DIRECTORY, WHERE YOUR .res FILE is!## ################################################## ###################### #### Name convention ################################################## ###################### ! $PathSeparator = "/"; ! $ResFileName = getValue("DATA READER", "Current Results File"); ! $ResPos = index($ResFileName, ".res"); ! $ResFileLength = length($ResFileName); ! if ($ResPos == ($ResFileLength - 4)){ ! $FileBase = substr($ResFileName, 0, $ResFileLength-4); ! } ! else { ! $FileBase = $ResFileName ; ! } ! $DirName = $FileBase . "_EXPORT2"; ############# ADJUST THIS ! mkdir ($DirName, 0777); ! $DirName = $DirName . $PathSeparator; ! open(OFH, " >> exportfile.csv"); ############# ADJUST THIS ################################################## ###################### #### Start postprocessing loop ################################################## ###################### ! $count = 200; ############# ADJUST THIS ! $Variable1 = "Total Temperature"; ############# ADJUST THIS ! $Variable2 = "Total Pressure"; ############# ADJUST THIS ! $Plane1 = "Inlet"; ############# ADJUST THIS ! $Plane2= "Outlet"; ############# ADJUST THIS ! @tlistt = (200, 201, 202, 203, 204, ..., 300); ! foreach $tlist (@tlistt){ DATA READER:DATA READER Current Timestep = $tlist END ! $mVariable1 = massFlowAve($Variable1, $Plane1,""); ############# ADJUST THIS ! $mVariable2 = massFlowAve($Variable1, $Plane2,""); ############# ADJUST THIS ! $mVariable3 = massFlowAve($Variable2, $Plane1,""); ############# ADJUST THIS ! $mVariable4 = massFlowAve($Variable2, $Plane2,""); ############# ADJUST THIS !print OFH $tlist," , ",$mVariable1," , ",$mVariable2," , ",$mVariable3," , ",$mVariable4, "\n"; ############# ADJUST THIS ! $count = $count + 1; ! } ############################# # # Ende der Sub-Definition ! close(OFH); --------------------------------------------------------------------------------------------------------------------------------- |
sorry, where this stupid smile is just type:
DATA READER"doublepoint"DATA READER |
Quote:
Dear Blackbody, yes, that's what i really need: export variables at each node at each timestep including their coordinates. If you could write here the macro...it would be fantastic. Thanks in advance Carlitos |
Thanks for write the macro Blackbody.
I've ran it but, unfortunately, an error pops up and tells me ERROR Too many END statements in CCL. Where's the mistake? I've copied your macro and made the adjust that you suggest. Could you tell anything? Thanks Here is the macro i've ran ################################################## ###################### #### Lecho ################################################## ###################### ! $PathSeparator = "/"; ! $ResFileName = getValue("DATA READER", "Current Results File"); ! $ResPos = index($ResFileName, ".res"); ! $ResFileLength = length($ResFileName); ! if ($ResPos == ($ResFileLength - 4)){ ! $FileBase = substr($ResFileName, 0, $ResFileLength-4); ! } ! else { ! $FileBase = $ResFileName ; ! } ! $DirName = $FileBase . "_EXPORT1"; ##################### ADJUST THIS ! mkdir ($DirName, 0777); ! $DirName = $DirName . $PathSeparator; ################################################## ###################### #### Start postprocessing loop ################################################## ###################### ! $count = 71100; ##################### ADJUST THIS (number of the start imestep) ! @tlistt = (71100, 72000, 72900); ##################### ADJUST THIS ! foreach $tlist (@tlistt){ DATA READER"doublepoint"DATA READER Current Timestep = $tlist END > load ! $dummyfile = $DirName . "t" . $count.".csv"; EXPORT: #ANSYS Export Data = Element Pressure #ANSYS Export Locator = wallmeshcdb #ANSYS Fluid Selection = All Fluids #ANSYS Reference Temperature = 0.0 [C] #ANSYS Specify Reference Temperature = Off Export Type = Generic #BC Profile Type = Inlet Velocity Export Connectivity = Off Export Coord Frame = Global Export File = $dummyfile Export Geometry = On Export Node Numbers = Off Export Null Data = Off Export Units System = Current #Export Variable Type = Hybrid Include File Information = Off Include Header = On Location List = Plane 1 ##################### ADJUST THIS (Inlet, Outlet, Plane1,…) (only one allowed!!!) Null Token = 0 Overwrite = On Precision = 10 Separator = ", " Spatial Variables = X,Y,Z Variable List = Lecho. Volume Fraction ##################### ADJUST THIS (you can specify more than one variable) Vector Brackets = () Vector Display = Scalar END >export ! $count = $count + 1; ############################# ! } # # |
Hi Carlitos
Ok carlitos try this !:)
copy the below macro in between hashes #, to some "file.cse" and copy file.cse to the directory where your *.trn files are located. Being in the same directory, at the UNIX or Windows command line just type cfx5post -batch file.cse ####for v11.0 cfx512post -batch file.cse ####for v12.0 As soon as you execute this and if everything is fine, I mean your location name , then on the screen you can see which case is presently in process. eg: :> cfx5post -batch file.cse 71100 72000 72900 :> #################################### COMMAND FILE: CFX Post Version = 11.0 END DATA READER: Clear All Objects = false Append Results = false Apply X Offset = false Apply Y Offset = false Apply Z Offset = false Keep Camera Position = true Load Particle Tracks = true END ! for ($i=71100; $i <= 72900; $i=$i+900) { ! print "$i \n"; > load filename=$i.trn EXPORT: #ANSYS Export Data = Element Heat Flux #ANSYS Reference Temperature = 0.0 [K] #ANSYS Specify Reference Temperature = Off # ANSYS Supplemental HTC = 0.0 [W m^-2 K^-1] # BC Profile Type = Inlet Velocity Export Connectivity = Off Export Coord Frame = Global Export File = $i.csv # Export file name with increment Export Geometry = On Export Node Numbers = Off Export Null Data = Off Export Type = Generic Export Units System = Current Export Variable Type = Current Include File Information = Off Include Header = On Location List = Plane 1 Null Token = 0 Overwrite = Off Precision = 10 Separator = ", " Spatial Variables = X,Y,Z Variable List = Lecho. Volume Fraction Vector Brackets = () Vector Display = Scalar END >export !} ############################################ if your using v12.0 just change the DATA READER and also include Load domains. just see my previous posts. I hope it works this time:) |
Dear pavitran,
thanks a lot :). The macro works perfectly on the command window, but there is a thing that i don't understand...when you comment to run the macro on Lynux you notice me to create a .cse file. How can i get making that kind of file?. I have no idea. And another question, where can i find more information about creating my own macros? Thanks again Carlitos |
Hi Carlitos
1. To edit or create a file in Linux, one way is using VI editor. so, create a dummy file with extension ".cse" and paste the macro and save the file.
2. Or open Microsoft Word, wordpad or notepad in Windows and paste the macro and then save the file with extension ".cse" and copy this file on to UNIX machine using FTP or winscp. Your next question about creating macros? Look at "Examples of Power Syntax" in CFX help file. It doesn't give much information but for a start it is good. If you get acquainted with creating macros and have some knowledge of bash scripts in Linux, then you can automate your entire postprocessing, which ultimately saves considerable time. Anways all the best!:) |
Hello Pavitran,
Thanks a lot for your last explanation. Now i'm posting again because i'm working on another macro which is making me get a bit crazy. I would like to calculate the mass flow of different fluids in a multiphase problem. The macro is showed below and the problem is that it calculates the mass flow of all the fluids instead of writing a single fluid. Moreover it appears a error message on the screen explaining to me it's impossible to load the file but actually a file.dat is written... How can i try to fancy with this point? Thanks in advance Carlitos ##################################### ! open(OFH, " >> fileg.dat"); # writing to a file ! for ($i=60030; $i <= 60130; $i=$i+50) { COMMAND FILE: CFX Post Version = 11.0 END DATA READER: Clear All Objects = false Append Results = false Apply X Offset = false Apply Y Offset = false Apply Z Offset = false Keep Camera Position = true Load Particle Tracks = true END > load filename=/carlitos/bis/80_1inhol_005/$i.trn ! $flujo = massFlow("Plane 2","CH4"); ! printf (OFH "%1.8f\n",$flujo); !} ! close(OFH); |
Hi Carlitos
1. First check --> Open CFX POST GUI and try to calculate mass flow of CH4. If it is working there, then your macro should also work properly, moreover the syntax is fine.
2. Loading file --> Dont use the full path, just be in that directory and call the *.trn file > load filename=$i.trn 3. Are you executing this macro at Command line. Then how your creating "Plane 2". Note: Search for "Function Calculator" in CFX help manual and go to "Direction or Axis Selection" page. There you will find a Note about massFlow. Have a look at that, as it mentions about some Expert control parameters.:) |
All times are GMT -4. The time now is 08:41. |