@@ -320,6 +320,76 @@ def solve_drain_current(
320
320
return current_array .squeeze ()
321
321
322
322
323
+ def solve_nodal_current (
324
+ NWN : nx .Graph ,
325
+ source_node : Union [Tuple , List [Tuple ]],
326
+ drain_node : Union [Tuple , List [Tuple ]],
327
+ voltage : float ,
328
+ scaled : bool = False ,
329
+ solver : str = "spsolve" ,
330
+ ** kwargs
331
+ ) -> np .ndarray :
332
+ """
333
+ Solve for the current through each node of a NWN. It will appear that
334
+ no current is flowing through source (drain) nodes for positive (negative)
335
+ voltages.
336
+
337
+ Parameters
338
+ ----------
339
+ NWN : Graph
340
+ Nanowire network.
341
+
342
+ source_node : tuple, or list of tuples
343
+ Voltage source nodes.
344
+
345
+ drain_node : tuple, or list of tuples
346
+ Grounded output nodes.
347
+
348
+ voltage : float
349
+ Voltage of the source nodes.
350
+
351
+ scaled : bool, optional
352
+ Whether or not to scaled the output by i0. Default: False.
353
+
354
+ solver: str, optional
355
+ Name of sparse matrix solving algorithm to use. Default: "spsolve".
356
+
357
+ Returns
358
+ -------
359
+ current_array : ndarray
360
+ Array containing the current flow through each drain node in the order
361
+ passed.
362
+
363
+ """
364
+ # Get nodal voltages
365
+ V_out = solve_network (
366
+ NWN , source_node , drain_node , voltage , "voltage" , solver , ** kwargs
367
+ )
368
+
369
+ # Preallocate output
370
+ current_array = np .zeros (len (NWN .nodes ))
371
+
372
+ # Calculate input current for each node
373
+ for node in NWN .nodes :
374
+ node_ind = NWN .graph ["node_indices" ][node ]
375
+ for edge in NWN .edges (node ):
376
+ edge0_ind = NWN .graph ["node_indices" ][edge [0 ]]
377
+ edge1_ind = NWN .graph ["node_indices" ][edge [1 ]]
378
+ V_delta = V_out [edge1_ind ] - V_out [edge0_ind ]
379
+
380
+ # Only add current entering a node so we can see how much
381
+ # current passes through. Else, we just get zero due to KCL.
382
+ if V_delta > 0 :
383
+ current_array [node_ind ] += (V_delta *
384
+ NWN .edges [edge ]["conductance" ] * np .sign (voltage ))
385
+
386
+ # Scale the output if desired
387
+ if scaled :
388
+ current_array *= NWN .graph ["units" ]["i0" ]
389
+
390
+ return current_array
391
+
392
+
323
393
def scale_sol (NWN : nx .Graph , sol : np .ndarray ):
324
394
"""
325
395
Scale the voltage and current solutions by their characteristic values.
0 commit comments