Exemple #1
0
def gmsh2hybridgrid(mshfile):
    """
    Convert the gmsh msh file to the hybrid grid class
    """

    celltype = {2:3,3:4} # lookup table for cell type

    # Read the raw ascii file    
    nodes, elements  = read_msh(mshfile)
    
    # Get the coordinates
    x = [nodes[ii]['X'] for ii in nodes.keys()]
    y = [nodes[ii]['Y'] for ii in nodes.keys()]
    
    cells = [elements[ii]['cells'] for ii in elements.keys() if elements[ii]['type'] in celltype.keys()]
    nfaces = [len(cells[ii]) for ii in range(len(cells))]
    
    Nc = len(cells)
    cellsin = np.zeros((Nc,max(nfaces)),np.int)-999999
    for ii in range(Nc):
        cellsin[ii,0:nfaces[ii]]=cells[ii]

    return HybridGrid(np.array(x),np.array(y),cellsin,nfaces=nfaces)    
Exemple #2
0
ylims = [y0-dx2,y0+dx2]

xgrd = np.linspace(xlims[0],xlims[1],nx)
ygrd = np.linspace(ylims[0],ylims[1],nx)

cells=[]
xp = []
yp = []

def pntindx(j,i,nrows):
    return j*nrows + i

for jj in range(nx):
    for ii in range(nx):
        xp.append(xgrd[ii])
        yp.append(ygrd[jj])

for jj in range(nx-1):
    for ii in range(nx-1):
        cells.append([pntindx(jj,ii,nx), pntindx(jj+1,ii,nx),\
            pntindx(jj+1,ii+1,nx),pntindx(jj,ii+1,nx)])
        
Nc = (nx-1)**2
nfaces = 4*np.ones((Nc,),np.int)

cells = np.array(cells)
# Convert to a suntans grid
grd = HybridGrid(xp,yp,cells,nfaces=nfaces)

grd2suntans(grd,outpath)
Exemple #3
0
"""

from sunpy import Grid
import matplotlib.pyplot as plt
import numpy as np
from hybridgrid import HybridGrid

###

ncfile = 'grid'

outpath = 'grid/hex'

sun = Grid(ncfile)
sun.neigh = sun.neigh.astype(int)

# Load the data into a hybrid grid class
grd = HybridGrid(sun.xp, sun.yp, sun.cells, nfaces=sun.nfaces)

grd.create_dual_grid(minfaces=5, outpath=outpath)

sun = Grid(outpath)

plt.figure()
sun.plotmesh(facecolors='none', linewidths=0.2)
plt.plot(sun.xv, sun.yv, 'm.')

plt.figure()
sun.plothist()
plt.show()
Exemple #4
0
import numpy as np
from hybridgrid import HybridGrid
from maptools import Polygon2GIS
###
#
ncfile = 'rundata'
###

sun = Grid(ncfile)
sun.neigh = sun.neigh.astype(int)

# Load the data into a hybrid grid class
grd = HybridGrid(sun.xp,
                 sun.yp,
                 sun.cells,
                 nfaces=sun.nfaces,
                 edges=sun.edges,
                 mark=sun.mark,
                 grad=sun.grad,
                 neigh=sun.neigh)

# Update the suntans grid with the hybrid grid features
#sun.mark = grd.mark
#sun.grad = grd.grad
#sun.neigh = grd.neigh
#sun.saveEdges(ncfile+'/edges.dat')

### Test the rotation
##cell_ccw = grd.ensure_ccw()
#
#Ac = grd.calc_area()
#