1#ifndef PHYTH_MATERIALS_HPP
2#define PHYTH_MATERIALS_HPP
7#include <unordered_map>
40 static std::unordered_map<std::string, MaterialData>
Parse(
const std::string &
filename) {
42 if (!
file.is_open()) {
43 throw std::runtime_error(
"Cannot open material file: " +
filename);
46 std::unordered_map<std::string, MaterialData>
result;
63 if (
end == std::string::npos) {
64 throw std::runtime_error(
"Invalid section header: " +
line);
83 if (
key ==
"youngs_modulus" ||
key ==
"E") {
85 }
else if (
key ==
"poisson_ratio" ||
key ==
"nu") {
106 const auto start =
str.find_first_not_of(
" \t\r\n");
107 if (
start == std::string::npos) {
111 const auto end =
str.find_last_not_of(
" \t\r\n");
128 return std::stod(
str);
129 }
catch (
const std::exception &) {
130 throw std::runtime_error(
"Invalid number format: " +
str);
165 throw std::runtime_error(
"Material not found: " + name);
184 std::vector<std::string>
names;
186 names.push_back(name);
250 std::unordered_map<std::string, IsotropicMaterial>
materials_;
Linear elastic isotropic material model.
Database for managing and retrieving material properties.
std::vector< std::string > ListMaterials() const
Get a list of all registered material names.
IsotropicMaterial Get(const std::string &name) const
Retrieve a material by its registered name.
void RegisterMaterial(const std::string &name, const IsotropicMaterial &material)
Register a new material in the database.
static MaterialDatabase FromINI(const std::string &path)
Create a MaterialDatabase from an INI configuration file.
std::unordered_map< std::string, IsotropicMaterial > materials_
Internal storage mapping names to materials.
Parser for material property files in INI format.
static double parseNumber(const std::string &str)
Parse a string as a double-precision floating point number.
Quantity< Pascal > youngs_modulus
Young's modulus E (Pa)
static std::unordered_map< std::string, MaterialData > Parse(const std::string &filename)
Parse an INI file and extract material definitions.
Scalar poisson_ratio
Poisson's ratio nu (dimensionless)
static void trim(std::string &str)
Remove leading and trailing whitespace characters.
Material property data structure.
Physical quantity with a value and a compile-time unit.