use of com.cas.circuit.vo.CR in project TeachingInSimulation by ScOrPiOzzy.
the class R method collectIsopotentialTerminal.
public static void collectIsopotentialTerminal(Terminal ref, IP isopotential, R r) {
// }
if (!isopotential.hasTerminal(ref)) {
isopotential.addTerminal(ref);
}
// 遍历所有和ref关联的导线
List<Terminal> wireAnotherTerms = new ArrayList<Terminal>();
for (Wire wire : ref.getWires()) {
if (!wire.isBothBinded()) {
// toRemove.add(linker);
continue;
}
if (isopotential.getPassedWires().contains(wire) || wire.isBrokenBreak()) {
continue;
}
isopotential.getPassedWires().add(wire);
Terminal anotherTerm = wire.getAnother(ref);
if (anotherTerm != null) {
// System.out.println(str + "R.collectIsopotentialTerminal ()" + wire);
wireAnotherTerms.add(anotherTerm);
collectIsopotentialTerminal(anotherTerm, isopotential, r);
}
}
// FIXME 删除只接了一个连接头的导线????
// wires.removeAll(toRemove);
// 获取线缆中与ref关联的连接头
Terminal contacted = ref.getContacted();
if (contacted != null && !isopotential.getPassedContacted().contains(contacted)) {
isopotential.getPassedContacted().add(contacted);
collectIsopotentialTerminal(contacted, isopotential, r);
}
// 遍历和ref有电阻关系的电阻
Map<Terminal, ResisRelation> resisRelationMap = ref.getResisRelationMap();
Iterator<Entry<Terminal, ResisRelation>> iter = resisRelationMap.entrySet().iterator();
Terminal key_Terminal = null;
ResisRelation resisRelation = null;
while (iter.hasNext()) {
Map.Entry<Terminal, ResisRelation> entry = iter.next();
key_Terminal = entry.getKey();
resisRelation = entry.getValue();
if (!isopotential.getPassedResis().contains(key_Terminal)) {
isopotential.getPassedResis().add(key_Terminal);
if (resisRelation.getValue() == 0 || wireAnotherTerms.contains(key_Terminal)) {
// 阻值为零,则以ref对应的连接头递归处理 或 此电阻被短接了
collectIsopotentialTerminal(key_Terminal, isopotential, r);
} else {
isopotential.getResisRelationList().add(resisRelation);
if (r != null) {
// 遇到连接头是电阻的一端的,先创建出一个复合电阻对象
if (r.resisRelationWithCR.get(resisRelation) != null) {
CR cr = r.resisRelationWithCR.get(resisRelation);
isopotential.getCRList().add(cr);
cr.setIospo2(isopotential);
} else {
CR cr = new CR(r);
// 设置这个复合电阻的所指代的真实电阻
cr.addResisRelation(resisRelation);
isopotential.getCRList().add(cr);
cr.setIospo1(isopotential);
r.resisRelationWithCR.put(resisRelation, cr);
}
}
}
}
}
}
use of com.cas.circuit.vo.CR in project TeachingInSimulation by ScOrPiOzzy.
the class R method mergeParallel.
/**
* @param ip
* @return
*/
@SuppressWarnings("unchecked")
private void mergeParallel(IP ip) {
if (passedIP.contains(ip)) {
return;
}
List<CR> crList = ip.getCRList();
if (crList.size() >= 2) {
IP anotherIsopo = null;
List<CR> runCRList = new ArrayList<CR>();
runCRList.addAll(crList);
for (CR cr : runCRList) {
anotherIsopo = cr.getAnotherIP(ip);
if (passedIP.contains(anotherIsopo)) {
continue;
}
if (anotherIsopo != null) {
List<CR> parallelCR = new ArrayList<CR>();
Util.intersection(parallelCR, ip.getCRList(), anotherIsopo.getCRList());
if (parallelCR.size() > 1) {
CR one = new CR(this);
one.setType(CR.PARALLEL);
for (CR parallel : parallelCR) {
one.attach(parallel);
}
one.merge();
}
}
}
}
}
use of com.cas.circuit.vo.CR 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.CR 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.CR 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();
}
}
}
Aggregations