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

Automatically export all reports in batch

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 21, 2011, 20:03
Question Automatically export all reports in batch
  #1
f-w
Senior Member
 
f-w's Avatar
 
Join Date: Apr 2009
Posts: 154
Rep Power: 17
f-w is on a distinguished road
Hello,

I typically run many simulations in batch mode with accompanying java macros that set up the conditions; these simulations have many reports. I'm looking for a way to export all reports after simulation convergence (in batch mode) into a csv file.

I have found a java macro which exports all reports to a csv file by running it manually on a simulation, but I need to run it automatically and only after convergence. Currently, the last command in my setup macros (which I use with each simulation in batch mode) is to RUN the simulation.

How do I go about running the report export macro before the simulation closes (and moves on to the next simulation) in batch mode?

Thanks

Attached is the report export macro I got from cd-adapco's java hut (author:Sangamesh)

Quote:
// STAR-CCM+ macro: Report_to_csv.java
package macro;

import java.util.*;
import java.io.*;
import java.nio.*;
import star.common.*;
import star.base.neo.*;
import star.base.report.*;
import star.flow.*;

public class Report_to_csv extends StarMacro {

BufferedWriter bwout = null;

public void execute() {

try {

Simulation simulation_0 = getActiveSimulation();

// Collecting the simualtion file name
String simulationName = simulation_0.getPresentationName();
simulation_0.println("Simulation Name:" + simulationName);

// Open Buffered Input and Output Readers
// Creating file with name "<sim_file_name>+report.csv"
bwout = new BufferedWriter(new FileWriter(resolvePath(simulationName +"report.csv")));
bwout.write("Report Name, Value, Unit, \n");

Collection<Report> reportCollection = simulation_0.getReportManager().getObjects();

for (Report thisReport : reportCollection){

String fieldLocationName = thisReport.getPresentationName();
Double fieldValue = thisReport.getReportMonitorValue();
String fieldUnits = thisReport.getUnits().toString();

// Printing to chek in output window
simulation_0.println("Field Location :" + fieldLocationName);
simulation_0.println(" Field Value :" + fieldValue);
simulation_0.println(" Field Units :" + fieldUnits);
simulation_0.println("");

// Write Output file as "sim file name"+report.csv
bwout.write( fieldLocationName + ", " +fieldValue + ", " + fieldUnits +"\n");

}
bwout.close();

} catch (IOException iOException) {
}

}
}

Last edited by f-w; July 25, 2011 at 11:39.
f-w is offline   Reply With Quote

Old   July 25, 2011, 19:51
Default
  #2
f-w
Senior Member
 
f-w's Avatar
 
Join Date: Apr 2009
Posts: 154
Rep Power: 17
f-w is on a distinguished road
I forgot that I can play a macro from within a macro. All I had to do was add the following line to the end of my conditioning macro:

new StarScript(getActiveSimulation(),new java.io.File(resolvePath("Report_to_csv.java"))).p lay();
f-w is offline   Reply With Quote

Old   August 3, 2011, 09:14
Default
  #3
New Member
 
Sebastian
Join Date: Mar 2011
Posts: 13
Rep Power: 15
cbisw is on a distinguished road
Not 100% sure if I understand what you are doing. Just run a macro once the simulation run finishes? I wrote a couple of macros a few months ago to do stuff after each iteration or timestep, maybe they are helpful to you.

First I toyed around with the observer pattern:

Quote:

public
class ObserverTest extends StarMacro {

publicvoid execute() {

Simulation sim = getActiveSimulation();

SimulationIterator simIt = sim.getSimulationIterator();
NeoObservable simObs = simIt.getIterationObservable();
MyObs myObs =
new MyObs(sim, simIt);
simObs.addObserver(myObs);

}

class MyObs extends IterationNotifier.Receiver {

private Simulation sim;
private SimulationIterator simIt;

MyObs(Simulation sim, SimulationIterator simIt) {
this.sim = sim;
this.simIt = simIt;
}

publicvoid update(Observable o, Object msg) {

sim.println("Observer has been notified");
// do whatever you want here

// e.g. check whether convergence has been reached

// and do stuff accordingly


}

}
}
Then I used another approach by making my macro run the simulation itself timestep by timestep. You would probably have to adjust your stopping criteria since you obviously have your own ones based on convergence. I simplified it and put comments where you can do things a) after every step and b) after last step:

Quote:

// execute() is called by Star-CCM+ when macro is run
publicvoid execute() {



System.out.println("MACRO> Macro XYZ has been started.");



// SET UP SIMULATION



// references to current simulation and solution
sim = getActiveSimulation();
out.println("Active simulation is '"+sim.getPresentationName()+"'.");
sol = sim.getSolution();



// initialize solution if necessary for starting values
// WARNING: not initializing the solution will cause the macro to fail because
// the number of points cannot be extracted the way it is done here
if( sol.isInitialized() == false ) {
out.println("Solution not initialized, initializing...");
sol.initializeSolution();
}



// status
int startTimelevel = sim.getSimulationIterator().getCurrentTimeLevel();
int startIteration = sim.getSimulationIterator().getCurrentIteration();
double timestep = ((ImplicitUnsteadySolver)sim.getSolverManager().getSolver(ImplicitUnsteadySolv er.class)).getTimeStep().getValue();



// set the current iteration
iteration = startIteration;
timelevel = startTimelevel;



// INITIALIZATION DONE



// RUN SINGLE TIME STEPS AND DO STUFF



do {



// run a single time step and wait until it has completed.
long timeBeforeStep = System.nanoTime();
sim.getSimulationIterator().run(1,true);



// output some information
iteration = sim.getSimulationIterator().getCurrentIteration();
out.println("Iteration: "+iteration);
out.println("Timelevel: "+sim.getSimulationIterator().getCurrentTimeLevel());



// do whatever you want to do each step here



long timeAfterStep = System.nanoTime();
long timeRequirement = timeAfterStep - timeBeforeStep;
out.println("Total time for this iteration: "+timeRequirement + " ns.");



} while (IsCriteriaSatisfied(sim) == false);



// at this point, any of the stopping criteria has been satisfied, execute() returns
// do whatever you want to do after simulation has ended here
out.println("MACRO> Stopping criterion met, quitting macro.");
out.close();
return;



}



// returns true if any stopping criteria has been met, taking into account the three default stopping criteria
privateboolean IsCriteriaSatisfied(Simulation Sim) {



PhysicalTimeStoppingCriterion physTimeCrit = ((PhysicalTimeStoppingCriterion) Sim.getSolverStoppingCriterionManager().getSolverS toppingCriterion("Maximum Physical Time"));
StepStoppingCriterion stepCrit = ((StepStoppingCriterion) Sim.getSolverStoppingCriterionManager().getSolverS toppingCriterion("Maximum Steps"));
AbortFileStoppingCriterion abortFileCrit = (AbortFileStoppingCriterion) Sim.getSolverStoppingCriterionManager().getSolverS toppingCriterion("Stop File");



if( physTimeCrit.getIsUsed() ) {
if( physTimeCrit.getIsSatisfied() ) {
Sim.println("MACRO> PhysicalTimeStoppingCriterion met");
returntrue;
}
}



if( stepCrit.getIsUsed() ) {
if( stepCrit.getIsSatisfied() ) {
Sim.println("MACRO> StepStoppingCriterion met");
returntrue;
}
}



if( abortFileCrit.getIsUsed() ) {
if( abortFileCrit.getIsSatisfied() ) {
Sim.println("MACRO> AbortFileStoppingCriterion met");
returntrue;
}
}



returnfalse;


}
cbisw is offline   Reply With Quote

Old   August 3, 2011, 19:05
Default
  #4
f-w
Senior Member
 
f-w's Avatar
 
Join Date: Apr 2009
Posts: 154
Rep Power: 17
f-w is on a distinguished road
Thanks for your contribution Sebastian, but as you can read from my 2nd post, I figured it out ...
f-w is offline   Reply With Quote

Old   August 4, 2011, 01:02
Default
  #5
New Member
 
Sebastian
Join Date: Mar 2011
Posts: 13
Rep Power: 15
cbisw is on a distinguished road
Oh alright, that came across like some kind of extra information. Guess I shouldn't try to answer threads in a hurry shortly before calling it a day
cbisw is offline   Reply With Quote

Old   August 23, 2016, 07:04
Default
  #6
New Member
 
Sergi
Join Date: Jun 2016
Location: UK
Posts: 4
Rep Power: 0
Sergi is on a distinguished road
This thread that it already has some time it's quite useful to export the reports into an excel spreadsheet in batch mode. The code in the 1st post worked brilliantly to me to export all the reports from my simulations.

But here's my question and hopefully someone can help me to find an answer because my Java knowledge is 0 and I do not know how to find or write myself the right code to export the Plots monitor into an excel file.

The thing is that I have a series of simulations and I would like to generate an excel file with the plots results for each simulation in batch mode.

Hope that I made myself clear, so if you need some extra info, please let me know it.

Any help or guidance on this, I would really appreciate it!
Sergi is offline   Reply With Quote

Old   September 24, 2019, 09:21
Default Export single reports, java api issues
  #7
New Member
 
Join Date: May 2018
Posts: 2
Rep Power: 0
Dumbledoge is on a distinguished road
Hello !

I am sorry I have to revive this thread again, but in case someone is looking for a way to extract single Reports by specifying the Report Name, this might help you:

Code:
// STAR-CCM+ macro: reportExtractor.java
package macro;
//
import java.util.*;
import java.io.*;
import java.nio.*;
import star.common.*;
import star.base.neo.*;
import star.base.report.*;
import star.flow.*;

public class reportExtractor extends StarMacro {
//
BufferedWriter writer = null;
//
public void execute() {
//
try {

Simulation activeSimulation = getActiveSimulation();

// Collecting the simualtion file name
String simulationName = activeSimulation.getPresentationName();
activeSimulation.println("Simulation Name:" + simulationName);

// Creating file with name "<sim_file_name>+report.csv"
writer = new BufferedWriter(new FileWriter(resolvePath(simulationName +"_report.csv")));
writer.write("Report Name, Value, Unit, \n");

Report testReport;

testReport = activeSimulation.getReportManager().getReport("Heat Flux of Contact Surfaces");

List<Report> reportCollection = new ArrayList<Report>();

reportCollection.add(testReport);


for (Report thisReport : reportCollection){

	String fieldLocationName = thisReport.getPresentationName();
	Double fieldValue = thisReport.getReportMonitorValue();
	String fieldUnits = thisReport.getUnits().toString();

// Printing to check in output window
	activeSimulation.println("Field Location: " + fieldLocationName);
 	activeSimulation.println("Field Value: " + fieldValue);
 	activeSimulation.println("Field Units: " + fieldUnits);
 	activeSimulation.println("");

// Write Output file as "sim file name"+report.csv
	writer.write( fieldLocationName + ", " +fieldValue + ", " + fieldUnits +"\n");
//
    }
    writer.close();
//
 } catch (IOException iOException) {
 }
//
 }
 }
Dumbledoge is offline   Reply With Quote

Old   May 24, 2022, 12:00
Default Where is the .csv File ?
  #8
New Member
 
Marcel
Join Date: Dec 2020
Location: Germany
Posts: 17
Rep Power: 5
Marcel95 is on a distinguished road
Can someone tell me where i will find the .csv file after running the macro??

I thought it would be at the same place as my simulation, but there is nothing.
Marcel95 is offline   Reply With Quote

Old   May 25, 2022, 05:51
Default
  #9
Senior Member
 
Sebastian Engel
Join Date: Jun 2011
Location: Germany
Posts: 566
Rep Power: 20
bluebase will become famous soon enough
if you do not specify an absolute path, the relative path points to the current work directory.


This should be the location from which the starccm binary is started.
If you are running windows, have a look into your home directory (such as C:/Users/Marcel/)




The sim object has a method which tells in which directory it is located. Here is an example to export all plots to the location of the sim file

Code:
Simulation simulation_0 = getActiveSimulation();          

String dir = simulation_0.getSessionDir(); //get the name of the simulation's directory
String sep = System.getProperty("file.separator"); //get the right separator for your operating system

for (StarPlot plot : simulation_0.getPlotManager().getObjects()) {
    plot.encode(resolvePath(dir + sep + plot.getPresentationName() + ".jpg"), "jpg", 800, 600);
}
bluebase is offline   Reply With Quote

Old   November 17, 2022, 04:14
Default
  #10
Member
 
Marc Ricart
Join Date: Jul 2022
Posts: 65
Rep Power: 3
cramr5 is on a distinguished road
Quote:
Originally Posted by Marcel95 View Post
Can someone tell me where i will find the .csv file after running the macro??

I thought it would be at the same place as my simulation, but there is nothing.
I don't think it's where you said "This should be the location from which the starccm binary is started.
If you are running windows, have a look into your home directory (such as C:/Users/Marcel/)"

I tried and in my case it was at the folder where the .java macro was
cramr5 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
How to write a shell for batch export? zeitistgeld ANSYS 1 October 2, 2009 08:20
Flow, Volume and Pressure Reports in Fluent after batch process ravids FLUENT 0 June 10, 2009 11:56
OpenFOAM on MinGW crosscompiler hosted on Linux allenzhao OpenFOAM Installation 127 January 30, 2009 19:08
How to export residuals plots data in batch mode ? Anthony Haroutunian CFX 1 March 1, 2007 16:10
batch process- export data Grace FLUENT 0 May 15, 2006 20:14


All times are GMT -4. The time now is 08:36.