Skip to content
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

Refactor llw2d.initheight #138

Merged
merged 1 commit into from
Jan 11, 2021
Merged

Refactor llw2d.initheight #138

merged 1 commit into from
Jan 11, 2021

Conversation

tkoskela
Copy link
Member

closes #134

  • Added parameters for peak position and peak height that were previously hard-coded
  • Created a helper function get_initial_height that can be broadcast over the grid. No need for loops.

Master:

@btime Model.LLW2d.initheight!(h, matrices.ocean_depth, params.dx, params.dy, params.source_size);
  4.016 ms (120006 allocations: 10.99 MiB)

This PR

@btime Model.LLW2d.initheight!(h, matrices.ocean_depth, params.dx, params.dy, params.source_size, params.peak_height, params.peak_position);
  237.715 μs (11 allocations: 9.61 KiB)

Copy link
Member

@giordano giordano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!!


dx = peak_x - x
dy = peak_y - y
distance_to_peak = sqrt(dx^2 + dy^2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment: this can also be done with the hypot function:

Suggested change
distance_to_peak = sqrt(dx^2 + dy^2)
distance_to_peak = hypot(dx, dy)

While being more accurate (it doesn't overflow/underflow), hypot is slower than sqrt(...^2 + ...^2 + ...). However for the values of dx and dy we expect, hypot might be an overkill, so in the end this should be fine as it is

@tkoskela tkoskela merged commit 2c60f1a into master Jan 11, 2021
@tkoskela tkoskela deleted the tk/initheight branch January 11, 2021 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parametrize initial condition in llw2d properly
2 participants