version 0.6.0
Loading...
Searching...
No Matches
How to print a new variable to a BP file

The following guidelines will help you to print a new variable in a BP file.

One can add a cell or face array variable to a BP file from any routine of the code, the variable can be global or locally defined.

Moreover, it is possible to integrate better this process and link the print to a user interface keyword.

Print a variable from any routine

At the beginning of your routine, use the variables_output module:

use variables_output

Then, you can add a scalar or vector field to the print field list with:

call print_list%add_field( your_scalar_field, 'your_scalar_field_name' )
call print_list%add_field( your_face_field, 'your_face_field_name')
Warning
No verification is done on the correct allocation of the furnished field. Hence, make sure that it is correctly allocated to the size of the mesh!
Note
Notice that the file is effectivelly written in a BP file at the end of the time loop, in output_grids_and_fields.f90 routine. The frequency the file is written is controled in the NTS file.

Add a keyword and add the variable to output_grids_and_fields routine

If you want to control the print thanks to the user interface, you have to add a new keyword, a new Fortran logical print variable and eventually modify the output_grids_and_fields.f90 routine

Add a new Fortran print variable

Image you compute the enstrophy, and you would like to print it as any other field such as temperature, pressure, etc.

First, in variables_output module (in src/lib/io/grids_and_fields/variables.f90), add a logical among the is_print_... declarations as follow:

logical :: is_print_enstrophy = .false.

Please keep it in alphabetical order.

Add a keyword

Then, add a keyword in keywords.inc (in src/notus/ui directory).

Please keep it in alphabetical order.

Next, you have to modify the post_processing block of the NTS file to add the enstrophy keyword into the output fields list of variables. To do so, in mod_ui_parse_post_processing module (src/lib/notus/ui/tree/post_processing/block_reader.f90) routine, in case(kw_output_fields) section, add:

case(kw_enstrophy)

   is_print_enstrophy = .true.

Modify the post processing block documentation.

Modify io_write_grids_and_fields.f90 (src/lib/io/grids_and_fields directory) routine

Now you are able to modify the routine that writes BP file by adding the following line in the Add scalar section of the routine:

if (is_print_enstrophy)           call add_field_to_list(print_list, enstrophy, 'enstrophy')

Notice that enstrophy field should be computed in output_grids_and_fields.f90 or be accessible thanks to a module that contains this array.