Interpolating file sequences
For cases in which interpolation is needed, one must interpolate a series of files. Here we show how that can be done easily.
Import general modules
[1]:
# Import required modules
from mpi4py import MPI #equivalent to the use of MPI_init() in C
import matplotlib.pyplot as plt
import numpy as np
# Get mpi info
comm = MPI.COMM_WORLD
# Hide the log for the notebook. Not recommended when running in clusters as it is better you see what happens
import os
os.environ["PYSEMTOOLS_HIDE_LOG"] = 'true'
Import modules from pysemtools
[2]:
from pysemtools.interpolation.wrappers import interpolate_fields_from_disk
Interpolate fields from a list
First we will define the inputs. For this, we need the name of the file that has the points, the name of the file that contains the spectral element mesh and optionally the name of the outputs. The latter defaults to intepolated_fields.hdf5
[3]:
query_points_fname = "points.hdf5"
data_path = "../data/sem_data/instantaneous/cylinder_rbc_nelv_600/"
sem_mesh_fname = f"{data_path}field0.f00801"
interpolated_fields_output_fname = "interpolated_fields.hdf5"
Additionally, we need a dictionary that we call settings. Here we give the information about where the fields will be read from.
We can provide as an input the file name sequence to be read by the interpolator. Or one can provide a file index produces by the indexing module of pysemtools.
Lastly we must say which fields to interpolate. If one passes the list with the string “all”, all fields in the file are interpolated.
[4]:
# Comment the option that you do not want to use
# Option 1 (if you have created an index file before)
field_interpolation_dictionary = {}
field_interpolation_dictionary['input_type'] = "file_index"
field_interpolation_dictionary['file_index'] = f"{data_path}field_index.json"
field_interpolation_dictionary['fields_to_interpolate'] = ["all"]
# Option 2 directly provide the names of the sequence of files you want to interpolate
field_interpolation_dictionary = {}
field_interpolation_dictionary['input_type'] = "file_sequence"
field_interpolation_dictionary['file_sequence'] = [f"{data_path}field0.f{str(i).zfill(5)}" for i in range(801, 850)]
field_interpolation_dictionary['fields_to_interpolate'] = ["all"]
[5]:
interpolate_fields_from_disk(comm, query_points_fname, sem_mesh_fname, field_interpolation_dictionary, interpolated_fields_output_fname=interpolated_fields_output_fname)
Now you are done! If you want to see more of what really happened in this script. Comment out the line that hides the log at the begining of this notebook.