1 // NetLink.java 2 // 3 // 4 // Copyright Björkman Elteknik och Data AB 2000 5 // 6 // 7 // History: 8 // 0.0 Created by Henrik Björkman 2001-01-07 9 // (using code from fluxa.java) 10 // 0.3 Added NetLinkLink. HEnrik 2001-01-08 11 12 import java.io.*; 13 import se.beod.henrik.filter.*; 14 //import java.lang.math; 15 import netlink_package.*; 16 import flux_package.*; 17 18 // nodes in each branch arranged in rising order number from the node 0 source 19 20 21 public class NetLink 22 { 23 final static double PI=3.14159; 24 final static double F=50; // Frequency 25 static double dp=0; 26 27 static int nTypes=0; 28 static NetLinkType linkType[]=new NetLinkType[100]; 29 30 static int nNodes=0; 31 static NetLinkNode node[]=new NetLinkNode[10000]; 32 33 static int nLinks=0; 34 static NetLinkLink link[]=new NetLinkLink[100]; 35 36 static void error(String str) 37 { 38 System.err.println("NetLink: " + str); 39 System.exit(0); 40 } 41 42 static void debug(String str) 43 { 44 System.out.println("NetLink: " + str); 45 } 46 47 static void print(String str) 48 { 49 System.out.print(str); 50 } 51 52 static void println(String str) 53 { 54 System.out.println(str); 55 } 56 57 static String readln() 58 { 59 String str=null; 60 61 try 62 { 63 BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); 64 str=in.readLine(); 65 } 66 catch (IOException e) {error(e.toString());} 67 68 return str; 69 } 70 71 72 73 static double sqr(double a) 74 { 75 return(a*a); 76 } 77 78 static double ATN(double a) 79 { 80 return Math.atan(a); 81 } 82 83 84 /** Read data from file. */ 85 static void readData(String file_name) 86 { 87 PrecompilerReader in=null; 88 89 try 90 { 91 in=new PrecompilerReader(new FileReader(file_name)); 92 } 93 catch (IOException e) {error(""+e);} 94 95 try 96 { 97 for(;;) 98 { 99 String str=in.readWord(); 100 101 if (str==null) break; 102 103 if (str.length()==0) {;} 104 else if (str.equals("dp")) 105 { 106 dp=in.readDouble(); 107 } 108 else if (str.equals("nodes")) 109 { 110 in.readAndSkipWord("{"); 111 for(;;) 112 { 113 node[nNodes]=NetLinkNode.readData(in); 114 if (node[nNodes]==null) break; 115 nNodes++; 116 str=in.readWord(); 117 if (!str.equals(",")) break; 118 } 119 } 120 else if (str.equals("types")) 121 { 122 in.readAndSkipWord("{"); 123 for(;;) 124 { 125 linkType[nTypes]=NetLinkType.readData(in); 126 if (linkType[nTypes]==null) break; 127 nTypes++; 128 str=in.readWord(); 129 if (!str.equals(",")) break; 130 } 131 } 132 else if (str.equals("links")) 133 { 134 in.readAndSkipWord("{"); 135 for(;;) 136 { 137 link[nLinks]=NetLinkLink.readData(in); 138 if (link[nLinks]==null) break; 139 nLinks++; 140 str=in.readWord(); 141 if (!str.equals(",")) break; 142 } 143 } 144 else 145 { 146 error(in.getInfo()+" unknown data: \""+str+"\""); 147 } 148 } 149 in.close(); 150 } 151 //catch (IOException e) {error(in.getInfo()+" "+e); } 152 catch (NumberFormatException e) {error(in.getInfo()+" "+e);} 153 } 154 155 156 // 100 rem summing load capacitive generaation and line losses from leaves to root 157 static void calculate() 158 { 159 int I; // node 1 is supplied from node 0 which is used for sum and no own load 160 int J; // inner quick counter 161 int K;//node type number number zero may be not used to get counting similar to nodes 162 int ITER=0; 163 int cTYP; 164 165 double startU=24;//kV startU should be actual voltage at source och ref for rel spanning med liten imp fr nod1 166 double startV=0; // voltage angle at source 167 double U5=startU;//U5 is used to find and to compare lowest voltage with last value 168 double U6; //voltage difference from previous voltage 169 double U7; //ABS(U7) 170 double U8=0.0001; //for approval of low enough change 171 172 double U[]=new double[1000]; 173 double V[]=new double[1000]; 174 175 double U2[]=new double[1000]; 176 double V2[]=new double[1000]; 177 178 double P1[]=new double[1000]; //accumulated load 179 double Q1[]=new double[1000]; 180 double P2[]=new double[1000]; //losses in the conductors that are fed from the node 181 double Q2[]=new double[1000]; 182 double P3[]=new double[1000]; //not used but could be insulation losses 183 double Q3[]=new double[1000]; //capacitive generation 184 double P4[]=new double[10]; //added plus and minus active load at link nodes to even out voltage and phase difference 185 double Q4[]=new double[10]; //added plus and minus reactive load 186 187 188 189 for (J=0;J1E-6) 195 { 196 197 if (ITER>100) {print("Iteration limit passed="+ITER);break;} 198 199 200 for (I=0;I=0;I--) 211 { 212 if (node[I]==null) {error("No I node "+I);} 213 214 for (J=nNodes-1;J>=0;J--) // node 0 may be the voltage reference point with low impedance to nearest node 215 { 216 debug("I J "+I+" "+J); 217 if (node[J]==null) {error("No J node "+J);} 218 219 if (node[J].nodeId==node[I].fedFrom) 220 { 221 NetLinkType feedingType=linkType[node[J].linkType];// cond to is the nodeJname which is fed from nodeIname search nodes J that have I as feeding node to sum up load and losses 222 if (feedingType==null) {error("No type "+node[J].linkType);} 223 P1[I]=P1[I]+P1[J]+P2[J]; 224 Q1[I]=Q1[I]+Q1[J]+Q2[J]-node[J].kmN*PI*F*feedingType.c*0.000001*U[J]*U[J]; 225 Q3[J]=node[J].kmN*PI*F*feedingType.c*0.000001*U[I]*U[I];Q3[I]=Q3[I]+Q3[J];//Capacitive gen node[J]from is the only one feeder to J 226 } 227 } 228 } 229 230 for (I=nNodes-1;I>0;I--) 231 { 232 NetLinkType feedingConductorType=linkType[node[I].linkType]; 233 234 //adding own load 235 P1[I]=P1[I]+node[I].mw; 236 Q1[I]=Q1[I]+node[I].mvar-Q3[I]; 237 238 // Calculating losses 239 V2[I]=ATN(node[I].kmN*(feedingConductorType.x*P1[I]-feedingConductorType.r*Q1[I])/U[I]/U[I]);//voltage angle change in the uniq feeder 240 U2[I]=U[I]-(U[I]-node[I].kmN*(feedingConductorType.r*P1[I]+feedingConductorType.x*Q1[I])/U[I])/Math.cos(V2[I]); 241 P2[I]=node[I].kmN*feedingConductorType.r*(P1[I]*P1[I]+Q1[I]*Q1[I])/U[I]/U[I]; 242 Q2[I]=node[I].kmN*feedingConductorType.x*(P1[I]*P1[I]+Q1[I]*Q1[I])/U[I]/U[I]; 243 } 244 245 debug(""); 246 for (I=0;I0.0001) 266 { 267 U5=U[nNodes-1]; 268 } 269 } 270 } 271 272 273 /** Read calibration data from file. */ 274 static void writeData() 275 { 276 int i; 277 278 println("dp "+dp); 279 280 println("links{"); 281 for (i=0;i"); 326 System.exit(0); 327 } 328 329 readData(args[0]); 330 331 writeData(); 332 333 calculate(); 334 335 writeData(); 336 337 } 338 339 340 341 } 342