def build_structure(E,rho,A,H,B1,B2,alpha,beta,timeOrder): node1 = FN.Node([-B2,H],2,timeOrder) node1.setConstraint(False, 0.0, 0) node1.setConstraint(False, 0.0, 1) node2 = FN.Node([0.0,0.0],2,timeOrder) node2.setConstraint(True, 0.0, 0) node2.setConstraint(False, 0.0, 1) node3 = FN.Node([B1,H],2,timeOrder) node3.setConstraint(False, 0.0, 0) node3.setConstraint(True, 0.0, 1) # node3.setConstraint(False,-0.05,1) mat1 = TrussMaterial(E,A,rho) mat2 = TrussMaterial(alpha*E,A,beta*rho) # element1 = CrisfieldElement([node1,node2],timeOrder,mat2,1) # element2 = CrisfieldElement([node2,node3],timeOrder,mat1,1) element1 = NonlinearCrisfieldElement([node1,node2],timeOrder,mat2,1) element2 = NonlinearCrisfieldElement([node2,node3],timeOrder,mat1,1) node3.setLoad(-2.0*E*A*H**3/(3.0*math.sqrt(3.0)*(element2.L**3)),1) mesh = TrussMesh(2) mesh.addNode(node1) mesh.addNode(node2) mesh.addNode(node3) mesh.addElement(element1) mesh.addElement(element2) 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)) 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 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 test1(): #node1 = mg.GeneralNode([0,0],2) #node2 = mg.GeneralNode([1,0],2) #node3 = mg.GeneralNode([1,1],2) #node4 = mg.GeneralNode([0,1],2) #node5 = mg.GeneralNode([2,0],2) #node6 = mg.GeneralNode([2,1],2) node1 = fn.Node([0, 0], 2, 2) node2 = fn.Node([1, 0], 2, 2) node3 = fn.Node([1, 1], 2, 2) node4 = fn.Node([0, 1], 2, 2) node5 = fn.Node([2, 0], 2, 2) node6 = fn.Node([2, 1], 2, 2) quad = mg.Quadrilateral([node1, node2, node3, node4]) #quad.getQuadMesh() #quad.plotQuadMesh() #quadtest = Quadrilateral([node1,node2,node4,node3],[0,1,3,2]) #print(quadtest == quad) quadtest = mg.Quadrilateral([node2, node5, node6, node3]) #quadtest.addNode(node1) #quadtest.addNode(node2) #quadtest.addNode(node5) #quadtest.addNode(node6) geo = mg.Geometry() geo.addPolygon(quad) geo.addPolygon(quadtest) quad.setWeightParallelEdges(2.0, 0.7, 0.1, 0) quad.setWeightParallelEdges(2.0, 0.7, 0.1, 1) quad.setDivisionEdge13(4) quad.setDivisionEdge24(4) quadtest.setWeightParallelEdges(2.0, 0.7, 0.1, 0) quadtest.setWeightParallelEdges(2.0, 0.7, 0.1, 1) quadtest.setDivisionEdge13(4) quadtest.setDivisionEdge24(4) #quad.getQuadMesh() #quad.plotMesh() geo.mesh() fig = geo.plotMesh() [nodes, elems, mats, bdls] = geo.getMesh(fn.Node, mg.nodesQuad9, 2) for node in nodes: pl.plot(node.getX()[0], node.getX()[1], 'xb') elements = [] for e in elems: elements.append(fe.StandardElement(e,[2,2],None,[i for i in range(9)],\ None,None))
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_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
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_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 test2(): nodes = [] nodes.append(fn.Node([0.0, -0.2], 2, 2)) nodes.append(fn.Node([0.015, -0.2], 2, 2)) nodes.append(fn.Node([0.0225, -0.2], 2, 2)) nodes.append(fn.Node([0.0325, -0.2], 2, 2)) nodes.append(fn.Node([0.2, -0.2], 2, 2)) 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.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(9): polys[i].setDivisionEdge13(10) for i in range(9, 18): polys[i].setDivisionEdge13(2) for i in range(27, 36): polys[i].setDivisionEdge13(5) for i in range(0, 28, 9): polys[i].setDivisionEdge24(4) for i in range(8, 36, 9): polys[i].setDivisionEdge24(4) for i in range(1, 29, 9): polys[i].setDivisionEdge24(2) for i in range(7, 35, 9): polys[i].setDivisionEdge24(4) mat1 = test_material(1) mat2 = test_material(2) mat3 = test_material(3) for i in range(1, 8): polys[i].setMaterial(mat1) polys[20].setMaterial(mat2) polys[22].setMaterial(mat2) polys[24].setMaterial(mat2) for poly in polys: if poly.getMaterial() is None: poly.setMaterial(mat3) geo.mesh() [nodesx, elems, mats, bdls] = geo.getMesh(fn.Node, 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.0)<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): elements.append(fe.StandardElement(e,[2,2],None,[i for i in range(9)],\ mats[i],None)) if bdls[i] is not None: def loadfunc(t): return bdls[i] * math.sin(8.1e3 * 2 * np.pi * t) else: loadfunc = None elements[i].setBodyLoad(loadfunc) return [nodesx, elements]
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_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
import Mesh.FEMMesh as FM import InOut.FEMOutput as FO 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: