Skip to content

3DComponent creation refactoring. #894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions _unittest/test_08_Primitives3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

scdoc = "input.scdoc"
step = "input.stp"

component3d = "new.a3dcomp"

class TestClass(BasisTest):
def setup_class(self):
Expand All @@ -34,6 +34,7 @@ def setup_class(self):
scdoc_file = os.path.join(local_path, "example_models", scdoc)
self.local_scratch.copyfile(scdoc_file)
self.step_file = os.path.join(local_path, "example_models", step)
self.component3d_file = os.path.join(self.local_scratch.path, component3d)
test_98_project = os.path.join(local_path, "example_models", "assembly2" + ".aedt")
self.test_98_project = self.local_scratch.copyfile(test_98_project)
test_99_project = os.path.join(local_path, "example_models", "assembly" + ".aedt")
Expand Down Expand Up @@ -844,27 +845,34 @@ def test_63_import_step(self):
assert self.aedtapp.modeler.import_3d_cad(self.step_file)
assert len(self.aedtapp.modeler.object_names) == 1

def test_64_create_equationbased_curve(self):
def test_64_create_3dcomponent(self):
assert self.aedtapp.modeler.create_3dcomponent(self.component3d_file)
new_obj = self.aedtapp.modeler.duplicate_along_line("Solid", [100, 0, 0])
rad = self.aedtapp.assign_radiation_boundary_to_objects("Solid")
exc = self.aedtapp.create_wave_port_from_sheet(10)
assert self.aedtapp.modeler.create_3dcomponent(self.component3d_file, exclude_region=True,
object_list=["Solid", new_obj[1][0]], boundaries_list=[rad.name],
excitation_list=[exc.name], included_cs="Global")

def test_65_create_equationbased_curve(self):
self.aedtapp.insert_design("Equations")
eq_line = self.aedtapp.modeler.create_equationbased_curve(x_t="_t", y_t="_t*2", num_points=0)
assert len(eq_line.edges) == 1
eq_segmented = self.aedtapp.modeler.create_equationbased_curve(x_t="_t", y_t="_t*2", num_points=5)
assert len(eq_segmented.edges) == 4

eq_xsection = self.aedtapp.modeler.create_equationbased_curve(x_t="_t", y_t="_t*2", xsection_type="Circle")
assert eq_xsection.name in self.aedtapp.modeler.solid_names

def test_65_create_3dcomponent(self):
def test_66_insert_3dcomponent(self):
self.aedtapp.solution_type = "Modal"
self.aedtapp["l_dipole"] = "13.5cm"

compfile = self.aedtapp.components3d["Dipole_Antenna_DM"]
geometryparams = self.aedtapp.get_components3d_vars("Dipole_Antenna_DM")
geometryparams["dipole_length"] = "l_dipole"
name = self.aedtapp.modeler.insert_3d_component(compfile, geometryparams)
assert isinstance(name, str)

def test_65b_group_components(self):
def test_66b_group_components(self):
self.aedtapp["l_dipole"] = "13.5cm"

compfile = self.aedtapp.components3d["Dipole_Antenna_DM"]
Expand All @@ -874,7 +882,7 @@ def test_65b_group_components(self):
name2 = self.aedtapp.modeler.insert_3d_component(compfile, geometryparams)
assert self.aedtapp.modeler.create_group(components=[name, name2], group_name="test_group") == "test_group"

def test_66_assign_material(self):
def test_67_assign_material(self):
box1 = self.aedtapp.modeler.create_box([60, 60, 60], [4, 5, 5])
box2 = self.aedtapp.modeler.create_box([50, 50, 50], [2, 3, 4])
cyl1 = self.aedtapp.modeler.create_cylinder(cs_axis="X", position=[50, 0, 0], radius=1, height=20)
Expand All @@ -894,12 +902,12 @@ def test_66_assign_material(self):
assert self.aedtapp.modeler[cyl1].material_name == "aluminum"
assert self.aedtapp.modeler[cyl2].material_name == "aluminum"

def test_67_cover_lines(self):
def test_68_cover_lines(self):
P1 = self.aedtapp.modeler.create_polyline([[0, 1, 2], [0, 2, 3], [2, 1, 4]], close_surface=True)
assert self.aedtapp.modeler.cover_lines(P1)

@pyaedt_unittest_check_desktop_error
def test_68_create_torus(self):
def test_69_create_torus(self):
torus = self.create_copper_torus()
assert torus.id > 0
assert torus.name.startswith("MyTorus")
Expand All @@ -908,7 +916,7 @@ def test_68_create_torus(self):

@pytest.mark.skipif(is_ironpython, reason="pytest is not supported with IronPython.")
@pyaedt_unittest_check_desktop_error
def test_69_create_torus_exceptions(self):
def test_70_create_torus_exceptions(self):

with pytest.raises(ValueError) as excinfo:
self.aedtapp.modeler.create_torus(
Expand All @@ -935,7 +943,7 @@ def test_69_create_torus_exceptions(self):
# assert "Major radius must be greater than minor radius." in str(excinfo.value)

@pyaedt_unittest_check_desktop_error
def test_70_create_point(self):
def test_71_create_point(self):
name = "mypoint"
if self.aedtapp.modeler[name]:
self.aedtapp.modeler.delete(name)
Expand Down
40 changes: 35 additions & 5 deletions pyaedt/modeler/Model3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,17 @@ def primitives(self):
return self._primitives

@aedt_exception_handler
def create_3dcomponent(self, component_file, component_name=None, variables_to_include=[], exclude_region=False):
def create_3dcomponent(
self,
component_file,
component_name=None,
variables_to_include=[],
exclude_region=False,
object_list=None,
boundaries_list=None,
excitation_list=None,
included_cs=None,
):
"""Create a 3D component file.

Parameters
Expand All @@ -62,6 +72,14 @@ def create_3dcomponent(self, component_file, component_name=None, variables_to_i
List of variables to include. The default is ``[]``.
exclude_region : bool, optional
Whether to exclude the region. The default is ``False``.
object_list : list, optional
List of Objects names to export. The default is all objects
boundaries_list : list, optional
List of Boundaries names to export. The default is all boundaries
excitation_list : list, optional
List of Excitation names to export. The default is all excitations
included_cs : list, optional
List of Coordinate Systems to export. The default is all coordinate systems

Returns
-------
Expand Down Expand Up @@ -122,14 +140,20 @@ def create_3dcomponent(self, component_file, component_name=None, variables_to_i
"ComponentOutline:=",
"None",
]
objs = self.object_names
if object_list:
objs = object_list
else:
objs = self.object_names
for el in objs:
if "Region" in el and exclude_region:
objs.remove(el)
arg.append("IncludedParts:="), arg.append(objs)
arg.append("HiddenParts:="), arg.append([])
activecs = self.oeditor.GetActiveCoordinateSystem()
allcs = self.oeditor.GetCoordinateSystems()
if included_cs:
allcs = included_cs
else:
allcs = self.oeditor.GetCoordinateSystems()
arg.append("IncludedCS:="), arg.append(allcs)
arg.append("ReferenceCS:="), arg.append(activecs)
variables = variables_to_include
Expand All @@ -149,7 +173,10 @@ def create_3dcomponent(self, component_file, component_name=None, variables_to_i
arg.append("VendorComponentIdentifier:="), arg.append("")
arg.append("PublicKeyFile:="), arg.append("")
arg2 = ["NAME:DesignData"]
boundaries = self.get_boundaries_name()
if boundaries_list:
boundaries = boundaries_list
else:
boundaries = self.get_boundaries_name()
arg2.append("Boundaries:="), arg2.append(boundaries)
if self._app.design_type == "Icepak":
meshregions = [name for name in self._app.mesh.meshregions.name]
Expand All @@ -159,7 +186,10 @@ def create_3dcomponent(self, component_file, component_name=None, variables_to_i
pass
arg2.append("MeshRegions:="), arg2.append(meshregions)
else:
excitations = self._app.excitations
if excitation_list:
excitations = excitation_list
else:
excitations = self._app.excitations
arg2.append("Excitations:="), arg2.append(excitations)
meshops = [el.name for el in self._app.mesh.meshoperations]
arg2.append("MeshOperations:="), arg2.append(meshops)
Expand Down