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 deleteProjectile(self): """Delete the projectile Deletes the projectile (drawn) but doesn't erase its properties. """ femm.mi_clearselected() femm.mi_selectgroup(1) femm.mi_deleteselected() femm.mi_deletematerial("Projectile") if self.espace is not None: femm.mi_addsegment(0, -self.espace, 0, self.espace)
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 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)
def draw_FEMM( self, nodeprop=None, propname=None, elementsize=None, automesh=None, hide=False, group=None, ): """< Draw the segment in FEMM and assign the property Parameters ---------- nodeprop : Nodal property (Default value = None) propname : Boundary property ’propname’ (Default value = None) elementsize : Local element size along segment no greater than elementsize (Default value = None) automesh : 0 = mesher defers to the element constraint defined by elementsize, 1 = mesher automatically chooses mesh size along the selected segments (Default value = None) hide : 0 = not hidden in post-processor, 1 == hidden in post processorc (Default value = False) group : group the segment belongs (Default value = None) Returns ------- """ # Get BC (if any) if self.label in boundary_prop: propname = boundary_prop[self.label] # Add the nodes X1, Y1 = self.begin.real, self.begin.imag X2, Y2 = self.end.real, self.end.imag femm.mi_addnode(X1, Y1) femm.mi_selectnode(X1, Y1) femm.mi_setnodeprop(nodeprop, group) femm.mi_clearselected() femm.mi_addnode(X2, Y2) femm.mi_selectnode(X2, Y2) femm.mi_setnodeprop(nodeprop, group) femm.mi_clearselected() # add the segment femm.mi_addsegment(X1, Y1, X2, Y2) # Set property femm.mi_selectsegment((X1 + X2) / 2, (Y1 + Y2) / 2) femm.mi_setsegmentprop(propname, elementsize, automesh, hide, group) femm.mi_clearselected()
def draw(self): R1 = self.OR - (self.dm + self.dri) #inner radius of rotor R2 = self.OR - self.dm #radius to inside of PM R3 = self.OR - self.dmp #radius to outside of steel rotor self.hollow = R1 > self.threshold num_magnets = 2 * self.p theta = 360 / num_magnets #span between magnet centers in deg c = np.cos(self.alpha_m / 2) s = np.sin(self.alpha_m / 2) #bottom 3 points p1 = [R2 * c, -R2 * s] p2 = [R3 * c, -R3 * s] p3 = [self.OR * c, -self.OR * s] #top 3 points p4 = [self.OR * c, self.OR * s] p5 = [R3 * c, R3 * s] p6 = [R2 * c, R2 * s] nominal_coords = [p1, p2, p3, p4, p5, p6] #draw each of the magnets for i in range(num_magnets): angle = i * theta rotated_coords = [ rotate(*coord, angle) for coord in nominal_coords ] for coord in rotated_coords: fe.mi_addnode(*coord) c1, c2, c3, c4, c5, c6 = rotated_coords #add segments in clockwise fashion fe.mi_addsegment(*c1, *c2) fe.mi_addsegment(*c2, *c3) fe.mi_addarc(*c3, *c4, self.alpha_m_deg, 1) fe.mi_addsegment(*c4, *c5) fe.mi_addsegment(*c5, *c6) fe.mi_addarc(*c1, *c6, self.alpha_m_deg, 1) #connect between magnets alpha_between = 360 / num_magnets - self.alpha_m_deg for i in range(num_magnets): start = rotate(*p5, theta * i) stop = rotate(*p2, theta * (i + 1)) fe.mi_addarc(*start, *stop, alpha_between, 1) if self.hollow: fe.mi_addnode(0, R1) fe.mi_addnode(0, -R1) fe.mi_addarc(0, R1, 0, -R1, 180, 1) fe.mi_addarc(0, -R1, 0, R1, 180, 1) self.is_drawn = True
def creation_geometrie(self): """Méthode permettant de générer la géométrie""" # Dessin d'un rectangle (xmin,ymin,xmax,ymax) femm.mi_drawrectangle(-self.largeur / 2, -self.hauteur / 2, self.largeur / 2, self.hauteur / 2) # Dessin de points (x,y) femm.mi_addnode(self.l_dent / 2, self.entrefer / 2) femm.mi_addnode(-self.l_dent / 2, self.entrefer / 2) femm.mi_addnode(self.l_dent / 2, -self.entrefer / 2) femm.mi_addnode(-self.l_dent / 2, -self.entrefer / 2) femm.mi_addnode(self.l_dent / 2, self.hauteur / 2 - self.l_dent / 2) femm.mi_addnode(-self.l_dent / 2, self.hauteur / 2 - self.l_dent / 2) femm.mi_addnode(self.l_dent / 2, -self.hauteur / 2 + self.l_dent / 2) femm.mi_addnode(-self.l_dent / 2, -self.hauteur / 2 + self.l_dent / 2) femm.mi_addnode(self.largeur / 2 - self.l_dent / 2, self.hauteur / 2 - self.l_dent / 2) femm.mi_addnode(-self.largeur / 2 + self.l_dent / 2, self.hauteur / 2 - self.l_dent / 2) femm.mi_addnode(self.largeur / 2 - self.l_dent / 2, -self.hauteur / 2 + self.l_dent / 2) femm.mi_addnode(-self.largeur / 2 + self.l_dent / 2, -self.hauteur / 2 + self.l_dent / 2) # Dessin des lignes (x1,y1,x2,y2) femm.mi_addsegment(self.l_dent / 2, self.entrefer / 2, -self.l_dent / 2, self.entrefer / 2) femm.mi_addsegment(self.l_dent / 2, -self.entrefer / 2, -self.l_dent / 2, -self.entrefer / 2) femm.mi_addsegment(self.l_dent / 2, self.entrefer / 2, self.l_dent / 2, self.hauteur / 2 - self.l_dent / 2) femm.mi_addsegment(-self.l_dent / 2, self.entrefer / 2, -self.l_dent / 2, self.hauteur / 2 - self.l_dent / 2) femm.mi_addsegment(self.l_dent / 2, -self.entrefer / 2, self.l_dent / 2, -self.hauteur / 2 + self.l_dent / 2) femm.mi_addsegment(-self.l_dent / 2, -self.entrefer / 2, -self.l_dent / 2, -self.hauteur / 2 + self.l_dent / 2) femm.mi_addsegment(self.l_dent / 2, self.hauteur / 2 - self.l_dent / 2, self.largeur / 2 - self.l_dent / 2, self.hauteur / 2 - self.l_dent / 2) femm.mi_addsegment(-self.l_dent / 2, self.hauteur / 2 - self.l_dent / 2, -self.largeur / 2 + self.l_dent / 2, self.hauteur / 2 - self.l_dent / 2) femm.mi_addsegment(self.l_dent / 2, -self.hauteur / 2 + self.l_dent / 2, self.largeur / 2 - self.l_dent / 2, -self.hauteur / 2 + self.l_dent / 2) femm.mi_addsegment(-self.l_dent / 2, -self.hauteur / 2 + self.l_dent / 2, -self.largeur / 2 + self.l_dent / 2, -self.hauteur / 2 + self.l_dent / 2) femm.mi_addsegment(self.largeur / 2 - self.l_dent / 2, self.hauteur / 2 - self.l_dent / 2, self.largeur / 2 - self.l_dent / 2, -self.hauteur / 2 + self.l_dent / 2) femm.mi_addsegment(-self.largeur / 2 + self.l_dent / 2, self.hauteur / 2 - self.l_dent / 2, -self.largeur / 2 + self.l_dent / 2, -self.hauteur / 2 + self.l_dent / 2) femm.mi_addsegment(self.l_dent / 2, self.entrefer / 2, self.l_dent / 2, -self.entrefer / 2) femm.mi_addsegment(-self.l_dent / 2, self.entrefer / 2, -self.l_dent / 2, -self.entrefer / 2)