Native Mesh Contouring for Vertex Fields #58
Draft
andrewdnolan wants to merge 1 commit intoE3SM-Project:mainfrom
Draft
Native Mesh Contouring for Vertex Fields #58andrewdnolan wants to merge 1 commit intoE3SM-Project:mainfrom
andrewdnolan wants to merge 1 commit intoE3SM-Project:mainfrom
Conversation
Collaborator
Author
import io
from contextlib import redirect_stdout
import matplotlib.pyplot as plt
import numpy as np
from mpas_tools.mesh.conversion import convert, cull
from mpas_tools.planar_hex import make_planar_hex_mesh
from mpas_tools.translate import center
import mosaic
from mosaic.contour import MPASContourGenerator
def sinusoid(x, y, A=2.0, N=1.5):
""" """
x_min = np.min(x)
y_min = np.min(y)
x_max = np.max(x)
y_max = np.max(y)
L_x = (x_max - x_min) / 2
L_y = (y_max - y_min) / 2
return A * np.sin(N * np.pi * (x / L_x)) * np.sin(N * np.pi * (y / L_y))
def planar_hex_mesh(N=100):
"""Wrapper for MPAS-Tools functions"""
output_capture = io.StringIO()
# Redirect stdout to the buffer within the 'with' block
with redirect_stdout(output_capture):
ds = make_planar_hex_mesh(
nx=N, ny=N, dc=1 / N, nonperiodic_x=True, nonperiodic_y=True
)
ds = cull(ds)
ds = convert(ds)
# returns None, does centering inplace
center(ds)
return ds
if __name__ == "__main__":
ds = planar_hex_mesh(50)
field = sinusoid(ds.xVertex, ds.yVertex)
descriptor = mosaic.Descriptor(ds)
mask = field < 0.0
generator = MPASContourGenerator(descriptor, field)
graph = generator._create_vertex_contour_graph(mask, filled=False)
fig, ax = plt.subplots(layout='constrained')
mosaic.polypcolor(ax, descriptor, field, alpha=1 / 3, ec="k", lw=1 / 5)
for i, j in graph.edges:
ax.plot(
descriptor.ds.xCell[[i,j]],
descriptor.ds.yCell[[i,j]],
c='k'
)
ax.scatter(
generator.ds.xEdge[generator.boundary_edges],
generator.ds.yEdge[generator.boundary_edges],
c='r',
s=2.5,
alpha=0.5
)
plt.show() |
ed71d2d to
2295b00
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Vertex contours on the native mesh can produce saddle points, which violate the cycle/path assumptions of cell contours.
More work will be required to handle these saddle points.