Post Processing with Pyrefine

Pyrefine has the ability to post-process a series of simulations over a mesh adaptation and extract quantities of interest for each mesh. There are premade scripts available or a custom post-processor can be created to manipulate the raw data that is read from the history files.

Scripts

FUN3D Steady History to tecplot - pr_post_fun3d_steady_hist_to_tec.py

A script to write the number of nodes and last line of hist data to tecplot for steady FUN3D adaptations

usage: pr_post_fun3d_steady_hist_to_tec [-h] [--dir DIR] [--num_meshes NUM_MESHES] [--output_file OUTPUT_FILE] project_rootname

Positional Arguments

project_rootname

Base name of files, e.g. {project_rootname}01_hist.dat

Named Arguments

--dir

Location of files

Default: “./Flow”

--num_meshes

Number of meshes, default finds all

Default: -1

--output_file

Tecplot file name

Default: “adapt_hist.dat”

Customizing the Post-Processor

The post processing class, Fun3dAdaptationSteadyHistoryReader, is meant to be flexible. Arbitrary commands can be added to the post processor without modifying the source code for the reader class. This is possible through the use of the Command design pattern. Post-processing steps are encapsulated as “command” objects. These commands are added to the reader class through the register_command() method. The commands are stored in a list and can be run in order.

Each command should be a class that overrides the abstract base class, PostProcessingCommand. Each child class must implement the method execute(). This method is meant to contain the bulk of the post-processing work. When the execute_commands() method is called, it will call the execute method on each command sequentially.

In this implementation of the command design pattern, the roles are set up as follows:

Example

from pyrefine.post_processing.fun3d_file_reader import Fun3dAdaptationSteadyHistoryReader as F3DReader
from pyrefine.post_processing.post_processing_command import PostProcessingCommand

class LOverDCommand(PostProcessingCommand):
    """
    A command to compute the lift-to-drag ratio using the existing values
    of `C_L` and `C_D`
    """
    def execute(self):
        """ Override method from abstract base class"""
        c_l = self.target.final_hist_values['C_L']
        c_d = self.target.final_hist_values['C_D']
        self.target.final_hist_values['L/D'] = c_l / c_d

# Setup the reader class
reader = F3DReader('folder', 'project')
new_command = LOverDCommand(reader)
reader.register_command(new_command)
reader.execute_commands()
print(reader.final_hist_values['L/D'])

Reader Class

class pyrefine.post_processing.fun3d_file_reader.Fun3dAdaptationSteadyHistoryReader(data_directory, project_rootname, number_of_meshes=-1)

Class for post-processing an adaptation run with FUN3D.

Parameters
  • data_directory (str) – Location where the history files are

  • project_rootname (str) – base name of project (without mesh number)

  • number_of_meshes (int) – number of meshes to read. If left as the default value of -1, the number of meshes will be counted based on the files found in the data_directory

number_of_meshes

number of meshes that were read

Type

int

number_of_nodes

number of nodes in each mesh

Type

np.ndarray

final_hist_values

history of values. Key is the variable name. Value is the numpy array with the history of that variable.

Type

dict

execute_commands()

Iterate through user-specified commands

The reader class is the invoker for the command design pattern

register_command(command)

Add a command to the post-processing list

The reader class is the invoker for the command design pattern

Parameters

command (PostProcessingCommand) – A post-processing command to be added to the list. These commands will be executed in a first-in, first-out sequence.

Raises

ValueError: – Raises a value error if the command is not a valid PostProcessingCommand

write_data_to_tec(filename)

Write the history information to a tecplot file

Parameters

filename (str) –

write_data_to_csv(filename)

Write the history information to a csv file

Parameters

filename (str) –

PostProcessCommand Class

class pyrefine.post_processing.post_processing_command.PostProcessingCommand(target)

A simple implementation of the command design pattern

Overide this abstract base class to add new commands to the Fun3d reader.

Parameters

target (Fun3dAdaptationSteadyHistoryReader) – Store a reference to the receiver or target of the command

abstract execute()

The bulk of the post-processing work should be stored in this method.

Return type

None