Skip to content

Commit

Permalink
REFACT: allow to read amat files out of syslib
Browse files Browse the repository at this point in the history
  • Loading branch information
SMoraisAnsys committed Oct 28, 2023
1 parent 235beb4 commit 93e7f5c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
5 changes: 3 additions & 2 deletions _unittest/test_00_EDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 11 additions & 12 deletions pyaedt/edb_core/materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
-------
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 93e7f5c

Please sign in to comment.