-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
1,501 additions
and
2,065 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.