forked from jasonfleming/pputils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adcirc2ren.py
executable file
·69 lines (61 loc) · 2.15 KB
/
adcirc2ren.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
#
#+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!
# #
# adcirc2ren.py #
# #
#+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!
#
# Author: Pat Prodanovic, Ph.D., P.Eng.
#
# Date: Feb 18, 2016
#
# Purpose: Script takes in a mesh in ADCIRC format, and outputs a nodes
# and elements file for use in John Burkardt's rcm renumbering algorithm.
#
# Uses: Python 2 or 3, Numpy
#
# Example:
#
# python adcirc2ren.py -i out.grd -o out_nodes.txt out_elements.txt
# where:
# -i input adcirc mesh file
# -o output files needed for rcm renumbering
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Global Imports
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import os,sys # system parameters
import numpy as np # numpy
from ppmodules.readMesh import * # to get all readMesh functions
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# MAIN
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
curdir = os.getcwd()
#
# I/O
if len(sys.argv) != 6 :
print('Wrong number of Arguments, stopping now...')
print('Usage:')
print('python adcirc2ren.py -i out.grd -o out_nodes.txt out_elements.txt')
sys.exit()
dummy1 = sys.argv[1]
adcirc_file = sys.argv[2]
dummy2 = sys.argv[3]
nodes_file = sys.argv[4]
elements_file = sys.argv[5]
# to create the output files
fn = open(nodes_file,"w")
fe = open(elements_file,"w")
# read the adcirc file
n,e,x,y,z,ikle = readAdcirc(adcirc_file)
# before writing the files, find coordinates of x min (to subtract from)
xref = x[np.argmin(x)]
yref = y[np.argmin(x)]
for i in range(n):
fn.write(str(x[i]-xref) + ' ' + str(y[i]-yref) + ' ' + str(z[i]) + '\n')
for i in range(e):
fe.write(str(ikle[i,0]) + ' ' + str(ikle[i,1]) + ' ' + str(ikle[i,2]) + '\n')
fo = open('coord_shift.txt','w')
fo.write(str(xref) + ' ' + str(yref))