Skip to content

Conversation

@vanroekel
Copy link
Contributor

@vanroekel vanroekel commented Jun 1, 2020

Adds the Skamarock and Gassmann cosine bell test case and a regression
suite across resolutions to test operator convergence

Reference: Section 2a in Skamarock, W.C. and A. Gassmann, 2011: Conservative Transport Schemes for Spherical Geodesic Grids: High-Order Flux Operators for ODE-Based Time Integration. Mon. Wea. Rev., 139, 2962–2975, https://doi.org/10.1175/MWR-D-10-05056.1

@vanroekel
Copy link
Contributor Author

@mark-petersen and @xylar here is my WIP advection operator convergence for the global advective test case. If you have some time, I'd greatly appreciate your comments.

@vanroekel
Copy link
Contributor Author

also tagging @jamilgafur

write_netcdf(convert(xarray.open_dataset('mesh_triangles.nc')),
'base_mesh.nc')
write_netcdf(convert(xarray.open_dataset('mesh_triangles.nc'),
graphInfoFileName='graph.info'),'base_mesh.nc')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perfect! My only comment here would be to indent another 5 spaces so the formatting follows the PEP8 convention.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just so I'm clear, indent the second line 5 more spaces? Is this so it is easier to see it is part of the convert function?

Copy link
Contributor

Choose a reason for hiding this comment

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

If you load e3sm_unified you can run

autopep8 --in-place --aggressive --aggressive foo.py

on your python files for automatic pep8 spacing.

ii = line.find('=')+1
pd = float(line[ii:])

init = xr.open_dataset('../../'+resTag+'/default/init_step/initial_state.nc')
Copy link
Collaborator

Choose a reason for hiding this comment

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

I really prefer people alter strings with .format() instead of string "addition". This may be may own prejudice but I don't see string addition used by seasoned python programmers.

Suggested change
init = xr.open_dataset('../../'+resTag+'/default/init_step/initial_state.nc')
init = xr.open_dataset('../../{}/default/init_step/initial_state.nc'.format(resTag))


init = xr.open_dataset('../../'+resTag+'/default/init_step/initial_state.nc')
#find time since the beginning of run
ds = xr.open_dataset('../../'+resTag+'/default/forward/output/output.0001-01-01_00.00.00.nc')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar to above, maybe use .format().

Comment on lines 64 to 67
for i in range(len(latC)):
temp = R*np.arccos(np.sin(latCent)*np.sin(latC[i]) + np.cos(latCent)*np.cos(latC[i])*np.cos(lonC[i] - newLon))
if temp < radius:
tracer[i] = psi0 / 2.0 * (1.0 + np.cos(3.1415926*temp/radius))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Never loop if you don't have to in python.

Suggested change
for i in range(len(latC)):
temp = R*np.arccos(np.sin(latCent)*np.sin(latC[i]) + np.cos(latCent)*np.cos(latC[i])*np.cos(lonC[i] - newLon))
if temp < radius:
tracer[i] = psi0 / 2.0 * (1.0 + np.cos(3.1415926*temp/radius))
temp = R*np.arccos(np.sin(latCent)*np.sin(latC) + np.cos(latCent)*np.cos(latC)*np.cos(lonC - newLon))
mask = temp < radius
tracer[mask] = psi0 / 2.0 * (1.0 + np.cos(numpy.py*temp[mask]/radius))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's nice! thanks for the suggestion

import matplotlib.pyplot as plt
import os

%matplotlib inline
Copy link
Collaborator

Choose a reason for hiding this comment

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

I haven't seen this one before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was an error in importing from jupyter notebook to python script. It's ipython magic. I've removed this.

@xylar
Copy link
Collaborator

xylar commented Jun 1, 2020

@vanroekel, most of my comments are just little things that you're free to take or leave. Looks like a decent approach to me. Happy to do some testing once the time comes.

Copy link
Contributor Author

@vanroekel vanroekel left a comment

Choose a reason for hiding this comment

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

Thanks @xylar I will make the changes. As I test this, I'm having a hard time controlling the plot size and position of the convergence label (annotate) command. Do you have any suggestions? Here is what a plot looks like right now

convergence

@xylar
Copy link
Collaborator

xylar commented Jun 1, 2020

Thanks @xylar I will make the changes. As I test this, I'm having a hard time controlling the plot size and position of the convergence label (annotate) command. Do you have any suggestions? Here is what a plot looks like right now

Oh, yeah, that doesn't look great. Let me see what I can figure out.

Comment on lines 8 to 14
matplotlib.rcParams['figure.figsize'] = (16, 16) # Large figures
dpi=200;

### axis_font = {'fontname':'Arial', 'size':'18'}
title_font = {'fontname':'Arial', 'size':'32', 'color':'black', 'weight':'normal'}
matplotlib.rc('xtick', labelsize=28)
matplotlib.rc('ytick', labelsize=28)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is the stuff that's causing your figure to look bad. Try taking it out. I'll make a few recommendations below once you do that.

p = np.polyfit(np.log10(xdata),np.log10(ydata),1)
conv = abs(p[0])

plt.loglog(xdata,ydata,'k')
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the figure isn't the size you want, set the size here:

plt.figure(figsize=[<width>, <height>])

where width and height are in inches.

plt.loglog(xdata,ydata,'k')
plt.scatter(xdata,ydata,s=40,c='r')
plt.annotate('Order of Convergence = {}'.format(np.round(conv,2)),xy=((xdata[-1]+xdata[0])*0.4,ydata[0]),fontsize=28)
plt.savefig('convergence.png')
Copy link
Collaborator

@xylar xylar Jun 1, 2020

Choose a reason for hiding this comment

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

If the png is low resolution, set dpi=200 here. I wouldn't bother doing that earlier unless you're going to use plt.show().


plt.loglog(xdata,ydata,'k')
plt.scatter(xdata,ydata,s=40,c='r')
plt.annotate('Order of Convergence = {}'.format(np.round(conv,2)),xy=((xdata[-1]+xdata[0])*0.4,ydata[0]),fontsize=28)
Copy link
Collaborator

Choose a reason for hiding this comment

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

28 is a big font size. And it might work better to just put it in the upper left corner or something. There are probably other tricks for putting it "where it fits bets" like is done for legends. If you want that, I can look into it.

@vanroekel
Copy link
Contributor Author

thanks @xylar! Your comments have been extremely helpful. Here is an updated plot

convergence

@vanroekel
Copy link
Contributor Author

@mark-petersen I've run through the advection test and here is the result

convergence

The convergence order is much lower than expected. When you have a chance could you look through this test and see if I have an error?

@mark-petersen mark-petersen self-assigned this Jun 2, 2020
@mark-petersen
Copy link
Contributor

@vanroekel thanks for your work on this. The low order of convergence is certainly surprising. The direct comparison is Skamarock and Gassmann figure 4:
image
They don't give numbers for the computed order on this plot, but everything is at least 2. MPAS-Ocean should be using the fourth order scheme. I would expect that limiting is not turning on, but we could check that.

@vanroekel
Copy link
Contributor Author

@mark-petersen monotone is on here. We also are using the blended 3rd/4th order scheme (coeff3rdOrder =0.25). I've tried for various values of that coefficient and it doesn't help convergence order. I've also tried with non monotone and the order is roughly the same.

@vanroekel
Copy link
Contributor Author

One other thing, there is a pretty strong time step sensitivity. Cutting dt to 1 min changes convergence strongly (not for the better). I'll add some plots of the tracer vs exact solution shortly

convergence

@vanroekel
Copy link
Contributor Author

a quick update, using RK4 improves convergence, but only slightly

convergence

mpas_ocn_init_hurricane.o \
mpas_ocn_init_tidal_boundary.o
mpas_ocn_init_tidal_boundary.o \
mpas_ocn_init_cosine_bell.o

Choose a reason for hiding this comment

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

Small edit, but spacing here is weird.

@mark-petersen mark-petersen force-pushed the ocean/addCosineBellTest branch from 850201c to 45bda53 Compare September 16, 2020 14:30
@mark-petersen
Copy link
Contributor

Rebased, compiled and tested with gnu and intel debug for initial condition. Ran QU240 test through forward.

Copy link
Contributor

@mark-petersen mark-petersen left a comment

Choose a reason for hiding this comment

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

This looks great! Thanks for your work @vanroekel. I cleaned up the COMPASS files so they are linked to templates rather than a bunch of individual files. Then it was very easy to add more resolutions in between. This still spans QU60 to QU240:
convergence
This is beautiful! The extra test cases give us more confidence in the slope.

I also was able to clean up the simulations. It had been writing output and restart files very frequently. It now can run all seven cases in 12 minutes on 4 nodes on grizzly with gnu.

@mark-petersen
Copy link
Contributor

@jonbob This one is ready to merge when we have an open E3SM slot. It changes both COMPASS and init mode Fortran code.

@xylar
Copy link
Collaborator

xylar commented Nov 6, 2020

I have a draft PR for moving the COMPASS changes from this PR to the new COMPASS repo: MPAS-Dev/compass#8

Once MPAS-Dev/compass#2 has been merged, we need to:

@xylar
Copy link
Collaborator

xylar commented Nov 14, 2020

remove COMPASS changes from this PR

@vanroekel, would you like to remove the COMPASS changes from this PR, or would you prefer I do it? Here is a link that I think describes the approach we would use: https://stackoverflow.com/a/17824718/7728169

@xylar xylar removed the COMPASS label Nov 14, 2020
@xylar
Copy link
Collaborator

xylar commented Nov 14, 2020

@vanroekel, I went ahead and tried the rebase. The link I posted above wasn't much help, I just needed to keep deleting modified contents in testing_and_setup/compass. Here's my version of the branch, which just has 2 commits:
https://github.com/xylar/MPAS-Model/tree/ocean/addCosineBellTest
I think the second commit could be squashed with the first.

@vanroekel
Copy link
Contributor Author

@xylar thanks for taking the time to pull the COMPASS changes out of that branch. It looks good to me.

@xylar
Copy link
Collaborator

xylar commented Nov 15, 2020

@vanroekel, I'm going to take that as tacit permission to alter your branch to update this PR.

@xylar xylar force-pushed the ocean/addCosineBellTest branch from 7db1d00 to 905dcd4 Compare November 15, 2020 08:39
@xylar
Copy link
Collaborator

xylar commented Nov 15, 2020

@mark-petersen, please merge this when it is convenient for E3SM. Then, we can update the ocean/develop submodule in MPAS-Dev/compass#8 and merge that PR.

@mark-petersen
Copy link
Contributor

@xylar, thanks for rebasing. Hopefully we can continue to merge these peripheral PRs during the mushy freeze.

Adds the Skamarock and Gassmann cosine bell test case and a regression
suite across resolutions to test operator convergence
@mark-petersen mark-petersen force-pushed the ocean/addCosineBellTest branch from 905dcd4 to 0f1b805 Compare January 15, 2021 14:13
@mark-petersen mark-petersen force-pushed the ocean/addCosineBellTest branch from 0f1b805 to f3f049a Compare January 15, 2021 14:16
@mark-petersen
Copy link
Contributor

Rebased. Corrected author and test case names. Tested successfully using COMPASS case, which is here: MPAS-Dev/compass#8, with gnu optimized and debug.

mark-petersen added a commit that referenced this pull request Jan 15, 2021
Merge PR #583 'vanroekel/ocean/addCosineBellTest' into ocean/develop
@mark-petersen
Copy link
Contributor

Rebased version passes nightly regression suite with gnu debug. Ran convergence test here: MPAS-Dev/compass#8 with gnu debug an optimized, produces same plot as above. Takes 12 minutes on grizzly with 4 nodes.

jonbob added a commit to E3SM-Project/E3SM that referenced this pull request Jan 18, 2021
Add cosine bell advection test case

This PR brings in a new mpas-source submodule with changes only to the
ocean core. It adds initial condition for cosine bell test case, used for
converge test of tracer advection.

See MPAS-Dev/MPAS-Model#583 and MPAS-Dev/compass#8.

[BFB]
jonbob added a commit to E3SM-Project/E3SM that referenced this pull request Jan 19, 2021
Add cosine bell advection test case

This PR brings in a new mpas-source submodule with changes only to the
ocean core. It adds initial condition for cosine bell test case, used
for converge test of tracer advection.

See MPAS-Dev/MPAS-Model#583 and MPAS-Dev/compass#8.

[BFB]
@mark-petersen mark-petersen merged commit b3d870d into MPAS-Dev:ocean/develop Jan 19, 2021
mark-petersen added a commit to mark-petersen/MPAS-Model that referenced this pull request Mar 16, 2021
Merge PR MPAS-Dev#583 'vanroekel/ocean/addCosineBellTest' into ocean/develop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants