Skip to content

Commit

Permalink
feat: delta temperature (lobotomy #2)
Browse files Browse the repository at this point in the history
  • Loading branch information
bruberu committed Jul 10, 2024
1 parent 56c90c4 commit a4b0b20
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/main/java/gregtech/api/nuclear/fission/FissionReactor.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,14 @@ public class FissionReactor {
* coolant boiling points in {@link FissionReactor#prepareInitialConditions()}
*/
public double coolantBoilingPointStandardPressure;

/**
* Average temperature of the coolant in kelvin as coolant exits the reactor.
*/
public double coolantExitTemperature;

public double prevTemperature;

/**
* Latent heat of vaporization in J/mol Determined by a weighted sum of the individual heats of vaporization in
* {@link FissionReactor#prepareInitialConditions()}
Expand Down Expand Up @@ -532,14 +538,14 @@ protected double coolantBoilingPoint(Material coolant) {
}

public void updateTemperature(int flowRate) {
double oldTemp = this.temperature;
this.prevTemperature = this.temperature;
// simulate heat based only on the reactor power
this.temperature = responseFunctionTemperature(envTemperature, this.temperature, this.power * 1e6, 0);
// prevent temperature from going above meltdown temp, to stop coolant from absorbing more heat than it should
this.temperature = Math.min(maxTemperature, temperature);
double heatRemoved = this.makeCoolantFlow(flowRate);
// calculate the actual temperature based on the reactor power and the heat removed
this.temperature = responseFunctionTemperature(envTemperature, oldTemp, this.power * 1e6, heatRemoved);
this.temperature = responseFunctionTemperature(envTemperature, prevTemperature, this.power * 1e6, heatRemoved);

this.temperature = Math.max(this.temperature, this.coolantBaseTemperature);
}
Expand Down Expand Up @@ -610,6 +616,7 @@ public void addComponent(ReactorComponent component, int x, int y) {
public NBTTagCompound serializeNBT() {
NBTTagCompound tagCompound = new NBTTagCompound();
tagCompound.setDouble("Temperature", this.temperature);
tagCompound.setDouble("PrevTemperature", this.prevTemperature);
tagCompound.setDouble("Pressure", this.pressure);
tagCompound.setDouble("Power", this.power);
tagCompound.setDouble("FuelDepletion", this.fuelDepletion);
Expand All @@ -626,6 +633,7 @@ public NBTTagCompound serializeNBT() {

public void deserializeNBT(NBTTagCompound tagCompound) {
this.temperature = tagCompound.getDouble("Temperature");
this.prevTemperature = tagCompound.getDouble("PrevTemperature");
this.pressure = tagCompound.getDouble("Pressure");
this.power = tagCompound.getDouble("Power");
this.fuelDepletion = tagCompound.getDouble("FuelDepletion");
Expand All @@ -648,7 +656,7 @@ public void regulateControlRods() {
return;

if (pressure > maxPressure * 0.8 || temperature > (coolantExitTemperature + maxTemperature) / 2 ||
temperature > maxTemperature - 150) {
temperature > maxTemperature - 150 || temperature - prevTemperature > 30) {
if (kEff > 1) {
this.controlRodInsertion += 0.004;
this.controlRodInsertion = Math.min(1, this.controlRodInsertion);
Expand Down

0 comments on commit a4b0b20

Please sign in to comment.