package classes; import com.google.gson.annotations.Expose; public class ResistanceCalculator { @Expose private int lowVoltage; @Expose private int highVoltage; @Expose private int lowDiameter; @Expose private int highDiameter; @Expose private double lowSpecificMaterialResistance; @Expose private double highSpecificMaterialResistance; public ResistanceCalculator(int lowVoltage, int highVoltage, int lowDiameter, int highDiameter, double lowSpecificMaterialResistance, double highSpecificMaterialResistance){ this.lowVoltage = lowVoltage; this.highVoltage = highVoltage; this.lowDiameter = lowDiameter; this.highDiameter = highDiameter; this.lowSpecificMaterialResistance = lowSpecificMaterialResistance; this.highSpecificMaterialResistance = highSpecificMaterialResistance; } public void setDistancesToCalcResistance(HolonObject powerPlant) { if (powerPlant != null) { // travers if (powerPlant.getConnectedTo().size() > 0) { for (CpsEdge edge : powerPlant.getConnectedTo()) { if (powerPlant.getId() == edge.getA().getId()) { traversEdges(edge.getB(), powerPlant, calcEdgeLength(edge), 0); } else { traversEdges(edge.getA(), powerPlant, calcEdgeLength(edge), 0); } } } else { System.out.println("Nothing connected to powerplant"); } } else { System.out.println("No powerplant connected"); } } private void traversEdges(AbstractCpsObject currentObject, AbstractCpsObject last, double distance, double lastDistance) { if (currentObject.getConnectedTo().size() > 1) { // recursive call for all edges for (CpsEdge edge : currentObject.getConnectedTo()) { double newDistance = calcEdgeLength(edge); if (currentObject.getId() == edge.getA().getId()) { // look at which way the edge points if (last.getId() != edge.getB().getId()) { traversEdges(edge.getB(), currentObject, distance + newDistance, newDistance); } } else { if (last.getId() != edge.getA().getId()) { traversEdges(edge.getA(), currentObject, distance + newDistance, newDistance); } } } } else { // at leaf for (HolonElement ele : ((HolonObject) currentObject).getElements()) { ele.setHighDistance(distance - lastDistance); ele.setLowDistance(lastDistance); } } } private double calcEdgeLength(CpsEdge edge) { Position aPos = edge.getA().getPosition(); Position bPos = edge.getB().getPosition(); double xDiff = Math.abs(aPos.x - bPos.x); double yDiff = Math.abs(aPos.y - bPos.y); return Math.sqrt(Math.pow(xDiff, 2) + Math.pow(yDiff, 2)); } public float calcEnergyAfterResistance(float currentEnergy, double lowDistance, double highDistance, float energyRequiredForPowerplantBlackstart){ double energyAfterLowVoltage = calcEnergyAfterPartOfGrid(currentEnergy, lowVoltage, lowDistance, lowSpecificMaterialResistance, lowDiameter, energyRequiredForPowerplantBlackstart); energyAfterLowVoltage = (0.98 * energyAfterLowVoltage); //transfomer loses return (float) calcEnergyAfterPartOfGrid(energyAfterLowVoltage, highVoltage, highDistance, highSpecificMaterialResistance, highDiameter, energyRequiredForPowerplantBlackstart); } private double calcEnergyAfterPartOfGrid(double currentEnergy, int voltage, double distance, double specificMaterialResistance, int diameter, float energyRequiredForPowerplantBlackstart){ double blackstartResistance = blackstartResistance(voltage, energyRequiredForPowerplantBlackstart); double cableResistance = cableResistance(specificMaterialResistance, distance, diameter); return (1 - (cableResistance / (cableResistance + blackstartResistance))) * currentEnergy; } private double blackstartResistance(int voltage, float energyRequiredForPowerplantBlackstart){ return Math.pow(voltage, 2) / energyRequiredForPowerplantBlackstart; } private double cableResistance(double specificMaterialResistance, double distance, int diameter){ return specificMaterialResistance * (distance / (0.25 * Math.PI * Math.pow(diameter, 2))); } double calcEnergyNeededForCertainEnergyAfterResistance(double energyWanted, double lowDistance, double highDistance, float energyRequiredForPowerplantBlackstart){ double energyBeforeHighVoltage = calcEnergyNeededBeforePartOfGrid(energyWanted, highVoltage, highDistance, highSpecificMaterialResistance, highDiameter, energyRequiredForPowerplantBlackstart); energyBeforeHighVoltage = 1.02 * energyBeforeHighVoltage; return calcEnergyNeededBeforePartOfGrid(energyBeforeHighVoltage, lowVoltage, lowDistance, lowSpecificMaterialResistance, lowDiameter, energyRequiredForPowerplantBlackstart); } private double calcEnergyNeededBeforePartOfGrid(double energyWanted, int voltage, double distance, double specificMaterialResistance, int diameter, float energyRequiredForPowerplantBlackstart){ double blackstartResistance = blackstartResistance(voltage, energyRequiredForPowerplantBlackstart); double cableResistance = cableResistance(specificMaterialResistance, distance, diameter); return (energyWanted / (1 - (cableResistance / (cableResistance + blackstartResistance)))); } }