|
[Sponsors] |
July 4, 2016, 10:09 |
Report value in csv file
|
#1 |
Member
Join Date: Nov 2015
Posts: 57
Rep Power: 10 |
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? |
|
July 5, 2016, 02:27 |
|
#2 |
Senior Member
kevin alun
Join Date: Sep 2011
Location: Germany
Posts: 106
Rep Power: 14 |
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} |
|
July 7, 2016, 03:39 |
|
#3 |
Member
Join Date: Nov 2015
Posts: 57
Rep Power: 10 |
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(); } } |
|
|
|
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 |