<commit_before>package org.pfaa.chemica.model;

import java.util.ArrayList;
import java.util.List;

public class Thermo {

	private List<Shomate> shomates = new ArrayList();
	private List<Double> temperatureBreaks;
	private double H, S;
	
	private Thermo(Thermo thermo) {
		this.H = thermo.H;
		this.S = thermo.S;
		this.shomates.addAll(thermo.shomates);
		this.temperatureBreaks.addAll(thermo.temperatureBreaks);
	}
	
	public Thermo(double H, double S, Shomate shomate) {
		this.H = H;
		this.S = S;
		this.shomates.add(shomate);
	}
	
	public Thermo(double H, double S, double Cp) { /* constant heat capacity */
		this(H, S, new Shomate(H, S, Cp));
	}

	public Thermo(double H, double S, double a, double b) { /* linear heat capacity */
		this(H, S, new Shomate(H, S, a, b));
	}
	
	private Shomate findSegment(double t) {
		int si = this.temperatureBreaks.size() - 1;
		while(si >= 0 && this.temperatureBreaks.get(si) < t)
			si--;
		return shomates.get(si + 1);
	}
	
	public double getHeatCapacity(double t) {
		return findSegment(t).getHeatCapacity(t);
	}

	public double integrateHeatCapacity(double t) {
		return getEnthalpy(t) - this.H;
	}
	
	public double getStandardEnthalpy() {
		return this.H;
	}
	
	public double getStandardEntropy() {
		return this.S;
	}
	
	public double getEnthalpy(double t) {
		return findSegment(t).getEnthalpy(t);
	}
	
	public double getEntropy(double t) {
		return findSegment(t).getEntropy(t);
	}
	
	public Thermo addSegment(double t0, Shomate segment) {
		Thermo clone = new Thermo(this);
		clone.shomates.add(segment);
		clone.temperatureBreaks.add(t0);
		return clone;
	}
	
	public Thermo addSegment(double t0, double Cp) {
		return addSegment(t0, new Shomate(this.H, this.S, Cp));
	}
	
	public Thermo addSegment(double t0, double a, double b) {
		return addSegment(t0, new Shomate(this.H, this.S, a, b));
	}
	
	public static class Shomate {
		public final double a, b, c, d, e, f, g;
	
		public Shomate(double H, double S, double a) { /* constant heat capacity */
			this(H, S, a, 0);
		}
		
		public Shomate(double H, double S, double a, double b) { /* simple linear relationship */
			this(a, b, 0, 0, 0, estimateF(H, a, b), estimateG(S, a, b));
		}
		
		public Shomate(double a, double b, double c, double d, double e, double f, double g) {
			this.a = a;
			this.b = b;
			this.c = c;
			this.d = d;
			this.e = e;
			this.f = f;
			this.g = g;
		}
		
		private static double estimateF(double H, double a, double b) {
			double t = Constants.STANDARD_TEMPERATURE / 1000;
			return H - a * t - b * Math.pow(t, 2) / 2;
		}
		
		private static double estimateG(double S, double a, double b) {
			double t = Constants.STANDARD_TEMPERATURE / 1000;
			return S - a * Math.log(t) - b * t;
		}
		
		public double getHeatCapacity(double t) {
			t = t / 1000;
			return a + b * t + c * Math.pow(t, 2) + d * Math.pow(t, 3) + e / Math.pow(t, 2);
		}
		
		public double getEnthalpy(double t) {
			t = t / 1000;
			return a * t + b * Math.pow(t, 2) / 2 + c * Math.pow(t, 3) / 3 + d * Math.pow(t, 4) / 4 - e / t + f;
		}
		
		public double getEntropy(double t) {
			t = t / 1000;
			return a * Math.log(t) + b * t + c * Math.pow(t, 2) / 2 + d * Math.pow(t, 3) / 3 - e / (2*Math.pow(t, 2)) + g;
		}
	}
}
<commit_msg>redesign the thermodynamic data model so that enthalpy and entropy are not redundant with the shomate parameters<commit_after>package org.pfaa.chemica.model;

import java.util.ArrayList;
import java.util.List;

public class Thermo {

	private List<Segment> shomates = new ArrayList();
	private List<Double> temperatureBreaks;
	
	private Thermo(Thermo thermo) {
		this.shomates.addAll(thermo.shomates);
		this.temperatureBreaks.addAll(thermo.temperatureBreaks);
	}
	
	private Thermo(Segment shomate) {
		this.shomates.add(shomate);
	}
	
	public Thermo(double S) { /* supports only transitions to this phase, but no heating or reactions */
		this(Double.NaN, S, Double.NaN);
	}
	public Thermo(double H, double S, double Cp) { /* constant heat capacity */
		this(H, S, Cp, 0);
	}
	public Thermo(double H, double S, double a, double b) { /* linear heat capacity */
		this(H, S, a, b, 0, 0);
	}
	public Thermo(double H, double S, double a, double b, double c, double e) { /* quadratic heat capacity */
		this(new Segment(H, S, a, b, c, e));
	}
	public Thermo(double a, double b, double c, double d, double e, double f, double g) { /* quadratic heat capacity */
		this(new Segment(a, b, c, d, e, f, g));
	}
	
	private Segment findSegment(double t) {
		int si = this.temperatureBreaks.size() - 1;
		while(si >= 0 && this.temperatureBreaks.get(si) < t)
			si--;
		return shomates.get(si + 1);
	}
	
	public double getHeatCapacity(double t) {
		return findSegment(t).getHeatCapacity(t);
	}

	public double integrateHeatCapacity(double t) {
		return getEnthalpy(t) - getStandardEnthalpy();
	}
	
	public double getStandardEnthalpy() {
		return getHeatCapacity(Constants.STANDARD_TEMPERATURE);
	}
	
	public double getStandardEntropy() {
		return getEntropy(Constants.STANDARD_TEMPERATURE);
	}
	
	public double getEnthalpy(double t) {
		return findSegment(t).getEnthalpy(t);
	}
	
	public double getEntropy(double t) {
		return findSegment(t).getEntropy(t);
	}
	
	public Thermo addSegment(double t0, Segment segment) {
		Thermo clone = new Thermo(this);
		clone.shomates.add(segment);
		clone.temperatureBreaks.add(t0);
		return clone;
	}
	
	public Thermo addSegment(double t0, double Cp) {
		return addSegment(t0, Cp, 0);
	}
	
	public Thermo addSegment(double t0, double a, double b) {
		return addSegment(t0, new Segment(this.getStandardEnthalpy(), this.getStandardEntropy(), a, b));
	}
	
	public Thermo addSegment(double t0, double a, double b, double c, double d, double e, double f, double g) {
		return addSegment(t0, new Segment(a, b, c, d, e, f, g));
	}
	
	private static class Segment {
		public final double a, b, c, d, e, f, g;
		
		public Segment(double a, double b, double c, double d, double e, double f, double g) { // full form
			this.a = a;
			this.b = b;
			this.c = c;
			this.d = d;
			this.e = e;
			this.f = f;
			this.g = g;
		}
		
		/* Simplified forms for when there are no published Shomate parameters */
		
		public Segment(double H, double S, double a) { // constant
			this(H, S, a, 0);
		}
		public Segment(double H, double S, double a, double b) { // linear
			this(H, S, a, b, 0, 0);
		}
		public Segment(double H, double S, double a, double b, double c, double e) { // quadratic
			this.a = a;
			this.b = b;
			this.c = c;
			this.d = 0;
			this.e = e;
			this.f = H - this.getEnthalpy(Constants.STANDARD_TEMPERATURE);
			this.g = S - this.getEntropy(Constants.STANDARD_TEMPERATURE);
		}
		
		public double getHeatCapacity(double t) {
			t = t / 1000;
			return a + b * t + c * Math.pow(t, 2) + d * Math.pow(t, 3) + e / Math.pow(t, 2);
		}
		
		public double getEnthalpy(double t) {
			t = t / 1000;
			return a * t + b * Math.pow(t, 2) / 2 + c * Math.pow(t, 3) / 3 + d * Math.pow(t, 4) / 4 - e / t + f;
		}
		
		public double getEntropy(double t) {
			t = t / 1000;
			return a * Math.log(t) + b * t + c * Math.pow(t, 2) / 2 + d * Math.pow(t, 3) / 3 - e / (2*Math.pow(t, 2)) + g;
		}
	}
}

{'fraction_non_alphanumeric': 0.1379647749510763, 'fraction_numerical': 0.013419066256639642, 'mean_word_length': 3.1550522648083623, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '116124', 'n_tokens_mistral': 3041, 'n_tokens_neox': 2624, 'n_words': 798}