/
GeekNerd
/
ServerModelingProject
Обзор
Документация
Войти
/
GeekNerd
/
ServerModelingProject
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Assets/Scripts/OptimizationLogic/Core/ZonalThermalModel.cs
124 строки
4 KB
Gorney-Alex
Init
30 май 2026, 19:05
30 май 2026, 19:05
3cdcc49
Код
Авторство
О чём код?
using System.Collections.Generic; using DataClasses; using DataClasses.Algorithm; using UnityEngine; namespace OptimizationLogic.Core { public sealed class ZonalThermalModel { private const float AirDensity = 1.2f; // kg/m^3 private const float Cp = 1.006f; // kJ/(kg*C) public float MaxTemperature { get; private set; } public Dictionary<int, float> ComputeZoneTemperatures( RoomConfig room, IReadOnlyList<PlacementZone> zones, IReadOnlyList<RackGene> placed, IReadOnlyList<RackData> models) { Dictionary<int, float> temps = new(); MaxTemperature = float.NegativeInfinity; if (room == null || zones == null) return temps; for (int k = 0; k < zones.Count; k++) { PlacementZone zone = zones[k]; float tsupply = GetSupplyTemperature(room, zone.Bounds.center); float mdot = GetMassFlow(room, zone.Bounds.center); float qSum = 0f; // kW if (placed != null && models != null) { for (int i = 0; i < placed.Count; i++) { RackGene g = placed[i]; if (!g.IsPlaced) continue; if (g.ZoneId != zone.ZoneId) continue; if (g.ModelIndex < 0 || g.ModelIndex >= models.Count) continue; RackData m = models[g.ModelIndex]; if (m == null) continue; qSum += Mathf.Max(0f, m.HeatOutput); } } float t; if (qSum <= 1e-6f || mdot <= 1e-6f) { t = tsupply; } else { t = tsupply + qSum / (mdot * Cp); } temps[zone.ZoneId] = t; if (t > MaxTemperature) MaxTemperature = t; } if (zones.Count == 0) MaxTemperature = GetSupplyTemperature(room, Vector2.zero); return temps; } public float ComputeThermalPenalty(RoomConfig room, Dictionary<int, float> temps) { if (room == null || temps == null) return 0f; float limit = room.TempLimit > 0f ? room.TempLimit : 27f; float penalty = 0f; foreach (var kvp in temps) { float over = kvp.Value - limit; if (over > 0f) penalty += over; } return penalty; } private static float GetSupplyTemperature(RoomConfig room, Vector2 zoneCenter) { // Prefer nearest CRAC supply temperature; fallback to RoomConfig.SupplyTemp. if (room.Cracs != null && room.Cracs.Count > 0) { CracData c = FindNearestCrac(room.Cracs, zoneCenter); if (c != null) return c.SupplyTemperature; } return room.SupplyTemp; } private static float GetMassFlow(RoomConfig room, Vector2 zoneCenter) { // Mass flow: mdot = rho * Ldot float volFlow = 1f; if (room.Cracs != null && room.Cracs.Count > 0) { CracData c = FindNearestCrac(room.Cracs, zoneCenter); if (c != null) volFlow = Mathf.Max(0f, c.VolumetricFlow); } return AirDensity * volFlow; } private static CracData FindNearestCrac(IReadOnlyList<CracData> cracs, Vector2 point) { CracData best = null; float bestD = float.PositiveInfinity; for (int i = 0; i < cracs.Count; i++) { CracData c = cracs[i]; if (c == null) continue; float d = Vector2.SqrMagnitude(point - c.Center); if (d < bestD) { bestD = d; best = c; } } return best; } } }