flow_element module
This module declares the flow_element.FlowElement elements.
FlowElement abstract parent class
- class flow_element.FlowElement
This abstract class declares the methods a flow element should implement to be added to
flow_element.Flow.- Raises
NotImplementedError – This exception will be thrown if a child class has not overridden this class’ methods prior to calling them.
- __init__()
Constructor method.
- Raises
NotImplementedError – Thrown if this method is not overridden by the child class.
- print_parameters()
Prints the flow element’s parameters to console.
- Raises
NotImplementedError – Thrown if this method is not overridden by the child class.
- name()
Returns the name of the element (for plotting).
- Raises
NotImplementedError – Thrown if this method is not overridden by the child class.
- id()
Returns the id of the element (for plotting). An id corresponds to the line number the element is declared at in the flow_elements.csv file, starting from 1.
- Raises
NotImplementedError – Thrown if this method is not overridden by the child class.
- add_walls(slopes, intercepts)
This method adds one or two walls to the flow and has to be called on each flow elements. It will result in the addition of symmetric elements with respect to the walls with opposite circulation. The walls are defined by linear functions. See
flow_element.Wallsfor more information.- Parameters
slopes (float) – Slopes of the linear functions describing the walls
intercepts (float) – Intercepts of the linear functions describing the walls
- Raises
NotImplementedError – Throws an exception if this method is called without being overridden.
- z_initial()
Returns the initial position of the element.
- Raises
NotImplementedError – Thrown if this method is not overridden by the child class.
- z_current()
Returns the current position of the element.
- Raises
NotImplementedError – Thrown if this method is not overridden by the child class.
- set_z(z)
Sets the current position of the element.
- Parameters
z (complex) – Current position of the element.
- Raises
NotImplementedError – Thrown if this method is not overridden by the child class.
- complex_potential(z)
Returns the complex potential \(w\) of this element at point \(z\): \(w(z - z_{self}) = \phi + i \psi\), where \(\phi\) is the velocity potential and \(\psi\) is the stream function.
- Parameters
z (complex) – Position where the complex potential \(w(z - z_{self})\) is to be computed.
- Raises
NotImplementedError – Thrown if this method is not overridden by the child class.
- complex_potential_symmetric(z, z_symmetric)
Returns the complex potential \(w\) of the images of self with respect to the walls. The symmetric elements will have a circulation of different sign to self element.
- Parameters
z (complex) – Position where the complex potential \(w(z - z_{self})\) is to be computed.
z_symmetric (complex) – Position of the image of the element this method is being called on
- Raises
NotImplementedError – Thrown if this method is not overridden by the child class.
- derivative_complex_potential(z)
Returns the derivative of the complex potential \(dw/dz\) of this element at point \(z\): \(dw/dz = u - i v\), where \(u\) and \(v\) are the horizontal and vertical components of the velocity respectively. Please note that \(v\) is given by \(- Im(dw/dz)\).
- Parameters
z (complex) – Position where the derivative of the complex potential is to be computed, $dw/dz$
- Raises
NotImplementedError – Thrown if this method is not overridden by the child class.
- derivative_complex_potential_symmetric(z, z_symmetric)
Returns the derivative of the complex potential \(dw/dz\) of the images of self with respect to the walls. The symmetric elements will have a circulation of different sign to self element.
- Parameters
z (complex) – Position where the derivative of the complex potential is to be computed
z_symmetric (complex) – Position of the image of the element this method is being called on
- Raises
NotImplementedError – Thrown if this method is not overridden by the child class.
UniformStream element
- class flow_element.UniformStream(free_stream_velocity, free_stream_incidence, id)
This class replicates the behavior of a uniform stream. It inherits the
FlowElementabstract class.- Parameters
free_stream_velocity (float) – Free stream velocity
free_stream_incidence (float) – Free stream incidence in radians
id (int) – Element id for user output
- __init__(free_stream_velocity, free_stream_incidence, id)
Constructor method
- print_parameters()
Prints the element’s parameters to console.
- name()
Returns the name of this element, i.e. “Uniform Stream”
- Returns
Name of the element
- Return type
str
- id()
Returns element id (for plotting)
- Returns
Element id
- Return type
int
- z_initial()
A uniform stream does not have a unique position on the complex plane so returns the origin.
- Returns
Returns the origin, i.e. (0. 0)
- Return type
complex
- z_current()
A uniform stream does not have a unique position on the complex plane so returns the origin.
- Returns
Returns the origin, i.e. (0. 0)
- Return type
complex
- set_z(z)
A uniform stream does not have a unique position on the complex planes. This method does nothing.
- Parameters
z (complex) – Useless parameter
- complex_potential(z)
Returns the complex potential \(w\) of this element at point \(z\): \(w(z - z_{self}) = \phi + i \psi\), where \(\phi\) is the velocity potential and \(\psi\) is the stream function. For a uniform stream: \(w(z - z_{self}) = U_{\infty} e^{- i \alpha} (z - z_{self})\).
- Parameters
z (complex) – Position where the complex potential \(w(z - z_{self})\) is to be computed.
- Returns
Complex potential \(w(z - z_{self})\)
- Return type
complex
- derivative_complex_potential(z)
Returns the derivative of the complex potential \(dw/dz\) of this element at point \(z\): \(dw/dz = u - i v\), where \(u\) and \(v\) are the horizontal and vertical components of the velocity respectively. For a uniform stream:
\[\frac{dw}{dz} = U_{\infty} e^{- i \alpha}\]Please note that \(v\) is given by \(- Im(dw/dz)\).
- Parameters
z (complex) – Position where the derivative of the complex potential \(dw/dz\) is to be computed
- Returns
Derivative of the complex potential
- Return type
complex
Source element
- class flow_element.Source(strength, z_initial, id, tolerance=0.0001)
This class replicates the behavior of a source. It inherits the
FlowElementabstract class.- Parameters
strength (float) – Strength of the source
z_initial (complex) – Initial position of the source
id (int) – Element id for user output
tolerance (float, optional) – If denominator is smaller than tolerance, skips the division and returns 0
- __init__(strength, z_initial, id, tolerance=0.0001)
Constructor method
- print_parameters()
Prints the element’s parameters to console.
- name()
Returns the name of this element, i.e. “Source”
- Returns
Name of the element
- Return type
str
- id()
Returns element id (for plotting)
- Returns
Element id
- Return type
int
- add_walls(slopes, intercepts)
This method adds one or two walls to the flow.
- Parameters
slopes (float) – Slope of the linear function describing the wall
intercepts (float) – Intercept of the linear function describing the wall
- z_initial()
Returns the initial position of the element
- Returns
Initial position of the element
- Return type
complex
- z_current()
Returns the current position of the element
- Returns
Current position of the element
- Return type
complex
- set_z(z)
Sets the current position of the element
- Parameters
z (complex) – Current position
- complex_potential(z)
Returns the complex potential \(w\) of this element at point \(z\): \(w(z - z_{self}) = \phi + i \psi\), where \(\phi\) is the velocity potential and \(\psi\) is the stream function. For a source:
\[w(z - z_{self}) = \frac{m}{2 \pi} ln(z - z_{self})\]- Parameters
z (complex) – Position where the complex potential \(w(z - z_{self})\) is to be computed.
- Returns
Complex potential \(w(z - z_{self})\)
- Return type
complex
- complex_potential_symmetric(z, z_symmetric)
Returns the complex potential \(w\) of self element at point \(z\): \(w(z - z_{vortex}) = \phi + i \psi\), where \(\phi\) is the velocity potential and \(\psi\) is the stream function. This method can be called to add an another self element at position z_symmetric with opposite circulation. For instance, to add a wall, call this method with z_symmetric being the position of the symmetric of self about the wall. For a source:
\[w(z - z_{self}) = \frac{- m}{2 \pi} ln(z - z_{self})\]- Parameters
z (complex) – Position where the complex potential \(w(z - z_{vortex})\) is to be computed.
z_symmetric (complex) – Position of the symmetric element the complex potential is to be computed on
- Returns
Complex potential \(w(z - z_{vortex})\)
- Return type
complex
- derivative_complex_potential(z)
Returns the derivative of the complex potential \(dw/dz\) of this element at point \(z\): \(dw/dz = u - i v\), where \(u\) and \(v\) are the horizontal and vertical components of the velocity respectively. For a source:
\[\frac{dw}{dz} = \frac{m}{2 \pi (z - z_{self})}\]Please note that \(v\) is given by \(- Im(dw/dz)\).
- Parameters
z (complex) – Position where the derivative of the complex potential \(dw/dz\) is to be computed
- Returns
Derivative of the complex potential
- Return type
complex
- derivative_complex_potential_symmetric(z, z_symmetric)
Returns the derivative of the complex potential \(dw/dz\) of this element at point \(z\): \(dw/dz = u - i v\), where \(u\) and \(v\) are the horizontal and vertical components of the velocity respectively. This method can be called to add an another self element at position z_symmetric. For instance, to add a wall, call this method with z_symmetric being the position of the symmetric of self about the wall. For a source:
\[\frac{dw}{dz} = \frac{- m}{2 \pi (z - z_{self})}\]Please note that \(v\) is given by \(- Im(dw/dz)\).
- Parameters
z (complex) – Position where the derivative of the complex potential \(dw/dz\) is to be computed
z_symmetric (complex) – Position of the symmetric element the derivative of the complex potential is to be computed on
- Returns
Derivative of the complex potential
- Return type
complex
Vortex element
- class flow_element.Vortex(circulation, z_initial, id, tolerance=0.0001)
This class replicates the behavior of a vortex. It inherits the
FlowElementabstract class.- Parameters
circulation (float) – Circulation of the vortex
z_initial (complex) – Initial position of the vortex
id (int) – Element id for user output
tolerance (float, optional) – If denominator smaller than tolerance, skips the division
- __init__(circulation, z_initial, id, tolerance=0.0001)
Constructor method
- print_parameters()
Prints element’s parameters to console.
- name()
Returns the name of this element, i.e. “Vortex”
- Returns
Name of the element
- Return type
str
- id()
Returns element id (for plotting)
- Returns
Element id
- Return type
int
- add_walls(slopes, intercepts)
This method adds one or two walls to the flow.
- Parameters
slope (float) – Slope of the linear function describing the wall
intercept (float) – Intercept of the linear function describing the wall
- z_initial()
Returns the initial position of the element
- Returns
Initial position of the element
- Return type
complex
- z_current()
Returns the current position of the element
- Returns
Current position of the element
- Return type
complex
- set_z(z)
Sets the current position of the element
- Parameters
z (complex) – Current position
- complex_potential(z)
Returns the complex potential \(w\) of this element at point \(z\): \(w(z - z_{self}) = \phi + i \psi\), where \(\phi\) is the velocity potential and \(\psi\) is the stream function. For a vortex:
\[w(z - z_{self}) = \frac{- i \Gamma}{2 \pi} ln(z - z_{self})\]- Parameters
z (complex) – Position where the complex potential \(w(z - z_{self})\) is to be computed.
- Returns
Complex potential \(w(z - z_{self})\)
- Return type
complex
- complex_potential_symmetric(z, z_symmetric)
Returns the complex potential \(w\) of self element at point \(z\): \(w(z - z_{vortex}) = \phi + i \psi\), where \(\phi\) is the velocity potential and \(\psi\) is the stream function. This method can be called to add an another self element at position z_symmetric. For instance, to add a wall, call this method with z_symmetric being the position of the symmetric of self about the wall. For a vortex:
\[w(z - z_{vortex}) = \frac{i \Gamma}{2 \pi} ln(z - z_{vortex})\]- Parameters
z (complex) – Position where the complex potential \(w(z - z_{vortex})\) is to be computed.
z_symmetric (complex) – Position of the symmetric element the complex potential is to be computed on
- Returns
Complex potential \(w(z - z_{vortex})\)
- Return type
complex
- derivative_complex_potential(z)
Returns the derivative of the complex potential \(dw/dz\) of this element at point \(z\): \(dw/dz = u - i v\), where \(u\) and \(v\) are the horizontal and vertical components of the velocity respectively. For a vortex:
\[\frac{dw}{dz} = \frac{- i \Gamma}{2 \pi (z - z_{self})}\]Please note that \(v\) is given by \(- Im(dw/dz)\).
- Parameters
z (complex) – Position where the derivative of the complex potential \(dw/dz\) is to be computed
- Returns
Derivative of the complex potential
- Return type
complex
Cylinder element
- class flow_element.Cylinder(radius, z_initial, circulation, fsv, fsi, id, tolerance=0.0001)
This class replicates the behavior of a circular cylinder. It inherits the
FlowElementabstract class.- Parameters
radius (float) – Radius of the cylinder
z_initial (complex) – Initial position of the cylinder
circulation (float) – Circulation of the cylinder
fsv (float) – Free stream velocity
fsi (float) – Free stream angle of incidence in radians
id (int) – Element id for user output
tolerance (float, optional) – If denominator smaller than tolerance, skips the division and returns zero
- __init__(radius, z_initial, circulation, fsv, fsi, id, tolerance=0.0001)
Constructor method
- print_parameters()
Prints element’s parameters to console.
- name()
Returns the name of this element, i.e. “Cylinder”
- Returns
Name of the element
- Return type
str
- id()
Returns element id (for plotting)
- Returns
Element id
- Return type
int
- z_initial()
Returns the initial position of the element
- Returns
Initial position of the element
- Return type
complex
- z_current()
Returns the current position of the element
- Returns
Current position of the element
- Return type
complex
- set_z(z)
Sets the current position of the element
- Parameters
z (complex) – Current position
- complex_potential(z)
Returns the complex potential \(w\) of this element at point \(z\): \(w(z - z_{self}) = \phi + i \psi\), where \(\phi\) is the velocity potential and \(\psi\) is the stream function. For a circular cylinder:
\[w(z - z_{self}) = U_{\infty} ((z - z_{self}) e^{-i \alpha} + \frac{R^2 e^{i \alpha}}{(z - z_{self})}) - \frac{i \Gamma}{2 \pi} ln(z - z_{self})\]- Parameters
z (complex) – Position where the complex potential \(w(z - z_{self})\) is to be computed.
- Returns
Complex potential \(w(z - z_{self})\)
- Return type
complex
- derivative_complex_potential(z)
Returns the derivative of the complex potential \(dw/dz\) of this element at point \(z\): \(dw/dz = u - i v\), where \(u\) and \(v\) are the horizontal and vertical components of the velocity respectively. For a circular cylinder:
\[\frac{dw}{dz} = U_{\infty} (e^{-i \alpha} - \frac{R^2 e^{i \alpha}}{(z - z_{self})^2}) - \frac{i \Gamma}{2 \pi (z - z_{self})}\]Please note that \(v\) is given by \(- Im(dw/dz)\).
- Parameters
z (complex) – Position where the derivative of the complex potential \(dw/dz\) is to be computed
- Returns
Derivative of the complex potential
- Return type
complex
JoukowskiElement element
- class flow_element.JoukowskiElement(z_initial, circulation, radius, fsv, fsi, a, id, tolerance=0.0001)
This class replicates the behavior of an element after the Joukowski transform. It inherits the
FlowElementabstract class.- Parameters
radius (float) – Radius
z_initial (complex) – Initial position
circulation (float) – Circulation
fsv (float) – Free stream velocity
fsi (float) – Free stream angle of incidence in radians
a (float) – Joukowski transform constant
id (int) – Element id for user output
tolerance (float, optional) – If denominator smaller than tolerance, skips the division and returns zero
- __init__(z_initial, circulation, radius, fsv, fsi, a, id, tolerance=0.0001)
Constructor method
- print_parameters()
Prints element’s parameters to console.
- name()
Returns the name of this element, i.e. “Cylinder”
- Returns
Name of the element
- Return type
str
- id()
Returns element id (for plotting)
- Returns
Element id
- Return type
int
- z_initial()
Returns the initial position of the element
- Returns
Initial position of the element
- Return type
complex
- z_current()
Returns the current position of the element
- Returns
Current position of the element
- Return type
complex
- set_z(z)
Sets the current position of the element
- Parameters
z (complex) – Current position
- complex_potential(z)
Returns the complex potential \(w\) of this element at point \(z\): \(w(z - z_{self}) = \phi + i \psi\), where \(\phi\) is the velocity potential and \(\psi\) is the stream function. For a circular cylinder:
\[w(z - z_{self}) = U_{\infty} ((z - z_{self}) e^{-i \alpha} + \frac{R^2 e^{i \alpha}}{(z - z_{self})}) - \frac{i \Gamma}{2 \pi} ln(z - z_{self})\]- Parameters
z (complex) – Position where the complex potential \(w(z - z_{self})\) is to be computed.
- Returns
Complex potential \(w(z - z_{self})\)
- Return type
complex
- derivative_complex_potential(z)
Returns the derivative of the complex potential \(dw/dz\) of this element at point \(z\): \(dw/dz = u - i v\), where \(u\) and \(v\) are the horizontal and vertical components of the velocity respectively. For a circular cylinder:
\[\frac{dw}{dz} = U_{\infty} (e^{-i \alpha} - \frac{R^2 e^{i \alpha}}{(z - z_{self})^2}) - \frac{i \Gamma}{2 \pi (z - z_{self})}\]Please note that \(v\) is given by \(- Im(dw/dz)\).
- Parameters
z (complex) – Position where the derivative of the complex potential \(dw/dz\) is to be computed
- Returns
Derivative of the complex potential
- Return type
complex
Flow container class
- class flow_element.Flow
This iterable class stores all the flow elements in a list. This list is iterated over to compute the complex potential and its derivative. This class inherits the
FlowElementabstract class and overrides its methods.- __init__()
Constructor method. Initializes an empty list and a variable to track the size of the list.
- print_parameters()
Prints the parameters of each flow elements to console.
- empty()
Returns true if there are no elements in the flow.
- Returns
True if the list of flow elements is empty.
- Return type
bool
- num_of_elements()
Returns the number of elements in the flow
- Returns
Number of elements in the flow
- Return type
int
- add_element(element)
Appends element to the list of flow elements.
- Parameters
element (
FlowElement) – Flow element to be added
- remove_element(id)
Removes the element at position id from the list of flow elements. This method has not been tested and should not be used.
- Parameters
id (int) – Index of the flow element to be removed in the flow elements list
- pop_element()
Pops the last element off the flow elements list.
- complex_potential(z)
Returns the complex potential \(w\) of all the flow elements at point \(z\): \(w(z - z_{self}) = \phi + i \psi\), where \(\phi\) is the velocity potential and \(\psi\) is the stream function. This methods iterates over all the elements in the list of flow elements and returns the sum of the complex_potential(z) method calls.
- Parameters
z (complex) – Position where the complex potential \(w(z - z_{self})\) is to be computed.
- Returns
Complex potential \(w(z - z_{self})\)
- Return type
complex
- derivative_complex_potential(z)
Returns the derivative of the complex potential \(dw/dz\) of this element at point \(z\): \(dw/dz = u - i v\), where \(u\) and \(v\) are the horizontal and vertical components of the velocity respectively. This methods iterates over all the elements in the list of flow elements and returns the sum of the derivative_complex_potential(z) method calls. Please note that \(v\) is given by \(- Im(dw/dz)\).
- Parameters
z (complex) – Position where the derivative of the complex potential \(dw/dz\) is to be computed
- Returns
Derivative of the complex potential
- Return type
complex
Walls class
- class flow_element.Walls(slopes, intercepts)
This class adds walls to the flow. When called on a flow element, it adds flow elements of the same type (with opposite circulation) symmetric about the walls. A maximum of two walls can be added. Walls can only be added with
flow_element.Sourceandflow_element.Vortex.- __init__(slopes, intercepts)
Constructor methods To add a vertical wall, set the slope to inf and the intercept to the x coordinate. To add any other straight walls, enter the linear function defining the wall.
- Parameters
slopes (list) – Slopes of the linear functions defining the walls
intercepts (list) – Intercepts of the linear functions defining the walls
- Raises
ValueError – Throws an exception if more than two slopes are passed
- __find_symmetric(z_element)
This private method computes the coordinates of the elements symmetric to z_element about the walls.
- Parameters
z_element (complex) – Position of the element the symmetric are to be computed on.
- Returns
List of positions of the symmetric elements
- Return type
list of complex
- complex_potential(element, z)
Computes the complex potential of the walls (i.e. the symmetric of the element about the walls with opposite circulation) of an element of type element at point z.
- Parameters
element (class:flow_element.FlowElement) – Flow element instance to compute the complex potential on.
z (complex) – Position where the complex potential is to be computed.
- Returns
Complex potential of the walls
- Return type
complex
- derivative_complex_potential(element, z)
Computes the derivative of the complex potential of the walls (i.e. the symmetric of the element about the walls with opposite circulation) of an element of type element at point z.
- Parameters
element (class:flow_element.FlowElement) – Flow element instance to compute the derivative on
z (complex) – Position where the derivative is to be computed.
- Returns
Derivative of the complex potential of the walls
- Return type
complex