code + log clean
This commit is contained in:
parent
8f33a16843
commit
eba8d51e3e
@ -16,6 +16,7 @@ export class Calculation {
|
|||||||
private potentials: number[] = [];
|
private potentials: number[] = [];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
readonly number: number,
|
||||||
readonly pivot: Junction,
|
readonly pivot: Junction,
|
||||||
readonly parts: Part[],
|
readonly parts: Part[],
|
||||||
readonly junctionsWithoutPivot: Junction[],
|
readonly junctionsWithoutPivot: Junction[],
|
||||||
@ -31,10 +32,13 @@ export class Calculation {
|
|||||||
junction.minCircuitVoltage = minCircuitVoltage;
|
junction.minCircuitVoltage = minCircuitVoltage;
|
||||||
junction.maxCircuitVoltage = maxCircuitVoltage;
|
junction.maxCircuitVoltage = maxCircuitVoltage;
|
||||||
junction.voltage = this.getPotential(junctionsWithoutPivot.indexOf(junction));
|
junction.voltage = this.getPotential(junctionsWithoutPivot.indexOf(junction));
|
||||||
|
console.debug(" junction", junction.fullName, junction.voltage, 'V');
|
||||||
});
|
});
|
||||||
pivot.minCircuitVoltage = minCircuitVoltage;
|
pivot.minCircuitVoltage = minCircuitVoltage;
|
||||||
pivot.maxCircuitVoltage = maxCircuitVoltage;
|
pivot.maxCircuitVoltage = maxCircuitVoltage;
|
||||||
pivot.voltage = 0;
|
pivot.voltage = 0;
|
||||||
|
const junctionCountIncludingPivot = junctionsWithoutPivot.length + 1;
|
||||||
|
console.debug(` => Circuit #${number} (${parts.length} parts, ${junctionCountIncludingPivot} junctions, ${wires.length} wires)`);
|
||||||
}
|
}
|
||||||
|
|
||||||
private matrixInit(size: number) {
|
private matrixInit(size: number) {
|
||||||
@ -71,6 +75,7 @@ export class Calculation {
|
|||||||
const potentialEnd = this.getPotential(indexEnd);
|
const potentialEnd = this.getPotential(indexEnd);
|
||||||
const potentialDifference = potentialStart === null || potentialEnd === null ? 0 : potentialEnd - potentialStart;
|
const potentialDifference = potentialStart === null || potentialEnd === null ? 0 : potentialEnd - potentialStart;
|
||||||
wire.current = conductance * potentialDifference;
|
wire.current = conductance * potentialDifference;
|
||||||
|
console.debug(" wire", wire.toString(), wire.current, 'A');
|
||||||
}
|
}
|
||||||
|
|
||||||
private getPotential(index: number): number | null {
|
private getPotential(index: number): number | null {
|
||||||
@ -101,31 +106,32 @@ export class Calculation {
|
|||||||
|
|
||||||
static calculate(circuit: Circuit): Calculation[] {
|
static calculate(circuit: Circuit): Calculation[] {
|
||||||
const restParts = [...circuit.parts];
|
const restParts = [...circuit.parts];
|
||||||
console.debug("Recalculating circuit...")
|
console.debug("Calculating circuit...")
|
||||||
const circuits: Calculation[] = [];
|
const circuits: Calculation[] = [];
|
||||||
let circuitNumber = 0;
|
let circuitCount = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
const battery = restParts.filter(p => p instanceof Battery)[0];
|
const pivot = restParts.filter(p => p instanceof Battery)[0];
|
||||||
if (!battery) {
|
if (!pivot) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
const circuit = this.calculateDisjunct(battery, restParts, circuitNumber++);
|
const circuit = this.calculateDisjunct(pivot.minus, restParts, circuitCount++);
|
||||||
circuits.push(circuit);
|
circuits.push(circuit);
|
||||||
}
|
}
|
||||||
|
console.debug(`Found ${circuitCount} disjunct circuits.`);
|
||||||
if (restParts.length > 0) {
|
if (restParts.length > 0) {
|
||||||
console.debug(`found ${restParts.length} not connected to any battery`);
|
console.debug(`Got ${restParts.length} unconnected parts.`);
|
||||||
}
|
}
|
||||||
return circuits;
|
return circuits;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static calculateDisjunct(battery: Battery, restParts: Part[], circuitNumber: number): Calculation {
|
private static calculateDisjunct(pivot: Junction, restParts: Part[], circuitNumber: number): Calculation {
|
||||||
console.debug(` Circuit #${circuitNumber}:`)
|
console.debug(` Circuit #${circuitNumber}:`)
|
||||||
|
console.debug(" pivot:", pivot.fullName);
|
||||||
|
|
||||||
const foundParts: Part[] = [battery];
|
const foundParts: Part[] = [pivot.part];
|
||||||
restParts.splice(restParts.indexOf(battery), 1);
|
restParts.splice(restParts.indexOf(pivot.part), 1);
|
||||||
|
|
||||||
const pivot = battery.minus;
|
const foundJunctionsWithoutPivot: Junction[] = [];
|
||||||
const foundJunctions: Junction[] = [];
|
|
||||||
const todo: Junction[] = [pivot];
|
const todo: Junction[] = [pivot];
|
||||||
|
|
||||||
const foundWires: Wire[] = [];
|
const foundWires: Wire[] = [];
|
||||||
@ -141,21 +147,20 @@ export class Calculation {
|
|||||||
}
|
}
|
||||||
const destinationJunction = wire.traverse(sourceJunction);
|
const destinationJunction = wire.traverse(sourceJunction);
|
||||||
const destinationPart = destinationJunction.part;
|
const destinationPart = destinationJunction.part;
|
||||||
const newJunction = destinationJunction !== pivot && !foundJunctions.includes(destinationJunction);
|
const newJunctionAndNotPivot = destinationJunction !== pivot && !foundJunctionsWithoutPivot.includes(destinationJunction);
|
||||||
console.debug(` ${newJunction ? "[NEW]" : "[___]"} ${wire}`)
|
console.debug(` ${newJunctionAndNotPivot ? "[NEW]" : "[___]"} Wire ${wire}`)
|
||||||
if (newJunction) {
|
if (newJunctionAndNotPivot) {
|
||||||
const newPart = !foundParts.includes(destinationPart);
|
const newPart = !foundParts.includes(destinationPart);
|
||||||
if (newPart) {
|
if (newPart) {
|
||||||
foundParts.push(destinationPart);
|
foundParts.push(destinationPart);
|
||||||
restParts.splice(restParts.indexOf(destinationPart), 1);
|
restParts.splice(restParts.indexOf(destinationPart), 1);
|
||||||
}
|
}
|
||||||
todo.push(destinationJunction);
|
todo.push(destinationJunction);
|
||||||
foundJunctions.push(destinationJunction);
|
foundJunctionsWithoutPivot.push(destinationJunction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const junctionCountIncludingPivot = foundJunctions.length + 1;
|
return new Calculation(circuitNumber, pivot, foundParts, foundJunctionsWithoutPivot, foundWires);
|
||||||
console.debug(` => Circuit #${circuitNumber} (${foundParts.length} parts, ${junctionCountIncludingPivot} junctions, ${foundWires.length} wires)`);
|
|
||||||
return new Calculation(pivot, foundParts, foundJunctions, foundWires);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,7 +34,7 @@ export class Junction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get fullName(): string {
|
get fullName(): string {
|
||||||
return `'${this.part.name}' '${this.name}'`;
|
return `"${this.part.name} (Pin ${this.name})"`;
|
||||||
}
|
}
|
||||||
|
|
||||||
get pixelX(): number {
|
get pixelX(): number {
|
||||||
|
|||||||
@ -28,9 +28,9 @@ export class Wire {
|
|||||||
|
|
||||||
toString() {
|
toString() {
|
||||||
if (this.start.part === this.end.part && this.name !== null) {
|
if (this.start.part === this.end.part && this.name !== null) {
|
||||||
return `'${this.start.part}' "${this.name}"`;
|
return `"${this.start.part}" "${this.name}"`;
|
||||||
}
|
}
|
||||||
return `${this.name !== null ? this.name + ' ' : ''}${this.start.fullName} ==> ${this.end.fullName}`;
|
return `${this.start.fullName} ==> ${this.end.fullName}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
traverse(junction: Junction) {
|
traverse(junction: Junction) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user