Skip to content

Commit

Permalink
1.16.16 attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
jrddunbr committed Jan 10, 2021
1 parent 5db4a94 commit 2834df4
Show file tree
Hide file tree
Showing 40 changed files with 1,501 additions and 2,065 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MAJORVERSION = 1
MINORVERSION = 16
REVISION = 15
REVISION = 16

GROUP = 'net.electricalage.eln'
ARCHIVE_NAME = 'ElectricalAge-jrddunbr'
Expand Down
240 changes: 52 additions & 188 deletions src/main/java/mods/eln/Eln.java

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/main/java/mods/eln/fluid/ElementSidedFluidHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,17 @@ open class ElementSidedFluidHandler: IFluidHandler, INBTTReady {
tank.readFromNBT(nbt, "${str}tank$idx")
tankList.add(tank)
}
println("numTanks: $numTanks")
println("tankList $tankList")
//println("numTanks: $numTanks")
//println("tankList $tankList")
tanks.clear()
ForgeDirection.VALID_DIRECTIONS.forEach {
val tankRef = nbt.getInteger("${str}${it.name}tankRef")
if (tankRef != -1 && numTanks != 0) {
println("$it: $tankRef")
//println("$it: $tankRef")
tanks[it] = tankList[tankRef]
}
}
println("tanks: $tanks")
//println("tanks: $tanks")
}

override fun writeToNBT(nbt: NBTTagCompound, str: String) {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/mods/eln/misc/ThermalParameters.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package mods.eln.misc

data class ThermalParameters(var thermalHeatTime: Double, var thermalMaxTemp: Double?, var thermalMinTemp: Double?) {
companion object {
fun battery(): ThermalParameters {
return ThermalParameters(60.0, 100.0, -40.0)
}
}
}
18 changes: 18 additions & 0 deletions src/main/java/mods/eln/node/NodeEntityClientSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,22 @@ public void clientSendInt(Byte id, int str) {
}

}

public void clientSendDouble(Byte id, double num) {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream stream = new DataOutputStream(bos);

preparePacketForServer(stream);

stream.writeByte(id);
stream.writeDouble(num);

sendPacketToServer(bos);
} catch (IOException e) {

e.printStackTrace();
}

}
}
132 changes: 0 additions & 132 deletions src/main/java/mods/eln/sim/BatteryProcess.java

This file was deleted.

89 changes: 89 additions & 0 deletions src/main/java/mods/eln/sim/BatteryProcess.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package mods.eln.sim

import mods.eln.misc.FunctionTable
import mods.eln.sim.mna.component.VoltageSource
import mods.eln.sim.mna.state.VoltageState

open class BatteryProcess(
var positiveLoad: VoltageState?,
var negativeLoad: VoltageState?,
var voltageFunction: FunctionTable,
@JvmField var IMax: Double,
var voltageSource: VoltageSource,
private var thermalLoad: ThermalLoad
) : IProcess {

@JvmField
var Q = 0.0
var QNominal = 0.0
var uNominal = 0.0
@JvmField
var life = 1.0
var isRechargeable = true

override fun process(time: Double) {
val lastQ = Q
var wasteQ = 0.0
Q = Math.max(Q - voltageSource.current * time / QNominal, 0.0)
if (Q > lastQ && !isRechargeable) {
println("Battery is recharging when it shouldn't!")
wasteQ = Q - lastQ
Q = lastQ
}
val voltage = computeVoltage()
voltageSource.u = voltage
if (wasteQ > 0) {
thermalLoad.movePowerTo(Math.abs(voltageSource.current * voltage))
}
}

fun computeVoltage(): Double {
val voltage = voltageFunction.getValue(Q / life)
return Math.max(0.0, voltage * uNominal)
}

fun changeLife(newLife: Double) {
if (newLife < life) {
Q *= newLife / life
}
life = newLife
}

var charge: Double
get() = Q / life
set(charge) {
Q = life * charge
}
val energy: Double
get() {
val stepNbr = 50
val chargeStep = charge / stepNbr
var chargeIntegrator = 0.0
var energy = 0.0
val QperStep = QNominal * life * chargeStep
for (step in 0 until stepNbr) {
val voltage = voltageFunction.getValue(chargeIntegrator) * uNominal
energy += voltage * QperStep
chargeIntegrator += chargeStep
}
return energy
}
val energyMax: Double
get() {
val stepNbr = 50
val chargeStep = 1.0 / stepNbr
var chargeIntegrator = 0.0
var energy = 0.0
val QperStep = QNominal * life * 1.0 / stepNbr
for (step in 0 until stepNbr) {
val voltage = voltageFunction.getValue(chargeIntegrator) * uNominal
energy += voltage * QperStep
chargeIntegrator += chargeStep
}
return energy
}
val u: Double
get() = computeVoltage()
val dischargeCurrent: Double
get() = voltageSource.i
}
44 changes: 0 additions & 44 deletions src/main/java/mods/eln/sim/BatterySlowProcess.java

This file was deleted.

33 changes: 33 additions & 0 deletions src/main/java/mods/eln/sim/BatterySlowProcess.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package mods.eln.sim

import mods.eln.server.SaveConfig

abstract class BatterySlowProcess(var batteryProcess: BatteryProcess, var thermalLoad: ThermalLoad) : IProcess {

var lifeNominalCurrent = 0.0
var lifeNominalLost = 0.0

override fun process(time: Double) {
val U = batteryProcess.u
if (U < -0.1 * batteryProcess.uNominal) {
destroy()
return
}
if (U > uMax) {
destroy()
return
}
if (SaveConfig.instance.batteryAging) {
var newLife = batteryProcess.life
val normalisedCurrent = Math.abs(batteryProcess.dischargeCurrent) / lifeNominalCurrent
newLife -= normalisedCurrent * normalisedCurrent * lifeNominalLost * time
if (newLife < 0.1) newLife = 0.1
batteryProcess.changeLife(newLife)
}
}

val uMax: Double
get() = 1.3 * batteryProcess.uNominal

abstract fun destroy()
}
5 changes: 5 additions & 0 deletions src/main/java/mods/eln/sim/mna/component/Resistor.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mods.eln.sim.mna.component;

import mods.eln.misc.Utils;
import mods.eln.sim.mna.SubSystem;
import mods.eln.sim.mna.misc.MnaConst;
import mods.eln.sim.mna.state.State;
Expand Down Expand Up @@ -47,6 +48,10 @@ public double getU() {
}

public Resistor setR(double r) {
if (Double.isNaN(r) || Double.isInfinite(r)) {
Utils.println("Error! Resistor cannot be set to " + r );
return this;
}
if (this.r != r) {
this.r = r;
this.rInv = 1 / r;
Expand Down
Loading

0 comments on commit 2834df4

Please sign in to comment.