Skip to content

Rangeiterator to region in Solver#972

Merged
ZedThree merged 10 commits intonextfrom
rangeiterator-to-region
Jun 14, 2018
Merged

Rangeiterator to region in Solver#972
ZedThree merged 10 commits intonextfrom
rangeiterator-to-region

Conversation

@bendudson
Copy link
Contributor

  • Adds regions RGN_UPPER_Y, RGN_LOWER_Y, RGN_INNER_X, RGN_OUTER_X, RGN_UPPER_INNER_Y, RGN_UPPER_OUTER_Y, RGN_LOWER_INNER_Y, RGN_LOWER_OUTER_Y and RGN_BNDRY (all boundaries).
  • Solver now uses Regions to loop over grid points and copy data to/from fields. Note that this changes the order in which evolving variables appear, if evolving boundaries are used. It has the advantage that the part of the grid which is evolved in time could potentially be modified using a custom Region.
  • Region constructor now creates an empty region if given an empty range of indices (e.g. xend < xstart). This is to allow empty regions to be created, and to make porting the boundary region creation code.

Much of the remaining use of RangeIterator requires index offsets, for example when setting boundary conditions.

Adds function call to BoutMesh::load which creates Regions for the X
and Y boundaries. Currently called

RGN_UPPER_Y
RGN_LOWER_Y
RGN_INNER_X
RGN_OUTER_X
RGN_LOWER_INNER_Y
RGN_LOWER_OUTER_Y
RGN_UPPER_INNER_Y
RGN_UPPER_OUTER_Y

In Solver the size of the regions is used to work out the number of
points which are evolving. To get this a `size` member function and
templated function are added.

Code in solver now considerably shorter, since just iterates over
region names.
Added a constructor Ind3D(SpecificInd) to allow indexing of a Field3D
by Ind2D + int  (z index offset).

New region "RGN_ALL_BOUNDARIES" which contains a unique set
of points in the boundaries.

Solver class changed to use RGN_NO_BNDRY and RGN_ALL_BOUNDARIES to
loop over points. This should make it possible to turn off time
evolution in parts of the grid, for example in odd-shaped domains.
Previously passing in an invalid range of indices,
where xend+1 <= ystart, for example, would throw.
This has some benefits, and could potentially catch code errors.
Unfortunately it also prevents empty regions being created,
and would complicate the code to create boundary regions.

Changed so that invalid index ranges are just empty.
Thanks to @d7919. The implicit conversion of Ind2D
to Ind3D is fixed and replaced by an explicit calculation.
Rather than throwing an exception, the code now returns an empty
region.
Less descriptive, but more consistent with RGN_NOBNDRY.
Region construction still throws if given invalid ny or nz sizes.
Replacing RangeIterator with Region, using the same
order as the Solver class to iterate over elements.
@ZedThree
Copy link
Member

Once #934 is merged (just waiting for tests), this can use those 2D <-> 3D conversion functions.

Also, we should add unit tests for these. I realise these are a bit more complicated as there's lots of possible combinations, but I'll have a stab at them tomorrow.

@ZedThree ZedThree added the work in progress Not ready for merging label Apr 27, 2018
ZedThree added 2 commits June 6, 2018 14:58
* next: (629 commits)
  Fix typo in collect
  Fix exit status of quiet script
  Apply fix for MXG!=1 to LaplaceSPT and LaplaceSerialBand
  Revert change to INVERT_BNDRY_ONE cases
  Allow number of x-boundary points to change in FFT Laplace solvers
  Fix order of arguments in call to tridagMatrix in LaplaceSPT
  Fix for updated breathe on readthedocs
  Zoidberg fixes for ny=1
  Show inheritance in boutarray module to see it inherits from numpy
  Removing matplotlib/numpy/scipy mock modules from sphix conf
  Add todo about removing numpy.random.normal import
  Add numpydocs-style docstring for datafile
  Don't reimport sys in sphinx conf.py
  Add numpydocs-style docstring for options
  Replace 8 spaces with 4
  Fix formatting with list in argument description
  Fix formatting for *args, **kwargs
  Use more consistent formatting of list of types
  Finish the numpdocs for zoidberg
  Move Python doc TODOs into own sections
  ...
if(bndry && !f.evolve_bndry)
continue;
(*f.var)(jx, jy, jz) = udata[p];
(*f.var)[Ind3D(i2d.ind*nz + jz)] = udata[p];
Copy link
Member

Choose a reason for hiding this comment

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

I've finally got around to updating this, but it ends up looking like:

        (*f.var)[f.var->getMesh()->ind2Dto3D(i2d, jz)] = udata[p];

Given that we're already looping over mesh->LocalNz, I'm not 100% sure this is any better. I suspect that solver probably assumes all the fields it's evolving are on the same mesh anyway...

@ZedThree ZedThree removed the work in progress Not ready for merging label Jun 7, 2018
@ZedThree ZedThree merged commit eb32f7a into next Jun 14, 2018
@ZedThree ZedThree deleted the rangeiterator-to-region branch June 14, 2018 15:48
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.

3 participants