Skip to content

Commit

Permalink
test #56 done
Browse files Browse the repository at this point in the history
  • Loading branch information
svandenb-dev committed Oct 22, 2024
1 parent edf790b commit e86f48b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 52 deletions.
73 changes: 37 additions & 36 deletions src/pyedb/grpc/edb_core/materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,42 +271,43 @@ def set_multipole_debye_model(self):
def set_djordjecvic_sarkar_model(self):
super(Material, self.__class__).dielectric_material_model.__set__(self, GrpcDjordjecvicSarkarModel.create())

# def to_dict(self):
# """Convert material into dictionary."""
# test = self.__dict__()
#
# res = {"name": self.name}
# res.update(self.model_dump())
# return res
#
# def update(self, input_dict: dict):
# if input_dict:
# # Update attributes
# for attribute in ATTRIBUTES:
# if attribute in input_dict:
# setattr(self, attribute, input_dict[attribute])
# if "loss_tangent" in input_dict: # pragma: no cover
# setattr(self, "loss_tangent", input_dict["loss_tangent"])
#
# # Update DS model
# # NOTE: Contrary to before we don't test 'dielectric_model_frequency' only
# if any(map(lambda attribute: input_dict.get(attribute, None) is not None, DC_ATTRIBUTES)):
# if not self.__dc_model:
# self.__dc_model = self.__edb_definition.DjordjecvicSarkarModel()
# for attribute in DC_ATTRIBUTES:
# if attribute in input_dict:
# if attribute == "dc_permittivity" and input_dict[attribute] is not None:
# self.__dc_model.SetUseDCRelativePermitivity(True)
# setattr(self, attribute, input_dict[attribute])
# self.__material_def.dielectric_material_model = self.__dc_model
# # Unset DS model if it is already assigned to the material in the database
# elif self.__dc_model:
# self.__material_def.dielectric_material_model = GrpcValue(None)
#
# def __load_all_properties(self):
# """Load all properties of the material."""
# for property in self.__properties.model_dump().keys():
# _ = getattr(self, property)
def to_dict(self):
"""Convert material into dictionary."""
test = self.__dict__()

res = {"name": self.name}
res.update(self.model_dump())
return res

def update(self, input_dict: dict):
if input_dict:
# Update attributes
for attribute in ATTRIBUTES:
if attribute in input_dict:
setattr(self, attribute, input_dict[attribute])
if "loss_tangent" in input_dict: # pragma: no cover
setattr(self, "loss_tangent", input_dict["loss_tangent"])

# Update DS model
# NOTE: Contrary to before we don't test 'dielectric_model_frequency' only
if any(map(lambda attribute: input_dict.get(attribute, None) is not None, DC_ATTRIBUTES)):
# DC model does not exists anymore in Grpc
if not self.__dc_model:
self.__dc_model = GrpcDjordjecvicSarkarModel.create()
for attribute in DC_ATTRIBUTES:
if attribute in input_dict:
if attribute == "dc_permittivity" and input_dict[attribute] is not None:
self.__dc_model.SetUseDCRelativePermitivity(True)
setattr(self, attribute, input_dict[attribute])
self.__material_def.dielectric_material_model = self.__dc_model
# Unset DS model if it is already assigned to the material in the database
elif self.__dc_model:
self.__material_def.dielectric_material_model = GrpcValue(None)

def __load_all_properties(self):
"""Load all properties of the material."""
for property in self.__properties.model_dump().keys():
_ = getattr(self, property)


class Materials(object):
Expand Down
18 changes: 9 additions & 9 deletions tests/grpc/system/test_edb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1135,15 +1135,15 @@ def test_create_padstack_instance(self, edb_examples):
def test_stackup_properties(self):
"""Evaluate stackup properties."""
# TODO check material init
# edb = Edb(edbversion=desktop_version, restart_rpc_server=True)
# edb.stackup.add_layer(layer_name="gnd", fillMaterial="air", thickness="10um")
# edb.stackup.add_layer(layer_name="diel1", fillMaterial="air", thickness="200um", base_layer="gnd")
# edb.stackup.add_layer(layer_name="sig1", fillMaterial="air", thickness="10um", base_layer="diel1")
# edb.stackup.add_layer(layer_name="diel2", fillMaterial="air", thickness="200um", base_layer="sig1")
# edb.stackup.add_layer(layer_name="sig3", fillMaterial="air", thickness="10um", base_layer="diel2")
# assert edb.stackup.thickness == 0.00043
# assert edb.stackup.num_layers == 5
# edb.close()
edb = Edb(edbversion=desktop_version, restart_rpc_server=True)
edb.stackup.add_layer(layer_name="gnd", fillMaterial="air", thickness="10um")
edb.stackup.add_layer(layer_name="diel1", fillMaterial="air", thickness="200um", base_layer="gnd")
edb.stackup.add_layer(layer_name="sig1", fillMaterial="air", thickness="10um", base_layer="diel1")
edb.stackup.add_layer(layer_name="diel2", fillMaterial="air", thickness="200um", base_layer="sig1")
edb.stackup.add_layer(layer_name="sig3", fillMaterial="air", thickness="10um", base_layer="diel2")
assert edb.stackup.thickness == 0.00043
assert edb.stackup.num_layers == 5
edb.close()
pass

def test_hfss_extent_info(self):
Expand Down
1 change: 1 addition & 0 deletions tests/grpc/system/test_edb_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def init(self, local_scratch):
pass

def test_find(self, edb_examples):
# Done
edbapp = edb_examples.get_si_verse()
assert edbapp.layout.find_primitive(layer_name="Inner5(PWR2)")
edbapp.close()
26 changes: 19 additions & 7 deletions tests/grpc/system/test_edb_materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,40 @@ def init(self, legacy_edb_app_without_material):
self.edbapp = legacy_edb_app_without_material
self.definition = self.edbapp.edb_api.definition

# Remove dummy material if it exist
material_def = self.definition.MaterialDef.FindByName(self.edbapp.active_db, MATERIAL_NAME)
if not material_def.IsNull():
material_def.Delete()
# Remove dummy material if it exists.
from ansys.edb.core.definition.material_def import (
MaterialDef as GrpcMaterialDef,
)

material_def = GrpcMaterialDef.find_by_name(self.edbapp.active_db, MATERIAL_NAME)
if not material_def.is_null:
material_def.delete()

def test_material_name(self):
"""Evaluate material properties."""
material_def = self.definition.MaterialDef.Create(self.edbapp.active_db, MATERIAL_NAME)
from ansys.edb.core.definition.material_def import (
MaterialDef as GrpcMaterialDef,
)

material_def = GrpcMaterialDef.create(self.edbapp.active_db, MATERIAL_NAME)
material = Material(self.edbapp, material_def)

assert MATERIAL_NAME == material.name

def test_material_properties(self):
"""Evaluate material properties."""
material_def = self.definition.MaterialDef.Create(self.edbapp.active_db, MATERIAL_NAME)
from ansys.edb.core.definition.material_def import (
MaterialDef as GrpcMaterialDef,
)

material_def = GrpcMaterialDef.create(self.edbapp.active_db, MATERIAL_NAME)
material = Material(self.edbapp, material_def)

for property in PROPERTIES:
for value in VALUES:
setattr(material, property, value)
assert float(value) == getattr(material, property)
assert 12 == material.loss_tangent
assert 12 == material.dielectric_loss_tangent

def test_material_dc_properties(self):
"""Evaluate material DC properties."""
Expand Down

0 comments on commit e86f48b

Please sign in to comment.