Last active
August 29, 2015 14:02
-
-
Save pfsq/0ca4e68f028ebfde3643 to your computer and use it in GitHub Desktop.
This macro will increase the distance between the trailing and leading vehicle and save reports and scenes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Design of Experiment | |
* | |
* Requirement: MacroUtils v3, available at macrohut.cd-adapco.com | |
* | |
* @author Pablo Fernandez (pfernandez@theansweris27.com) | |
*/ | |
import java.io.*; | |
import macroutils.*; | |
import star.base.neo.*; | |
import star.base.report.Report; | |
import star.common.*; | |
public class drafting extends MacroUtils { | |
public void execute() { | |
_initUtils(); | |
runExperiment(); | |
} | |
public void runExperiment() { | |
// Data file for further postprocessing | |
File file = new File(simPath + "_doe.csv"); | |
PrintWriter out = null; | |
createFile(file, out); | |
// Get boundaries | |
Region rg = sim.getRegionManager().getRegion("Overset 2D"); | |
Units units = sim.getUnitsManager().getPreferredUnits(new IntVector(new int[] {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})); | |
// Loop | |
for (Integer i=1; i<=40; i+=1) { | |
clearSolution(); | |
float xL = i/10.0; | |
// Set boundary values for velocity | |
sim.getRepresentationManager().translateMesh(new NeoObjectVector(new Object[] {rg}), new DoubleVector(new double[] {0.1045, 0.0, 0.0}), new NeoObjectVector(new Object[] {units, units, units}), lab0); | |
sim.getInterfaceManager().initialize(); | |
runCase(2); // run case | |
report(file,out,String.format("%.1f;%s", xL, getDataStr())); | |
String picture = String.format("\\Imagenes Doe\\%s_%02d",simTitle,i); | |
hardCopyPictures(1280, 720, picture); | |
} | |
} | |
void createFile(File file, PrintWriter out) { | |
try { | |
FileWriter fstream = new FileWriter(file, false); // true tells to append data. | |
out = new PrintWriter(fstream); | |
out.println("Spacing (x/L);Drag Lead (-);Lift Lead (-);Drag Trail (-);Lift Trail (-)"); | |
} catch (IOException e) { | |
System.err.println("Error: " + e.getMessage()); | |
} finally { | |
if(out != null) { | |
out.close(); | |
} | |
} | |
} | |
public void report(File file, PrintWriter out, String s) { | |
try { | |
FileWriter fstream = new FileWriter(file, true); | |
out = new PrintWriter(fstream); | |
out.println(s); | |
out.close(); | |
} catch (IOException e) { | |
System.err.println("Error: " + e.getMessage()); | |
} | |
} | |
String getDataStr() { | |
Report rDrag = getReport("Drag Coefficient"); | |
Report rLift = getReport("Lift Coefficient"); | |
Report rDragTrail = getReport("Drag Coefficient Trail"); | |
Report rLiftTrail = getReport("Lift Coefficient Trail"); | |
String str = String.format("%f;%f;%f;%f", | |
rDrag.getReportMonitorValue(), | |
rLift.getReportMonitorValue(), | |
rDragTrail.getReportMonitorValue(), | |
rLiftTrail.getReportMonitorValue()); | |
return str; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment