Meshes¶
The first step in using PyPan is to generate a Mesh object which can be passed to a PyPan solver. This is done using the Mesh class. The Mesh class can read in an STL or VTK file and use that to generate the necessary data for PyPan to solve the flow field.
- class pypan.Mesh(**kwargs)¶
A class for defining collections of panels.
- Parameters
name (str) – Name of the mesh.
mesh_file (str) –
File path to the mesh file. Please note that PyPan assumes the panel normals all point outward. Failure to meet this condition can produce erroneous results. Can be “STL” or “VTK”.
ASCII or binary STL files may be used.
Currently PyPan can import a VTK unstructured mesh. The panels should be given as POLYGONS. PyPan can accept no other format currently. Within a VTK file, the normal vector, area, and centroid may also be given under CELL_DATA. In all cases LOOKUP_TABLE should be default (PyPan is not currently able to parse non-default lookup tables).
multi_file (bool, optional) – Whether the mesh file contains multiple meshes which should be combined into one. This functionality only exists for STL files (as far as I know). Defaults to False, in which case, if the file contains multiple meshes, only the first will be read in.
adjacency_file (str, optional) – Name of the panel adjacency mapping file for this mesh. Must be previously generated using Mesh.export_panel_adjacency_mapping(). Defaults to None, in which case the panel adjacency mapping will be determined using a brute force approach. Also, if the file cannot be found as specified, it will be ignored and the panel adjacency mapping will be determined using the brute force approach.
CG (list, optional) – Location of the center of gravity for the mesh. This is the location about which moments are computed. Defaults to [0.0, 0.0, 0.0]. This is relative to the coordinate system of the mesh.
gradient_fit_type (str, optional) – The type of basis functions to use for least-squares estimation of gradients. May be ‘linear’ or ‘quad’. Defaults to ‘quad’ (recommended).
- export_panel_adjacency_mapping(filename)¶
Writes the panel adjacency mapping to the specified file. This mapping can then be read into PyPan when initializing the mesh on subsequent runs, speeding up initialization times.
- Parameters
filename (str) – Name of the file to write the panel adjacency mapping to. Should be type “.pam”.
- export_vtk(filename)¶
Exports the mesh to a VTK file. Please note this exports the mesh only. There is an export_vtk() method within the Solver class which will export the mesh along with the flow data.
- Parameters
filename (str) – Name of the file to write the results to. Must have ‘.vtk’ extension.
- finalize_kutta_edge_search(u_inf)¶
Determines where the Kutta condition should exist based on previously located adjacent panels and the freestream velocity.
- Parameters
u_inf (ndarray) – Freestream velocity vector (direction of the oncoming flow).
- get_gradient(phi)¶
Returns a least-squares estimate of the gradient of phi in the plane of the panel at each panel centroid assuming a quadratic model for phi in the plane of the panel. Phi should be given as the value of a scalar function at each panel centroid, in the correct order.
- Parameters
phi (ndarray) – Value of the scalar field at each panel centroid.
- Returns
grad_phi – The gradient of phi at each panel centroid wrt the Cartesian axes.
- Return type
ndarray
- get_vtk_data()¶
Returns a list of vertices and a list of indices referencing each panel to its vertices in the first list.
- plot(**kwargs)¶
Plots the mesh in 3D. Python’s plotting library is very slow for large datasets and has a poor UI. We recommend using export_vtk() instead and importing into a dedicated renderer, such as Paraview.
- Parameters
panels (bool, optional) – Whether to display panels. Defaults to False.
vertices (bool, optional) – Whether to display vertices. Defaults to True.
centroids (bool, optional) – Whether to display centroids. Defaults to False.
kutta_edges (bool, optional) – Whether to display the edges at which the Kutta condition will be enforced. Defaults to True.
highlight_panels (list, optional) – A list of panel indices to highlight in yellow. Defaults to no panels.
- set_wake(**kwargs)¶
Sets up a wake for this mesh.
A fixed wake consists of straight, semi-infinite vortex filaments attached to the Kutta edges. The direction is specified by “fixed_direction_type”.
An iterative wake consists of segmented semi-infinite vortex filaments. These initially be set in the direction of the local freestream vector resulting from the freestream velocity and rotation.
- Parameters
type (str, optional) – May be “fixed”, “full_streamline”, “relaxed”, or “marching_streamline”. Defaults to “fixed”.
kutta_angle (float, optional) – The angle threshold in degrees for determining which edges are Kutta edges. Defaults to 90.0.
check_freestream (bool, optional) – Whether to include freestream information in the Kutta edge search. If True, a Kutta edge will only be specified between panels which satisfy the Kutta angle and and which have at least one of their normals at less than 90.0 to the freestream velocity (pointing towards the body). Defaults to True.
fixed_direction_type (str, optional) – May be “custom”, “freestream”, or “freestream_and_rotation”. Defaults to “freestream_and_rotation”.
custom_dir (list or ndarray, optional) – Direction of the vortex filaments. Only used if “fixed_direction_type” is “custom”, and then it is required.
N_segments (int, optional) – Number of segments to use for each filament. Defaults to 20. If type is “marching_streamline”, this number determines number of wake iterations specified for the solver. Not required for type “fixed”.
segment_length (float, optional) – Length of each discrete filament segment. Defaults to 1.0. Not required for type “fixed”.
end_segment_infinite (bool, optional) – Whether the final segment of the filament should be treated as infinite. Only used if type is “full_streamline” or “relaxed”. Defaults to False. Not required for type “fixed”.
corrector_iterations (int, optional) – How many times to correct the streamline (velocity) prediction for each segment within a streamline wake (not “relaxed” or “fixed”). Defaults to 1.
K (float) – Time stepping factor for shifting the filament vertices based on the local induced velocity and distance from the trailing edge. Only required for type “relaxed”.