Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def generate_mesh():
"""Generates a fairly large mesh.
"""
# import meshzoo
# points, cells = meshzoo.rectangle(nx=300, ny=300)
# return meshio.Mesh(points, {"triangle": cells})
if os.path.isfile("cache.xdmf"):
mesh = meshio.read("cache.xdmf")
else:
s = pygalmesh.Ball([0, 0, 0], 1.0)
mesh = pygalmesh.generate_mesh(s, cell_size=2.0e-2, verbose=True)
# mesh = pygalmesh.generate_mesh(s, cell_size=1.0e-1, verbose=True)
mesh.cells = {"tetra": mesh.cells["tetra"]}
mesh.point_data = []
mesh.cell_data = {"tetra": {}}
mesh.write("cache.xdmf")
print(mesh)
return mesh
def pacman():
this_dir = os.path.dirname(os.path.realpath(__file__))
mesh = meshio.read(os.path.join(this_dir, "meshes", "pacman.vtk"))
return mesh.points[:, :2], mesh.get_cells_type("triangle")
geom.add_circle(
[0.0, 0.0, 0.0],
1.0,
5.0e-3,
num_sections=4,
# If compound==False, the section borders have to be points of the
# discretization. If using a compound circle, they don't; gmsh can
# choose by itself where to point the circle points.
compound=True,
)
X, cells, _, _, _ = pygmsh.generate_mesh(
geom, fast_conversion=True, remove_faces=True
)
meshio.write_points_cells(filename, X, cells)
mesh = meshio.read(filename)
c = mesh.cells["triangle"].astype(numpy.int)
X, cells = optimesh.chen_holst.odt(mesh.points, c, 1.0e-3, 100)
return
if sub:
cmd = "python pyfrp_meshIO_script.py "+ self.fnMesh
import shlex
import subprocess
args = shlex.split(cmd)
p = subprocess.Popen(args)
p.wait()
else:
#MeshIO
import meshio
points, cells, point_data, cell_data, field_data = meshio.read(self.fnMesh)
meshio.write(fn,points,cells,point_data=point_data,cell_data=cell_data,field_data=field_data)
return fn
off_file,
outfile,
lloyd=lloyd,
odt=odt,
perturb=perturb,
exude=exude,
edge_size=edge_size,
facet_angle=facet_angle,
facet_size=facet_size,
facet_distance=facet_distance,
cell_radius_edge_ratio=cell_radius_edge_ratio,
cell_size=cell_size,
verbose=verbose,
)
mesh = meshio.read(outfile)
os.remove(off_file)
os.remove(outfile)
return mesh
"""
Generate input files from a Gmsh mesh file for the Lymira bridge with
symmetry with respect to the horizontal axis.
It imposes roller constraints for the left side (x==0), right
side (x==span/2), and bottom (y==0). The loading is uniformly
distributed on top (y==rise + thickness).
"""
from __future__ import division
import meshio
import numpy as np
points, cells, point_data, cell_data, field_data = \
meshio.read("Limyra bridge arch.msh")
# We remove the first node is part of the construction
# of the geometry but not part of the mesh.
points = points[1:, :]
span = 12.75
rise = 2
thickness = 1.25
# Elements data
elements = cells["quad"]
els_array = np.ones([elements.shape[0], 7], dtype=int)
els_array[:, 0] = range(elements.shape[0])
els_array[:, 3::] = elements - 1
# Nodes data
"""
Template to generate the input files for the FEM code solids_ISO.
The script uses module meshio.py to read a GMSH mesh and produce
text files nodes.txt, eles.txt , mater.txt and loads.txt
@authors: Juan Gomez
Nicolas Guarin-Zapata
"""
from __future__ import division, print_function
from __future__ import division
import meshio
import solidspy.preprocesor as msh
import numpy as np
#
points, cells, point_data, cell_data, field_data = \
meshio.read("Boussi.msh")
#
nodes_array = msh.node_writer(points , point_data)
nf , els1_array = msh.ele_writer(cells , cell_data , "triangle" , 10000 , 3 , 0 , 0)
#
nodes_array = msh.boundary_conditions(cells , cell_data , 200 , nodes_array , -1 , 0)
nodes_array = msh.boundary_conditions(cells , cell_data , 500 , nodes_array , 0 , -1)
#
np.savetxt("eles.txt" , els1_array , fmt="%d")
np.savetxt("nodes.txt", nodes_array , fmt=("%d", "%.4f", "%.4f", "%d", "%d"))
# -*- coding: utf-8 -*-
"""
Load a GMSH mesh and plot contours for its height.
"""
import meshio
import matplotlib.pyplot as plt
from matplotlib.tri import Triangulation
from matplotlib import rcParams
rcParams['font.family'] = 'serif'
rcParams['font.size'] = 14
rcParams['image.cmap'] = "YlGnBu_r"
points, cells, point_data, cell_data, field_data = \
meshio.read("../MESHES/DAM/dam.msh")
x = points[:, 0]
y = points[:, 1]
tri = Triangulation(x, y, cells['triangle'])
plt.tricontourf(tri, y, 12, shading="gourad")
plt.axis("image")
plt.show()
nb = self.tecNb
if nb < len(self.tecdata)-1 :
if self.tecdata.iloc[nb+1,0] <= self.tNow+self.dt :
nb += 1
if nb > self.tecNb or nb == -1:
if nb == -1:
nb = 0
self.tecNb = nb
if pd.isnull(self.tecdata['tUni'][nb]):
# Horizontal displacements along X-axis
flagAdvection = False
if not pd.isnull(self.tecdata['tMapX'][nb]):
mdata = meshio.read(self.tecdata.iloc[nb,2])
tectonicX = mdata.point_data[self.tecdata.iloc[nb,5]]
flagAdvection = True
del mdata
else:
tectonicX = np.zeros(self.gpoints)
# Horizontal displacements along Y-axis
if not pd.isnull(self.tecdata['tMapY'][nb]):
mdata = meshio.read(self.tecdata.iloc[nb,3])
tectonicY = mdata.point_data[self.tecdata.iloc[nb,6]]
flagAdvection = True
del mdata
else:
tectonicY = np.zeros(self.gpoints)
# Vertical displacements
# -*- coding: utf-8 -*-
"""
Genera archivos de entrada para el programa de elementos finitos
FEM_iso para la prueba brasilera, usando 2 simetrías en el modelo.
@author: Nicolas Guarin-Zapata
@date: Mayo 18, 2017
"""
from __future__ import division, print_function
import numpy as np
import meshio
import solidspy.preprocesor as msh
points, cells, point_data, cell_data, field_data = \
meshio.read("Prueba_brasilera.msh")
nodes_array = msh.node_writer(points, point_data)
nf , els_array = msh.ele_writer(cells, cell_data, "triangle", 1000 , 3 , 0 , 0)
nodes_array = msh.boundary_conditions(cells, cell_data, 100, nodes_array, -1, 0)
nodes_array = msh.boundary_conditions(cells, cell_data, 200, nodes_array, 0, -1)
np.savetxt("eles.txt" , els_array , fmt="%d")
np.savetxt("nodes.txt", nodes_array , fmt=("%d", "%.4f", "%.4f", "%d", "%d"))