CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   CFX (https://www.cfd-online.com/Forums/cfx/)
-   -   how to export every data w.r.t time to txt file (https://www.cfd-online.com/Forums/cfx/25213-how-export-every-data-w-r-t-time-txt-file.html)

hung February 19, 2010 20:23

Hi
it works by change the comma to the semicolon.
cheer

blackbody April 21, 2010 13:07

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!!!

blackbody June 3, 2010 11:05

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...

pavitran June 3, 2010 23:58

Hi
 
Sorry, I have posted below to extract variables using function calculator.

pavitran June 4, 2010 00:04

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

Carlitos June 4, 2010 07:38

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

blackbody June 4, 2010 07:43

Hey, i'm currently working on it.... if i manage to let it run i will post it here of course!
cu

blackbody June 4, 2010 09:09

@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

pavitran June 4, 2010 09:15

Hi
 
Quote:

Originally Posted by Carlitos (Post 261661)
I've tried to use the code that appears in this threat above but it doesn't work.
Carlitos

For CFX v12.0 the start should be

! 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.

blackbody June 4, 2010 10:05

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
----------------------------------------------------

pavitran June 4, 2010 12:22

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.

blackbody June 4, 2010 12:38

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);

---------------------------------------------------------------------------------------------------------------------------------

blackbody June 4, 2010 12:40

sorry, where this stupid smile is just type:

DATA READER"doublepoint"DATA READER

Carlitos June 4, 2010 12:40

Quote:

Originally Posted by blackbody (Post 261687)
@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?

for the first one i have a very nice macro...
let me know


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

Carlitos June 4, 2010 13:33

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;

#############################
! }
#
#

pavitran June 7, 2010 06:34

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:)

Carlitos June 7, 2010 11:41

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

pavitran June 7, 2010 22:10

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!:)

Carlitos June 14, 2010 12:25

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);

pavitran June 15, 2010 01:57

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 23:04.