A fun, lightweight tool to visualize potential flows quickly!
Project description
PotentialFlowVisualizer (PFV)
By Peter Sharpe
A fun, lightweight tool to visualize potential flows quickly!
PFV Description
PotentialFlowVisualizer is a convenient Python library that can be used to quickly visualize various potential flow fields. If you're new to potential flows, I've written a short intro at the bottom of this document.
PFV syntax is explicitly designed to be concise and readable. Rendering of flow fields happens through Plot.ly's beautiful visualization tools. This library is designed to have minimal dependencies - it requires just NumPy and Plotly.
Installation
Install with pip: pip install potentialflowvisualizer
Examples
Here are a few examples to show you how you might use PFV to look at basic flowfields:
Freestream, Source, and Sink (Rankine Oval)
from potentialflowvisualizer import *
field = Flowfield([
Freestream(1, 0),
Source(10, -3, 0),
Source(-10, 3, 0),
])
field.draw("streamfunction")
Lifting Cylinder Flow
from potentialflowvisualizer import *
field = Flowfield([
Freestream(1, 0),
Vortex(20, 0, 0),
Doublet(-100, 0, 0, 0)
])
field.draw("streamfunction")
Nonlifting NACA0020
Here, we use some key results of slender body theory to (approximately) model a thin streamlined body.
from potentialflowvisualizer import *
# Body Geometry definition
x = np.linspace(-5, 5, 21)
c = np.max(x) - np.min(x)
x0 = np.min(x)
y = 0.2 * c * 10 * (
+ 0.2969 * ((x - x0) / c) ** 0.5
- 0.1260 * ((x - x0) / c)
- 0.3516 * ((x - x0) / c) ** 2
+ 0.2843 * ((x - x0) / c) ** 3
- 0.1036 * ((x - x0) / c) ** 4
)
dy = np.diff(y)
# Freestream properties
V = 1
# Set up the flowfield
field = Flowfield([
Freestream(V, 0)
])
field.objects.extend( # Add line sources to model the thickness
[LineSource(V * dy[i], x[i], 0, x[i + 1], 0) for i in range(len(x) - 1)]
)
field.draw("streamfunction") # And visualize it
Nonlifting NACA0020 at an Angle
To first order, we can model the flow around a NACA0020 section at an angle by adding doublets. (Note that the lack of net vorticity means that this is a nonlifting flow.) As we can see, slender body theory starts to break down a bit in this case.
from potentialflowvisualizer import *
# Body Geometry definition
x = np.linspace(-5, 5, 51)
c = np.max(x) - np.min(x)
x0 = np.min(x)
y = 0.2 * c * 10 * (
+ 0.2969 * ((x - x0) / c) ** 0.5
- 0.1260 * ((x - x0) / c)
- 0.3516 * ((x - x0) / c) ** 2
+ 0.2843 * ((x - x0) / c) ** 3
- 0.1036 * ((x - x0) / c) ** 4
)
dy = np.diff(y)
# Freestream properties
V = 1
alpha = 10
alpha_rad = np.radians(alpha)
# Set up the flowfield
field = Flowfield([
Freestream(V * np.cos(alpha_rad), V * np.sin(alpha_rad))
])
field.objects.extend( # Add line sources to model the thickness
[LineSource(V * dy[i], x[i], 0, x[i + 1], 0) for i in range(len(x) - 1)]
)
field.objects.extend( # Add doublets to model crossflow
[Doublet(2 * V * y[i] * alpha_rad, x[i], 0, np.radians(90)) for i in range(len(x))]
)
field.draw("streamfunction") # And visualize it
Potential Flow: A 30-second Crash Course
Potential flow is a model of how fluids behave under certain mathematically-convenient assumptions. Potential flows can be described by a short, elegant equation:
Here, is a scalar that represents the "velocity potential" at a given point - we use the word "potential", because it's sort of analogous to potential energy or a voltage potential. To find the fluid's velocity at a point, we look at the derivatives of the potential at that point:
There are a few "fundamental solutions" to this governing equation - a few of these are shown below. The governing equation is linear, so we can superimpose various fundamental solutions until we obtain a flowfield that describes some physically-relevant situation.
Because of this, potential flow is applicable to many common problems in aerodynamics and hydrodynamics. Furthermore, the ability to break complex flow fields into simple "fundamental solutions" allows engineers to gain an intuitive understanding of the physics at play - something that can be much more difficult with other, more complicated flow models.
License
MIT License
Copyright 2020 Peter Sharpe
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file PotentialFlowVisualizer-0.2.1.tar.gz
.
File metadata
- Download URL: PotentialFlowVisualizer-0.2.1.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/3.10.0 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.8.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66e0da063ace2b2d8fd37fc23db5d81c724f10715a7e09425c822ab11e8b16ad |
|
MD5 | 883e52a8c5984750c031be7cbdb89f2e |
|
BLAKE2b-256 | f6f8a2ea77ee000a34c6537b49bf99b6e63d32a00443eae516553177be60dd20 |
File details
Details for the file PotentialFlowVisualizer-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: PotentialFlowVisualizer-0.2.1-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/3.10.0 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.8.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e6d4ca6b87f5a4a97f438d1dcf6820342bf539baf2d20e7e996547313fc6477 |
|
MD5 | 946124e2519e5862c255a5d121c3ca4c |
|
BLAKE2b-256 | 60d40edf6cd312bc46f32a5e65e529ea786b38b5749e012216755841049c96a1 |