From 6f2999456b46da883509f9e8e6c497e87ab1c14c Mon Sep 17 00:00:00 2001 From: Samuel Lopez <85613111+Samuelopez-ansys@users.noreply.github.com> Date: Tue, 13 Aug 2024 10:38:57 +0200 Subject: [PATCH] FEAT: Create equationbased surface (#5038) Co-authored-by: ricrag Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- _unittest/test_08_Primitives3D.py | 7 +++ pyaedt/modeler/cad/Primitives3D.py | 86 ++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) diff --git a/_unittest/test_08_Primitives3D.py b/_unittest/test_08_Primitives3D.py index 1fa0bf436e3..71b4f43b928 100644 --- a/_unittest/test_08_Primitives3D.py +++ b/_unittest/test_08_Primitives3D.py @@ -2017,3 +2017,10 @@ def test_93_import_discovery(self): assert self.aedtapp.modeler.import_discovery_model(self.discovery_file) assert self.aedtapp.modeler.objects assert self.aedtapp.modeler.solid_bodies + + def test_94_create_equationbased_surface(self): + self.aedtapp.insert_design("Equations_surf") + surf = self.aedtapp.modeler.create_equationbased_surface( + x_uv="(sin(_v*2*pi)^2+1.2)*cos(_u*2*pi)", y_uv="(sin(_v*2*pi)^2+1.2)*sin(_u*2*pi)", z_uv="_v*2" + ) + assert surf.name in self.aedtapp.modeler.sheet_names diff --git a/pyaedt/modeler/cad/Primitives3D.py b/pyaedt/modeler/cad/Primitives3D.py index 59378eddad0..5e3ba8b39cc 100644 --- a/pyaedt/modeler/cad/Primitives3D.py +++ b/pyaedt/modeler/cad/Primitives3D.py @@ -1078,6 +1078,92 @@ def create_equationbased_curve(self, x_t=0, y_t=0, z_t=0, t_start=0, t_end=1, nu new_name = self.oeditor.CreateEquationCurve(vArg1, vArg2) return self._create_object(new_name, **kwargs) + # fmt: off + @pyaedt_function_handler() + def create_equationbased_surface(self, x_uv=0, y_uv=0, z_uv=0, u_start=0, u_end=1, v_start=0, v_end=1, + name=None, **kwargs): # fmt: on + """Create an equation-based surface. + + Parameters + ---------- + x_uv : str or float + Expression for the X-component of the surface as a function of ``"_u,_v"``. + For example, ``"cos(_u) * sin(_v)"``. + y_uv : str or float + Expression for the Y-component of the surface as a function of ``"_u,_v"`` + z_uv : str or float + Expression for the Z-component of the surface as a function of ``"_u,_v"`` + u_start : str or float + Starting value of the parameter ``"_u"``. + u_end : str or float + Ending value of the parameter ``"_u"``. + v_start : str or float + Starting value of the parameter ``"_v"``. + v_end : str or float + Ending value of the parameter ``"_v"``. + name : str, optional + Name of the created surface in the 3D modeler. The default is ``None``, + in which case the default name is assigned. + **kwargs : optional + Additional keyword arguments may be passed when creating the primitive to set properties. See + ``pyaedt.modeler.cad.object3d.Object3d`` for more details. + + Returns + ------- + :class:`pyaedt.modeler.cad.object3d.Object3d` + 3D object. + + References + ---------- + + >>> oEditor.CreateEquationSurface + + Examples + -------- + + The optional parameter ``matname`` allows you to set the material name. + The optional parameter ``name`` allows you to assign a name to the surface. + + This method applies to all 3D applications: HFSS, Q3D, Icepak, Maxwell 3D, + and Mechanical. + + >>> from pyaedt import Hfss + >>> aedtapp = Hfss() + >>> surf = aedtapp.modeler.create_equationbased_surface(x_uv='(cos(_v)+2)*cos(_u)', + ... y_uv='(cos(_v)+2)*sin(_u)', + ... z_uv='sin(_v)', + ... u_start=0, + ... u_end='2*pi', + ... v_start=0, + ... v_end='2*pi' + ... ) + """ + + vArg1 = [ + "NAME:EquationBasedSurfaceParameters", + "XuvFunction:=", + str(x_uv), + "YuvFunction:=", + str(y_uv), + "ZuvFunction:=", + str(z_uv), + "uStart:=", + str(u_start), + "uEnd:=", + str(u_end), + "vStart:=", + str(v_start), + "vEnd:=", + str(v_end), + "Version:=", + 1, + ] + + vArg2 = self._default_object_attributes(name) + + new_name = self.oeditor.CreateEquationSurface(vArg1, vArg2) + return self._create_object(new_name, **kwargs) + # fmt: off @pyaedt_function_handler(polyline_name="assignment", position="origin", num_thread="turns") def create_helix(self, assignment, origin, x_start_dir, y_start_dir, z_start_dir, turns=1,