Skip to content

Instantly share code, notes, and snippets.

@pfsq
Last active March 26, 2021 09:28
Show Gist options
  • Save pfsq/aea09bf577368382abc3 to your computer and use it in GitHub Desktop.
Save pfsq/aea09bf577368382abc3 to your computer and use it in GitHub Desktop.
/**
* Design of Experiment: Free stream velocity from 50 to 300 kph in
* steps of 50 kph.
*
* Requirement: MacroUtils v3, available at macrohut.cd-adapco.com
*
* @author Pablo Fernandez (pfernandez@theansweris27.com)
*/
import java.io.*;
import macroutils.*;
import star.base.neo.DoubleVector;
import star.base.report.Report;
import star.common.*;
import star.flow.*;
import star.vis.*;
public class doeVelocity 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("Fluid Volume");
Boundary inlet = rg.getBoundaryManager().getBoundary("Box.Inlet");
VelocityMagnitudeProfile vMP = inlet.getValues().get(VelocityMagnitudeProfile.class);
Boundary floor = rg.getBoundaryManager().getBoundary("Box.Floor");
WallVelocityProfile wVP = floor.getValues().get(WallVelocityProfile.class);
Scene sc = sim.getSceneManager().getScene("Volume Render");
ScalarDisplayer sD = ((ScalarDisplayer) sc.getDisplayerManager().getDisplayer("Resampled Volume Scalar 1"));
// Loop
for (Integer i=50; i<=300; i+=50) {
clearSolutionHistory();
// Set boundary values for velocity
vMP.getMethod(ConstantScalarProfileMethod.class).getQuantity().setValue(i);
wVP.getMethod(ConstantVectorProfileMethod.class).getQuantity().setComponents(0.0, i, 0.0);
runCase(500); // run case for 500 iterations
report(file,out,String.format("%s;%s", i, getDataStr()));
sD.getScalarDisplayQuantity().setRange(new DoubleVector(new double[] {0.0, i*0.66}));
hardCopyPictures(1280, 720, "\\images Doe\\" + simTitle + i + "kph");
}
}
void createFile(File file, PrintWriter out) {
try {
FileWriter fstream = new FileWriter(file, false); // true tells to append data.
out = new PrintWriter(fstream);
out.println("Velocity (kph);Drag (N);Downforce (N)");
} 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 Wing");
Report rDownforce = getReport("Downforce Wing");
String str = String.format("%f;%f",rDrag.getReportMonitorValue(),rDownforce.getReportMonitorValue());
return str;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment