Example #1
0
//so far, calc C does max 2 port elements
MatrixXcf Circuit_Handler::calc_C(){
	MatrixXcf C(num_of_nodes,num_of_nodes);
	MatrixXcf tempC(1,1);
	C.setZero(); //will be sparse anyways
	map<int,Impedance *> tempMap;
	Intersection *tempInt;
	Impedance *tempImp;
	gnc = 1;//global node counter, used to assign global numbers to nodes
	int rowstart = 0;//references C Matrix
	int colstart = 0;//references C matrix
	//start by loading intersections in the way we calc'd X[X1,X3,X5]
	for (vector<Intersection *>::iterator it = intersections.begin() ; it != intersections.end(); ++it){
                        tempInt = *it; //get first intersection
			tempMap = tempInt->get_Mapped_Impedances(); //return list of impedances
			for(int i = 1; i< tempInt->get_Conn_Nodes() + 1; ++i){
				vector<int> tempV; //to store previous node info
				vector<int> existing; //to add to node info
				if(tempMap.find(i) != tempMap.end()){ //impedance should exist here
					tempImp = tempMap[i]; //get impedance
					if(tempImp->get_Type() == 0){ //0 for port
						ports.push_back(gnc);	
					}
					int numports = tempImp->get_Num_of_Ports(); //2 or 1 port
					tempC.resize(numports,numports); //get ready to receive C
					tempC = tempImp->get_Cmat(); //get impedance C matrix

					//look to see if we have seen this impedance before
					if(global_tracker.find(tempImp->get_Uid()) != global_tracker.end()){
						//if we have, get its previous node list
						existing = global_tracker[tempImp->get_Uid()];
						
						for(vector<int>::iterator et = existing.begin(); et != existing.end(); ++et){
				//sort through old nodes and insert C matrix accordingly

							int oldport = *et;
							int oldref = oldport -1;
							C(oldref,colstart) = tempC(0,1);
							C(rowstart,oldref) = tempC(1,0);
							C(rowstart,colstart) = tempC(1,1);
							
						}
						existing.push_back(gnc); //lets capture this node
						//add impedance with node list back to tree
						global_tracker[tempImp->get_Uid()] = existing;		
					}else{
						//if we haven't seen before, just get reflection coeff
						C(rowstart,colstart) = tempC(0,0);
						tempV.push_back(gnc);
						global_tracker[tempImp->get_Uid()] = tempV;
					}
						
				}
				++rowstart;
				++colstart;
				++gnc;	
			}
        }
	return C;	
	
}
Example #2
0
void Circuit_Handler::calc_Num_Nodes(){
        num_of_nodes = 0;
        Intersection *tempi;
        for (vector<Intersection *>::iterator it = intersections.begin() ; it != intersections.end(); ++it){
                        tempi = *it;
                        num_of_nodes += tempi->get_Conn_Nodes();
        }
}