package holeg.test_sensitivity; import holeg.power_flow.*; import java.io.*; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; public class TestSensitivityProgram { public static void test() { // Load data Bus[] buses = TestData.getIEEE14Busses(); Line[] lines = TestData.getIEEE14Lines(); float xStart = 0; float xEnd = 20.0f; float yStart = 0; float yEnd = 20.0f; float h = 0.1f; int[] lineIndex = new int[] { 6 }; int busIndex = 12; List csvOutput = new ArrayList<>(); StringBuilder xLine = new StringBuilder(); xLine.append(";"); for (float x = xStart; x <= xEnd; x += h) { xLine.append(String.format("%.3f", x)); xLine.append(";"); } csvOutput.add(xLine.toString()); double[] R = new double[lineIndex.length]; double[] X = new double[lineIndex.length]; for (int i = 0; i < lineIndex.length; i++) { R[i] = lines[lineIndex[i]].R; X[i] = lines[lineIndex[i]].X; } double Pg = buses[busIndex].Pg; double Pl = buses[busIndex].Pl; double Qg = buses[busIndex].Qg; double Ql = buses[busIndex].Ql; for (float y = yStart; y <= yEnd; y += h) { System.out.printf("%f / %f\n", y, yEnd); StringBuilder csvLine = new StringBuilder(); csvLine.append(String.format("%.3f", y)); csvLine.append(";"); for (float x = xStart; x <= xEnd; x += h) { /*for (int i = 0; i v.real > 0.3)) csvLine.append(1); else csvLine.append(0); csvLine.append(";"); } csvOutput.add(csvLine.toString()); } String d = new SimpleDateFormat("yyyy-MM-dd hh-mm-ss").format(new Date()); writeToFile("C:\\Users\\hkunz\\Desktop\\test" + d + ".csv", csvOutput); System.out.println("Done!"); } private static void writeToFile(String fileName, List data) { PrintWriter out = null; try { out = new PrintWriter(new OutputStreamWriter( new BufferedOutputStream(new FileOutputStream(fileName)), StandardCharsets.UTF_8)); for (String line : data) out.println(line); } catch (FileNotFoundException e) { e.printStackTrace(); } finally { if (out != null) { out.flush(); out.close(); } } } }