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

XZInterpolation rename, and passing Options to XZInterpolation objects #1896

Merged
merged 40 commits into from
Mar 2, 2020

Conversation

johnomotani
Copy link
Contributor

@johnomotani johnomotani commented Jan 23, 2020

Rename Interpolation to XZInterpolation as it only supports a specific type of interpolation, and we might introduce other types in future.

Update the XZInterpolation constructor so it accepts an Options* opt argument, so the options can be used by the implementations.

Structure the sections for the options controlling ParallelTransform objects and XZInterpolation objects more sensibly. Previously: all Interpolation objects used the [interpolation] section; FCITransform objects used an [fci] section; and the type of parallel transform was set by mesh:paralleltransform. Now the ParallelTransforms are created using a paralleltransform subsection of the mesh options ([mesh:paralleltransform]) by default, with the type set by e.g.

[mesh:paralleltransform]
type = fci

The interpolations used by FCI take their type (and any other options that might be added in future) from a subsection of the paralleltransform section, e.g.

[mesh:paralleltransform:xzinterpolation]
type = lagrange4pt

Introduces another convenience overload for the generic Factory, Factory::create(Options* options, Args&&... args) , that makes using factories inside another class neater, when following the pattern: calling class gets passed Options section in its constructor; calling class passes relevant subsection to member objects (and the subsection should determine the particular type of a generic member object).

Breaking changes:

  • Interpolation class is renamed to XZInterpolation - should not affect user code
    • All the implementations are also renamed XZHermiteSpline, etc.
  • XZInterpolation declaration moved from include/interpolation.hxx to include/interpolation_xz.hxx - should not affect user code
    • note most uses of #include "interpolation.hxx" in user code are probably for interp_to(), which is not affected by this PR, and not for XZInterpolation`
  • Type of parallel transform is now set in type entry of [mesh:paralleltransform] section, instead of paralleltransform entry of [mesh] section
  • FCI options are set in [mesh:paralleltransform] instead of [fci]
    • The only option at the moment was fci:z_periodic, which is now mesh:paralleltransform:z_periodic
  • Default section for XZInterpolation options is [xzinterpolation] instead of [interpolation]
  • Interpolation used by a ParallelTransform uses options from a subsection of [mesh:paralleltransform], for example the FCI interpolation options are set in [mesh:paralleltransform:xzinterpolation]

ParallelTransforms now get options from a "paralleltransform" subsection
of the mesh options, so by default [mesh:paralleltransform], when they
are created by Coordinates.

For FCITransform, this replaces the [fci] section.
These were used by the InterpolationFactory before the change to use the
generic Factory.
In preparation for introducing other types of interpolation class,
rename to make clear that XZInterpolation, and its various
implementations, are specifically for 2d interpolations in the x-z
plane.
Also rename:
- src/mesh/interpolation.cxx to src/mesh/interpolation_xz.cxx.
- src/mesh/interpolation/bilinear.cxx to
  src/mesh/interpolation/bilinear_xz.cxx
- src/mesh/interpolation/hermite_spline.cxx to
  src/mesh/interpolation/hermite_spline.cxx
- src/mesh/interpolation/lagrange4pt.cxx to
  src/mesh/interpolation/lagrange4pt.cxx
- src/mesh/interpolation/monotonic_hermite_spline.cxx to
  src/mesh/interpolation/monotonic_hermite_spline.cxx
Since options for setting parallel transform were moved from the
mesh:paralleltransform option to mesh:paralleltransform:type, update
inputfiles and places where that option is read in example code.
Allows implementations to use passed-in options if needed.

Rename interpolation options sections from "interpolation" to
"xzinterpolation".
Convenience overload for the generic Factory that provides a method to
create an object while getting the type from Options*. This is useful
when creating objects inside another class which wants to pass a
subsection from its own options.
@johnomotani johnomotani added the breaking change Introduces a change that is not backward compatible with the previous major version label Jan 23, 2020
@dschwoerer
Copy link
Contributor

Rename Interpolation to XZInterpolation as it only supports a specific type of interpolation, and we might introduce other types in future.

I am not sure we should make it more complicated then needed. Are you intending to introduce other interpolation schemes?

Structure the sections for the options controlling ParallelTransform objects and XZInterpolation objects more sensibly. Previously: all Interpolation objects used the [interpolation] section; FCITransform objects used an [fci] section; and the type of parallel transform was set by mesh:paralleltransform. Now the ParallelTransforms are created using a paralleltransform subsection of the mesh options ([mesh:paralleltransform]) by default, with the type set by e.g.

Could you provide a script to fix input files automatically?

@johnomotani
Copy link
Contributor Author

Rename Interpolation to XZInterpolation as it only supports a specific type of interpolation, and we might introduce other types in future.

I am not sure we should make it more complicated then needed. Are you intending to introduce other interpolation schemes?

Yes, there's a ZInterpolation coming in #1803.

Could you provide a script to fix input files automatically?

@ZedThree suggested on Slack that we do so https://bout-project.slack.com/archives/CJYH9Q70X/p1579779782011800. It should be possible, but I'm not planning to write one due to lack of time. I think a good start would be to make an input file parser that preserves structure and comments when it writes out again (which the BoutOptionsFile Python class does not do). Could be a feature to add to boutproject/xBOUT#94?

@johnomotani
Copy link
Contributor Author

a good start would be to make an input file parser that preserves structure and comments when it writes out again (which the BoutOptionsFile Python class does not do).

If that was done, we could use something like this

#!/usr/bin/env python3

from boutdata.data import BoutOptionsFile
from copy import deepcopy

def fixInputFile4to5(f):
    # fix parallel transform options, see PR #1896
    if 'mesh' in f:
        meshopts = f.getSection('mesh')
        if 'paralleltransform' in meshopts:
            ptvalue = meshopts['paralleltransform']
            del meshopts['paralleltransform']
            ptopts = meshopts.getSection('paralleltransform')
            ptopts['type'] = ptvalue
    if 'fci' in f:
        if f['fci'].sections():
            raise ValueError('Do not know what to do with subsections of [fci]')
        ptopts = f.getSection('mesh').getSection('paralleltransform')
        for key in f['fci'].keys():
            ptopts[key] = f['fci'][key]
        del f['fci']

    # fix interpolation options, see PR #1896
    if 'interpolation' in f:
        if f['interpolation'].sections():
            raise ValueError('Do not know what to do with subsections of [interpolation]')
        newsection = meshopts.getSection('paralleltransform').getSection('xzinterpolation')
        for key in f['interpolation'].keys():
            newsection[key] = f['interpolation'][key]
        del f['interpolation']

    return f


if __name__ == '__main__':
    from sys import argv, exit

    filename = argv[1]
    
    f = BoutOptionsFile(filename)
    
    f = fixInputFile4to5(f)
    
    while True:
        user_input = input('Do you want to overwrite "'+filename+'"? [y/N/v/h]').lower()
        
        if user_input == 'y':
            f.write(filename=filename, overwrite=True)
            exit(0)
        elif user_input == 'n' or user_input == '':
            exit(0)
        elif user_input == 'v':
            print(f)
        elif user_input == 'h':
            print('y - overwrite "'+filename+'" with the fixed version\n'
                  + 'n (default) - exit without changing "'+filename+'"\n'
                  + 'v - view the fixed input file\n'
                  + 'h - print this help')

[Note: to run the above example needs a method adding to BoutOptions

    def __delitem__(self, key):
        """
        Delete a key
        """
        key = key.lower()
        if key in self._keys:
            del self._keys[key]
        elif key in self._sections:
            del self._sections[key]
        else:
            raise KeyError(key)

and with the current BoutOptionsFile it clobbers comments, whitespace, and possibly the order of sections/options.]

src/mesh/parallel/fci.cxx Outdated Show resolved Hide resolved
src/mesh/parallel/fci.hxx Outdated Show resolved Hide resolved
@ZedThree
Copy link
Member

LGTM. I'll add updater scripts next week

@ZedThree
Copy link
Member

Turns out tests/integrated/test-interpolate/runtest sets interpolation:type=<type> on the command line, so that also needs updating to xzinterpolation:type, and tests/MMS/spatial/fci/runtest sets fci:y_periodic -> mesh:paralleltransform:y_periodic.

Updating command line options in scripts might be trickier to do both automatically and accurately.

Also, I think I missed why adding Options to XZInterpolation is necessary. I can't see where it's used?

@johnomotani
Copy link
Contributor Author

Also, I think I missed why adding Options to XZInterpolation is necessary. I can't see where it's used?

That does seem to be true. I suspect that I just thought that given we have an xzinterpolation section, it would be nice to keep the options in the XZInterpolation objects, just in case any of the implementations ever needed some settings. I think at the moment xzinterpolation:type is the only setting, and that is only needed by the factory not the XZInterpolation classes themselves. Would you rather remove the Options member until it's needed?

@ZedThree
Copy link
Member

Would you rather remove the Options member until it's needed?

I think that would be better. I found it a bit confusing, as I thought I was missing something.

ZedThree and others added 5 commits February 28, 2020 16:45
…-comments

Add v5 upgrader scripts for XZInterpolation
fci:y_periodic -> mesh:paralleltransform:y_periodic
interpolation:type -> xzinterpolation:type
Is not currently used, so clearer to not have it at all.
optionsOrDefaultSection is already called on the Options* pointer by
getType.
@ZedThree ZedThree merged commit 444b3d5 into next Mar 2, 2020
@ZedThree ZedThree deleted the parallel-transform-interpolation-options branch March 2, 2020 15:30
johnomotani added a commit that referenced this pull request Mar 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Introduces a change that is not backward compatible with the previous major version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants