-
Notifications
You must be signed in to change notification settings - Fork 66
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
Add python code for computing planar hex meshes #246
Conversation
Currently produces bit-for-bit identical results to `periodic_hex/periodic_grid` but could be extended in the future to produce non-periodic meshes.
TestingI tested both a 10x20 cell, 1km mesh and a 500x500 cell, 10km mesh. Both were bit-for-bit identical to results from MPAS-Tools/mesh_tools/planar_hex/planar_hex.py Lines 349 to 372 in f1ec117
Surprisingly, the python code is 8x faster for the larger mesh than the Fortran code. |
I chose not to have the python code add the I also chose not to produce the |
@xylar , I confirmed this works as advertised, and I agree with the decision to leave out Time and any non-mesh variables. I also agree that there is no real value in the behavior of periodic_hex to output graph.info.part.* files, and the new script does not need to do that. (The only really useful file is graph.info, but periodic_hex currently does not output that, and there is an existing script in the MPAS-Tools repo that can be used to create it.) I also confirmed that this is substantially faster than the current code! A couple of things I noticed:
|
@matthewhoffman, thanks for the review!
Yes, I rely extensively on
I must have missed that check. I agree that it's necessary. |
I had a discussion with @matthewhoffman. Both of us would like to know how others feel about the dependency on |
For me, it's a no brainer: if it works, and it's fast, and removing |
Thanks or weighing in @milenaveneziani. @mgduda, do you have an opinion about this? Keep in mind that my primary reason for developing it is as a tool that can more easily be incorporated into a conda package (which can include xarray as a dependency without any extra pain for the user). This need not be a replacement for |
@maltrud had raised the concern that xarray output wasn't working well in MPAS for him and @bradyrx. I can confirm that I can run the results of this tool through |
@xylar, to clarify, the issue I had was with using Even taking care to set the output format to NetCDF3_64BIT wouldn't help. I.e., metadata of the modified netCDF looked identical to that of files that worked with MPAS, but something under the hood from |
@xylar , there was no assumption before that output from perdiodic_hex should work as a valid MPAS mesh without running through the mesh converter tool first. So I think it's perfectly fine (and preferable) to still require that. |
@bradyrx, your case wouldn't have worked with the mesh converter, I suspect. It's only for MPAS meshes, not any kind of MPAS data (e.g. particles). I have had (minor) issues with fill values from xarray in my other work, which is why I have a helper function to use standard fill values in the output. It just occurs to me that I have a run that's mysteriously crashing, and xarray could be the cause! I wonder what it does that MPAS doesn't like. Definitely worth looking into but it's outside the scope of this PR, for sure. |
@matthewhoffman, yep, that sound reasonable. If results from |
To clarify, the thinking Doug always had was to make only one tool (mesh converter) responsible for precise implementation of the MPAS mesh spec. In the early days we kept running into issues where such and such tool or MPAS framework routine would appear broken only to discover some obscure detail of the mesh spec was not being obeyed in a mesh. The mesh spec is complicated enough that requiring every tool to follow it to the letter isn't worth the effort. |
That's a good guiding principle, for sure. It's obviously a little problematic that the tool for enforcing the mesh spec was written using c++, a language used by very few of the existing developers, and using a version of the NetCDF c++ library that was short-lived. But hindsight is always 20/20 and we have ways of building that tool wherever needed now (#243). For the record, I tried rewriting the mesh converter in python and it was a nightmare (and very slow) so I have a lot of respect of Doug's work on that tool. |
This will help with incorporating planar_hex into a python package soon.
36f6746
to
98e1edf
Compare
By restructuring the file, the function `make_periodic_planar_hex_mesh` can be called from another python script to generate a mesh object for further manipulation. Eventually, this should help with making a non-periodic version of the mesh, perhaps with another tool. It would also allow for culling cells or other operations without the need to write out and read back in the mesh or to call this script as a subprocess of another script.
98e1edf
to
1ff7a8a
Compare
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.
I tested with this COMPASS test case:
ocean/baroclinic_channel/10km/restart_test
Except I substituted this for init_step1:
./planar_hex.py --nx 16 --ny 50 --dc 10000 -o base_mesh.nc
It worked great! The other init and forward steps went all the way through based on this mesh, with no problem.
@siddharthabishnu @amrapallig and @ipdemes This is a very useful tool that Xylar just added to create a 3D regular hex domain with your specifications. Please give it a try. It is in this branch of MPAS-Tools right now, but will be merged soon. With this tool, you can do a spatial convergence test. Here is a quick way to access it while it is on this branch:
then use it with:
You will need the right python environment. On LANL IC:
If you have comments, or problems, you can post on this PR. |
@siddharthabishnu @amrapallig and @ipdemes I should also say, after this command:
you still need to run the c-code mpas mesh converter:
which produces the graph.info file. That code is housed here: https://github.com/MPAS-Dev/MPAS-Tools/tree/master/mesh_tools/mesh_conversion_tools. @xylar Does planar_hex.py produce a valid MPAS mesh, or does |
@mark-petersen, see discussion above. @matthewhoffman thinks that no tool other than |
@matthewhoffman Actually, we do assume that the output of |
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.
I was able to run an idealized supercell simulation with MPAS-Atmosphere using a mesh generated by this script. For what it's worth, I installed xarray
using pip.
@matthewhoffman, it sounds like you're in a minority in wanting the tool rewritten without |
@xylar , if no one else objects to xarray, then I withdraw my concern. Feel free to merge this! |
Thanks, @matthewhoffman. I appreciate that your goal was to keep the tools in this repo as clean an simple to use as possible. I'll definitely keep that goal in mind in my future additions. |
conda package for MPAS tools This package is intended to include all the tools needed to run run COMPASS test cases and other typical mesh creation workflows. This includes: * the mesh conversion tools (#243) * a python interface to the mesh conversion tools * the planar hex creation tool (#246) * a modified version of the mesh translation tool (python 3 compatible and callable as a function as well as a script * 4 land-ice mesh tools (updated for python 3) * 3 ocean coastal modification scripts (now available as functions and updated for python 3) * add a copy of the MPAS-Model license (a license is required for conda-forge packages) * a starting point for documentation
Currently produces bit-for-bit identical results to
periodic_hex/periodic_grid
but could be extended in the future to produce non-periodic meshes.The reason for this update is that the python code will likely be much easier to incorporate into workflows like COMPASS because it doesn't require compilation or the Fortran NetCDF library. It could also be incorporated quite easily into a conda package for mesh tools (see #243 and #245).
partially addresses #245