-
Notifications
You must be signed in to change notification settings - Fork 2
Elastic_trampoline_files #59
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
Open
Gauravu2
wants to merge
9
commits into
bhosale2:main
Choose a base branch
from
Gauravu2:elastic_trampoline
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2ed8a71
Elastic_trampoline_files
Gauravu2 fa91108
Fix CI fail
Gauravu2 2f00561
Update curl.py
Gauravu2 b7bb631
Update collision_force.py
Gauravu2 865f967
Implicit diffusion added
Gauravu2 f71a880
Merge branch 'main' into elastic_trampoline
bhosale2 4d977d0
Merge branch 'main' into elastic_trampoline
bhosale2 9730f2f
Merge branch 'main' into elastic_trampoline
bhosale2 288ae6a
Merge branch 'main' into elastic_trampoline
bhosale2 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import numpy as np | ||
| import scipy.sparse as spp | ||
|
|
||
|
|
||
| def collision_force(k, phi_1, phi_2, blend_w, grid_size_z, grid_size_r, eps, dx): | ||
| """ | ||
| computes the collision force between 2 bodies | ||
| using their level sets | ||
| """ | ||
|
|
||
| gradient = ( | ||
| spp.diags( | ||
| [-0.5, 0.5, -0.5, 0.5], | ||
| [-1, 1, grid_size_r - 1, -grid_size_r + 1], | ||
| shape=(grid_size_r, grid_size_r), | ||
| format="csr", | ||
| ) | ||
| / dx | ||
| ) | ||
|
|
||
| gradient_T = ( | ||
| spp.diags( | ||
| [-0.5, 0.5, -0.5, 0.5], | ||
| [-1, 1, grid_size_z - 1, -grid_size_z + 1], | ||
| shape=(grid_size_z, grid_size_z), | ||
| format="csr", | ||
| ) | ||
| / dx | ||
| ) | ||
|
|
||
| phi_diff = 0.5 * (phi_2 - phi_1) | ||
| delta_phi = phi_diff * 0 | ||
| delta_phi += ( | ||
| (np.fabs(phi_diff) < blend_w) | ||
| * 0.5 | ||
| * (1 + np.cos(np.pi * phi_diff / blend_w)) | ||
| / blend_w | ||
| ) | ||
| phi_diff_x = np.mat(phi_diff) * gradient_T | ||
| phi_diff_y = gradient * np.mat(phi_diff) | ||
| s = np.sqrt(np.square(phi_diff_x) + np.square(phi_diff_y)) | ||
| phi_diff_x /= s + eps | ||
| phi_diff_y /= s + eps | ||
| S = phi_diff / np.sqrt(phi_diff**2 + eps**2) | ||
| body_mask = np.logical_or((phi_1 > 0), (phi_2 > 0)) | ||
| force_x = body_mask * S * phi_diff_x * k * delta_phi | ||
| force_y = body_mask * S * phi_diff_y * k * delta_phi | ||
| return force_x, force_y | ||
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,31 @@ | ||
| import numpy as np | ||
| import scipy.sparse as spp | ||
|
|
||
|
|
||
| def curl(ax, ay, grid_size_z, grid_size_r, dx): | ||
| """ | ||
| compute curl of the vector using CD | ||
| """ | ||
|
|
||
| gradient = ( | ||
| spp.diags( | ||
| [-0.5, 0.5, -0.5, 0.5], | ||
| [-1, 1, grid_size_r - 1, -grid_size_r + 1], | ||
| shape=(grid_size_r, grid_size_r), | ||
| format="csr", | ||
| ) | ||
| / dx | ||
| ) | ||
|
|
||
| gradient_T = ( | ||
| spp.diags( | ||
| [-0.5, 0.5, -0.5, 0.5], | ||
| [-1, 1, grid_size_z - 1, -grid_size_z + 1], | ||
| shape=(grid_size_z, grid_size_z), | ||
| format="csr", | ||
| ) | ||
| / dx | ||
| ) | ||
|
|
||
| vort = np.mat(ay) * gradient_T - gradient * np.mat(ax) | ||
|
Comment on lines
+5
to
+30
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can't we use |
||
| return vort | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please write the vectorized versions (slice-based, similar to functions in
kernels), Let's skip using the sparse matrices if possible. Also, collision forces should be a part of the main package.