Skip to content

Commit

Permalink
make comm_tag a required parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasdiener committed Jan 23, 2023
1 parent 445f712 commit 87a5c53
Show file tree
Hide file tree
Showing 21 changed files with 123 additions and 59 deletions.
11 changes: 10 additions & 1 deletion examples/autoignition-mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ class MyRuntimeError(RuntimeError):
pass


class FluidTag:
pass


class FluidOpTag:
pass


@mpi_entry_point
def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True,
use_leap=False, use_overintegration=False, use_profiling=False,
Expand Down Expand Up @@ -612,11 +620,12 @@ def my_rhs(t, state):
limiter_func=_limit_fluid_cv)

fluid_operator_states = make_operator_fluid_states(
dcoll, fluid_state, gas_model, boundaries=boundaries,
dcoll, fluid_state, gas_model, boundaries=boundaries, comm_tag=FluidTag,
quadrature_tag=quadrature_tag, limiter_func=_limit_fluid_cv)

fluid_rhs = fluid_operator(
dcoll, state=fluid_state, gas_model=gas_model, time=t,
comm_tag=FluidOpTag,
boundaries=boundaries, operator_states_quad=fluid_operator_states,
quadrature_tag=quadrature_tag,
inviscid_numerical_flux_func=inv_num_flux_func)
Expand Down
13 changes: 11 additions & 2 deletions examples/doublemach-mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ class MyRuntimeError(RuntimeError):
pass


class EulerTag:
pass


class AVLaplacianTag:
pass


def get_doublemach_mesh():
"""Generate or import a grid using `gmsh`.
Expand Down Expand Up @@ -405,9 +413,10 @@ def my_rhs(t, state):
fluid_state = make_fluid_state(state, gas_model)
return (
euler_operator(dcoll, state=fluid_state, time=t,
boundaries=boundaries,
boundaries=boundaries, comm_tag=EulerTag,
gas_model=gas_model, quadrature_tag=quadrature_tag)
+ av_laplacian_operator(dcoll, fluid_state=fluid_state,
+ av_laplacian_operator(dcoll, comm_tag=AVLaplacianTag,
fluid_state=fluid_state,
boundaries=boundaries,
time=t, gas_model=gas_model,
alpha=alpha, s0=s0, kappa=kappa,
Expand Down
7 changes: 6 additions & 1 deletion examples/heat-source-mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
from logpyle import IntervalTimer, set_dt


class DiffusionTag:
pass


@mpi_entry_point
def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True,
use_leap=False, use_profiling=False, casename=None, lazy=False,
Expand Down Expand Up @@ -151,7 +155,8 @@ def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True,

def rhs(t, u):
return (
diffusion_operator(dcoll, kappa=1, boundaries=boundaries, u=u)
diffusion_operator(dcoll, comm_tag=DiffusionTag,
kappa=1, boundaries=boundaries, u=u)
+ actx.np.exp(-np.dot(nodes, nodes)/source_width**2))

compiled_rhs = actx.compile(rhs)
Expand Down
8 changes: 6 additions & 2 deletions examples/hotplate-mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class MyRuntimeError(RuntimeError):
pass


class NSTag:
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"]
Expand Down Expand Up @@ -409,8 +413,8 @@ def my_post_step(step, t, dt, state):

def my_rhs(t, state):
fluid_state = make_fluid_state(state, gas_model)
return ns_operator(dcoll, boundaries=boundaries, state=fluid_state,
time=t, gas_model=gas_model)
return ns_operator(dcoll, comm_tag=NSTag, boundaries=boundaries,
state=fluid_state, time=t, gas_model=gas_model)

current_dt = get_sim_timestep(dcoll, current_state, current_t, current_dt,
current_cfl, t_final, constant_cfl)
Expand Down
6 changes: 5 additions & 1 deletion examples/lump-mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ class MyRuntimeError(RuntimeError):
pass


class EulerTag:
pass


@mpi_entry_point
def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True,
use_leap=False, use_profiling=False, casename=None, lazy=False,
Expand Down Expand Up @@ -330,7 +334,7 @@ def my_post_step(step, t, dt, state):

def my_rhs(t, state):
fluid_state = make_fluid_state(state, gas_model)
return euler_operator(dcoll, state=fluid_state, time=t,
return euler_operator(dcoll, comm_tag=EulerTag, state=fluid_state, time=t,
boundaries=boundaries, gas_model=gas_model)

current_dt = get_sim_timestep(dcoll, current_state, current_t, current_dt,
Expand Down
6 changes: 5 additions & 1 deletion examples/mixture-mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class MyRuntimeError(RuntimeError):
pass


class EulerTag:
pass


@mpi_entry_point
def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True,
use_leap=False, use_profiling=False, casename=None, rst_filename=None,
Expand Down Expand Up @@ -382,7 +386,7 @@ def my_rhs(t, state):
cv, tseed = state
fluid_state = make_fluid_state(cv, gas_model, temperature_seed=tseed)
return make_obj_array(
[euler_operator(dcoll, state=fluid_state, time=t,
[euler_operator(dcoll, comm_tag=EulerTag, state=fluid_state, time=t,
boundaries=boundaries, gas_model=gas_model),
0*tseed])

Expand Down
6 changes: 5 additions & 1 deletion examples/nsmix-mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ class MyRuntimeError(RuntimeError):
pass


class NSTag:
pass


@mpi_entry_point
def main(ctx_factory=cl.create_some_context, use_logmgr=True,
use_leap=False, use_profiling=False, casename=None,
Expand Down Expand Up @@ -485,7 +489,7 @@ def my_rhs(t, state):
cv, tseed = state
fluid_state = make_fluid_state(cv=cv, gas_model=gas_model,
temperature_seed=tseed)
ns_rhs = ns_operator(dcoll, state=fluid_state, time=t,
ns_rhs = ns_operator(dcoll, comm_tag=NSTag, state=fluid_state, time=t,
boundaries=visc_bnds, gas_model=gas_model)
cv_rhs = ns_rhs + eos.get_species_source_terms(cv, fluid_state.temperature)
return make_obj_array([cv_rhs, 0*tseed])
Expand Down
7 changes: 6 additions & 1 deletion examples/poiseuille-local_dt-mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ class MyRuntimeError(RuntimeError):
pass


class NSTag:
pass


@mpi_entry_point
def main(ctx_factory=cl.create_some_context, use_logmgr=True,
use_overintegration=False, lazy=False,
Expand Down Expand Up @@ -432,7 +436,8 @@ def my_post_step(step, t, dt, state):

def my_rhs(t, state):
fluid_state = make_fluid_state(state, gas_model)
return ns_operator(dcoll, gas_model=gas_model, boundaries=boundaries,
return ns_operator(dcoll, comm_tag=NSTag, gas_model=gas_model,
boundaries=boundaries,
state=fluid_state, time=t,
quadrature_tag=quadrature_tag)

Expand Down
7 changes: 6 additions & 1 deletion examples/poiseuille-mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ class MyRuntimeError(RuntimeError):
pass


class NSTag:
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"]
Expand Down Expand Up @@ -419,7 +423,8 @@ def my_post_step(step, t, dt, state):

def my_rhs(t, state):
fluid_state = make_fluid_state(state, gas_model)
return ns_operator(dcoll, gas_model=gas_model, boundaries=boundaries,
return ns_operator(dcoll, comm_tag=NSTag, gas_model=gas_model,
boundaries=boundaries,
state=fluid_state, time=t,
quadrature_tag=quadrature_tag)

Expand Down
7 changes: 6 additions & 1 deletion examples/pulse-mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ class MyRuntimeError(RuntimeError):
pass


class EulerTag:
pass


@mpi_entry_point
def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True,
use_overintegration=False, lazy=False, use_leap=False, use_profiling=False,
Expand Down Expand Up @@ -303,7 +307,8 @@ def my_rhs(t, state):
return euler_operator(dcoll, state=fluid_state, time=t,
boundaries=boundaries,
gas_model=gas_model,
quadrature_tag=quadrature_tag)
quadrature_tag=quadrature_tag,
comm_tag=EulerTag)

current_dt = get_sim_timestep(dcoll, current_state, current_t, current_dt,
current_cfl, t_final, constant_cfl)
Expand Down
6 changes: 5 additions & 1 deletion examples/scalar-lump-mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ class MyRuntimeError(RuntimeError):
pass


class EulerTag:
pass


@mpi_entry_point
def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True,
use_leap=False, use_profiling=False, casename=None,
Expand Down Expand Up @@ -341,7 +345,7 @@ def my_post_step(step, t, dt, state):

def my_rhs(t, state):
fluid_state = make_fluid_state(state, gas_model)
return euler_operator(dcoll, state=fluid_state, time=t,
return euler_operator(dcoll, comm_tag=EulerTag, state=fluid_state, time=t,
boundaries=boundaries, gas_model=gas_model)

current_dt = get_sim_timestep(dcoll, current_state, current_t, current_dt,
Expand Down
6 changes: 5 additions & 1 deletion examples/sod-mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ class MyRuntimeError(RuntimeError):
pass


class EulerTag:
pass


@mpi_entry_point
def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True,
use_leap=False, use_profiling=False, casename=None, lazy=False,
Expand Down Expand Up @@ -331,7 +335,7 @@ def my_post_step(step, t, dt, state):

def my_rhs(t, state):
fluid_state = make_fluid_state(cv=state, gas_model=gas_model)
return euler_operator(dcoll, state=fluid_state, time=t,
return euler_operator(dcoll, comm_tag=EulerTag, state=fluid_state, time=t,
boundaries=boundaries, gas_model=gas_model)

current_dt = get_sim_timestep(dcoll, current_state, current_t, current_dt,
Expand Down
7 changes: 6 additions & 1 deletion examples/vortex-mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class MyRuntimeError(RuntimeError):
pass


class EulerTag:
pass


@mpi_entry_point
def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True,
use_leap=False, use_profiling=False, casename=None, lazy=False,
Expand Down Expand Up @@ -357,7 +361,8 @@ def my_post_step(step, t, dt, state):
def my_rhs(t, state):
fluid_state = make_fluid_state(state, gas_model)
return euler_operator(dcoll, state=fluid_state, time=t,
boundaries=boundaries, gas_model=gas_model)
boundaries=boundaries, gas_model=gas_model,
comm_tag=EulerTag)

current_dt = get_sim_timestep(dcoll, current_state, current_t, current_dt,
current_cfl, t_final, constant_cfl)
Expand Down
6 changes: 5 additions & 1 deletion examples/wave-mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
logmgr_add_device_memory_usage)


class WaveTag:
pass


def bump(actx, nodes, t=0):
"""Create a bump."""
dim = len(nodes)
Expand Down Expand Up @@ -187,7 +191,7 @@ def main(actx_class, snapshot_pattern="wave-mpi-{step:04d}-{rank:04d}.pkl",
vis = make_visualizer(dcoll)

def rhs(t, w):
return wave_operator(dcoll, c=wave_speed, w=w)
return wave_operator(dcoll, c=wave_speed, w=w, comm_tag=WaveTag)
fields = force_evaluation(actx, fields)
compiled_rhs = actx.compile(rhs)

Expand Down
6 changes: 5 additions & 1 deletion examples/wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
logmgr_add_device_memory_usage)


class WaveTag:
pass


def bump(actx, nodes, t=0):
"""Create a bump."""
dim = len(nodes)
Expand Down Expand Up @@ -138,7 +142,7 @@ def main(actx_class, use_profiling=False, use_logmgr=False, lazy: bool = False):
vis = make_visualizer(dcoll)

def rhs(t, w):
return wave_operator(dcoll, c=wave_speed, w=w)
return wave_operator(dcoll, c=wave_speed, w=w, comm_tag=WaveTag)

compiled_rhs = actx.compile(rhs)
fields = force_evaluation(actx, fields)
Expand Down
17 changes: 8 additions & 9 deletions mirgecom/artificial_viscosity.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,11 @@ class _AVRTag:
pass


def av_laplacian_operator(dcoll, boundaries, fluid_state, alpha, gas_model=None,
def av_laplacian_operator(dcoll, boundaries, fluid_state, alpha, comm_tag,
gas_model=None,
kappa=1., s0=-6., time=0, quadrature_tag=DISCR_TAG_BASE,
dd=DD_VOLUME_ALL, boundary_kwargs=None, indicator=None,
divergence_numerical_flux=num_flux_central, comm_tag=None,
divergence_numerical_flux=num_flux_central,
operator_states_quad=None,
grad_cv=None,
**kwargs):
Expand All @@ -182,6 +183,9 @@ def av_laplacian_operator(dcoll, boundaries, fluid_state, alpha, gas_model=None,
alpha: float
The maximum artificial viscosity coefficient to be applied
comm_tag: Hashable
Tag for distributed communication
indicator: :class:`~meshmode.dof_array.DOFArray`
The indicator field used for locating where AV should be applied. If not
supplied by the user, then
Expand All @@ -206,16 +210,11 @@ def av_laplacian_operator(dcoll, boundaries, fluid_state, alpha, gas_model=None,
the DOF descriptor of the discretization on which *fluid_state* lives.
Must be a volume on the base discretization.
comm_tag: Hashable
Tag for distributed communication
Returns
-------
:class:`mirgecom.fluid.ConservedVars`
The artificial viscosity operator applied to *q*.
"""
assert comm_tag is not None, "comm_tag can not be 'None'"

boundaries = normalize_boundaries(boundaries)

cv = fluid_state.cv
Expand Down Expand Up @@ -248,8 +247,8 @@ def interp_to_vol_quad(u):
if operator_states_quad is None:
from mirgecom.gas_model import make_operator_fluid_states
operator_states_quad = make_operator_fluid_states(
dcoll, fluid_state, gas_model, boundaries, quadrature_tag,
dd=dd_vol, comm_tag=comm_tag)
dcoll, fluid_state, gas_model, boundaries, comm_tag, quadrature_tag,
dd=dd_vol)

vol_state_quad, inter_elem_bnd_states_quad, domain_bnd_states_quad = \
operator_states_quad
Expand Down
6 changes: 2 additions & 4 deletions mirgecom/diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ def boundary_flux(bdtag, bdry):


def diffusion_operator(
dcoll, kappa, boundaries, u, *, return_grad_u=False,
quadrature_tag=DISCR_TAG_BASE, dd=DD_VOLUME_ALL, comm_tag=None,
dcoll, kappa, boundaries, u, *, comm_tag, return_grad_u=False,
quadrature_tag=DISCR_TAG_BASE, dd=DD_VOLUME_ALL,
# Added to avoid repeated computation
# FIXME: See if there's a better way to do this
grad_u=None):
Expand Down Expand Up @@ -353,8 +353,6 @@ def diffusion_operator(
grad_u: numpy.ndarray
the gradient of *u*; only returned if *return_grad_u* is True
"""
assert comm_tag is not None, "comm_tag can not be 'None'"

if isinstance(u, np.ndarray):
if not isinstance(boundaries, list):
raise TypeError("boundaries must be a list if u is an object array")
Expand Down
Loading

0 comments on commit 87a5c53

Please sign in to comment.