-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpf.c.html
More file actions
585 lines (515 loc) · 60.7 KB
/
pf.c.html
File metadata and controls
585 lines (515 loc) · 60.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
<center><a href="pf.c">Actual source code: pf.c</a></center><br>
<html>
<head> <link rel="canonical" href="http://www.mcs.anl.gov/petsc/petsc-current/src/snes/examples/tutorials/network/pflow/pf.c.html" />
<title></title>
<meta name="generator" content="c2html 0.9.4">
<meta name="date" content="2017-04-24T14:31:34+00:00">
</head>
<body bgcolor="#FFFFFF">
<div id="version" align=right><b>petsc-3.7.6 2017-04-24</b></div>
<div id="bugreport" align=right><a href="mailto:petsc-maint@mcs.anl.gov?subject=Typo or Error in Documentation &body=Please describe the typo or error in the documentation: petsc-3.7.6 v3.7.6 src/snes/examples/tutorials/network/pflow/pf.c.html "><small>Report Typos and Errors</small></a></div>
<pre width="80"><a name="line1"> 1: </a>static char help[] = <font color="#666666">"This example demonstrates the use of DMNetwork interface for solving a nonlinear electric power grid problem.\n\</font>
<a name="line2"> 2: </a><font color="#666666"> The available solver options are in the pfoptions file and the data files are in the datafiles directory.\n\</font>
<a name="line3"> 3: </a><font color="#666666"> The data file format used is from the MatPower package (http://www.pserc.cornell.edu//matpower/).\n\</font>
<a name="line4"> 4: </a><font color="#666666"> Run this program: mpiexec -n <n> ./<a href="../../../../../../docs/manualpages/PF/PF.html#PF">PF</a>\n\</font>
<a name="line5"> 5: </a><font color="#666666"> mpiexec -n <n> ./<a href="../../../../../../docs/manualpages/PF/PF.html#PF">PF</a> -pfdata <filename>\n"</font>;
<a name="line7"> 7: </a><font color="#B22222">/* T</font>
<a name="line8"> 8: </a><font color="#B22222"> Concepts: DMNetwork</font>
<a name="line9"> 9: </a><font color="#B22222"> Concepts: PETSc <a href="../../../../../../docs/manualpages/SNES/SNES.html#SNES">SNES</a> solver</font>
<a name="line10"> 10: </a><font color="#B22222">*/</font>
<a name="line12"> 12: </a> #include <A href="pf.h.html">pf.h</A>
<a name="line14"> 14: </a><a href="../../../../../../docs/manualpages/Sys/PetscMPIInt.html#PetscMPIInt">PetscMPIInt</a> rank;
<a name="line18"> 18: </a><strong><font color="#4169E1"><a name="GetListofEdges"></a><a href="../../../../../../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</a> GetListofEdges(<a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> nbranches, EDGEDATA branch,int edges[])</font></strong>
<a name="line19"> 19: </a>{
<a name="line20"> 20: </a> <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> i, fbus,tbus;
<a name="line23"> 23: </a> <font color="#4169E1">for</font> (i=0; i < nbranches; i++) {
<a name="line24"> 24: </a> fbus = branch[i].internal_i;
<a name="line25"> 25: </a> tbus = branch[i].internal_j;
<a name="line26"> 26: </a> edges[2*i] = fbus;
<a name="line27"> 27: </a> edges[2*i+1] = tbus;
<a name="line28"> 28: </a> }
<a name="line29"> 29: </a> <font color="#4169E1">return</font>(0);
<a name="line30"> 30: </a>}
<a name="line32"> 32: </a><font color="#4169E1">typedef</font> <font color="#4169E1">struct</font>{
<a name="line33"> 33: </a> <a href="../../../../../../docs/manualpages/Sys/PetscScalar.html#PetscScalar">PetscScalar</a> Sbase;
<a name="line34"> 34: </a>}UserCtx;
<a name="line38"> 38: </a><strong><font color="#4169E1"><a name="FormFunction"></a><a href="../../../../../../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</a> FormFunction(<a href="../../../../../../docs/manualpages/SNES/SNES.html#SNES">SNES</a> snes,<a href="../../../../../../docs/manualpages/Vec/Vec.html#Vec">Vec</a> X, <a href="../../../../../../docs/manualpages/Vec/Vec.html#Vec">Vec</a> F,void *appctx)</font></strong>
<a name="line39"> 39: </a>{
<a name="line41"> 41: </a> <a href="../../../../../../docs/manualpages/DM/DM.html#DM">DM</a> networkdm;
<a name="line42"> 42: </a> UserCtx *User=(UserCtx*)appctx;
<a name="line43"> 43: </a> <a href="../../../../../../docs/manualpages/Vec/Vec.html#Vec">Vec</a> localX,localF;
<a name="line44"> 44: </a> <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> e;
<a name="line45"> 45: </a> <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> v,vStart,vEnd,vfrom,vto;
<a name="line46"> 46: </a> const <a href="../../../../../../docs/manualpages/Sys/PetscScalar.html#PetscScalar">PetscScalar</a> *xarr;
<a name="line47"> 47: </a> <a href="../../../../../../docs/manualpages/Sys/PetscScalar.html#PetscScalar">PetscScalar</a> *farr;
<a name="line48"> 48: </a> <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> offsetfrom,offsetto,offset;
<a name="line49"> 49: </a> DMNetworkComponentGenericDataType *arr;
<a name="line52"> 52: </a> <a href="../../../../../../docs/manualpages/SNES/SNESGetDM.html#SNESGetDM">SNESGetDM</a>(snes,&networkdm);
<a name="line53"> 53: </a> <a href="../../../../../../docs/manualpages/DM/DMGetLocalVector.html#DMGetLocalVector">DMGetLocalVector</a>(networkdm,&localX);
<a name="line54"> 54: </a> <a href="../../../../../../docs/manualpages/DM/DMGetLocalVector.html#DMGetLocalVector">DMGetLocalVector</a>(networkdm,&localF);
<a name="line55"> 55: </a> <a href="../../../../../../docs/manualpages/Vec/VecSet.html#VecSet">VecSet</a>(F,0.0);
<a name="line57"> 57: </a> <a href="../../../../../../docs/manualpages/DM/DMGlobalToLocalBegin.html#DMGlobalToLocalBegin">DMGlobalToLocalBegin</a>(networkdm,X,<a href="../../../../../../docs/manualpages/Sys/INSERT_VALUES.html#INSERT_VALUES">INSERT_VALUES</a>,localX);
<a name="line58"> 58: </a> <a href="../../../../../../docs/manualpages/DM/DMGlobalToLocalEnd.html#DMGlobalToLocalEnd">DMGlobalToLocalEnd</a>(networkdm,X,<a href="../../../../../../docs/manualpages/Sys/INSERT_VALUES.html#INSERT_VALUES">INSERT_VALUES</a>,localX);
<a name="line60"> 60: </a> <a href="../../../../../../docs/manualpages/DM/DMGlobalToLocalBegin.html#DMGlobalToLocalBegin">DMGlobalToLocalBegin</a>(networkdm,F,<a href="../../../../../../docs/manualpages/Sys/INSERT_VALUES.html#INSERT_VALUES">INSERT_VALUES</a>,localF);
<a name="line61"> 61: </a> <a href="../../../../../../docs/manualpages/DM/DMGlobalToLocalEnd.html#DMGlobalToLocalEnd">DMGlobalToLocalEnd</a>(networkdm,F,<a href="../../../../../../docs/manualpages/Sys/INSERT_VALUES.html#INSERT_VALUES">INSERT_VALUES</a>,localF);
<a name="line63"> 63: </a> <a href="../../../../../../docs/manualpages/Vec/VecGetArrayRead.html#VecGetArrayRead">VecGetArrayRead</a>(localX,&xarr);
<a name="line64"> 64: </a> <a href="../../../../../../docs/manualpages/Vec/VecGetArray.html#VecGetArray">VecGetArray</a>(localF,&farr);
<a name="line66"> 66: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetVertexRange.html#DMNetworkGetVertexRange">DMNetworkGetVertexRange</a>(networkdm,&vStart,&vEnd);
<a name="line67"> 67: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetComponentDataArray.html#DMNetworkGetComponentDataArray">DMNetworkGetComponentDataArray</a>(networkdm,&arr);
<a name="line69"> 69: </a> <font color="#4169E1">for</font> (v=vStart; v < vEnd; v++) {
<a name="line70"> 70: </a> <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> i,j,offsetd,key;
<a name="line71"> 71: </a> <a href="../../../../../../docs/manualpages/Sys/PetscScalar.html#PetscScalar">PetscScalar</a> Vm;
<a name="line72"> 72: </a> <a href="../../../../../../docs/manualpages/Sys/PetscScalar.html#PetscScalar">PetscScalar</a> Sbase=User->Sbase;
<a name="line73"> 73: </a> VERTEXDATA bus=NULL;
<a name="line74"> 74: </a> GEN gen;
<a name="line75"> 75: </a> LOAD load;
<a name="line76"> 76: </a> <a href="../../../../../../docs/manualpages/Sys/PetscBool.html#PetscBool">PetscBool</a> ghostvtex;
<a name="line77"> 77: </a> <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> numComps;
<a name="line79"> 79: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkIsGhostVertex.html#DMNetworkIsGhostVertex">DMNetworkIsGhostVertex</a>(networkdm,v,&ghostvtex);
<a name="line80"> 80: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetNumComponents.html#DMNetworkGetNumComponents">DMNetworkGetNumComponents</a>(networkdm,v,&numComps);
<a name="line81"> 81: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetVariableOffset.html#DMNetworkGetVariableOffset">DMNetworkGetVariableOffset</a>(networkdm,v,&offset);
<a name="line82"> 82: </a> <font color="#4169E1">for</font> (j = 0; j < numComps; j++) {
<a name="line83"> 83: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetComponentTypeOffset.html#DMNetworkGetComponentTypeOffset">DMNetworkGetComponentTypeOffset</a>(networkdm,v,j,&key,&offsetd);
<a name="line84"> 84: </a> <font color="#4169E1">if</font> (key == 1) {
<a name="line85"> 85: </a> <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> nconnedges;
<a name="line86"> 86: </a> const <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> *connedges;
<a name="line88"> 88: </a> bus = (VERTEXDATA)(arr+offsetd);
<a name="line89"> 89: </a> <font color="#B22222">/* Handle reference bus constrained dofs */</font>
<a name="line90"> 90: </a> <font color="#4169E1">if</font> (bus->ide == REF_BUS || bus->ide == ISOLATED_BUS) {
<a name="line91"> 91: </a> farr[offset] = xarr[offset] - bus->va*PETSC_PI/180.0;
<a name="line92"> 92: </a> farr[offset+1] = xarr[offset+1] - bus->vm;
<a name="line93"> 93: </a> <font color="#4169E1">break</font>;
<a name="line94"> 94: </a> }
<a name="line96"> 96: </a> <font color="#4169E1">if</font> (!ghostvtex) {
<a name="line97"> 97: </a> Vm = xarr[offset+1];
<a name="line99"> 99: </a> <font color="#B22222">/* Shunt injections */</font>
<a name="line100">100: </a> farr[offset] += Vm*Vm*bus->gl/Sbase;
<a name="line101">101: </a> <font color="#4169E1">if</font>(bus->ide != PV_BUS) farr[offset+1] += -Vm*Vm*bus->bl/Sbase;
<a name="line102">102: </a> }
<a name="line104">104: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetSupportingEdges.html#DMNetworkGetSupportingEdges">DMNetworkGetSupportingEdges</a>(networkdm,v,&nconnedges,&connedges);
<a name="line105">105: </a> <font color="#4169E1">for</font> (i=0; i < nconnedges; i++) {
<a name="line106">106: </a> EDGEDATA branch;
<a name="line107">107: </a> <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> keye;
<a name="line108">108: </a> <a href="../../../../../../docs/manualpages/Sys/PetscScalar.html#PetscScalar">PetscScalar</a> Gff,Bff,Gft,Bft,Gtf,Btf,Gtt,Btt;
<a name="line109">109: </a> const <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> *cone;
<a name="line110">110: </a> <a href="../../../../../../docs/manualpages/Sys/PetscScalar.html#PetscScalar">PetscScalar</a> Vmf,Vmt,thetaf,thetat,thetaft,thetatf;
<a name="line112">112: </a> e = connedges[i];
<a name="line113">113: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetComponentTypeOffset.html#DMNetworkGetComponentTypeOffset">DMNetworkGetComponentTypeOffset</a>(networkdm,e,0,&keye,&offsetd);
<a name="line114">114: </a> branch = (EDGEDATA)(arr+offsetd);
<a name="line115">115: </a> <font color="#4169E1">if</font> (!branch->status) <font color="#4169E1">continue</font>;
<a name="line116">116: </a> Gff = branch->yff[0];
<a name="line117">117: </a> Bff = branch->yff[1];
<a name="line118">118: </a> Gft = branch->yft[0];
<a name="line119">119: </a> Bft = branch->yft[1];
<a name="line120">120: </a> Gtf = branch->ytf[0];
<a name="line121">121: </a> Btf = branch->ytf[1];
<a name="line122">122: </a> Gtt = branch->ytt[0];
<a name="line123">123: </a> Btt = branch->ytt[1];
<a name="line125">125: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetConnectedNodes.html#DMNetworkGetConnectedNodes">DMNetworkGetConnectedNodes</a>(networkdm,e,&cone);
<a name="line126">126: </a> vfrom = cone[0];
<a name="line127">127: </a> vto = cone[1];
<a name="line129">129: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetVariableOffset.html#DMNetworkGetVariableOffset">DMNetworkGetVariableOffset</a>(networkdm,vfrom,&offsetfrom);
<a name="line130">130: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetVariableOffset.html#DMNetworkGetVariableOffset">DMNetworkGetVariableOffset</a>(networkdm,vto,&offsetto);
<a name="line132">132: </a> thetaf = xarr[offsetfrom];
<a name="line133">133: </a> Vmf = xarr[offsetfrom+1];
<a name="line134">134: </a> thetat = xarr[offsetto];
<a name="line135">135: </a> Vmt = xarr[offsetto+1];
<a name="line136">136: </a> thetaft = thetaf - thetat;
<a name="line137">137: </a> thetatf = thetat - thetaf;
<a name="line139">139: </a> <font color="#4169E1">if</font> (vfrom == v) {
<a name="line140">140: </a> farr[offsetfrom] += Gff*Vmf*Vmf + Vmf*Vmt*(Gft*PetscCosScalar(thetaft) + Bft*PetscSinScalar(thetaft));
<a name="line141">141: </a> farr[offsetfrom+1] += -Bff*Vmf*Vmf + Vmf*Vmt*(-Bft*PetscCosScalar(thetaft) + Gft*PetscSinScalar(thetaft));
<a name="line142">142: </a> } <font color="#4169E1">else</font> {
<a name="line143">143: </a> farr[offsetto] += Gtt*Vmt*Vmt + Vmt*Vmf*(Gtf*PetscCosScalar(thetatf) + Btf*PetscSinScalar(thetatf));
<a name="line144">144: </a> farr[offsetto+1] += -Btt*Vmt*Vmt + Vmt*Vmf*(-Btf*PetscCosScalar(thetatf) + Gtf*PetscSinScalar(thetatf));
<a name="line145">145: </a> }
<a name="line146">146: </a> }
<a name="line147">147: </a> } <font color="#4169E1">else</font> <font color="#4169E1">if</font> (key == 2) {
<a name="line148">148: </a> <font color="#4169E1">if</font> (!ghostvtex) {
<a name="line149">149: </a> gen = (GEN)(arr+offsetd);
<a name="line150">150: </a> <font color="#4169E1">if</font> (!gen->status) <font color="#4169E1">continue</font>;
<a name="line151">151: </a> farr[offset] += -gen->pg/Sbase;
<a name="line152">152: </a> farr[offset+1] += -gen->qg/Sbase;
<a name="line153">153: </a> }
<a name="line154">154: </a> } <font color="#4169E1">else</font> <font color="#4169E1">if</font> (key == 3) {
<a name="line155">155: </a> <font color="#4169E1">if</font> (!ghostvtex) {
<a name="line156">156: </a> load = (LOAD)(arr+offsetd);
<a name="line157">157: </a> farr[offset] += load->pl/Sbase;
<a name="line158">158: </a> farr[offset+1] += load->ql/Sbase;
<a name="line159">159: </a> }
<a name="line160">160: </a> }
<a name="line161">161: </a> }
<a name="line162">162: </a> <font color="#4169E1">if</font> (bus && bus->ide == PV_BUS) {
<a name="line163">163: </a> farr[offset+1] = xarr[offset+1] - bus->vm;
<a name="line164">164: </a> }
<a name="line165">165: </a> }
<a name="line166">166: </a> <a href="../../../../../../docs/manualpages/Vec/VecRestoreArrayRead.html#VecRestoreArrayRead">VecRestoreArrayRead</a>(localX,&xarr);
<a name="line167">167: </a> <a href="../../../../../../docs/manualpages/Vec/VecRestoreArray.html#VecRestoreArray">VecRestoreArray</a>(localF,&farr);
<a name="line168">168: </a> <a href="../../../../../../docs/manualpages/DM/DMRestoreLocalVector.html#DMRestoreLocalVector">DMRestoreLocalVector</a>(networkdm,&localX);
<a name="line170">170: </a> <a href="../../../../../../docs/manualpages/DM/DMLocalToGlobalBegin.html#DMLocalToGlobalBegin">DMLocalToGlobalBegin</a>(networkdm,localF,<a href="../../../../../../docs/manualpages/Sys/ADD_VALUES.html#ADD_VALUES">ADD_VALUES</a>,F);
<a name="line171">171: </a> <a href="../../../../../../docs/manualpages/DM/DMLocalToGlobalEnd.html#DMLocalToGlobalEnd">DMLocalToGlobalEnd</a>(networkdm,localF,<a href="../../../../../../docs/manualpages/Sys/ADD_VALUES.html#ADD_VALUES">ADD_VALUES</a>,F);
<a name="line172">172: </a> <a href="../../../../../../docs/manualpages/DM/DMRestoreLocalVector.html#DMRestoreLocalVector">DMRestoreLocalVector</a>(networkdm,&localF);
<a name="line173">173: </a> <font color="#4169E1">return</font>(0);
<a name="line174">174: </a>}
<a name="line178">178: </a><strong><font color="#4169E1"><a name="FormJacobian"></a><a href="../../../../../../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</a> FormJacobian(<a href="../../../../../../docs/manualpages/SNES/SNES.html#SNES">SNES</a> snes,<a href="../../../../../../docs/manualpages/Vec/Vec.html#Vec">Vec</a> X, <a href="../../../../../../docs/manualpages/Mat/Mat.html#Mat">Mat</a> J,<a href="../../../../../../docs/manualpages/Mat/Mat.html#Mat">Mat</a> Jpre,void *appctx)</font></strong>
<a name="line179">179: </a>{
<a name="line181">181: </a> <a href="../../../../../../docs/manualpages/DM/DM.html#DM">DM</a> networkdm;
<a name="line182">182: </a> UserCtx *User=(UserCtx*)appctx;
<a name="line183">183: </a> <a href="../../../../../../docs/manualpages/Vec/Vec.html#Vec">Vec</a> localX;
<a name="line184">184: </a> <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> e;
<a name="line185">185: </a> <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> v,vStart,vEnd,vfrom,vto;
<a name="line186">186: </a> const <a href="../../../../../../docs/manualpages/Sys/PetscScalar.html#PetscScalar">PetscScalar</a> *xarr;
<a name="line187">187: </a> <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> offsetfrom,offsetto,goffsetfrom,goffsetto;
<a name="line188">188: </a> DMNetworkComponentGenericDataType *arr;
<a name="line189">189: </a> <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> row[2],col[8];
<a name="line190">190: </a> <a href="../../../../../../docs/manualpages/Sys/PetscScalar.html#PetscScalar">PetscScalar</a> values[8];
<a name="line193">193: </a> <a href="../../../../../../docs/manualpages/Mat/MatZeroEntries.html#MatZeroEntries">MatZeroEntries</a>(J);
<a name="line195">195: </a> <a href="../../../../../../docs/manualpages/SNES/SNESGetDM.html#SNESGetDM">SNESGetDM</a>(snes,&networkdm);
<a name="line196">196: </a> <a href="../../../../../../docs/manualpages/DM/DMGetLocalVector.html#DMGetLocalVector">DMGetLocalVector</a>(networkdm,&localX);
<a name="line198">198: </a> <a href="../../../../../../docs/manualpages/DM/DMGlobalToLocalBegin.html#DMGlobalToLocalBegin">DMGlobalToLocalBegin</a>(networkdm,X,<a href="../../../../../../docs/manualpages/Sys/INSERT_VALUES.html#INSERT_VALUES">INSERT_VALUES</a>,localX);
<a name="line199">199: </a> <a href="../../../../../../docs/manualpages/DM/DMGlobalToLocalEnd.html#DMGlobalToLocalEnd">DMGlobalToLocalEnd</a>(networkdm,X,<a href="../../../../../../docs/manualpages/Sys/INSERT_VALUES.html#INSERT_VALUES">INSERT_VALUES</a>,localX);
<a name="line201">201: </a> <a href="../../../../../../docs/manualpages/Vec/VecGetArrayRead.html#VecGetArrayRead">VecGetArrayRead</a>(localX,&xarr);
<a name="line203">203: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetVertexRange.html#DMNetworkGetVertexRange">DMNetworkGetVertexRange</a>(networkdm,&vStart,&vEnd);
<a name="line204">204: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetComponentDataArray.html#DMNetworkGetComponentDataArray">DMNetworkGetComponentDataArray</a>(networkdm,&arr);
<a name="line206">206: </a> <font color="#4169E1">for</font> (v=vStart; v < vEnd; v++) {
<a name="line207">207: </a> <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> i,j,offsetd,key;
<a name="line208">208: </a> <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> offset,goffset;
<a name="line209">209: </a> <a href="../../../../../../docs/manualpages/Sys/PetscScalar.html#PetscScalar">PetscScalar</a> Vm;
<a name="line210">210: </a> <a href="../../../../../../docs/manualpages/Sys/PetscScalar.html#PetscScalar">PetscScalar</a> Sbase=User->Sbase;
<a name="line211">211: </a> VERTEXDATA bus;
<a name="line212">212: </a> <a href="../../../../../../docs/manualpages/Sys/PetscBool.html#PetscBool">PetscBool</a> ghostvtex;
<a name="line213">213: </a> <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> numComps;
<a name="line215">215: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkIsGhostVertex.html#DMNetworkIsGhostVertex">DMNetworkIsGhostVertex</a>(networkdm,v,&ghostvtex);
<a name="line216">216: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetNumComponents.html#DMNetworkGetNumComponents">DMNetworkGetNumComponents</a>(networkdm,v,&numComps);
<a name="line217">217: </a> <font color="#4169E1">for</font> (j = 0; j < numComps; j++) {
<a name="line218">218: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetVariableOffset.html#DMNetworkGetVariableOffset">DMNetworkGetVariableOffset</a>(networkdm,v,&offset);
<a name="line219">219: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetVariableGlobalOffset.html#DMNetworkGetVariableGlobalOffset">DMNetworkGetVariableGlobalOffset</a>(networkdm,v,&goffset);
<a name="line220">220: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetComponentTypeOffset.html#DMNetworkGetComponentTypeOffset">DMNetworkGetComponentTypeOffset</a>(networkdm,v,j,&key,&offsetd);
<a name="line221">221: </a> <font color="#4169E1">if</font> (key == 1) {
<a name="line222">222: </a> <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> nconnedges;
<a name="line223">223: </a> const <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> *connedges;
<a name="line225">225: </a> bus = (VERTEXDATA)(arr+offsetd);
<a name="line226">226: </a> <font color="#4169E1">if</font> (!ghostvtex) {
<a name="line227">227: </a> <font color="#B22222">/* Handle reference bus constrained dofs */</font>
<a name="line228">228: </a> <font color="#4169E1">if</font> (bus->ide == REF_BUS || bus->ide == ISOLATED_BUS) {
<a name="line229">229: </a> row[0] = goffset; row[1] = goffset+1;
<a name="line230">230: </a> col[0] = goffset; col[1] = goffset+1; col[2] = goffset; col[3] = goffset+1;
<a name="line231">231: </a> values[0] = 1.0; values[1] = 0.0; values[2] = 0.0; values[3] = 1.0;
<a name="line232">232: </a> <a href="../../../../../../docs/manualpages/Mat/MatSetValues.html#MatSetValues">MatSetValues</a>(J,2,row,2,col,values,<a href="../../../../../../docs/manualpages/Sys/ADD_VALUES.html#ADD_VALUES">ADD_VALUES</a>);
<a name="line233">233: </a> <font color="#4169E1">break</font>;
<a name="line234">234: </a> }
<a name="line235">235: </a>
<a name="line236">236: </a> Vm = xarr[offset+1];
<a name="line237">237: </a>
<a name="line238">238: </a> <font color="#B22222">/* Shunt injections */</font>
<a name="line239">239: </a> row[0] = goffset; row[1] = goffset+1;
<a name="line240">240: </a> col[0] = goffset; col[1] = goffset+1;
<a name="line241">241: </a> values[0] = values[1] = values[2] = values[3] = 0.0;
<a name="line242">242: </a> <font color="#4169E1">if</font> (bus->ide != PV_BUS) {
<a name="line243">243: </a> values[1] = 2.0*Vm*bus->gl/Sbase;
<a name="line244">244: </a> values[3] = -2.0*Vm*bus->bl/Sbase;
<a name="line245">245: </a> }
<a name="line246">246: </a> <a href="../../../../../../docs/manualpages/Mat/MatSetValues.html#MatSetValues">MatSetValues</a>(J,2,row,2,col,values,<a href="../../../../../../docs/manualpages/Sys/ADD_VALUES.html#ADD_VALUES">ADD_VALUES</a>);
<a name="line247">247: </a> }
<a name="line249">249: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetSupportingEdges.html#DMNetworkGetSupportingEdges">DMNetworkGetSupportingEdges</a>(networkdm,v,&nconnedges,&connedges);
<a name="line250">250: </a> <font color="#4169E1">for</font> (i=0; i < nconnedges; i++) {
<a name="line251">251: </a> EDGEDATA branch;
<a name="line252">252: </a> VERTEXDATA busf,bust;
<a name="line253">253: </a> <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> offsetfd,offsettd,keyf,keyt;
<a name="line254">254: </a> <a href="../../../../../../docs/manualpages/Sys/PetscScalar.html#PetscScalar">PetscScalar</a> Gff,Bff,Gft,Bft,Gtf,Btf,Gtt,Btt;
<a name="line255">255: </a> const <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> *cone;
<a name="line256">256: </a> <a href="../../../../../../docs/manualpages/Sys/PetscScalar.html#PetscScalar">PetscScalar</a> Vmf,Vmt,thetaf,thetat,thetaft,thetatf;
<a name="line258">258: </a> e = connedges[i];
<a name="line259">259: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetComponentTypeOffset.html#DMNetworkGetComponentTypeOffset">DMNetworkGetComponentTypeOffset</a>(networkdm,e,0,&key,&offsetd);
<a name="line260">260: </a> branch = (EDGEDATA)(arr+offsetd);
<a name="line261">261: </a> <font color="#4169E1">if</font> (!branch->status) <font color="#4169E1">continue</font>;
<a name="line262">262: </a>
<a name="line263">263: </a> Gff = branch->yff[0];
<a name="line264">264: </a> Bff = branch->yff[1];
<a name="line265">265: </a> Gft = branch->yft[0];
<a name="line266">266: </a> Bft = branch->yft[1];
<a name="line267">267: </a> Gtf = branch->ytf[0];
<a name="line268">268: </a> Btf = branch->ytf[1];
<a name="line269">269: </a> Gtt = branch->ytt[0];
<a name="line270">270: </a> Btt = branch->ytt[1];
<a name="line272">272: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetConnectedNodes.html#DMNetworkGetConnectedNodes">DMNetworkGetConnectedNodes</a>(networkdm,e,&cone);
<a name="line273">273: </a> vfrom = cone[0];
<a name="line274">274: </a> vto = cone[1];
<a name="line276">276: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetVariableOffset.html#DMNetworkGetVariableOffset">DMNetworkGetVariableOffset</a>(networkdm,vfrom,&offsetfrom);
<a name="line277">277: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetVariableOffset.html#DMNetworkGetVariableOffset">DMNetworkGetVariableOffset</a>(networkdm,vto,&offsetto);
<a name="line278">278: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetVariableGlobalOffset.html#DMNetworkGetVariableGlobalOffset">DMNetworkGetVariableGlobalOffset</a>(networkdm,vfrom,&goffsetfrom);
<a name="line279">279: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetVariableGlobalOffset.html#DMNetworkGetVariableGlobalOffset">DMNetworkGetVariableGlobalOffset</a>(networkdm,vto,&goffsetto);
<a name="line281">281: </a> <font color="#4169E1">if</font> (goffsetto < 0) goffsetto = -goffsetto - 1;
<a name="line283">283: </a> thetaf = xarr[offsetfrom];
<a name="line284">284: </a> Vmf = xarr[offsetfrom+1];
<a name="line285">285: </a> thetat = xarr[offsetto];
<a name="line286">286: </a> Vmt = xarr[offsetto+1];
<a name="line287">287: </a> thetaft = thetaf - thetat;
<a name="line288">288: </a> thetatf = thetat - thetaf;
<a name="line290">290: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetComponentTypeOffset.html#DMNetworkGetComponentTypeOffset">DMNetworkGetComponentTypeOffset</a>(networkdm,vfrom,0,&keyf,&offsetfd);
<a name="line291">291: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetComponentTypeOffset.html#DMNetworkGetComponentTypeOffset">DMNetworkGetComponentTypeOffset</a>(networkdm,vto,0,&keyt,&offsettd);
<a name="line292">292: </a> busf = (VERTEXDATA)(arr+offsetfd);
<a name="line293">293: </a> bust = (VERTEXDATA)(arr+offsettd);
<a name="line295">295: </a> <font color="#4169E1">if</font> (vfrom == v) {
<a name="line296">296: </a> <font color="#4169E1">if</font> (busf->ide != REF_BUS) {
<a name="line297">297: </a> <font color="#B22222">/* farr[offsetfrom] += Gff*Vmf*Vmf + Vmf*Vmt*(Gft*PetscCosScalar(thetaft) + Bft*PetscSinScalar(thetaft)); */</font>
<a name="line298">298: </a> row[0] = goffsetfrom;
<a name="line299">299: </a> col[0] = goffsetfrom; col[1] = goffsetfrom+1; col[2] = goffsetto; col[3] = goffsetto+1;
<a name="line300">300: </a> values[0] = Vmf*Vmt*(Gft*-PetscSinScalar(thetaft) + Bft*PetscCosScalar(thetaft)); <font color="#B22222">/* df_dthetaf */</font>
<a name="line301">301: </a> values[1] = 2.0*Gff*Vmf + Vmt*(Gft*PetscCosScalar(thetaft) + Bft*PetscSinScalar(thetaft)); <font color="#B22222">/* df_dVmf */</font>
<a name="line302">302: </a> values[2] = Vmf*Vmt*(Gft*PetscSinScalar(thetaft) + Bft*-PetscCosScalar(thetaft)); <font color="#B22222">/* df_dthetat */</font>
<a name="line303">303: </a> values[3] = Vmf*(Gft*PetscCosScalar(thetaft) + Bft*PetscSinScalar(thetaft)); <font color="#B22222">/* df_dVmt */</font>
<a name="line304">304: </a>
<a name="line305">305: </a> <a href="../../../../../../docs/manualpages/Mat/MatSetValues.html#MatSetValues">MatSetValues</a>(J,1,row,4,col,values,<a href="../../../../../../docs/manualpages/Sys/ADD_VALUES.html#ADD_VALUES">ADD_VALUES</a>);
<a name="line306">306: </a> }
<a name="line307">307: </a> <font color="#4169E1">if</font> (busf->ide != PV_BUS && busf->ide != REF_BUS) {
<a name="line308">308: </a> row[0] = goffsetfrom+1;
<a name="line309">309: </a> col[0] = goffsetfrom; col[1] = goffsetfrom+1; col[2] = goffsetto; col[3] = goffsetto+1;
<a name="line310">310: </a> <font color="#B22222">/* farr[offsetfrom+1] += -Bff*Vmf*Vmf + Vmf*Vmt*(-Bft*PetscCosScalar(thetaft) + Gft*PetscSinScalar(thetaft)); */</font>
<a name="line311">311: </a> values[0] = Vmf*Vmt*(Bft*PetscSinScalar(thetaft) + Gft*PetscCosScalar(thetaft));
<a name="line312">312: </a> values[1] = -2.0*Bff*Vmf + Vmt*(-Bft*PetscCosScalar(thetaft) + Gft*PetscSinScalar(thetaft));
<a name="line313">313: </a> values[2] = Vmf*Vmt*(-Bft*PetscSinScalar(thetaft) + Gft*-PetscCosScalar(thetaft));
<a name="line314">314: </a> values[3] = Vmf*(-Bft*PetscCosScalar(thetaft) + Gft*PetscSinScalar(thetaft));
<a name="line315">315: </a>
<a name="line316">316: </a> <a href="../../../../../../docs/manualpages/Mat/MatSetValues.html#MatSetValues">MatSetValues</a>(J,1,row,4,col,values,<a href="../../../../../../docs/manualpages/Sys/ADD_VALUES.html#ADD_VALUES">ADD_VALUES</a>);
<a name="line317">317: </a> }
<a name="line318">318: </a> } <font color="#4169E1">else</font> {
<a name="line319">319: </a> <font color="#4169E1">if</font> (bust->ide != REF_BUS) {
<a name="line320">320: </a> row[0] = goffsetto;
<a name="line321">321: </a> col[0] = goffsetto; col[1] = goffsetto+1; col[2] = goffsetfrom; col[3] = goffsetfrom+1;
<a name="line322">322: </a> <font color="#B22222">/* farr[offsetto] += Gtt*Vmt*Vmt + Vmt*Vmf*(Gtf*PetscCosScalar(thetatf) + Btf*PetscSinScalar(thetatf)); */</font>
<a name="line323">323: </a> values[0] = Vmt*Vmf*(Gtf*-PetscSinScalar(thetatf) + Btf*PetscCosScalar(thetaft)); <font color="#B22222">/* df_dthetat */</font>
<a name="line324">324: </a> values[1] = 2.0*Gtt*Vmt + Vmf*(Gtf*PetscCosScalar(thetatf) + Btf*PetscSinScalar(thetatf)); <font color="#B22222">/* df_dVmt */</font>
<a name="line325">325: </a> values[2] = Vmt*Vmf*(Gtf*PetscSinScalar(thetatf) + Btf*-PetscCosScalar(thetatf)); <font color="#B22222">/* df_dthetaf */</font>
<a name="line326">326: </a> values[3] = Vmt*(Gtf*PetscCosScalar(thetatf) + Btf*PetscSinScalar(thetatf)); <font color="#B22222">/* df_dVmf */</font>
<a name="line327">327: </a>
<a name="line328">328: </a> <a href="../../../../../../docs/manualpages/Mat/MatSetValues.html#MatSetValues">MatSetValues</a>(J,1,row,4,col,values,<a href="../../../../../../docs/manualpages/Sys/ADD_VALUES.html#ADD_VALUES">ADD_VALUES</a>);
<a name="line329">329: </a> }
<a name="line330">330: </a> <font color="#4169E1">if</font> (bust->ide != PV_BUS && bust->ide != REF_BUS) {
<a name="line331">331: </a> row[0] = goffsetto+1;
<a name="line332">332: </a> col[0] = goffsetto; col[1] = goffsetto+1; col[2] = goffsetfrom; col[3] = goffsetfrom+1;
<a name="line333">333: </a> <font color="#B22222">/* farr[offsetto+1] += -Btt*Vmt*Vmt + Vmt*Vmf*(-Btf*PetscCosScalar(thetatf) + Gtf*PetscSinScalar(thetatf)); */</font>
<a name="line334">334: </a> values[0] = Vmt*Vmf*(Btf*PetscSinScalar(thetatf) + Gtf*PetscCosScalar(thetatf));
<a name="line335">335: </a> values[1] = -2.0*Btt*Vmt + Vmf*(-Btf*PetscCosScalar(thetatf) + Gtf*PetscSinScalar(thetatf));
<a name="line336">336: </a> values[2] = Vmt*Vmf*(-Btf*PetscSinScalar(thetatf) + Gtf*-PetscCosScalar(thetatf));
<a name="line337">337: </a> values[3] = Vmt*(-Btf*PetscCosScalar(thetatf) + Gtf*PetscSinScalar(thetatf));
<a name="line338">338: </a>
<a name="line339">339: </a> <a href="../../../../../../docs/manualpages/Mat/MatSetValues.html#MatSetValues">MatSetValues</a>(J,1,row,4,col,values,<a href="../../../../../../docs/manualpages/Sys/ADD_VALUES.html#ADD_VALUES">ADD_VALUES</a>);
<a name="line340">340: </a> }
<a name="line341">341: </a> }
<a name="line342">342: </a> }
<a name="line343">343: </a> <font color="#4169E1">if</font> (!ghostvtex && bus->ide == PV_BUS) {
<a name="line344">344: </a> row[0] = goffset+1; col[0] = goffset+1;
<a name="line345">345: </a> values[0] = 1.0;
<a name="line346">346: </a> <a href="../../../../../../docs/manualpages/Mat/MatSetValues.html#MatSetValues">MatSetValues</a>(J,1,row,1,col,values,<a href="../../../../../../docs/manualpages/Sys/ADD_VALUES.html#ADD_VALUES">ADD_VALUES</a>);
<a name="line347">347: </a> }
<a name="line348">348: </a> }
<a name="line349">349: </a> }
<a name="line350">350: </a> }
<a name="line351">351: </a> <a href="../../../../../../docs/manualpages/Vec/VecRestoreArrayRead.html#VecRestoreArrayRead">VecRestoreArrayRead</a>(localX,&xarr);
<a name="line352">352: </a> <a href="../../../../../../docs/manualpages/DM/DMRestoreLocalVector.html#DMRestoreLocalVector">DMRestoreLocalVector</a>(networkdm,&localX);
<a name="line354">354: </a> <a href="../../../../../../docs/manualpages/Mat/MatAssemblyBegin.html#MatAssemblyBegin">MatAssemblyBegin</a>(J,MAT_FINAL_ASSEMBLY);
<a name="line355">355: </a> <a href="../../../../../../docs/manualpages/Mat/MatAssemblyEnd.html#MatAssemblyEnd">MatAssemblyEnd</a>(J,MAT_FINAL_ASSEMBLY);
<a name="line356">356: </a> <font color="#4169E1">return</font>(0);
<a name="line357">357: </a>}
<a name="line361">361: </a><strong><font color="#4169E1"><a name="SetInitialValues"></a><a href="../../../../../../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</a> SetInitialValues(<a href="../../../../../../docs/manualpages/DM/DM.html#DM">DM</a> networkdm,<a href="../../../../../../docs/manualpages/Vec/Vec.html#Vec">Vec</a> X,void* appctx)</font></strong>
<a name="line362">362: </a>{
<a name="line364">364: </a> VERTEXDATA bus;
<a name="line365">365: </a> GEN gen;
<a name="line366">366: </a> <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> v, vStart, vEnd, offset;
<a name="line367">367: </a> <a href="../../../../../../docs/manualpages/Sys/PetscBool.html#PetscBool">PetscBool</a> ghostvtex;
<a name="line368">368: </a> <a href="../../../../../../docs/manualpages/Vec/Vec.html#Vec">Vec</a> localX;
<a name="line369">369: </a> <a href="../../../../../../docs/manualpages/Sys/PetscScalar.html#PetscScalar">PetscScalar</a> *xarr;
<a name="line370">370: </a> <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> key,numComps,j,offsetd;
<a name="line371">371: </a> DMNetworkComponentGenericDataType *arr;
<a name="line372">372: </a>
<a name="line374">374: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetVertexRange.html#DMNetworkGetVertexRange">DMNetworkGetVertexRange</a>(networkdm,&vStart, &vEnd);
<a name="line376">376: </a> <a href="../../../../../../docs/manualpages/DM/DMGetLocalVector.html#DMGetLocalVector">DMGetLocalVector</a>(networkdm,&localX);
<a name="line378">378: </a> <a href="../../../../../../docs/manualpages/Vec/VecSet.html#VecSet">VecSet</a>(X,0.0);
<a name="line379">379: </a> <a href="../../../../../../docs/manualpages/DM/DMGlobalToLocalBegin.html#DMGlobalToLocalBegin">DMGlobalToLocalBegin</a>(networkdm,X,<a href="../../../../../../docs/manualpages/Sys/INSERT_VALUES.html#INSERT_VALUES">INSERT_VALUES</a>,localX);
<a name="line380">380: </a> <a href="../../../../../../docs/manualpages/DM/DMGlobalToLocalEnd.html#DMGlobalToLocalEnd">DMGlobalToLocalEnd</a>(networkdm,X,<a href="../../../../../../docs/manualpages/Sys/INSERT_VALUES.html#INSERT_VALUES">INSERT_VALUES</a>,localX);
<a name="line382">382: </a> <a href="../../../../../../docs/manualpages/Vec/VecGetArray.html#VecGetArray">VecGetArray</a>(localX,&xarr);
<a name="line383">383: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetComponentDataArray.html#DMNetworkGetComponentDataArray">DMNetworkGetComponentDataArray</a>(networkdm,&arr);
<a name="line384">384: </a> <font color="#4169E1">for</font> (v = vStart; v < vEnd; v++) {
<a name="line385">385: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkIsGhostVertex.html#DMNetworkIsGhostVertex">DMNetworkIsGhostVertex</a>(networkdm,v,&ghostvtex);
<a name="line386">386: </a> <font color="#4169E1">if</font> (ghostvtex) <font color="#4169E1">continue</font>;
<a name="line387">387: </a>
<a name="line388">388: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetVariableOffset.html#DMNetworkGetVariableOffset">DMNetworkGetVariableOffset</a>(networkdm,v,&offset);
<a name="line389">389: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetNumComponents.html#DMNetworkGetNumComponents">DMNetworkGetNumComponents</a>(networkdm,v,&numComps);
<a name="line390">390: </a> <font color="#4169E1">for</font> (j=0; j < numComps; j++) {
<a name="line391">391: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetComponentTypeOffset.html#DMNetworkGetComponentTypeOffset">DMNetworkGetComponentTypeOffset</a>(networkdm,v,j,&key,&offsetd);
<a name="line392">392: </a> <font color="#4169E1">if</font> (key == 1) {
<a name="line393">393: </a> bus = (VERTEXDATA)(arr+offsetd);
<a name="line394">394: </a> xarr[offset] = bus->va*PETSC_PI/180.0;
<a name="line395">395: </a> xarr[offset+1] = bus->vm;
<a name="line396">396: </a> } <font color="#4169E1">else</font> <font color="#4169E1">if</font>(key == 2) {
<a name="line397">397: </a> gen = (GEN)(arr+offsetd);
<a name="line398">398: </a> <font color="#4169E1">if</font> (!gen->status) <font color="#4169E1">continue</font>;
<a name="line399">399: </a> xarr[offset+1] = gen->vs;
<a name="line400">400: </a> <font color="#4169E1">break</font>;
<a name="line401">401: </a> }
<a name="line402">402: </a> }
<a name="line403">403: </a> }
<a name="line404">404: </a> <a href="../../../../../../docs/manualpages/Vec/VecRestoreArray.html#VecRestoreArray">VecRestoreArray</a>(localX,&xarr);
<a name="line405">405: </a> <a href="../../../../../../docs/manualpages/DM/DMLocalToGlobalBegin.html#DMLocalToGlobalBegin">DMLocalToGlobalBegin</a>(networkdm,localX,<a href="../../../../../../docs/manualpages/Sys/ADD_VALUES.html#ADD_VALUES">ADD_VALUES</a>,X);
<a name="line406">406: </a> <a href="../../../../../../docs/manualpages/DM/DMLocalToGlobalEnd.html#DMLocalToGlobalEnd">DMLocalToGlobalEnd</a>(networkdm,localX,<a href="../../../../../../docs/manualpages/Sys/ADD_VALUES.html#ADD_VALUES">ADD_VALUES</a>,X);
<a name="line407">407: </a> <a href="../../../../../../docs/manualpages/DM/DMRestoreLocalVector.html#DMRestoreLocalVector">DMRestoreLocalVector</a>(networkdm,&localX);
<a name="line408">408: </a> <font color="#4169E1">return</font>(0);
<a name="line409">409: </a>}
<a name="line414">414: </a><strong><font color="#4169E1"><a name="main"></a>int main(int argc,char ** argv)</font></strong>
<a name="line415">415: </a>{
<a name="line417">417: </a> char pfdata_file[PETSC_MAX_PATH_LEN]=<font color="#666666">"datafiles/case9.m"</font>;
<a name="line418">418: </a> PFDATA *pfdata;
<a name="line419">419: </a> <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> numEdges=0,numVertices=0;
<a name="line420">420: </a> int *edges = NULL;
<a name="line421">421: </a> <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> i;
<a name="line422">422: </a> <a href="../../../../../../docs/manualpages/DM/DM.html#DM">DM</a> networkdm;
<a name="line423">423: </a> <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> componentkey[4];
<a name="line424">424: </a> UserCtx User;
<a name="line425">425: </a> <a href="../../../../../../docs/manualpages/Profiling/PetscLogStage.html#PetscLogStage">PetscLogStage</a> stage1,stage2;
<a name="line426">426: </a> <a href="../../../../../../docs/manualpages/Sys/PetscMPIInt.html#PetscMPIInt">PetscMPIInt</a> size;
<a name="line427">427: </a> <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> eStart, eEnd, vStart, vEnd,j;
<a name="line428">428: </a> <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> genj,loadj;
<a name="line429">429: </a> <a href="../../../../../../docs/manualpages/Vec/Vec.html#Vec">Vec</a> X,F;
<a name="line430">430: </a> <a href="../../../../../../docs/manualpages/Mat/Mat.html#Mat">Mat</a> J;
<a name="line431">431: </a> <a href="../../../../../../docs/manualpages/SNES/SNES.html#SNES">SNES</a> snes;
<a name="line433">433: </a> <a href="../../../../../../docs/manualpages/Sys/PetscInitialize.html#PetscInitialize">PetscInitialize</a>(&argc,&argv,<font color="#666666">"pfoptions"</font>,help);
<a name="line434">434: </a> <a href="http://www.mpich.org/static/docs/latest/www3/MPI_Comm_rank.html#MPI_Comm_rank">MPI_Comm_rank</a>(<a href="../../../../../../docs/manualpages/Sys/PETSC_COMM_WORLD.html#PETSC_COMM_WORLD">PETSC_COMM_WORLD</a>,&rank);
<a name="line436">436: </a> <font color="#B22222">/* Create an empty network object */</font>
<a name="line437">437: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkCreate.html#DMNetworkCreate">DMNetworkCreate</a>(<a href="../../../../../../docs/manualpages/Sys/PETSC_COMM_WORLD.html#PETSC_COMM_WORLD">PETSC_COMM_WORLD</a>,&networkdm);
<a name="line438">438: </a> <font color="#B22222">/* Register the components in the network */</font>
<a name="line439">439: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkRegisterComponent.html#DMNetworkRegisterComponent">DMNetworkRegisterComponent</a>(networkdm,<font color="#666666">"branchstruct"</font>,<font color="#4169E1">sizeof</font>(<font color="#4169E1">struct _p_EDGEDATA</font>),&componentkey[0]);
<a name="line440">440: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkRegisterComponent.html#DMNetworkRegisterComponent">DMNetworkRegisterComponent</a>(networkdm,<font color="#666666">"busstruct"</font>,<font color="#4169E1">sizeof</font>(<font color="#4169E1">struct _p_VERTEXDATA</font>),&componentkey[1]);
<a name="line441">441: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkRegisterComponent.html#DMNetworkRegisterComponent">DMNetworkRegisterComponent</a>(networkdm,<font color="#666666">"genstruct"</font>,<font color="#4169E1">sizeof</font>(<font color="#4169E1">struct _p_GEN</font>),&componentkey[2]);
<a name="line442">442: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkRegisterComponent.html#DMNetworkRegisterComponent">DMNetworkRegisterComponent</a>(networkdm,<font color="#666666">"loadstruct"</font>,<font color="#4169E1">sizeof</font>(<font color="#4169E1">struct _p_LOAD</font>),&componentkey[3]);
<a name="line444">444: </a> <a href="../../../../../../docs/manualpages/Profiling/PetscLogStageRegister.html#PetscLogStageRegister">PetscLogStageRegister</a>(<font color="#666666">"Read Data"</font>,&stage1);
<a name="line445">445: </a> <a href="../../../../../../docs/manualpages/Profiling/PetscLogStagePush.html#PetscLogStagePush">PetscLogStagePush</a>(stage1);
<a name="line446">446: </a> <font color="#B22222">/* READ THE DATA */</font>
<a name="line447">447: </a> <font color="#4169E1">if</font> (!rank) {
<a name="line448">448: </a> <font color="#B22222">/* READ DATA */</font>
<a name="line449">449: </a> <font color="#B22222">/* Only rank 0 reads the data */</font>
<a name="line450">450: </a> <a href="../../../../../../docs/manualpages/Sys/PetscOptionsGetString.html#PetscOptionsGetString">PetscOptionsGetString</a>(NULL,NULL,<font color="#666666">"-pfdata"</font>,pfdata_file,PETSC_MAX_PATH_LEN-1,NULL);
<a name="line451">451: </a> <a href="../../../../../../docs/manualpages/Sys/PetscNew.html#PetscNew">PetscNew</a>(&pfdata);
<a name="line452">452: </a> PFReadMatPowerData(pfdata,pfdata_file);
<a name="line453">453: </a> User.Sbase = pfdata->sbase;
<a name="line455">455: </a> numEdges = pfdata->nbranch;
<a name="line456">456: </a> numVertices = pfdata->nbus;
<a name="line458">458: </a> <a href="../../../../../../docs/manualpages/Sys/PetscMalloc.html#PetscMalloc">PetscMalloc</a>(2*numEdges*<font color="#4169E1">sizeof</font>(int),&edges);
<a name="line459">459: </a> GetListofEdges(pfdata->nbranch,pfdata->branch,edges);
<a name="line460">460: </a> }
<a name="line461">461: </a> <a href="../../../../../../docs/manualpages/Profiling/PetscLogStagePop.html#PetscLogStagePop">PetscLogStagePop</a>();
<a name="line462">462: </a> <a href="http://www.mpich.org/static/docs/latest/www3/MPI_Barrier.html#MPI_Barrier">MPI_Barrier</a>(<a href="../../../../../../docs/manualpages/Sys/PETSC_COMM_WORLD.html#PETSC_COMM_WORLD">PETSC_COMM_WORLD</a>);
<a name="line463">463: </a> <a href="../../../../../../docs/manualpages/Profiling/PetscLogStageRegister.html#PetscLogStageRegister">PetscLogStageRegister</a>(<font color="#666666">"Create network"</font>,&stage2);
<a name="line464">464: </a> <a href="../../../../../../docs/manualpages/Profiling/PetscLogStagePush.html#PetscLogStagePush">PetscLogStagePush</a>(stage2);
<a name="line465">465: </a> <font color="#B22222">/* Set number of nodes/edges */</font>
<a name="line466">466: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkSetSizes.html#DMNetworkSetSizes">DMNetworkSetSizes</a>(networkdm,numVertices,numEdges,<a href="../../../../../../docs/manualpages/Sys/PETSC_DETERMINE.html#PETSC_DETERMINE">PETSC_DETERMINE</a>,<a href="../../../../../../docs/manualpages/Sys/PETSC_DETERMINE.html#PETSC_DETERMINE">PETSC_DETERMINE</a>);
<a name="line467">467: </a> <font color="#B22222">/* Add edge connectivity */</font>
<a name="line468">468: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkSetEdgeList.html#DMNetworkSetEdgeList">DMNetworkSetEdgeList</a>(networkdm,edges);
<a name="line469">469: </a> <font color="#B22222">/* Set up the network layout */</font>
<a name="line470">470: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkLayoutSetUp.html#DMNetworkLayoutSetUp">DMNetworkLayoutSetUp</a>(networkdm);
<a name="line472">472: </a> <font color="#4169E1">if</font> (!rank) {
<a name="line473">473: </a> <a href="../../../../../../docs/manualpages/Sys/PetscFree.html#PetscFree">PetscFree</a>(edges);
<a name="line474">474: </a> }
<a name="line475">475: </a> <font color="#B22222">/* Add network components */</font>
<a name="line476">476: </a>
<a name="line477">477: </a> genj=0; loadj=0;
<a name="line478">478: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetEdgeRange.html#DMNetworkGetEdgeRange">DMNetworkGetEdgeRange</a>(networkdm,&eStart,&eEnd);
<a name="line479">479: </a> <font color="#4169E1">for</font> (i = eStart; i < eEnd; i++) {
<a name="line480">480: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkAddComponent.html#DMNetworkAddComponent">DMNetworkAddComponent</a>(networkdm,i,componentkey[0],&pfdata->branch[i-eStart]);
<a name="line481">481: </a> }
<a name="line482">482: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetVertexRange.html#DMNetworkGetVertexRange">DMNetworkGetVertexRange</a>(networkdm,&vStart,&vEnd);
<a name="line483">483: </a> <font color="#4169E1">for</font> (i = vStart; i < vEnd; i++) {
<a name="line484">484: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkAddComponent.html#DMNetworkAddComponent">DMNetworkAddComponent</a>(networkdm,i,componentkey[1],&pfdata->bus[i-vStart]);
<a name="line485">485: </a> <font color="#4169E1">if</font> (pfdata->bus[i-vStart].ngen) {
<a name="line486">486: </a> <font color="#4169E1">for</font> (j = 0; j < pfdata->bus[i-vStart].ngen; j++) {
<a name="line487">487: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkAddComponent.html#DMNetworkAddComponent">DMNetworkAddComponent</a>(networkdm,i,componentkey[2],&pfdata->gen[genj++]);
<a name="line488">488: </a> }
<a name="line489">489: </a> }
<a name="line490">490: </a> <font color="#4169E1">if</font> (pfdata->bus[i-vStart].nload) {
<a name="line491">491: </a> <font color="#4169E1">for</font> (j=0; j < pfdata->bus[i-vStart].nload; j++) {
<a name="line492">492: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkAddComponent.html#DMNetworkAddComponent">DMNetworkAddComponent</a>(networkdm,i,componentkey[3],&pfdata->load[loadj++]);
<a name="line493">493: </a> }
<a name="line494">494: </a> }
<a name="line495">495: </a> <font color="#B22222">/* Add number of variables */</font>
<a name="line496">496: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkAddNumVariables.html#DMNetworkAddNumVariables">DMNetworkAddNumVariables</a>(networkdm,i,2);
<a name="line497">497: </a> }
<a name="line498">498: </a> <font color="#B22222">/* Set up <a href="../../../../../../docs/manualpages/DM/DM.html#DM">DM</a> for use */</font>
<a name="line499">499: </a> <a href="../../../../../../docs/manualpages/DM/DMSetUp.html#DMSetUp">DMSetUp</a>(networkdm);
<a name="line501">501: </a> <font color="#4169E1">if</font> (!rank) {
<a name="line502">502: </a> <a href="../../../../../../docs/manualpages/Sys/PetscFree.html#PetscFree">PetscFree</a>(pfdata->bus);
<a name="line503">503: </a> <a href="../../../../../../docs/manualpages/Sys/PetscFree.html#PetscFree">PetscFree</a>(pfdata->gen);
<a name="line504">504: </a> <a href="../../../../../../docs/manualpages/Sys/PetscFree.html#PetscFree">PetscFree</a>(pfdata->branch);
<a name="line505">505: </a> <a href="../../../../../../docs/manualpages/Sys/PetscFree.html#PetscFree">PetscFree</a>(pfdata->load);
<a name="line506">506: </a> <a href="../../../../../../docs/manualpages/Sys/PetscFree.html#PetscFree">PetscFree</a>(pfdata);
<a name="line507">507: </a> }
<a name="line510">510: </a> <a href="http://www.mpich.org/static/docs/latest/www3/MPI_Comm_size.html#MPI_Comm_size">MPI_Comm_size</a>(<a href="../../../../../../docs/manualpages/Sys/PETSC_COMM_WORLD.html#PETSC_COMM_WORLD">PETSC_COMM_WORLD</a>,&size);
<a name="line511">511: </a> <font color="#4169E1">if</font> (size > 1) {
<a name="line512">512: </a> <a href="../../../../../../docs/manualpages/DM/DM.html#DM">DM</a> distnetworkdm;
<a name="line513">513: </a> <font color="#B22222">/* Network partitioning and distribution of data */</font>
<a name="line514">514: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkDistribute.html#DMNetworkDistribute">DMNetworkDistribute</a>(networkdm,0,&distnetworkdm);
<a name="line515">515: </a> <a href="../../../../../../docs/manualpages/DM/DMDestroy.html#DMDestroy">DMDestroy</a>(&networkdm);
<a name="line516">516: </a> networkdm = distnetworkdm;
<a name="line517">517: </a> }
<a name="line519">519: </a> <a href="../../../../../../docs/manualpages/Profiling/PetscLogStagePop.html#PetscLogStagePop">PetscLogStagePop</a>();
<a name="line520">520: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetEdgeRange.html#DMNetworkGetEdgeRange">DMNetworkGetEdgeRange</a>(networkdm,&eStart,&eEnd);
<a name="line521">521: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetVertexRange.html#DMNetworkGetVertexRange">DMNetworkGetVertexRange</a>(networkdm,&vStart,&vEnd);
<a name="line522">522: </a>
<a name="line523">523: </a><font color="#A020F0">#if 0</font>
<a name="line524">524: </a> <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> numComponents;
<a name="line525">525: </a> EDGEDATA edge;
<a name="line526">526: </a> <a href="../../../../../../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> offset,key,kk;
<a name="line527">527: </a> DMNetworkComponentGenericDataType *arr;
<a name="line528">528: </a> VERTEXDATA bus;
<a name="line529">529: </a> GEN gen;
<a name="line530">530: </a> LOAD load;
<a name="line531">531: </a>
<a name="line532">532: </a> <font color="#4169E1">for</font> (i = eStart; i < eEnd; i++) {
<a name="line533">533: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetComponentDataArray.html#DMNetworkGetComponentDataArray">DMNetworkGetComponentDataArray</a>(networkdm,&arr);
<a name="line534">534: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetComponentTypeOffset.html#DMNetworkGetComponentTypeOffset">DMNetworkGetComponentTypeOffset</a>(networkdm,i,0,&key,&offset);
<a name="line535">535: </a> edge = (EDGEDATA)(arr+offset);
<a name="line536">536: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetNumComponents.html#DMNetworkGetNumComponents">DMNetworkGetNumComponents</a>(networkdm,i,&numComponents);
<a name="line537">537: </a> <a href="../../../../../../docs/manualpages/Sys/PetscPrintf.html#PetscPrintf">PetscPrintf</a>(<a href="../../../../../../docs/manualpages/Sys/PETSC_COMM_SELF.html#PETSC_COMM_SELF">PETSC_COMM_SELF</a>,<font color="#666666">"Rank %d ncomps = %d Line %d ---- %d\n"</font>,rank,numComponents,edge->internal_i,edge->internal_j);
<a name="line538">538: </a> }
<a name="line540">540: </a> <font color="#4169E1">for</font> (i = vStart; i < vEnd; i++) {
<a name="line541">541: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetComponentDataArray.html#DMNetworkGetComponentDataArray">DMNetworkGetComponentDataArray</a>(networkdm,&arr);
<a name="line542">542: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetNumComponents.html#DMNetworkGetNumComponents">DMNetworkGetNumComponents</a>(networkdm,i,&numComponents);
<a name="line543">543: </a> <font color="#4169E1">for</font> (kk=0; kk < numComponents; kk++) {
<a name="line544">544: </a> <a href="../../../../../../docs/manualpages/DM/DMNetworkGetComponentTypeOffset.html#DMNetworkGetComponentTypeOffset">DMNetworkGetComponentTypeOffset</a>(networkdm,i,kk,&key,&offset);
<a name="line545">545: </a> <font color="#4169E1">if</font> (key == 1) {
<a name="line546">546: </a> bus = (VERTEXDATA)(arr+offset);
<a name="line547">547: </a> <a href="../../../../../../docs/manualpages/Sys/PetscPrintf.html#PetscPrintf">PetscPrintf</a>(<a href="../../../../../../docs/manualpages/Sys/PETSC_COMM_SELF.html#PETSC_COMM_SELF">PETSC_COMM_SELF</a>,<font color="#666666">"Rank %d ncomps = %d Bus %d\n"</font>,rank,numComponents,bus->internal_i);
<a name="line548">548: </a> } <font color="#4169E1">else</font> <font color="#4169E1">if</font> (key == 2) {
<a name="line549">549: </a> gen = (GEN)(arr+offset);
<a name="line550">550: </a> <a href="../../../../../../docs/manualpages/Sys/PetscPrintf.html#PetscPrintf">PetscPrintf</a>(<a href="../../../../../../docs/manualpages/Sys/PETSC_COMM_SELF.html#PETSC_COMM_SELF">PETSC_COMM_SELF</a>,<font color="#666666">"Rank %d Gen pg = %f qg = %f\n"</font>,rank,gen->pg,gen->qg);
<a name="line551">551: </a> } <font color="#4169E1">else</font> <font color="#4169E1">if</font> (key == 3) {
<a name="line552">552: </a> load = (LOAD)(arr+offset);
<a name="line553">553: </a> <a href="../../../../../../docs/manualpages/Sys/PetscPrintf.html#PetscPrintf">PetscPrintf</a>(<a href="../../../../../../docs/manualpages/Sys/PETSC_COMM_SELF.html#PETSC_COMM_SELF">PETSC_COMM_SELF</a>,<font color="#666666">"Rank %d Load pl = %f ql = %f\n"</font>,rank,load->pl,load->ql);
<a name="line554">554: </a> }
<a name="line555">555: </a> }
<a name="line556">556: </a> }
<a name="line557">557: </a><font color="#A020F0">#endif </font>
<a name="line558">558: </a> <font color="#B22222">/* Broadcast Sbase to all processors */</font>
<a name="line559">559: </a> <a href="http://www.mpich.org/static/docs/latest/www3/MPI_Bcast.html#MPI_Bcast">MPI_Bcast</a>(&User.Sbase,1,<a href="../../../../../../docs/manualpages/Sys/MPIU_SCALAR.html#MPIU_SCALAR">MPIU_SCALAR</a>,0,<a href="../../../../../../docs/manualpages/Sys/PETSC_COMM_WORLD.html#PETSC_COMM_WORLD">PETSC_COMM_WORLD</a>);
<a name="line561">561: </a> <a href="../../../../../../docs/manualpages/DM/DMCreateGlobalVector.html#DMCreateGlobalVector">DMCreateGlobalVector</a>(networkdm,&X);
<a name="line562">562: </a> <a href="../../../../../../docs/manualpages/Vec/VecDuplicate.html#VecDuplicate">VecDuplicate</a>(X,&F);
<a name="line564">564: </a> <a href="../../../../../../docs/manualpages/DM/DMCreateMatrix.html#DMCreateMatrix">DMCreateMatrix</a>(networkdm,&J);
<a name="line565">565: </a> <a href="../../../../../../docs/manualpages/Mat/MatSetOption.html#MatSetOption">MatSetOption</a>(J,MAT_NEW_NONZERO_ALLOCATION_ERR,<a href="../../../../../../docs/manualpages/Sys/PETSC_FALSE.html#PETSC_FALSE">PETSC_FALSE</a>);
<a name="line567">567: </a> SetInitialValues(networkdm,X,&User);
<a name="line569">569: </a> <font color="#B22222">/* HOOK UP SOLVER */</font>
<a name="line570">570: </a> <a href="../../../../../../docs/manualpages/SNES/SNESCreate.html#SNESCreate">SNESCreate</a>(<a href="../../../../../../docs/manualpages/Sys/PETSC_COMM_WORLD.html#PETSC_COMM_WORLD">PETSC_COMM_WORLD</a>,&snes);
<a name="line571">571: </a> <a href="../../../../../../docs/manualpages/SNES/SNESSetDM.html#SNESSetDM">SNESSetDM</a>(snes,networkdm);
<a name="line572">572: </a> <a href="../../../../../../docs/manualpages/SNES/SNESSetFunction.html#SNESSetFunction">SNESSetFunction</a>(snes,F,FormFunction,&User);
<a name="line573">573: </a> <a href="../../../../../../docs/manualpages/SNES/SNESSetJacobian.html#SNESSetJacobian">SNESSetJacobian</a>(snes,J,J,FormJacobian,&User);
<a name="line574">574: </a> <a href="../../../../../../docs/manualpages/SNES/SNESSetFromOptions.html#SNESSetFromOptions">SNESSetFromOptions</a>(snes);
<a name="line576">576: </a> <a href="../../../../../../docs/manualpages/SNES/SNESSolve.html#SNESSolve">SNESSolve</a>(snes,NULL,X);
<a name="line578">578: </a> <a href="../../../../../../docs/manualpages/Vec/VecDestroy.html#VecDestroy">VecDestroy</a>(&X);
<a name="line579">579: </a> <a href="../../../../../../docs/manualpages/Vec/VecDestroy.html#VecDestroy">VecDestroy</a>(&F);
<a name="line580">580: </a> <a href="../../../../../../docs/manualpages/Mat/MatDestroy.html#MatDestroy">MatDestroy</a>(&J);
<a name="line582">582: </a> <a href="../../../../../../docs/manualpages/SNES/SNESDestroy.html#SNESDestroy">SNESDestroy</a>(&snes);
<a name="line583">583: </a> <a href="../../../../../../docs/manualpages/DM/DMDestroy.html#DMDestroy">DMDestroy</a>(&networkdm);
<a name="line585">585: </a> <a href="../../../../../../docs/manualpages/Sys/PetscFinalize.html#PetscFinalize">PetscFinalize</a>();
<a name="line586">586: </a> <font color="#4169E1">return</font> 0;
<a name="line587">587: </a>}
</pre>
</body>
</html>