-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCtpredict.py
More file actions
61 lines (58 loc) · 2.21 KB
/
Copy pathCtpredict.py
File metadata and controls
61 lines (58 loc) · 2.21 KB
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
#########################################################################
#THIS SCRIPT COMPUTES C(t) PREDICTED AND ITS ERROR FROM FIRST DERIVATIVES
#########################################################################
#Author: DiegoDZ
#Date: jun 2017
#########################################################################
import numpy as np
from scipy.linalg import expm
from scipy.linalg import norm
import datetime
#####################################
#LOAD FILES AND DEFINE VARIBLES
#####################################
print datetime.datetime.now(), 'Loading files...'
C0 = np.loadtxt('C0stat')
Cshort = np.loadtxt('Ctstat_2e3steps')
nRows, nCols = np.shape(C0)
nBlocks = 9
sBlocks = int(np.sqrt(nBlocks))
nNodes = len(C0[0]) / int(np.sqrt(nBlocks))
dim = sBlocks * nNodes
dt = 0.002 #dt=0.0002 lammps. Saved output each 10 nSteps -> 0.002 between snapshots
nSteps = 2000
#####################################
#DEFINE FUNCTIONS
#####################################
#Change format: vector-> matrix
def reshape_vm(A):
B = A.reshape(nBlocks,nNodes*nNodes).reshape(sBlocks,sBlocks,nNodes,nNodes).transpose(0,2,1,3).reshape(dim,dim)
return B
#Change format: Matrix-> Vector
def reshape_mv(A):
B = A.reshape(sBlocks,nNodes,sBlocks,nNodes).swapaxes(1,2).ravel()
return B
#Error
def frobenious(A,B):
error = norm((reshape_vm(A - B)), 'fro') / nNodes
return error
#####################################
#COMPUTE C(t) PREDICTED AND ITS ERROR
#####################################
tauStart = 0.03
tauStop = 0.05
tauJump = 0.01
for i in np.arange(tauStart, tauStop, tauJump):
Lambda = np.loadtxt('Lambda'+str(i))
Ctpredict = np.zeros((nSteps, nNodes**2*nBlocks))
errorCtpredict = np.zeros(nSteps)
t=0
for j in range(nSteps):
print datetime.datetime.now(), 'Computing step', str(j), 'for lambda', str(i)
Ctpredict[j,:] = reshape_mv(np.dot(expm(-Lambda * t),C0))
errorCtpredict[j] = frobenious(Ctpredict[j,:],Cshort[j,:])
t+=dt
print datetime.datetime.now(), 'Saving output for lambda', str(i)
np.savetxt('Ctpredict' + str(i), Ctpredict)
np.savetxt('errorCtpredict' + str(i), errorCtpredict)
#EOF