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

Update get_box_mesh.py #924

Merged
merged 50 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
6032947
Create get_box_mesh.py
aakankshbhat Jun 29, 2023
2999678
Update get_box_mesh.py
aakankshbhat Jun 30, 2023
4314ee3
Update get_box_mesh.py
aakankshbhat Jun 30, 2023
0297845
get_box_mesh_v2
aakankshbhat Jun 30, 2023
cfa7091
Rename get_box_mesh_v2 to get_box_mesh_v2.py
aakankshbhat Jun 30, 2023
d01cb35
Update simutil.py
aakankshbhat Jun 30, 2023
7e0cfe0
Update combozzle-mpi.py to import get_box_mesh
aakankshbhat Jun 30, 2023
ae5aee3
Remove previous get_box_mesh definition
aakankshbhat Jun 30, 2023
cc3e3f6
import from simutil once instead of twice
aakankshbhat Jul 3, 2023
50e2dcd
import get_box_mesh instead of defining it
aakankshbhat Jul 3, 2023
cbf44d3
import get_box_mesh instead of defining it
aakankshbhat Jul 3, 2023
72174a2
import get_box_mesh instead of defining it
aakankshbhat Jul 3, 2023
341964c
import get_box_mesh instead of defining it
aakankshbhat Jul 3, 2023
9b069bb
import get_box_mesh instead of defining it
aakankshbhat Jul 3, 2023
470babd
import get_box_mesh instead of defining it
aakankshbhat Jul 3, 2023
5a5e99d
import get_box_mesh instead of defining it
aakankshbhat Jul 3, 2023
f5dd63c
import get_box_mesh instead of defining it
aakankshbhat Jul 3, 2023
cc15390
import get_box_mesh instead of defining it
aakankshbhat Jul 3, 2023
db8666c
Documentation for get_box_mesh
aakankshbhat Jul 5, 2023
48c2c4f
Update get_box_mesh function documentation to include tagged boundary…
aakankshbhat Jul 6, 2023
0938d27
remove extra underscore in get_box_mesh
aakankshbhat Jul 7, 2023
8e2698f
remove extra underscore in get_box_mesh
aakankshbhat Jul 7, 2023
25486d7
remove extra underscore in get_box_mesh
aakankshbhat Jul 7, 2023
31d98a9
remove extra underscore in get_box_mesh
aakankshbhat Jul 7, 2023
813d467
remove extra underscore in get_box_mesh
aakankshbhat Jul 7, 2023
0e63ea1
remove extra underscore in get_box_mesh
aakankshbhat Jul 7, 2023
e861962
remove extra underscore in get_box_mesh
aakankshbhat Jul 7, 2023
5033121
remove extra underscore in get_box_mesh
aakankshbhat Jul 7, 2023
2040682
fixing syntax errors
aakankshbhat Jul 10, 2023
7f6cd13
Reduce line length for flake8 test
aakankshbhat Jul 10, 2023
c55d3e1
fixing syntax errors
aakankshbhat Jul 10, 2023
541b67e
Whitespace and Blank line corrections
aakankshbhat Jul 15, 2023
dd58b52
Whitespace changes
aakankshbhat Jul 15, 2023
fb453c7
Whitespace and blank line corrections
aakankshbhat Jul 17, 2023
f7d9f07
whitespace corrections in documentation
aakankshbhat Jul 19, 2023
e13252b
Extra blank line corrections
aakankshbhat Jul 19, 2023
0294a26
Fixing test cases for pytest
aakankshbhat Jul 21, 2023
f85b6e6
fixing whitespace errors for flake8 test
aakankshbhat Jul 21, 2023
898a6cb
fixing boundary errors
aakankshbhat Jul 21, 2023
f11fcfd
Fixing boundary errors
aakankshbhat Jul 24, 2023
8f6e156
fixing boundary errors
aakankshbhat Jul 24, 2023
8b00f4f
add 1 to a few more boundaries in tests
majosm Jul 26, 2023
0010727
use nelements_per_axis instead of deprecated n
majosm Jul 26, 2023
af8f692
minor change to combozzle to avoid conflict with production
majosm Jul 26, 2023
5d6c9ff
Fix documentation errors
aakankshbhat Jul 31, 2023
3c454f4
Merge branch 'illinois-ceesd:main' into update_get_box_mesh
aakankshbhat Jul 31, 2023
2184573
update boundary tags for new pytest parameters
aakankshbhat Aug 1, 2023
86d4312
remove old get_box_mesh files
majosm Aug 1, 2023
2b3a0c5
minor tweaks
majosm Aug 1, 2023
17dec39
format documentation
majosm Aug 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 12 additions & 25 deletions examples/combozzle-mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
get_sim_timestep,
generate_and_distribute_mesh,
write_visfile,
force_evaluation
force_evaluation,
get_box_mesh
)
from mirgecom.io import make_init_message
from mirgecom.mpi import mpi_entry_point
Expand Down Expand Up @@ -88,20 +89,6 @@ class MyRuntimeError(RuntimeError):


# Box grid generator widget lifted from @majosm and slightly bent
def _get_box_mesh(dim, a, b, n, t=None, periodic=None):
if periodic is None:
periodic = (False)*dim

dim_names = ["x", "y", "z"]
bttf = {}
for i in range(dim):
bttf["-"+str(i+1)] = ["-"+dim_names[i]]
bttf["+"+str(i+1)] = ["+"+dim_names[i]]
from meshmode.mesh.generation import generate_regular_rect_mesh as gen
return gen(a=a, b=b, n=n, boundary_tag_to_face=bttf, mesh_type=t,
periodic=periodic)


class InitSponge:
r"""Solution initializer for flow in the ACT-II facility.

Expand Down Expand Up @@ -192,7 +179,7 @@ def main(use_logmgr=True,
y_scale = 1
z_scale = 1

# - params for unscaled npts/axis
# - params for unscaled nels/axis
domain_xlen = .01
domain_ylen = .01
domain_zlen = .01
Expand Down Expand Up @@ -262,7 +249,7 @@ def main(use_logmgr=True,
# }}}

# coarse-scale grid/domain control
n_refine = 1 # scales npts/axis uniformly
n_refine = 1 # scales nels/axis uniformly
weak_scale = 1 # scales domain uniformly, keeping dt constant

# AV / Shock-capturing parameters
Expand Down Expand Up @@ -551,9 +538,9 @@ def main(use_logmgr=True,
ncy = int(ysize / chlen)
ncz = int(zsize / chlen)

npts_x = ncx * n_refine + 1
npts_y = ncy * n_refine + 1
npts_z = ncz * n_refine + 1
nels_x = ncx * n_refine
nels_y = ncy * n_refine
nels_z = ncz * n_refine

x0 = xsize/2
y0 = ysize/2
Expand All @@ -566,23 +553,23 @@ def main(use_logmgr=True,
zback = z0 - zsize/2
zfront = z0 + zsize/2

npts_axis = (npts_x,)
nels_axis = (nels_x,)
box_ll = (xleft,)
box_ur = (xright,)
if dim > 1:
npts_axis = (npts_x, npts_y)
nels_axis = (nels_x, nels_y)
box_ll = (xleft, ybottom)
box_ur = (xright, ytop)
if dim > 2:
npts_axis = (npts_x, npts_y, npts_z)
nels_axis = (nels_x, nels_y, nels_z)
box_ll = (xleft, ybottom, zback)
box_ur = (xright, ytop, zfront)

periodic = (periodic_boundary == 1,)*dim
if rank == 0:
print(f"---- Mesh generator inputs -----\n"
f"\tDomain: [{box_ll}, {box_ur}], {periodic=}\n"
f"\tNpts/axis: {npts_axis}")
f"\tNels/axis: {nels_axis}")

if single_gas_only:
inert_only = 1
Expand Down Expand Up @@ -618,7 +605,7 @@ def main(use_logmgr=True,
rst_step = restart_data["step"]
rst_order = restart_data["order"]
else: # generate the grid from scratch
generate_mesh = partial(_get_box_mesh, dim, a=box_ll, b=box_ur, n=npts_axis,
generate_mesh = partial(get_box_mesh, dim, a=box_ll, b=box_ur, n=nels_axis,
periodic=periodic)

local_mesh, global_nelements = generate_and_distribute_mesh(comm,
Expand Down
24 changes: 8 additions & 16 deletions examples/hotplate-mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@
from mirgecom.discretization import create_discretization_collection
from mirgecom.fluid import make_conserved
from mirgecom.navierstokes import ns_operator
from mirgecom.simutil import get_sim_timestep
from mirgecom.simutil import (
get_sim_timestep,
get_box_mesh
)

from mirgecom.io import make_init_message
from mirgecom.mpi import mpi_entry_point
Expand Down Expand Up @@ -68,17 +71,6 @@ class MyRuntimeError(RuntimeError):
pass


# Box grid generator widget lifted from @majosm and slightly bent
def _get_box_mesh(dim, a, b, n, t=None):
dim_names = ["x", "y", "z"]
bttf = {}
for i in range(dim):
bttf["-"+str(i+1)] = ["-"+dim_names[i]]
bttf["+"+str(i+1)] = ["+"+dim_names[i]]
from meshmode.mesh.generation import generate_regular_rect_mesh as gen
return gen(a=a, b=b, n=n, boundary_tag_to_face=bttf, mesh_type=t)


@mpi_entry_point
def main(use_logmgr=True,
use_leap=False, casename=None,
Expand Down Expand Up @@ -144,12 +136,12 @@ def main(use_logmgr=True,
assert restart_data["nparts"] == nparts
else: # generate the grid from scratch
n_refine = 2
npts_x = 6 * n_refine
npts_y = 4 * n_refine
npts_axis = (npts_x, npts_y)
nels_x = 5 * n_refine
nels_y = 3 * n_refine
nels_axis = (nels_x, nels_y)
box_ll = (left_boundary_location, bottom_boundary_location)
box_ur = (right_boundary_location, top_boundary_location)
generate_mesh = partial(_get_box_mesh, 2, a=box_ll, b=box_ur, n=npts_axis)
generate_mesh = partial(get_box_mesh, 2, a=box_ll, b=box_ur, n=nels_axis)
from mirgecom.simutil import generate_and_distribute_mesh
local_mesh, global_nelements = generate_and_distribute_mesh(comm,
generate_mesh)
Expand Down
29 changes: 9 additions & 20 deletions examples/poiseuille-mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import numpy as np
from pytools.obj_array import make_obj_array
from functools import partial

from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa

from grudge.shortcuts import make_visualizer
Expand All @@ -36,8 +35,10 @@
from mirgecom.discretization import create_discretization_collection
from mirgecom.fluid import make_conserved
from mirgecom.navierstokes import ns_operator
from mirgecom.simutil import get_sim_timestep

from mirgecom.simutil import (
get_sim_timestep,
get_box_mesh
)
from mirgecom.io import make_init_message
from mirgecom.mpi import mpi_entry_point
from mirgecom.integrators import rk4_step
Expand All @@ -59,7 +60,6 @@
set_sim_state
)


logger = logging.getLogger(__name__)


Expand All @@ -69,17 +69,6 @@ class MyRuntimeError(RuntimeError):
pass


# Box grid generator widget lifted from @majosm and slightly bent
def _get_box_mesh(dim, a, b, n, t=None):
dim_names = ["x", "y", "z"]
bttf = {}
for i in range(dim):
bttf["-"+str(i+1)] = ["-"+dim_names[i]]
bttf["+"+str(i+1)] = ["+"+dim_names[i]]
from meshmode.mesh.generation import generate_regular_rect_mesh as gen
return gen(a=a, b=b, n=n, boundary_tag_to_face=bttf, mesh_type=t)


@mpi_entry_point
def main(use_logmgr=True,
use_overintegration=False,
Expand Down Expand Up @@ -145,13 +134,13 @@ def main(use_logmgr=True,
global_nelements = restart_data["global_nelements"]
assert restart_data["nparts"] == nparts
else: # generate the grid from scratch
n_refine = 5
npts_x = 10 * n_refine
npts_y = 6 * n_refine
npts_axis = (npts_x, npts_y)
n_refine = 2
nels_x = 9 * n_refine
nels_y = 5 * n_refine
nels_axis = (nels_x, nels_y)
box_ll = (left_boundary_location, ybottom)
box_ur = (right_boundary_location, ytop)
generate_mesh = partial(_get_box_mesh, 2, a=box_ll, b=box_ur, n=npts_axis)
generate_mesh = partial(get_box_mesh, 2, a=box_ll, b=box_ur, n=nels_axis)
from mirgecom.simutil import generate_and_distribute_mesh
local_mesh, global_nelements = generate_and_distribute_mesh(comm,
generate_mesh)
Expand Down
57 changes: 57 additions & 0 deletions mirgecom/simutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
.. autofunction:: geometric_mesh_partitioner
.. autofunction:: distribute_mesh
.. autofunction:: get_number_of_tetrahedron_nodes
.. autofunction:: get_box_mesh

Simulation support utilities
----------------------------
Expand Down Expand Up @@ -97,6 +98,62 @@ def get_number_of_tetrahedron_nodes(dim, order, include_faces=False):
return nnodes


def get_box_mesh(dim, a, b, n, t=None, periodic=None):
"""
Create a rectangular "box" like mesh with tagged boundary faces.

The resulting mesh has boundary tags
`"-i"` and `"+i"` for `i=1,...,dim`
corresponding to lower and upper faces normal to coordinate dimension `i`.

Parameters
----------
dim: int
The mesh topological dimension
a: float or tuple
The coordinates of the lower corner of the box. If scalar-valued, gets
promoted to a uniform tuple.
b: float or tuple
The coordinates of the upper corner of the box. If scalar-valued, gets
promoted to a uniform tuple.
n: int or tuple
The number of elements along a given dimension. If scalar-valued, gets
promoted to a uniform tuple.
t: str or None
The mesh type. See
:func:`meshmode.mesh.generation.generate_box_mesh` for details.
periodic: bool or tuple or None
Indicates whether the mesh is periodic in a given dimension. If
scalar-valued, gets promoted to a uniform tuple.

Returns
-------
:class:`meshmode.mesh.Mesh`
The generated box mesh.
"""
if np.isscalar(a):
a = (a,)*dim
if np.isscalar(b):
b = (b,)*dim
if np.isscalar(n):
n = (n,)*dim
if periodic is None:
periodic = (False,)*dim
elif np.isscalar(periodic):
periodic = (periodic,)*dim

dim_names = ["x", "y", "z"]
bttf = {}
for i in range(dim):
bttf["-"+str(i+1)] = ["-"+dim_names[i]]
bttf["+"+str(i+1)] = ["+"+dim_names[i]]

from meshmode.mesh.generation import generate_regular_rect_mesh as gen
return gen(a=a, b=b, nelements_per_axis=n,
boundary_tag_to_face=bttf,
mesh_type=t, periodic=periodic)


def check_step(step, interval):
"""
Check step number against a user-specified interval.
Expand Down
18 changes: 3 additions & 15 deletions test/test_av.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
from pyopencl.tools import ( # noqa
pytest_generate_tests_for_pyopencl as pytest_generate_tests,
)

from mirgecom.simutil import get_box_mesh
from pytools.obj_array import make_obj_array

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -337,18 +337,6 @@ def test_trig(ctx_factory, dim, order):
)


# Box grid generator widget lifted from @majosm's diffusion tester
def _get_box_mesh(dim, a, b, n):
dim_names = ["x", "y", "z"]
boundary_tag_to_face = {}
for i in range(dim):
boundary_tag_to_face["-"+str(i+1)] = ["-"+dim_names[i]]
boundary_tag_to_face["+"+str(i+1)] = ["+"+dim_names[i]]
from meshmode.mesh.generation import generate_regular_rect_mesh
return generate_regular_rect_mesh(a=(a,)*dim, b=(b,)*dim, n=(n,)*dim,
boundary_tag_to_face=boundary_tag_to_face)


class _VortexSoln:

def __init__(self, **kwargs):
Expand Down Expand Up @@ -411,10 +399,10 @@ def _boundary_state_func(dcoll, dd_bdry, gas_model, state_minus, **kwargs):
return make_fluid_state(prescribed_soln(r=nodes, eos=gas_model.eos,
**kwargs), gas_model)

npts_geom = 17
nels_geom = 16
a = 1.0
b = 2.0
mesh = _get_box_mesh(dim=dim, a=a, b=b, n=npts_geom)
mesh = get_box_mesh(dim=dim, a=a, b=b, n=nels_geom)
from mirgecom.discretization import create_discretization_collection
dcoll = create_discretization_collection(actx, mesh, order=order)
nodes = actx.thaw(dcoll.nodes())
Expand Down
Loading