You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
4.9 KiB
138 lines
4.9 KiB
package com.mh.common.utils; |
|
|
|
import java.math.BigDecimal; |
|
import java.math.RoundingMode; |
|
|
|
/** |
|
* @author LJF |
|
* @version 1.0 |
|
* @project NewZhujiang_Server |
|
* @description 天气工具类 |
|
* @date 2024-04-15 11:16:06 |
|
*/ |
|
public class WeatherUtil { |
|
|
|
// Magnus公式常数 |
|
private static final double A = 17.27; |
|
private static final double B = 237.7; |
|
|
|
public double E(double t) { |
|
// 饱和水汽压:E(t)=611.2exp(17.67t/(243.5+t)) |
|
return 611.2 * Math.exp(17.67 * t / (243.5 + t)); |
|
} |
|
|
|
public double g(double t) { |
|
// 干空气比焓:g(t)=1.01t 1.01为干空气的定压比热,kJ/(kg℃)。 |
|
return 1.01 * t; |
|
} |
|
|
|
public double v(double t) { |
|
// 水蒸气比焓:v(t)=2501+1.85t 2501是水在0℃时变成水蒸气的汽化潜热,kJ/kg;1.85是水蒸气的定压比热,kJ/(kg℃) |
|
return 2501 + 1.85 * t; |
|
} |
|
|
|
public double d(double t, double psi, double p) { |
|
// 湿空气的含湿量:d(t,ψ)=0.622ψE(t)/(p-ψE(t)) ψ为相对湿度;p为标准大气压101325,单位为Pa |
|
return 0.622 * psi * E(t) / (p - psi * E(t)); |
|
} |
|
|
|
public double d2(double tg, double ts, double ds) { |
|
// tw为湿空气湿球温度,℃;t为干球温度,℃;ds为湿空气等焓加湿到饱和状态时含湿量(简称饱和含湿量),kg / kg(a) |
|
// 此处假设ds值直接输入,不需要查表 |
|
if (ts >= 0) { |
|
return ((2530 - 2.326 * ts) * ds - 1.006 * (tg - ts)) / |
|
(2501 + 1.86 * tg - 4.186 * ts); |
|
} else { |
|
return ((2830 - 0.24 * ts) * ds - 1.006 * (tg - ts)) / |
|
(2830 + 1.86 * tg - 2.1 * ts); |
|
} |
|
} |
|
|
|
public double h(double t, double psi, double p) { |
|
// 湿空气的比焓:h(t,ψ)=g(t)+d(t,ψ)v(t) |
|
return g(t) + d(t, psi, p) * v(t); |
|
} |
|
|
|
public double computePsi(double tg, double ts, double p) { |
|
// ψ为相对湿度, tg为干球温度,ts为湿球温度 |
|
return p * (g(ts) - g(tg) + d(ts, 1, p) * v(ts)) / |
|
(E(tg) * (g(ts) - g(tg) + d(ts, 1, p) * v(ts) + 0.622 * v(tg))); |
|
} |
|
|
|
/** |
|
* 计算湿球温度 |
|
* @param temp |
|
* @param wet |
|
* @return |
|
*/ |
|
public BigDecimal returnComputePsi(double temp, double wet, double p) { |
|
double oTs = 0; |
|
double oD = 0; |
|
for (int i = 0; i < 10000; i++) { |
|
oTs += 0 + i * 0.00001; |
|
oD = computePsi(temp, oTs, p); |
|
double gap = wet - oD; |
|
if (Math.abs(gap) <= 0.001) { |
|
break; |
|
} |
|
} |
|
return new BigDecimal(oTs); |
|
} |
|
|
|
/** |
|
* 计算含湿量 |
|
* @param temp 单位:℃ |
|
* @param wet 单位:0.01 |
|
* @param pressure 单位:KPa |
|
* @return |
|
*/ |
|
public BigDecimal returnMoistureContent(String temp, String wet, String pressure) { |
|
// 计算水蒸气饱和压力 |
|
BigDecimal divide = new BigDecimal("7.5").multiply(new BigDecimal(temp)) |
|
.divide(new BigDecimal("237") |
|
.add(new BigDecimal(temp)), 20, RoundingMode.HALF_UP); |
|
// double result = Math.pow(10, Double.parseDouble(divide.toString()))*0.611; |
|
// System.out.println("水蒸气饱和压力==》" + result); |
|
// 计算含湿量 |
|
BigDecimal ps = new BigDecimal(wet).multiply(BigDecimal.valueOf(Math.pow(10, Double.parseDouble(divide.toString())) * 0.611)); |
|
BigDecimal d = new BigDecimal("622").multiply( |
|
ps.divide(new BigDecimal(pressure).subtract(ps), 10, RoundingMode.HALF_UP)); |
|
return d; |
|
} |
|
|
|
/** |
|
* 比较焓值 |
|
* @param temp 单位:℃ |
|
* @param wet 单位:0.01 |
|
* @param pressure 单位:KPa |
|
* @return |
|
*/ |
|
public BigDecimal returnEnthalpy(String temp, String wet, String pressure) { |
|
BigDecimal moistureContent = returnMoistureContent(temp, wet, pressure); |
|
BigDecimal add = (new BigDecimal("2490") |
|
.add(new BigDecimal("1.84").multiply(new BigDecimal(temp)))) |
|
.multiply(moistureContent).divide(new BigDecimal("1000"), 10, RoundingMode.HALF_UP); |
|
// 计算焓值 |
|
BigDecimal i = (new BigDecimal(temp).multiply(new BigDecimal("1.01"))).add(add); |
|
return i.setScale(1, RoundingMode.HALF_UP); |
|
} |
|
|
|
/** |
|
* 计算露点温度 |
|
* @param temperature 当前温度(℃) |
|
* @param humidity 相对湿度(%) |
|
* @return 露点温度(℃),保留2位小数 |
|
*/ |
|
public BigDecimal calculateDewPoint(double temperature, double humidity) { |
|
// 1. 计算中间变量α |
|
double alpha = (A * temperature) / (B + temperature) + Math.log(humidity / 100.0); |
|
|
|
// 2. 计算露点温度 |
|
double dewPoint = (B * alpha) / (A - alpha); |
|
|
|
// 3. 四舍五入保留2位小数 |
|
return BigDecimal.valueOf(dewPoint) |
|
.setScale(2, RoundingMode.HALF_UP); |
|
} |
|
|
|
}
|
|
|