Beispiel #1
0
def test_create_basis(V, D, DA, pathname_mesh, sqrt_num_boxes, sensors):
    mesh_dictionary, region_dictionary = discretize_fem_mesh(
        'square', pathname_mesh, sqrt_num_boxes)
    phi = create_basis(V, D)

    sigma, set_of_phi, set_of_da = create_sigma(region_dictionary, phi, DA)

    # TODO: check why this is sensitive to initial epsilon value
    p, ada = opa.optimal_arrangement(sensors, np.asarray(sigma), 100000, 10)
    print(p, ada)

    return phi, ada, set_of_phi, set_of_da
Beispiel #2
0
def adaptation_scheme_replacement(region_dictionary, node_solution, DA, t0,
                                  t_resample, sensors):
    node_solution = np.reshape(
        node_solution,
        (np.shape(node_solution)[0], 1, np.shape(node_solution)[1]))
    total_time = np.shape(node_solution)[2]
    # Keep start and end times of ada values
    ada_vals = {}

    # Calculate POD basis for initial set of data for time [0, t0)
    truncated_data = node_solution[:, :, 0:t0]
    phi = calculate_POD_basis(truncated_data, DA)
    sigma, set_of_phi, set_of_da = create_sigma(region_dictionary, phi, DA)

    # To start, information from whole field are used
    ada_vals[(0, t0 - 1)] = list(set(region_dictionary.values()))

    # Estimate optimal placement information from POD basis
    p, ada = opa.optimal_arrangement(sensors, np.asarray(sigma), 1000, 10)

    sample_start_time = t0
    sample_end_time = t0 + t_resample
    new_ada = ada
    new_data = truncated_data
    sigma_data = truncated_data
    # TODO: check to make sure all the updated values are being updated correctly

    while sample_start_time < total_time:
        ada_vals[(sample_start_time,
                  min(sample_end_time, total_time) - 1)] = new_ada

        # Estimate field from sensor arrangement [t0, t1)
        # Get field measurements from time t0 to t1, apply estimation technique using selected sensors
        print(new_ada)
        estimated_vals = np.array([], dtype=np.float64).reshape(
            np.shape(node_solution)[0], 0)
        for time in range(sample_start_time, min(sample_end_time, total_time)):
            y = node_solution[:, :, time]  # Get data from original data set
            set_of_y = y_set(region_dictionary, new_ada, y)
            y_hat = state_estimation_2D(
                new_ada, phi, set_of_phi, set_of_da,
                set_of_y)  # Estimated data -- add noise?
            estimated_vals = np.concatenate((estimated_vals, y_hat), axis=1)

        # Update POD with information from estimated field
        # Add values to ORIGINAL data matrix -- can also add to POD estimated to get "lower order" estimates of field

        estimated_vals = estimated_vals[:, np.newaxis, :]

        if np.shape(sigma_data)[2] > np.shape(
                estimated_vals[:, np.newaxis, :])[2]:
            sigma_data = new_data[:, :,
                                  np.shape(estimated_vals[:, np.newaxis, :]
                                           )[2]:np.shape(new_data)[2]]
            sigma_data = np.concatenate(
                (np.asfarray(sigma_data), np.asfarray(estimated_vals)), axis=2)
        else:
            sigma_data = estimated_vals

        new_data = np.concatenate(
            (np.asfarray(new_data), np.asfarray(estimated_vals)), axis=2)
        phi = calculate_POD_basis(sigma_data, DA)
        new_sigma, set_of_phi, set_of_da = create_sigma(
            region_dictionary, phi, DA)

        # Calculate new optimal arrangement of sensors
        p, new_ada = opa.optimal_arrangement(sensors, np.asarray(new_sigma),
                                             1000, 10)

        # Next iteration
        sample_start_time = sample_end_time
        sample_end_time = sample_start_time + t_resample

    return new_data, ada_vals