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

Grids now have a topology #614

Merged
merged 20 commits into from
Feb 10, 2020
Merged

Grids now have a topology #614

merged 20 commits into from
Feb 10, 2020

Conversation

ali-ramadhan
Copy link
Member

@ali-ramadhan ali-ramadhan commented Feb 4, 2020

This PR adds grid topologies: Periodic, Bounded, and Singleton. We should finalize our choice of named before merging.

As topology is now a required kwarg of all grid constructors tons of refactoring was needed. It also does a bit of cleanup: AbstractGrid is now defined in the Grids submodule, and grids no longer have the Tx, Ty, Tz property (total number of grid points).

Documentation should be updated before this PR is merged.

Resolves #446
Resolves #459
Resolves #489

@ali-ramadhan ali-ramadhan added cleanup 🧹 Paying off technical debt abstractions 🎨 Whatever that means labels Feb 4, 2020
@ali-ramadhan ali-ramadhan changed the title Grid now have a topology Grids now have a topology Feb 4, 2020
@codecov
Copy link

codecov bot commented Feb 4, 2020

Codecov Report

Merging #614 into master will increase coverage by 0.03%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #614      +/-   ##
==========================================
+ Coverage   74.55%   74.59%   +0.03%     
==========================================
  Files         117      118       +1     
  Lines        2209     2220      +11     
==========================================
+ Hits         1647     1656       +9     
- Misses        562      564       +2     
Impacted Files Coverage Δ
src/BoundaryConditions/boundary_condition_types.jl 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 11c41e1...3bef9da. Read the comment docs.

@glwagner
Copy link
Member

glwagner commented Feb 4, 2020

I don’t like “Singleton”: Periodic and Bounded refer to the physical nature of the dimension, while Singleton obliquely references the size of an underlying array of discrete data. A better name would refer to the physical nature of the coordinate; “Uniform” or “Flat” are examples.

It could make sense to make (Periodic, Periodic, Bounded) a default. This is already the default of Model.

@ali-ramadhan
Copy link
Member Author

I don’t like “Singleton”: Periodic and Bounded refer to the physical nature of the dimension, while Singleton obliquely references the size of an underlying array of discrete data. A better name would refer to the physical nature of the coordinate; “Uniform” or “Flat” are examples.

We're setting up a discrete model anyways, but I guess if it's supposed to model some physical system then "Singleton" may not be completely appropriate.

I'd vote for Flat over Uniform then. Uniform could be multiple grid points while Flat strongly implies one grid point (while both imply homogenous dynamics in that dimension).

It could make sense to make (Periodic, Periodic, Bounded) a default. This is already the default of Model.

Yeah I guess we have a choice here: do we want to make horizontally periodic the default or are users now required to specify a grid topology?

I could see benefits either way. Keeping it the default would introduce no breaking changes and simplify the tests, but requiring it would improve the clarity of most scripts (an issue that has been brought up before, see #459). I think most real scripts (not tests) should be specifying a topology for clarity.

@ali-ramadhan
Copy link
Member Author

Another design we can consider is something like:

grid = RegularCartesianGrid(size=(x=128, z=64), x=(-1, 1), z=(-1, 0), topology=(x=Periodic, z=Bounded))

where since y has not been specified, it is assumed to be Flat.

This makes the grid constructors more verbose but has the added benefit of being clearer and not having to specify flat dimensions, i.e. it's an xz-model so y should not even be mentioned.

It would require a lot more refactoring though... but now's the time I guess.

@glwagner
Copy link
Member

glwagner commented Feb 4, 2020

It would require a lot more refactoring though... but now's the time I guess.

I think explicit is better.

Why do we need to refactor? Why don't we just specify a default topology in the grid constructor? Then, the only refactoring we need to do is for models in the channel domain.

@glwagner
Copy link
Member

glwagner commented Feb 4, 2020

I'd vote for Flat over Uniform then. Uniform could be multiple grid points while Flat strongly implies one grid point (while both imply homogenous dynamics in that dimension).

I'm fine with Flat. But the topology does not restrict how many grid points one uses. I don't see the point of doing that. We only need this for eliding derivative operations, not restricting user behavior.

@ali-ramadhan
Copy link
Member Author

Why do we need to refactor? Why don't we just specify a default topology in the grid constructor? Then, the only refactoring we need to do is for models in the channel domain.

I'll add a default topology=(Periodic, Periodic, Bounded) then.

The bigger refactor would be if we decided to go with named tuples like size=(x=16, z=32) instead of just tuples size=(16, 1, 32).

I'm fine with Flat.

Flat it is then.

But the topology does not restrict how many grid points one uses. I don't see the point of doing that. We only need this for eliding derivative operations, not restricting user behavior.

True but I don't see the point of running with more than one grid point in a dimension that's supposed to be Singleton or Flat. But I guess users can do many weird things, and this wouldn't be the weirdest.

Copy link
Member

@glwagner glwagner left a comment

Choose a reason for hiding this comment

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

Looks great.

Oceananigans.Operators

using Oceananigans: AbstractGrid
using Printf
Copy link
Member

Choose a reason for hiding this comment

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

Is this preferred style? Why? I like fewer characters...

src/Grids/regular_cartesian_grid.jl Outdated Show resolved Hide resolved
using Oceananigans.Architectures: @hascuda
@hascuda using CUDAnative, CuArrays

using Oceananigans.Architectures
using Oceananigans.Grids
using Oceananigans.Operators
using Oceananigans.Coriolis
Copy link
Member

Choose a reason for hiding this comment

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

Explicit imports might be nice here for all these physics terms... but we can save this for later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
abstractions 🎨 Whatever that means cleanup 🧹 Paying off technical debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Grid Topology concept Use less defaults in model construction? Use FT for "floating point type"
2 participants