# seawater-core **Repository Path**: xia-guard/seawater-core ## Basic Information - **Project Name**: seawater-core - **Description**: EOS-80 seawater density/salinity calculator (pure Java) - **Primary Language**: Java - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-10-20 - **Last Updated**: 2026-10-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # seawater-core EOS-80 海水密度/盐度计算库(纯 Java,零依赖) EOS-80 Seawater Density/Salinity Calculation Library (Pure Java, Zero Dependencies) [![Maven Central](https://img.shields.io/maven-central/v/io.github.dtxiaweibing/seawater-core)](https://search.maven.org/artifact/io.github.dtxiaweibing/seawater-core) --- ## 特性 / Features - 纯 Java 8+,无任何第三方依赖,可运行于任意 JVM/Android - 完整 EOS-80 公式,含压力(深度)项 - 四参数三求一:温度(T)、盐度(S)、压力(P)、密度(ρ) 任意知三求一 - 密度 ⇄ 盐度 双向换算(二分法求解) - 水深 / 压力单位换算 Pure Java 8+, no third-party dependencies, runs on any JVM/Android. Complete EOS-80 formula with pressure (depth) terms. Four-parameter computation: given any 3 of Temperature(T), Salinity(S), Pressure(P), Density(ρ), compute the 4th. Bidirectional density ⇄ salinity conversion (bisection method). Depth / pressure unit conversion. ## 安装 / Installation Maven: ```xml io.github.dtxiaweibing seawater-core 1.0.2 ``` Gradle: ```groovy implementation 'io.github.dtxiaweibing:seawater-core:1.0.2' ``` ## 四参数关系 / Four-Parameter Relationship EOS-80 标准中,温度(T)、盐度(S)、压力(P)、密度(ρ) 四个参数相互关联,**任意知道三个即可计算第四个**: In the EOS-80 standard, Temperature(T), Salinity(S), Pressure(P), and Density(ρ) are interrelated. **Given any 3, the 4th can be computed**: | 已知 Known | 求解 Solve | 方法 Method | 精度 | |---|---|---|---| | T, S, P | ρ | `density(T, S, P)` | 高 (直接公式) | | T, S, ρ | P | 二分法求压力 | 高 | | T, P, ρ | S | `solveSalinity(T, ρ, P)` | 高 (二分法) | | S, P, ρ | T | 二分法求温度 | 高 | > 注:当前库提供 `density()` 和 `solveSalinity()` 两个核心函数,`solveTemperature` 和 `solvePressure` 可通过二分法基于这两个函数实现。 > Note: The library provides `density()` and `solveSalinity()`. `solveTemperature` and `solvePressure` can be implemented via bisection using these two functions. ## 使用 / Usage ```java import io.github.dtxiaweibing.seawater.SeawaterDensity; // 海水密度:温度25℃、盐度30PSU、海平面 double rho = SeawaterDensity.densityAtSeaLevel(25.0, 30.0); // → 约 1019.6 kg/m³ // 含深度:水深5米(约0.5 bar) double rhoDeep = SeawaterDensity.densityAtDepth(25.0, 30.0, 5.0); // 含压力:直接指定压力(bar) double rhoP = SeawaterDensity.density(25.0, 30.0, 0.5); // 由密度反推盐度 double sal = SeawaterDensity.solveSalinity(25.0, 1021.5); // → 约 32.56 PSU // 纯水密度 double pw = SeawaterDensity.pureWaterDensity(25.0); // 水深/压力换算 double bar = SeawaterDensity.depthToPressureBar(10.0); // → 1.0 bar double m = SeawaterDensity.pressureBarToDepth(1.0); // → 10.0 m ``` ## API | 方法 / Method | 说明 / Description | |---|---| | `pureWaterDensity(tempC)` | 纯水密度 (kg/m³),0~40 ℃ / Pure water density | | `densityAtSeaLevel(tempC, salinity)` | 海平面海水密度 (kg/m³) / Sea level density | | `density(tempC, salinity, pressure)` | 含压力海水密度,pressure 单位 bar / Density with pressure | | `densityAtDepth(tempC, salinity, depthMeters)` | 指定水深的海水密度 / Density at depth | | `solveSalinity(tempC, targetDensity)` | 密度 → 盐度 (PSU),海平面 / Density → Salinity | | `solveSalinity(tempC, targetDensity, pressure)` | 密度 → 盐度,可指定压力 / Density → Salinity with pressure | | `secantBulkModulus(tempC, salinity, pressure)` | EOS-80 割线体积模量 (bar) / Secant bulk modulus | | `depthToPressureBar(depthMeters)` | 水深 → 压力 / Depth → Pressure | | `pressureBarToDepth(pressureBar)` | 压力 → 水深 / Pressure → Depth | --- ## 标准校验点 / Standard Verification Points 以下为 EOS-80 (UNESCO 1983) 公式计算值,用于验证本库实现的正确性。 参考值由独立 Python EOS-80 实现(与本库使用完全相同的 UNESCO 1983 系数)生成,输入温度为 ITS-90 温标。 本库内部自动执行 ITS-90 → IPTS-68 温标换算后套用公式,与参考值一致。 参考文献:UNESCO Technical Papers in Marine Science No.44 (1983), Fofonoff & Millard. These are EOS-80 (UNESCO 1983) formula computed values, used to verify this library's correctness. Reference values are generated by an independent Python EOS-80 implementation using identical UNESCO 1983 coefficients. Input temperatures are ITS-90; the library internally converts ITS-90 → IPTS-68 before applying the formula. Reference: UNESCO Technical Papers in Marine Science No.44 (1983), Fofonoff & Millard. ### 1. 海平面密度 (P=0 bar) / Sea Level Density | T(℃) | S(PSU) | 参考值 Reference (kg/m³) | 本库输出 Computed (kg/m³) | 偏差 Diff (kg/m³) | |---|---|---|---|---| | 0 | 0 | 999.842594 | 999.842594 | 0.000000 | | 5 | 0 | 999.966732 | 999.966732 | 0.000000 | | 10 | 0 | 999.701870 | 999.701870 | 0.000000 | | 15 | 0 | 999.101032 | 999.101032 | 0.000000 | | 20 | 0 | 998.205329 | 998.205329 | 0.000000 | | 25 | 0 | 997.046420 | 997.046420 | 0.000000 | | 30 | 0 | 995.648960 | 995.648960 | 0.000000 | | 35 | 0 | 994.033060 | 994.033060 | 0.000000 | | 40 | 0 | 992.216736 | 992.216736 | 0.000000 | | 0 | 35 | 1028.106331 | 1028.106331 | 0.000000 | | 5 | 35 | 1027.675325 | 1027.675325 | 0.000000 | | 10 | 35 | 1026.952000 | 1026.952000 | 0.000000 | | 15 | 35 | 1025.971963 | 1025.971963 | 0.000000 | | 20 | 35 | 1024.761740 | 1024.761740 | 0.000000 | | 25 | 35 | 1023.341235 | 1023.341235 | 0.000000 | | 30 | 35 | 1021.726181 | 1021.726181 | 0.000000 | | 35 | 35 | 1019.930597 | 1019.930597 | 0.000000 | | 40 | 35 | 1017.969237 | 1017.969237 | 0.000000 | ### 2. 高压密度校验 (S=35 PSU, P=500~5000 bar) / High Pressure Density > ⚠️ UNESCO 1983 公式压力有效范围为 **0~1000 bar**。P=500~1000 bar 为公式有效区间; > P=2000~5000 bar 为多项式**外推值**,仅用于验证本库与独立 EOS-80 实现的一致性, > 不代表 UNESCO 1983 在该区间的物理精度。外推值以 `*` 标注。 > > ⚠️ UNESCO 1983 valid pressure range is **0~1000 bar**. P=500~1000 bar is within range; > P=2000~5000 bar are **extrapolated** polynomial values, shown only to confirm > consistency with an independent EOS-80 implementation, not physical accuracy. > Extrapolated rows are marked `*`. | P(bar) | T(℃) | 参考值 Reference (kg/m³) | 本库输出 Computed (kg/m³) | 偏差 Diff (kg/m³) | |---|---|---|---|---| | 500 | 0 | 1050.677714 | 1050.677714 | 0.000000 | | 500 | 5 | 1049.657233 | 1049.657233 | 0.000000 | | 500 | 10 | 1048.450525 | 1048.450525 | 0.000000 | | 500 | 15 | 1047.075502 | 1047.075502 | 0.000000 | | 500 | 20 | 1045.545155 | 1045.545155 | 0.000000 | | 500 | 25 | 1043.868982 | 1043.868982 | 0.000000 | | 500 | 30 | 1042.054754 | 1042.054754 | 0.000000 | | 500 | 35 | 1040.110497 | 1040.110497 | 0.000000 | | 500 | 40 | 1038.046647 | 1038.046647 | 0.000000 | | 1000 | 0 | 1070.958384 | 1070.958384 | 0.000000 | | 1000 | 5 | 1069.488772 | 1069.488772 | 0.000000 | | 1000 | 10 | 1067.906304 | 1067.906304 | 0.000000 | | 1000 | 15 | 1066.217548 | 1066.217548 | 0.000000 | | 1000 | 20 | 1064.426570 | 1064.426570 | 0.000000 | | 1000 | 25 | 1062.535844 | 1062.535844 | 0.000000 | | 1000 | 30 | 1060.547657 | 1060.547657 | 0.000000 | | 1000 | 35 | 1058.465849 | 1058.465849 | 0.000000 | | 1000 | 40 | 1056.297803 | 1056.297803 | 0.000000 | | 2000* | 0 | 1105.692329 | 1105.692329 | 0.000000 | | 2000* | 5 | 1103.742734 | 1103.742734 | 0.000000 | | 2000* | 10 | 1101.733312 | 1101.733312 | 0.000000 | | 2000* | 15 | 1099.663662 | 1099.663662 | 0.000000 | | 2000* | 20 | 1097.531650 | 1097.531650 | 0.000000 | | 2000* | 25 | 1095.334378 | 1095.334378 | 0.000000 | | 2000* | 30 | 1093.069620 | 1093.069620 | 0.000000 | | 2000* | 35 | 1090.737581 | 1090.737581 | 0.000000 | | 2000* | 40 | 1088.342902 | 1088.342902 | 0.000000 | | 3000* | 0 | 1134.047957 | 1134.047957 | 0.000000 | | 3000* | 5 | 1132.136704 | 1132.136704 | 0.000000 | | 3000* | 10 | 1130.111071 | 1130.111071 | 0.000000 | | 3000* | 15 | 1127.976965 | 1127.976965 | 0.000000 | | 3000* | 20 | 1125.736419 | 1125.736419 | 0.000000 | | 3000* | 25 | 1123.389314 | 1123.389314 | 0.000000 | | 3000* | 30 | 1120.935347 | 1120.935347 | 0.000000 | | 3000* | 35 | 1118.376172 | 1118.376172 | 0.000000 | | 3000* | 40 | 1115.717671 | 1115.717671 | 0.000000 | | 4000* | 0 | 1157.326135 | 1157.326135 | 0.000000 | | 4000* | 5 | 1155.902697 | 1155.902697 | 0.000000 | | 4000* | 10 | 1154.229424 | 1154.229424 | 0.000000 | | 4000* | 15 | 1152.321867 | 1152.321867 | 0.000000 | | 4000* | 20 | 1150.189581 | 1150.189581 | 0.000000 | | 4000* | 25 | 1147.838608 | 1147.838608 | 0.000000 | | 4000* | 30 | 1145.274003 | 1145.274003 | 0.000000 | | 4000* | 35 | 1142.502398 | 1142.502398 | 0.000000 | | 4000* | 40 | 1139.534556 | 1139.534556 | 0.000000 | | 5000* | 0 | 1176.516447 | 1176.516447 | 0.000000 | | 5000* | 5 | 1175.955326 | 1175.955326 | 0.000000 | | 5000* | 10 | 1174.955513 | 1174.955513 | 0.000000 | | 5000* | 15 | 1173.536491 | 1173.536491 | 0.000000 | | 5000* | 20 | 1171.711780 | 1171.711780 | 0.000000 | | 5000* | 25 | 1169.491990 | 1169.491990 | 0.000000 | | 5000* | 30 | 1166.887789 | 1166.887789 | 0.000000 | | 5000* | 35 | 1163.912735 | 1163.912735 | 0.000000 | | 5000* | 40 | 1160.585971 | 1160.585971 | 0.000000 | ### 3. 反推盐度校验 / Salinity Back-Calculation 通过密度反推盐度,验证双向换算精度: Back-calculating salinity from density to verify bidirectional accuracy: | 输入 Input | 本库输出 Computed | 参考值 Reference | 偏差 Diff | |---|---|---|---| | solveSal(5, 1027.6753, 0) | 35.0000 PSU | 35.0000 PSU | 0.0000 | | solveSal(25, 1023.3412, 0) | 35.0000 PSU | 35.0000 PSU | 0.0000 | | solveSal(25, 1062.5358, 1000) | 35.0000 PSU | 35.0000 PSU | 0.0000 | | solveSal(5, 1049.6572, 500) | 35.0000 PSU | 35.0000 PSU | 0.0000 | | solveSal(15, 1099.6637, 2000) | 35.0000 PSU | 35.0000 PSU | 0.0000 | | solveSal(25, 1169.4920, 5000) | 35.0000 PSU | 35.0000 PSU | 0.0000 | | solveSal(10, 999.7019, 0) | 0.0000 PSU | 0.0000 PSU | 0.0000 | | solveSal(20, 998.2053, 0) | 0.0000 PSU | 0.0000 PSU | 0.0000 | | solveSal(30, 995.6490, 0) | 0.0000 PSU | 0.0000 PSU | 0.0000 | | solveSal(40, 992.2167, 0) | 0.0000 PSU | 0.0000 PSU | 0.0000 | ### 4. 校验汇总 / Summary | 校验类别 Category | 总数 Total | 通过 Pass | 精度范围 Accuracy | |---|---|---|---| | 海平面密度 (P=0) | 18 | 18 | 0.000000 kg/m³ | | 高压密度 有效区间 (500≤P≤1000 bar) | 18 | 18 | 0.000000 kg/m³ | | 高压密度 外推 (P≥2000 bar)* | 36 | 36 | 0.000000 kg/m³ (仅多项式一致,非物理精度) | | 反推盐度 | 10 | 10 | < 0.0001 PSU | --- ## 参数范围与精度 / Parameter Ranges & Accuracy ### EOS-80 公式有效范围 / EOS-80 Valid Range | 参数 Parameter | 有效范围 Valid Range | 说明 Notes | |---|---|---| | 温度 Temperature | -2~40 ℃ | UNESCO 1983 规定范围 | | 盐度 Salinity | 0~42 PSU | UNESCO 1983 规定范围 | | 压力 Pressure | 0~1000 bar | 对应水深 0~10000m | > 本库内部自动执行 ITS-90 → IPTS-68 温标换算,在上述有效范围内与独立 EOS-80 参考实现偏差为 0(浮点精度内)。 > This library automatically converts ITS-90 → IPTS-68 temperature scale internally. > Within the valid range, it matches independent EOS-80 reference implementations with zero deviation (within floating-point precision). ### 不适用场景 / Not Recommended | 场景 Scenario | 原因 Reason | |---|---| | 超冷水 (< -2℃) | 超出公式有效范围 | | 高盐度卤水 (> 42 PSU) | 超出公式有效范围 | ### 压力换算说明 / Pressure Conversion 本库采用近似换算:**10m 水柱 ≈ 1 bar** 实际海水压力与温度、盐度有关,精确换算需考虑: - p(bar) ≈ depth(m) × ρ(kg/m³) × g(m/s²) / 10⁵ - 标准海水 (S=35, T=15℃):10.03m ≈ 1 bar 本近似满足养殖、浅海、水族等场景,深海应用需使用精确压力换算。 --- ## 限制 / Limitations - 温度 0~40 ℃;盐度 0~42 PSU(超出自动截断至 0~42) - 压力换算采用近似:10m 水柱 ≈ 1 bar - 输入温度为 ITS-90 温标,内部自动换算为 IPTS-68 后套用 EOS-80 公式 Temperature range: 0~40 ℃; Salinity range: 0~42 PSU (auto-clamped). Pressure approximation: 10m water column ≈ 1 bar. Input temperatures are ITS-90; internally converted to IPTS-68 for the EOS-80 formula. ## License Apache-2.0