-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample_QR_streaming.py
44 lines (37 loc) · 1.13 KB
/
example_QR_streaming.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
#!/usr/bin/env python
#
# Example of how to run a POD on runtime.
#
# Last revision: 20/01/2025
from __future__ import print_function, division
import mpi4py
mpi4py.rc.recv_mprobe = False
import numpy as np
import pyLOM
## Parameters
DATAFILE = './DATA/CYLINDER.h5'
VARIABLE = 'VELOC'
## Data loading
m = pyLOM.Mesh.load(DATAFILE)
d = pyLOM.Dataset.load(DATAFILE,ptable=m.partition_table)
U = d[VARIABLE]
t = d.get_variable('time')
## Set up parameters
nbatches = 4
nt = t.shape[0]
batchsize = int(np.floor(nt/nbatches))
nmod = 4
q = 1
## Initialize the QB with the first batch
X = U[:,:batchsize]
Q1,B1,Yo = pyLOM.math.init_qr_streaming(X, nmod, q)
Xr = pyLOM.math.matmul(Q1,B1)
Ek = pyLOM.math.energy(Xr,X)
pyLOM.pprint(0, 'Partial energy recovered', Ek, flush=True)
## Iterate over the rest of batches
for ii in range(nbatches-1):
X = U[:,(ii+1)*batchsize:(ii+2)*batchsize]
Q1,B1,Yo = pyLOM.math.update_qr_streaming(X,Q1,B1,Yo,nmod,q)
Xr = pyLOM.math.matmul(Q1,B1[:,-batchsize:].copy())
Ek = pyLOM.math.energy(Xr,X)
pyLOM.pprint(0, ii, 'Partial energy recovered', Ek, flush=True)