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

Av operator #582

Merged
merged 26 commits into from
Jun 15, 2022
Merged

Av operator #582

merged 26 commits into from
Jun 15, 2022

Conversation

MTCam
Copy link
Member

@MTCam MTCam commented Dec 16, 2021

This change set adds artificial viscosity (mostly) as developed by @w-hagen, with the tweaks and improvements we've made along the way including @thomasgibson changes to bring in over-integration capabilities.

Checklist for @lukeolson

  • Is the scope and purpose of the PR clear?
    • The PR should have a description.
    • The PR should have a guide if needed (e.g., an ordering).
  • Is every top-level method and class documented? Are things that should be documented actually so?
    • I could not find a clear statement on the BC. Add some description of the BC handled to close this checkbox. Preferably in the AV docstring.
  • Is the interface understandable? (I.e. can someone figure out what stuff does?) Is it well-defined?
  • Does the implementation do what the docstring claims?
  • Is everything that is implemented covered by tests?
    • Testing the boundary conditions is still open it appears. Add a test to close this box.
    • Testing av_laplacian_operator is limited. Consider adding a more complete MMS. In the very least note limitations of this Laplace operator in the notes (lack of testing for discontinuous coefficients?)
  • Do you see any immediate risks or performance disadvantages with the design? Example: what do interface normals attach to?

@MTCam MTCam added Production Feeder Feeds the production branch enhancement New feature or request labels Dec 16, 2021
@MTCam MTCam mentioned this pull request Feb 18, 2022
@MTCam MTCam requested review from lukeolson and w-hagen May 27, 2022 15:55
@MTCam MTCam marked this pull request as ready for review May 27, 2022 15:55
@MTCam MTCam changed the base branch from ns-update to main June 1, 2022 21:20
Copy link
Contributor

@inducer inducer left a comment

Choose a reason for hiding this comment

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

Some initial thoughts below.

test/test_av.py Outdated
Comment on lines 65 to 66
Tests that the cells tagging properly tags cells
given prescribed solutions.
Copy link
Contributor

Choose a reason for hiding this comment

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

Expand to describe precisely what is being tested.

Copy link
Member Author

Choose a reason for hiding this comment

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

Took a stab at this. Want to have a look and sharpen it up @w-hagen ?

@@ -0,0 +1,265 @@
"""Test the artificial viscosity functions."""
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO, this is missing a test for proper handing of boundary conditions, particularly in view of the fact that we had trouble with that.

Copy link
Member Author

Choose a reason for hiding this comment

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

A test has been added to make sure the AV fluxes returned from the fluid BC constructs match those which we intended for them to be. We collectively share a lack of knowledge about what the BCs should actually be for this operator (i.e., when computing the 2nd part; div(alpha*indicator*grad(Q))). For the first (grad(Q)) part, this operator now mercifully uses grad(Q) from the fluid computation, and is thus using the appropriate fluid BCs directly there - whatever those may be for the given boundary. The added tests check the AV-specific interface fluxes for the 2nd part.

test/test_av.py Outdated
Comment on lines 170 to 174
"""Test artificial_viscosity.

Tests the application on a few simple functions
to confirm artificial viscosity returns the analytical result.
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Improve the description here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Took a stab at this in a9743ee.

test/test_av.py Outdated
Comment on lines 170 to 174
"""Test artificial_viscosity.

Tests the application on a few simple functions
to confirm artificial viscosity returns the analytical result.
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be replaced by a manufactured-solution test, instead of these two simplistic known-solution tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried quickly re-use the diffusion operator MMS tests, but turns out not to be as easy of a drop-in as I had imagined.

We'll need some infrastructure backing to make this happen. It looks like the amount of effort to get an MMS infrastructure for AV is about the same as replacing the guts of AV with the diffusion operator. I think we'd prefer using the diffusion operator. Another option would be just beefing up the tests a bit with more analytic functions, perhaps leveraging the symbolic infrastructure.

Copy link
Member Author

Choose a reason for hiding this comment

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

@lukeolson added a trig test that helps with this a little.

I tried to add a discontinuous coeff test (which I do not expect this operator to pass) - but it turned out to be too much effort for this fluid-specific operator. If this operator was just a (multi)scalar laplacian operator, then it'd be a no-brainer. Alas, now it re-uses the gradient operator and boundary projection routines designed specifically for fluid solutions - and thus requires physically-consistent fluid solutions.

test/test_av.py Outdated
Comment on lines 170 to 174
"""Test artificial_viscosity.

Tests the application on a few simple functions
to confirm artificial viscosity returns the analytical result.
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

This does not test the numerical fluxes, since there are no jumps. As a result, numerical stability of AV is not being tested.

Copy link
Member Author

Choose a reason for hiding this comment

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

It appears that the diffusion operator has only one test where jumps are tested. We could potentially port that over to AV testing, if that is of interest.

mirgecom/initializers.py Outdated Show resolved Hide resolved
pass


def av_laplacian_operator(discr, boundaries, fluid_state, alpha, gas_model=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Let me ask the elephant-in-the-room question here: Given that we have variable-coefficient diffusion, why do we want this? As @majosm can possibly attest, getting diffusion with elementwise-discontinuous coefficients right is not entirely trivial. And the already-implemented diffusion operator literally implements the same operator. It doesn't help that this operator is not well-tested.

I'd be OK with this becoming a deprecated wrapper of the diffusion operator.

Copy link
Member Author

Choose a reason for hiding this comment

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

return -div_operator(discr, dd_vol, dd_faces, interp_to_vol_quad(r), r_bnd)


def smoothness_indicator(discr, u, kappa=1.0, s0=-6.0):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can be built simply out of the modal discretization facility in meshmode. There's definitely no need for this to make use of a loopy kernel. @kaushikcfd had also worked on a more lazy-compatible version of this. I am surprised to see that that is not part of this.

Copy link
Member Author

@MTCam MTCam Jun 6, 2022

Choose a reason for hiding this comment

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

I believe the version you are thinking of is added by @kaushikcfd in #666. It requires the fusion array context and does not work without it afaik.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The tagging bit won't work, but the einsum bit should be fine. I don't have a preference for which PR the einsum is introduced in.

Copy link
Contributor

Choose a reason for hiding this comment

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

What part of the tagging is the issue? I'm looking over the code in #666, and it mostly seems like it ought to go even with arraycontext/meshmode main?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Tag types like DiscretizationDOFAxisTag haven't made it to meshmode main.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do we have a path forward for this item?

Copy link
Member Author

Choose a reason for hiding this comment

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

fwiw, here's the error i get when trying to run with @kaushikcfd indicator:

    indicator = smoothness_indicator(discr, fluid_state.mass_density,
  File "/Users/mtcampbe/CEESD/devel/tau/main/emirge/mirgecom/mirgecom/artificial_viscosity.py", line 318, in smoothness_indicator
    from meshmode.transform_metadata import DiscretizationDOFAxisTag
ImportError: cannot import name 'DiscretizationDOFAxisTag' from 'meshmode.transform_metadata' (/Users/mtcampbe/CEESD/devel/tau/

Copy link
Collaborator

Choose a reason for hiding this comment

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

The actx.tag_axis part would be illegal, but without that the call to actx.einsum should be legal on meshmode main. I'm ok with the rewrite to einsum either here or in #666.

Copy link
Member Author

Choose a reason for hiding this comment

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

I just added @kaushikcfd version of this in (732f005). The tests passed locally with main (:tada:).

@inducer
Copy link
Contributor

inducer commented Jun 5, 2022

It might make sense to squash this so that the Github UI does not bog down.

health_error = True
logger.info(f"{rank=}: NANs/Infs in pressure data.")

from mirgecom.simutil import allsync
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe these should be global_reduce now

Copy link
Member Author

Choose a reason for hiding this comment

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

default_simplex_group_factory, QuadratureSimplexGroupFactory

order = 3
discr = EagerDGDiscretization(
Copy link
Contributor

Choose a reason for hiding this comment

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

These should be updated to the new collection. But this is done in #360

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's make a dedicated issue about updating mirgecom to use discretization collections. This cannot be done example-by-example. It requires a large collection of supporting updates throughout mirgecom.

Copy link
Member Author

Choose a reason for hiding this comment

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

Working to centralize and then replace the discretization collection in a dedicated effort was precisely the reason we added this code:
https://github.com/illinois-ceesd/mirgecom/blob/main/mirgecom/discretization.py

7b9ee93 uses the wrapper, and gets rid of the deprecation warning.

from mirgecom.logging_quantities import (
initialize_logmgr,
logmgr_add_many_discretization_quantities,
logmgr_add_device_name,
Copy link
Contributor

Choose a reason for hiding this comment

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

use logmgr_cl_device_name

Copy link
Member Author

Choose a reason for hiding this comment

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

current_state = make_fluid_state(cv=current_cv, gas_model=gas_model)

visualizer = make_visualizer(discr,
discr.order if discr.dim == 2 else discr.order)
Copy link
Contributor

Choose a reason for hiding this comment

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

.order is deprecated (it appears)

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, what is the point of this line.

Copy link
Collaborator

@w-hagen w-hagen Jun 6, 2022

Choose a reason for hiding this comment

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

I think that was used for a bit to plot at a higher discretization order but looks like I changed that and never got rid of the if statement. That part can be removed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh sure - but this particular line says something like "if sthing then discr.order else discr.order"

Copy link
Member Author

Choose a reason for hiding this comment

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

@MTCam MTCam removed the request for review from w-hagen June 6, 2022 20:09
0.5 * (1.0 + actx.np.sin(np.pi * (indicator - s0) / (2.0 * kappa))),
0.0 * indicator,
)
indicator = actx.np.where(yesnou, 1.0 + 0.0 * indicator, sin_indicator)
Copy link
Contributor

@lukeolson lukeolson Jun 10, 2022

Choose a reason for hiding this comment

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

np.where() works with a scalar field... this would avoid an extra dof array by just using 1.0

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if that's extended in the array context though worth checking

Copy link
Member Author

Choose a reason for hiding this comment

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

I do not know if it has changed (i doubt it), but I definitely needed each "rhs" args to be arrays of equal size when using this function in the past.

Copy link
Member Author

Choose a reason for hiding this comment

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

heh, whadda ya know.

def test_actx_np_where(actx_factory):

Copy link
Member Author

Choose a reason for hiding this comment

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

Went ahead and fixed this in (732f005)

@MTCam MTCam enabled auto-merge (squash) June 15, 2022 16:48
@MTCam MTCam merged commit 117714c into main Jun 15, 2022
@MTCam MTCam deleted the av-operator branch June 15, 2022 17:19
@MTCam MTCam mentioned this pull request Jun 25, 2022
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Production Feeder Feeds the production branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants