sgio.read_materials_from_json#
- sgio.read_materials_from_json(file_path: str) dict[str, CauchyContinuumModel]#
Read multiple materials from a JSON file and return as a dictionary.
- Parameters:
file_path (str) – Path to the JSON file containing a list of material dictionaries
- Returns:
Dictionary with material names as keys and material model objects as values
- Return type:
dict[str, CauchyContinuumModel]
- Raises:
FileNotFoundError – If the specified file does not exist
ValueError – If the JSON is invalid, if any material has no name, or if duplicate material names are found
TypeError – If the JSON content is not a list
Examples
>>> # JSON file: [{"name": "Steel", "isotropy": 0, "e": 200e9, "nu": 0.3}, >>> # {"name": "Aluminum", "isotropy": 0, "e": 70e9, "nu": 0.33}] >>> materials = read_materials_from_json("materials.json") >>> len(materials) 2 >>> materials['Steel'].e1 200000000000.0 >>> materials['Aluminum'].e1 70000000000.0
Notes
This function now returns a dictionary to align with the name-based material storage architecture. Each material’s name field is used as the dictionary key. Duplicate names will raise a ValueError.