aPriori Documentation
  • 👋Welcome to aPriori
  • Getting started
    • What is aPriori?
    • Installation
    • Quickstart
  • Fundamentals and usage
    • aPriori Fundamentals
      • Data Formatting
      • Cut a 3D scalar
      • Filter a 3D scalar field
      • Initialize a DNS field
      • Data visualization
      • Cut a DNS field
      • Filter a DNS field
    • Machine Learning Tutorials
      • Data-Driven Closure for Turbulence-Chemistry interaction
      • Dynamic Data-Driven Smagorinky Closure for LES
  • API guide
    • Field3D
      • Field3D.build_attributes_list
      • Field3D.check_valid_attribute
      • Field3D.compute_chemical_timescale
      • Field3D.compute_kinetic_energy
      • Field3D.compute_mixing_timescale
      • Field3D.compute_residual_kinetic_energy
      • Field3D.compute_residual_dissipation_rate
      • Field3D.compute_reaction_rates
      • Field3D.compute_reaction_rates_batch
      • Field3D.compute_strain_rate
      • Field3D.compute_tau_r
      • Field3D.compute_velocity_module
      • Field3D.cut
      • Field3D.filter_favre
      • Field3D.filter
      • Field3D.find_path
      • Field3D.plot_x_midplane
      • Field3D.plot_y_midplane
      • Field3D.plot_z_midplane
      • Field3D.print_attributes
      • Field3D.update
    • Scalar3D
      • Scalar3D.is_light_mode
      • Scalar3D.reshape_3d
      • Scalar3D.reshape_column
      • Scalar3D.reshape_line
      • Scalar3D.cut
      • Scalar3D.filter_gauss
      • Scalar3D.plot_x_midplane
      • Scalar3D.plot_y_midplane
      • Scalar3D.plot_z_midplane
    • Mesh3D
  • BIBLIOGRAPHY
Powered by GitBook
On this page
  1. Fundamentals and usage
  2. aPriori Fundamentals

Initialize a DNS field

PreviousFilter a 3D scalar fieldNextData visualization

Last updated 8 months ago

Exercise 05

Following this exercise will clarify the main goal of the project. Here we will start using the class Field3D, which shows the full potential of the package in handling formatted DNS data.

The tutorials from now on are entirely based on formatted data. If you aim to run this tutorial on your laptop, please download the data folder from the aPriori with the funciton ap.download(). If you already downloaded the data, uou can just comment that line.

"""
Created on Fri May 24 14:10:20 2024

@author: lorenzo piu
"""

Import module and define data path

>>> import os
>>> import aPrioriDNS as ap
>>> import json

>>> ap.download

>>> directory = os.path.join('.','Lifted_H2_subdomain') # change this with your path to the data folder

>>> # Blastnet's data contain information about the shape of the field in the info.json file.
>>> # When initialized, the Field3D object will automatically read all the information,
>>> # so this time we don't need to worry about defining the shape
>>> # with open(os.path.join(directory,'info.json'), 'r') as file:
>>> #     info = json.load(file)
>>> # DNS_shape = info['global']['Nxyz']

Initialize Field

If your data follows the Blastnet formatting, you should have nothing else to worry about than defining the correct relative path that takes from your script's folder to the folder where the DNS data are located on your system.

Let's see how to use the utility:

>>> DNS_field = ap.Field3D(directory)
Output
---------------------------------------------------------------
Initializing 3D Field

Checking files inside folder ../data/Lifted_H2_subdomain...

Folder structure OK

---------------------------------------------------------------
Building mesh attribute...
Mesh fields read correctly

---------------------------------------------------------------
Reading kinetic mechanism...
Kinetic mechanism file found: ../data/Lifted_H2_subdomain/chem_thermo_tran/li_h2.yaml
Species:
['H2', 'O2', 'H2O', 'H', 'O', 'OH', 'HO2', 'H2O2', 'N2']

---------------------------------------------------------------
Building scalar attributes...
Field attributes:
+-----------+------------------------------------------------------+
| Attribute |                         Path                         |
+-----------+------------------------------------------------------+
|     P     |   ../data/Lifted_H2_subdomain/data/P_Pa_id000.dat    |
|    RHO    | ../data/Lifted_H2_subdomain/data/RHO_kgm-3_id000.dat |
|     T     |    ../data/Lifted_H2_subdomain/data/T_K_id000.dat    |
|    U_X    |  ../data/Lifted_H2_subdomain/data/UX_ms-1_id000.dat  |
|    U_Y    |  ../data/Lifted_H2_subdomain/data/UY_ms-1_id000.dat  |
|    U_Z    |  ../data/Lifted_H2_subdomain/data/UZ_ms-1_id000.dat  |
|    YH2    |    ../data/Lifted_H2_subdomain/data/YH2_id000.dat    |
|    YO2    |    ../data/Lifted_H2_subdomain/data/YO2_id000.dat    |
|   YH2O    |   ../data/Lifted_H2_subdomain/data/YH2O_id000.dat    |
|    YH     |    ../data/Lifted_H2_subdomain/data/YH_id000.dat     |
|    YO     |    ../data/Lifted_H2_subdomain/data/YO_id000.dat     |
|    YOH    |    ../data/Lifted_H2_subdomain/data/YOH_id000.dat    |
|   YHO2    |   ../data/Lifted_H2_subdomain/data/YHO2_id000.dat    |
|   YH2O2   |   ../data/Lifted_H2_subdomain/data/YH2O2_id000.dat   |
|    YN2    |    ../data/Lifted_H2_subdomain/data/YN2_id000.dat    |
+-----------+------------------------------------------------------+

What can we do now that the field is initialized?

Now the object can access all the functionalities implemented. those will be covered in more detail in the next sections. With this object, we can easily access the data inside the folder, e.g.:

>>> DNS_field.T
<aPrioriDNS.DNS.Scalar3D at 0x14c36ab50>

gives as output a Scalar3D object associated with the temperature field, while

>>> DNS_field.U_Y._3D

Will return a numpy 3D array with the values associated with the Y component of velocity.

We can still use all the functionalities that we saw in the previous sections, so if we want to have an array with the filtered molar concentration of oxygen, it's sufficient to write:

>>> filt_YO2 = DNS.filter_3D(DNS_field.YO2._3D, 8)
>>> DNS_field.plot_z_midplane('YH2O2')

And finally, plotting 3D scalars associated with the relative mesh becomes very straightforward:

GitHub repo