125 lines
4.3 KiB
Java
125 lines
4.3 KiB
Java
/*
|
|
* %W% %E% Dymik739
|
|
* Email: dymik739@109.86.70.81
|
|
*
|
|
* Copyright (C) 2023 FIOT Dev Team
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
/**
|
|
* Class which represents a server rack.
|
|
*
|
|
* @author Dymik739
|
|
* @since 0.3
|
|
*/
|
|
public class ServerRack extends Appliance {
|
|
/** Defines power used by the rack at lowest temperature. */
|
|
private float basePower = 160.0f;
|
|
|
|
/** Defines power limit for this rack */
|
|
private float maxPower = 350.0f;
|
|
|
|
/** Contains the inner temperature of this rack */
|
|
private float temperature = 20f;
|
|
|
|
/** Defines current usage of this device */
|
|
private float currentLoad = 0.2f;
|
|
|
|
/** Predicts the future change of the load */
|
|
private float loadVector = +1f;
|
|
|
|
/**
|
|
* Constructor for this class.
|
|
*
|
|
* @param plugged defines if the device is plugged in at the start
|
|
*/
|
|
public ServerRack(boolean plugged) {
|
|
super(plugged);
|
|
super.setType("ServerRack");
|
|
}
|
|
|
|
/**
|
|
* Method for simulating this device behaviour.
|
|
* This rack processes video segments for the streaming platform and
|
|
* serves them to the public in different qualities. Every device requires
|
|
* the fragments to be encoded in it's respective format in order to play
|
|
* the stream. As such, the load rises when new fragment arrives and falls
|
|
* as it converts it into all the formats required.
|
|
*
|
|
* Temperature depends on many factors. Firstly, the device heats up while
|
|
* performing tasks and the rate is affected by:
|
|
* - current temperature (hotter = more power drawn);
|
|
* - load on the CPU (more load = more heat);
|
|
*
|
|
* Of course, the temperature can be reduced using the vent installed in
|
|
* the house. The rate of reduction is calculated using:
|
|
* - current temperature (the bigger the difference compared to the outside
|
|
* temperature, the larger impact the vent has on it);
|
|
* - air flow, created by the vent (the faster the air moves, the more
|
|
* heat it takes away from the system);
|
|
*
|
|
* This device can also cool itself down while standing still as the heat
|
|
* slowly transfers to the air even when the vent doesn't force it.
|
|
* The rate is calculated by only the temperature difference between inner
|
|
* and outer temperatures.
|
|
*
|
|
* @param seconds delta time to simulate for
|
|
* @param ventRPM air flow created by the vent
|
|
*/
|
|
public void step(float seconds, float ventRPM) {
|
|
currentLoad += loadVector/10 * seconds;
|
|
|
|
if (currentLoad >= 1) {
|
|
loadVector = -1f;
|
|
} else if (currentLoad <= 0.2) {
|
|
loadVector = +1f;
|
|
}
|
|
|
|
if (super.getPowerState()) {
|
|
temperature += min(basePower + (temperature - 20f) * 1.8f
|
|
* max(min(currentLoad, 1), 0), maxPower) * seconds
|
|
* 0.024f;
|
|
}
|
|
|
|
temperature -= (temperature - 20f) * ventRPM * 0.00013f * seconds;
|
|
temperature -= 0.002f * (temperature - 20f) * seconds;
|
|
}
|
|
|
|
/**
|
|
* Method which calculates power consumption if this device.
|
|
*
|
|
* @return power consumption of this device
|
|
*/
|
|
public float getPowerConsumption() {
|
|
if (super.getPowerState()) {
|
|
return min(basePower + (temperature - 20f) * 1.8f * max(min(currentLoad, 1), 0), maxPower);
|
|
} else {
|
|
return 0f;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Overridden toString() method for printing the state of this device.
|
|
*
|
|
* @return String representing current state of this device
|
|
*/
|
|
@Override
|
|
public String toString() {
|
|
return String.format("ServerRack(%s, %4.1fW, %3.1f℃C, %3.1f%%)",
|
|
super.getPowerState() ? "on" : "off", getPowerConsumption(),
|
|
temperature, currentLoad * 100);
|
|
}
|
|
}
|