// Calculate Vsh to match the tuned constant Q private Complex solveConstQ(Complex vsh1, Complex vi, ConverterLF converter, double tunedValue) { double qerr = 100.0; Complex vsh = vsh1; double vmsh = vsh.abs(); double thetash = Math.atan2(vsh.getImaginary(), vsh.getReal()); double vmi = vi.abs(); double thetai = Math.atan2(vi.getImaginary(), vi.getReal()); double gsh = converter.getYth().getReal(); double bsh = converter.getYth().getImaginary(); // Iteration by Newton method while (qerr > 0.0001) { // Active power balance equation Fp: active output of v source = 0 double fp = vmsh * vmsh * gsh - vmi * vmsh * (gsh * Math.cos(thetai - thetash) - bsh * Math.sin(thetai - thetash)); // Reactive power balance equation Fq: reactive injection at bus i = -Qsh ("-" means injecting // other than absorbing) double fq = -tunedValue + vmi * vmi * bsh + vmi * vmsh * (gsh * Math.sin(thetai - thetash) - bsh * Math.cos(thetai - thetash)); // Update the mismatch qerr = Math.max(Math.abs(fp), Math.abs(fq)); // Jacobian double a = 2 * vmsh * gsh - vmi * (gsh * Math.cos(thetai - thetash) - bsh * Math.sin(thetai - thetash)); // dFp/dVsh double b = -vmi * vmsh * (gsh * Math.sin(thetai - thetash) + bsh * Math.cos(thetai - thetash)); // dFp/dThetash double c = vmi * (gsh * Math.sin(thetai - thetash) - bsh * Math.cos(thetai - thetash)); // dFq/dVsh double d = -vmi * vmsh * (gsh * Math.cos(thetai - thetash) + bsh * Math.sin(thetai - thetash)); // dFq/dThetash // Solve the mismatch equation double det = a * d - b * c; double dvmsh = (d * fp - b * fq) / det; double dthetash = (-c * fp + a * fq) / det; // Update Vsh and thetash vmsh -= dvmsh; thetash -= dthetash; } System.out.println("thetai=" + thetai + ", thetash=" + thetash); return new Complex(vmsh * Math.cos(thetash), vmsh * Math.sin(thetash)); }
// Calculate Vsh to match the tuned constant B private Complex solveConstB(Complex vsh1, Complex vi, ConverterLF converter, double tunedValue) { double berr = 100.0; Complex vsh = vsh1; double vmsh = vsh.abs(); double thetash = Math.atan2(vsh.getImaginary(), vsh.getReal()); double vmi = vi.abs(); double thetai = Math.atan2(vi.getImaginary(), vi.getReal()); double gsh = converter.getYth().getReal(); double bsh = converter.getYth().getImaginary(); // Iteration by Newton method while (berr > 0.00001) { // Active power balance equation Fp: active output of v source = 0 double fp = vmsh * vmsh * gsh - vmi * vmsh * (gsh * Math.cos(thetai - thetash) - bsh * Math.sin(thetai - thetash)); // Shunt admittance equation Fb: shunt admittance at bus i = Vi / Ishunt double fb = vmsh * (gsh * Math.sin(thetash - thetai) + bsh * Math.cos(thetash - thetai)) + vmi * (tunedValue - bsh); // Update the mismatch berr = Math.max(Math.abs(fp), Math.abs(fb)); // Jacobian double a = 2 * vmsh * gsh - vmi * (gsh * Math.cos(thetai - thetash) - bsh * Math.sin(thetai - thetash)); // dFp/dVsh double b = -vmi * vmsh * (gsh * Math.sin(thetai - thetash) + bsh * Math.cos(thetai - thetash)); // dFp/dThetash double c = gsh * Math.sin(thetash - thetai) + bsh * Math.cos(thetash - thetai); // dFb/dVsh double d = vmsh * (gsh * Math.cos(thetash - thetai) - bsh * Math.sin(thetash - thetai)); // dFb/dThetash // Solve the mismatch equation double det = a * d - b * c; double dvmsh = (d * fp - b * fb) / det; double dthetash = (-c * fp + a * fb) / det; // Update Vsh and thetash vmsh -= dvmsh; thetash -= dthetash; } return new Complex(vmsh * Math.cos(thetash), vmsh * Math.sin(thetash)); }