network.c

来自「circuit calculation program」· C语言 代码 · 共 98 行

C
98
字号
#include "graph.h"


static int network_next0 ( network_ctx *ctx, int i )
{
	for ( ; i < n_nodes; i++ ) {
		if (CHECK_NODEFLAG (i,PROCESSED) ) continue;
		
		/* starts from a node attaching to power source */
		if (!CHECK_NODEFLAG (i,CVS) ) continue;

		ctx->node_id = i;
		ctx->node_id_next = i+1;		
		ctx->pin_next = 0;
		return network_next (ctx);
	}
	return -1;
}

int network_first ( network_ctx *ctx )
{
	return network_next0 ( ctx,0 );
}



int network_next ( network_ctx *ctx )
{
	int i,j;
	
	i = ctx->node_id;
	/* starts with a node with power source */
	for ( j = ctx->pin_next; j < NODE_PINS (i); j++ ) {
			if (CHECK_PINFLAG (nodes[i]->pin_gid[j], PROCESSED) ) continue;
			ctx->pin_next = j+1;
			return NODE_PIN(i)[j];
	}

	i = GET_EQUIV(i); 

	if (i!=-1) {
		ctx->node_id = i;
		ctx->pin_next = 1;
		return NODE_PIN(i)[0];
	} 

	return network_next0( ctx, ctx->node_id_next );
}


void network_closure (int i )
{
	int k;

	
	/* stops in this pin already scanned */
	assert (!CHECK_PINFLAG (i,PROCESSED) );
	SET_PINFLAG (i,PROCESSED);
	
	/* get the first net connecting to another node */
	k = COMPCLASS (i)->sibling_first( COMP (i), i );

	while (k!=i){/* finish if (k == -1)  */
			
			if (!CHECK_PINFLAG (k,PROCESSED) ) {
				
				if (VOLTAGE_OK (COMP (k), i, k ) ) 
					link_add ( i, k );

				/* stops at a power source            */ 
				if (!CHECK_NODEFLAG (NODE (k), SOURCE))
					network_closure (k);
				else					
					SET_PINFLAG (k,PROCESSED);
			}				
			/* get the next net connecting to another node */
			k = COMPCLASS (i)->sibling_next(COMP (i), i,k );
	}
	
	/* if I equation has not yet been established for this node */
	if (!CHECK_NODEFLAG (NODE (i), PROCESSED)
	     && !CHECK_NODEFLAG (NODE (i),SOURCE) ) {

		current_eq (NODE (i));
		SET_NODEFLAG (NODE (i), PROCESSED);
			     	
	     	for (k = 0; k < NODE_PINS (NODE(i)); k ++ ) {
	     		int pin_gid = NODE_PIN(NODE(i))[k];
	     		
	     		printf ("go to node:%d pin:%d of %s\n",NODE(i),pin_gid, COMP(pin_gid)->label);
	     		if (!CHECK_PINFLAG (pin_gid,PROCESSED) )
	     			network_closure (pin_gid);
		}	     			

	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?