Last active
January 14, 2023 23:02
-
-
Save tai271828/d5f50e4a06274b1203ed79f6739039dd to your computer and use it in GitHub Desktop.
Example to run profiling jobs for modmesh
This file contains 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
# Copyright (c) 2023, Taihsiang Ho <[email protected]> | |
# | |
# Redistribution and use in source and binary forms, with or without | |
# modification, are permitted provided that the following conditions are met: | |
# | |
# - Redistributions of source code must retain the above copyright notice, this | |
# list of conditions and the following disclaimer. | |
# - Redistributions in binary form must reproduce the above copyright notice, | |
# this list of conditions and the following disclaimer in the documentation | |
# and/or other materials provided with the distribution. | |
# - Neither the name of the copyright holder nor the names of its contributors | |
# may be used to endorse or promote products derived from this software | |
# without specific prior written permission. | |
# | |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
# POSSIBILITY OF SUCH DAMAGE. | |
__package__ = "modmesh.app" | |
import sys | |
import modmesh | |
import modmesh.onedim.euler1d | |
from modmesh.app.euler1d import QuantityLine, Plot, Controller | |
from PySide6.QtWidgets import QApplication | |
class Controller(modmesh.app.euler1d.Controller): | |
def __init__(self, shocktube, max_steps, use_sub=None): | |
super().__init__(shocktube, max_steps, use_sub=None) | |
@staticmethod | |
def log(msg): | |
sys.stdout.write(msg) | |
sys.stdout.write("\n") | |
def run(interval=10, max_steps=50, **kw): | |
st = modmesh.onedim.euler1d.ShockTube() | |
st.build_constant( | |
gamma=1.4, pressure1=1.0, density1=1.0, pressure5=0.1, density5=0.125 | |
) | |
st.build_numerical(xmin=-10, xmax=10, ncoord=201, time_increment=0.05) | |
ctrl = Controller(shocktube=st, max_steps=max_steps, **kw) | |
ctrl.setup_solver(interval) | |
ctrl.show() | |
return ctrl | |
app = QApplication() | |
ctrl = run(interval=10, max_steps=50) | |
ctrl.start() | |
app.exec() | |
print(modmesh.time_registry.report()) | |
# vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4: |
This file contains 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
#!/usr/bin/env python3 | |
import modmesh as mm | |
from modmesh.onedim import euler1d | |
from _modmesh import stop_watch | |
shock_tube = euler1d.ShockTube() | |
shock_tube.build_constant( | |
gamma=1.4, | |
pressure1=1.0, | |
density1=1.0, | |
pressure5=0.1, | |
density5=0.125, | |
) | |
shock_tube.build_numerical(xmin=-1, xmax=1, ncoord=21, time_increment=0.05) | |
# reset lap | |
stop_watch.lap() | |
shock_tube.calc_velocity2(0, 10) | |
print(f"calc_velocity2: \t{stop_watch.lap()}") | |
# reset lap | |
stop_watch.lap() | |
shock_tube.build_field(t=10) | |
print(f"build_field t=10:\t{stop_watch.lap()}") | |
# reset lap | |
stop_watch.lap() | |
shock_tube.build_field(t=100) | |
print(f"build_field t=100:\t{stop_watch.lap()}") | |
print(mm.time_registry.report()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment