Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 18 additions & 28 deletions SystemHeat/SystemHeat/HeatLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
/// Build a new HeatLoop
/// </summary>
/// <param name="id">The loop ID number</param>
public HeatLoop(SystemHeatSimulator sim, int id)

Check warning on line 76 in SystemHeat/SystemHeat/HeatLoop.cs

View workflow job for this annotation

GitHub Actions / build / build

Parameter 'sim' has no matching param tag in the XML comment for 'HeatLoop.HeatLoop(SystemHeatSimulator, int)' (but other parameters do)
{
ID = id;
modules = new List<ModuleSystemHeat>();
Expand Down Expand Up @@ -219,8 +219,8 @@
/// 2) calculates the temperature change of the loop
/// 3) propagates all new values to the simulation members
/// </summary>
/// <param name="simTimStep">the time step</param>

Check warning on line 222 in SystemHeat/SystemHeat/HeatLoop.cs

View workflow job for this annotation

GitHub Actions / build / build

XML comment has a param tag for 'simTimStep', but there is no parameter by that name
void SimulateIteration(float simTimeStep)

Check warning on line 223 in SystemHeat/SystemHeat/HeatLoop.cs

View workflow job for this annotation

GitHub Actions / build / build

Parameter 'simTimeStep' has no matching param tag in the XML comment for 'HeatLoop.SimulateIteration(float)' (but other parameters do)
{
// Calculate the loop net flux
float currentNetFlux = CalculateNetFlux();
Expand All @@ -228,8 +228,8 @@
NegativeFlux = CalculateNegativeFlux();
float absFlux = Mathf.Abs(currentNetFlux);

AllocateFlux(PositiveFlux);
NetFlux = currentNetFlux;
float oldTemperature = Temperature;

// Determine the ideal change in temperature
float deltaTemperatureIdeal = NetFlux * 1000f / (Volume * CoolantType.Density * CoolantType.HeatCapacity) * simTimeStep;
Expand Down Expand Up @@ -280,6 +280,15 @@
}
}

// How much temperature have we lost in this step?
var tempLoss = Mathf.Max(oldTemperature - Temperature, 0f);
// ... and how much energy did that take?
var energyLoss = tempLoss * 0.001f * Volume * CoolantType.Density * CoolantType.HeatCapacity;
// Now if we spread that out over the time step how how much extra flux do we get?
var lossFlux = energyLoss / simTimeStep;

AllocateFlux(PositiveFlux + lossFlux);

// Ensure temperature doesn't go super high or low when the KSP environment gets weird (scene transitions)
Temperature = Mathf.Clamp(Temperature, GetEnvironmentTemperature(), float.MaxValue);
// Propagate to all modules
Expand All @@ -298,39 +307,20 @@

protected void AllocateFlux(float totalFlux)
{
// Get all consuming systems
for (int i = 0; i < modules.Count; i++)
{
var module = modules[i];
if (module.totalSystemFlux >= 0) continue;
var consumer = modules[i];
if (consumer.totalSystemFlux >= 0f) continue;

if (totalFlux <= 0f)
{
module.consumedSystemFlux = 0f;
}
else
{
if (totalFlux + module.totalSystemFlux > 0f)
{
totalFlux += module.totalSystemFlux;
module.consumedSystemFlux = module.totalSystemFlux;
}
else if (totalFlux + module.totalSystemFlux == 0f)
{
module.consumedSystemFlux = 0f;
totalFlux = 0f;
}
else //(totalFlux + orderedConsumers[i].totalSystemFlux < 0f)
{
module.consumedSystemFlux = -totalFlux;
totalFlux = 0f;
}
}
var systemFlux = -consumer.totalSystemFlux;
if (totalFlux < systemFlux)
systemFlux = totalFlux;

totalFlux -= systemFlux;
consumer.consumedSystemFlux = -systemFlux;
}


}

void SimulateConvection(float simTimeStep)
{

Expand Down
Loading