Newer
Older
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# -*- coding: utf-8 -*-
"""
Created on Fri Apr 15 18:34:15 2016
@author: shfe
Description: This script is used for writing the hydro input files for HAWC2
(the wave type det_airy is not included)
"""
import os
class hydro_input(object):
""" Basic class aiming for write the hydrodynamics input file"""
def __init__(self, wavetype, wdepth, spectrum, Hs, Tp, seed,
gamma = 3.3, stretching = 1, wn = None, coef = 200,
spreading = None):
self.wdepth = wdepth
if self.wdepth < 0:
raise ValueError('water depth must be greater than 0')
# Regular Airy Wave Input
if wavetype == 'reg_airy':
self.waveno = 0
self.argument = 'begin %s ;\n\t\tstretching %d;\n\t\twave %d %d;\n\tend;' \
%(wavetype,stretching,Hs,Tp)
# Iregular Airy Wave Input
if wavetype == 'ireg_airy':
self.waveno = 1
# jonswap spectrum
if spectrum == 'jonswap':
spectrumno = 1
self.argument = 'begin %s ;\n\t\tstretching %d;\n\t\tspectrum %d;'\
'\n\t\tjonswap %.1f %.1f %.1f;\n\t\tcoef %d %d;' \
%(wavetype,stretching,spectrumno,Hs,Tp,gamma,coef,seed)
# Pierson Moscowitz spectrum
elif spectrum == 'pm':
spectrumno = 2
self.argument = 'begin %s ;\n\t\tstretching %d;\n\t\tspectrum %d;'\
'\n\t\tpm %.1f %.1f ;\n\t\tcoef %d %d;' \
%(wavetype,stretching,spectrumno,Hs,
Tp,coef,seed)
# check the spreading function
if spreading is not None:
self.argument += '\n\t\tspreading 1 %d;'%(spreading)
self.argument += '\n\tend;';
# Stream Wave Input
if wavetype == 'strf':
self.waveno = 3
self.argument = 'begin %s ;\n\t\twave %d %d;\n\tend;' \
%(wavetype,Hs,Tp)
def execute(self, filename, folder):
cwd = os.getcwd()
folder_path = os.path.join(cwd,folder)
file_path = os.path.join(folder_path,filename)
# check if the hydro input file exists
if os.path.exists(file_path):
pass
else:
FILE = open(file_path,'w+')
line1 = 'begin wkin_input ;'
line2 = 'wavetype %d ;' %self.waveno
line3 = 'wdepth %d ;' %self.wdepth
line4 = 'end ;'
file_contents = '%s\n\t%s\n\t%s\n\t%s\n%s\n;\nexit;' \
%(line1,line2,line3,self.argument,line4)
FILE.write(file_contents)
FILE.close()
if __name__ == '__main__':
hs = 3
Tp = 11
hydro = hydro_input(Hs = hs, Tp = Tp, wdepth = 33,spectrum='jonswap',spreading = 2)
hydro.execute(filename='sss')