Ejemplo n.º 1
0
void setV(stringstream& lineStream, NodeList& NList) {

	int nodeID;
	double voltage;
	
	if(!anyArgs(lineStream)) return;
	
	lineStream >> nodeID;

		if(!validNode(nodeID, lineStream)) return;
		
	lineStream >> voltage;
	
		if(lineStream.fail()) {
			cout << "Error: " << endl;
			return;
		}
	
	if(!endOfArgs(lineStream)) return;
	
	if(NList.findNode(nodeID) == NULL) NList.insertNode(nodeID);
		
	NList.findNode(nodeID) -> setVoltage(voltage);
		
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout << "Set: node " << nodeID << " to " << setprecision(2) << voltage << setprecision(6) << " Volts" << endl;
	cout.unsetf(ios::fixed);
	cout.unsetf(ios::showpoint);
	
}
Ejemplo n.º 2
0
void unsetV(stringstream& lineStream, NodeList& NList) {

	int nodeID;
	
	if(!anyArgs(lineStream)) return;
	
	lineStream >> nodeID;

		if(!validNode(nodeID, lineStream)) return;
	
	if(!endOfArgs(lineStream)) return;
	
	if(NList.findNode(nodeID) == NULL) cout << "Error: node " << nodeID << " doesn't exist" << endl;
	else {
	
		NList.findNode(nodeID) -> unsetVoltage();
		
		cout << "Unset: the solver will determine the voltage of node " << nodeID << endl;
	} 
	
}
Ejemplo n.º 3
0
void insertR(stringstream& lineStream, NodeList& NList) {

	string name;
	double resistance;
	int nodeID1, nodeID2;

	//Read in each argument one at a time and check for errors
	lineStream >> name;

		if(!anyArgs(lineStream)) return;

		if(name == "all") {
			cout << "Error: resistor name cannot be the keyword \"all\"" << endl;
			return;
		}

	lineStream >> resistance;

		if(!validResistance(resistance, lineStream)) return;

	lineStream >> nodeID1;

		if(!validNode(nodeID1, lineStream)) return;

	lineStream >> nodeID2;

		if(!validNode(nodeID2, lineStream)) return;


	if(nodeID1 == nodeID2) {
		cout << "Error: both terminals of resistor connect to node " << nodeID1 << endl;
		return;
	}

	//check if there are more arguments
	if(!endOfArgs(lineStream)) return;
	
	//VALID ARGUMENTS
	
	//check if nodes exist, if not create
	if(NList.findNode(nodeID1) == NULL) NList.insertNode(nodeID1);
	if(NList.findNode(nodeID2) == NULL) NList.insertNode(nodeID2);
	
	//check if resistor name already exists
	if(NList.findResistor(name) != NULL) {
	
		cout << "Error: resistor " << name << " already exists" << endl;
		return;
	}
        
	//if resistor doesnt exist
	int nodes[2] = {nodeID1, nodeID2};
	NList.addResistor(name, resistance, nodes);
        
    	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout << "Inserted: resistor " << name << " " << setprecision(2) << resistance << " Ohms " << setprecision(6);
	cout.unsetf(ios::fixed);
	cout.unsetf(ios::showpoint);
	cout << nodeID1 << " -> " << nodeID2 << endl;

	return;
}