CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > Siemens > STAR-CCM+

Report value in csv file

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By marmot
  • 1 Post By taillanm

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 4, 2016, 10:09
Default Report value in csv file
  #1
Member
 
Join Date: Nov 2015
Posts: 57
Rep Power: 10
taillanm is on a distinguished road
Hello all,

I have n simulations files where I want to export a report value into a csv file. I would loop first to read those sim files; My report value of the first sim file would go in the first line of my array, my value of the second sim file in the second line of the array and so on..

Do you have an idea of how it might look like?
taillanm is offline   Reply With Quote

Old   July 5, 2016, 02:27
Default
  #2
Senior Member
 
kevin alun
Join Date: Sep 2011
Location: Germany
Posts: 106
Rep Power: 14
marmot is on a distinguished road
I did not test it but something like this structure,

ArrayList simRuns = new ArrayList();
ArrayList name = new ArrayList();

Simulation simOld = getActiveSimulation();

//Input parameters

name.add("13A");
simRuns.add("M13A");
name.add("14A");
simRuns.add("M14A");
name.add("15A");
simRuns.add("M15A");

//Get the location of the sim file
String filePath = simOld.getSessionDir().toString();

//Close sim file
simOld.close();

//Array to store my values
ArrayList<Double> someValue = new ArrayList<Double>();

for (int i = 0; i < simRuns.size(); i++) {

String simName = (String) simRuns.get(i);
//Get my case
Simulation sim = new Simulation(filePath + File.separator + simName + ".sim");

//whatever report you need, example area average
areaAvgRep=sim.getReportManager().createReport(Are aAverageReport.class);

//you can also do a user field function but example is primitive for pressure
PrimitiveFieldFunction pFF = ((PrimitiveFieldFunction) sim.getFieldFunctionManager().getFunction("Pressur e"));

areaAvgRep.setScalar(pFF);

//Lets say you have a section already in the sim file
PlaneSection planeSection_0 = ((PlaneSection) sim.getPartManager().getObject("zSection"));
areaAvgRep.getParts().setObjects(planeSection_0);

//get the value
aValue = areaAvgReport.getValue();

someValue.add(aValue);


//close
sim.close();
} //go again for the next sim file

//Time to write out the data
FileWriter fstream;
BufferedWriter reportfile = null;

try{
fstream = new FileWriter(filePath + File.separator+"SomeValue"+".csv" );
reportfile = new BufferedWriter(fstream);
reportfile.write("caseName"+","+"ValueType");
reportfile.write("\r\n");
for loop
reportfile.write(name.get(i).toString() + "," + someValue.get(i).toString());
reportfile.write("\r\n");
end loop

reportfile.close();
}catch {something here}
aow likes this.
marmot is offline   Reply With Quote

Old   July 7, 2016, 03:39
Default
  #3
Member
 
Join Date: Nov 2015
Posts: 57
Rep Power: 10
taillanm is on a distinguished road
Hi thanks for the input, I finally worked on what I already had to loop over my sim files; this should work:

package macro;
import java.io.*;
import java.util.*;
import java.io.File;
import java.io.BufferedWriter;
import java.io.FileWriter;
import org.openide.util.Exceptions;
import star.common.*;
import star.base.report.*;
import star.base.neo.*;

public class exportCSV extends StarMacro {

public class SimFileFilter implements FilenameFilter {
public boolean accept(File dir, String name) {
return name.endsWith(".sim");
}
}
public void execute() {
Simulation sim = getActiveSimulation();
sim.kill();
File simDir = new File(resolvePath("."));
System.out.println("Directory: " + simDir);
for (File f : simDir.listFiles(new SimFileFilter())) {
startAndRun(f);
}
}
public void startAndRun(File f) {

String fileName = f.getAbsolutePath();
Simulation sim = new Simulation(fileName);

File file = new File(resolvePath("/home/m1tailla/TAILLANDIER/Etude/test/output.csv"));
Collection<Report> reps = sim.getReportManager().getObjects();
try {
BufferedWriter out = new BufferedWriter(new FileWriter(file));
out.append("ReportValue");
out.newLine();

for(Report ri :reps) {

// this is specific for my case, if you have many reports but are interested in only specific types (here volume average) it should look like this:

if(ri instanceof VolumeAverageReport){
VolumeAverageReport vr = (VolumeAverageReport) ri;

out.append("" + vr.getValue());
out.newLine();
}
}
out.close();
} catch(IOException ex) {
sim.println("Error type: " +ex.getMessage());
}
sim.saveState(fileName);
sim.kill();
}
}
aow likes this.
taillanm 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
[OpenFOAM.org] Error creating ParaView-4.1.0 OpenFOAM 2.3.0 tlcoons OpenFOAM Installation 13 April 20, 2016 17:34
what is swap4foam ?? AB08 OpenFOAM 28 February 2, 2016 01:22
[swak4Foam] build problem swak4Foam OF 2.2.0 mcathela OpenFOAM Community Contributions 14 April 23, 2013 13:59
Version 15 on Mac OS X gschaider OpenFOAM Installation 113 December 2, 2009 10:23
DecomposePar links against liblamso0 with OpenMPI jens_klostermann OpenFOAM Bugs 11 June 28, 2007 17:51


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