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

how to export every data w.r.t time to txt file

Register Blogs Community New Posts Updated Threads Search

Like Tree6Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 6, 2014, 13:49
Default
  #81
Senior Member
 
Matthias Voß
Join Date: Mar 2009
Location: Berlin, Germany
Posts: 449
Rep Power: 20
mvoss is on a distinguished road
I am not sure but it seems illogical to me to name the output like a usual variable. Just name it FH and try again.
mvoss is offline   Reply With Quote

Old   April 6, 2014, 14:21
Default
  #82
New Member
 
Sagar
Join Date: Apr 2014
Posts: 10
Rep Power: 12
eaysk is on a distinguished road
Did you mean that I rename $vol_frac_fluid to $FH?

I did that but its still not working.
eaysk is offline   Reply With Quote

Old   April 6, 2014, 14:58
Default
  #83
New Member
 
Sagar
Join Date: Apr 2014
Posts: 10
Rep Power: 12
eaysk is on a distinguished road
Even the simplest of file writing commands don't seem to work for me.

I tried this-

COMMAND FILE:
CFX Post Version = 14.5.7
END

! open($FH, ">data.txt");

! printf($FH ,100);

! close($FH);

But it wrote nothing in data.txt
eaysk is offline   Reply With Quote

Old   April 6, 2014, 16:31
Default
  #84
Senior Member
 
Matthias Voß
Join Date: Mar 2009
Location: Berlin, Germany
Posts: 449
Rep Power: 20
mvoss is on a distinguished road
! open(FH, ">data.txt");

! printf(FH ,100);

! close(FH);
mvoss is offline   Reply With Quote

Old   April 6, 2014, 16:46
Default
  #85
New Member
 
Sagar
Join Date: Apr 2014
Posts: 10
Rep Power: 12
eaysk is on a distinguished road
I get an error now-

ERROR
CCL parser failed with message:
Perl Syntax errors detected:
No comma allowed after filehandle at (eval 5707) line 6.
eaysk is offline   Reply With Quote

Old   April 6, 2014, 17:12
Default
  #86
Senior Member
 
Matthias Voß
Join Date: Mar 2009
Location: Berlin, Germany
Posts: 449
Rep Power: 20
mvoss is on a distinguished road
! open (MYFILE, '>>data.txt');
! print MYFILE "Bob\n";
! close (MYFILE);
mvoss is offline   Reply With Quote

Old   April 7, 2014, 05:38
Default
  #87
New Member
 
Sagar
Join Date: Apr 2014
Posts: 10
Rep Power: 12
eaysk is on a distinguished road
That isn't working either.

Is it necessary to include any perl libraries into the code? What I mean is that in C, when printf is used, it becomes necessary to include the standard input-output library using #include<stdio.h>. When other input-output functions cin and cout are used, we write #include<iostream.h>...

I have also created a file called file.txt or data.txt in the folder where I saved my data files 'bcp4_3_v4_sr4_omg15-13-00200' to 'bcp4_3_v4_sr4_omg15-13-28000' and the state file for 'Plane 1' before I ran the code.

But nothing is written into the files! Not even for simple commands like-

! open (MYFILE, '>>data.txt');
! print MYFILE "Bob\n";
! close (MYFILE);

But I don't get any errors either..

Note that I am able to load my datafiles, I am just not able to write to file.
eaysk is offline   Reply With Quote

Old   April 7, 2014, 05:48
Default
  #88
Senior Member
 
Matthias Voß
Join Date: Mar 2009
Location: Berlin, Germany
Posts: 449
Rep Power: 20
mvoss is on a distinguished road
Try to do a search on the created file "data.txt" in your system. If there is no error, then the task was completed. And at least an empty data.txt was created somewhere.
mvoss is offline   Reply With Quote

Old   April 7, 2014, 06:18
Default
  #89
Senior Member
 
Lance
Join Date: Mar 2009
Posts: 669
Rep Power: 22
Lance is on a distinguished road
Check that the current directory is where you think it is.

Code:
!use Cwd;
!print cwd();
Lance is offline   Reply With Quote

Old   April 7, 2014, 06:37
Default
  #90
New Member
 
Sagar
Join Date: Apr 2014
Posts: 10
Rep Power: 12
eaysk is on a distinguished road
There is no empty text file created. I thought that there should already be an existing file in the working directory with the name of the file that would contain the output.. So I created a text file in the working directory and then run the code. But it makes no difference whatever method I do. I can load the files but not write to files.

Should I be using the Command Editor of CFD-Post to process my code? Because I don't understand where a print function would display the output.. So I can't print the current working directory anywhere.
eaysk is offline   Reply With Quote

Old   April 7, 2014, 07:09
Default
  #91
Senior Member
 
Lance
Join Date: Mar 2009
Posts: 669
Rep Power: 22
Lance is on a distinguished road
Yes, use the command editor. I run CFX under linux and get the output to the terminal window. But I think that if you start cfd-post in stand alone there's an output window (think DOS-style) as well?
Lance is offline   Reply With Quote

Old   April 7, 2014, 08:14
Default
  #92
Senior Member
 
Bruno
Join Date: Mar 2009
Location: Brazil
Posts: 277
Rep Power: 21
brunoc is on a distinguished road
If printing the average volfrac at a plane is all you want to do, why not just use the built in chart from Post?

Anyway, try using the complete file path to the file you want to write. That might make things easier:

Code:
! open(OUT, ">E:/TEMP/test.txt");
! print OUT "testing:\n";
! printf(OUT "%.8e\n", 1.23);
! close(OUT);
You might also want to (temporarily) rename your working dir to something easier, such as, say, 'C:\myrun\', at least until you find out why script isn't working.

Code:
COMMAND FILE:
  CFX Post Version = 14.5.7
END

! my $file="C:/file.txt";
! open(FH, ">$file");
!
! $start = 200;
! $finish = 28000;
! $basename = "C:/bcp4_3_v4_sr4_omg15_pw3/bcp4_3_v4_sr4_ omg15_pw3 (fi=0.9097)/Data files/bcp4_3_v4_sr4_omg15-13";
! for ($i=$start; $i <= $finish; $i=$i+100)
! {
!   if($i<1000) {
      > load filename=$basename-00$i.dat
!   }
!   elsif($i<10000) {
      > load filename=$basename-0$i.dat
!   }
!   else {
      > load filename=$basename-$i.dat
!   }
!
!   $vol_frac_fluid = areaAve("Water.Volume Fraction", "Plane 1");
!   printf(FH "1.8f\n", $vol_frac_fluid);
! }
! close(FH);
brunoc is offline   Reply With Quote

Old   April 7, 2014, 09:18
Default
  #93
New Member
 
Sagar
Join Date: Apr 2014
Posts: 10
Rep Power: 12
eaysk is on a distinguished road
Thank you so much Bruno!

There were was wrong syntax i.e. backlash instead of frontslash, in the file specification..

It works file now

The basename suggestion doesn't work because the string gets formatted whenever \b comes up in the file name

Is it possible to make a chart for water.volumefraction vs. timestep directly using Post tools?
eaysk is offline   Reply With Quote

Old   April 7, 2014, 09:58
Default
  #94
Senior Member
 
Bruno
Join Date: Mar 2009
Location: Brazil
Posts: 277
Rep Power: 21
brunoc is on a distinguished road
Use slashes (/), not backslashes (\). A slash won't cause you problems. I tested it here and it worked fine.

And yes, it's possible to generate what you want using a chart in Post. You just need to create an expression with what you want to plot. One of the tutorials from CFX covers that. Look for the ones that use a transient setup or take a look at the documentation for charts in CFD-Post.
brunoc is offline   Reply With Quote

Old   August 25, 2015, 09:45
Default
  #95
New Member
 
Join Date: Aug 2015
Posts: 1
Rep Power: 0
Mahe18 is on a distinguished road
Hey Guys,

I know this thread is quite old, but I have a question I can not solve by myself and hope somebody can help me.
I have ran a simulation and do have 2000 .trn files. From these files I want to extract the pressure and the velocity. I am already able to do this, however I have to import ever .trn file before I can run my script otherwise I get 2000 .csv files with the same value.

I hope somebody can help me! here is my script:

COMMAND FILE:
CFX Post Version = 16.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 =
Construct Variables From Fourier Coefficients = True
END

DATA READER:
Domains to Load=
END
> load filename = /file.res , \
force_reload=true


! use strict;
! use warnings;

! my $trn;

! for ($trn = 6001; $trn <= 6007; $trn ++ ){

! print "$trn\n ";

> load timestep = $trn

> addtimestep filename=path/$trn.trn,\
case=file.res , ignoreduplicates=true

EXPORT:
ANSYS Export Data = Element Heat Flux
ANSYS File Format = ANSYS

ANSYS Reference Temperature = 0.0 [K]
ANSYS Specify Reference Temperature = Off
ANSYS Supplemental HTC = 0.0 [W m^-2 K^-1]
Additional Variable List =
BC Profile Type = Inlet Velocity
Export Connectivity = Off
Export Coord Frame = Global
Export File =/path/plane$trn.csv
Export Geometry = On
Export Location Aliases =
Export Node Numbers = Off
Export Null Data = On

Export Type = Generic
Export Units System = Current
Export Variable Type = Current
External Export Data = None
Include File Information = Off
Include Header = On
Location = inlet
Location List = /PLANE:Plane 1
Null Token = null
Overwrite = On
Precision = 10
Separator = ", "
Spatial Variables = X,Y,Z
Variable List = Pressure, Velocity u, Velocity v, Velocity w
Vector Brackets = ()
Vector Display = Scalar
END
>export


! };
Mahe18 is offline   Reply With Quote

Reply


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
[swak4Foam] swak4foam building problem GGerber OpenFOAM Community Contributions 54 April 24, 2015 16:02
Moving mesh Niklas Wikstrom (Wikstrom) OpenFOAM Running, Solving & CFD 122 June 15, 2014 06:20
OpenFOAM on MinGW crosscompiler hosted on Linux allenzhao OpenFOAM Installation 127 January 30, 2009 19:08
DxFoam reader update hjasak OpenFOAM Post-Processing 69 April 24, 2008 01:24
Could anybody help me see this error and give help liugx212 OpenFOAM Running, Solving & CFD 3 January 4, 2006 18:07


All times are GMT -4. The time now is 17:52.