import os import sys import time import sqlite3 import numpy as np import pandas as pd import pyaedt.modeler.Primitives3D as p3d from pyaedt.modules import Mesh from pyaedt.maxwell import Maxwell, Maxwell3d, Maxwell2d def create_toroid_m2d(m2d, a, b, position=[0,0,0], num_sides=60, name='core', matname='ferrite'): ''' Create a Maxwell3D toroidal object. The corresponding dimensional variables A, B, C, and Rfillet are created in Ansys AEDT Inputs ----------- m3d: Maxwell3D object. a: outer diameter. b: inner diameter. c: height. r: fillet radius. position: center origen. By default the coordinate system is is taken [0,0,0] cs_axis: Axis along with to extrude the toroid name: name of the 3D object. Default is 'core'. matname: name of the material to be applied to the 3D object. By default 'ferrite' is applied. Returns ----------- Maxwell3D.modeler.primitive 3D object ''' m2d["A"] = str(a) + "mm" m2d["B"] = str(b) + "mm" core = m2d.modeler.primitives.create_circle(position=position, radius="A/2", num_sides=num_sides, is_covered=True, name=name, matname=matname) core_subtract = m2d.modeler.primitives.create_circle(position=position, radius="B/2", num_sides=num_sides, is_covered=True, name=name, matname=matname) m2d.modeler.subtract([core], [core_subtract], keepOriginals=False) return core t0 = time.time() # project_dir = "C:/Users/Abiezer.Tejeda/Documents/Ansoft/PyAEDT_Tutorials/" project_dir = os.getcwd() project_name = "M2D_AssignCurrent.aedt" design_name = "Assign_Current_Condition" solution = "MagnetostaticXY" # m3d = Maxwell3d(designname=design_name, NG=True, solution_type=solution) m2d = Maxwell2d(designname=design_name, NG=True, solution_type=solution) m2d.modeler.model_units = "mm" A = 39.88 B = 24.13 C = 14.48 R = 1.0 # Create some design variables m2d["I1"] = "10A" # coil current m2d["Wd"] = "4mm" # coil diameter m2d["C"] = f"{C}mm" # core height/depth m2d["num_sides"] = 60 # Create toroidal core and assign the default ferrite material core = create_toroid_m2d(m2d, A, B, name="Core", matname="ferrite") # Create coil coil = m2d.modeler.primitives.create_circle(position=[0,0,0], radius = "Wd/2", num_sides="num_sides", is_covered=True, name="Coil", matname="Copper") coil.color = (255, 128, 64) # print(f"coil name: {coil.name}") # print(coil.id) # print(f"coil type: {type(coil.id)}") # Assign current to the coil current_boundary = m2d.assign_current([coil], amplitude="I1", phase="0deg", solid=True, swap_direction=False, name="Current1") # m2d.modeler.oeditor.AssignCurrent(coil.name) # Create the air region for the solution space region = m2d.modeler.primitives.create_region([100,100,100,100,100,100]) # Assign a ballon boundary condition on all edges of the air region box m2d.assign_balloon(region.edges) # Create the solution setup properties props = { "PercentError":0.5, "MaximumPasses":25, "SolveMatrixAtLast":True, "PercentRefinement":50, "MinimumPasses":2, "MinimumConvergedPasses":1, "NonLinearResidual":1e-4, "SmoothBHCurve": True, "UseIterativeSolver":False } setup = m2d.create_setup(setupname="setup1", props=props) # Assign mesh operations msh = m2d.mesh core_mesh = msh.assign_length_mesh(names=["core"], isinside=True, maxlength=0.3, maxel=None, meshop_name="Mesh_Core_2D") m2d.save_project(os.path.join(project_dir,project_name)) m2d.close_desktop() t1 = time.time() print(f"Ellapsed Time: {t1-t0}")