def A(N1, N2, l1, l2): m = RegularQuadMesh(N1 = N1, N2 = N2, l1 = l1/4., l2 = l2) def U(x,y,z,label): ymax, xmax = y.max(), x.max() ux = y/ymax*xmax uy = 0.*x uz = 0.*x return ux, uy, uz u = m.nodes.eval_vectorFunction(U) m.nodes.apply_displacement(u) m.union( m.apply_reflection(point = (l1/2., 0., 0.), normal = (1., 0., 0.) ) ) return m
def MakeMesh(self): """ Builds the mesh """ Ri = self.inner_radius Ro = self.outer_radius thickness = self.thickness Nr, Nt, Na = self.Nr, self.Nt, self.Na mesh = RegularQuadMesh(Nt, Nr, .25, Ro - Ri, name = self.elType) mesh.nodes.add_set_by_func('left_nodes', lambda x, y, z, labels: x == 0.) mesh.nodes.add_set_by_func('right_nodes', lambda x, y, z, labels: x == .25) def function(x, y, z, labels): theta = 2 * np.pi * (.25 - x) r = y + Ri ux = -x + r * np.cos(theta) uy = -y + r * np.sin(theta) uz = 0. * z return ux, uy, uz vectorField = mesh.nodes.eval_vectorFunction(function) mesh.nodes.apply_displacement(vectorField) nodes = mesh.nodes for i in xrange(len(nodes.labels)): if nodes.x[i] < 0.: nodes.x[i] = 0. mesh.add_set('all_elements', mesh.labels) mesh.add_set('surface_elements',range( Nt * (Nr-1)+1, Nt*Nr+1 )) mesh.add_surface('surface_faces',[ ('surface_elements',3) ]) if self.is_3D: mesh = mesh.extrude(N = Na, l = thickness, mapping = {self.elType: self.elType}) self.mesh = mesh
def Y(N1, N2, l1, l2): m = A(N1, N2 / 2, l1, l2 / 2.) m = m.apply_reflection(point=(0., l2 / 2., 0.), normal=(0., 1., 0.)) m2 = RegularQuadMesh(N1=2 * N1, N2=N2 / 2, l1=l1 / 2., l2=l2 / 2.) m2.nodes.translate(x=l1 / 4.) m.union(m2) return m
def P(N1, N2, l1, l2): m = RegularQuadMesh(N1 = N1, N2 = N2, l1 = l1/4., l2 = l2) m1 = RegularQuadMesh(N1 = N2, N2 = N1, l1 = 1., l2 = l2/6.) def U(x, y, z, labels): r0y = l2/12. r0x = r0y theta = np.pi * (x-.5) rx = y + r0x ry = y + r0y ux = -x + rx * np.cos(theta) uy = -y + ry * np.sin(theta) uz = 0. * z return ux, uy, uz u = m1.nodes.eval_vectorFunction(U) m1.nodes.apply_displacement(u) m1.nodes.translate(x = l1/4., y = 3.*l2/4.) m.union(m1) return m
from abapy.mesh import Mesh, Nodes, RegularQuadMesh import matplotlib.pyplot as plt from numpy import cos, sin, pi from copy import copy def function(x, y, z, labels): r0 = 1. theta = 2 * pi * x r = y + r0 ux = -x + r * cos(theta) uy = -y + r * sin(theta) uz = 0. * z return ux, uy, uz N1, N2 = 100, 25 l1, l2 = .75, 1. Ncolor = 20 mesh = RegularQuadMesh(N1 = N1, N2 = N2, l1 = l1, l2 = l2) vectorField = mesh.nodes.eval_vectorFunction(function) mesh.nodes.apply_displacement(vectorField) field = vectorField.get_coord(2) # we chose to plot coordinate 2 field2 = vectorField.get_coord(2) # we chose to plot coordinate 2 x,y,z = mesh.get_edges() # Mesh edges X,Y,Z,tri = mesh.dump2triplot() xb,yb,zb = mesh.get_border() # mesh borders xe, ye, ze = mesh.get_edges() fig = plt.figure(figsize=(10,10)) fig.gca().set_aspect('equal') plt.axis('off') plt.plot(xb,yb,'k-', linewidth = 2.) plt.plot(xe, ye,'k-', linewidth = .5) plt.tricontour(X,Y,tri,field.data, Ncolor, colors = 'black') color = plt.tricontourf(X,Y,tri,field.data, Ncolor)
from abapy.indentation import Hanson from abapy.mesh import Mesh, Nodes, RegularQuadMesh from matplotlib import pyplot as plt import numpy as np """ =========== Hanson model for conical indentation =========== """ H = Hanson(F=1., E=1., nu=0.3, half_angle=70.29) Ne = 20 mesh = RegularQuadMesh(N1=Ne, N2=Ne, l1=H.a * 2., l2=H.a * 2., dtf='d') mesh.nodes.translate(H.a / 20., H.a / 20.) S = mesh.nodes.eval_tensorFunction(H.sigma) R, Z, T, tri = mesh.dump2triplot() R, Z = np.array(R), np.array(Z) # Some fields srr = S.get_component(11) szz = S.get_component(22) stt = S.get_component(33) srz = S.get_component(12) smises = S.vonmises() s1, s2, s3, v1, v2, v3 = S.eigen() # Eigenvalues and eigenvectors data = smises.data N = 20 levels = np.linspace(0., max(data), N) a = H.a
def function(x, y, z, labels): r0 = 1.0 theta = 0.5 * np.pi * x r = y + r0 ux = -x + r * np.cos(theta ** 2) uy = -y + r * np.sin(theta ** 2) uz = 0.0 * z return ux, uy, uz N1, N2 = 30, 30 l1, l2 = 0.75, 1.0 m = RegularQuadMesh(N1=N1, N2=N2, l1=l1, l2=l2) vectorField = m.nodes.eval_vectorFunction(function) m.nodes.apply_displacement(vectorField) patches = m.dump2polygons() volume = m.volume() bb = m.nodes.boundingBox() patches.set_facecolor(None) # Required to allow face color patches.set_array(volume) patches.set_linewidth(1.0) fig = plt.figure(0) plt.clf() ax = fig.add_subplot(111) ax.set_aspect("equal") ax.add_collection(patches) plt.legend() cbar = plt.colorbar(patches)
s_tt = -(1. - 2. * nu) / (2. * pi * rho**2) * (z / rho - rho / (rho + z)) #s_tt = ( 1. - 2. * nu) / (2. * pi ) * ( 1. / r**2 -z/( rho * r**2) -z / rho**3 ) s_rz = -3. / (2. * pi) * r * z**2 / rho**5 s_rt = zeros_like(r) s_zt = zeros_like(r) return s_rr, s_zz, s_tt, s_rz, s_rt, s_zt return ux, uy, uz N1, N2 = 50, 50 l1, l2 = 1., 1. Ncolor = 200 levels = linspace(0., 10., 20) mesh = RegularQuadMesh(N1=N1, N2=N2, l1=l1, l2=l2) # Finding the node located at x = y =0.: nodes = mesh.nodes for i in xrange(len(nodes.labels)): if nodes.x[i] == 0. and nodes.y[i] == 0.: node = nodes.labels[i] mesh.drop_node(node) tensorField = mesh.nodes.eval_tensorFunction(boussinesq) field = tensorField.get_component(22) # sigma_zz field2 = tensorField.vonmises() # von Mises stress field3 = tensorField.pressure() # pressure fig = plt.figure(figsize=(16, 4)) ax = fig.add_subplot(131) ax2 = fig.add_subplot(132) ax3 = fig.add_subplot(133) ax.set_aspect('equal')
from abapy.mesh import RegularQuadMesh, Mesh from matplotlib import pyplot as plt m = RegularQuadMesh(N1=2, N2=2) m.add_set('el_set', [1, 2]) m.add_surface('my_surface', [ ('el_set', 2), ]) m2 = m.extrude(l=1., N=2) x, y, z = m.get_edges() x2, y2, z2 = m2.get_edges() # Adding some 3D "home made" perspective: zx, zy = .3, .3 for i in xrange(len(x2)): if x2[i] != None: x2[i] += zx * z2[i] y2[i] += zy * z2[i] # Plotting stuff plt.figure() plt.clf() plt.gca().set_aspect('equal') plt.axis('off') plt.plot(x, y, 'b-', linewidth=4., label='Orginal Mesh') plt.plot(x2, y2, 'r-', linewidth=1., label='Extruded mesh') plt.legend() plt.show()
from abapy.mesh import RegularQuadMesh from matplotlib import pyplot as plt N1, N2 = 30, 5 # Number of elements l1, l2 = 4.0, 1.0 # Mesh size fs = 20.0 # fontsize mesh = RegularQuadMesh(N1, N2, l1, l2) plt.figure(figsize=(8, 3)) plt.gca().set_aspect("equal") nodes = mesh.nodes xn, yn, zn = nodes.x, nodes.y, nodes.z # Nodes coordinates xe, ye, ze = mesh.get_edges() # Mesh edges xb, yb, zb = mesh.get_border() # Mesh border plt.plot(xe, ye, "r-", label="edges") plt.plot(xb, yb, "b-", label="border") plt.plot(xn, yn, "go", label="nodes") plt.xlim([-0.1 * l1, 1.1 * l1]) plt.ylim([-0.1 * l2, 1.1 * l2]) plt.xticks([0, l1], ["$0$", "$l_1$"], fontsize=fs) plt.yticks([0, l2], ["$0$", "$l_2$"], fontsize=fs) plt.xlabel("$N_1$", fontsize=fs) plt.ylabel("$N_2$", fontsize=fs) plt.legend() plt.show()
def function(x, y, z, labels): r0 = 1. theta = .5 * np.pi * x r = y + r0 ux = -x + r * np.cos(theta**2) uy = -y + r * np.sin(theta**2) uz = 0. * z return ux, uy, uz N1, N2 = 30, 30 l1, l2 = .75, 1. m = RegularQuadMesh(N1 = N1, N2 = N2, l1 = l1, l2 = l2) vectorField = m.nodes.eval_vectorFunction(function) m.nodes.apply_displacement(vectorField) patches = m.dump2polygons() bb = m.nodes.boundingBox() patches.set_linewidth(1.) fig = plt.figure(0) plt.clf() ax = fig.add_subplot(111) ax.set_aspect("equal") ax.add_collection(patches) plt.grid() plt.xlim(bb[0]) plt.ylim(bb[1]) plt.xlabel("$x$ position") plt.ylabel("$y$ position")
from abapy.mesh import RegularQuadMesh N1, N2 = 2, 2 l1, l2 = 1., 1. mesh1 = RegularQuadMesh(N1=N1, N2=N2, l1=l1, l2=l2) mesh2 = RegularQuadMesh(N1=N1, N2=N2, l1=l1, l2=l2) mesh2.translate(x=l1, y=l2)
from abapy.mesh import RegularQuadMesh N1,N2 = 2,2 l1, l2 = 1., 1. mesh1 = RegularQuadMesh(N1 = N1, N2 = N2, l1 = l1, l2 = l2) mesh2 = RegularQuadMesh(N1 = N1, N2 = N2, l1 = l1, l2 = l2) mesh2.translate(x = l1, y = l2)
from abapy.postproc import FieldOutput, VectorFieldOutput from abapy.mesh import RegularQuadMesh mesh = RegularQuadMesh() data1 = [2, 2, 5, 10] data2 = [1.0 for i in data1] labels = range(1, len(data1) + 1) fo1, fo2 = ( FieldOutput(labels=labels, data=data1, position="node"), FieldOutput(labels=labels, data=data2, position="node"), ) vector = VectorFieldOutput(data1=fo1, data2=fo2) out = mesh.dump2vtk() + vector.dump2vtk() f = open("vector.vtk", "w") f.write("out") f.close()
def function(x, y, z, labels): r0 = 1. theta = .5 * np.pi * x r = y + r0 ux = -x + r * np.cos(theta**2) uy = -y + r * np.sin(theta**2) uz = 0. * z return ux, uy, uz N1, N2, N3 = 10, 10, 5 l1, l2, l3 = .75, 1., 1. m = RegularQuadMesh(N1 = N1, N2 = N2, l1 = l1, l2 = l2) m = m.extrude(l = l3, N = N3 ) vectorField = m.nodes.eval_vectorFunction(function) m.nodes.apply_displacement(vectorField) patches = m.dump2polygons(use_3D = True, face_color = None, edge_color = "black") bb = m.nodes.boundingBox() patches.set_linewidth(1.) fig = plt.figure(0) plt.clf() ax = a3.Axes3D(fig) ax.set_aspect("equal") ax.add_collection3d(patches) plt.xlim(bb[0])
def function(x, y, z, labels): r0 = 1. theta = .5 * np.pi * x r = y + r0 ux = -x + r * np.cos(theta**2) uy = -y + r * np.sin(theta**2) uz = 0. * z return ux, uy, uz N1, N2, N3 = 10, 10, 5 l1, l2, l3 = .75, 1., 1. m = RegularQuadMesh(N1=N1, N2=N2, l1=l1, l2=l2) m = m.extrude(l=l3, N=N3) vectorField = m.nodes.eval_vectorFunction(function) m.nodes.apply_displacement(vectorField) patches = m.dump2polygons(use_3D=True, face_color=None, edge_color="black") bb = m.nodes.boundingBox() patches.set_linewidth(1.) fig = plt.figure(0) plt.clf() ax = a3.Axes3D(fig) ax.set_aspect("equal") ax.add_collection3d(patches) plt.xlim(bb[0]) plt.ylim(bb[1]) plt.xlabel("$x$ position")
theta = .5 * np.pi * x r = y + r0 ux = -x + r * np.cos(theta**2) uy = -y + r * np.sin(theta**2) uz = 0. * z return ux, uy, uz def scalar_function(x, y, z, labels): """ Scalar function used to produced the plotted field. """ return x**2 + y**2 #MESH GENERATION N1, N2 = 30, 30 l1, l2 = .75, 1. m = RegularQuadMesh(N1 = N1, N2 = N2, l1 = l1, l2 = l2) #FIELDS GENERATION u = m.nodes.eval_vectorFunction(vector_function) m.add_field(u, "u") f = m.nodes.eval_function(scalar_function) m.add_field(f, "f") #PLOTS fig = plt.figure(0) plt.clf() ax = fig.add_subplot(1,1,1) m.draw(ax, disp_func = lambda fields : fields["u"], field_func = lambda fields : fields["f"], cmap = cm.jet, cbar_orientation = "vertical", contour = False,
s_tt = -( 1. - 2. * nu) / (2. * pi * rho**2 ) * ( z/rho - rho / (rho + z) ) #s_tt = ( 1. - 2. * nu) / (2. * pi ) * ( 1. / r**2 -z/( rho * r**2) -z / rho**3 ) s_rz = -3./ (2. * pi) * r * z**2 / rho **5 s_rt = zeros_like(r) s_zt = zeros_like(r) return s_rr, s_zz, s_tt, s_rz, s_rt, s_zt return ux, uy, uz N1, N2 = 50, 50 l1, l2 = 1., 1. Ncolor = 200 levels = linspace(0., 10., 20) mesh = RegularQuadMesh(N1 = N1, N2 = N2, l1 = l1, l2 = l2) # Finding the node located at x = y =0.: nodes = mesh.nodes for i in xrange(len(nodes.labels)): if nodes.x[i] == 0. and nodes.y[i] == 0.: node = nodes.labels[i] mesh.drop_node(node) tensorField = mesh.nodes.eval_tensorFunction(boussinesq) field = tensorField.get_component(22) # sigma_zz field2 = tensorField.vonmises() # von Mises stress field3 = tensorField.pressure() # pressure fig = plt.figure(figsize=(16,4)) ax = fig.add_subplot(131) ax2 = fig.add_subplot(132) ax3 = fig.add_subplot(133) ax.set_aspect('equal')
from abapy.mesh import RegularQuadMesh from matplotlib import pyplot as plt N1,N2 = 20,20 l1, l2 = 1., 1. mesh1 = RegularQuadMesh(N1 = N1, N2 = N2, l1 = l1, l2 = l2, name = 'mesh1_el') mesh2 = RegularQuadMesh(N1 = N1, N2 = N2, l1 = l1, l2 = l2, name = 'mesh2_el') mesh2.add_set('set2',[1,3]) mesh2.nodes.translate(x = l1, y = l2) mesh1.union(mesh2) plt.figure() xe, ye, ze = mesh1.get_edges() plt.plot(xe, ye) plt.show()
from abapy.mesh import RegularQuadMesh mesh = RegularQuadMesh() mesh.add_surface('topsurface', [ ('top', 1) ]) mesh.add_surface('topsurface', [ ('top', 2) ]) mesh.surfaces
from abapy.mesh import RegularQuadMesh N1, N2 = 1, 1 mesh = RegularQuadMesh(N1, N2) nodes = mesh.nodes nodes.replace_node(1, 2) print (nodes)
from abapy.mesh import Mesh, Nodes, RegularQuadMesh import matplotlib.pyplot as plt from numpy import cos, pi def function(x, y, z, labels): r = (x**2 + y**2)**.5 return cos(2*pi*x)*cos(2*pi*y)/(r+1.) N1, N2 = 30, 30 l1, l2 = 1., 1. Ncolor = 10 mesh = RegularQuadMesh(N1 = N1, N2 = N2, l1 = l1, l2 = l2) field = mesh.nodes.eval_function(function) fig = plt.figure(figsize=(16,4)) ax = fig.add_subplot(131) ax2 = fig.add_subplot(132) ax3 = fig.add_subplot(133) ax.set_aspect('equal') ax2.set_aspect('equal') ax3.set_aspect('equal') ax.set_xticks([]) ax.set_yticks([]) ax2.set_xticks([]) ax2.set_yticks([]) ax3.set_xticks([]) ax3.set_yticks([]) ax.set_frame_on(False) ax2.set_frame_on(False) ax3.set_frame_on(False) ax.set_title('Orginal Mesh') ax2.set_title('Triangularized Mesh') ax3.set_title('Field') x,y,z = mesh.get_edges() # Mesh edges
from abapy.mesh import RegularQuadMesh from matplotlib import pyplot as plt # Creating a mesh m = RegularQuadMesh(N1 = 2, N2 = 2) x0, y0, z0 = m.get_edges() # Finding the node located at x = y =0.: nodes = m.nodes for i in xrange(len(nodes.labels)): if nodes.x[i] == 0. and nodes.y[i] == 0.: node = nodes.labels[i] # Removing this node m.drop_node(node) x1, y1, z1 = m.get_edges() bbx, bby, bbz = m.nodes.boundingBox() plt.figure() plt.clf() plt.gca().set_aspect('equal') plt.axis('off') plt.xlim(bbx) plt.ylim(bby) plt.plot(x0,y0, 'r-', linewidth = 2., label = 'Removed element') plt.plot(x1,y1, 'b-', linewidth = 2., label = 'New mesh') plt.legend() plt.show()
from abapy.mesh import RegularQuadMesh from matplotlib import pyplot as plt N1, N2 = 20, 20 l1, l2 = 1., 1. mesh1 = RegularQuadMesh(N1=N1, N2=N2, l1=l1, l2=l2, name='mesh1_el') mesh2 = RegularQuadMesh(N1=N1, N2=N2, l1=l1, l2=l2, name='mesh2_el') mesh2.add_set('set2', [1, 3]) mesh2.nodes.translate(x=l1, y=l2) mesh1.union(mesh2) plt.figure() xe, ye, ze = mesh1.get_edges() plt.plot(xe, ye) plt.show()
""" Bousinesq model =============== """ Bo = CFE.Boussinesq(F = 10.) """ Mesh model """ N1, N2 = 50, 50 l1, l2 = 1., 1. Ncolor = 200 levels = linspace(0., 10., 20) mesh = RegularQuadMesh(N1 = N1, N2 = N2, l1 = l1, l2 = l2) nodes = mesh.nodes tensorField = mesh.nodes.eval_tensorFunction(Bo.sigma_boussinesq()) sigma_zz = tensorField.get_component(22) VM = tensorField.vonmises() P = tensorField.pressure() xt,yt,zt = mesh.convert2tri3().get_edges() xb,yb,zb = mesh.get_border() X,Y,Z,tri = mesh.dump2triplot() """ Display of stress fields """
from abapy.mesh import RegularQuadMesh, Mesh from matplotlib import pyplot as plt from array import array from abapy.indentation import IndentationMesh m = RegularQuadMesh(N1=2, N2=2) m.connectivity[2] = array(m.dti, [5, 7, 4]) m.connectivity[3] = array(m.dti, [5, 6, 9]) m.add_set('el_set', [1, 2]) m.add_set('el_set2', [2, 4]) m.add_surface('my_surface', [ ('el_set', 1), ]) m2 = m.sweep(sweep_angle=70., N=2, extrude=True) x, y, z = m.get_edges() x2, y2, z2 = m2.get_edges() # Adding some 3D "home made" perspective: zx, zy = .3, .3 for i in range(len(x2)): if x2[i] != None: x2[i] += zx * z2[i] y2[i] += zy * z2[i] # Plotting stuff plt.figure() plt.clf() plt.gca().set_aspect('equal') plt.axis('off') plt.plot(x, y, 'b-', linewidth=4., label='Orginal Mesh') plt.plot(x2, y2, 'r-', linewidth=1., label='Sweeped mesh')
from abapy.postproc import FieldOutput, VectorFieldOutput from abapy.mesh import RegularQuadMesh mesh = RegularQuadMesh() data1 = [2, 2, 5, 10] data2 = [1. for i in data1] labels = range(1, len(data1) + 1) fo1, fo2 = FieldOutput(labels=labels, data=data1, position='node'), FieldOutput( labels=labels, data=data2, position='node') vector = VectorFieldOutput(data1=fo1, data2=fo2) out = mesh.dump2vtk() + vector.dump2vtk() f = open('vector.vtk', 'w') f.write("out") f.close()
def MakeInp(self): pattern = """**---------------------------------- **DISTRIBUTED MECHANICAL PROPERTIES **---------------------------------- **HEADER *Preprint, echo=NO, model=NO, history=NO, contact=NO **---------------------------------- ** PART "pSAMPLE" DEFINITION *Part, name = pSample #MESH #SECTIONS *End part **---------------------------------- ** ASSEMBLY *Assembly, name = Assembly *Instance, name=iSample, part=pSample *End Instance *End Assembly **---------------------------------- ** MATERIALS #MATERIALS **---------------------------------- ** STEPS *Step, Name=Loading0, Nlgeom=YES, Inc=1000000 *Static #FRAME_DURATION, 1, 1e-08, #FRAME_DURATION ** BOUNDARY CONDITIONS *Boundary iSample.Bottom, 2, 2 iSample.BottomLeft, 1, 1#3DBOUNDARY iSample.Top, 2, 2, #DISP ** RESTART OPTIONS *Restart, write, frequency=0 ** FIELD OUTPUTS *Output, field, frequency=999999 *Node Output U *Element Output, directions=YES E, PE, EE, PEEQ, S ** HYSTORY OUTPUTS *Output, history *Energy Output ALLPD, ALLSE, ALLWK *Node Output, nset=iSample.Top RF2 *Node Output, nset=iSample.TopLeft U2 *Node Output, nset=iSample.Left COOR1 *Node Output, nset=iSample.Right COOR1 *Element Output, elset=iSample.allElements, directions=NO EVOL *End Step """ Nx , Ny, Nz = self.Nx, self.Ny, self.Nz lx, ly, lz = self.lx, self.ly, self.lz elType = self.elType material = self.material disp = self.disp nFrames = self.nFrames if self.is_3D: Ne = Nx * Ny * Nz else: Ne = Nx * Ny sections = "" matinp = "" if self.compart: section_pattern = "*Solid Section, elset=Elset{0}, material={1}\n*Elset, Elset=Elset{0}\n{0},\n" labels = [mat.labels[0] for mat in material] for i in xrange(Ne): sections += section_pattern.format(i+1, labels[i]) matinp += material[i].dump2inp() + '\n' else: section_pattern = "*SOLID SECTION, ELSET = ALLELEMENTS, MATERIAL = {0}\n{1}" label = material.labels[0] sections = section_pattern.format(label, self.lz) matinp = material.dump2inp() m = RegularQuadMesh(Nx, Ny, l1= lx, l2 = ly, name = elType) m.add_set(label = "AllElements", elements = m.labels) nsets = copy.copy(m.nodes.sets) if self.is_3D: m = m.extrude(N = Nz, l = lz) m.nodes.sets['bottomleft'] = nsets['bottomleft'] m.nodes.sets['bottomright'] = nsets['bottomright'] pattern = pattern.replace("#MESH", m.dump2inp()) pattern = pattern.replace("#SECTIONS", sections[:-1]) pattern = pattern.replace("#MATERIALS", matinp[:-1]) pattern = pattern.replace("#DISP", str(disp)) pattern = pattern.replace("#FRAME_DURATION", str(1./nFrames)) if self.is_3D: pattern = pattern.replace("#3DBOUNDARY", "\niSample.BottomLeft, 3, 3\niSample.BottomRight, 3, 3") else: pattern = pattern.replace("#3DBOUNDARY", "") f = open(self.workdir + self.label + '.inp', 'wb') f.write(pattern) f.close()
Vector function used to produced the displacement field. """ r0 = 1. theta = .5 * np.pi * x r = y + r0 ux = -x + r * np.cos(theta**2) uy = -y + r * np.sin(theta**2) uz = 0. * z return ux, uy, uz def scalar_function(x, y, z, labels): """ Scalar function used to produced the plotted field. """ return x**2 + y**2 #MESH GENERATION N1, N2, N3 = 8, 8, 8 l1, l2, l3 = .75, 1., .5 m = RegularQuadMesh(N1 = N1, N2 = N2, l1 = l1, l2 = l2).extrude(N = N3, l = l3) #FIELDS GENERATION s = m.nodes.eval_tensorFunction(tensor_function) m.add_field(s, "s") u = m.nodes.eval_vectorFunction(vector_function) m.add_field(u, "u") m.nodes.apply_displacement(u) f = m.nodes.eval_function(scalar_function) m.add_field(f, "f") m.dump2vtk("Mesh-dump2vtk.vtk")
from abapy.mesh import RegularQuadMesh mesh = RegularQuadMesh() mesh.add_surface('topsurface', [('top', 1)]) mesh.add_surface('topsurface', [('top', 2)]) mesh.surfaces
from abapy.mesh import RegularQuadMesh, Mesh from matplotlib import pyplot as plt from array import array from abapy.indentation import IndentationMesh m = RegularQuadMesh(N1 = 2, N2 =2) m.connectivity[2] = array(m.dti,[5, 7, 4]) m.connectivity[3] = array(m.dti,[5, 6, 9]) m.add_set('el_set',[1,2]) m.add_set('el_set2',[2,4]) m.add_surface('my_surface',[('el_set',1),]) m2 = m.sweep(sweep_angle = 70., N = 2, extrude=True) x,y,z = m.get_edges() x2,y2,z2 = m2.get_edges() # Adding some 3D "home made" perspective: zx, zy = .3, .3 for i in xrange(len(x2)): if x2[i] != None: x2[i] += zx * z2[i] y2[i] += zy * z2[i] # Plotting stuff plt.figure() plt.clf() plt.gca().set_aspect('equal') plt.axis('off') plt.plot(x,y, 'b-', linewidth = 4., label = 'Orginal Mesh') plt.plot(x2,y2, 'r-', linewidth = 1., label = 'Sweeped mesh') plt.legend() plt.show()
def function(x, y, z, labels): r0 = 1. theta = .5 * np.pi * x r = y + r0 ux = -x + r * np.cos(theta**2) uy = -y + r * np.sin(theta**2) uz = 0. * z return ux, uy, uz N1, N2 = 30, 30 l1, l2 = .75, 1. m = RegularQuadMesh(N1=N1, N2=N2, l1=l1, l2=l2) vectorField = m.nodes.eval_vectorFunction(function) m.nodes.apply_displacement(vectorField) patches = m.dump2polygons() bb = m.nodes.boundingBox() patches.set_linewidth(1.) fig = plt.figure(0) plt.clf() ax = fig.add_subplot(111) ax.set_aspect("equal") ax.add_collection(patches) plt.grid() plt.xlim(bb[0]) plt.ylim(bb[1]) plt.xlabel("$x$ position")
uy = -y + r * np.sin(theta**2) uz = 0. * z return ux, uy, uz def scalar_function(x, y, z, labels): """ Scalar function used to produced the plotted field. """ return x**2 + y**2 # MESH GENERATION N1, N2 = 30, 30 l1, l2 = .75, 1. m = RegularQuadMesh(N1=N1, N2=N2, l1=l1, l2=l2) # FIELDS GENERATION u = m.nodes.eval_vectorFunction(vector_function) m.add_field(u, "u") f = m.nodes.eval_function(scalar_function) m.add_field(f, "f") # PLOTS fig = plt.figure(0) plt.clf() ax = fig.add_subplot(1, 1, 1) m.draw(ax, disp_func=lambda fields: fields["u"], field_func=lambda fields: fields["f"], cmap=cm.jet, cbar_orientation="vertical", contour=False,
from abapy.mesh import RegularQuadMesh N = 1 l1, l2 = 1., 2. mesh = RegularQuadMesh(N1=N, N2=N, l1=l1, l2=l2) mesh.nodes.closest_node(1)
from abapy.mesh import RegularQuadMesh from matplotlib import pyplot as plt N1, N2 = 30, 5 # Number of elements l1, l2 = 4., 1. # Mesh size fs = 20. # fontsize mesh = RegularQuadMesh(N1, N2, l1, l2) plt.figure(figsize=(8, 3)) plt.gca().set_aspect('equal') nodes = mesh.nodes xn, yn, zn = nodes.x, nodes.y, nodes.z # Nodes coordinates xe, ye, ze = mesh.get_edges() # Mesh edges xb, yb, zb = mesh.get_border() # Mesh border plt.plot(xe, ye, 'r-', label='edges') plt.plot(xb, yb, 'b-', label='border') plt.plot(xn, yn, 'go', label='nodes') plt.xlim([-.1 * l1, 1.1 * l1]) plt.ylim([-.1 * l2, 1.1 * l2]) plt.xticks([0, l1], ['$0$', '$l_1$'], fontsize=fs) plt.yticks([0, l2], ['$0$', '$l_2$'], fontsize=fs) plt.xlabel('$N_1$', fontsize=fs) plt.ylabel('$N_2$', fontsize=fs) plt.legend() plt.show()
from abapy.mesh import RegularQuadMesh N1, N2 = 1, 1 mesh = RegularQuadMesh(N1, N2) mesh.replace_node(1, 2) print(mesh)
from abapy.mesh import RegularQuadMesh N1, N2 = 1,1 mesh = RegularQuadMesh(N1, N2) mesh.replace_node(1,2) print mesh
from abapy.indentation import Hanson from abapy.mesh import Mesh, Nodes, RegularQuadMesh from matplotlib import pyplot as plt import numpy as np """ =========== Hanson model for conical indentation =========== """ H = Hanson(F = 1., E=1., nu = 0.3, half_angle = 70.29) Ne = 20 mesh = RegularQuadMesh(N1 = Ne, N2 = Ne, l1 = H.a * 2., l2 = H.a * 2., dtf = 'd') mesh.nodes.translate(H.a/20., H.a/20.) S = mesh.nodes.eval_tensorFunction(H.sigma) R,Z,T,tri = mesh.dump2triplot() R, Z = np.array(R), np.array(Z) # Some fields srr = S.get_component(11) szz = S.get_component(22) stt = S.get_component(33) srz = S.get_component(12) smises = S.vonmises() s1, s2, s3, v1, v2, v3 = S.eigen() # Eigenvalues and eigenvectors data = smises.data N = 20 levels = np.linspace(0., max(data), N) a = H.a
from abapy.mesh import RegularQuadMesh from matplotlib import pyplot as plt # Creating a mesh m = RegularQuadMesh(N1=2, N2=2) x0, y0, z0 = m.get_edges() # Finding the node located at x = y =0.: nodes = m.nodes for i in xrange(len(nodes.labels)): if nodes.x[i] == 0. and nodes.y[i] == 0.: node = nodes.labels[i] # Removing this node m.drop_node(node) x1, y1, z1 = m.get_edges() bbx, bby, bbz = m.nodes.boundingBox() plt.figure() plt.clf() plt.gca().set_aspect('equal') plt.axis('off') plt.xlim(bbx) plt.ylim(bby) plt.plot(x0, y0, 'r-', linewidth=2., label='Removed element') plt.plot(x1, y1, 'b-', linewidth=2., label='New mesh') plt.legend() plt.show()
from abapy.mesh import RegularQuadMesh, Mesh from matplotlib import pyplot as plt m = RegularQuadMesh(N1 = 2, N2 =2) m.add_set('el_set',[1,2]) m.add_surface('my_surface',[('el_set',2), ]) m2 = m.extrude(l = 1., N = 2) x,y,z = m.get_edges() x2,y2,z2 = m2.get_edges() # Adding some 3D "home made" perspective: zx, zy = .3, .3 for i in xrange(len(x2)): if x2[i] != None: x2[i] += zx * z2[i] y2[i] += zy * z2[i] # Plotting stuff plt.figure() plt.clf() plt.gca().set_aspect('equal') plt.axis('off') plt.plot(x,y, 'b-', linewidth = 4., label = 'Orginal Mesh') plt.plot(x2,y2, 'r-', linewidth = 1., label = 'Extruded mesh') plt.legend() plt.show()