Skip to content

Commit

Permalink
fix: better structural feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
bruberu committed Jun 7, 2024
1 parent b252975 commit 42ffe41
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package gregtech.api.metatileentity.multiblock;

import net.minecraft.util.math.BlockPos;

public interface IFissionReactorHatch {

/**
Expand All @@ -8,4 +10,6 @@ public interface IFissionReactorHatch {
* @return If the channel directly below the hatch is valid or not
*/
boolean checkValidity(int depth);

BlockPos getPos();
}
45 changes: 26 additions & 19 deletions src/main/java/gregtech/api/nuclear/fission/FissionReactor.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public class FissionReactor {
* {@link FissionReactor#prepareInitialConditions()}
*/
public double coolantBaseTemperature;
public double maxFuelDepletion = 1;
public double fuelDepletion = 1;
public double prevFuelDepletion;
public double heatRemoved;
Expand All @@ -112,16 +113,16 @@ public class FissionReactor {
public static double thermalConductivity = 45; // 45 W/(m K), for steel
public static double wallThickness = 0.1;
public static double coolantWallThickness = 0.06; // Ideal for a 1-m diameter steel pipe with the given maximum
// pressure
// pressure
public static double specificHeatCapacity = 420; // 420 J/(kg K), for steel
public static double convectiveHeatTransferCoefficient = 10; // 10 W/(m^2 K), for slow-moving air

public static double powerDefectCoefficient = 0.016; // In units of reactivity
public static double decayProductRate = 0.997; // Based on the half-life of xenon-135, using real-life days as
// Minecraft days, and yes, I am using this for plutonium too
// Minecraft days, and yes, I am using this for plutonium too
public static double poisonFraction = 0.063; // Xenon-135 yield from fission
public static double crossSectionRatio = 4; // The ratio between the cross section for typical fuels and xenon-135;
// very much changed here for balance purposes
// very much changed here for balance purposes

public double coolantMass;
public double fuelMass;
Expand Down Expand Up @@ -185,14 +186,6 @@ public FissionReactor(int size, int depth, double controlRodInsertion) {
300; // Assuming 300 kg/m^3 when it's basically empty, does not have to be precise
}

public boolean canCoolantBoil() {
return false;
}

public boolean explosionPossible() {
return false;
}

public void prepareThermalProperties() {
int idRod = 0, idControl = 0, idChannel = 0;

Expand Down Expand Up @@ -411,11 +404,20 @@ protected void computeCoolantChannelWeights() {
CoolantChannel.normalizeWeights(effectiveCoolantChannels);
}

public boolean isDepleted() {
return maxFuelDepletion <= fuelDepletion;
}

public void prepareInitialConditions() {
coolantBaseTemperature = 0;
coolantBoilingPointStandardPressure = 0;
avgPressure = 0;
coolantHeatOfVaporization = 0;
maxFuelDepletion = 0;
for (FuelRod rod : fuelRods) {
maxFuelDepletion += rod.getFuel().getDuration();
}

for (CoolantChannel channel : effectiveCoolantChannels) {

CoolantProperty prop = channel.getCoolant().getProperty(PropertyKey.COOLANT);
Expand Down Expand Up @@ -482,9 +484,7 @@ public void makeCoolantFlow(int flowRate) {

channel.getInputHandler().getFluidTank().drain(actualFlowRate, true);

if (this.temperature > this.coolantBoilingPoint()) {
channel.getOutputHandler().getFluidTank().fill(HPCoolant, true);
}
channel.getOutputHandler().getFluidTank().fill(HPCoolant, true);

if (prop.accumulatesHydrogen() &&
this.temperature > zircaloyHydrogenReactionTemperature) {
Expand Down Expand Up @@ -539,6 +539,7 @@ public void updatePressure() {
public void updateNeutronPoisoning() {
this.neutronPoisonAmount += this.decayProductsAmount * (1 - decayProductRate) * poisonFraction;
this.neutronPoisonAmount *= decayProductRate;
this.neutronPoisonAmount -= this.neutronPoisonAmount * crossSectionRatio * power / surfaceArea;
}

public double getDecayHeat() {
Expand All @@ -558,7 +559,7 @@ public void updatePower() {
// (1 - 1 / k) = rho(k) => rho^-1(rho) = 1 / (1 - rho)
// rho^-1(rho(k) - defect) is thus 1 / (1 - (1 - 1/k - defect)) = 1 / (1/k + defect)
this.kEff = 1 / ((1 / this.kEff) + powerDefectCoefficient * (this.power / this.maxPower) +
neutronPoisonAmount * crossSectionRatio);
neutronPoisonAmount * crossSectionRatio / surfaceArea);
this.kEff = Math.max(0, this.kEff);
this.prevPower = this.power;
this.prevFuelDepletion = this.fuelDepletion;
Expand All @@ -567,9 +568,9 @@ public void updatePower() {

this.power = responseFunction(Math.min(this.realMaxPower(), this.power * kEff + 0.0001), this.power,
this.criticalRodInsertion, 1);
this.fuelDepletion = Math.min(this.fuelDepletion + 0.001 * this.power / this.maxPower, 1.);
this.fuelDepletion += this.power;

this.decayProductsAmount += Math.max(this.fuelDepletion - this.prevFuelDepletion, 0.);
this.decayProductsAmount += Math.max(this.fuelDepletion - this.prevFuelDepletion, 0.) / 1000;
} else {
this.power = responseFunction(Math.min(this.realMaxPower(), this.power * kEff), this.power,
controlRodInsertion, 1);
Expand All @@ -580,7 +581,7 @@ public void updatePower() {
public double realMaxPower() {
if (this.moderatorTipped && (this.controlRodInsertion <= 9 && this.controlRodInsertion >= 7)) {
return this.maxPower * 1.1;
} else if (this.controlRodInsertion > this.criticalRodInsertion || this.fuelDepletion >= 1. || !this.isOn) {
} else if (this.controlRodInsertion > this.criticalRodInsertion || this.isDepleted() || !this.isOn) {
return this.getDecayHeat();
} else {
return this.maxPower;
Expand Down Expand Up @@ -638,7 +639,13 @@ public void updateControlRodInsertion(double controlRodInsertion) {
public void regulateControlRods() {
if (!this.isOn)
return;
if (temperature < maxTemperature * 3 / 4 && pressure < maxPressure * 3 / 4) {
double load = Math.max(temperature / maxTemperature, pressure / maxPressure);
if (load > 1. / 40 && kEff > 1.02) {
this.controlRodInsertion += 5f / 255;
this.controlRodInsertion = Math.max(0, this.controlRodInsertion);
this.controlRodFactor = ControlRod.controlRodFactor(effectiveControlRods, this.controlRodInsertion);
}
if (load < 3. / 4) {
if (kEff < 1) {
this.controlRodInsertion -= 1f / 255;
this.controlRodInsertion = Math.max(0, this.controlRodInsertion);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gregtech/api/pattern/BlockPattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class BlockPattern {
protected final int fingerLength; // z size
protected final int thumbLength; // y size
protected final int palmLength; // x size
protected final BlockWorldState worldState = new BlockWorldState();
public final BlockWorldState worldState = new BlockWorldState();
protected final PatternMatchContext matchContext = new PatternMatchContext();
protected final Map<TraceabilityPredicate.SimplePredicate, Integer> globalCount;
protected final Map<TraceabilityPredicate.SimplePredicate, Integer> layerCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ public static void register() {
.color(0x232323).iconSet(METALLIC)
.flags(DISABLE_DECOMPOSITION)
.components(HighEnrichedUraniumDioxide, 1, DepletedUraniumDioxide, 20)
.fissionFuelProperties(2000, 1000, 55., 1., 1000., 0.)
.fissionFuelProperties(1000, 750, 55., 1., 1000., 0.)
.build()
.setFormula("UO2", true);

Expand All @@ -518,7 +518,7 @@ public static void register() {
.color(0x242826).iconSet(METALLIC)
.flags(DISABLE_DECOMPOSITION)
.components(HighEnrichedUraniumDioxide, 1, DepletedUraniumDioxide, 5)
.fissionFuelProperties(2000, 1000, 40., 1., 1250., 0.)
.fissionFuelProperties(2000, 600, 40., 1., 1250., 0.)
.build()
.setFormula("UO2", true);

Expand All @@ -527,7 +527,7 @@ public static void register() {
.color(0x62C032).iconSet(METALLIC)
.flags(DISABLE_DECOMPOSITION)
.components(FissilePlutoniumDioxide, 1, Uraninite, 20)
.fissionFuelProperties(2000, 1500, 50., 10., 1500., 10.)
.fissionFuelProperties(2000, 1000, 50., 10., 1500., 10.)
.build()
.setFormula("(U,Pu)O2", true);

Expand All @@ -536,7 +536,7 @@ public static void register() {
.color(0x7EA432).iconSet(METALLIC)
.flags(DISABLE_DECOMPOSITION)
.components(FissilePlutoniumDioxide, 1, Uraninite, 5)
.fissionFuelProperties(2000, 1500, 35., 25., 2000., 25.)
.fissionFuelProperties(2000, 800, 35., 25., 2000., 25.)
.build()
.setFormula("(U,Pu)O2", true);
}
Expand Down
Loading

0 comments on commit 42ffe41

Please sign in to comment.