Cut a 3D scalar
Last updated
Last updated
The goal of this exercise is to explain how the class Scalar3D works, in the two modes available. Once understood this, using this class should simplify operations with large 3d arrays.
Make sure to download the data folder from the to be able to do this tutorial until the end.
First of all, we need to import the module. Make sure you installed the package with the command pip install aPrioriDNS
now let's define a generic array that we will use as a scalar field
Cut the field using the mode 'equal'. This is useful when we want to cut the extrema after filtering operations, or in general after operations that have problems in the boundary treatment. Let's say we want to cut two cells from every boundary:
This time we are going to use the DNS dataset, to use the Scalar3D class in a more useful way. We won't initialize the object with a value that correspond to a numpy array, but just with the path of the file that should be read. This will create a pointer to the file location, and the object will read the file every necessary time. This mode is called 'light_mode' and can be used if we initialize the Scalar3D object without specifying the value, but specifying the path.
In the following lines of code it's explained how to use the Scalar3D object in light mode. If you downloaded the entire folder from GitHub this path definition should work fine.
With the shape and the path of the file, we can define the Scalar3D object:
The object is now defined and we can access its values. Nothing special until now. But let's check why using the Scalar3D object works so well with DNS data. Now we are going to define a numpy array of the same size as the temperature field, and we'll compare how much memory it takes in your system:
Showed the advantage of the object, in the following section the goal is to learn how to use the method cut to cut this field. To cut a different amount of cells in every direction x, y and z, we can use the mode 'xyz'. This mode allows us to cut a different number of cells from the 3 directions, but the number of cells cut, for example, in the x direction, will be symmetric in the two directions of the x axis. If we cut 3 cells in the x direction, the function will remove 3 cells at the beginning and 3 at the end.