Skip to content

Commit

Permalink
Merge branch 'main' into release/0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuelopez-ansys committed Nov 12, 2024
2 parents 65bf696 + 48f4e87 commit e2ec823
Show file tree
Hide file tree
Showing 14 changed files with 306 additions and 76 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
name: codecov-unit-tests
file: ./coverage.xml
flags: unit
flags: linux_unit

- name: Upload pytest test results
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -158,7 +158,7 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
name: codecov-system-solvers-tests-windows
file: ./coverage.xml
flags: system,solvers,windows
flags: windows_system_solvers

- name: Upload pytest test results
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -214,7 +214,7 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
name: codecov-system-solvers-tests-linux
file: ./coverage.xml
flags: system,solvers,linux
flags: linux_system_solvers

- name: Upload pytest test results
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -278,7 +278,7 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
name: codecov-system-general-tests-windows
file: ./coverage.xml
flags: system,general,windows
flags: windows_system_general

- name: Upload pytest test results
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -346,7 +346,7 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
name: codecov-system-general-tests
file: ./coverage.xml
flags: system,general,linux
flags: linux_system_general

- name: Upload pytest test results
uses: actions/upload-artifact@v4
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ tests = [
"pyvista[io]>=0.38.0,<0.45",
# Never directly imported but required when loading ML related file see #4713
"scikit-learn>=1.0.0,<1.6",
"scikit-rf>=0.30.0,<1.4",
"scikit-rf>=0.30.0,<1.5",
"SRTM.py",
"utm",
]
Expand Down Expand Up @@ -100,7 +100,7 @@ all = [
"fast-simplification>=0.1.7",
# Never directly imported but required when loading ML related file see #4713
"scikit-learn>=1.0.0,<1.6",
"scikit-rf>=0.30.0,<1.4",
"scikit-rf>=0.30.0,<1.5",
"SRTM.py",
"utm",
]
Expand All @@ -113,7 +113,7 @@ installer = [
"pyvista[io]>=0.38.0,<0.45",
# Never directly imported but required when loading ML related file see #4713
"scikit-learn>=1.0.0,<1.6",
"scikit-rf>=0.30.0,<1.4",
"scikit-rf>=0.30.0,<1.5",
"SRTM.py",
"utm",
"jupyterlab>=3.6.0,<4.4",
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/aedt/core/application/analysis_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ def assignmaterial_from_sherlock_files(self, component_file, material_file):
list_mat_obj += [rd for rd, md in zip(component_data["Ref Des"], component_data["Material"]) if md == mat]
list_mat_obj = [mo for mo in list_mat_obj if mo in all_objs]
if list_mat_obj:
newmat = self.materials.checkifmaterialexists(mat)
newmat = self.materials.exists_material(mat)
if not newmat:
newmat = self.materials.add_material(mat.lower())
if "Material Density" in material_data:
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/aedt/core/generic/configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ def import_config(self, config_file, *args):
if self.options.import_materials and dict_in.get("materials", None):
self.results.import_materials = True
for el, val in dict_in["materials"].items():
if self._app.materials.checkifmaterialexists(el):
if self._app.materials.exists_material(el):
newname = generate_unique_name(el)
self._app.logger.warning("Material %s already exists. Renaming to %s", el, newname)
else:
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/aedt/core/modeler/advanced_cad/stackup_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def __init__(self, application, material_name, cloned_material_name, list_of_pro
self._magnetic_loss_tangent = None
self._material = None
self._material_name = None
if application.materials.checkifmaterialexists(material_name):
if application.materials.exists_material(material_name):
if not list_of_properties:
cloned_material = application.materials.duplicate_material(material_name, cloned_material_name)
permittivity = cloned_material.permittivity.value
Expand Down
3 changes: 1 addition & 2 deletions src/ansys/aedt/core/modeler/cad/object_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ def material_name(self):

@material_name.setter
def material_name(self, mat):
matobj = self._primitives._materials.checkifmaterialexists(mat)
matobj = self._primitives._materials.exists_material(mat)
mat_value = None
if matobj:
mat_value = chr(34) + matobj.name + chr(34)
Expand Down Expand Up @@ -1267,7 +1267,6 @@ def part_coordinate_system(self, sCS):
pcs = ["NAME:Orientation", "Value:=", sCS]
self._change_property(pcs)
self._part_coordinate_system = sCS
return True

@property
def solve_inside(self):
Expand Down
77 changes: 77 additions & 0 deletions src/ansys/aedt/core/modeler/cad/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from ansys.aedt.core.generic.data_handlers import json_to_dict
from ansys.aedt.core.generic.general_methods import _dim_arg
from ansys.aedt.core.generic.general_methods import _uname
from ansys.aedt.core.generic.general_methods import clamp
from ansys.aedt.core.generic.general_methods import generate_unique_name
from ansys.aedt.core.generic.general_methods import is_linux
from ansys.aedt.core.generic.general_methods import is_number
Expand Down Expand Up @@ -6280,6 +6281,82 @@ def update_object(self, assignment):
o = self._create_object(name)
return o

@pyaedt_function_handler()
def update_geometry_property(self, assignment, name=None, value=None):
"""Update property of assigned geometry objects.
Parameters
----------
assignment : str, or list
Object name or list of object names to be updated.
name : str, optional
Property name to change. The default is ``None``, in which case no property is updated.
Available options are: ``"display_wireframe"``, `"material"``, and `"solve_inside"``.
value : bool or str, optional
Property value. The default is ``None`` in which case
no value is assigned.
Returns
-------
bool
``True`` when successful, ``False`` when failed.
"""
assignment = self.convert_to_selections(assignment, True)

# Define property mapping
property_mapping = {
"display_wireframe": {"property_name": "Display Wireframe", "reset_attr": ["_wireframe"]},
"material_name": {"property_name": "Material", "reset_attr": ["_material_name", "_model", "_solve_inside"]},
"solve_inside": {"property_name": "Solve Inside", "reset_attr": ["_solve_inside"]},
"color": {"property_name": "Color", "reset_attr": ["_color"]},
"transparency": {"property_name": "Transparent", "reset_attr": ["_transparency"]},
"part_coordinate_system": {"property_name": "Orientation", "reset_attr": ["_part_coordinate_system"]},
}

# Check if property name is valid
property_key = name.lower()
if property_key not in property_mapping:
self.logger.error("Invalid property name.")
return False

# Retrieve property settings
property_name = property_mapping[property_key]["property_name"]
reset_attr = property_mapping[property_key]["reset_attr"]

# Handle special cases for material
if property_key == "material_name" and isinstance(value, str):
matobj = self._materials.exists_material(value)
if matobj:
value = f'"{matobj.name}"'
elif "[" in value or "(" in value: # pragma: no cover
value = value
else:
self.logger.error("Invalid material value.")
return False

value_command = ["Value:=", value]
if property_key == "color":
if isinstance(value, tuple) or isinstance(value, list):
R = clamp(value[0], 0, 255)
G = clamp(value[1], 0, 255)
B = clamp(value[2], 0, 255)
value_command = ["R:=", str(R), "G:=", str(G), "B:=", str(B)]
else:
self.logger.error("Invalid color.")
return False

# Reset property values
for obj_name in assignment:
obj = self.objects_by_name[obj_name]
for attr in reset_attr:
setattr(obj, attr, None)

props = [f"NAME:{property_name}"]
props.extend(value_command)

return self._change_geometry_property(props, assignment)

@pyaedt_function_handler()
def value_in_object_units(self, value):
"""Convert one or more strings for numerical lengths to floating point values.
Expand Down
4 changes: 2 additions & 2 deletions src/ansys/aedt/core/modeler/cad/primitives_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -3086,7 +3086,7 @@ def check_choke_values(self, input_dir, create_another_file=True):
try:
core_material = str(values["Core"]["Material"])
if len(core_material) > 0:
if self.materials.checkifmaterialexists(core_material):
if self.materials.exists_material(core_material):
values["Core"]["Material"] = self.materials._get_aedt_case_name(core_material)
else:
self.logger.error(
Expand All @@ -3109,7 +3109,7 @@ def check_choke_values(self, input_dir, create_another_file=True):
try:
winding_material = str(values["Outer Winding"]["Material"])
if len(winding_material) > 0:
if self.materials.checkifmaterialexists(winding_material):
if self.materials.exists_material(winding_material):
values["Outer Winding"]["Material"] = self.materials._get_aedt_case_name(winding_material)
else:
self.logger.error(
Expand Down
73 changes: 68 additions & 5 deletions src/ansys/aedt/core/modeler/circuits/primitives_nexxim.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ def create_voltage_probe(self, name=None, location=None, angle=0, use_instance_i
Parameters
----------
name :
name : str, optional
Name of the voltage probe. The default is ``None``.
location : list of float, optional
Position on the X axis and Y axis. The default is ``None``.
Expand All @@ -830,24 +830,87 @@ def create_voltage_probe(self, name=None, location=None, angle=0, use_instance_i
References
----------
>>> oEditor.CreateComponent
Examples
--------
>>> from ansys.aedt.core import Circuit
>>> cir = Circuit()
>>> cir.modeler.components.create_voltage_probe(name="probe")
>>> cir.release_desktop(False, False)
"""
return self.__create_probe(
name=name,
probe_type="voltage",
location=location,
angle=angle,
use_instance_id_netlist=use_instance_id_netlist,
)

@pyaedt_function_handler()
def create_current_probe(self, name=None, location=None, angle=0, use_instance_id_netlist=False):
"""Create a current probe.
Parameters
----------
name : str, optional
Name of the current probe. The default is ``None``.
location : list of float, optional
Position on the X axis and Y axis. The default is ``None``.
angle : float, optional
Angle rotation in degrees. The default is ``0``.
use_instance_id_netlist : bool, optional
Whether to use the instance ID in the net list.
The default is ``False``.
Returns
-------
:class:`ansys.aedt.core.modeler.cad.object_3dcircuit.CircuitComponent`
Circuit Component Object.
References
----------
>>> oEditor.CreateComponent
Examples
--------
>>> from ansys.aedt.core import Circuit
>>> cir = Circuit()
>>> cir.modeler.components.create_current_probe(name="probe")
>>> cir.release_desktop(False, False)
"""
return self.__create_probe(
name=name,
probe_type="current",
location=location,
angle=angle,
use_instance_id_netlist=use_instance_id_netlist,
)

def __create_probe(self, name=None, probe_type="voltage", location=None, angle=0.0, use_instance_id_netlist=False):
if probe_type == "voltage":
component_name = "VPROBE"
elif probe_type == "current":
component_name = "IPROBE"
else: # pragma: no cover
self.logger.error("Wrong probe type assigned.")
return False

if location is None:
location = []
else:
location = [location[0] + 0.2 * 24.4 / 1000, location[1] + 0.2 * 24.4 / 1000]

cmpid = self.create_component(
None,
name,
component_library="Probes",
component_name="VPROBE",
component_name=component_name,
location=location,
angle=angle,
use_instance_id_netlist=use_instance_id_netlist,
)

cmpid.set_property("Name", name)
if name:
cmpid.set_property("InstanceName", name)
return cmpid

@pyaedt_function_handler(compname="name")
Expand Down
35 changes: 32 additions & 3 deletions src/ansys/aedt/core/modules/material_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __iter__(self):
return iter(self.material_keys.values()) if sys.version_info.major > 2 else self.material_keys.itervalues()

def __getitem__(self, item):
matobj = self.checkifmaterialexists(item)
matobj = self.exists_material(item)
if matobj:
return matobj
elif item in list(self.surface_material_keys.keys()):
Expand Down Expand Up @@ -243,6 +243,35 @@ def _get_surface_materials(self):
def checkifmaterialexists(self, material):
"""Check if a material exists in AEDT or PyAEDT Definitions.
.. deprecated:: 0.11.4
Use :func:`exists_material` method instead.
Parameters
----------
material : str
Name of the material. If the material exists and is not in the materials database,
it is added to this database.
Returns
-------
:class:`ansys.aedt.core.modules.material.Material`
Material object if present, ``False`` when failed.
References
----------
>>> oDefinitionManager.GetProjectMaterialNames
>>> oMaterialManager.GetData
"""
warnings.warn(
"`checkifmaterialexists` is deprecated. Use `exists_material` method instead.", DeprecationWarning
)
return self.exists_material(material=material)

@pyaedt_function_handler()
def exists_material(self, material):
"""Check if a material exists in AEDT or PyAEDT Definitions.
Parameters
----------
material : str
Expand Down Expand Up @@ -293,7 +322,7 @@ def check_thermal_modifier(self, material):
``True`` when successful, ``False`` when failed.
"""
omat = self.checkifmaterialexists(material)
omat = self.exists_material(material)
if omat:
for el in MatProperties.aedtname:
if omat.__dict__["_" + el].thermalmodifier:
Expand Down Expand Up @@ -451,7 +480,7 @@ def add_material_sweep(self, assignment, name):
"""
matsweep = []
for mat in assignment:
matobj = self.checkifmaterialexists(mat)
matobj = self.exists_material(mat)
if matobj:
matsweep.append(matobj)

Expand Down
Loading

0 comments on commit e2ec823

Please sign in to comment.