-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0619ed4
Showing
14 changed files
with
629 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
__pycache__ | ||
outputs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"tag": "inflow", | ||
"example": "inflow", | ||
"N": 256, | ||
"dt": 1, | ||
"T": 200, | ||
"diff": 0, | ||
"visc": 0, | ||
"draw": "mix", | ||
"fps": 20, | ||
"save_grids": 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"tag": "taylorgreen", | ||
"example": "taylorgreen", | ||
"N": 32, | ||
"dt": 0.05, | ||
"T": 100, | ||
"diff": 0, | ||
"visc": 0, | ||
"draw": "velocity", | ||
"fps": 20, | ||
"save_grids": 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"tag": "vortexsheet", | ||
"example": "vortexsheet", | ||
"N": 128, | ||
"dt": 0.025, | ||
"T": 100, | ||
"diff": 0, | ||
"visc": 0, | ||
"draw": "density", | ||
"fps": 20, | ||
"save_grids": 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import importlib | ||
|
||
|
||
def get_example_setup(name): | ||
try: | ||
module = importlib.import_module("examples." + name) | ||
setup = getattr(module, "setup") | ||
return setup | ||
except Exception as e: | ||
print(e) | ||
raise RuntimeError(f"Cannot find example setup. Example name: {name}.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# from https://github.com/GregTJ/stable-fluids/blob/main/example.py | ||
import numpy as np | ||
|
||
|
||
def create_circular_points(point_dist: float, point_count: int): | ||
points = np.linspace(-np.pi, np.pi, point_count, endpoint=False) | ||
points = tuple(np.array((np.cos(p), np.sin(p))) for p in points) | ||
normals = tuple(-p for p in points) | ||
points = tuple(point_dist * p for p in points) | ||
return points, normals | ||
|
||
|
||
def inflow_velocity(coords: np.ndarray, vel: float=1. / 250, point_radius: float=0.032, point_dist: float=0.8, point_count: int=4): | ||
points, normals = create_circular_points(point_dist, point_count) | ||
|
||
inflow_velocity = np.zeros_like(coords) | ||
for p, n in zip(points, normals): | ||
mask = np.linalg.norm(coords - p[None, None], 2, axis=-1) <= point_radius | ||
inflow_velocity[mask] += n[None] * vel | ||
return inflow_velocity | ||
|
||
|
||
def inflow_density(coords: np.ndarray, point_radius: float=0.032, point_dist: float=0.8, point_count: int=4): | ||
points, normals = create_circular_points(point_dist, point_count) | ||
|
||
inflow_density = np.zeros(coords.shape[:-1]) | ||
for p in points: | ||
mask = np.linalg.norm(coords - p[None, None], 2, axis=-1) <= point_radius | ||
inflow_density[mask] = 1 | ||
return inflow_density | ||
|
||
|
||
setup = { | ||
"domain": [[-1, 1], [-1, 1]], | ||
"vsource": inflow_velocity, | ||
"dsource": inflow_density, | ||
"src_duration": 60 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import numpy as np | ||
|
||
|
||
def taylorgreen_velocity(coords: np.ndarray): | ||
"""taylorgreen velocity. domain: [0, 2pi] x [0, 2pi]. | ||
Args: | ||
coords (np.ndarray): coordinates of shape (..., 2) | ||
Returns: | ||
velocity: velocity at coordinates | ||
""" | ||
A = 1 | ||
a = 1 | ||
B = -1 | ||
b = 1 | ||
x = coords[..., 0] | ||
y = coords[..., 1] | ||
u = A * np.sin(a * x) * np.cos(b * y) | ||
v = B * np.cos(a * x) * np.sin(b * y) | ||
vel = np.stack([u, v], axis=-1) | ||
return vel | ||
|
||
|
||
setup = { | ||
"domain": [[0, 2 * np.pi], [0, 2 * np.pi]], | ||
"vsource": taylorgreen_velocity, | ||
"dsource": None, | ||
"src_duration": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import numpy as np | ||
|
||
|
||
def vortexsheet_velocity(coords: np.ndarray, rigidR=0.5, rate=0.1): | ||
"""domain: [-1, 1] x [-1, 1]""" | ||
w = 1 * 1.0 / rate | ||
R = np.linalg.norm(coords, 2, axis=-1) | ||
mask = R < rigidR | ||
weight = 1 | ||
u = w * coords[..., 1] * weight | ||
v = -w * coords[..., 0] * weight | ||
u[~mask] = 0 | ||
v[~mask] = 0 | ||
vel = np.stack([u, v], axis=-1) | ||
return vel | ||
|
||
|
||
def vortexsheet_density(coords: np.ndarray, rigidR=0.5): | ||
R = np.linalg.norm(coords, 2, axis=-1) | ||
den = np.zeros(coords.shape[:-1]) | ||
den[R < rigidR] = 1.0 | ||
return den | ||
|
||
|
||
setup = { | ||
"domain": [[-1, 1], [-1, 1]], | ||
"vsource": vortexsheet_velocity, | ||
"dsource": vortexsheet_density, | ||
"src_duration": 1 | ||
} |
Oops, something went wrong.