In this section you'll learn how to filter a 3D field using the Scalar3D class.
Make sure to download the data folder from the to be able to do this tutorial until the end
"""
Created on Fri May 24 12:00:20 2024
@author: lorenzo piu
"""
Import and define array
First of all, it's necessary to import the modules that we will use in this tutorial
>>> import aPrioriDNS.DNS as DNS
>>> from aPrioriDNS.DNS import Scalar3D
Again we are going to use the class Scalar3D object assigning a value, which is not the main purpose of the class, but it can be useful to have this option.
>>> import os
>>> # change this with your path to the data folder
>>> directory = os.path.join('..','data','Lifted_H2_subdomain')
>>> T_path = os.path.join(directory,'data', 'T_K_id000.dat')
>>> print(f"\nChecking the path '{T_path}' is correct...")
Checking the path '../data/Lifted_H2_subdomain/data/T_K_id000.dat' is correct...
>>> if not os.path.exists(T_path):
... raise ValueError("The path '{T_path}' does not exist in your system. Check to have the correct path to your data folder in the code")
>>> # Blastnet's data contain information about the shape of the field in the info.json file
>>> import json
>>> with open(os.path.join(directory,'info.json'), 'r') as file:
... info = json.load(file)
>>> DNS_shape = info['global']['Nxyz']
>>> # Now we have the shape and the path of the file, we can define the Scalar3D object:
>>> T = Scalar3D(shape=DNS_shape, path=T_path)
>>> # Try to access the value of the temperature field:
>>> print("Temperature values in the cells 5:8, 5:8, 5:8")
>>> print(T._3D[5:8, 5:8, 5:8])
Temperature values in the cells 5:8, 5:8, 5:8
[[[948.34 954.703 958.952]
[934.218 939.709 943.358]
[921.206 925.98 929.27 ]]
[[953.27 958.763 962.017]
[938.411 942.927 945.55 ]
[924.591 928.335 930.622]]
[[958.015 962.569 964.736]
[942.356 945.86 947.389]
[927.675 930.377 931.61 ]]]
I know it's not optimal to visualize the effect of the filtering operation in this way, so if you're curious to see how this affects the temperature field, I suggest reading the next two exercises.
At this point let's see how we can filter a scalar inside our DNS field. The procedure to load the files' information is the same as in the