mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-05 07:09:25 -05:00
With short steps only around the torch, the processor is faster than the card at the quarter-inch cells full sheets use, and the card only gained at a cell size they do not use. Drop OpenNest.Gpu, the ILGPU dependency and the accelerator interface; the heat map runs the same on every computer. The measured card timings stay in docs/plate-heat-map.md. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
602 lines
24 KiB
C#
602 lines
24 KiB
C#
using OpenNest.CNC;
|
|
using OpenNest.CNC.Thermal;
|
|
using OpenNest.Geometry;
|
|
using OpenNest.Support;
|
|
|
|
namespace OpenNest.Tests.CNC;
|
|
|
|
public class PlateHeatSimulationTests
|
|
{
|
|
private static readonly CutParameters Cutting = new()
|
|
{
|
|
Feedrate = 100, // in/min
|
|
RapidTravelRate = 600,
|
|
PierceTime = TimeSpan.FromSeconds(1),
|
|
Units = Units.Inches,
|
|
};
|
|
|
|
private static ThermalParameters Thermal(double surfaceCoefficient = 0, SupportBed? bed = null,
|
|
double contactCoefficient = 200) => new()
|
|
{
|
|
Material = ThermalMaterial.MildSteel,
|
|
Thickness = 0.25,
|
|
Units = Units.Inches,
|
|
AbsorbedPower = 1000,
|
|
SurfaceCoefficient = surfaceCoefficient,
|
|
CellSize = 0.5,
|
|
SupportBed = bed,
|
|
ContactCoefficient = contactCoefficient,
|
|
};
|
|
|
|
// Joules per kelvin held by one cell of the grid above.
|
|
private static double CellCapacity(ThermalParameters p)
|
|
{
|
|
var dx = p.CellSize * 0.0254;
|
|
return p.Material.Density * p.Material.SpecificHeat * p.Thickness * 0.0254 * dx * dx;
|
|
}
|
|
|
|
// A part with one contour, its perimeter.
|
|
private static Program Square(double size)
|
|
{
|
|
var program = new Program();
|
|
program.Codes.Add(new RapidMove(0, 0));
|
|
program.Codes.Add(new LinearMove(0, size));
|
|
program.Codes.Add(new LinearMove(size, size));
|
|
program.Codes.Add(new LinearMove(size, 0));
|
|
program.Codes.Add(new LinearMove(0, 0));
|
|
return program;
|
|
}
|
|
|
|
// A square part with a square cutout in its middle: the hole counterclockwise, then the
|
|
// perimeter clockwise. A gap leaves the perimeter that far short of its start, as a tab does.
|
|
private static Program Frame(double size, double hole, double gap = 0)
|
|
{
|
|
var a = (size - hole) / 2;
|
|
var b = a + hole;
|
|
var program = new Program();
|
|
program.Codes.Add(new RapidMove(a, a));
|
|
program.Codes.Add(new LinearMove(b, a));
|
|
program.Codes.Add(new LinearMove(b, b));
|
|
program.Codes.Add(new LinearMove(a, b));
|
|
program.Codes.Add(new LinearMove(a, a));
|
|
program.Codes.Add(new RapidMove(0, 0));
|
|
program.Codes.Add(new LinearMove(0, size));
|
|
program.Codes.Add(new LinearMove(size, size));
|
|
program.Codes.Add(new LinearMove(size, 0));
|
|
program.Codes.Add(new LinearMove(gap, 0));
|
|
return program;
|
|
}
|
|
|
|
private static Program Line(double length)
|
|
{
|
|
var program = new Program();
|
|
program.Codes.Add(new RapidMove(0, 0));
|
|
program.Codes.Add(new LinearMove(length, 0));
|
|
return program;
|
|
}
|
|
|
|
private static (Plate Plate, CutSimulation Simulation) Cut(Program program, Vector location)
|
|
{
|
|
var plate = new Plate(48, 96);
|
|
plate.Parts.Add(new Part(new Drawing("part", program), location));
|
|
return (plate, CutSimulation.Build(plate, Cutting));
|
|
}
|
|
|
|
private static double TorchOnSeconds(CutSimulation simulation) => simulation.Steps
|
|
.Where(s => s.Kind is CutSimulationStepKind.Cut or CutSimulationStepKind.Pierce)
|
|
.Sum(s => s.Duration.TotalSeconds);
|
|
|
|
private static double TotalHeat(PlateHeatSimulation heat, ThermalParameters p)
|
|
{
|
|
var sum = 0.0;
|
|
foreach (var t in heat.Temperatures)
|
|
sum += t;
|
|
return sum * CellCapacity(p);
|
|
}
|
|
|
|
[Fact]
|
|
public void WithoutSurfaceLossAllAbsorbedEnergyStaysInTheSheet()
|
|
{
|
|
var (plate, simulation) = Cut(Line(20), new Vector(10, 10));
|
|
var p = Thermal();
|
|
var heat = new PlateHeatSimulation(plate, simulation, p);
|
|
|
|
heat.RunToEnd(TimeSpan.FromSeconds(30));
|
|
|
|
var expected = p.AbsorbedPower * TorchOnSeconds(simulation);
|
|
Assert.Equal(expected, TotalHeat(heat, p), expected * 1e-4);
|
|
}
|
|
|
|
[Fact]
|
|
public void SurfaceLossDecaysHeatExponentially()
|
|
{
|
|
var (plate, simulation) = Cut(Line(20), new Vector(10, 10));
|
|
var p = Thermal(surfaceCoefficient: 20);
|
|
var heat = new PlateHeatSimulation(plate, simulation, p);
|
|
|
|
heat.RunToEnd();
|
|
var atEnd = TotalHeat(heat, p);
|
|
heat.RunToEnd(TimeSpan.FromSeconds(120));
|
|
|
|
var thickness = p.Thickness * 0.0254;
|
|
var rate = 2 * p.SurfaceCoefficient / (p.Material.Density * p.Material.SpecificHeat * thickness);
|
|
Assert.Equal(System.Math.Exp(-rate * 120), TotalHeat(heat, p) / atEnd, 3);
|
|
}
|
|
|
|
private static PlateHeatSimulation Automatic(Plate plate) =>
|
|
new(plate, CutSimulation.Build(plate, Cutting), new ThermalParameters
|
|
{
|
|
Material = ThermalMaterial.MildSteel,
|
|
Thickness = 0.25,
|
|
Units = Units.Inches,
|
|
});
|
|
|
|
[Fact]
|
|
public void SmallPlateGetsFinerCells()
|
|
{
|
|
var plate = new Plate(6, 16);
|
|
plate.Parts.Add(new Part(new Drawing("part", Frame(4, 2)), new Vector(1, 1)));
|
|
|
|
Assert.Equal(0.5 / 8, Automatic(plate).CellSize);
|
|
}
|
|
|
|
// A 5x10 sheet of eight 25 in squares: about half an hour of cutting.
|
|
private static Plate FullSheet()
|
|
{
|
|
var plate = new Plate(60, 120);
|
|
var drawing = new Drawing("part", Square(25));
|
|
for (var x = 0; x < 2; x++)
|
|
for (var y = 0; y < 4; y++)
|
|
plate.Parts.Add(new Part(drawing, new Vector(2 + x * 28, 2 + y * 28)));
|
|
return plate;
|
|
}
|
|
|
|
[Fact]
|
|
public void FullSheetGetsQuarterInchCells() => Assert.Equal(0.25, Automatic(FullSheet()).CellSize);
|
|
|
|
[Fact]
|
|
public void FullSheetWithAVeryLongCutKeepsHalfInchCells()
|
|
{
|
|
var p = new ThermalParameters { Material = ThermalMaterial.Aluminum, Thickness = 0.25, Units = Units.Inches };
|
|
|
|
Assert.Equal(0.5, PlateHeatSimulation.AutomaticCellSize(new Box(0, 0, 120, 60), 40_000, p));
|
|
}
|
|
|
|
// Quarter-inch cells hold for cuts of hours, so every full sheet compares at one cell size.
|
|
[Theory]
|
|
[InlineData(3600, 0.25)]
|
|
[InlineData(20_000, 0.25)]
|
|
[InlineData(80_000, 0.5)]
|
|
public void FullSheetKeepsQuarterInchCellsForCutsOfHours(double seconds, double expected)
|
|
{
|
|
var p = new ThermalParameters { Material = ThermalMaterial.MildSteel, Thickness = 0.25, Units = Units.Inches };
|
|
|
|
Assert.Equal(expected, PlateHeatSimulation.AutomaticCellSize(new Box(0, 0, 120, 60), seconds, p));
|
|
}
|
|
|
|
[Fact]
|
|
public void ACancelledRunStopsAndFinishesExactlyLater()
|
|
{
|
|
var plate = FullSheet();
|
|
var simulation = CutSimulation.Build(plate, new CutParameters { Feedrate = 100, Units = Units.Inches });
|
|
PlateHeatSimulation Heat() => new(plate, simulation, new ThermalParameters
|
|
{
|
|
Material = ThermalMaterial.MildSteel,
|
|
Thickness = 0.25,
|
|
Units = Units.Inches,
|
|
CellSize = 0.5,
|
|
});
|
|
var heat = Heat();
|
|
using var cancel = new CancellationTokenSource();
|
|
cancel.Cancel();
|
|
|
|
Assert.Throws<OperationCanceledException>(() => heat.RunToEnd(cancellationToken: cancel.Token));
|
|
Assert.True(heat.Time < simulation.TotalTime);
|
|
heat.RunToEnd();
|
|
|
|
var straight = Heat();
|
|
straight.RunToEnd();
|
|
Assert.Equal(straight.Temperatures.ToArray(), heat.Temperatures.ToArray());
|
|
}
|
|
|
|
// Half an inch past the budget, a run is cut into longer steps than the torch needs.
|
|
[Fact]
|
|
public void OnlyCuttingTimeTakesShortSteps()
|
|
{
|
|
var (_, simulation) = Cut(Line(20), new Vector(10, 80));
|
|
var cut = simulation.Steps.Where(s => s.Kind == CutSimulationStepKind.Cut).ToArray();
|
|
var from = cut[0].StartTime.TotalSeconds;
|
|
var to = cut[^1].EndTime.TotalSeconds;
|
|
// 100 in/min crosses 0.25 in cells in 0.15 s.
|
|
var schedule = new HeatStepSchedule(simulation, 0.6, 0.25, 1, 0.005);
|
|
|
|
var time = 0.0;
|
|
while (time < simulation.TotalTime.TotalSeconds)
|
|
{
|
|
var (next, split) = schedule.Next(time);
|
|
Assert.True(next > time);
|
|
if (time >= from && next <= to)
|
|
Assert.True(next - time <= 0.15 + 1e-9, $"{next - time} s step while cutting");
|
|
if (next <= from - 0.6 || time >= to + 0.6)
|
|
Assert.Equal(1, split);
|
|
time = next;
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void HeatSpreadsFromTheCut()
|
|
{
|
|
var (plate, simulation) = Cut(Line(4), new Vector(20, 20));
|
|
var heat = new PlateHeatSimulation(plate, simulation, Thermal());
|
|
|
|
heat.RunToEnd();
|
|
var near = heat.CellAt(new Vector(22, 20.1));
|
|
var away = heat.CellAt(new Vector(22, 23.1));
|
|
Assert.True(heat.Temperatures[near] > 0);
|
|
var awayAtEnd = heat.Temperatures[away];
|
|
|
|
heat.RunToEnd(TimeSpan.FromSeconds(60));
|
|
|
|
Assert.True(heat.Temperatures[away] > awayAtEnd);
|
|
Assert.True(heat.Temperatures[near] < heat.Peaks[near]);
|
|
Assert.True(heat.Peaks[near] > heat.Peaks[away]);
|
|
}
|
|
|
|
// Feeds that cross a whole and a fractional number of cells per diffusion-limited step.
|
|
[Theory]
|
|
[InlineData(47, 0.25)]
|
|
[InlineData(97, 0.25)]
|
|
[InlineData(283, 0.25)]
|
|
[InlineData(47, 0.125)]
|
|
[InlineData(97, 0.125)]
|
|
[InlineData(283, 0.125)]
|
|
public void AStraightCutPeaksEvenlyAlongItsLength(double feedrate, double cell)
|
|
{
|
|
var plate = new Plate(48, 96);
|
|
plate.Parts.Add(new Part(new Drawing("part", Line(23.7)), new Vector(10.03, 10.31)));
|
|
var simulation = CutSimulation.Build(plate, new CutParameters
|
|
{
|
|
Feedrate = feedrate,
|
|
RapidTravelRate = 600,
|
|
Units = Units.Inches,
|
|
});
|
|
var heat = new PlateHeatSimulation(plate, simulation, new ThermalParameters
|
|
{
|
|
Material = ThermalMaterial.MildSteel,
|
|
Thickness = 0.135,
|
|
Units = Units.Inches,
|
|
CellSize = cell,
|
|
});
|
|
|
|
heat.RunToEnd(TimeSpan.FromSeconds(10));
|
|
|
|
// The middle of the cut, clear of the warm-up and the end.
|
|
var peaks = new List<float>();
|
|
for (var x = 18 + cell / 2; x < 28; x += cell)
|
|
peaks.Add(heat.Peaks[heat.CellAt(new Vector(x, 10.31))]);
|
|
var ripple = (peaks.Max() - peaks.Min()) / peaks.Average();
|
|
Assert.True(ripple < 0.1, $"peaks vary {ripple:P0} along the cut");
|
|
}
|
|
|
|
// Only the cells around the torch take the short steps of cutting. The picture has to stay
|
|
// close to the one from every cell taking them, at a slow feed and at one that crosses many
|
|
// cells in a step the rest of the plate takes.
|
|
[Theory]
|
|
[InlineData(100, 600)]
|
|
[InlineData(1600, 2000)]
|
|
public void ShortStepsAroundTheTorchGiveNearlyTheWholePlatesPicture(double feedrate, double rapid)
|
|
{
|
|
var plate = new Plate(48, 96);
|
|
plate.Parts.Add(new Part(new Drawing("frame", Frame(10, 6)), new Vector(4, 4)));
|
|
plate.Parts.Add(new Part(new Drawing("far", Frame(8, 3)), new Vector(60, 30)));
|
|
plate.Parts.Add(new Part(new Drawing("line", Line(20)), new Vector(20, 20.1)));
|
|
var simulation = CutSimulation.Build(plate, new CutParameters
|
|
{
|
|
Feedrate = feedrate,
|
|
RapidTravelRate = rapid,
|
|
PierceTime = TimeSpan.FromSeconds(0.2),
|
|
Units = Units.Inches,
|
|
});
|
|
PlateHeatSimulation Run(bool wholePlateSteps)
|
|
{
|
|
var heat = new PlateHeatSimulation(plate, simulation, new ThermalParameters
|
|
{
|
|
Material = ThermalMaterial.MildSteel,
|
|
Thickness = 0.0598,
|
|
Units = Units.Inches,
|
|
CellSize = 0.25,
|
|
SupportBed = Slats,
|
|
WholePlateSteps = wholePlateSteps,
|
|
});
|
|
heat.RunToEnd(TimeSpan.FromSeconds(5));
|
|
return heat;
|
|
}
|
|
|
|
var whole = Run(wholePlateSteps: true);
|
|
var around = Run(wholePlateSteps: false);
|
|
|
|
// As the simulator colors it: the hottest half percent of peaks is full scale.
|
|
var hot = whole.Peaks.ToArray().Where(v => v > 0).Order().ToArray();
|
|
var scale = hot[(int)(0.995 * (hot.Length - 1))];
|
|
double[] Differences(ReadOnlySpan<float> a, ReadOnlySpan<float> b)
|
|
{
|
|
var differences = new double[a.Length];
|
|
for (var i = 0; i < a.Length; i++)
|
|
differences[i] = System.Math.Abs(System.Math.Min(a[i], scale) - System.Math.Min(b[i], scale)) / scale;
|
|
Array.Sort(differences);
|
|
return differences;
|
|
}
|
|
|
|
var peaks = Differences(whole.Peaks, around.Peaks);
|
|
var now = Differences(whole.Temperatures, around.Temperatures);
|
|
Assert.True(peaks[(int)(0.999 * (peaks.Length - 1))] < 0.03, $"peaks differ {peaks[(int)(0.999 * (peaks.Length - 1))]:P1} at the 99.9th percentile");
|
|
Assert.True(peaks[^1] < 0.15, $"a peak differs {peaks[^1]:P1}");
|
|
Assert.True(now[^1] < 0.03, $"a temperature differs {now[^1]:P1}");
|
|
|
|
double Sum(ReadOnlySpan<float> values)
|
|
{
|
|
var sum = 0.0;
|
|
foreach (var value in values)
|
|
sum += value;
|
|
return sum;
|
|
}
|
|
Assert.Equal(Sum(whole.Temperatures), Sum(around.Temperatures), Sum(whole.Temperatures) * 1e-3);
|
|
}
|
|
|
|
// A run stopped exactly on a step in the middle of a slot and carried on takes that slot's
|
|
// short steps in two lots, so it is no longer a straight run's: it may not leave checkpoints
|
|
// for a later seek to resume from.
|
|
[Fact]
|
|
public void StoppingOnAStepInsideASlotLeavesLaterSeeksExact()
|
|
{
|
|
var (plate, simulation) = Cut(Frame(10, 6), new Vector(8, 8));
|
|
// Half-inch cells have one-second slots, cut into four at 100 in/min, so step ends are
|
|
// times a TimeSpan holds exactly.
|
|
var p = Thermal(20, Slats);
|
|
var schedule = new HeatStepSchedule(simulation, 1, 0.5, 1, 0.005);
|
|
var (slot, _, split) = schedule.StepAfter(simulation.TotalTime.TotalSeconds * 0.35);
|
|
Assert.Equal(4, split);
|
|
var stop = TimeSpan.FromSeconds(schedule.End(slot, 2, split));
|
|
var later = TimeSpan.FromTicks((long)(simulation.TotalTime.Ticks * 0.8));
|
|
|
|
var heat = new PlateHeatSimulation(plate, simulation, p);
|
|
heat.AdvanceTo(stop);
|
|
heat.RunToEnd();
|
|
heat.AdvanceTo(later);
|
|
|
|
var straight = new PlateHeatSimulation(plate, simulation, p);
|
|
straight.AdvanceTo(later);
|
|
Assert.Equal(straight.Temperatures.ToArray(), heat.Temperatures.ToArray());
|
|
Assert.Equal(straight.Peaks.ToArray(), heat.Peaks.ToArray());
|
|
}
|
|
|
|
[Fact]
|
|
public void CutoutSlugFallsAwayWithItsHeat()
|
|
{
|
|
// A 10 in part at (8, 8) with a 6 in hole from 10 to 16.
|
|
var (plate, simulation) = Cut(Frame(10, 6), new Vector(8, 8));
|
|
var heat = new PlateHeatSimulation(plate, simulation, Thermal());
|
|
|
|
heat.RunToEnd();
|
|
|
|
var inside = heat.CellAt(new Vector(13, 13));
|
|
Assert.True(heat.IsRemoved(inside));
|
|
Assert.Equal(0f, heat.Temperatures[inside]);
|
|
Assert.False(heat.IsRemoved(heat.CellAt(new Vector(9.25, 13))));
|
|
Assert.False(heat.IsRemoved(heat.CellAt(new Vector(5, 5))));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(0)]
|
|
[InlineData(0.03)] // a tab leaves the perimeter open
|
|
public void PartAroundACutoutKeepsItsHeat(double gap)
|
|
{
|
|
var (plate, simulation) = Cut(Frame(10, 6, gap), new Vector(8, 8));
|
|
var heat = new PlateHeatSimulation(plate, simulation, Thermal());
|
|
|
|
heat.RunToEnd();
|
|
|
|
// The ring between the hole and the perimeter is the part, not a slug.
|
|
var ring = heat.CellAt(new Vector(9.25, 13.25));
|
|
Assert.False(heat.IsRemoved(ring));
|
|
Assert.True(heat.Temperatures[ring] > 0);
|
|
Assert.True(heat.IsRemoved(heat.CellAt(new Vector(13, 13))));
|
|
}
|
|
|
|
[Fact]
|
|
public void CutFreePartKeepsItsHeatAcrossTheKerf()
|
|
{
|
|
var (plate, simulation) = Cut(Square(6), new Vector(10, 10));
|
|
var heat = new PlateHeatSimulation(plate, simulation, Thermal());
|
|
heat.RunToEnd();
|
|
|
|
double PartHeat()
|
|
{
|
|
var sum = 0.0;
|
|
for (var i = 0; i < heat.Temperatures.Length; i++)
|
|
{
|
|
var c = heat.CellCenter(i);
|
|
if (c.X > 10 && c.X < 16 && c.Y > 10 && c.Y < 16)
|
|
sum += heat.Temperatures[i];
|
|
}
|
|
return sum;
|
|
}
|
|
|
|
var before = PartHeat();
|
|
heat.RunToEnd(TimeSpan.FromSeconds(120));
|
|
|
|
Assert.True(before > 0);
|
|
Assert.False(heat.IsRemoved(heat.CellAt(new Vector(13, 13))));
|
|
Assert.Equal(before, PartHeat(), before * 1e-4);
|
|
}
|
|
|
|
[Fact]
|
|
public void GoingBackInTimeReplaysTheSameState()
|
|
{
|
|
var (plate, simulation) = Cut(Frame(10, 6), new Vector(8, 8));
|
|
var heat = new PlateHeatSimulation(plate, simulation, Thermal(20));
|
|
var middle = TimeSpan.FromTicks(simulation.TotalTime.Ticks / 2);
|
|
|
|
heat.AdvanceTo(middle);
|
|
var first = heat.Temperatures.ToArray();
|
|
heat.RunToEnd();
|
|
heat.AdvanceTo(middle);
|
|
|
|
Assert.Equal(first, heat.Temperatures.ToArray());
|
|
}
|
|
|
|
[Fact]
|
|
public void SeekingAcrossCheckpointsGivesAStraightRunsState()
|
|
{
|
|
// Fine cells make a run long enough to pass several checkpoints.
|
|
var plate = new Plate(12, 12);
|
|
plate.Parts.Add(new Part(new Drawing("part", Frame(10, 6)), new Vector(1, 1)));
|
|
var simulation = CutSimulation.Build(plate, Cutting);
|
|
var p = new ThermalParameters
|
|
{
|
|
Material = ThermalMaterial.MildSteel,
|
|
Thickness = 0.25,
|
|
Units = Units.Inches,
|
|
CellSize = 0.125,
|
|
SupportBed = Slats,
|
|
};
|
|
TimeSpan At(double fraction) => TimeSpan.FromTicks((long)(simulation.TotalTime.Ticks * fraction));
|
|
|
|
(float[] Temperatures, float[] Peaks) Straight(double fraction)
|
|
{
|
|
var fresh = new PlateHeatSimulation(plate, simulation, p);
|
|
fresh.AdvanceTo(At(fraction));
|
|
return (fresh.Temperatures.ToArray(), fresh.Peaks.ToArray());
|
|
}
|
|
|
|
var heat = new PlateHeatSimulation(plate, simulation, p);
|
|
heat.RunToEnd();
|
|
// Playback frames leave the model between full steps before each seek.
|
|
foreach (var fraction in new[] { 0.9, 0.6, 0.35, 0.1, 0.95 })
|
|
{
|
|
for (var frame = 1; frame <= 3; frame++)
|
|
heat.AdvanceTo(heat.Time + TimeSpan.FromSeconds(0.04));
|
|
heat.AdvanceTo(At(fraction));
|
|
|
|
var (temperatures, peaks) = Straight(fraction);
|
|
Assert.Equal(temperatures, heat.Temperatures.ToArray());
|
|
Assert.Equal(peaks, heat.Peaks.ToArray());
|
|
}
|
|
}
|
|
|
|
// Slats along X, one every 4 in, 1 in wide, centered at 2, 6, 10... in from the origin.
|
|
private static readonly SupportSlats Slats = new(SlatAxis.X, pitch: 4, thickness: 1, offset: 2);
|
|
|
|
[Fact]
|
|
public void CellOverASlatCoolsFasterThanOneBetweenSlats()
|
|
{
|
|
// The same cut on a slat's center line and midway between two slats.
|
|
double Retained(double y)
|
|
{
|
|
var (plate, simulation) = Cut(Line(4), new Vector(20, y));
|
|
var bare = new PlateHeatSimulation(plate, simulation, Thermal(20));
|
|
var onSlats = new PlateHeatSimulation(plate, simulation, Thermal(20, Slats));
|
|
bare.RunToEnd(TimeSpan.FromSeconds(60));
|
|
onSlats.RunToEnd(TimeSpan.FromSeconds(60));
|
|
var cell = onSlats.CellAt(new Vector(22, y));
|
|
return onSlats.Temperatures[cell] / bare.Temperatures[cell];
|
|
}
|
|
|
|
var over = Retained(10.25);
|
|
var between = Retained(12.25);
|
|
|
|
Assert.True(over < between, $"over a slat {over}, between slats {between}");
|
|
Assert.True(between < 1);
|
|
}
|
|
|
|
[Fact]
|
|
public void WithoutABedTheModelIsUnchanged()
|
|
{
|
|
var (plate, simulation) = Cut(Square(6), new Vector(10, 10));
|
|
var before = new PlateHeatSimulation(plate, simulation, Thermal(20));
|
|
before.RunToEnd(TimeSpan.FromSeconds(60));
|
|
|
|
// The plate's own bed is used only when passed in.
|
|
plate.SupportBed = Slats;
|
|
var after = new PlateHeatSimulation(plate, simulation, Thermal(20));
|
|
after.RunToEnd(TimeSpan.FromSeconds(60));
|
|
var noContact = new PlateHeatSimulation(plate, simulation, Thermal(20, Slats, contactCoefficient: 0));
|
|
noContact.RunToEnd(TimeSpan.FromSeconds(60));
|
|
|
|
Assert.False(after.UsesSupportBed);
|
|
Assert.True(after.SupportFractions.IsEmpty);
|
|
Assert.Equal(before.Temperatures.ToArray(), after.Temperatures.ToArray());
|
|
Assert.Equal(before.Peaks.ToArray(), after.Peaks.ToArray());
|
|
Assert.Equal(before.Temperatures.ToArray(), noContact.Temperatures.ToArray());
|
|
}
|
|
|
|
[Fact]
|
|
public void FullSlatContactDecaysHeatThroughBothPaths()
|
|
{
|
|
// Slats as wide as their pitch cover the whole sheet.
|
|
var (plate, simulation) = Cut(Line(20), new Vector(10, 10));
|
|
var p = Thermal(20, new SupportSlats(SlatAxis.Y, pitch: 1, thickness: 1, offset: 0.5), contactCoefficient: 300);
|
|
var heat = new PlateHeatSimulation(plate, simulation, p);
|
|
Assert.All(heat.SupportFractions.ToArray(), f => Assert.Equal(1f, f, 5));
|
|
|
|
heat.RunToEnd();
|
|
var atEnd = TotalHeat(heat, p);
|
|
heat.RunToEnd(TimeSpan.FromSeconds(60));
|
|
|
|
var thickness = p.Thickness * 0.0254;
|
|
var capacity = p.Material.Density * p.Material.SpecificHeat * thickness;
|
|
var rate = (2 * p.SurfaceCoefficient + p.ContactCoefficient) / capacity;
|
|
Assert.Equal(System.Math.Exp(-rate * 60), TotalHeat(heat, p) / atEnd, 3);
|
|
}
|
|
|
|
[Fact]
|
|
public void SlatFractionsFollowTheSlatsOverlapNotTheCells()
|
|
{
|
|
// 0.75 in slats centered on 2, 6, 10...: a half-inch cell from 9.5 to 10 is 3/4 on one.
|
|
var (plate, simulation) = Cut(Line(4), new Vector(20, 20));
|
|
var heat = new PlateHeatSimulation(plate, simulation,
|
|
Thermal(bed: new SupportSlats(SlatAxis.X, pitch: 4, thickness: 0.75, offset: 2)));
|
|
|
|
Assert.True(heat.UsesSupportBed);
|
|
Assert.Equal(0.75f, heat.SupportFractions[heat.CellAt(new Vector(30, 9.75))], 5);
|
|
Assert.Equal(0.75f, heat.SupportFractions[heat.CellAt(new Vector(30, 10.25))], 5);
|
|
Assert.Equal(0f, heat.SupportFractions[heat.CellAt(new Vector(30, 12.25))]);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(1, 1, 1)]
|
|
[InlineData(2, -1, 1)]
|
|
[InlineData(3, -1, -1)]
|
|
[InlineData(4, 1, -1)]
|
|
public void SlatsAndGridPointsMirrorWithThePlateQuadrant(int quadrant, int signX, int signY)
|
|
{
|
|
var plate = new Plate(48, 96) { Quadrant = quadrant };
|
|
var simulation = CutSimulation.Build(plate, Cutting);
|
|
|
|
// Slats along X sit at Y = ±2, ±6...; slats along Y at X = ±2, ±6....
|
|
var alongX = new PlateHeatSimulation(plate, simulation, Thermal(bed: Slats));
|
|
Assert.Equal(1f, alongX.SupportFractions[alongX.CellAt(new Vector(signX * 30.25, signY * 2.25))]);
|
|
Assert.Equal(0f, alongX.SupportFractions[alongX.CellAt(new Vector(signX * 30.25, signY * 4.25))]);
|
|
|
|
var alongY = new PlateHeatSimulation(plate, simulation,
|
|
Thermal(bed: new SupportSlats(SlatAxis.Y, pitch: 4, thickness: 1, offset: 2)));
|
|
Assert.Equal(1f, alongY.SupportFractions[alongY.CellAt(new Vector(signX * 6.25, signY * 30.25))]);
|
|
Assert.Equal(0f, alongY.SupportFractions[alongY.CellAt(new Vector(signX * 4.25, signY * 30.25))]);
|
|
|
|
// Grid points at (±1.25, ±1.25) + 3 in steps, each on a 1/8 in pad in the middle of a cell.
|
|
var grid = new PlateHeatSimulation(plate, simulation, Thermal(bed: new SupportGrid(3, 3, 1.25, 1.25)));
|
|
var pad = 0.125 * 0.125 / (0.5 * 0.5);
|
|
Assert.Equal((float)pad, grid.SupportFractions[grid.CellAt(new Vector(signX * 4.25, signY * 7.25))], 5);
|
|
Assert.Equal(0f, grid.SupportFractions[grid.CellAt(new Vector(signX * 4.75, signY * 7.25))]);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("304 Stainless", "Stainless steel")]
|
|
[InlineData("SS", "Stainless steel")]
|
|
[InlineData("Aluminum 5052", "Aluminum")]
|
|
[InlineData("A36", "Mild steel")]
|
|
[InlineData("", "Mild steel")]
|
|
public void MaterialNamesPickAPreset(string name, string expected) =>
|
|
Assert.Equal(expected, ThermalMaterial.ForName(name).Name);
|
|
}
|