def plot_field(eng, mesh, val='u'): Ne = mesh.Ne it = FM.get_connections(mesh) mat = [] for e in mesh.getElements(): mat.append(e.getMaterial().getID() + 1) xyz = [] field = [] for n in mesh.getNodes(): xyz.append(n.getX().tolist()) if val == 'u': for n in mesh.getNodes(): field.append(n.getU().tolist()) elif val == 'v': for n in mesh.getNodes(): field.append(n.getV().tolist()) elif val == 'a': for n in mesh.getNodes(): field.append(n.getU().tolist()) else: return #eng = matlab.engine.start_matlab() IT = matlab.int64(it) MAT = matlab.int64(mat) XYZ = matlab.double(xyz) Field = matlab.double(field) eng.plot_field(IT, Field, XYZ, Ne, MAT, 0) return eng
def readInput(filename, nodeOrder, timeOrder, intData, Ndof=1): mesh = FM.Mesh() file = open(filename, 'r') int(file.readline().split()[1]) nnode = int(file.readline().split()[1]) nnod = int(file.readline().split()[1]) nelm = int(file.readline().split()[1]) int(file.readline().split()[1]) int(file.readline().split()[1]) file.readline() for i in range(nnod): a = list(float(x) for x in file.readline().split()) x_ = np.array(a[1:3]) mesh.addNode(FN.Node(x_, Ndof, timeOrder, i)) file.readline() for i in range(nelm): a = list(int(x) for x in file.readline().split()) nodes = [] for j in range(nnode): nodes.append(findNode(mesh.getNodes(), a[j + 1] - 1)) e = AxiSymMagnetic(nodes,[2,2],\ QE.LagrangeBasis1D,nodeOrder,None,intData) mesh.addElement(e) file.readline() for i in range(nnod): a = list(float(x) for x in file.readline().split()) for j in range(Ndof): mesh.getNodes()[i].setLoad(a[j + 1], j) file.readline() for i in range(nnod): a = file.readline().split() for j in range(Ndof): mesh.getNodes()[i].setConstraint( int(a[2 * j + 1 + 2]) == 0, float(a[2 * (j + 1) + 2]), j) air = LinearMagneticMaterial(1.0, 1.0, 0.0, 2) cooper = LinearMagneticMaterial(1.0, 1.0, 5.0e6, 3) steel = LinearMagneticMaterial(100.0, 1.0, 5.0e6, 1) #steel = JAMaterial(5.0e6,9,1) file.readline() for i in range(nelm): a = list(int(x) for x in file.readline().split()) if a[1] == 2: mesh.getElements()[i].updateMat(air) if a[1] == 3: mesh.getElements()[i].updateMat(cooper) if a[1] == 1: mesh.getElements()[i].updateMat(steel) #mesh.getElements()[i].setLinearity(False) #mesh.getElements()[i].updateMat(JAMaterial(5.0e6,intData.getNumberPoint(),1)) file.close() return mesh
def create_simple_mesh(): nodes = [] nodes.append(FN.Node([0.0, 0.0], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([1.0, 0.0], Ndof, timeOrder=tOrder)) edge = mg.Edge(nodes[0], nodes[1]) poly = edge.extendToQuad(np.array([0.0, 1.0]), 1.0) geo = mg.Geometry() geo.addPolygon(poly) poly.setDivisionEdge13(4) mat2 = LinearMagneticMaterial(100.0, 1.0, 5.0e6, 2) poly.setMaterial(mat2) geo.mesh() [nodesx, elems, mats, bdls] = geo.getMesh(None, mg.nodesQuad9, 2) for n in nodesx: if math.fabs(n.getX()[0] - 0.0) < 1.0e-14: n.setConstraint(False, 0.0, 0) if math.fabs(n.getX()[1]) < 1.0e-14 or math.fabs(n.getX()[1] - 1.0) < 1.0e-14: n.setConstraint(False, 10 * 0.5 * n.getX()[0], 0) if math.fabs(n.getX()[0] - 1.0) < 1.0e-14: n.setConstraint(False, 10 * 0.5 * n.getX()[0], 0) elements = [] for i, e in enumerate(elems): m = mats[i] elements.append(AxiSymMagnetic(e,[2,2],QE.LagrangeBasis1D,\ QE.generateQuadNodeOrder([2,2],2),m,intDat)) mesh = FM.Mesh() mesh.addNodes(nodesx) mesh.addElements(elements) def loadfunc(t): #return load*math.cos(8.1e3*2*np.pi*t) #return load*math.cos(8.1e3*2*np.pi*t) return load # mesh.Nodes[4].setLoad(loadfunc,0) return mesh
def getValueInElement(self, mesh, e, x, isteps=0, val='u'): """ get output value at position x(natural coordinate) in element e of mesh """ IT = fm.get_connection(mesh, e) try: resuu = [] for i in isteps: resu, tout = StandardFileOutput.readOutput( self.outfile, i, IT, val) for j, n in enumerate(e.getNodes()): n.setU(resu[i][j]) resuu.append(e.values_at(x, val)) return resuu except Exception: resu, tout = StandardFileOutput.readOutput(self.outfile, i, IT, val) for j, n in enumerate(e.getNodes()): n.setU(resu[i][j]) return e.values_at(x, val)
def create_mesh_x(): H = 0.001 R = 0.1 nodes = [] nodes.append(FN.Node([0, -2 * H * 10], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([R * 2, -2 * H * 10], Ndof, timeOrder=tOrder)) nodes.append( FN.Node([R * 2 + 0.1 * R, -2 * H * 10], Ndof, timeOrder=tOrder)) edges = [mg.Edge(nodes[i], nodes[i + 1]) for i in range(len(nodes) - 1)] geo = mg.Geometry() d = np.array([0.0, 1.0]) s = 10 * H for e in edges: geo.addPolygons(e.extendToQuad(d, s)) # nodes1 = [] # nodes1.append(FN.Node([0,H*21],Ndof,timeOrder = tOrder)) # nodes1.append(FN.Node([R*2,H*21],Ndof,timeOrder = tOrder)) # nodes1.append(FN.Node([R*2+0.1*R,H*21],Ndof,timeOrder = tOrder)) # # edges1 = [mg.Edge(nodes1[i],nodes1[i+1]) for i in range(len(nodes1)-1)] # # for e in edges1: # geo.addPolygons(e.extendToQuad(d,s)) nodes2 = [] nodes2.append(FN.Node([0, 0], Ndof, timeOrder=tOrder)) nodes2.append(FN.Node([R, 0], Ndof, timeOrder=tOrder)) edges2 = [ mg.Edge(nodes2[i], nodes2[i + 1]) for i in range(len(nodes2) - 1) ] s = H for e in edges2: geo.addPolygons(e.extendToQuad(d, s)) polys = geo.getPolygons() polys[0].setDivisionEdge13(20) polys[0].setDivisionEdge24(1) polys[2].setDivisionEdge13(20) polys[2].setDivisionEdge24(1) # polys[4].setDivisionEdge13(8) # polys[4].setDivisionEdge24(1) mat1 = LinearMagneticMaterial(1000.0, 0.0, 0.0, 0) mat2 = LinearMagneticMaterial(1.0, 0.0, 1.0, 1) mat3 = LinearMagneticMaterial(100.0, 0.0, 1.0, 2) mat4 = LinearMagneticMaterial(1.0, 0.0, 1.0, 3) polys[0].setMaterial(mat3) polys[1].setMaterial(mat2) polys[2].setMaterial(mat1) # polys[3].setMaterial(mat2) # polys[4].setMaterial(mat1) geo.mesh() [nodesx, elems, mats, bdls] = geo.getMesh(None, mg.nodesQuad9, 2) for n in nodesx: if math.fabs(n.getX()[0]) < 1.0e-14: # n.setConstraint(False, 0.0, 0) n.setConstraint(False, 0.0, 0) n.setConstraint(False, 0.0, 1) elements = [] for i, e in enumerate(elems): m = mats[i] # elements.append(AxiMechElement(e,[2,2],QE.LagrangeBasis1D,\ # nodeOrder,m,intDat,condt)) elements.append(AxiSymMagnetic(e,[2,2],QE.LagrangeBasis1D,\ nodeOrder,m,intDat)) if m.idx == 1: elements[-1].setBodyLoad(loadfuncx) # if m.idx == 0: # elements[-1].setBodyLoad(loadfuncG) # elements[-1].setBodyLoad(loadfunc) mesh = FM.MeshWithBoundaryElement() mesh.addNodes(nodesx) mesh.addElements(elements) geo.meshBoundary() [nodes1, elems1, normBndVec, bndMat] = geo.getBoundaryMesh(None,\ mg.nodesBoundaryQuad9,Ndof,get_mat=True) r0 = syp.sympify('r0') x0 = syp.sympify('x0') rx = syp.sympify('rx') xx = syp.sympify('xx') mt = (rx + r0)**2 + (xx - x0)**2 m = 4.0 * rx * r0 m = m / mt mtx = syp.sqrt(mt) * syp.pi kint = syp.elliptic_k(m) eint = syp.elliptic_e(m) # Gf = r0*((2.0-m)*kint-2.0*eint)/(m*mtx) Gf = ((2.0 - m) * kint - 2.0 * eint) / (m * mtx) Gfr = syp.diff(Gf, rx) Gfz = syp.diff(Gf, xx) Gfr0 = syp.diff(Gf, r0) Gfz0 = syp.diff(Gf, x0) Gfr0r = syp.diff(Gfr, r0) Gfr0z = syp.diff(Gfr, x0) Gfz0r = syp.diff(Gfz, r0) Gfz0z = syp.diff(Gfz, x0) Gfrr = syp.diff(Gfr, rx) Gfrz = syp.diff(Gfr, xx) Gfzr = syp.diff(Gfz, rx) Gfzz = syp.diff(Gfz, xx) Gfunc = syp.lambdify((rx,xx,r0,x0),Gf,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGr = syp.lambdify((rx,xx,r0,x0),Gfr,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGz = syp.lambdify((rx,xx,r0,x0),Gfz,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGrr = syp.lambdify((rx,xx,r0,x0),Gfrr,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGrz = syp.lambdify((rx,xx,r0,x0),Gfrz,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGzr = syp.lambdify((rx,xx,r0,x0),Gfzr,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGzz = syp.lambdify((rx,xx,r0,x0),Gfzz,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGr0 = syp.lambdify((rx,xx,r0,x0),Gfr0,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGz0 = syp.lambdify((rx,xx,r0,x0),Gfz0,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGr0r = syp.lambdify((rx,xx,r0,x0),Gfr0r,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGr0z = syp.lambdify((rx,xx,r0,x0),Gfr0z,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGz0r = syp.lambdify((rx,xx,r0,x0),Gfz0r,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGz0z = syp.lambdify((rx,xx,r0,x0),Gfz0z,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) elementBs = [] for i, e in enumerate(elems1): if np.fabs(e[1].getX()[0]) < 1.0e-13: continue elementBs.append(AxiSymMagneticBoundaryLinear(e,2,QE.LagrangeBasis1D,\ QE.generateQuadNodeOrder(2,1),intDatB,intSingDat,normBndVec[i],i)) elementBs[-1].setMaterial(bndMat[i]) # if bndMat[i].idx == 0: # elementBs[-1].deformed=True # if np.fabs(e[1].getX()[1])<1.0e-14: # elementBs[-1].normv = np.array([0.0,-1.0]) # if np.fabs(e[1].getX()[1]-H)<1.0e-14: # elementBs[-1].normv = np.array([0.0,1.0]) # if np.fabs(e[1].getX()[0]-R)<1.0e-14: # elementBs[-1].normv = np.array([1.0,0.0]) elementBs[-1].Gfunc = Gfunc elementBs[-1].Gdr = gradGr elementBs[-1].Gdz = gradGz elementBs[-1].Gdrr = gradGrr elementBs[-1].Gdrz = gradGrz elementBs[-1].Gdzr = gradGzr elementBs[-1].Gdzz = gradGzz elementBs[-1].Gdr0 = gradGr0 elementBs[-1].Gdz0 = gradGz0 elementBs[-1].Gdr0r = gradGr0r elementBs[-1].Gdr0z = gradGr0z elementBs[-1].Gdz0r = gradGz0r elementBs[-1].Gdz0z = gradGz0z # elementBs[-1].linear=False mesh.addBoundaryElements(elementBs) for n in mesh.getNodes(): ine = False for e in elementBs: if n in e: ine = True if not ine: n.setConstraint(False, 0.0, 1) # ndup = [] # for n in mesh.getNodes(): # xn = n.getX() # n1 = np.fabs(xn[0]-0.2)<1.0e-14 and np.fabs(xn[1]+0.02)<1.0e-14 # n2 = np.fabs(xn[0]-0.2)<1.0e-14 and np.fabs(xn[1]+0.01)<1.0e-14 # n3 = np.fabs(xn[0]-0.2)<1.0e-14 and np.fabs(xn[1]-0.011)<1.0e-13 # n4 = np.fabs(xn[0]-0.2)<1.0e-14 and np.fabs(xn[1]-0.021)<1.0e-13 # if n1 or n2 or n3 or n4: # be1 = None # be2 = None # for be in mesh.BoundaryElements: # if n in be: # if be1 is None: # be1 = be # elif be2 is None: # be2 = be # break # nx1 = n.copy() # nx1.setConstraint(False,0.0,0) # nx1.setConstraint(False,0.0,1) # nx1.friendOF(n,2) # nx2 = n.copy() # nx2.setConstraint(False,0.0,0) # nx2.setConstraint(False,0.0,1) # nx2.friendOF(n,2) # n.freedom[3] = False # for i1, nt1 in enumerate(be1.Nodes): # if n == nt1: # be1.Nodes[i1] = nx1 # ndup.append(nx1) # for i2, nt2 in enumerate(be2.Nodes): # if n == nt2: # be2.Nodes[i2] = nx2 # ndup.append(nx2) # for n in ndup: # mesh.Nodes.append(n) # mesh.Nnod += 1 mesh.generateID() return mesh
def create_test_mesh(): nodes = [] nodes.append(FN.Node([0.0, -1.0], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([1.0, -1.0], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([2.0, -1.0], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([2.5, -1.0], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([3.0, -1.0], Ndof, timeOrder=tOrder)) edges = [mg.Edge(nodes[i], nodes[i + 1]) for i in range(len(nodes) - 1)] geo = mg.Geometry() geo = mg.Geometry() d = np.array([0.0, 1.0]) s = [1.0, 0.25, 0.55, 0.25, 1.0] for e in edges: geo.addPolygons(e.extendToQuad(d, s)) polys = geo.getPolygons() mat1 = LinearMagneticMaterial(1.0, 1.0, 0.0, 1) # mat2 = LinearMagneticMaterial(1.0,1.0,5.0e6,2) for p in polys: p.setMaterial(mat1) polys[12].setBodyLoad(1.0) for p in polys: p.setDivisionEdge13(2) p.setDivisionEdge24(2) geo.mesh() [nodesx, elems, mats, bdls] = geo.getMesh(None, mg.nodesQuad9, Ndof) load = 355.0 for n in nodesx: if math.fabs(n.getX()[0] - 0.0) < 1.0e-14: n.setConstraint(False, 0.0, 0) # n.setConstraint(False, 0.0, 1) # if math.fabs(n.getX()[0])>1.0-1.0e-13 and \ # n.getX()[1]>0.25-1.0e-13 and \ # n.getX()[1]<0.75+1.0e-13 and n.getX()[0]<2.5+1.0e-13: # n.setLoad(load,0) # if math.fabs(n.getX()[0]-2.25)<1.0e-13 and\ # math.fabs(n.getX()[1]-0.525)<1.0e-13: # n.setLoad(load*2.0*np.pi*n.getX()[0],0) elements = [] for i, e in enumerate(elems): m = mats[i] elements.append(AxiSymMagnetic(e,[2,2],QE.LagrangeBasis1D,\ QE.generateQuadNodeOrder([2,2],2),m,intDat)) if bdls[i] is not None: def loadfunc(x, t): #return load*math.sin(8.1e3*2*np.pi*t) return load else: loadfunc = None elements[i].setBodyLoad(loadfunc) mesh = FM.MeshWithBoundaryElement() mesh.addNodes(nodesx) mesh.addElements(elements) geo.meshBoundary() [nodes1, elems1, normBndVec] = geo.getBoundaryMesh(None,\ mg.nodesBoundaryQuad9,Ndof) r0 = syp.sympify('r0') x0 = syp.sympify('x0') rx = syp.sympify('rx') xx = syp.sympify('xx') mt = (rx + r0)**2 + (xx - x0)**2 m = 4.0 * rx * r0 m = m / mt mtx = syp.sqrt(mt) * syp.pi kint = syp.elliptic_k(m) eint = syp.elliptic_e(m) # Gf = r0*((2.0-m)*kint-2.0*eint)/(m*mtx) Gf = ((2.0 - m) * kint - 2.0 * eint) / (m * mtx) Gfr = syp.diff(Gf, rx) Gfz = syp.diff(Gf, xx) Gfr0 = syp.diff(Gf, r0) Gfz0 = syp.diff(Gf, x0) Gfr0r = syp.diff(Gfr0, rx) Gfr0z = syp.diff(Gfr0, xx) Gfz0r = syp.diff(Gfz0, rx) Gfz0z = syp.diff(Gfz0, xx) Gfrr = syp.diff(Gfr, rx) Gfrz = syp.diff(Gfr, xx) Gfzr = syp.diff(Gfz, rx) Gfzz = syp.diff(Gfz, xx) Gfunc = syp.lambdify((rx,xx,r0,x0),Gf,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGr = syp.lambdify((rx,xx,r0,x0),Gfr,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGz = syp.lambdify((rx,xx,r0,x0),Gfz,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGrr = syp.lambdify((rx,xx,r0,x0),Gfrr,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGrz = syp.lambdify((rx,xx,r0,x0),Gfrz,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGzr = syp.lambdify((rx,xx,r0,x0),Gfzr,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGzz = syp.lambdify((rx,xx,r0,x0),Gfzz,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGr0 = syp.lambdify((rx,xx,r0,x0),Gfr0,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGz0 = syp.lambdify((rx,xx,r0,x0),Gfz0,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGr0r = syp.lambdify((rx,xx,r0,x0),Gfr0r,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGr0z = syp.lambdify((rx,xx,r0,x0),Gfr0z,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGz0r = syp.lambdify((rx,xx,r0,x0),Gfz0r,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGz0z = syp.lambdify((rx,xx,r0,x0),Gfz0z,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) elementBs = [] for i, e in enumerate(elems1): if e[1].getX()[0] == 0.0: continue elementBs.append(AxiSymMagneticBoundaryLinear(e,2,QE.LagrangeBasis1D,\ QE.generateQuadNodeOrder(2,1),intDatB,intSingDat,normBndVec[i],i)) elementBs[-1].setMaterial(mat1) elementBs[-1].Gfunc = Gfunc elementBs[-1].Gdr = gradGr elementBs[-1].Gdz = gradGz elementBs[-1].Gdrr = gradGrr elementBs[-1].Gdrz = gradGrz elementBs[-1].Gdzr = gradGzr elementBs[-1].Gdzz = gradGzz elementBs[-1].Gdr0 = gradGr0 elementBs[-1].Gdz0 = gradGz0 elementBs[-1].Gdr0r = gradGr0r elementBs[-1].Gdr0z = gradGr0z elementBs[-1].Gdz0r = gradGz0r elementBs[-1].Gdz0z = gradGz0z elementBs[-1].linear = True for n in mesh.getNodes(): ine = False for e in elementBs: if n in e: ine = True if not ine: n.setConstraint(False, 0.0, 1) #mesh.addElements(elementBs) mesh.addBoundaryElements(elementBs) mesh.generateID() return mesh
def create_simple_mesh(): nodes = [] nodes.append(FN.Node([0.0, 0.0], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([1.0, 0.0], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([2.0, 0.25], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([2.5, 0.25], Ndof, timeOrder=tOrder)) edge1 = mg.Edge(nodes[0], nodes[1]) poly1 = edge1.extendToQuad(np.array([0.0, 1.0]), 1.0) edge2 = mg.Edge(nodes[2], nodes[3]) poly2 = edge2.extendToQuad(np.array([0.0, 1.0]), 0.5) poly2.setBodyLoad(1.0) poly1.setDivisionEdge24(2) geo = mg.Geometry() geo.addPolygon(poly1) geo.addPolygon(poly2) mat1 = LinearMagneticMaterial(1.0, 1.0, 0.0, 1) mat2 = LinearMagneticMaterial(1.0, 1.0, 0.0, 2) poly1.setMaterial(mat1) poly2.setMaterial(mat2) geo.mesh() [nodesx, elems, mats, bdls] = geo.getMesh(None, mg.nodesQuad9, Ndof) for n in nodesx: if math.fabs(n.getX()[0] - 0.0) < 1.0e-14: n.setConstraint(False, 0.0, 0) n.setConstraint(False, 0.0, 1) elements = [] load = 355.0 for i, e in enumerate(elems): m = mats[i] elements.append(AxiSymMagnetic(e,[2,2],QE.LagrangeBasis1D,\ QE.generateQuadNodeOrder([2,2],2),m,intDat)) if bdls[i] is not None: def loadfunc(x, t): #return load*math.sin(8.1e3*2*np.pi*t) return load else: loadfunc = None elements[i].setBodyLoad(loadfunc) mesh = FM.MeshWithBoundaryElement() mesh.addNodes(nodesx) mesh.addElements(elements) geo.meshBoundary() [nodes1, elems1, normBndVec] = geo.getBoundaryMesh(None,\ mg.nodesBoundaryQuad9,Ndof) r0 = syp.sympify('r0') x0 = syp.sympify('x0') rx = syp.sympify('rx') xx = syp.sympify('xx') mt = (rx + r0)**2 + (xx - x0)**2 m = 4.0 * rx * r0 m = m / mt mtx = syp.sqrt(mt) * syp.pi kint = syp.elliptic_k(m) eint = syp.elliptic_e(m) # Gf = r0*((2.0-m)*kint-2.0*eint)/(m*mtx) Gf = ((2.0 - m) * kint - 2.0 * eint) / (m * mtx) Gfr = syp.diff(Gf, rx) Gfz = syp.diff(Gf, xx) Gfr0 = syp.diff(Gf, r0) Gfz0 = syp.diff(Gf, x0) Gfr0r = syp.diff(Gfr, r0) Gfr0z = syp.diff(Gfr, x0) Gfz0r = syp.diff(Gfz, r0) Gfz0z = syp.diff(Gfz, x0) Gfrr = syp.diff(Gfr, rx) Gfrz = syp.diff(Gfr, xx) Gfzr = syp.diff(Gfz, rx) Gfzz = syp.diff(Gfz, xx) Gfunc = syp.lambdify((rx,xx,r0,x0),Gf,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGr = syp.lambdify((rx,xx,r0,x0),Gfr,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGz = syp.lambdify((rx,xx,r0,x0),Gfz,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGrr = syp.lambdify((rx,xx,r0,x0),Gfrr,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGrz = syp.lambdify((rx,xx,r0,x0),Gfrz,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGzr = syp.lambdify((rx,xx,r0,x0),Gfzr,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGzz = syp.lambdify((rx,xx,r0,x0),Gfzz,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGr0 = syp.lambdify((rx,xx,r0,x0),Gfr0,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGz0 = syp.lambdify((rx,xx,r0,x0),Gfz0,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGr0r = syp.lambdify((rx,xx,r0,x0),Gfr0r,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGr0z = syp.lambdify((rx,xx,r0,x0),Gfr0z,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGz0r = syp.lambdify((rx,xx,r0,x0),Gfz0r,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) gradGz0z = syp.lambdify((rx,xx,r0,x0),Gfz0z,\ modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}]) elementBs = [] for i, e in enumerate(elems1): if e[1].getX()[0] == 0.0: continue elementBs.append(AxiSymMagneticBoundaryLinear(e,2,QE.LagrangeBasis1D,\ QE.generateQuadNodeOrder(2,1),intDatB,intSingDat,normBndVec[i],i)) elementBs[-1].setMaterial(mat1) elementBs[-1].Gfunc = Gfunc elementBs[-1].Gdr = gradGr elementBs[-1].Gdz = gradGz elementBs[-1].Gdrr = gradGrr elementBs[-1].Gdrz = gradGrz elementBs[-1].Gdzr = gradGzr elementBs[-1].Gdzz = gradGzz elementBs[-1].Gdr0 = gradGr0 elementBs[-1].Gdz0 = gradGz0 elementBs[-1].Gdr0r = gradGr0r elementBs[-1].Gdr0z = gradGr0z elementBs[-1].Gdz0r = gradGz0r elementBs[-1].Gdz0z = gradGz0z elementBs[-1].linear = True for n in mesh.getNodes(): ine = False for e in elementBs: if n in e: ine = True if not ine: n.setConstraint(False, 0.0, 1) #mesh.addElements(elementBs) mesh.addBoundaryElements(elementBs) ndup = [] for n in mesh.getNodes(): xn = n.getX() # n1 = np.fabs(xn[0])<1.0e-14 and np.fabs(xn[1])<1.0e-14 n2 = np.fabs(xn[0] - 1.0) < 1.0e-14 and np.fabs(xn[1]) < 1.0e-14 n3 = np.fabs(xn[0] - 1.0) < 1.0e-14 and np.fabs(xn[1] - 1.0) < 1.0e-14 # n4 = np.fabs(xn[0])<1.0e-14 and np.fabs(xn[1]-1.0)<1.0e-14 n5 = np.fabs(xn[0] - 2.0) < 1.0e-14 and np.fabs(xn[1] - 0.25) < 1.0e-14 n6 = np.fabs(xn[0] - 2.5) < 1.0e-14 and np.fabs(xn[1] - 0.25) < 1.0e-14 n7 = np.fabs(xn[0] - 2.5) < 1.0e-14 and np.fabs(xn[1] - 0.75) < 1.0e-14 n8 = np.fabs(xn[0] - 2.0) < 1.0e-14 and np.fabs(xn[1] - 0.75) < 1.0e-14 if n2 or n3 or n5 or n6 or n7 or n8: be1 = None be2 = None for be in mesh.BoundaryElements: if n in be: if be1 is None: be1 = be elif be2 is None: be2 = be break nx1 = n.copy() nx1.friendOF(n, 0) nx2 = n.copy() nx2.friendOF(n, 0) n.freedom[1] = False for i1, nt1 in enumerate(be1.Nodes): if n == nt1: be1.Nodes[i1] = nx1 ndup.append(nx1) for i2, nt2 in enumerate(be2.Nodes): if n == nt2: be2.Nodes[i2] = nx2 ndup.append(nx2) for n in ndup: mesh.Nodes.append(n) mesh.Nnod += 1 mesh.generateID() #mesh.Nodes[4].setLoad(loadfunc,0) return mesh
def create_mesh(): H = 0.01 R = 0.1 nodes = [] nodes.append(FN.Node([0,0],Ndof,timeOrder = tOrder)) nodes.append(FN.Node([R,0],Ndof,timeOrder = tOrder)) edges = [mg.Edge(nodes[i],nodes[i+1]) for i in range(len(nodes)-1)] geo = mg.Geometry() d = np.array([0.0,1.0]) s = H for e in edges: geo.addPolygons(e.extendToQuad(d,s)) polys = geo.getPolygons() polys[0].setDivisionEdge13(2) polys[0].setDivisionEdge24(1) mat1 = LinearMechanicMaterial(2.1e11, 0.3, 7.8e3,10000.0) polys[0].setMaterial(mat1) geo.mesh() [nodesx, elems, mats, bdls] = geo.getMesh(None,mg.nodesQuad9,2) for n in nodesx: # n.setConstraint(False, 0.0, 0) # n.setConstraint(False, 0.0, 1) if math.fabs(n.getX()[0]-R)<1.0e-14 and math.fabs(n.getX()[1]-H*0.5)<1.0e-14: # if math.fabs(n.getX()[0]-R)<1.0e-14 : # n.setConstraint(False, 0.0, 0) n.setConstraint(False, 0.0, 1) # ncenter = n # n.setLoad(-1.0e6,0) # n.setConstraint(False, condt[1]*0.5*n.getX()[0],2) if math.fabs(n.getX()[0]-R)<1.0e-14 : n.setConstraint(False, 0.0, 0) # n.setConstraint(False, 0.0, 1) # n.setConstraint(False, condt[1]*0.5*n.getX()[0],2) if math.fabs(n.getX()[0])<1.0e-14: n.setConstraint(False, 0.0, 0) # n.setConstraint(False,0.0,2) # if math.fabs(n.getX()[1])<1.0e-14 or\ # math.fabs(n.getX()[1]-H)<1.0e-14: # n.setConstraint(False, condt[1]*0.5*n.getX()[0],2) # for n in nodesx: # if math.fabs(n.getX()[0]-R)<1.0e-14: # n.friendOF(ncenter,0) elements = [] for i,e in enumerate(elems): m = mats[i] elements.append(AxiMechElement(e,[2,2],QE.LagrangeBasis1D,\ nodeOrder,m,intDat,condt)) # elements[-1].setBodyLoad(loadfunc) mesh = FM.MeshWithBoundaryElement() mesh.addNodes(nodesx) mesh.addElements(elements) geo.meshBoundary() [nodes1, elems1, normBndVec] = geo.getBoundaryMesh(None,\ mg.nodesBoundaryQuad9,Ndof) elementBs = [] condtx = condt for i,e in enumerate(elems1): # if np.fabs(e[1].getX()[0]-R) < 1.0e-13: # condtx = condt # elementBs.append(AxiSymMagMech(e,2,QE.LagrangeBasis1D,\ # QE.generateQuadNodeOrder(2,1),intDatB,normBndVec[i],i,condtx)) # elementBs[-1].setMaterial(mat1) # else: # condtx = np.array([0.0,0.0]) if np.fabs(e[1].getX()[0]) < 1.0e-13: continue elementBs.append(AxiSymMagMech(e,2,QE.LagrangeBasis1D,\ QE.generateQuadNodeOrder(2,1),intDatB,normBndVec[i],i,condtx)) elementBs[-1].setMaterial(mat1) if np.fabs(e[1].getX()[1])<1.0e-14: elementBs[-1].normv = np.array([0.0,-1.0]) if np.fabs(e[1].getX()[1]-H)<1.0e-14: elementBs[-1].normv = np.array([0.0,1.0]) mesh.addBoundaryElements(elementBs) return mesh
def create_mesh(): H = 0.01 R = 0.1 Ho = 0.1 Ro = 0.2 nodes = [] nodes.append(FN.Node([0, 0], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([R, 0], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([Ro, 0], Ndof, timeOrder=tOrder)) edges = [mg.Edge(nodes[i], nodes[i + 1]) for i in range(len(nodes) - 1)] geo = mg.Geometry() d = np.array([0.0, 1.0]) s = [Ho, H, Ho] for e in edges: geo.addPolygons(e.extendToQuad(d, s)) nepl = 4 ney = 2 polys = geo.getPolygons() polys[0].setDivisionEdge13(nepl) polys[0].setDivisionEdge24(ney) polys[1].setDivisionEdge13(nepl) polys[1].setDivisionEdge24(1) polys[2].setDivisionEdge13(nepl) polys[2].setDivisionEdge24(ney) polys[3].setDivisionEdge13(1) polys[3].setDivisionEdge24(ney) polys[4].setDivisionEdge13(1) polys[4].setDivisionEdge24(1) polys[5].setDivisionEdge13(1) polys[5].setDivisionEdge24(ney) mat1 = LinearMechanicMaterial(2.1e11, 0.3, 7.8e3, 10000.0, 0) mat2 = LinearMechanicMaterial(0.0, 0.0, 1.0, 1.0, 1) for i in range(6): if i != 1: polys[i].setMaterial(mat2) else: polys[i].setMaterial(mat1) geo.mesh() [nodesx, elems, mats, bdls] = geo.getMesh(None, mg.nodesQuad9, 2) for n in nodesx: if n.getX()[0] > R + 1.0e-8: n.setConstraint(False, 0.0, 0) n.setConstraint(False, 0.0, 1) if n.getX()[1] < Ho - 1.0e-8: n.setConstraint(False, 0.0, 0) n.setConstraint(False, 0.0, 1) if n.getX()[1] > Ho + H + 1.0e-8: n.setConstraint(False, 0.0, 0) n.setConstraint(False, 0.0, 1) # n.setConstraint(False, 0.0, 0) # n.setConstraint(False, 0.0, 1) # if math.fabs(n.getX()[0]-R)<1.0e-14 and math.fabs(n.getX()[1]-(H*0.5+Ho))<1.0e-13: # ncenter = n if math.fabs(n.getX()[0] - R) < 1.0e-14: n.setConstraint(False, 0.0, 0) n.setConstraint(False, 0.0, 1) # n.setConstraint(False, condt[1]*0.5*n.getX()[0],2) if math.fabs(n.getX()[0]) < 1.0e-14: n.setConstraint(False, 0.0, 0) n.setConstraint(False, 0.0, 2) if math.fabs(n.getX()[1])<1.0e-14 or\ math.fabs(n.getX()[1]-(H+2*Ho))<1.0e-13: n.setConstraint(False, condt[1] * 0.5 * n.getX()[0], 2) n.controlVar(2) if math.fabs(n.getX()[0] - Ro) < 1.0e-14: n.setConstraint(False, condt[1] * 0.5 * n.getX()[0], 2) n.controlVar(2) # for n in nodesx: # if math.fabs(n.getX()[0]-R)<1.0e-14 and n.getX()[1]>Ho-1.0e-8\ # and n.getX()[1]<Ho+H+1.0e-8: # n.friendOF(ncenter,0) elements = [] for i, e in enumerate(elems): m = mats[i] elements.append(AxiMechElement(e,[2,2],QE.LagrangeBasis1D,\ nodeOrder,m,intDat,condt)) # elements[-1].setBodyLoad(loadfunc) mesh = FM.MeshWithBoundaryElement() mesh.addNodes(nodesx) mesh.addElements(elements) return mesh
import Mesh.FEMNode as FN import numpy as np import pylab as pl filen = '/media/haiau/Data/PyFEM_Results/result_100.dat' Ndof = 2 tOrder = 2 res100,_ = FO.StandardFileOutput.readOutput(filen,val='x') res = res100.tolist() nodes = [] for x in res: nodes.append(FN.Node(x,Ndof,timeOrder=tOrder)) node = FM.findNodeNearX(nodes,np.array([0.015,0.0,0.0])) #testres,t = FO.StandardFileOutput.readOutput(filen,list(range(100)),val='u') fldrn = '/media/haiau/Data/PyFEM_Results/result_' num_steps = [100,200,400,800,1600,3200] def error_analysis(fldrn): resu = [] rest = [] for n in num_steps: filen = fldrn + str(n)+'.dat' print('reading data file: '+filen)
def create_mesh(): nodes = [] nodes.append(FN.Node([0.0, -0.1], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([0.015, -0.1], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([0.0225, -0.036], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([0.0325, -0.036], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([0.0225, -0.0075], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([0.0325, -0.0075], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([0.0225, 0.021], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([0.0325, 0.021], Ndof, timeOrder=tOrder)) edges = [] edges.append(mg.Edge(nodes[0], nodes[1])) edges.append(mg.Edge(nodes[2], nodes[3])) edges.append(mg.Edge(nodes[4], nodes[5])) edges.append(mg.Edge(nodes[6], nodes[7])) geo = mg.Geometry() d = np.array([0.0, 1.0]) s = [0.05, 0.014, 0.015, 0.0135, 0.015, 0.0135, 0.015, 0.014, 0.05] geo.addPolygons(edges[0].extendToQuad(d, s)) s = [0.2, 0.015, 0.015, 0.015] for i in range(1, len(edges)): geo.addPolygons(edges[i].extendToQuad(d, s[i])) #fig = geo.plot(poly_number=True) ndiv = 1 polys = geo.getPolygons() # for p in polys: # p.setDivisionEdge13(ndiv) # p.setDivisionEdge24(ndiv) for i in range(9): polys[i].setDivisionEdge13(4 * ndiv) polys[0].setDivisionEdge24(2 * ndiv) polys[8].setDivisionEdge24(2 * ndiv) mat2 = LinearMagneticMaterial(1.0, 0.0, 5.0e6, 2) #mat1 = JAMaterial(5.0e6,9,1) mat1 = LinearMagneticMaterial(100.0, 0.0, 5.0e6, 1) for i in range(9): polys[i].setMaterial(mat1) polys[9].setMaterial(mat2) polys[9].setBodyLoad(1.0) polys[10].setMaterial(mat2) polys[10].setBodyLoad(1.0) polys[11].setMaterial(mat2) polys[11].setBodyLoad(1.0) geo.mesh() #fig = geo.plotMesh(fill_mat = True) [nodesx, elems, mats, bdls] = geo.getMesh(None, mg.nodesQuad9, Ndof) for n in nodesx: if math.fabs(n.getX()[0] - 0.0) < 1.0e-14: n.setConstraint(False, 0.0, 0) n.setConstraint(False, 0.0, 1) elements = [] for i, e in enumerate(elems): m = mats[i] elements.append(AxiSymMagnetic(e,[2,2],QE.LagrangeBasis1D,\ QE.generateQuadNodeOrder([2,2],2),m,intDat)) #if m.getID() == 1: # elements[-1].setLinearity(False) if bdls[i] is not None: def loadfunc(x, t): return load * math.sin(8.1e3 * 2 * np.pi * t) #return -load else: loadfunc = None elements[-1].setBodyLoad(loadfunc) mesh = FM.MeshWithBoundaryElement() mesh.addNodes(nodesx) mesh.addElements(elements) geo.meshBoundary() [nodes1, elems1, normBndVec] = geo.getBoundaryMesh(None,\ mg.nodesBoundaryQuad9,Ndof) elementBs = [] for i, e in enumerate(elems1): elementBs.append(AxiSymMagneticBoundary(e,2,QE.LagrangeBasis1D,\ QE.generateQuadNodeOrder(2,1),intDatB,intSingDat,normBndVec[i],i)) elementBs[-1].setMaterial(mat2) for n in mesh.getNodes(): ine = False for e in elementBs: if n in e: ine = True if not ine: n.setConstraint(False, 0.0, 1) #mesh.addElements(elementBs) mesh.addBoundaryElements(elementBs) mesh.generateID() #mesh.Nodes[4].setLoad(loadfunc,0) return mesh
def create_mesh(): r0 = 0.0 r1 = 2.0e-2 r2 = 3.0e-2 r3 = 3.2e-2 r4 = 5.2e-2 r5 = 5.7e-2 r6 = 1.0e-1 phi = np.array([22.5,37.5,82.5,97.5,142.5,157.5,202.5,217.5,262.5,277.5,322.5,337.5]) phi = d_to_r(phi) mesh = FM.Mesh() basisf = QE.LagrangeBasis1D for i in range(-1,len(phi)-1): if i%2 == 1: nr = 4 else: nr = 2 elements,belm = polarMesh(r0,r1,phi[i],phi[i+1],nr,2,Ndof,tOrder,typ='quad',bnd=1) mat_rotor = LinearMagneticMaterial(30.0,0.0,3.72e6,0) elm = [PolarMagnetic(e,[2,2],basisf,nodeOrder,mat_rotor,intDat) for e in elements] mesh.addElements(elm) elements,belm = polarMesh(r1,r2,phi[i],phi[i+1],nr,2,Ndof,tOrder,typ='quad',bnd=1) mat_ind = LinearMagneticMaterial(1.0,0.0,3.72e7,1) elm = [PolarMagnetic(e,[2,2],basisf,nodeOrder,mat_ind,intDat) for e in elements] mesh.addElements(elm) elements,belm = polarMesh(r2,r3,phi[i],phi[i+1],nr,4,Ndof,tOrder,typ='quad',bnd=1) mat_air = LinearMagneticMaterial(1.0,0.0,0.0,4) elm = [PolarMagnetic(e,[2,2],basisf,nodeOrder,mat_air,intDat) for e in elements] mesh.addElements(elm) elements,belm = polarMesh(r3,r4,phi[i],phi[i+1],nr,2,Ndof,tOrder,typ='quad',bnd=1) mat_phase = LinearMagneticMaterial(1.0,0.0,0.0,2) elm = [PolarMagnetic(e,[2,2],basisf,nodeOrder,mat_phase,intDat) for e in elements] if i%2 == 1: for e in elm: e.setBodyLoad(loadfunc[math.ceil(i/2)],math.ceil(i/2)) # for n in e.Nodes: # n.setLoad(loadfunc[math.ceil(i/2)],0) mesh.addElements(elm) # if belm is not None: # belms = [PE.PolarElementGapBoundary(e,2,basisf,1.0/(np.pi*4.0e-7),normv=[-1.0,0.0]) for e in belm] # for e in belms: # e.current = False # mesh.addGapElements(belms) elements,belm = polarMesh(r4,r5,phi[i],phi[i+1],nr,1,Ndof,tOrder,typ='quad') mat_stator = LinearMagneticMaterial(30.0,0.0,0.0,3) elm = [PolarMagnetic(e,[2,2],basisf,nodeOrder,mat_stator,intDat) for e in elements] mesh.addElements(elm) # elements,belm = polarMesh(r5,r6,phi[i],phi[i+1],nr,1,Ndof,tOrder,typ='quad') # mat_outside = LinearMagneticMaterial(1.0,0.0,0.0,4) # elm = [PolarMagnetic(e,[2,2],basisf,nodeOrder,mat_outside,intDat) for e in elements] # mesh.addElements(elm) for n in mesh.Nodes: if n.getX()[0] <= 1.0e-14: n.setConstraint(False,0.0,0) if math.fabs(n.getX()[0] - r5) < 1.0e-14: n.setConstraint(False,0.0,0) mesh.generateID() return mesh
def create_test_mesh(): nodes = [] nodes.append(FN.Node([0.0, -1.0], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([1.0, -1.0], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([2.0, -1.0], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([2.5, -1.0], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([3.0, -1.0], Ndof, timeOrder=tOrder)) edges = [mg.Edge(nodes[i], nodes[i + 1]) for i in range(len(nodes) - 1)] geo = mg.Geometry() geo = mg.Geometry() d = np.array([0.0, 1.0]) s = [1.0, 0.25, 0.55, 0.25, 1.0] for e in edges: geo.addPolygons(e.extendToQuad(d, s)) polys = geo.getPolygons() mat1 = LinearMagneticMaterial(1.0, 1.0, 0.0, 1) # mat2 = LinearMagneticMaterial(1.0,1.0,5.0e6,2) for p in polys: p.setMaterial(mat1) polys[12].setBodyLoad(1.0) for p in polys: p.setDivisionEdge13(2) p.setDivisionEdge24(2) geo.mesh() [nodesx, elems, mats, bdls] = geo.getMesh(None, mg.nodesQuad9, Ndof) load = 355.0 for n in nodesx: # if math.fabs(n.getX()[0]-0.0)<1.0e-14: # n.setConstraint(False, 0.0, 0) # n.setConstraint(False, 0.0, 1) # if math.fabs(n.getX()[0])>1.0-1.0e-13 and \ # n.getX()[1]>0.25-1.0e-13 and \ # n.getX()[1]<0.75+1.0e-13 and n.getX()[0]<2.5+1.0e-13: # n.setLoad(load,0) if math.fabs(n.getX()[0]-2.25)<1.0e-13 and\ math.fabs(n.getX()[1]-0.525)<1.0e-13: n.setLoad(load, 0) elements = [] for i, e in enumerate(elems): m = mats[i] elements.append(Magnetic2D(e,[2,2],QE.LagrangeBasis1D,\ QE.generateQuadNodeOrder([2,2],2),m,intDat)) # if bdls[i] is not None: # def loadfunc(x,t): # #return load*math.sin(8.1e3*2*np.pi*t) # return load # else: # loadfunc = None # elements[i].setBodyLoad(loadfunc) mesh = FM.MeshWithBoundaryElement() mesh.addNodes(nodesx) mesh.addElements(elements) geo.meshBoundary() [nodes1, elems1, normBndVec] = geo.getBoundaryMesh(None,\ mg.nodesBoundaryQuad9,Ndof) x0 = syp.sympify('x0') y0 = syp.sympify('y0') xx = syp.sympify('xx') yy = syp.sympify('yy') mt = (x0 - xx)**2 + (yy - y0)**2 Gf = -syp.log(mt) / (4.0 * syp.pi) Gfx = syp.diff(Gf, xx) Gfy = syp.diff(Gf, yy) Gfx0 = syp.diff(Gf, x0) Gfy0 = syp.diff(Gf, y0) Gfx0x = syp.diff(Gfx0, xx) Gfx0y = syp.diff(Gfx0, yy) Gfy0x = syp.diff(Gfy0, xx) Gfy0y = syp.diff(Gfy0, yy) Gfxx = syp.diff(Gfx, xx) Gfxy = syp.diff(Gfx, yy) Gfyx = syp.diff(Gfy, xx) Gfyy = syp.diff(Gfy, yy) Gfunc = syp.lambdify((xx, yy, x0, y0), Gf, modules=['numpy']) gradGx = syp.lambdify((xx, yy, x0, y0), Gfx, modules=['numpy']) gradGy = syp.lambdify((xx, yy, x0, y0), Gfy, modules=['numpy']) gradGxx = syp.lambdify((xx, yy, x0, y0), Gfxx, modules=['numpy']) gradGxy = syp.lambdify((xx, yy, x0, y0), Gfxy, modules=['numpy']) gradGyx = syp.lambdify((xx, yy, x0, y0), Gfyx, modules=['numpy']) gradGyy = syp.lambdify((xx, yy, x0, y0), Gfyy, modules=['numpy']) gradGx0 = syp.lambdify((xx, yy, x0, y0), Gfx0, modules=['numpy']) gradGy0 = syp.lambdify((xx, yy, x0, y0), Gfy0, modules=['numpy']) gradGx0x = syp.lambdify((xx, yy, x0, y0), Gfx0x, modules=['numpy']) gradGx0y = syp.lambdify((xx, yy, x0, y0), Gfx0y, modules=['numpy']) gradGy0x = syp.lambdify((xx, yy, x0, y0), Gfy0x, modules=['numpy']) gradGy0y = syp.lambdify((xx, yy, x0, y0), Gfy0y, modules=['numpy']) elementBs = [] for i, e in enumerate(elems1): # if e[1].getX()[0] == 0.0: # continue elementBs.append(SymMagneticBoundaryLinear(e,2,QE.LagrangeBasis1D,\ QE.generateQuadNodeOrder(2,1),intDatB,intSingDat,normBndVec[i],i,\ commonData = commonD)) elementBs[-1].setMaterial(mat1) elementBs[-1].Gfunc = Gfunc elementBs[-1].Gdx = gradGx elementBs[-1].Gdy = gradGy elementBs[-1].Gdxx = gradGxx elementBs[-1].Gdxy = gradGxy elementBs[-1].Gdyx = gradGyx elementBs[-1].Gdyy = gradGyy elementBs[-1].Gdx0 = gradGx0 elementBs[-1].Gdy0 = gradGy0 elementBs[-1].Gdx0x = gradGx0x elementBs[-1].Gdx0y = gradGx0y elementBs[-1].Gdy0x = gradGy0x elementBs[-1].Gdy0y = gradGy0y elementBs[-1].linear = True for n in mesh.getNodes(): ine = False for e in elementBs: if n in e: ine = True if not ine: n.setConstraint(False, 0.0, 1) #mesh.addElements(elementBs) mesh.addBoundaryElements(elementBs) mesh.generateID() return mesh
def create_simple_mesh(): nodes = [] nodes.append(FN.Node([0.0, 0.0], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([1.0, 0.0], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([2.0, 0.25], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([2.5, 0.25], Ndof, timeOrder=tOrder)) edge1 = mg.Edge(nodes[0], nodes[1]) poly1 = edge1.extendToQuad(np.array([0.0, 1.0]), 1.0) edge2 = mg.Edge(nodes[2], nodes[3]) poly2 = edge2.extendToQuad(np.array([0.0, 1.0]), 0.5) poly2.setBodyLoad(1.0) # poly1.setDivisionEdge24(2) geo = mg.Geometry() geo.addPolygon(poly1) geo.addPolygon(poly2) mat1 = LinearMagneticMaterial(1.0, 1.0, 0.0, 1) mat2 = LinearMagneticMaterial(1.0, 1.0, 0.0, 2) poly1.setMaterial(mat1) poly2.setMaterial(mat2) load = 355.0 geo.mesh() [nodesx, elems, mats, bdls] = geo.getMesh(None, mg.nodesQuad9, Ndof) # for n in nodesx: ## if math.fabs(n.getX()[0]-0.0)<1.0e-14: ## n.setConstraint(False, 0.0, 0) ## n.setConstraint(False, 0.0, 1) # if math.fabs(n.getX()[0]-2.25)<1.0e-13 and\ # math.fabs(n.getX()[1]-0.5)<1.0e-13: # n.setLoad(load,0) elements = [] for i, e in enumerate(elems): m = mats[i] elements.append(Magnetic2D(e,[2,2],QE.LagrangeBasis1D,\ QE.generateQuadNodeOrder([2,2],2),m,intDat)) if bdls[i] is not None: def loadfunc(x, t): #return load*math.sin(8.1e3*2*np.pi*t) return load else: loadfunc = None elements[i].setBodyLoad(loadfunc) mesh = FM.MeshWithBoundaryElement() mesh.addNodes(nodesx) mesh.addElements(elements) geo.meshBoundary() [nodes1, elems1, normBndVec] = geo.getBoundaryMesh(None,\ mg.nodesBoundaryQuad9,Ndof) x0 = syp.sympify('x0') y0 = syp.sympify('y0') xx = syp.sympify('xx') yy = syp.sympify('yy') mt = (x0 - xx)**2 + (yy - y0)**2 Gf = -syp.log(mt) / (4.0 * syp.pi) Gfx = syp.diff(Gf, xx) Gfy = syp.diff(Gf, yy) Gfx0 = syp.diff(Gf, x0) Gfy0 = syp.diff(Gf, y0) Gfx0x = syp.diff(Gfx0, xx) Gfx0y = syp.diff(Gfx0, yy) Gfy0x = syp.diff(Gfy0, xx) Gfy0y = syp.diff(Gfy0, yy) Gfxx = syp.diff(Gfx, xx) Gfxy = syp.diff(Gfx, yy) Gfyx = syp.diff(Gfy, xx) Gfyy = syp.diff(Gfy, yy) Gfunc = syp.lambdify((xx, yy, x0, y0), Gf, modules=['numpy']) gradGx = syp.lambdify((xx, yy, x0, y0), Gfx, modules=['numpy']) gradGy = syp.lambdify((xx, yy, x0, y0), Gfy, modules=['numpy']) gradGxx = syp.lambdify((xx, yy, x0, y0), Gfxx, modules=['numpy']) gradGxy = syp.lambdify((xx, yy, x0, y0), Gfxy, modules=['numpy']) gradGyx = syp.lambdify((xx, yy, x0, y0), Gfyx, modules=['numpy']) gradGyy = syp.lambdify((xx, yy, x0, y0), Gfyy, modules=['numpy']) gradGx0 = syp.lambdify((xx, yy, x0, y0), Gfx0, modules=['numpy']) gradGy0 = syp.lambdify((xx, yy, x0, y0), Gfy0, modules=['numpy']) gradGx0x = syp.lambdify((xx, yy, x0, y0), Gfx0x, modules=['numpy']) gradGx0y = syp.lambdify((xx, yy, x0, y0), Gfx0y, modules=['numpy']) gradGy0x = syp.lambdify((xx, yy, x0, y0), Gfy0x, modules=['numpy']) gradGy0y = syp.lambdify((xx, yy, x0, y0), Gfy0y, modules=['numpy']) elementBs = [] for i, e in enumerate(elems1): # if e[1].getX()[0] == 0.0: # continue elementBs.append(SymMagneticBoundaryLinear(e,2,QE.LagrangeBasis1D,\ QE.generateQuadNodeOrder(2,1),intDatB,intSingDat,normBndVec[i],i,\ commonData = commonD)) elementBs[-1].setMaterial(mat1) elementBs[-1].Gfunc = Gfunc elementBs[-1].Gdx = gradGx elementBs[-1].Gdy = gradGy elementBs[-1].Gdxx = gradGxx elementBs[-1].Gdxy = gradGxy elementBs[-1].Gdyx = gradGyx elementBs[-1].Gdyy = gradGyy elementBs[-1].Gdx0 = gradGx0 elementBs[-1].Gdy0 = gradGy0 elementBs[-1].Gdx0x = gradGx0x elementBs[-1].Gdx0y = gradGx0y elementBs[-1].Gdy0x = gradGy0x elementBs[-1].Gdy0y = gradGy0y elementBs[-1].linear = True for n in mesh.getNodes(): ine = False for e in elementBs: if n in e: ine = True if not ine: n.setConstraint(False, 0.0, 1) #mesh.addElements(elementBs) mesh.addBoundaryElements(elementBs) ndup = [] for n in mesh.getNodes(): xn = n.getX() n1 = np.fabs(xn[0]) < 1.0e-14 and np.fabs(xn[1]) < 1.0e-14 n2 = np.fabs(xn[0] - 1.0) < 1.0e-14 and np.fabs(xn[1]) < 1.0e-14 n3 = np.fabs(xn[0] - 1.0) < 1.0e-14 and np.fabs(xn[1] - 1.0) < 1.0e-14 n4 = np.fabs(xn[0]) < 1.0e-14 and np.fabs(xn[1] - 1.0) < 1.0e-14 n5 = np.fabs(xn[0] - 2.0) < 1.0e-14 and np.fabs(xn[1] - 0.25) < 1.0e-14 n6 = np.fabs(xn[0] - 2.5) < 1.0e-14 and np.fabs(xn[1] - 0.25) < 1.0e-14 n7 = np.fabs(xn[0] - 2.5) < 1.0e-14 and np.fabs(xn[1] - 0.75) < 1.0e-14 n8 = np.fabs(xn[0] - 2.0) < 1.0e-14 and np.fabs(xn[1] - 0.75) < 1.0e-14 if n1 or n2 or n3 or n4 or n5 or n6 or n7 or n8: be1 = None be2 = None for be in mesh.BoundaryElements: if n in be: if be1 is None: be1 = be elif be2 is None: be2 = be break nx1 = n.copy() nx1.friendOF(n, 0) nx2 = n.copy() nx2.friendOF(n, 0) n.freedom[1] = False for i1, nt1 in enumerate(be1.Nodes): if n == nt1: be1.Nodes[i1] = nx1 ndup.append(nx1) for i2, nt2 in enumerate(be2.Nodes): if n == nt2: be2.Nodes[i2] = nx2 ndup.append(nx2) for n in ndup: mesh.Nodes.append(n) mesh.Nnod += 1 mesh.generateID() #mesh.Nodes[4].setLoad(loadfunc,0) return mesh
def create_mesh(): r0 = 0.0 r1 = 2.0e-2 r2 = 3.0e-2 r2x = 3.05e-2 r3 = 3.2e-2 r3x = 3.15e-2 r4 = 5.2e-2 r5 = 5.7e-2 r6 = 1.0e-1 phi = np.array([ 22.5, 37.5, 82.5, 97.5, 142.5, 157.5, 202.5, 217.5, 262.5, 277.5, 322.5, 337.5 ]) phi = d_to_r(phi) mesh = FM.MeshWithGapElement() mesh.setMaterialConstant(1.0 / (np.pi * 4.0e-7)) mesh.setNumberHarmonic(numH) mesh.setRadiusRatio(r2 / r3) basisf = QE.LagrangeBasis1D elements, belm = polarMesh(r0, r1, 0.0, 2.0 * np.pi, 50, 1, Ndof, tOrder, typ='quadring') mat_rotor = LinearMagneticMaterial(30.0, 0.0, 3.72e6, 0) elm = [ PolarMagnetic(e, [2, 2], basisf, nodeOrder, mat_rotor, intDat) for e in elements ] mesh.addElements(elm) elements, belm = polarMesh(r1, r2, 0.0, 2.0 * np.pi, 50, 2, Ndof, tOrder, typ='quadring', bnd=2) mat_ind = LinearMagneticMaterial(1.0, 0.0, 3.72e7, 1) elm = [ PolarMagnetic(e, [2, 2], basisf, nodeOrder, mat_ind, intDat) for e in elements ] mesh.addElements(elm) # elements,belm = polarMesh(r2,r2x,0.0,2.0*np.pi,30,1,Ndof,tOrder,typ='quadring',bnd=2) # mat_air = LinearMagneticMaterial(1.0,0.0,0.0,4) # elm = [PolarMagnetic(e,[2,2],basisf,nodeOrder,mat_air,intDat) for e in elements] # mesh.addElements(elm) if belm is not None: belms = [ PE.PolarElementGapBoundary(e, 2, basisf, 1.0 / (np.pi * 4.0e-7), nHarmonic=numH, rRatio=r2 / r3) for e in belm ] for e in belms: # e.current = False e.setMovingVelocity([0.0, nrad]) mesh.addGapElements(belms) for i in range(-1, len(phi) - 1): if i % 2 == 1: nr = 8 else: nr = 2 # elements,belm = polarMesh(r0,r1,phi[i],phi[i+1],nr,2,Ndof,tOrder,typ='quad') # mat_rotor = LinearMagneticMaterial(30.0,0.0,3.72e6,0) # elm = [PolarMagnetic(e,[2,2],basisf,nodeOrder,mat_rotor,intDat) for e in elements] # mesh.addElements(elm) # # elements,belm = polarMesh(r1,r2,phi[i],phi[i+1],nr,2,Ndof,tOrder,typ='quad',bnd=2) # mat_ind = LinearMagneticMaterial(1.0,0.0,3.72e7,1) # elm = [PolarMagnetic(e,[2,2],basisf,nodeOrder,mat_ind,intDat) for e in elements] # mesh.addElements(elm) # # if belm is not None: # belms = [PE.PolarElementGapBoundary(e,2,basisf,1.0/(np.pi*4.0e-7),nHarmonic=numH,rRatio=r2/r3) for e in belm] # for e in belms: # e.current = False ## e.setMovingVelocity([0.0,nrad*2.0*np.pi]) ## e.setMovingVelocity([0.0,nrad]) # mesh.addGapElements(belms) # elements,belm = polarMesh(r3x,r3,phi[i],phi[i+1],nr,1,Ndof,tOrder,typ='quadring',bnd=2) ## mat_air = LinearMagneticMaterial(1.0,0.0,0.0,4) # elm = [PolarMagnetic(e,[2,2],basisf,nodeOrder,mat_air,intDat) for e in elements] # mesh.addElements(elm) # if belm is not None: # belms = [PE.PolarElementGapBoundary(e,2,basisf,1.0/(np.pi*4.0e-7),normv=[-1.0,0.0]) for e in belm] # for e in belms: # e.current = False # mesh.addGapElements(belms) elements, belm = polarMesh(r3, r4, phi[i], phi[i + 1], nr, 2, Ndof, tOrder, typ='quad', bnd=1) mat_phase = LinearMagneticMaterial(1.0, 0.0, 0.0, 2) elm = [ PolarMagnetic(e, [2, 2], basisf, nodeOrder, mat_phase, intDat) for e in elements ] if i % 2 == 1: for e in elm: e.setBodyLoad(loadfunc[math.ceil(i / 2)], math.ceil(i / 2)) # for n in e.Nodes: # n.setLoad(loadfunc[math.ceil(i/2)],0) mesh.addElements(elm) if belm is not None: belms = [ PE.PolarElementGapBoundary(e, 2, basisf, 1.0 / (np.pi * 4.0e-7), nHarmonic=numH, rRatio=r2 / r3, normv=[-1.0, 0.0]) for e in belm ] for e in belms: e.current = False mesh.addGapElements(belms) elements, belm = polarMesh(r4, r5, phi[i], phi[i + 1], nr, 1, Ndof, tOrder, typ='quad') mat_stator = LinearMagneticMaterial(30.0, 0.0, 0.0, 3) elm = [ PolarMagnetic(e, [2, 2], basisf, nodeOrder, mat_stator, intDat) for e in elements ] mesh.addElements(elm) # elements,belm = polarMesh(r5,r6,phi[i],phi[i+1],nr,1,Ndof,tOrder,typ='quad') # mat_outside = LinearMagneticMaterial(1.0,0.0,0.0,4) # elm = [PolarMagnetic(e,[2,2],basisf,nodeOrder,mat_outside,intDat) for e in elements] # mesh.addElements(elm) for n in mesh.Nodes: if n.getX()[0] <= 1.0e-14: n.setConstraint(False, 0.0, 0) if math.fabs(n.getX()[0] - r5) < 1.0e-14: n.setConstraint(False, 0.0, 0) mesh.generateID() return mesh
def readInput(filename, nodeOrder, timeOrder, intData, Ndof=1): mesh = FM.MeshWithBoundaryElement() file = open(filename, 'r') int(file.readline().split()[1]) nnode = int(file.readline().split()[1]) nnod = int(file.readline().split()[1]) nelm = int(file.readline().split()[1]) int(file.readline().split()[1]) int(file.readline().split()[1]) file.readline() for i in range(nnod): a = list(float(x) for x in file.readline().split()) x_ = np.array(a[1:3]) mesh.addNode(FN.Node(x_, Ndof, timeOrder, i)) file.readline() for i in range(nelm): a = list(int(x) for x in file.readline().split()) nodes = [] for j in range(nnode): try: nn = findNode(mesh.getNodes(), a[j + 1] - 1) nodes.append(nn) except: continue if len(nodes) > 3: e = AxiSymMagnetic(nodes,[2,2],\ QE.LagrangeBasis1D,nodeOrder,None,intData) mesh.addElement(e) elif len(nodes) == 3: e = AxiSymMagneticBoundary(nodes,2,QE.LagrangeBasis1D,\ QE.generateQuadNodeOrder(2,1),intDatB,intSingDat,None,i) for el in mesh.getElements(): if el.hasNodes(nodes): edge = mg.Edge(nodes[0], nodes[2]) e.setNormalVector(\ edge.getNormalVector(el.getNodes()[4].getX())) break mesh.addBoundaryElement(e) file.readline() for i in range(nnod): a = list(float(x) for x in file.readline().split()) #for j in range(Ndof): # mesh.getNodes()[i].setLoad(a[j+1],j) file.readline() for i in range(nnod): a = file.readline().split() for j in range(Ndof): mesh.getNodes()[i].setConstraint(\ int(a[2*j+1])==0,float(a[2*(j+1)]),j) air = LinearMagneticMaterial(1.0, 1.0, 3.4e7, 2) cooper = LinearMagneticMaterial(1.0, 1.0, 5.0e6, 3) steel = LinearMagneticMaterial(1.0, 1.0, 0.0, 1) file.readline() for i in range(nelm): a = list(int(x) for x in file.readline().split()) if a[1] == 2: mesh.getElements()[i].setMaterial(air) if a[1] == 3: mesh.getElements()[i].setMaterial(cooper) if a[1] == 1: mesh.getElements()[i].setMaterial(steel) if mesh.getElements()[i].getNodes()[0].getX()[0] < 0.06: def loadfunc(x, t): return 20.0 * 960.0 / (0.028 * 0.052) * math.sin( 50.0 * 2.0 * np.pi * t) mesh.getElements()[i].setBodyLoad(loadfunc) else: def loadfuncx(x, t): return -20.0 * 576.0 / (0.015 * 0.052) * math.sin( 50.0 * 2.0 * np.pi * t) mesh.getElements()[i].setBodyLoad(loadfuncx) #mesh.getElements()[i].updateMat(JAMaterial(5.0e6,intData.getNumberPoint(),1)) file.close() mesh.generateID() return mesh
def create_mesh(): nodes = [] nodes.append(FN.Node([0.0, -0.2], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([0.015, -0.2], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([0.0225, -0.2], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([0.0325, -0.2], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([0.2, -0.2], Ndof, timeOrder=tOrder)) edges = [mg.Edge(nodes[i], nodes[i + 1]) for i in range(len(nodes) - 1)] geo = mg.Geometry() d = np.array([0.0, 1.0]) s = [ 0.1, 0.05, 0.014, 0.015, 0.0135, 0.015, 0.0135, 0.015, 0.014, 0.05, 0.1 ] #s = [0.1,0.064,0.015,0.0135,0.015,0.0135,0.015,0.064,0.1] for e in edges: geo.addPolygons(e.extendToQuad(d, s)) polys = geo.getPolygons() for i in range(11): polys[i].setDivisionEdge13(4) for i in range(11, 22): polys[i].setDivisionEdge13(2) for i in range(33, 44): polys[i].setDivisionEdge13(5) for i in range(0, 34, 11): polys[i].setDivisionEdge24(4) for i in range(1, 35, 11): polys[i].setDivisionEdge24(2) for i in range(9, 43, 11): polys[i].setDivisionEdge24(2) for i in range(10, 44, 11): polys[i].setDivisionEdge24(4) mat3 = LinearMagneticMaterial(1.0, 1.0, 5.0e6, 3) mat2 = LinearMagneticMaterial(1.0, 1.0, 0.0, 2) #mat1 = JAMaterial(5.0e6,9,1) mat1 = LinearMagneticMaterial(1.0, 1.0, 5.0e6, 1) for i in range(1, 10): polys[i].setMaterial(mat1) polys[25].setMaterial(mat3) polys[25].setBodyLoad(load) polys[27].setMaterial(mat3) polys[27].setBodyLoad(load) polys[29].setMaterial(mat3) polys[29].setBodyLoad(load) for poly in polys: if poly.getMaterial() is None: poly.setMaterial(mat2) geo.mesh() [nodesx, elems, mats, bdls] = geo.getMesh(None, mg.nodesQuad9, 2) #fig = geo.plot(poly_number = True, fill_mat = True) # geo.plotMesh(col = 'b-',fill_mat = True) # for i,node in enumerate(nodesx): # pl.plot(node.getX()[0],node.getX()[1],'.b') # if math.fabs(node.getX()[0] - 0.015)<1.0e-14: # pl.text(node.getX()[0],node.getX()[1],str(i)) for n in nodesx: if math.fabs(n.getX()[0]-0.0)<1.0e-14 or \ math.fabs(n.getX()[1]-0.2)<1.0e-14 or \ math.fabs(n.getX()[0]-0.2)<1.0e-14 or \ math.fabs(n.getX()[1]+0.2)<1.0e-14: n.setConstraint(False, 0.0, 0) #n.setConstraint(False, 0.0, 1) #pl.plot(n.getX()[0],n.getX()[1],'.r') elements = [] for i, e in enumerate(elems): #if mats[i] is JAMaterial: # m = JAMaterial(5.0e6,9,1) #else: # m = mats[i] m = mats[i] #elements.append(AxiSymMagnetic(e,[2,2],QE.LagrangeBasis1D,\ #QE.generateQuadNodeOrder([2,2],2),m,intDat)) elements.append(AxiSymMagnetic(e,[2,2],QE.LagrangeBasis1D,\ nodeOrder,m,intDat)) #if m.getID() == 1: # elements[-1].setLinearity(False) #if bdls[i] is not None: if elements[-1].material.getID() == 3: elements[-1].setBodyLoad(loadfunc) mesh = FM.Mesh() mesh.addNodes(nodesx) mesh.addElements(elements) return mesh
def create_simple_mesh(): nodes = [] nodes.append(FN.Node([0.0, 0.0], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([1.0, 0.0], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([2.0, 0.25], Ndof, timeOrder=tOrder)) nodes.append(FN.Node([2.5, 0.25], Ndof, timeOrder=tOrder)) edge1 = mg.Edge(nodes[0], nodes[1]) poly1 = edge1.extendToQuad(np.array([0.0, 1.0]), 1.0) edge2 = mg.Edge(nodes[2], nodes[3]) poly2 = edge2.extendToQuad(np.array([0.0, 1.0]), 0.5) poly2.setBodyLoad(1.0) poly1.setDivisionEdge24(2) geo = mg.Geometry() geo.addPolygon(poly1) geo.addPolygon(poly2) mat1 = LinearMagneticMaterial(1.0, 1.0, 5.0e6, 1) mat2 = LinearMagneticMaterial(1.0, 1.0, 5.0e6, 2) poly1.setMaterial(mat1) poly2.setMaterial(mat2) geo.mesh() [nodesx, elems, mats, bdls] = geo.getMesh(None, mg.nodesQuad9, Ndof) for n in nodesx: if math.fabs(n.getX()[0] - 0.0) < 1.0e-14: n.setConstraint(False, 0.0, 0) n.setConstraint(False, 0.0, 1) elements = [] for i, e in enumerate(elems): m = mats[i] elements.append(AxiSymMagnetic(e,[2,2],QE.LagrangeBasis1D,\ QE.generateQuadNodeOrder([2,2],2),m,intDat)) if bdls[i] is not None: def loadfunc(x, t): #return load*math.sin(8.1e3*2*np.pi*t) return load else: loadfunc = None elements[i].setBodyLoad(loadfunc) mesh = FM.MeshWithBoundaryElement() mesh.addNodes(nodesx) mesh.addElements(elements) geo.meshBoundary() [nodes1, elems1, normBndVec] = geo.getBoundaryMesh(None,\ mg.nodesBoundaryQuad9,Ndof) elementBs = [] for i, e in enumerate(elems1): elementBs.append(AxiSymMagneticBoundary(e,2,QE.LagrangeBasis1D,\ QE.generateQuadNodeOrder(2,1),intDatB,intSingDat,normBndVec[i],i)) elementBs[-1].setMaterial(mat1) for n in mesh.getNodes(): ine = False for e in elementBs: if n in e: ine = True if not ine: n.setConstraint(False, 0.0, 1) #mesh.addElements(elementBs) mesh.addBoundaryElements(elementBs) mesh.generateID() #mesh.Nodes[4].setLoad(loadfunc,0) return mesh
Ndof = 2 tOrder = 2 ndiv = [1, 2, 4, 8] res = [] for n in ndiv: filen = fldrn + str(n) + '.dat' print('reading data file: ' + filen) res100, _ = FO.StandardFileOutput.readOutput(filen, val='x') resx = res100.tolist() nodes = [] for x in resx: nodes.append(FN.Node(x, Ndof, timeOrder=tOrder)) _, inode = FM.findNodeNearX(nodes, np.array([0.015, -0.1, 0.0])) testout, tout = FO.StandardFileOutput.readOutput(filen, timeStep='all', node=inode, val='u') rest = [t[0][0] for t in testout] res.append(np.array(rest)) err = [] for i, n in enumerate(ndiv[0:-1]): err.append( np.linalg.norm(res[i + 1] - res[i]) / np.linalg.norm(res[i + 1])) #pl.plot(ndiv[0:-1],err) pl.plot(ndiv, np.array(res)[:, 200], '-x')