def addNodeZ(n, group=-1): if group == -1: group = femmgroupmode femm.mi_addnode(n.real, n.imag) femm.mi_selectnode(n.real, n.imag) femm.mi_setgroup(group) femm.mi_clearselected()
def set_group(self, groupID): #select circle slightly larger than the rotor select_oversize = 0.001 #mm fe.mi_selectcircle(0, 0, self.OR + select_oversize, 4) fe.mi_setgroup(groupID) fe.mi_clearselected()
def addNode(r, phi, group=-1): if group == -1: group = femmgroupmode n = cmath.rect(r, rad(phi)) femm.mi_addnode(n.real, n.imag) femm.mi_selectnode(n.real, n.imag) femm.mi_setgroup(group) femm.mi_clearselected()
def addLineZZ(n1, n2, group=-1): if group == -1: group = femmgroupmode femm.mi_addsegment(n1.real, n1.imag, n2.real, n2.imag) # select middle of arc for adding group n = (n1.real + n2.real) / 2 + ((n1.imag + n2.imag) / 2) * 1j femm.mi_selectsegment(n.real, n.imag) femm.mi_setgroup(group) femm.mi_clearselected()
def addBlockLabel(r, phi, group=-1): if group == -1: group = femmgroupmode n = cmath.rect(r, rad(phi)) femm.mi_addblocklabel(n.real, n.imag) femm.mi_selectlabel(n.real, n.imag) femm.mi_setgroup(group) femm.mi_clearselected() return n
def addLine(r1, phi1, r2, phi2, group=-1): if group == -1: group = femmgroupmode n1 = cmath.rect(r1, rad(phi1)) n2 = cmath.rect(r2, rad(phi2)) femm.mi_addsegment(n1.real, n1.imag, n2.real, n2.imag) # select middle of arc for adding group # todo: better guess at point on line (unpredictable if phi1 != phi2) n = cmath.rect((r1 + r2) / 2., rad((phi1 + phi2) / 2.)) femm.mi_selectsegment(n.real, n.imag) femm.mi_setgroup(group) femm.mi_clearselected()
def addArcZZ(n1, n2, group=-1): if group == -1: group = femmgroupmode r1, phi1 = cmath.polar(n1) r2, phi2 = cmath.polar(n2) femm.mi_addarc(n1.real, n1.imag, n2.real, n2.imag, deg(abs(phi1 - phi2)), 10) # select middle of arc for adding group # todo: better guess at point on arc (unpredictable if r1 != r2) n = cmath.rect((r1 + r2) / 2., (phi1 + phi2) / 2.) femm.mi_selectarcsegment(n.real, n.imag) femm.mi_setgroup(group) femm.mi_clearselected()
def drawCoil(self): """Draw the coil Draws the coil in the FEMM instance Raises: Exception -- The coil is not defined, please call defineCoil before. """ if self.Lb is not None: femm.mi_clearselected() femm.mi_addmaterial("Cuivre", 1, 1, 0, 0, 1 / self.rho * 10**-6, 0, 0, 1, 3 if self.wire_type == "round" else 6, 0, 0, 1, self.phi) femm.mi_addnode(self.Rbi, -self.Lb / 2) femm.mi_addnode(self.Rbo, -self.Lb / 2) femm.mi_addnode(self.Rbi, self.Lb / 2) femm.mi_addnode(self.Rbo, self.Lb / 2) femm.mi_addsegment(self.Rbi, -self.Lb / 2, self.Rbo, -self.Lb / 2) femm.mi_addsegment(self.Rbo, -self.Lb / 2, self.Rbo, self.Lb / 2) femm.mi_addsegment(self.Rbo, self.Lb / 2, self.Rbi, self.Lb / 2) femm.mi_addsegment(self.Rbi, -self.Lb / 2, self.Rbi, self.Lb / 2) femm.mi_selectnode(self.Rbi, -self.Lb / 2) femm.mi_selectnode(self.Rbo, -self.Lb / 2) femm.mi_selectnode(self.Rbi, self.Lb / 2) femm.mi_selectnode(self.Rbo, self.Lb / 2) femm.mi_selectsegment(self.Rbi, 0) femm.mi_selectsegment((self.Rbi + self.Rbo) / 2, -self.Lb / 2) femm.mi_selectsegment(self.Rbo, 0) femm.mi_selectsegment((self.Rbi + self.Rbo) / 2, self.Lb / 2) femm.mi_setgroup(2) femm.mi_addblocklabel((self.Rbi + self.Rbo) / 2, 0) femm.mi_selectlabel((self.Rbi + self.Rbo) / 2, -self.Lb / 2) femm.mi_setblockprop("Cuivre", 0, self.meshsize, "Bobine", 0, 2, self.n) femm.mi_clearselected() else: raise Exception("No coil defined.")
def drawProjectile(self): """Draw projectile Draws the projectil in the FEMM instance Raises: Exception -- Projectile is not defined """ if self.Lp is not None: femm.mi_addmaterial("Projectile", self.mu, self.mu, 0, 0, 0, 0, 0, 1, 0, 0, 0) femm.mi_clearselected() femm.mi_addnode(0, -self.Lp / 2) femm.mi_addnode(self.Rp, -self.Lp / 2) femm.mi_addnode(0, self.Lp / 2) femm.mi_addnode(self.Rp, self.Lp / 2) femm.mi_addsegment(0, -self.Lp / 2, self.Rp, -self.Lp / 2) femm.mi_addsegment(self.Rp, -self.Lp / 2, self.Rp, self.Lp / 2) femm.mi_addsegment(self.Rp, self.Lp / 2, 0, self.Lp / 2) femm.mi_addsegment(0, self.Lp / 2, 0, -self.Lp / 2) femm.mi_selectnode(0, -self.Lp / 2) femm.mi_selectnode(self.Rp, -self.Lp / 2) femm.mi_selectnode(0, self.Lp / 2) femm.mi_selectnode(self.Rp, self.Lp / 2) femm.mi_selectsegment(0, 0) femm.mi_selectsegment(self.Rp / 2, -self.Lp / 2) femm.mi_selectsegment(self.Rp, 0) femm.mi_selectsegment(self.Rp / 2, self.Lp / 2) femm.mi_setgroup(1) femm.mi_addblocklabel(self.Rp / 2, 0) femm.mi_selectlabel(self.Rp / 2, 0) femm.mi_setblockprop("Projectile", 0, self.meshsize, "<None>", 0, 1, 0) femm.mi_clearselected() else: raise Exception("No projectile defined.")
def drawroundedcorner_box(femm, group, width, length, x_center, y_center, corner_radius, one_sided): x1 = x_center - width / 2 y1 = y_center - length / 2 x2 = x1 + width y2 = y1 + length # mc = .02 * inches mc = corner_radius # first create nodes at the 4 corners # because they will be joined by an arc segment c1_x = x1 c1_y = y1 c2_x = x2 c2_y = y1 c3_x = x2 c3_y = y2 c4_x = x1 c4_y = y2 # now make blunted edge magnet based on it n1x = c1_x n1y = c1_y + mc n2x = c1_x + mc n2y = c1_y n3x = c2_x - mc n3y = c2_y n4x = c2_x n4y = c2_y + mc n5x = c3_x n5y = c3_y - mc n6x = c3_x - mc n6y = c3_y n7x = c4_x + mc n7y = c4_y n8x = c4_x n8y = c4_y - mc # If drawing all 4 corners if (one_sided == 0): femm.mi_addnode(n1x, n1y) femm.mi_addnode(n2x, n2y) femm.mi_addnode(n3x, n3y) femm.mi_addnode(n4x, n4y) femm.mi_addnode(n5x, n5y) femm.mi_addnode(n6x, n6y) femm.mi_addnode(n7x, n7y) femm.mi_addnode(n8x, n8y) femm.mi_addarc(n1x, n1y, n2x, n2y, 90, 3) femm.mi_addsegment(n2x, n2y, n3x, n3y) femm.mi_addarc(n3x, n3y, n4x, n4y, 90, 3) femm.mi_addsegment(n4x, n4y, n5x, n5y) femm.mi_addarc(n5x, n5y, n6x, n6y, 90, 3) femm.mi_addsegment(n6x, n6y, n7x, n7y) femm.mi_addarc(n7x, n7y, n8x, n8y, 90, 3) femm.mi_addsegment(n8x, n8y, n1x, n1y) femm.mi_clearselected() # femm.mi_drawrectangle(x1, mag_y1, mag_x2, mag_y2) # femm.mi_selectrectangle(x1, mag_y1, mag_x2, mag_y2,0) femm.mi_selectsegment(c1_x, c1_y) femm.mi_setgroup(group) femm.mi_selectsegment(c1_x + width / 4, c1_y) femm.mi_setgroup(group) femm.mi_selectsegment(c2_x, c2_y) femm.mi_setgroup(group) femm.mi_selectsegment(c3_x, c3_y + length / 2) femm.mi_setgroup(group) femm.mi_selectsegment(c3_x, c3_y) femm.mi_setgroup(group) femm.mi_selectsegment(c3_x - width / 4, c3_y) femm.mi_setgroup(group) femm.mi_selectsegment(c4_x, c4_y) femm.mi_setgroup(group) femm.mi_selectsegment(c4_x, c4_y - length / 2) femm.mi_setgroup(group) #femm.mi_clearselected() # if drawing only rounded corners on far side # because location is on axis. if (one_sided == 1): femm.mi_addnode(c1_x, c1_y) femm.mi_addnode(n3x, n3y) femm.mi_addnode(n4x, n4y) femm.mi_addnode(n5x, n5y) femm.mi_addnode(n6x, n6y) femm.mi_addnode(c4_x, c4_y) femm.mi_addsegment(c4_x, c4_y, c1_x, c1_y) femm.mi_addsegment(c1_x, c1_y, n3x, n3y) femm.mi_addarc(n3x, n3y, n4x, n4y, 90, 3) femm.mi_addsegment(n4x, n4y, n5x, n5y) femm.mi_addarc(n5x, n5y, n6x, n6y, 90, 3) femm.mi_addsegment(n6x, n6y, c4_x, c4_y) femm.mi_clearselected() femm.mi_selectsegment(c1_x, c1_y + length / 2) femm.mi_setgroup(group) femm.mi_selectsegment(c1_x + width / 2, c1_y) femm.mi_setgroup(group) femm.mi_selectsegment(c2_x, c2_y) femm.mi_setgroup(group) femm.mi_selectsegment(c2_x, c2_y + length / 2) femm.mi_setgroup(group) femm.mi_selectsegment(c3_x, c3_y) femm.mi_setgroup(group) femm.mi_selectsegment(c3_x - width / 2, c3_y) femm.mi_setgroup(group)
od_m = 0.5 * inches # Magnet Diameter(assumes cylindrical magnet) mag_y_loc_o = Lc / 2 + 2 * Lc # Initial position of the magnet mag_y_loc = mag_y_loc_o # current position of the magnet (can change) magnet_corner_radius = .01 * inches # Approximate, mag_label_x = od_m / 4 # x location for magnet property node mag_label_y = mag_y_loc # y location for magnet property node one_sided_magnet_flag = 1 # the magnet is on axis, so only needs rounded corners on one side drawroundedcorner_box(femm, 3, od_m / 2, Lm, mag_label_x, mag_label_y, magnet_corner_radius, one_sided_magnet_flag) femm.mi_addblocklabel(mag_label_x, mag_label_y) femm.mi_selectlabel(mag_label_x, mag_label_y) femm.mi_setblockprop('NdFeB 52 MGOe', 0, 1, '<none>', 90, 0, 0) femm.mi_setgroup(3) # seems i needed this as well.. # MAJOR ADDITION femm.mi_selectlabel(mag_label_x, mag_label_y) femm.mi_setgroup(3) femm.mi_clearselected() # DEFINE ABSORBING BOUNDARY CONDITIONS # THIS IS LIKELY A SOURCE OF ERROR IF YOU CHANGE THE COIL AND MAGNET SIZES sim_diameter = mag_y_loc_o + Lm / 2 + Lc / 2 + Lc y_center_of_ABC = sim_diameter / 4 - Lm / 2 x_center_of_ABC = 0 femm.mi_makeABC(7, sim_diameter / 2 * 1.2, x_center_of_ABC, y_center_of_ABC, 0) ## RUNN 1 z_start = mag_y_loc_o z_end = 0 num_points = 25 # resolution of points inbetween z_start and z_end