From cc2a092bceb77e7f1c7b91e1fc8501b6c19bdcf8 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Sun, 12 May 2019 22:47:40 -0500 Subject: [PATCH] Port over some examples --- .../advection/var-velocity.py | 12 +++++++----- {unported-examples => examples}/advection/weak.py | 2 +- .../fusion-study.py => dagrt-fusion.py} | 0 {unported-examples => examples}/geometry.py | 6 +++--- {unported-examples => examples}/maxwell/cavities.py | 13 ++++++++----- 5 files changed, 19 insertions(+), 14 deletions(-) rename {unported-examples => examples}/advection/var-velocity.py (94%) rename {unported-examples => examples}/advection/weak.py (98%) rename examples/{dagrt_fusion/fusion-study.py => dagrt-fusion.py} (100%) rename {unported-examples => examples}/geometry.py (92%) rename {unported-examples => examples}/maxwell/cavities.py (92%) diff --git a/unported-examples/advection/var-velocity.py b/examples/advection/var-velocity.py similarity index 94% rename from unported-examples/advection/var-velocity.py rename to examples/advection/var-velocity.py index 00e4f0c8..bc720731 100644 --- a/unported-examples/advection/var-velocity.py +++ b/examples/advection/var-velocity.py @@ -40,6 +40,9 @@ from grudge import sym, bind, DGDiscretizationWithBoundaries from pytools.obj_array import join_fields +FINAL_TIME = 5 + + def main(write_output=True, order=4): cl_ctx = cl.create_some_context() queue = cl.CommandQueue(cl_ctx) @@ -105,10 +108,9 @@ def main(write_output=True, order=4): def rhs(t, u): return bound_op(queue, t=t, u=u) - final_time = 50 dt = dt_factor * h/order**2 - nsteps = (final_time // dt) + 1 - dt = final_time/nsteps + 1e-15 + nsteps = (FINAL_TIME // dt) + 1 + dt = FINAL_TIME/nsteps + 1e-15 from grudge.shortcuts import set_up_rk4 dt_stepper = set_up_rk4("u", dt, u, rhs) @@ -118,14 +120,14 @@ def main(write_output=True, order=4): step = 0 - for event in dt_stepper.run(t_end=final_time): + for event in dt_stepper.run(t_end=FINAL_TIME): if isinstance(event, dt_stepper.StateComputed): step += 1 if step % 30 == 0: print(step) - vis.write_vtk_file("fld-%04d.vtu" % step, + vis.write_vtk_file("fld-var-velocity-%04d.vtu" % step, [("u", event.state_component)]) diff --git a/unported-examples/advection/weak.py b/examples/advection/weak.py similarity index 98% rename from unported-examples/advection/weak.py rename to examples/advection/weak.py index cdadb49e..bd9d61ca 100644 --- a/unported-examples/advection/weak.py +++ b/examples/advection/weak.py @@ -103,7 +103,7 @@ def main(write_output=True, order=4): step += 1 #print(step, event.t, norm(queue, u=event.state_component[0])) - vis.write_vtk_file("fld-%04d.vtu" % step, + vis.write_vtk_file("fld-weak-%04d.vtu" % step, [ ("u", event.state_component) ]) diff --git a/examples/dagrt_fusion/fusion-study.py b/examples/dagrt-fusion.py similarity index 100% rename from examples/dagrt_fusion/fusion-study.py rename to examples/dagrt-fusion.py diff --git a/unported-examples/geometry.py b/examples/geometry.py similarity index 92% rename from unported-examples/geometry.py rename to examples/geometry.py index e10254bf..6e146f21 100644 --- a/unported-examples/geometry.py +++ b/examples/geometry.py @@ -26,7 +26,7 @@ THE SOFTWARE. import numpy as np # noqa import pyopencl as cl -from grudge import sym, bind, Discretization, shortcuts +from grudge import sym, bind, DGDiscretizationWithBoundaries, shortcuts def main(write_output=True): @@ -36,14 +36,14 @@ def main(write_output=True): from meshmode.mesh.generation import generate_warped_rect_mesh mesh = generate_warped_rect_mesh(dim=2, order=4, n=6) - discr = Discretization(cl_ctx, mesh, order=4) + discr = DGDiscretizationWithBoundaries(cl_ctx, mesh, order=4) sym_op = sym.normal(sym.BTAG_ALL, mesh.dim) #sym_op = sym.nodes(mesh.dim, where=sym.BTAG_ALL) print(sym.pretty(sym_op)) op = bind(discr, sym_op) print() - print(op.code) + print(op.eval_code) vec = op(queue) diff --git a/unported-examples/maxwell/cavities.py b/examples/maxwell/cavities.py similarity index 92% rename from unported-examples/maxwell/cavities.py rename to examples/maxwell/cavities.py index 85a7c3de..a58f2739 100644 --- a/unported-examples/maxwell/cavities.py +++ b/examples/maxwell/cavities.py @@ -28,11 +28,14 @@ THE SOFTWARE. import numpy as np import pyopencl as cl from grudge.shortcuts import set_up_rk4 -from grudge import sym, bind, Discretization +from grudge import sym, bind, DGDiscretizationWithBoundaries from grudge.models.em import get_rectangular_cavity_mode +STEPS = 60 + + def main(dims, write_output=True, order=4): cl_ctx = cl.create_some_context() queue = cl.CommandQueue(cl_ctx) @@ -43,7 +46,7 @@ def main(dims, write_output=True, order=4): b=(1.0,)*dims, n=(5,)*dims) - discr = Discretization(cl_ctx, mesh, order=order) + discr = DGDiscretizationWithBoundaries(cl_ctx, mesh, order=order) if 0: epsilon0 = 8.8541878176e-12 # C**2 / (N m**2) @@ -84,7 +87,7 @@ def main(dims, write_output=True, order=4): dt_stepper = set_up_rk4("w", dt, fields, rhs) - final_t = dt * 600 + final_t = dt * STEPS nsteps = int(final_t/dt) print("dt=%g nsteps=%d" % (dt, nsteps)) @@ -102,7 +105,7 @@ def main(dims, write_output=True, order=4): e, h = op.split_eh(fields) if 1: - vis.write_vtk_file("fld-%04d.vtu" % step, + vis.write_vtk_file("fld-cavities-%04d.vtu" % step, [ ("e", e), ("h", h), @@ -119,7 +122,7 @@ def main(dims, write_output=True, order=4): time()-t_last_step) if step % 10 == 0: e, h = op.split_eh(event.state_component) - vis.write_vtk_file("fld-%04d.vtu" % step, + vis.write_vtk_file("fld-cavities-%04d.vtu" % step, [ ("e", e), ("h", h), -- GitLab