Re: [swanmodel-users] converting fort.14 to element and node files
Brought to you by:
mzijlema
|
From: Alexander C. <al...@oc...> - 2016-08-17 15:40:09
|
Here is a python script I wrote a while ago to do this. It hasn't been
particularly optimized or well tested but you could give it a shot
(Requires the python library numpy to be installed. Call like "python
script.py fort.14 outputmeshname":
import sys
import numpy as np
import warnings
from cStringIO import StringIO as StringIO
vertex_format = '%10d %10.4f %10.4f %3d\n'
triangle_format = '%10d %10d %10d %10d\n'
def vert2str(vertices, bound):
index = 1
if bound is not None:
bound = bound.astype(int)
for i in xrange(vertices.shape[0]):
if bound is None:
yield vertex_format % (index, vertices[i, 0], vertices[i, 1], 0)
else:
yield vertex_format % (index, vertices[i, 0], vertices[i, 1], bound[i])
index += 1
def topo2str(topology):
index = 1
for i in xrange(topology.shape[0]):
yield triangle_format % (index, topology[i, 0], topology[i, 1], topology[i, 2])
index += 1
def write_triangulation(outputpath, vertices, topology, boundaries=None):
vertices = np.array(vertices) # Assumes [[x0, y0], [x1, y1], ...]
topology = np.array(topology) # Assumes dim=1 is length 3
if vertices.shape[1] != 2:
vertices = vertices.T
if vertices.shape[0] == 2:
raise ValueError('Cannot output triangulation with 2 points.')
if topology.shape[1] != 3:
topology = topology.T
if topology.shape[0] == 3:
raise warnings.warn('Make sure that dim=0 is the triangle varying dimension.', Warning)
with open(outputpath + '.node', 'w') as node:
node.write("%d 2 0 1\n" % (vertices.shape[0],))
for vertex in vert2str(vertices, boundaries):
node.write(vertex)
with open(outputpath + '.ele', 'w') as element:
element.write("%d 3 0\n" % (topology.shape[0],))
for triangle in topo2str(topology):
element.write(triangle)
mesh = {}
vertstr = ""
elestr = ""
with open(sys.argv[1]) as f:
header = f.readline()
line = f.readline()
numele, numvert = tuple([int(x) for x in line.split()])
for i in xrange(numvert):
vertstr += f.readline()
tempverts = np.loadtxt(StringIO(vertstr))
assert int(tempverts[-1, 0]) == numvert
mesh['vertices'] = tempverts[:, 1:-1]
for i in xrange(numele):
elestr += f.readline()
tempele = np.loadtxt(StringIO(elestr), dtype=np.int)
assert int(tempele[-1, 0]) == numele
assert (tempele[:, 1] == 3).all()
mesh['triangles'] = tempele[:, 2:]
nope = int(f.readline().split()[0])
numbverts = int(f.readline().split()[0])
boundary = []
for i in xrange(nope):
thisnum = int(f.readline().split()[0])
for j in xrange(thisnum):
boundary.append(int(f.readline().replace('\n', '')))
assert numbverts == len(boundary)
boundary = np.array(boundary) - 1
mesh['vertex_markers'] = np.zeros((numvert,), dtype=np.int)
mesh['vertex_markers'][boundary] = 1
write_triangulation(sys.argv[2],
mesh['vertices'],
mesh['triangles'],
boundaries=mesh['vertex_markers'])
Alexander Crosby
Ocean Engineer
Oceanweather Inc.
5 River Road #1
Cos Cob, CT 06807
al...@oc...
On 07/14/2016 02:07 AM, Sandhya K G wrote:
>
> Hi all,
>
>
> I am using SMS software to generate fort.14 file for unstructured SWAN
> runs. I need to convert the fort.14 file into element (.ele) and node
> (.node) files. Anybody can give any guidance for this?
>
> I am not finding any explanation for the contents of these files. Any
> document is available explaining these three files?
>
>
>
> Thanks & Regards,
> ********************************************************************************************************
> Sandhya K G
> url: http://www.incois.gov.in
> ********************************************************************************************************
>
>
> ------------------------------------------------------------------------------
> What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
> patterns at an interface-level. Reveals which users, apps, and protocols are
> consuming the most bandwidth. Provides multi-vendor support for NetFlow,
> J-Flow, sFlow and other flows. Make informed decisions using capacity planning
> reports.http://sdm.link/zohodev2dev
>
>
> _______________________________________________
> swanmodel-users mailing list
> swa...@li...
> https://lists.sourceforge.net/lists/listinfo/swanmodel-users
|