use of com.cas.circuit.vo.IP in project TeachingInSimulation by ScOrPiOzzy.
the class R method checkRemoveCR.
@SuppressWarnings("unchecked")
private boolean checkRemoveCR() {
// 这里可能需要丢弃n坨
// 用于记录这里的n坨都是可丢弃的
boolean hasFlgTuo = false;
// 检查中心拖出来的电阻
if (readyToCheckIPs.size() > 0) {
for (IP centerIP : readyToCheckIPs) {
if (centerIP.getCRList().size() <= 1 || centerIP == startIP || centerIP == endIP) {
continue;
}
List<CR> tuoCRs = new ArrayList<CR>();
tuoCRs.addAll(centerIP.getCRList());
tuoCRs.removeAll(startIP.getCRList());
tuoCRs.removeAll(endIP.getCRList());
for (CR tuoCR : tuoCRs) {
IP anotherIP = tuoCR.getAnotherIP(centerIP);
tuoCR.removeFromIP(centerIP);
if (anotherIP != null) {
addToRemoveIPList(anotherIP);
}
}
if (!hasFlgTuo) {
hasFlgTuo = true;
}
}
readyToCheckIPs.clear();
}
if (startIP.getCRList().size() > 1 || endIP.getCRList().size() > 1) {
// startip或endIP外侧需要丢弃n坨
List<CR> commonCR = new ArrayList<CR>();
Util.intersection(commonCR, startIP.getCRList(), endIP.getCRList());
List<CR> startTempCRs = new ArrayList<CR>();
startTempCRs.addAll(startIP.getCRList());
startTempCRs.removeAll(commonCR);
for (CR cr : startTempCRs) {
cr.removeFromIP(startIP);
}
List<CR> endTempCRs = new ArrayList<CR>();
endTempCRs.addAll(endIP.getCRList());
endTempCRs.removeAll(commonCR);
for (CR cr : endTempCRs) {
cr.removeFromIP(endIP);
}
hasFlgTuo = true;
} else if (startIP.getCRList().size() == 1 && endIP.getCRList().size() == 1) {
// System.err.println(str + "电路电阻复合完毕");
} else {
System.err.println("不该出现的情况3");
}
return hasFlgTuo;
}
use of com.cas.circuit.vo.IP in project TeachingInSimulation by ScOrPiOzzy.
the class R method shareVoltageLocal.
/**
* 电源调用,
* @return
*/
protected boolean shareVoltageLocal() {
// 找出上一次电路中参与的连接头
List<Terminal> lastCircuitTerminal = new ArrayList<Terminal>();
for (IP ip : allIsopoList) {
addNonRepeatListAll(lastCircuitTerminal, ip.getTerminals());
// lastCircuitTerminal.addAll(ip.getTerminals());
}
// 计算电路电阻
CR cr = mesure();
if (startIP == null || endIP == null) {
Logger.getLogger(this.getClass().getCanonicalName()).warn("startIP == null || endIP == null");
return true;
}
if (cr.getValue() == CR.MIN_RESIS_VALUE) {
startTerminal.getElecComp().powerShorted(startTerminal, endTerminal);
return false;
}
cr.getIsopo2().setVoltageValue(0);
cr.getIsopo1().setVoltageValue(voltage.getValue());
// 根据电阻分压
cr.shareVoltage();
if (startIP == null || endIP == null) {
// System.out.println("电压已经清除了");
return false;
}
// 记录所走到元器件
List<ElecCompDef> elecCompList = new ArrayList<ElecCompDef>();
// 找出本次电路中参与的连接头
List<Terminal> thisCircuitTerminal = new ArrayList<Terminal>();
for (IP ip : allIsopoList) {
// thisCircuitTerminal.addAll(ip.getTerminals());
addNonRepeatListAll(thisCircuitTerminal, ip.getTerminals());
findElecComp(elecCompList, ip.getTerminals(), true);
}
// 剩余的连接头表示是此次电路中没有涉及的,需要清理连接头上的电压
lastCircuitTerminal.removeAll(thisCircuitTerminal);
// elecCompSet.clear();
IP ip = null;
// FIXME false
findElecComp(elecCompList, lastCircuitTerminal, false);
for (Terminal terminal : lastCircuitTerminal) {
if (!startIP.hasTerminal(terminal) && !endIP.hasTerminal(terminal)) {
ip = terminal.getIsopotential(voltage.getEnv());
if (ip != null) {
ip.detory();
}
terminal.removeVolt(voltage.getEnv());
}
}
for (ElecCompDef elecCompDef : elecCompList) {
if (elecCompDef != null) {
elecCompDef.doMagnetism();
}
}
return lastCircuitTerminal.size() != 0;
}
use of com.cas.circuit.vo.IP in project TeachingInSimulation by ScOrPiOzzy.
the class R method mesure.
/**
* 测电阻调用
* @return
*/
public CR mesure(Terminal startTerm, Terminal endTerm) {
synchronized (this) {
// 清理属性值,false表示暂不清理连接头上的电压
cleanProperty();
// 传入的参数为null值,
if (startTerm == null || endTerm == null) {
return new CR(this, CR.MAX_RESIS_VALUE);
}
// 找到指定电压环境下每一个电阻两端的电势
R.findAllIsopotential(startTerm, this, false);
// 合并电阻
mergeCircuit();
for (IP ip : isopoList) {
if (startIP == null && ip.hasTerminal(startTerm)) {
startIP = ip;
}
if (endIP == null && ip.hasTerminal(endTerm)) {
endIP = ip;
}
// 优化遍历
if (startIP != null && endIP != null) {
break;
}
}
if (endIP == null) {
cleanProperty();
findAllResisIsopotential(startTerm, false);
findAllResisIsopotential(endTerm, false);
// 再找一下保证startIP和endIP不null
for (IP ip : isopoList) {
if (startIP == null && ip.hasTerminal(startTerm)) {
startIP = ip;
}
if (endIP == null && ip.hasTerminal(endTerm)) {
endIP = ip;
}
// 优化遍历
if (startIP != null && endIP != null) {
break;
}
}
CR maxCR = new CR(this, CR.MAX_RESIS_VALUE);
maxCR.setIospo1(startIP);
maxCR.setIospo2(endIP);
startIP.getCRList().add(maxCR);
endIP.getCRList().add(maxCR);
}
if (startIP == endIP) {
CR minCR = new CR(this, CR.MIN_RESIS_VALUE);
minCR.setIospo1(startIP);
minCR.setIospo2(endIP);
startIP.getCRList().add(minCR);
endIP.getCRList().add(minCR);
return minCR;
} else {
boolean needRemive = false;
do {
mergeCircuit();
needRemive = checkRemoveCR();
} while (needRemive);
return getCompositeResistance();
}
}
}
use of com.cas.circuit.vo.IP in project TeachingInSimulation by ScOrPiOzzy.
the class R method mergeCircuit.
/**
* @param startIsopo
* @return
*/
private void mergeCircuit() {
int count = 0;
int lastIPNum = isopoList.size();
while (isopoList.size() > 2 && count < 10) {
mergeSeries();
mergeParallel();
for (IP ip : toRemoveIsopoList) {
isopoList.remove(ip);
}
toRemoveIsopoList.clear();
// 如果有衰减
if (lastIPNum > isopoList.size()) {
lastIPNum = isopoList.size();
} else {
count++;
}
}
if (isopoList.size() == 2) {
IP ip1 = isopoList.get(0);
IP ip2 = isopoList.get(1);
if (ip1.getCRList().size() == 1 && ip2.getCRList().size() == 1 && ip1.getCRList().get(0) == ip2.getCRList().get(0)) {
// break;
} else {
mergeParallel2();
}
}
}
use of com.cas.circuit.vo.IP in project TeachingInSimulation by ScOrPiOzzy.
the class R method cleanProperty.
public void cleanProperty() {
for (IP ip : allIsopoList) {
ip.detory();
}
allIsopoList.clear();
isopoList.clear();
resisRelationWithCR.clear();
toRemoveIsopoList.clear();
passedIP.clear();
startIP = null;
endIP = null;
}
Aggregations