@@ -295,91 +295,90 @@ PetscErrorCode PFLOWJacobian(SNES snes, Vec X, Mat J, Mat Jpre, void *ctx) {
295
295
thetatf = thetat - thetaf;
296
296
flps += 2 ;
297
297
298
- if (!line->isdcline ) {
299
- PetscScalar Gff, Bff, Gft, Bft, Gtf, Btf, Gtt, Btt;
300
- Gff = line->yff [0 ];
301
- Bff = line->yff [1 ];
302
- Gft = line->yft [0 ];
303
- Bft = line->yft [1 ];
304
- Gtf = line->ytf [0 ];
305
- Btf = line->ytf [1 ];
306
- Gtt = line->ytt [0 ];
307
- Btt = line->ytt [1 ];
308
-
309
- if (bus == busf) {
310
- if (bus->ide != REF_BUS) {
311
- row[0 ] = locglobf;
312
- col[0 ] = locglobf;
313
- col[1 ] = locglobf + 1 ;
314
- col[2 ] = locglobt;
315
- col[3 ] = locglobt + 1 ;
316
- val[0 ] = Vmf * Vmt * (-Gft * sin (thetaft) + Bft * cos (thetaft));
317
- val[1 ] =
318
- 2 * Gff * Vmf + Vmt * (Gft * cos (thetaft) + Bft * sin (thetaft));
319
- val[2 ] = Vmf * Vmt * (Gft * sin (thetaft) - Bft * cos (thetaft));
320
- val[3 ] = Vmf * (Gft * cos (thetaft) + Bft * sin (thetaft));
321
- flps += 21 + (4 * EXAGO_FLOPS_SINOP) + (4 * EXAGO_FLOPS_COSOP);
322
- ierr = MatSetValues (J, 1 , row, 4 , col, val, ADD_VALUES);
323
- CHKERRQ (ierr);
324
-
325
- if (bus->ide != PV_BUS) {
326
- row[0 ] = locglobf + 1 ;
327
- val[0 ] = Vmf * Vmt * (Bft * sin (thetaft) + Gft * cos (thetaft));
328
- val[1 ] = -2 * Bff * Vmf +
329
- Vmt * (-Bft * cos (thetaft) + Gft * sin (thetaft));
330
- val[2 ] = Vmf * Vmt * (-Bft * sin (thetaft) - Gft * cos (thetaft));
331
- val[3 ] = Vmf * (-Bft * cos (thetaft) + Gft * sin (thetaft));
332
- flps += 21 + (4 * EXAGO_FLOPS_SINOP) + (4 * EXAGO_FLOPS_COSOP);
333
- ierr = MatSetValues (J, 1 , row, 4 , col, val, ADD_VALUES);
334
- CHKERRQ (ierr);
335
- }
336
- }
337
- } else {
338
- if (bus->ide != REF_BUS) {
339
- row[0 ] = locglobt;
340
- col[0 ] = locglobt;
341
- col[1 ] = locglobt + 1 ;
342
- col[2 ] = locglobf;
343
- col[3 ] = locglobf + 1 ;
344
- val[0 ] = Vmt * Vmf * (-Gtf * sin (thetatf) + Btf * cos (thetatf));
345
- val[1 ] =
346
- 2 * Gtt * Vmt + Vmf * (Gtf * cos (thetatf) + Btf * sin (thetatf));
347
- val[2 ] = Vmt * Vmf * (Gtf * sin (thetatf) - Btf * cos (thetatf));
348
- val[3 ] = Vmt * (Gtf * cos (thetatf) + Btf * sin (thetatf));
349
- flps += 21 + (4 * EXAGO_FLOPS_SINOP) + (4 * EXAGO_FLOPS_COSOP);
350
- ierr = MatSetValues (J, 1 , row, 4 , col, val, ADD_VALUES);
351
- CHKERRQ (ierr);
352
-
353
- if (bus->ide != PV_BUS) {
354
- row[0 ] = locglobt + 1 ;
355
- val[0 ] = Vmt * Vmf * (Btf * sin (thetatf) + Gtf * cos (thetatf));
356
- val[1 ] = -2 * Btt * Vmt +
357
- Vmf * (-Btf * cos (thetatf) + Gtf * sin (thetatf));
358
- val[2 ] = Vmt * Vmf * (-Btf * sin (thetatf) - Gtf * cos (thetatf));
359
- val[3 ] = Vmt * (-Btf * cos (thetatf) + Gtf * sin (thetatf));
360
- flps += 21 + (4 * EXAGO_FLOPS_SINOP) + (4 * EXAGO_FLOPS_COSOP);
361
- ierr = MatSetValues (J, 1 , row, 4 , col, val, ADD_VALUES);
362
- CHKERRQ (ierr);
363
- }
364
- }
365
- }
366
- } else if (line->isdcline ) {
367
- /* DC line */
368
- if (bus == busf) {
369
- row[0 ] = locglobf + 1 ;
370
- col[0 ] = locglobf + 1 ;
371
- val[0 ] = 1.0 ;
372
- ierr = MatSetValues (J, 1 , row, 1 , col, val, ADD_VALUES);
373
- CHKERRQ (ierr);
374
- } else {
375
- row[0 ] = locglobt + 1 ;
376
- col[0 ] = locglobt + 1 ;
377
- val[0 ] = 1.0 ;
378
- ierr = MatSetValues (J, 1 , row, 1 , col, val, ADD_VALUES);
379
- CHKERRQ (ierr);
380
- }
381
- } else {
382
- /* For future use */
298
+ if (!line->isdcline ) {
299
+ PetscScalar Gff, Bff, Gft, Bft, Gtf, Btf, Gtt, Btt;
300
+ Gff = line->yff [0 ];
301
+ Bff = line->yff [1 ];
302
+ Gft = line->yft [0 ];
303
+ Bft = line->yft [1 ];
304
+ Gtf = line->ytf [0 ];
305
+ Btf = line->ytf [1 ];
306
+ Gtt = line->ytt [0 ];
307
+ Btt = line->ytt [1 ];
308
+
309
+
310
+ if (bus == busf) {
311
+ if (bus->ide != REF_BUS) {
312
+ row[0 ] = locglobf;
313
+ col[0 ] = locglobf;
314
+ col[1 ] = locglobf + 1 ;
315
+ col[2 ] = locglobt;
316
+ col[3 ] = locglobt + 1 ;
317
+ val[0 ] = Vmf * Vmt * (-Gft * sin (thetaft) + Bft * cos (thetaft));
318
+ val[1 ] =
319
+ 2 * Gff * Vmf + Vmt * (Gft * cos (thetaft) + Bft * sin (thetaft));
320
+ val[2 ] = Vmf * Vmt * (Gft * sin (thetaft) - Bft * cos (thetaft));
321
+ val[3 ] = Vmf * (Gft * cos (thetaft) + Bft * sin (thetaft));
322
+ flps += 21 + (4 * EXAGO_FLOPS_SINOP) + (4 * EXAGO_FLOPS_COSOP);
323
+ ierr = MatSetValues (J, 1 , row, 4 , col, val, ADD_VALUES);
324
+ CHKERRQ (ierr);
325
+
326
+ if (bus->ide != PV_BUS) {
327
+ row[0 ] = locglobf + 1 ;
328
+ val[0 ] = Vmf * Vmt * (Bft * sin (thetaft) + Gft * cos (thetaft));
329
+ val[1 ] = -2 * Bff * Vmf +
330
+ Vmt * (-Bft * cos (thetaft) + Gft * sin (thetaft));
331
+ val[2 ] = Vmf * Vmt * (-Bft * sin (thetaft) - Gft * cos (thetaft));
332
+ val[3 ] = Vmf * (-Bft * cos (thetaft) + Gft * sin (thetaft));
333
+ flps += 21 + (4 * EXAGO_FLOPS_SINOP) + (4 * EXAGO_FLOPS_COSOP);
334
+ ierr = MatSetValues (J, 1 , row, 4 , col, val, ADD_VALUES);
335
+ CHKERRQ (ierr);
336
+ }
337
+ }
338
+ } else {
339
+ if (bus->ide != REF_BUS) {
340
+ row[0 ] = locglobt;
341
+ col[0 ] = locglobt;
342
+ col[1 ] = locglobt + 1 ;
343
+ col[2 ] = locglobf;
344
+ col[3 ] = locglobf + 1 ;
345
+ val[0 ] = Vmt * Vmf * (-Gtf * sin (thetatf) + Btf * cos (thetatf));
346
+ val[1 ] =
347
+ 2 * Gtt * Vmt + Vmf * (Gtf * cos (thetatf) + Btf * sin (thetatf));
348
+ val[2 ] = Vmt * Vmf * (Gtf * sin (thetatf) - Btf * cos (thetatf));
349
+ val[3 ] = Vmt * (Gtf * cos (thetatf) + Btf * sin (thetatf));
350
+ flps += 21 + (4 * EXAGO_FLOPS_SINOP) + (4 * EXAGO_FLOPS_COSOP);
351
+ ierr = MatSetValues (J, 1 , row, 4 , col, val, ADD_VALUES);
352
+ CHKERRQ (ierr);
353
+
354
+ if (bus->ide != PV_BUS) {
355
+ row[0 ] = locglobt + 1 ;
356
+ val[0 ] = Vmt * Vmf * (Btf * sin (thetatf) + Gtf * cos (thetatf));
357
+ val[1 ] = -2 * Btt * Vmt +
358
+ Vmf * (-Btf * cos (thetatf) + Gtf * sin (thetatf));
359
+ val[2 ] = Vmt * Vmf * (-Btf * sin (thetatf) - Gtf * cos (thetatf));
360
+ val[3 ] = Vmt * (-Btf * cos (thetatf) + Gtf * sin (thetatf));
361
+ flps += 21 + (4 * EXAGO_FLOPS_SINOP) + (4 * EXAGO_FLOPS_COSOP);
362
+ ierr = MatSetValues (J, 1 , row, 4 , col, val, ADD_VALUES);
363
+ CHKERRQ (ierr);
364
+ }
365
+ }
366
+ }
367
+ } else if (line->isdcline ) {
368
+ /* DC line */
369
+ if (bus == busf) {
370
+ row[0 ] = locglobf+1 ;
371
+ col[0 ] = locglobf+1 ;
372
+ val[0 ] = 1.0 ;
373
+ ierr = MatSetValues (J,1 ,row,1 ,col,val,ADD_VALUES);
374
+ CHKERRQ (ierr);
375
+ } else {
376
+ row[0 ] = locglobt+1 ;
377
+ col[0 ] = locglobt+1 ;
378
+ val[0 ] = 1.0 ;
379
+ ierr = MatSetValues (J,1 ,row,1 ,col,val,ADD_VALUES);
380
+ CHKERRQ (ierr);
381
+ }
383
382
}
384
383
}
385
384
}
0 commit comments