<commit_before>package sophena.math.energetic;

import sophena.model.BufferTank;
import sophena.model.HeatNet;

public class Buffers {

	private Buffers() {
	}

	/**
	 * Calculates the buffer tank capacity of the given heating net
	 * specification, in kWh.
	 */
	public static double maxCapacity(HeatNet net) {
		if (net == null || net.bufferTank == null)
			return 0;
		double volume = net.bufferTank.volume; // liters
		double maxTemp = net.maxBufferLoadTemperature;
		double minTemp = net.lowerBufferLoadTemperature != null
				? net.lowerBufferLoadTemperature
				: net.supplyTemperature;
		return 0.001166 * volume * (maxTemp - minTemp);
	}

	/**
	 * Calculates the static loss factor of the buffer tank in the given
	 * heatnet. This value is then combined with the current buffer state in an
	 * simulation step to calculate the buffer loss (see the loss function).
	 */
	public static double lossFactor(HeatNet net) {
		if (net == null || net.bufferTank == null)
			return 0;
		BufferTank buffer = net.bufferTank;
		double ins = buffer.insulationThickness / 1000;
		if (ins == 0)
			return 0;
		double r = (buffer.diameter / 1000 - (2 * ins)) / 2;
		double h = buffer.height / 1000 - (2 * ins);
		double area = 2 * Math.PI * r * (r + h);
		double uValue = net.bufferLambda / ins;
		return area * uValue;
	}

	/**
	 * Returns the buffer loss for the given fill rate (a value between 0 and
	 * 1).
	 */<commit_msg>#6 minimal insulation thickness of 0.001 m<commit_after>package sophena.math.energetic;

import sophena.model.BufferTank;
import sophena.model.HeatNet;

public class Buffers {

	private Buffers() {
	}

	/**
	 * Calculates the buffer tank capacity of the given heating net
	 * specification, in kWh.
	 */
	public static double maxCapacity(HeatNet net) {
		if (net == null || net.bufferTank == null)
			return 0;
		double volume = net.bufferTank.volume; // liters
		double maxTemp = net.maxBufferLoadTemperature;
		double minTemp = net.lowerBufferLoadTemperature != null
				? net.lowerBufferLoadTemperature
				: net.supplyTemperature;
		return 0.001166 * volume * (maxTemp - minTemp);
	}

	/**
	 * Calculates the static loss factor of the buffer tank in the given
	 * heatnet. This value is then combined with the current buffer state in an
	 * simulation step to calculate the buffer loss (see the loss function).
	 */
	public static double lossFactor(HeatNet net) {
		if (net == null || net.bufferTank == null)
			return 0;
		BufferTank buffer = net.bufferTank;
		double ins = buffer.insulationThickness / 1000;
		if (ins <= 0) {
			ins = 0.001;
		}
		double r = (buffer.diameter / 1000 - (2 * ins)) / 2;
		double h = buffer.height / 1000 - (2 * ins);
		double area = 2 * Math.PI * r * (r + h);
		double uValue = net.bufferLambda / ins;
		return area * uValue;
	}

	/**
	 * Returns the buffer loss for the given fill rate (a value between 0 and
	 * 1).
	 */
{'fraction_non_alphanumeric': 0.10416666666666667, 'fraction_numerical': 0.022916666666666665, 'mean_word_length': 3.236764705882353, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6613493', 'n_tokens_mistral': 1042, 'n_tokens_neox': 892, 'n_words': 318}