-
Notifications
You must be signed in to change notification settings - Fork 3
/
ro1-modred.py
49 lines (45 loc) · 1.6 KB
/
ro1-modred.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
import numpy
import modred
import pickle
import time
import os, sys
dirpath = os.path.dirname(os.path.realpath(__file__))
if modred.__version__[0] != '1':
print 'modred version 1 is needed!'
sys.exit(1)
try:
podbase = pickle.load(open('out/reduced-order1/podbase.pickle', 'rb'))
except:
t0 = time.time()
num_modes = 18 # number of POD modes to use
try:
rig = pickle.load(open('out/reduced-order1/rig.pickle', 'rb'))
dsp = pickle.load(open('out/reduced-order1/dsp.pickle', 'rb'))
except:
print 'File(s) out/reduced-order1/[rig,dsp].pickle not found',
print '--> running ro0-fem-tl.py ...',
global percentage
percentage = True
execfile (dirpath + '/ro1-fem-tl.py')
try:
rig = pickle.load(open('out/reduced-order1/rig.pickle', 'rb'))
dsp = pickle.load(open('out/reduced-order1/dsp.pickle', 'rb'))
except:
print 'Running ro0-fem-tl.py has failed --> report a bug!'
import sys
sys.exit(0)
vecs = numpy.transpose(numpy.array(rig+dsp))
svec = vecs.shape[0]
nvec = vecs.shape[1]
print 'Solving for', nvec, 'input vectors of size', svec, '...'
modes, eig_vals = modred.compute_POD_matrices_snaps_method(vecs, list(range(num_modes)))
#modes, eig_vals = modred.compute_POD_matrices_direct_method(vecs, list(range(num_modes)))
print 'Eig vals:'
print eig_vals
mod = numpy.transpose(modes).tolist()
val = eig_vals.tolist()
basevec = [x for vec in mod for x in vec]
podbase = (val[0:len(mod)], basevec)
pickle.dump(podbase, open('out/reduced-order1/podbase.pickle', 'wb'))
t1 = time.time()
print '\bPOD runtime: %.3f seconds' % (t1-t0)