}
    north
    {
        type            calculated;
        value           uniform (0 0 0 0 0 0 0 0 0);
    }
}

// ************************************************************************* //
"""
"""
Calculate Eigenvals and Eigenvecs
"""
t0 = t.time()
_, eigval_test, eigvec_test = processReynoldsStress(y_test,
                                                    make_anisotropic=False,
                                                    realization_iter=0,
                                                    to_old_grid_shape=False)
del y_test
# If filter was True, eigval_pred_test is a mesh grid
_, eigval_pred, eigvec_pred = processReynoldsStress(y_pred,
                                                    make_anisotropic=False,
                                                    realization_iter=0,
                                                    to_old_grid_shape=False)
del y_pred
t1 = t.time()
print('\nFinished calculating eigenvals and eigenvecs in {:.4f} s'.format(t1 -
                                                                          t0))
"""
Write Eigenvecs back to OpenFOAM File
"""
print(
Ejemplo n.º 2
0
    y_pred_test[i] = rotij.T @ (y_pred_test_rot[i] @ rotij)

for i in range(len(y_pred_train_rot)):
    y_pred_train[i] = rotij.T @ (y_pred_train_rot[i] @ rotij)

y_pred_test, y_pred_train = y_pred_test.reshape((-1, 9)), y_pred_train.reshape((-1, 9))
y_pred_test, y_pred_train = contractSymmetricTensor(y_pred_test), contractSymmetricTensor(y_pred_train)


"""
Postprocess Machine Learning Predictions
"""
t0 = t.time()
# _, eigval_test, _ = processReynoldsStress(y_test, make_anisotropic=False, realization_iter=0)
# _, eigval_train, _ = processReynoldsStress(y_train, make_anisotropic=False, realization_iter=0)
y_pred_test3, eigval_pred_test, _ = processReynoldsStress(y_pred_test, make_anisotropic=False, realization_iter=realize_iter)
y_pred_train3, eigval_pred_train, _ = processReynoldsStress(y_pred_train, make_anisotropic=False, realization_iter=realize_iter)
t1 = t.time()
print('\nFinished processing Reynolds stress in {:.4f} s'.format(t1 - t0))

t0 = t.time()
# xy_bary_test, rgb_bary_test = getBarycentricMapData(eigval_test)
# xy_bary_train, rgb_bary_train = getBarycentricMapData(eigval_train)
xy_bary_pred_test, rgb_bary_pred_test = getBarycentricMapData(eigval_pred_test)
xy_bary_pred_train, rgb_bary_pred_train = getBarycentricMapData(eigval_pred_train)
t1 = t.time()
print('\nFinished getting Barycentric map data in {:.4f} s'.format(t1 - t0))

t0 = t.time()
# ccx_test_mesh, ccy_test_mesh, _, rgb_bary_test_mesh = interpolateGridData(ccx_test, ccy_test, rgb_bary_test, mesh_target=uniform_mesh_size, interp=interp_method, fill_val=0.3)
# ccx_train_mesh, ccy_train_mesh, _, rgb_bary_train_mesh = interpolateGridData(ccx_train, ccy_train, rgb_bary_train, mesh_target=uniform_mesh_size, interp=interp_method, fill_val=0.3)
    # anomaly_idx_train = outliers['anomalyIdxTrains']
    anomaly_idx_test = outliers['anomaly_idx_test']
    # anomaly_idx_train2 = outliers2['anomalyIdxTrains']
    # anomaly_idx_test2 = outliers2['anomaly_idx_test']
    # anomaly_idx_train3 = outliers3['anomalyIdxTrains']
    # anomaly_idx_test3 = outliers3['anomaly_idx_test']
    # anomaly_idx_train4 = outliers4['anomalyIdxTrains']
    # anomaly_idx_test4 = outliers4['anomaly_idx_test']
    # anomaly_idx_train5 = outliers5['anomalyIdxTrains']
    # anomaly_idx_test5 = outliers5['anomaly_idx_test']
    """
    Postprocess Machine Learning Predictions
    """
    t0 = t.time()
    _, eigval_test, _ = processReynoldsStress(y_test,
                                              make_anisotropic=False,
                                              realization_iter=0)
    # _, eigval_train, _ = processReynoldsStress(y_train, make_anisotropic=False, realization_iter=0)
    t1 = t.time()
    print('\nFinished processing Reynolds stress in {:.4f} s'.format(t1 - t0))

    t0 = t.time()
    xy_bary_test, rgb_bary_test = getBarycentricMapData(eigval_test)
    # Limit RGB value to [0, 1]
    rgb_bary_test[rgb_bary_test > 1.] = 1.
    # xy_bary_train, rgb_bary_train = getBarycentricMapData(eigval_train)
    rgb_bary_test_out = rgb_bary_test.copy()
    rgb_bary_test_out[anomaly_idx_test] = gray
    # rgb_bary_train_out = rgb_bary_train.copy()
    # rgb_bary_train_out[anomaly_idx_train], rgb_bary_train_out[anomaly_idx_train2], rgb_bary_train_out[anomaly_idx_train3], \
    # rgb_bary_train_out[anomaly_idx_train4], rgb_bary_train_out[anomaly_idx_train5] \
list_x, list_y, list_z = [], [], []
list_rgb, list_bij, list_rij = [], [], []
# Go through specified slices
for i, slicename in enumerate(case.slicenames):
    """
    Process Uninterpolated Anisotropy Tensor
    """
    # Retrieve Rij of this slice
    rij = case.slices_val[slicename]
    rij = expandSymmetricTensor(rij).reshape((-1, 3, 3))
    # Rotate Rij if requested, rotateData only accept full matrix form
    if rotate_data: rij = rotateData(rij, anglez=rot_z)
    rij = contractSymmetricTensor(rij)
    rij_tmp = rij.copy()
    # Get bij from Rij and its corresponding eigenval and eigenvec
    bij, eig_val, eig_vec = processReynoldsStress(rij_tmp, realization_iter=0, make_anisotropic=make_anisotropic, to_old_grid_shape=False)
    # bij was (n_samples, 3, 3) contract it
    bij = contractSymmetricTensor(bij)
    # Get barycentric map coor and normalized RGB
    xy_bary, rgb = getBarycentricMapData(eig_val, c_offset=c_offset, c_exp=c_exp)


    """
    Interpolation
    """
    # 1st coor is always x not matter vertical or horizontal slice
    # 2nd coor is y if horizontal slice otherwise z, take appropriate confinebox limit
    coor2_lim = confinebox[i][2:4] if case.slices_orient[slicename] == 'horizontal' else confinebox[i][4:]
    # Selective interpolation upon request
    if 'bary' in plot_property or '*' in plot_property:
        x_mesh, y_mesh, z_mesh, rgb_mesh = case.interpolateDecomposedSliceData_Fast(case.slices_coor[slicename][:, 0], case.slices_coor[slicename][:, 1], case.slices_coor[slicename][:, 2], rgb,