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)

mvoss April 6, 2014 13:49

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.

eaysk April 6, 2014 14:21

Did you mean that I rename $vol_frac_fluid to $FH?

I did that but its still not working.

eaysk April 6, 2014 14:58

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

mvoss April 6, 2014 16:31

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

! printf(FH ,100);

! close(FH);

eaysk April 6, 2014 16:46

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.

mvoss April 6, 2014 17:12

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

eaysk April 7, 2014 05:38

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.

mvoss April 7, 2014 05:48

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.

Lance April 7, 2014 06:18

Check that the current directory is where you think it is.

Code:

!use Cwd;
!print cwd();


eaysk April 7, 2014 06:37

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.

Lance April 7, 2014 07:09

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?

brunoc April 7, 2014 08:14

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


eaysk April 7, 2014 09:18

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?

brunoc April 7, 2014 09:58

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.

Mahe18 August 25, 2015 09:45

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


! };


All times are GMT -4. The time now is 03:14.