From 93e7f5c6cdd7c177d8dce94366996671615fc633 Mon Sep 17 00:00:00 2001 From: Sebastien Morais Date: Sat, 28 Oct 2023 18:26:48 +0200 Subject: [PATCH] REFACT: allow to read amat files out of syslib --- _unittest/test_00_EDB.py | 5 +++-- pyaedt/edb_core/materials.py | 23 +++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/_unittest/test_00_EDB.py b/_unittest/test_00_EDB.py index 3973b7eb094..05219ea7c8d 100644 --- a/_unittest/test_00_EDB.py +++ b/_unittest/test_00_EDB.py @@ -3013,9 +3013,10 @@ def test_149_materials_read_materials(self, mock_file_open, mock_materials_prope mats = materials.read_materials("some path") assert mats == expected_res - def test_150_material_load_syslib_amat(self): + def test_150_material_load_amat(self): """Load material from an AMAT file.""" - assert self.edbapp.materials.load_syslib_amat() + mat_file = os.path.join(self.edbapp.base_path, "syslib", "Materials.amat") + assert self.edbapp.materials.load_amat(mat_file) material_list = list(self.edbapp.materials.materials.keys()) assert material_list assert len(material_list) > 0 diff --git a/pyaedt/edb_core/materials.py b/pyaedt/edb_core/materials.py index 60c183995a7..9e65929a6c9 100644 --- a/pyaedt/edb_core/materials.py +++ b/pyaedt/edb_core/materials.py @@ -861,22 +861,21 @@ def add_material_from_aedt(self, material_name): return True @pyaedt_function_handler() - def load_syslib_amat(self, filename="Materials.amat"): - """Load materials from an AMAT file located in the project system library. + def load_amat(self, amat_file): + """Load materials from an AMAT file. Parameters ---------- - filename : str - Name of the AMAT file. + amat_file : str + Full path to the amat file to read and add to the Edb. Returns ------- bool """ - mat_file = os.path.join(self._syslib, filename) - if not os.path.exists(mat_file): - self._pedb.logger.error("File path {} does not exist.".format(mat_file)) - material_dict = self.read_materials(mat_file) + if not os.path.exists(amat_file): + self._pedb.logger.error("File path {} does not exist.".format(amat_file)) + material_dict = self.read_materials(amat_file) for material_name, material in material_dict.items(): if not material_name in list(self.materials.keys()): new_material = self.add_material(name=material_name) @@ -897,13 +896,13 @@ def load_syslib_amat(self, filename="Materials.amat"): @staticmethod @pyaedt_function_handler() - def read_materials(mat_file): + def read_materials(amat_file): """Read materials from an AMAT file. Parameters ---------- - filename : str - Name of the AMAT file. + amat_file : str + Full path to the amat file to read. Returns ------- @@ -941,7 +940,7 @@ def get_line_float_value(line): "mass_density", ] - with open(mat_file, "r") as amat_fh: + with open(amat_file, "r") as amat_fh: raw_lines = amat_fh.read().splitlines() mat_found = "" for line in raw_lines: