Skip to content
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
157 commits
Select commit Hold shift + click to select a range
7be62eb
Re-enable timestep and CFL routines after new world grudge provided g…
MTCam May 28, 2021
7531492
Use mpi comm from discr.
MTCam May 28, 2021
3d9e742
Apply simplication from (live) @thomasgibson review.
MTCam May 28, 2021
8e6c579
Merge branch 'main' into enable-cfl-and-dt
MTCam May 28, 2021
caf7e51
Merge branch 'main' into enable-cfl-and-dt
thomasgibson May 28, 2021
5fac3cb
Use grudge dt finding utils (#371)
MTCam Jun 3, 2021
711995a
Correct for built-in grudge geofacs, local cfl viz in selected examples.
MTCam Jun 3, 2021
bf0dcb6
Report CFL in status msg.
MTCam Jun 3, 2021
28c3fe2
Merge branch 'main' into enable-cfl-and-dt
MTCam Jun 3, 2021
f2f4777
Update to new dt_geometric_factors interface.
MTCam Jun 4, 2021
00e55f5
Clean up the inviscid dt routines a bit, evict reductions.
MTCam Jun 4, 2021
2a3f299
Clean up the sim util dt routine a bit, add reductions.
MTCam Jun 4, 2021
035a6de
Merge branch 'main' into enable-cfl-and-dt
MTCam Jun 5, 2021
1b3e3d8
Switch back to grudge main.
MTCam Jun 5, 2021
80d8087
Sharpen the documentation, and the interface.
MTCam Jun 6, 2021
5377759
Documutation
MTCam Jun 6, 2021
856821c
Add pre/post callback function args to advance_state
thomasgibson May 28, 2021
72ceaf6
Pass checkpoint functions as pre-step callbacks
thomasgibson May 28, 2021
2814826
Add healthcheck callback and exceptions
thomasgibson May 28, 2021
25dd51c
Use healthcheck callbacks in examples
thomasgibson May 28, 2021
7ee673c
Fix docstring for sim_healthcheck
thomasgibson May 28, 2021
9dba4ff
Document callback signature and return state
thomasgibson Jun 4, 2021
f1b3e4f
Test the basic healthcheck callback
thomasgibson Jun 4, 2021
faba167
Remove EOS copy-pasta
thomasgibson Jun 4, 2021
0b6df95
Minor refactoring and allow callbacks to terminate the simulation
thomasgibson Jun 5, 2021
b656079
Fix exception docs
thomasgibson Jun 5, 2021
2acdf73
Expand documentation of callbacks
thomasgibson Jun 5, 2021
5405604
Simplify sim_checkpoint and modularize callbacks
thomasgibson Jun 5, 2021
ca7c37b
Update steppers
thomasgibson Jun 6, 2021
da65cd2
Write short test for comparison callback
thomasgibson Jun 6, 2021
2523fbd
Renaming: {cfd_healthcheck,StepperCrashError} -> {sim_healthcheck,Syn…
thomasgibson Jun 7, 2021
8284d8a
Simplify drivers; move exception handling into sim_checkpoint
thomasgibson Jun 7, 2021
00d29a0
Merge branch 'main' into thg/callbacks
thomasgibson Jun 8, 2021
cba127b
Fix callback tests
thomasgibson Jun 8, 2021
5c091bd
Merge branch 'thg/callbacks' of github.com:illinois-ceesd/mirgecom in…
thomasgibson Jun 8, 2021
b58594c
Use better dt_utils function.
MTCam Jun 8, 2021
14760b8
Merge branch 'main' into enable-cfl-and-dt
MTCam Jun 8, 2021
e2dc67b
Use grudge@nongeo-factors-per-group util inducer/grudge/#121
MTCam Jun 8, 2021
4c938fa
Clean up sim_checkpoint function
thomasgibson Jun 8, 2021
b1eb999
Update to latest (and greatest) API from grudge
MTCam Jun 9, 2021
6ef0f05
Fix transcribo on grudge dt utils func name
MTCam Jun 9, 2021
63097b6
Merge branch 'main' into enable-cfl-and-dt
MTCam Jun 10, 2021
0c2e986
Update simutils/health/checkpoint - move most to driver, simplify
MTCam Jun 11, 2021
169b92d
Merge branch 'main' into mrgmain
MTCam Jun 11, 2021
15bdf3d
Port examples into place, slight adjustment/cleanup/corrections for s…
MTCam Jun 11, 2021
68302b4
Update tests to match the facilities.
MTCam Jun 11, 2021
8b506e1
Twiddle to test both pressure and mass for first bad state.
MTCam Jun 11, 2021
9ed0202
Port examples to cv actx
MTCam Jun 11, 2021
5043f86
Merge branch 'main' into recallbacks
MTCam Jun 11, 2021
51ade9b
Sharpen the error sync.
MTCam Jun 11, 2021
6833902
Update error handling to match review suggestion by @thomasgibson.
MTCam Jun 11, 2021
080513e
Udpate error handling per @thomasgibson review.
MTCam Jun 11, 2021
355a251
Update API per updated grudge
MTCam Jun 11, 2021
df41a5d
Switch back to grudge proper.
MTCam Jun 11, 2021
67f0686
Merge branch 'main' into enable-cfl-and-dt
MTCam Jun 11, 2021
3824627
Update timestep API per CV array container
MTCam Jun 11, 2021
70ff6dc
Sharpen the handling of post-stepping (exceptional) io per @majosm.
MTCam Jun 12, 2021
cccff7f
Sharpen the valid ranges specific to each example, and remove default…
MTCam Jun 12, 2021
1772b86
Correct call to naninf in test.
MTCam Jun 12, 2021
a9b7990
Use verbs for function names.
MTCam Jun 12, 2021
100df77
Use new name for visfile util, switch autoignition and vortex over to…
MTCam Jun 13, 2021
6f7ef04
Clean up logging a bit, attempt to use nlog to control logging interval.
MTCam Jun 13, 2021
5f31dcf
Use better, more descriptive variable names.
MTCam Jun 13, 2021
270ea3b
Use better, more descriptive variable names.
MTCam Jun 13, 2021
6ff984d
Update dt calculator to jibe with review suggestions.
MTCam Jun 13, 2021
4376604
Merge branch 'main' into recallbacks
MTCam Jun 15, 2021
cbd85cc
Merge branch 'main' into enable-cfl-and-dt
MTCam Jun 15, 2021
cfadcf6
Merge branch 'main' into enable-cfl-and-dt
MTCam Jun 15, 2021
2d37e96
Merge branch 'main' into recallbacks
MTCam Jun 15, 2021
146cf6f
Sharpen doc slightly
MTCam Jun 16, 2021
ce3373e
Sharpen doc slightly, and succintify routine a bit
MTCam Jun 16, 2021
b4779d4
Add constant CFL example
MTCam Jun 16, 2021
337b647
Tweak status message just a bit... logging will take over soon.
MTCam Jun 16, 2021
0c9c459
Make sim_checkpoint return state, dt
MTCam Jun 16, 2021
9b75f84
Merge branch 'main' into enable-cfl-and-dt
MTCam Jun 19, 2021
c74b9f5
Merge branch 'main' into recallbacks
MTCam Jun 19, 2021
8d60a7c
Merge branch 'main' into enable-cfl-and-dt
MTCam Jun 23, 2021
1ca252e
Merge branch 'main' into recallbacks
MTCam Jun 23, 2021
4c94a7d
Fix merge errors
MTCam Jun 23, 2021
5f38088
Sharpen logic/comment for clarity
MTCam Jun 24, 2021
fa77a6f
Merge branch 'main' into enable-cfl-and-dt
MTCam Jun 25, 2021
6e1e913
Merge branch 'main' into recallbacks
MTCam Jun 25, 2021
90dfda2
Fix up Leap for constant cfl mode, clean up loose ends per review com…
MTCam Jun 25, 2021
e60f7ee
Merge branch 'unfkdt' into enable-cfl-and-dt
MTCam Jun 25, 2021
c3169c2
Attempt to address linting errors.
MTCam Jun 25, 2021
a2a3670
Merge branch 'main' into enable-cfl-and-dt
MTCam Jun 25, 2021
fa9aab6
Merge branch 'main' into recallbacks
MTCam Jun 25, 2021
708593a
Make dummy checkpoint return dt
MTCam Jun 25, 2021
a9ee9f4
Merge branch 'unfkdt' into enable-cfl-and-dt
MTCam Jun 25, 2021
3e34bcc
Merge branch 'main' into recallbacks
MTCam Jun 29, 2021
aa0e353
Merge branch 'main' into enable-cfl-and-dt
MTCam Jun 29, 2021
c068283
Merge branch 'main' into enable-cfl-and-dt
MTCam Jun 30, 2021
7f38ed1
Merge branch 'main' into recallbacks
MTCam Jun 30, 2021
0e938cd
Merge branch 'main' into enable-cfl-and-dt
MTCam Jun 30, 2021
ffb35b8
Merge branch 'main' into recallbacks
MTCam Jun 30, 2021
293d28f
Refactor autoignit just a bit
MTCam Jul 2, 2021
8443a66
Refactor autoignition example per discussions.
MTCam Jul 3, 2021
d2b2c68
Bring examples up-to-date with current stepper API
MTCam Jul 3, 2021
9a5fcf3
Add DT health check to autoignition.
MTCam Jul 3, 2021
de48784
Modernize lump example
MTCam Jul 6, 2021
a5e5fc4
remove unused exceptions module, for now
MTCam Jul 6, 2021
42ea719
remove unused exceptions module, for now
MTCam Jul 6, 2021
0d74f9c
fix api/signature and doc
MTCam Jul 6, 2021
ae90d9f
Update stepper API to current
MTCam Jul 7, 2021
d092b82
Modernize more examples.
MTCam Jul 7, 2021
ff489e1
Fix simutil import
MTCam Jul 7, 2021
aa07513
Fix up steppers to call get_timestep properly
MTCam Jul 7, 2021
1464b9b
Fix up inviscid_sim_timestep to properly consider t_remaining
MTCam Jul 7, 2021
3dfdb21
Modernize examples.
MTCam Jul 7, 2021
926e76a
Correct misnamed restart parameter.
MTCam Jul 7, 2021
cd95207
Merge branch 'main' into recallbacks
MTCam Jul 7, 2021
f4466c1
Merge branch 'main' into enable-cfl-and-dt
MTCam Jul 7, 2021
82eb938
Reduce number of steps to speed up CI.
MTCam Jul 8, 2021
47d41d7
Turn off profiling, reduce number of steps to improve CI time
MTCam Jul 8, 2021
ef1ca55
Reduce number of steps to improve CI time.
MTCam Jul 8, 2021
02b37d8
Unify call signatures of user-defined utilities.
MTCam Jul 8, 2021
7d6c988
Correct some dumb issues with the examples.
MTCam Jul 8, 2021
ab06ff7
Correct errant call-sites to new utility signatures.
MTCam Jul 8, 2021
9c63136
Call logmgr_set_time on restart.
MTCam Jul 8, 2021
1b4df75
Deprecate logmgr, dim, eos args to stepper.
MTCam Jul 8, 2021
c857e06
Correct mistake in input restart file naming.
MTCam Jul 8, 2021
bdd4d90
Correct mistake in input restart file naming.
MTCam Jul 8, 2021
1a7e8e3
Correct import location for logmgr_set_time
MTCam Jul 8, 2021
6a7d20c
Document dt, deprecate get_timestep arg
MTCam Jul 8, 2021
ea98b59
Update examples to use exceptions to clean up error handling, evict g…
MTCam Jul 9, 2021
d7bca23
Merge branch 'main' into recallbacks
MTCam Jul 9, 2021
e36cb2b
Merge branch 'main' into enable-cfl-and-dt
MTCam Jul 9, 2021
72505bc
Correct finished check, return a proper constant dt result, some othe…
MTCam Jul 9, 2021
544a63f
Merge branch 'yupdayt-recallbacks' into recallbacks
MTCam Jul 9, 2021
3c3bbd5
Correct and enhance the restart processing to demonstrate change-of-o…
MTCam Jul 9, 2021
41f78ba
Update restart logic, add missing final dump advice.
MTCam Jul 9, 2021
5c3ab55
Use built-in exceptions instead of custom ones.
MTCam Jul 9, 2021
c544ddd
Satisfy pylint to raise an actual named exception inside try.
MTCam Jul 9, 2021
810ab46
Fix up the documentation to have the correct signature for callbacks
MTCam Jul 9, 2021
549a8dd
Massage exceptions a bit so that the error messages are a little more…
MTCam Jul 9, 2021
d51755a
Merge branch 'exceptions-massage' into recallbacks
MTCam Jul 9, 2021
af009c3
Rearrange function def order for consistency and less "tism" activation.
MTCam Jul 9, 2021
5306e30
Tweak exception handling to our liking.
MTCam Jul 9, 2021
5bd30d8
Add syncing utility and use it in examples.
MTCam Jul 9, 2021
d45d81a
Merge with recallbacks
MTCam Jul 9, 2021
56df2d8
Notify of which examples failed.
MTCam Jul 9, 2021
2210715
Merge branch 'main' into enable-cfl-and-dt
MTCam Jul 10, 2021
53a220d
Fix merge error
MTCam Jul 10, 2021
f781d80
Clean up a couple of drivers, move toward constant cfl support
MTCam Jul 10, 2021
b8114cd
add missing arg to write_vis
MTCam Jul 10, 2021
c523fa4
Remove superfluous constant CFL example.
MTCam Jul 10, 2021
c68f1e4
Clean up, succinctify some of the interfaces, add cfl to viz interface.
MTCam Jul 12, 2021
a3250f4
Rarrange cosmetically into logical sections, use simutil timestep util.
MTCam Jul 12, 2021
5d373ac
Use simutil timestep util, clean up restart handling, some cosmetics
MTCam Jul 12, 2021
71d74f8
Rename the timestepping interface, add note about viscous
MTCam Jul 12, 2021
07fa272
Clean up examples a bit, massage timestepping control for constant CF…
MTCam Jul 12, 2021
59fc7a4
Correct health call.
MTCam Jul 12, 2021
4595fcc
Sharpen and correct docstrings.
MTCam Jul 12, 2021
2fe594a
Shorten the line without perturbing the info?
MTCam Jul 12, 2021
7ec27d4
Merge branch 'main' into enable-cfl-and-dt
MTCam Jul 12, 2021
69a5fa4
Update production setup to be compatible with CFL/DT development.
MTCam Jul 12, 2021
e766f75
Remove y1 compatibility changes
MTCam Jul 13, 2021
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
11 changes: 8 additions & 3 deletions examples/autoignition-mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@
generate_and_distribute_mesh,
ExactSolutionMismatch
)
from mirgecom.inviscid import get_inviscid_cfl
from mirgecom.io import make_init_message
from mirgecom.mpi import mpi_entry_point

from mirgecom.integrators import rk4_step
from mirgecom.steppers import advance_state
from mirgecom.boundary import AdiabaticSlipBoundary
from mirgecom.initializers import MixtureInitializer
from mirgecom.eos import PyrometheusMixture

import cantera
import pyrometheus as pyro

Expand Down Expand Up @@ -270,9 +271,13 @@ def my_checkpoint(step, t, dt, state):
# awful - computes potentially expensive viz quantities
# regardless of whether it is time to viz
reaction_rates = eos.get_production_rates(state)
viz_fields = [("reaction_rates", reaction_rates)]
local_cfl = get_inviscid_cfl(discr, eos=eos, dt=current_dt, cv=state)
Comment thread
inducer marked this conversation as resolved.
Outdated
viz_fields = [("reaction_rates", reaction_rates),
("cfl", local_cfl)]
from grudge.op import nodal_max
max_cfl = nodal_max(discr, "vol", local_cfl)
return sim_checkpoint(discr, visualizer, eos, cv=state,
vizname=casename, step=step,
vizname=casename, step=step, cfl=max_cfl,
t=t, dt=dt, nstatus=nstatus, nviz=nviz,
constant_cfl=constant_cfl, comm=comm,
viz_fields=viz_fields)
Expand Down
12 changes: 10 additions & 2 deletions examples/lump-mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
from mirgecom.boundary import PrescribedBoundary
from mirgecom.initializers import Lump
from mirgecom.eos import IdealSingleGas
from mirgecom.inviscid import get_inviscid_cfl


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -131,9 +132,16 @@ def my_rhs(t, state):
boundaries=boundaries, eos=eos)

def my_checkpoint(step, t, dt, state):
from grudge.op import nodal_max
local_cfl = get_inviscid_cfl(discr, eos=eos, dt=current_dt, cv=state)
max_cfl = nodal_max(discr, "vol", local_cfl)
viz_fields = [
("cfl", local_cfl)
]
return sim_checkpoint(discr, visualizer, eos, cv=state,
exact_soln=initializer, vizname=casename, step=step,
t=t, dt=dt, nstatus=nstatus, nviz=nviz,
viz_fields=viz_fields, exact_soln=initializer,
vizname=casename, step=step,
t=t, dt=dt, nstatus=nstatus, nviz=nviz, cfl=max_cfl,
exittol=exittol, constant_cfl=constant_cfl, comm=comm)

try:
Expand Down
315 changes: 315 additions & 0 deletions examples/mixture-fixed-cfl-mpi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,315 @@
"""Demonstrate combustive mixture with constant CFL mode."""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In light of the new example added to examples, I was thinking: Do we want to try to cut down the examples and only keep ones that we need for particular functionality? For example, probably don't need wave-eagar and wave-eagar-mpi? Maybe drop the other mixture-mpi.py in favor of this new one? I worry about the steadily increasing CI times, but perhaps It's not that big of a deal?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I definitely would like to see the wave stuff go. It calls very little of the mirgecom infrastructure and I think they are misleading as mirgecom examples.

Definitely would plan on merging this mixture example to the existing, or just enabling constant CFL mode optionally on all the examples too.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would personally rather see wave-eager or wave-eager-mpi get updated with the modern simutils, etc. stuff when that’s done instead of trashing them. I don’t know that we need to keep both of them though.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'd feel a lot better about the wave examples if they used an operator, and boundary data structures from mirgecom. For me, simutils is a little too driver-adjacent or surface to make the wave examples mirgecom-relevant. They just seem like grudge examples copied to the mirgecom examples dir.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Let's add a readme for the examples? I hope this can help us organize our thoughts around what can get the axe. #392


__copyright__ = """
Copyright (C) 2020 University of Illinois Board of Trustees
"""

__license__ = """
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
import logging
import numpy as np
import pyopencl as cl
import pyopencl.tools as cl_tools
from functools import partial

from meshmode.array_context import PyOpenCLArrayContext
from meshmode.dof_array import thaw
from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa
from grudge.eager import EagerDGDiscretization
from grudge.shortcuts import make_visualizer


from mirgecom.euler import euler_operator
from mirgecom.simutil import (
check_step,
generate_and_distribute_mesh,
ExactSolutionMismatch
)
from mirgecom.inviscid import (
get_inviscid_timestep,
get_inviscid_cfl
)
from mirgecom.io import make_init_message
from mirgecom.mpi import mpi_entry_point
from mirgecom.integrators import rk4_step
from mirgecom.steppers import advance_state
from mirgecom.boundary import AdiabaticSlipBoundary
from mirgecom.initializers import MixtureInitializer
from mirgecom.eos import PyrometheusMixture

import cantera
import pyrometheus as pyro

logger = logging.getLogger(__name__)


@mpi_entry_point
def main(ctx_factory=cl.create_some_context, use_leap=False):
"""Drive example."""
cl_ctx = ctx_factory()
queue = cl.CommandQueue(cl_ctx)
actx = PyOpenCLArrayContext(queue,
allocator=cl_tools.MemoryPool(cl_tools.ImmediateAllocator(queue)))

dim = 2
nel_1d = 8
order = 1

# This example runs only 3 steps by default (to keep CI ~short)
# With the mixture defined below, equilibrium is achieved at ~40ms
# To run to equlibrium, set t_final >= 40ms.
t_final = 1e-7
current_cfl = 0.01
velocity = np.zeros(shape=(dim,))
current_dt = 1e-9
current_t = 0
constant_cfl = True
nstatus = 1
nviz = 2
rank = 0
checkpoint_t = current_t
current_step = 0
if use_leap:
from leap.rk import RK4MethodBuilder
timestepper = RK4MethodBuilder("state")
else:
timestepper = rk4_step
box_ll = -0.005
box_ur = 0.005
error_state = False
debug = False

from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()

from meshmode.mesh.generation import generate_regular_rect_mesh
generate_mesh = partial(generate_regular_rect_mesh, a=(box_ll,) * dim,
b=(box_ur,) * dim, nelements_per_axis=(nel_1d,) * dim)
local_mesh, global_nelements = generate_and_distribute_mesh(comm, generate_mesh)
local_nelements = local_mesh.nelements

discr = EagerDGDiscretization(
actx, local_mesh, order=order, mpi_communicator=comm
)
nodes = thaw(actx, discr.nodes())

# {{{ Set up initial state using Cantera

# Use Cantera for initialization
# -- Pick up a CTI for the thermochemistry config
# --- Note: Users may add their own CTI file by dropping it into
# --- mirgecom/mechanisms alongside the other CTI files.
from mirgecom.mechanisms import get_mechanism_cti
mech_cti = get_mechanism_cti("uiuc")

cantera_soln = cantera.Solution(phase_id="gas", source=mech_cti)
nspecies = cantera_soln.n_species

# Initial temperature, pressure, and mixutre mole fractions are needed to
# set up the initial state in Cantera.
init_temperature = 1500.0 # Initial temperature hot enough to burn
# Parameters for calculating the amounts of fuel, oxidizer, and inert species
equiv_ratio = 1.0
ox_di_ratio = 0.21
stoich_ratio = 3.0
# Grab the array indices for the specific species, ethylene, oxygen, and nitrogen
i_fu = cantera_soln.species_index("C2H4")
i_ox = cantera_soln.species_index("O2")
i_di = cantera_soln.species_index("N2")
x = np.zeros(nspecies)
# Set the species mole fractions according to our desired fuel/air mixture
x[i_fu] = (ox_di_ratio*equiv_ratio)/(stoich_ratio+ox_di_ratio*equiv_ratio)
x[i_ox] = stoich_ratio*x[i_fu]/equiv_ratio
x[i_di] = (1.0-ox_di_ratio)*x[i_ox]/ox_di_ratio
# Uncomment next line to make pylint fail when it can't find cantera.one_atm
one_atm = cantera.one_atm # pylint: disable=no-member
# one_atm = 101325.0

# Let the user know about how Cantera is being initilized
print(f"Input state (T,P,X) = ({init_temperature}, {one_atm}, {x}")
# Set Cantera internal gas temperature, pressure, and mole fractios
cantera_soln.TPX = init_temperature, one_atm, x
# Pull temperature, total density, mass fractions, and pressure from Cantera
# We need total density, and mass fractions to initialize the fluid/gas state.
can_t, can_rho, can_y = cantera_soln.TDY
can_p = cantera_soln.P
# *can_t*, *can_p* should not differ (significantly) from user's initial data,
# but we want to ensure that we use exactly the same starting point as Cantera,
# so we use Cantera's version of these data.

# }}}

# {{{ Create Pyrometheus thermochemistry object & EOS

# Create a Pyrometheus EOS with the Cantera soln. Pyrometheus uses Cantera and
# generates a set of methods to calculate chemothermomechanical properties and
# states for this particular mechanism.
casename = "mixture-adaptive"
pyrometheus_mechanism = pyro.get_thermochem_class(cantera_soln)(actx.np)
eos = PyrometheusMixture(pyrometheus_mechanism,
temperature_guess=init_temperature)

# }}}

# {{{ MIRGE-Com state initialization

# Initialize the fluid/gas state with Cantera-consistent data:
# (density, pressure, temperature, mass_fractions)
print(f"Cantera state (rho,T,P,Y) = ({can_rho}, {can_t}, {can_p}, {can_y}")
initializer = MixtureInitializer(dim=dim, nspecies=nspecies,
pressure=can_p, temperature=can_t,
massfractions=can_y, velocity=velocity)

my_boundary = AdiabaticSlipBoundary()
boundaries = {BTAG_ALL: my_boundary}
current_state = initializer(eos=eos, x_vec=nodes, t=0)

# Inspection at physics debugging time
if debug:
print("Initial MIRGE-Com state:")
print(f"{current_state=}")
print(f"Initial DV pressure: {eos.pressure(current_state)}")
print(f"Initial DV temperature: {eos.temperature(current_state)}")

# }}}

visualizer = make_visualizer(discr)
initname = initializer.__class__.__name__
eosname = eos.__class__.__name__
init_message = make_init_message(dim=dim, order=order,
nelements=local_nelements,
global_nelements=global_nelements,
dt=current_dt, t_final=t_final, nstatus=nstatus,
nviz=nviz, cfl=current_cfl,
constant_cfl=constant_cfl, initname=initname,
eosname=eosname, casename=casename)

# Cantera equilibrate calculates the expected end state @ chemical equilibrium
# i.e. the expected state after all reactions
cantera_soln.equilibrate("UV")
eq_temperature, eq_density, eq_mass_fractions = cantera_soln.TDY
eq_pressure = cantera_soln.P

# Report the expected final state to the user
if rank == 0:
logger.info(init_message)
logger.info(f"Expected equilibrium state:"
f" {eq_pressure=}, {eq_temperature=},"
f" {eq_density=}, {eq_mass_fractions=}")

def my_rhs(t, state):
return (euler_operator(discr, cv=state, t=t,
boundaries=boundaries, eos=eos)
+ eos.get_species_source_terms(state))

def mixture_prestep_function(step, t, dt, state):
do_viz = check_step(step, nviz)
viz_fields = [("cv", state)]
current_dt = dt

if constant_cfl:
local_dt = get_inviscid_timestep(discr, eos=eos, cv=state)
from grudge.op import nodal_min
current_dt = current_cfl * nodal_min(discr, "vol", local_dt)
else: # constant dt mode
if do_viz: # calculate cfl field only if visualizing
local_cfl = get_inviscid_cfl(discr, eos=eos, dt=dt, cv=state)
if do_viz: # extend viz field if viz time
# Calculate DV only if needed for visualization
dv = eos.dependent_vars(state)
viz_fields.append(("dv", dv))
# only if vizzing, calculate reaction rates
reaction_rates = eos.get_production_rates(state)
viz_fields.append(("reaction_rates", reaction_rates))
if constant_cfl:
viz_fields.append(("dt", local_dt))
else: # constant dt mode
viz_fields.append(("cfl", local_cfl))

errors = current_dt < 0 or np.isnan(current_dt) or current_dt == np.inf

if do_viz or errors: # write viz at viztime, or if there were errors
from mirgecom.io import make_rank_fname, make_par_fname
rank_fn = make_rank_fname(basename=casename, rank=rank, step=step, t=t)
visualizer.write_parallel_vtk_file(
comm, rank_fn, viz_fields, overwrite=True,
par_manifest_filename=make_par_fname(
basename=casename, step=step, t=t
)
)

if check_step(step, nstatus) or errors:
if not do_viz: # we already have dv on viz steps
dv = eos.dependent_vars(state)
from grudge.op import nodal_max
min_temperature = nodal_min(discr, "vol", dv.temperature)
max_temperature = nodal_max(discr, "vol", dv.temperature)
min_pressure = nodal_min(discr, "vol", dv.pressure)
max_pressure = nodal_max(discr, "vol", dv.pressure)
if rank == 0:
logger.info(f"\nStep:{step}, Time:{t}, DT:{current_dt},"
f"CFL:{current_cfl}\n"
f"---- P({min_pressure}, {max_pressure})\n"
f"---- T({min_temperature}, {max_temperature})\n")

# this exit is safe, errors(current_dt) is already collective
if errors:
logger.info("Fatal error: Invalid simulation DT")
import sys
sys.exit()

t_remaining = max(0, t_final - t)
return min(t_remaining, current_dt)

try:
(current_step, current_t, current_state) = \
advance_state(rhs=my_rhs, timestepper=timestepper,
checkpoint=mixture_prestep_function, state=current_state,
t=current_t, t_final=t_final)

except ExactSolutionMismatch as ex:
error_state = True
current_step = ex.step
current_t = ex.t
current_state = ex.state

if not check_step(current_step, nviz): # If final step not an output step
if rank == 0:
logger.info("Checkpointing final state ...")
mixture_prestep_function(current_step, t=current_t,
dt=(current_t - checkpoint_t),
state=current_state)

if current_t - t_final < 0:
error_state = True

if error_state:
raise ValueError("Simulation did not complete successfully.")

if rank == 0:
logger.info(f"Simulation finished at time {current_t=}.")


if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
main(use_leap=False)

# vim: foldmethod=marker
Loading