1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- package holeg.test_sensitivity;
- import holeg.power_flow.*;
- import java.io.*;
- import java.nio.charset.StandardCharsets;
- import java.util.ArrayList;
- import java.util.List;
- public class TestSensitivityProgram {
- public static void test() {
- // Load data
- Bus[] buses = TestData.getIEEE14Busses();
- Line[] lines = TestData.getIEEE14Lines();
- float xStart = -0.8f;
- float xEnd = 10.0f;
- float yStart = -0.8f;
- float yEnd = 10.0f;
- float h = 0.5f;
- int lineIndex = 7;
- int busIndex = 5;
- List<String> 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 = lines[lineIndex].R;
- double X = lines[lineIndex].X;
- double Pg = buses[busIndex].Pg;
- double Pl = buses[busIndex].Pl;
- 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) {
- Line line = lines[lineIndex];
- line.R = R * (1 + x);
- line.X = X * (1 + y);
- /*Bus bus = buses[busIndex];
- bus.Pg = Pg * (1 + x);
- bus.Pl = Pl * (1 + y);*/
- // Create problem and solver
- PowerFlowProblem problem = new PowerFlowProblem(buses, lines, 1, 1 / 100.0);
- Solver solver = new NewtonRaphsonSolver();
- // Solve the problem with default settings
- SolverResult result = solver.solve(problem, new SolverSettings());
- if (result.solved)
- csvLine.append(1);
- else
- csvLine.append(0);
- csvLine.append(";");
- }
- csvOutput.add(csvLine.toString());
- }
- writeToFile("C:\\Users\\Henrik\\Desktop\\test.csv", csvOutput);
- System.out.println("Done!");
- }
- private static void writeToFile(String fileName, List<String> 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();
- }
- }
- }
- }
|