diff --git a/src/pymatlib/core/yaml_parser.py b/src/pymatlib/core/yaml_parser.py index f96957d69bf80d45cd1eecf85e00b1423afc2007..fc514fb1609acec232e57c5f3d052ddf9d95c2c0 100644 --- a/src/pymatlib/core/yaml_parser.py +++ b/src/pymatlib/core/yaml_parser.py @@ -250,7 +250,7 @@ class MaterialConfigParser: 'heat_conductivity': (1, 600), # W/(m·K) 'kinematic_viscosity': (1e-8, 1e-3), # m²/s 'latent_heat_of_fusion': (0, 600000), # J/kg - 'latent_heat_of_vaporization': (50000, 12000000), # J/kg + 'latent_heat_of_vaporization': (0, 12000000), # J/kg 'specific_enthalpy': (0, 15000000), # J/kg 'surface_tension': (0.1, 3.0), # N/m 'thermal_diffusivity': (1e-8, 1e-3), # m²/s @@ -564,7 +564,9 @@ class MaterialConfigParser: categorized_properties = self._categorize_properties(properties) for prop_type, prop_list in categorized_properties.items(): for prop_name, config in prop_list: - if prop_type == PropertyType.CONSTANT: + if prop_type == PropertyType.CONSTANT and prop_name in ['latent_heat_of_fusion', 'latent_heat_of_vaporization']: + self._process_latent_heat_constant(alloy, prop_name, config, T) + elif prop_type == PropertyType.CONSTANT: self._process_constant_property(alloy, prop_name, config) elif prop_type == PropertyType.FILE: self._process_file_property(alloy, prop_name, config, T) @@ -577,6 +579,43 @@ class MaterialConfigParser: ######################################################################################################################## + def _process_latent_heat_constant(self, alloy: Alloy, prop_name: str, prop_config: Union[float, str], T: Union[float, sp.Symbol]) -> None: + """ + Process latent heat properties when provided as constants. + This automatically expands them to key-val pairs using solidus and liquidus temperatures. + Args: + alloy (Alloy): The alloy object to update. + prop_name (str): The name of the property to set ('latent_heat_of_fusion' or 'latent_heat_of_vaporization'). + prop_config (Union[float, str]): The constant latent heat value. + T (Union[float, sp.Symbol]): Temperature value or symbol. + """ + try: + # Convert to float + latent_heat_value = float(prop_config) + # Validate the value + self._validate_property_value(prop_name, latent_heat_value) + # Create expanded key-val configuration + if prop_name == 'latent_heat_of_fusion': + # For fusion, heat is absorbed between solidus and liquidus + expanded_config = { + 'key': ['solidus_temperature', 'liquidus_temperature'], + 'val': [0, latent_heat_value] + } + elif prop_name == 'latent_heat_of_vaporization': + # For vaporization, heat is absorbed at boiling point + # Assume boiling happens after liquidus temperature + expanded_config = { + 'key': ['liquidus_temperature', 'liquidus_temperature+300'], + 'val': [0, latent_heat_value] + } + else: + raise ValueError(f"Unsupported latent heat property: {prop_name}") + # Process using the standard key-val method + self._process_key_val_property(alloy, prop_name, expanded_config, T) + except (ValueError, TypeError) as e: + error_msg = f"Failed to process {prop_name} constant \n -> {e}" + raise ValueError(error_msg) from e + @staticmethod def _process_constant_property(alloy: Alloy, prop_name: str, prop_config: Union[float, str]) -> None: """ @@ -719,10 +758,38 @@ class MaterialConfigParser: processed_key = [] for k in key_def: if isinstance(k, str): + # Handle base temperature references if k == 'solidus_temperature': processed_key.append(alloy.temperature_solidus) elif k == 'liquidus_temperature': processed_key.append(alloy.temperature_liquidus) + # Handle temperature expressions like 'liquidus_temperature+300' + elif '+' in k: + # Split the string into base and offset + base, offset = k.split('+') + offset_value = float(offset) + # Get the base temperature + if base == 'solidus_temperature': + base_value = alloy.temperature_solidus + elif base == 'liquidus_temperature': + base_value = alloy.temperature_liquidus + else: + base_value = float(base) + # Calculate the final temperature + processed_key.append(base_value + offset_value) + elif '-' in k: + # Split the string into base and offset + base, offset = k.split('-') + offset_value = -float(offset) + # Get the base temperature + if base == 'solidus_temperature': + base_value = alloy.temperature_solidus + elif base == 'liquidus_temperature': + base_value = alloy.temperature_liquidus + else: + base_value = float(base) + # Calculate the final temperature + processed_key.append(base_value + offset_value) else: processed_key.append(float(k)) else: diff --git a/src/pymatlib/data/alloys/SS304L/SS304L.yaml b/src/pymatlib/data/alloys/SS304L/SS304L.yaml index d417e8a9f1ee737c9397044923c3bc6876e0d23b..73d0c501da24efaf28e7f5b73bdf4dd07a67dc66 100644 --- a/src/pymatlib/data/alloys/SS304L/SS304L.yaml +++ b/src/pymatlib/data/alloys/SS304L/SS304L.yaml @@ -182,9 +182,14 @@ properties: # temp_col: T (K) # prop_col: Latent heat (J/Kg) #OR - latent_heat_of_fusion: - key: [solidus_temperature, liquidus_temperature] - val: [0, 171401] + latent_heat_of_fusion: 171401. + + + latent_heat_of_vaporization: 171401. + #OR + # latent_heat_of_vaporization: + # key: [liquidus_temperature, liquidus_temperature+300] + # val: [0, 171401] # heat_conductivity: