-
Notifications
You must be signed in to change notification settings - Fork 78
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
Level global cell for CpGrid with LGRs #762
Conversation
e9e6a57
to
694547c
Compare
jenkins build this please |
694547c
to
c70338f
Compare
jenkins build this please |
9ba2308
to
f1f25d0
Compare
jenkins build this please |
f1f25d0
to
c70338f
Compare
If we refine without LGRs, what size and values does globalCell have for the levels? |
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.
Looks good.
Just a few suggestions for better code reuse.
There are also comments on checks that won't hold if there are inactive cells. Maybe that is tested elsewhere and irrelevant?
opm/grid/cpgrid/CpGrid.cpp
Outdated
std::array<int,3> childIJK = {0,0,0}; | ||
|
||
childIJK[0] = idx_in_parent_cell % cells_per_dim[0]; | ||
idx_in_parent_cell -= childIJK[0]; // k*cells_per_dim[0]*cells_per_dim[1] + j*cells_per_dim[0] | ||
idx_in_parent_cell /= cells_per_dim[0]; // k*cells_per_dim[1] + j | ||
childIJK[1] = idx_in_parent_cell % cells_per_dim[1]; | ||
idx_in_parent_cell -= childIJK[1]; // k*cells_per_dim[1] | ||
childIJK[2] = idx_in_parent_cell /cells_per_dim[1]; |
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.
Such computations are done a lot. It might be good to refactor them out to a separate function and reuse it elsewhere (e.g. CpGridData::getIJK
)
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.
This is now in CpGridData::getInParentCellIJK()
tests/cpgrid/adapt_cpgrid_test.cpp
Outdated
auto itMin = std::min_element((data.back() -> global_cell_).begin(), (data.back()-> global_cell_).end()); | ||
auto itMax = std::max_element((data.back() -> global_cell_).begin(), (data.back() -> global_cell_).end()); | ||
BOOST_CHECK_EQUAL( *itMin, 0); | ||
BOOST_CHECK_EQUAL( *itMax, data.front()-> size(0) -1); |
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.
Maybe change this test to work also for grid with inactive cells?
You could check that each value is between zero and the maximum cartesian index possible.
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.
tests/cpgrid/adapt_cpgrid_test.cpp
Outdated
auto itMinLevel = std::min_element((data[level] -> global_cell_).begin(), (data[level] -> global_cell_).end()); | ||
auto itMaxLevel = std::max_element((data[level] -> global_cell_).begin(), (data[level] -> global_cell_).end()); | ||
BOOST_CHECK_EQUAL( *itMinLevel, 0); | ||
BOOST_CHECK_EQUAL( *itMaxLevel, data[level]-> size(0) -1); |
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.
Same here and below. There could be inactive parent cells in the region to refine and hence missing kids (in the future?).
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.
Now the check is done with inequalities, meaning that the maximum value of global cell should be between 0 and the maximum Cartesian Index (the later might vary for each LGR, and it's equal to the maximum Cartesian Index from level zero for the leaf grid view)
Good point. I didn't comment on that in the PR description. When we refine without LGRs, the size of global_cell_ coincides with the total amount of cells on the level grid/leaf grid view. For refined level grids, the values are 0,1,2,..., total amount of cells in that refined level grid. For the leaf grid view, both refine-methods (with or without LGRs) do exactly the same: <leaf_grid_view>.global_cell_[ leaf cell index ] = global_cell_ value of the oldest ancestor from level zero. One idea to make these two refine-approaches compatible is to detect minimum and maximums ijk values of marked cells, and mimic what's done for LGRs in the without-LGRs refinement, with these "fake startIJK and endIJK" |
I don't think we should make them compatible as they are not. cartesian indices on the level only makes sense for LGRs. In the long term we should probably throw if useers use them in adaptively refined grids. Let's postpone this, though, |
c70338f
to
a8aeded
Compare
a8aeded
to
de130b7
Compare
Now there are a few lines in inactiveCell_test.cpp checking that the max value of global cell is below the max Cartesian Index for level grids, and for the leaf (which corresponds to the max Cartesian Index value of level zero grid) |
jenkins build this please |
@blattms thanks for your feedback! (which is now incorporated) |
opm/grid/cpgrid/CpGridData.hpp
Outdated
/// (total amount of children of a parent cell minus one since starting index is zero). | ||
/// @param [in] cells_per_dim | ||
/// @param [out] ijk In-parent-cell Cartesian index triplet | ||
void getInParentCellIJK(int idx_in_parent_cell, const std::array<int,3>& cells_per_dim, std::array<int,3>& ijk) const |
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.
Isn't this much more general than the name and the documentation suggests? It seems to convert a cartesian index to ijk and has no relation to refinement. You just happen to use it during refinement, currently. Why not simply name it getIJK?
In addition we could just return the ijk directly and only have two parameters.
Then you can do this in line 306: ijk = getIK(c, logical_cartesian_size_);
and that method is done.
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.
It sounds doable. I kept both methods since CpGrid::getIJK uses current_view_data_ ->getIJK (which is CpGridData::getIJK), and the integer argument "c" then it's used to get global_cell_[c] and then with this new integer, the "usual repeated deduction of ijk is done"
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.
It's probably your comment combined with ijk = getIJK(global_cell_[c], logical_cartesian_size_)
jenkins build this please |
This PR is relevant for including wells on LGRs (CpGrid). Potentially relevant for output files too.
For CpGrid with LGRs, we determine the
global_cell_
values for refined level grids.If an LGR has
NX * NY * NZ
dimension (amount of cells in each direction x,y,z respectively), then each refined cell can be associated with a (local) IJK and its (local) Cartesian index.For a leaf grid view, we assign the
global_cell_
values of either the parent cell or the equivalent cell from level zero.Not relevant for the Reference Manual.