Skip to content

Commit

Permalink
Merge pull request #3805 from ansys/refact/edb_load_amat
Browse files Browse the repository at this point in the history
Refact edb load amat
  • Loading branch information
SMoraisAnsys authored Nov 4, 2023
2 parents 59f3781 + b48ae86 commit 876744c
Show file tree
Hide file tree
Showing 7 changed files with 361 additions and 123 deletions.
123 changes: 123 additions & 0 deletions _unittest/example_models/syslib/Materials.amat
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
$begin '$base_index$'
$begin 'properties'
all_levels=000000000000
time(year=000000002021, month=000000000009, day=000000000001, hour=000000000015, min=000000000032, sec=000000000052)
version=000000000000
$end 'properties'
$begin '$base_index$'
$index$(pos=000000318773, lin=000000011311, lvl=000000000000)
$end '$base_index$'
$end '$base_index$'
$begin 'FC-78'
$begin 'MaterialDef'
$begin 'FC-78'
CoordinateSystemType='Cartesian'
BulkOrSurfaceType=1
$begin 'PhysicsTypes'
set('Thermal')
$end 'PhysicsTypes'
$begin 'AttachedData'
$begin 'MatAppearanceData'
property_data='appearance_data'
Red=0
Green=128
Blue=255
Transparency=0.8
$end 'MatAppearanceData'
$end 'AttachedData'
thermal_conductivity='0.062'
mass_density='1700'
specific_heat='1050'
thermal_expansion_coeffcient='0.0016'
$begin 'thermal_material_type'
property_type='ChoiceProperty'
Choice='Fluid'
$end 'thermal_material_type'
$begin 'clarity_type'
property_type='ChoiceProperty'
Choice='Transparent'
$end 'clarity_type'
molecular_mass='0.001'
viscosity='0.000462'
ModTime=1592011950
$end 'FC-78'
$end 'MaterialDef'
$end 'FC-78'
$begin 'Polyflon CuFlon (tm)'
$begin 'AttachedData'
$begin 'MatAppearanceData'
property_data='appearance_data'
Red=230
Green=225
Blue=220
$end 'MatAppearanceData'
$end 'AttachedData'
simple('permittivity', 2.1)
simple('dielectric_loss_tangent', 0.00045)
ModTime=1499970477
$end 'Polyflon CuFlon (tm)'
$begin 'Water(@360K)'
$begin 'MaterialDef'
$begin 'Water(@360K)'
CoordinateSystemType='Cartesian'
BulkOrSurfaceType=1
$begin 'PhysicsTypes'
set('Thermal')
$end 'PhysicsTypes'
$begin 'AttachedData'
$begin 'MatAppearanceData'
property_data='appearance_data'
Red=0
Green=128
Blue=255
Transparency=0.8
$end 'MatAppearanceData'
$end 'AttachedData'
thermal_conductivity='0.6743'
mass_density='967.4'
specific_heat='4206'
thermal_expansion_coeffcient='0.0006979'
$begin 'thermal_material_type'
property_type='ChoiceProperty'
Choice='Fluid'
$end 'thermal_material_type'
$begin 'clarity_type'
property_type='ChoiceProperty'
Choice='Transparent'
$end 'clarity_type'
material_refractive_index='1.333'
diffusivity='1.657e-007'
molecular_mass='0.018015'
viscosity='0.000324'
ModTime=1592011950
$end 'Water(@360K)'
$end 'MaterialDef'
$end 'Water(@360K)'
$begin 'steel_stainless'
$begin 'AttachedData'
$begin 'MatAppearanceData'
property_data='appearance_data'
Red=176
Green=154
Blue=176
$end 'MatAppearanceData'
$end 'AttachedData'
simple('conductivity', 1100000)
simple('thermal_conductivity', 13.8)
simple('mass_density', 8055)
simple('specific_heat', 480)
simple('youngs_modulus', 195000000000)
simple('poissons_ratio', 0.3)
simple('thermal_expansion_coeffcient', 1.08e-005)
ModTime=1499970477
$end 'steel_stainless'
$begin '$index$'
$begin '$index$'
steel_stainless(pos=1224, lin=48, lvl=0)
'Polyflon CuFlon (tm)'(pos=22164, lin=814, lvl=0)
'FC-78'(pos=126130, lin=4842, lvl=0)
'Water(@360K)'(pos=118115, lin=4556, lvl=0)
$base_index$(pos=0, lin=1, lvl=0)
$index$(pos=318773, lin=11311, lvl=0)
$end '$index$'
$end '$index$'
114 changes: 108 additions & 6 deletions _unittest/test_00_EDB.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import builtins
import json
import os

# Setup paths for module imports
# Import required modules
import sys
from unittest.mock import mock_open

from mock import MagicMock
from mock import PropertyMock
from mock import patch
import pytest

from pyaedt import Edb
from pyaedt.edb_core.components import resistor_value_parser
from pyaedt.edb_core.edb_data.edbvalue import EdbValue
from pyaedt.edb_core.edb_data.simulation_configuration import SimulationConfiguration
from pyaedt.edb_core.edb_data.sources import Source
from pyaedt.edb_core.materials import Materials
from pyaedt.generic.constants import RadiationBoxType
from pyaedt.generic.general_methods import check_numeric_equivalence

Expand All @@ -33,6 +39,59 @@

test_subfolder = "TEDB"

MATERIALS = """
$begin 'Polyflon CuFlon (tm)'
$begin 'AttachedData'
$begin 'MatAppearanceData'
property_data='appearance_data'
Red=230
Green=225
Blue=220
$end 'MatAppearanceData'
$end 'AttachedData'
simple('permittivity', 2.1)
simple('dielectric_loss_tangent', 0.00045)
ModTime=1499970477
$end 'Polyflon CuFlon (tm)'
$begin 'Water(@360K)'
$begin 'MaterialDef'
$begin 'Water(@360K)'
CoordinateSystemType='Cartesian'
BulkOrSurfaceType=1
$begin 'PhysicsTypes'
set('Thermal')
$end 'PhysicsTypes'
$begin 'AttachedData'
$begin 'MatAppearanceData'
property_data='appearance_data'
Red=0
Green=128
Blue=255
Transparency=0.8
$end 'MatAppearanceData'
$end 'AttachedData'
thermal_conductivity='0.6743'
mass_density='967.4'
specific_heat='4206'
thermal_expansion_coeffcient='0.0006979'
$begin 'thermal_material_type'
property_type='ChoiceProperty'
Choice='Fluid'
$end 'thermal_material_type'
$begin 'clarity_type'
property_type='ChoiceProperty'
Choice='Transparent'
$end 'clarity_type'
material_refractive_index='1.333'
diffusivity='1.657e-007'
molecular_mass='0.018015'
viscosity='0.000324'
ModTime=1592011950
$end 'Water(@360K)'
$end 'MaterialDef'
$end 'Water(@360K)'
"""


@pytest.fixture(scope="class")
def edbapp(add_edb):
Expand Down Expand Up @@ -2954,14 +3013,57 @@ def test_147_find_dc_shorts(self):
assert len(edbapp.nets["DDR4_DM3"].find_dc_short()) == 0
edbapp.close()

def test_148_load_amat(self):
assert "Rogers RO3003 (tm)" in self.edbapp.materials.materials_in_aedt
material_file = os.path.join(self.edbapp.materials.syslib, "Materials.amat")
assert self.edbapp.materials.add_material_from_aedt("Arnold_Magnetics_N28AH_-40C")
assert "Arnold_Magnetics_N28AH_-40C" in self.edbapp.materials.materials.keys()
assert self.edbapp.materials.load_amat(material_file)
@patch("pyaedt.edb_core.materials.Materials.materials", new_callable=PropertyMock)
@patch.object(builtins, "open", new_callable=mock_open, read_data=MATERIALS)
def test_149_materials_read_materials(self, mock_file_open, mock_materials_property):
"""Read materials from an AMAT file."""
mock_materials_property.return_value = ["copper"]
materials = Materials(MagicMock())
expected_res = {
"Polyflon CuFlon (tm)": {"permittivity": 2.1, "tangent_delta": 0.00045},
"Water(@360K)": {
"thermal_conductivity": 0.6743,
"mass_density": 967.4,
"specific_heat": 4206,
"thermal_expansion_coeffcient": 0.0006979,
},
}
mats = materials.read_materials("some path")
assert mats == expected_res

def test_150_material_load_amat(self):
"""Load material from an AMAT file."""
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
assert self.edbapp.materials.materials["Rogers RO3003 (tm)"].loss_tangent == 0.0013
assert self.edbapp.materials.materials["Rogers RO3003 (tm)"].permittivity == 3.0

def test_151_materials_read_materials(self):
"""Read materials."""
path = os.path.join(local_path, "example_models", "syslib", "Materials.amat")
mats = self.edbapp.materials.read_materials(path)
key = "FC-78"
assert key in mats
assert mats[key]["thermal_conductivity"] == 0.062
assert mats[key]["mass_density"] == 1700
assert mats[key]["specific_heat"] == 1050
assert mats[key]["thermal_expansion_coeffcient"] == 0.0016
key = "Polyflon CuFlon (tm)"
assert key in mats
assert mats[key]["permittivity"] == 2.1
assert mats[key]["tangent_delta"] == 0.00045
key = "Water(@360K)"
assert key in mats
assert mats[key]["thermal_conductivity"] == 0.6743
assert mats[key]["mass_density"] == 967.4
assert mats[key]["specific_heat"] == 4206
assert mats[key]["thermal_expansion_coeffcient"] == 0.0006979
key = "steel_stainless"
assert mats[key]["conductivity"] == 1100000
assert mats[key]["thermal_conductivity"] == 13.8
assert mats[key]["mass_density"] == 8055
assert mats[key]["specific_heat"] == 480
assert mats[key]["thermal_expansion_coeffcient"] == 1.08e-005
11 changes: 6 additions & 5 deletions doc/source/Getting_started/Troubleshooting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,12 @@ Failure connecting to the gRPC server
On Linux, PyAEDT may fail to initialize a new instance of the gRPC server
or connect to an existing server session.
This may be due to:
- Firewall
- Proxy
- Permissions
- License
- Scheduler (for example if the gRPC server was started from LSF or Slurm)

- Firewall
- Proxy
- Permissions
- License
- Scheduler (for example if the gRPC server was started from LSF or Slurm)

For issues related to use of a proxy server, you may set the following environment variable to
disable the proxy server for the *localhost*.
Expand Down
1 change: 1 addition & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ def setup(app):
# specify the location of your github repo
html_theme_options = {
"github_url": "https://github.com/ansys/pyaedt",
"navigation_with_keys": False,
"show_prev_next": False,
"show_breadcrumbs": True,
"collapse_navigation": True,
Expand Down
Loading

0 comments on commit 876744c

Please sign in to comment.