Example #1
0
import numpy as N
import modred as MR

# Define the handles for the snapshots
num_vecs = 30    
direct_snapshots = [MR.VecHandleArrayText('direct_vec%d.txt' % i) 
    for i in range(num_vecs)]
adjoint_snapshots = [MR.VecHandleArrayText('adjoint_vec%d.txt' % i)
    for i in range(num_vecs)]

# Save arbitrary data in text files
x = N.linspace(0, N.pi, 200)
for i, snap in enumerate(direct_snapshots):
    snap.put(N.sin(x*i))
for i, snap in enumerate(adjoint_snapshots):
    snap.put(N.cos(0.5*x*i))

# Calculate and save BPOD modes
my_BPOD = MR.BPODHandles(N.vdot, max_vecs_per_node=10)
L_sing_vecs, sing_vals, R_sing_vecs = \
    my_BPOD.compute_decomp(direct_snapshots, adjoint_snapshots)

num_modes = 10
mode_nums = range(num_modes)  
direct_modes = [MR.VecHandleArrayText('direct_mode%d' % i) 
    for i in mode_nums]
adjoint_modes = [MR.VecHandleArrayText('adjoint_mode%d' % i) 
    for i in mode_nums]
my_BPOD.compute_direct_modes(mode_nums, direct_modes)
my_BPOD.compute_adjoint_modes(mode_nums, adjoint_modes)
from future.builtins import range
import numpy as np
import modred as mr

# Define the handles for the snapshots
num_vecs = 30
direct_snapshots = [
    mr.VecHandleArrayText('direct_vec%d.txt' % i) for i in range(num_vecs)
]
adjoint_snapshots = [
    mr.VecHandleArrayText('adjoint_vec%d.txt' % i) for i in range(num_vecs)
]

# Save arbitrary data in text files
x = np.linspace(0, np.pi, 200)
for i, snap in enumerate(direct_snapshots):
    snap.put(np.sin(x * i))
for i, snap in enumerate(adjoint_snapshots):
    snap.put(np.cos(0.5 * x * i))

# Calculate and save BPOD modes
my_BPOD = mr.BPODHandles(np.vdot, max_vecs_per_node=10)
sing_vals, L_sing_vecs, R_sing_vecs = my_BPOD.compute_decomp(
    direct_snapshots, adjoint_snapshots)

num_modes = 10
mode_nums = list(range(num_modes))
direct_modes = [mr.VecHandleArrayText('direct_mode%d' % i) for i in mode_nums]
adjoint_modes = [
    mr.VecHandleArrayText('adjoint_mode%d' % i) for i in mode_nums
]
Example #3
0
snapshots = [
    mr.VecHandlePickle('%s/vec%d.pkl' % (out_dir, i),
                       base_vec_handle=base_vec_handle,
                       scale=quad_weights[i]) for i in mr.range(num_vecs)
]

# Save arbitrary snapshot data
num_elements = 2000
if parallel.is_rank_zero():
    for snap in snapshots + [base_vec_handle]:
        snap.put(np.random.random(num_elements))
parallel.barrier()

# Compute and save POD modes
my_POD = mr.PODHandles(np.vdot)
my_POD.compute_decomp(snapshots)
my_POD.put_decomp('%s/sing_vals.txt' % out_dir, '%s/sing_vecs.txt' % out_dir)
my_POD.put_correlation_array('%s/correlation_array.txt' % out_dir)
mode_indices = [1, 4, 5, 0, 10]
modes = [
    mr.VecHandleArrayText('%s/mode%d.txt' % (out_dir, i)) for i in mode_indices
]
my_POD.compute_modes(mode_indices, modes)

# Check that modes are orthonormal
vec_space = mr.VectorSpaceHandles(inner_product=np.vdot)
IP_array = vec_space.compute_symm_inner_product_array(modes)
if not np.allclose(IP_array, np.eye(len(mode_indices))):
    print('Warning: modes are not orthonormal')
    print(IP_array)
Example #4
0
base_vec_handle = mr.VecHandlePickle('base_vec.pkl')
snapshots = [
    mr.VecHandlePickle('vec%d.pkl' % i,
                       base_vec_handle=base_vec_handle,
                       scale=quad_weights[i]) for i in range(num_vecs)
]

# Save arbitrary data, normally unnecessary.
num_elements = 2000
parallel = mr.parallel_default_instance
if parallel.is_rank_zero():
    for snap in snapshots + [base_vec_handle]:
        snap.put(np.random.random(num_elements))
parallel.barrier()

# Compute and save POD modes.
my_POD = mr.PODHandles(np.vdot)
my_POD.compute_decomp(snapshots)
my_POD.put_decomp('sing_vals.txt', 'sing_vecs.txt')
my_POD.put_correlation_mat('correlation_mat.txt')
mode_indices = [1, 4, 5, 0, 10]
modes = [mr.VecHandleArrayText('mode%d.txt' % i) for i in mode_indices]
my_POD.compute_modes(mode_indices, modes)

# Check that modes are orthonormal
vec_space = mr.VectorSpaceHandles(inner_product=np.vdot)
IP_mat = vec_space.compute_symmetric_inner_product_mat(modes)
if not np.allclose(IP_mat, np.eye(len(mode_indices))):
    print('Warning: modes are not orthonormal', IP_mat)
Example #5
0
from future.builtins import range
import os

import numpy as np

import modred as mr

# Create directory for output files
out_dir = 'tutorial_ex3_out'
if not os.path.isdir(out_dir):
    os.makedirs(out_dir)

# Define the handles for the snapshots
num_vecs = 30
direct_snapshots = [
    mr.VecHandleArrayText('%s/direct_vec%d.txt' % (out_dir, i))
    for i in range(num_vecs)
]
adjoint_snapshots = [
    mr.VecHandleArrayText('%s/adjoint_vec%d.txt' % (out_dir, i))
    for i in range(num_vecs)
]

# Save arbitrary data in text files
x = np.linspace(0, np.pi, 200)
for i, snap in enumerate(direct_snapshots):
    snap.put(np.sin(x * i))
for i, snap in enumerate(adjoint_snapshots):
    snap.put(np.cos(0.5 * x * i))

# Calculate and save BPOD modes