-
-
Notifications
You must be signed in to change notification settings - Fork 122
Add solid fake for perpendicular flap tutorial #541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f025c94
Added solid-fake for perpendicular flap tutorial
NiklasVin a94a44a
Formatting
NiklasVin 806d99f
Simplify fake model
NiklasVin 8686c5e
Format
NiklasVin b71da70
Merge branch 'precice:develop' into solid-fake
NiklasVin e93232e
Add solid fake to list of solid solvers in README
NiklasVin 40ca2ab
Add suggested changes, run and requirements file
NiklasVin 81f6797
Add suggested changes
NiklasVin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,92 @@ | ||
from __future__ import division | ||
|
||
import numpy as np | ||
import precice | ||
|
||
|
||
def displace_flap(x, y, t, flap_tip_y): | ||
x_displ = np.zeros_like(x) | ||
y_displ = np.zeros_like(y) | ||
# get displacement independent of x, only dependent on y and t | ||
max_x_displ = 0.5 | ||
period_fac = 3 * np.pi | ||
damping_fac = 8 # damps the amplitude of the sine | ||
# defines how much the sine is shifted in y-direction | ||
shift = 0.95 | ||
# wiggles the flap periodically. | ||
# the arcsin(-shift) in the sine evaluation is necessary to start at a flap displacement of 0 at t=0 | ||
# (i.e. sin(arcsin(-shift))+shift = 0) | ||
x_displ = np.minimum(((np.sin(period_fac * t + np.arcsin(-shift)) + shift) / | ||
damping_fac), max_x_displ) * y / flap_tip_y | ||
|
||
dimensions = 2 | ||
displ = np.zeros((len(x), dimensions)) | ||
displ[:, 0] = x_displ | ||
displ[:, 1] = y_displ | ||
|
||
return displ | ||
|
||
|
||
configuration_file_name = "../precice-config.xml" | ||
participant_name = "Solid" | ||
mesh_name = "Solid-Mesh" | ||
write_data_name = 'Displacement' | ||
|
||
solver_process_index = 0 | ||
solver_process_size = 1 | ||
|
||
# define mesh | ||
H = 1 | ||
W = 0.1 | ||
|
||
interface = precice.Participant(participant_name, configuration_file_name, solver_process_index, solver_process_size) | ||
dimensions = interface.get_mesh_dimensions(mesh_name) | ||
assert (dimensions == 2) | ||
|
||
x_left = 0.0 - 0.5 * W # left boundary of the flap | ||
x_right = 0.5 * W # right boundary of the flap | ||
y_bottom = 0.0 # bottom of the flap | ||
y_top = y_bottom + H # top of the flap | ||
|
||
n = 24 # Number of vertices per side | ||
t = 0 | ||
|
||
vertices = np.zeros((2 * n, dimensions)) | ||
# define vertices of flap's left side | ||
vertices[:n, 1] = np.linspace(y_bottom, y_top, n) | ||
vertices[:n, 0] = x_left | ||
# define vertices of flap's right side | ||
vertices[n:, 1] = np.linspace(y_bottom, y_top, n) | ||
vertices[n:, 0] = x_right | ||
|
||
vertex_ids = interface.set_mesh_vertices(mesh_name, vertices) | ||
|
||
if interface.requires_initial_data(): | ||
# initially, there should be no displacement | ||
interface.write_data(np.zeros_like(vertices)) | ||
|
||
interface.initialize() | ||
NiklasVin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# change if necessary | ||
solver_dt = np.inf | ||
# for checkpointing | ||
t_cp = 0 | ||
|
||
while interface.is_coupling_ongoing(): | ||
if interface.requires_writing_checkpoint(): | ||
t_cp = t | ||
|
||
precice_dt = interface.get_max_time_step_size() | ||
dt = min([solver_dt, precice_dt]) | ||
# wiggle the flap | ||
write_data = displace_flap(vertices[:, 0], vertices[:, 1], t, H) | ||
|
||
interface.write_data(mesh_name, write_data_name, vertex_ids, write_data) | ||
interface.advance(dt) | ||
|
||
if interface.requires_reading_checkpoint(): | ||
t = t_cp | ||
else: | ||
# update t | ||
t += dt | ||
|
||
interface.finalize() |
This file contains hidden or 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 @@ | ||
numpy >1, <2 | ||
pyprecice==3 |
This file contains hidden or 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,7 @@ | ||
#!/usr/bin/env sh | ||
set -e -u | ||
|
||
python3 -m venv .venv | ||
. .venv/bin/activate | ||
pip install -r requirements.txt | ||
python3 fake.py |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.