From 60a6f9fed1e92e38325ad90077e737a4188c3ee6 Mon Sep 17 00:00:00 2001
From: Rahil Doshi <rahil.doshi@fau.de>
Date: Tue, 18 Mar 2025 17:22:38 +0100
Subject: [PATCH] Update property value validation in yaml parser, remove
 checks from models.py

---
 src/pymatlib/core/models.py      | 38 ++++++++++++++++----------------
 src/pymatlib/core/yaml_parser.py | 21 ++++++++++++------
 2 files changed, 33 insertions(+), 26 deletions(-)

diff --git a/src/pymatlib/core/models.py b/src/pymatlib/core/models.py
index 4a76560..ab85451 100644
--- a/src/pymatlib/core/models.py
+++ b/src/pymatlib/core/models.py
@@ -8,7 +8,7 @@ NumericType = TypeVar('NumericType', float, np.float32, np.float64)
 
 # Constants
 ABSOLUTE_ZERO = 0.0  # Kelvin
-DEFAULT_TOLERANCE = 1e-10
+# DEFAULT_TOLERANCE = 1e-10
 
 
 def sympy_wrapper(value: Union[sp.Expr, NumericType, ArrayTypes, MaterialProperty]) \
@@ -51,24 +51,24 @@ def material_property_wrapper(value: Union[sp.Expr, NumericType, ArrayTypes]) \
     return MaterialProperty(wrapped_value)
 
 
-def _validate_positive(*values, names=None):
+'''def _validate_positive(*values, names=None):
     """Validate that float values are positive."""
     if names is None:
         names = [f"Value {i+1}" for i in range(len(values))]
 
     for value, name in zip(values, names):
         if isinstance(value, float) and value <= 0:
-            raise ValueError(f"{name} must be positive, got {value}")
+            raise ValueError(f"{name} must be positive, got {value}")'''
 
 
-def _validate_non_negative(*values, names=None):
+'''def _validate_non_negative(*values, names=None):
     """Validate that float values are non-negative."""
     if names is None:
         names = [f"Value {i+1}" for i in range(len(values))]
 
     for value, name in zip(values, names):
         if isinstance(value, float) and value < 0:
-            raise ValueError(f"{name} cannot be negative, got {value}")
+            raise ValueError(f"{name} cannot be negative, got {value}")'''
 
 
 def _prepare_material_expressions(*properties):
@@ -111,12 +111,12 @@ def density_by_thermal_expansion(
             raise ValueError(f"Temperature cannot be below absolute zero ({ABSOLUTE_ZERO}K)")
     if isinstance(temperature, ArrayTypes):
         raise TypeError(f"Incompatible input type for temperature. Expected float or sp.Expr, got {type(temperature)}")
-    if temperature_base < ABSOLUTE_ZERO:
-        raise ValueError(f"Base temperature cannot be below absolute zero ({ABSOLUTE_ZERO}K)")
-    if density_base <= 0:
-        raise ValueError("Base density must be positive")
-    if isinstance(thermal_expansion_coefficient, float) and (thermal_expansion_coefficient < -3e-5 or thermal_expansion_coefficient > 0.001):
-        raise ValueError(f"Thermal expansion coefficient must be between -3e-5 and 0.001, got {thermal_expansion_coefficient}")
+    # if temperature_base < ABSOLUTE_ZERO:
+        # raise ValueError(f"Base temperature cannot be below absolute zero ({ABSOLUTE_ZERO}K)")
+    # if density_base <= 0:
+        # raise ValueError("Base density must be positive")
+    # if isinstance(thermal_expansion_coefficient, float) and (thermal_expansion_coefficient < -3e-5 or thermal_expansion_coefficient > 0.001):
+        # raise ValueError(f"Thermal expansion coefficient must be between -3e-5 and 0.001, got {thermal_expansion_coefficient}")
 
     try:
         tec_expr = thermal_expansion_coefficient.expr if isinstance(thermal_expansion_coefficient, MaterialProperty) else sympy_wrapper(thermal_expansion_coefficient)
@@ -145,7 +145,7 @@ def thermal_diffusivity_by_heat_conductivity(
         TypeError: If incompatible input data types are provided.
         ValueError: If physically impossible values are used.
     """
-    _validate_positive(heat_conductivity, density, heat_capacity, names=["Heat conductivity", "Density", "Heat capacity"])
+    # _validate_positive(heat_conductivity, density, heat_capacity, names=["Heat conductivity", "Density", "Heat capacity"])
 
     (k_expr, rho_expr, cp_expr), sub_assignments \
         = _prepare_material_expressions(heat_conductivity, density, heat_capacity)
@@ -165,16 +165,16 @@ def energy_density_standard(
         -> MaterialProperty:
 
     # Input validation to check for incompatible data types
-    if isinstance(temperature, float) and temperature < ABSOLUTE_ZERO:
-        raise ValueError(f"Temperature cannot be below absolute zero ({ABSOLUTE_ZERO}K)")
+    # if isinstance(temperature, float) and temperature < ABSOLUTE_ZERO:
+        # raise ValueError(f"Temperature cannot be below absolute zero ({ABSOLUTE_ZERO}K)")
     '''if isinstance(density, float) and density <= 0:
         raise ValueError(f"Density must be positive, got {density}")
     if isinstance(heat_capacity, float) and heat_capacity <= 0:
         raise ValueError(f"Heat capacity must be positive, got {heat_capacity}")'''
-    _validate_positive(density, heat_capacity, names=['Density', 'Heat capacity'])
+    # _validate_positive(density, heat_capacity, names=['Density', 'Heat capacity'])
     '''if isinstance(latent_heat, float) and latent_heat < 0:
         raise ValueError(f"Latent heat cannot be negative (should be zero or positive), got {latent_heat}")'''
-    _validate_non_negative(latent_heat, names=['Latent heat'])
+    # _validate_non_negative(latent_heat, names=['Latent heat'])
 
     '''sub_assignments = [
         assignment for prop in [density, heat_capacity, latent_heat]
@@ -203,8 +203,8 @@ def energy_density_enthalpy_based(
         latent_heat: Union[float, MaterialProperty]) \
         -> MaterialProperty:
 
-    _validate_positive(density, specific_enthalpy, names=["Density", "Specific enthalpy"])
-    _validate_non_negative(latent_heat, names=["Latent heat"])
+    # _validate_positive(density, specific_enthalpy, names=["Density", "Specific enthalpy"])
+    # _validate_non_negative(latent_heat, names=["Latent heat"])
 
     (density_expr, specific_enthalpy_expr, latent_heat_expr), sub_assignments \
         = _prepare_material_expressions(density, specific_enthalpy, latent_heat)
@@ -218,7 +218,7 @@ def energy_density_total_enthalpy(
         specific_enthalpy: Union[float, MaterialProperty]) \
         -> MaterialProperty:
 
-    _validate_positive(density, specific_enthalpy, names=["Density", "Specific enthalpy"])
+    # _validate_positive(density, specific_enthalpy, names=["Density", "Specific enthalpy"])
 
     (density_expr, specific_enthalpy_expr), sub_assignments \
         = _prepare_material_expressions(density, specific_enthalpy)
diff --git a/src/pymatlib/core/yaml_parser.py b/src/pymatlib/core/yaml_parser.py
index 8d4ff00..7b19550 100644
--- a/src/pymatlib/core/yaml_parser.py
+++ b/src/pymatlib/core/yaml_parser.py
@@ -229,18 +229,25 @@ class MaterialConfigParser:
         # Property-specific range constraints
         PROPERTY_RANGES = {
             'base_temperature': (0, 5000),  # K
-            'temperature': (0, 5000),  # K
-            'base_density': (800, 22000),  # kg/m³
-            'density': (800, 22000),  # kg/m³
+            'base_density': (-100, 22000),  # kg/m³
+            'density': (100, 22000),  # kg/m³
+            'dynamic_viscosity': (1e-4, 1e5),  # Pa·s
+            'energy_density': (0, 1e8),  # J/m³
+            'energy_density_solidus': (0, 1e8),  # J/m³
+            'energy_density_liquidus': (0, 1e8),  # J/m³
+            'energy_density_temperature_array': (0, 5000),  # K
+            'energy_density_array': (0, 1e8),  # J/m³
             'heat_capacity': (100, 10000),  # J/(kg·K)
             'heat_conductivity': (1, 600),  # W/(m·K)
-            'thermal_expansion_coefficient': (-5e-5, 3e-5),  # 1/K
-            'dynamic_viscosity': (1e-4, 1e5),  # Pa·s
             'kinematic_viscosity': (1e-8, 1e-3),  # m²/s
-            'thermal_diffusivity': (1e-8, 1e-3),  # m²/s
-            'surface_tension': (0.1, 3.0),  # N/m
             'latent_heat_of_fusion': (0, 600000),  # J/kg
             'latent_heat_of_vaporization': (50000, 12000000),  # J/kg
+            'specific_enthalpy': (0, 15000000),  # J/kg
+            'surface_tension': (0.1, 3.0),  # N/m
+            'temperature': (0, 5000),  # K
+            'temperature_array': (0, 5000),  # K
+            'thermal_diffusivity': (1e-8, 1e-3),  # m²/s
+            'thermal_expansion_coefficient': (-3e-5, 3e-5),  # 1/K
         }
 
         try:
-- 
GitLab