本文整理汇总了Python中util.msg.bold函数的典型用法代码示例。如果您正苦于以下问题:Python bold函数的具体用法?Python bold怎么用?Python bold使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bold函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_data
def init_data(myd, rp):
""" initialize the tophat advection problem """
msg.bold("initializing the tophat advection problem...")
# make sure that we are passed a valid patch object
if not isinstance(myd, patch.CellCenterData2d):
print("ERROR: patch invalid in tophat.py")
print(myd.__class__)
sys.exit()
dens = myd.get_var("density")
xmin = myd.grid.xmin
xmax = myd.grid.xmax
ymin = myd.grid.ymin
ymax = myd.grid.ymax
xctr = 0.5*(xmin + xmax)
yctr = 0.5*(ymin + ymax)
dens[:, :] = 0.0
R = 0.1
inside = (myd.grid.x2d - xctr)**2 + (myd.grid.y2d - yctr)**2 < R**2
dens[inside] = 1.0
示例2: init_data
def init_data(my_data, rp):
""" initialize the rt problem """
msg.bold("initializing the rt problem...")
# make sure that we are passed a valid patch object
if not isinstance(my_data, patch.CellCenterData2d):
print("ERROR: patch invalid in rt.py")
print(my_data.__class__)
sys.exit()
# get the density, momenta, and energy as separate variables
dens = my_data.get_var("density")
xmom = my_data.get_var("x-momentum")
ymom = my_data.get_var("y-momentum")
ener = my_data.get_var("energy")
gamma = rp.get_param("eos.gamma")
grav = rp.get_param("compressible.grav")
dens1 = rp.get_param("rt.dens1")
dens2 = rp.get_param("rt.dens2")
p0 = rp.get_param("rt.p0")
amp = rp.get_param("rt.amp")
sigma = rp.get_param("rt.sigma")
# initialize the components, remember, that ener here is
# rho*eint + 0.5*rho*v**2, where eint is the specific
# internal energy (erg/g)
xmom[:, :] = 0.0
ymom[:, :] = 0.0
dens[:, :] = 0.0
# set the density to be stratified in the y-direction
myg = my_data.grid
ycenter = 0.5*(myg.ymin + myg.ymax)
p = myg.scratch_array()
j = myg.jlo
while j <= myg.jhi:
if (myg.y[j] < ycenter):
dens[:, j] = dens1
p[:, j] = p0 + dens1*grav*myg.y[j]
else:
dens[:, j] = dens2
p[:, j] = p0 + dens1*grav*ycenter + dens2*grav*(myg.y[j] - ycenter)
j += 1
ymom[:, :] = amp*np.cos(2.0*np.pi*myg.x2d/(myg.xmax-myg.xmin))*np.exp(-(myg.y2d-ycenter)**2/sigma**2)
ymom *= dens
# set the energy (P = cs2*dens)
ener[:, :] = p[:, :]/(gamma - 1.0) + \
0.5*(xmom[:, :]**2 + ymom[:, :]**2)/dens[:, :]
示例3: init_data
def init_data(my_data, rp):
""" initialize the tophat advection problem """
msg.bold("initializing the tophat advection problem...")
# make sure that we are passed a valid patch object
if not isinstance(my_data, patch.CellCenterData2d):
print("ERROR: patch invalid in tophat.py")
print(my_data.__class__)
sys.exit()
dens = my_data.get_var("density")
xmin = my_data.grid.xmin
xmax = my_data.grid.xmax
ymin = my_data.grid.ymin
ymax = my_data.grid.ymax
xctr = 0.5*(xmin + xmax)
yctr = 0.5*(ymin + ymax)
dens[:,:] = 0.0
for i in range(my_data.grid.ilo, my_data.grid.ihi+1):
for j in range(my_data.grid.jlo, my_data.grid.jhi+1):
if (numpy.sqrt((my_data.grid.x[i]-xctr)**2 +
(my_data.grid.y[j]-yctr)**2) < 0.1):
dens[i,j] = 1.0
示例4: __init__
def __init__(self, solver_name):
"""
Constructor
Parameters
----------
solver_name : str
Name of solver to use
"""
msg.bold('pyro ...')
if solver_name not in valid_solvers:
msg.fail("ERROR: %s is not a valid solver" % solver_name)
self.pyro_home = os.path.dirname(os.path.realpath(__file__)) + '/'
# import desired solver under "solver" namespace
self.solver = importlib.import_module(solver_name)
self.solver_name = solver_name
# -------------------------------------------------------------------------
# runtime parameters
# -------------------------------------------------------------------------
# parameter defaults
self.rp = runparams.RuntimeParameters()
self.rp.load_params(self.pyro_home + "_defaults")
self.rp.load_params(self.pyro_home + solver_name + "/_defaults")
self.tc = profile.TimerCollection()
self.is_initialized = False
示例5: init_data
def init_data(my_data, rp):
""" initialize the smooth advection problem """
msg.bold("initializing the smooth advection problem...")
# make sure that we are passed a valid patch object
if not isinstance(my_data, patch.CellCenterData2d):
print("ERROR: patch invalid in smooth.py")
print(my_data.__class__)
sys.exit()
dens = my_data.get_var("density")
xmin = my_data.grid.xmin
xmax = my_data.grid.xmax
ymin = my_data.grid.ymin
ymax = my_data.grid.ymax
xctr = 0.5*(xmin + xmax)
yctr = 0.5*(ymin + ymax)
i = my_data.grid.ilo
while i <= my_data.grid.ihi:
j = my_data.grid.jlo
while j <= my_data.grid.jhi:
dens[i,j] = 1.0 + numpy.exp(-60.0*((my_data.grid.x[i]-xctr)**2 + \
(my_data.grid.y[j]-yctr)**2))
j += 1
i += 1
示例6: initData
def initData(my_data):
""" initialize the incompressible shear problem """
msg.bold("initializing the incompressible shear problem...")
rp = my_data.rp
# make sure that we are passed a valid patch object
if not isinstance(my_data, patch.CellCenterData2d):
print my_data.__class__
msg.fail("ERROR: patch invalid in shear.py")
# get the necessary runtime parameters
rho_s = rp.get_param("shear.rho_s")
delta_s = rp.get_param("shear.delta_s")
# get the velocities
u = my_data.get_var("x-velocity")
v = my_data.get_var("y-velocity")
myg = my_data.grid
if (myg.xmin != 0 or myg.xmax != 1 or
myg.ymin != 0 or myg.ymax != 1):
msg.fail("ERROR: domain should be a unit square")
y_half = 0.5*(myg.ymin + myg.ymax)
print 'y_half = ', y_half
print 'delta_s = ', delta_s
print 'rho_s = ', rho_s
# there is probably an easier way to do this without loops, but
# for now, we will just do an explicit loop.
i = myg.ilo
while i <= myg.ihi:
j = myg.jlo
while j <= myg.jhi:
if (myg.y[j] <= y_half):
u[i,j] = numpy.tanh(rho_s*(myg.y[j] - 0.25))
else:
u[i,j] = numpy.tanh(rho_s*(0.75 - myg.y[j]))
v[i,j] = delta_s*numpy.sin(2.0*math.pi*myg.x[i])
j += 1
i += 1
print "extrema: ", numpy.min(u.flat), numpy.max(u.flat)
示例7: init_data
def init_data(my_data, rp):
""" initialize the HSE problem """
msg.bold("initializing the HSE problem...")
# make sure that we are passed a valid patch object
if not isinstance(my_data, patch.CellCenterData2d):
print("ERROR: patch invalid in hse.py")
print(my_data.__class__)
sys.exit()
# get the density, momenta, and energy as separate variables
dens = my_data.get_var("density")
xmom = my_data.get_var("x-momentum")
ymom = my_data.get_var("y-momentum")
ener = my_data.get_var("energy")
gamma = rp.get_param("eos.gamma")
grav = rp.get_param("compressible.grav")
dens0 = rp.get_param("hse.dens0")
print("dens0 = ", dens0)
H = rp.get_param("hse.h")
# isothermal sound speed (squared)
cs2 = H*abs(grav)
# initialize the components, remember, that ener here is
# rho*eint + 0.5*rho*v**2, where eint is the specific
# internal energy (erg/g)
xmom[:, :] = 0.0
ymom[:, :] = 0.0
dens[:, :] = 0.0
# set the density to be stratified in the y-direction
myg = my_data.grid
p = myg.scratch_array()
for j in range(myg.jlo, myg.jhi+1):
dens[:, j] = dens0*np.exp(-myg.y[j]/H)
if j == myg.jlo:
p[:, j] = dens[:, j]*cs2
else:
p[:, j] = p[:, j-1] + 0.5*myg.dy*(dens[:, j] + dens[:, j-1])*grav
# set the energy
ener[:, :] = p[:, :]/(gamma - 1.0) + \
0.5*(xmom[:, :]**2 + ymom[:, :]**2)/dens[:, :]
示例8: init_data
def init_data(my_data, rp):
""" initialize a smooth advection problem for testing convergence """
msg.bold("initializing the advect problem...")
# make sure that we are passed a valid patch object
if not isinstance(my_data, patch.CellCenterData2d):
print("ERROR: patch invalid in advect.py")
print(my_data.__class__)
sys.exit()
# get the density, momenta, and energy as separate variables
dens = my_data.get_var("density")
xmom = my_data.get_var("x-momentum")
ymom = my_data.get_var("y-momentum")
ener = my_data.get_var("energy")
# initialize the components, remember, that ener here is rho*eint
# + 0.5*rho*v**2, where eint is the specific internal energy
# (erg/g)
dens.d[:,:] = 1.0
xmom.d[:,:] = 0.0
ymom.d[:,:] = 0.0
gamma = rp.get_param("eos.gamma")
xmin = rp.get_param("mesh.xmin")
xmax = rp.get_param("mesh.xmax")
ymin = rp.get_param("mesh.ymin")
ymax = rp.get_param("mesh.ymax")
xctr = 0.5*(xmin + xmax)
yctr = 0.5*(ymin + ymax)
# this is identical to the advection/smooth problem
dens.d[:,:] = 1.0 + np.exp(-60.0*((my_data.grid.x2d-xctr)**2 +
(my_data.grid.y2d-yctr)**2))
# velocity is diagonal
u = 1.0
v = 1.0
xmom.d[:,:] = dens.d[:,:]*u
ymom.d[:,:] = dens.d[:,:]*v
# pressure is constant
p = 1.0
ener.d[:,:] = p/(gamma - 1.0) + 0.5*(xmom.d[:,:]**2 + ymom.d[:,:]**2)/dens.d[:,:]
示例9: init_data
def init_data(my_data, rp):
""" initialize the incompressible shear problem """
msg.bold("initializing the incompressible shear problem...")
# make sure that we are passed a valid patch object
if not isinstance(my_data, patch.CellCenterData2d):
print(my_data.__class__)
msg.fail("ERROR: patch invalid in shear.py")
# get the necessary runtime parameters
eps = rp.get_param("vortex.eps")
print('eps = ', eps)
# get the velocities
u = my_data.get_var("x-velocity")
v = my_data.get_var("y-velocity")
myg = my_data.grid
u.d[:,:] = -np.sin(math.pi*myg.y2d)
v.d[:,:] = np.sin(math.pi*myg.x2d)
#u.d[:,:] = -np.sin(2.0*math.pi*myg.x2d)*np.cos(2.0*math.pi*myg.y2d)*ran
#v.d[:,:] = np.cos(2.0*math.pi*myg.x2d)*np.sin(2.0*math.pi*myg.y2d)*ran
if eps != 0.0:
#perturbed velocity1 at (0,0)
r2 = myg.x2d**2+myg.y2d**2
dvx1l = -eps**3*myg.y2d/r2*(1-np.exp(-r2/eps**2))
dvy1l = eps**3*myg.x2d/r2*(1-np.exp(-r2/eps**2))
#perturbed velocity1 at (2pi,0)
r2 = (myg.x2d - 2.0)**2+myg.y2d**2
dvx1r = -eps**3*myg.y2d/r2*(1-np.exp(-r2/eps**2))
dvy1r = eps**3*(myg.x2d-2.0)/r2*(1-np.exp(-r2/eps**2))
#perturbed velocity2 at (pi,0)
r2 = (myg.x2d - 1.0)**2+myg.y2d**2
dvx2 = eps**3*myg.y2d/r2*(1-np.exp(-r2/eps**2))
dvy2 = -eps**3*(myg.x2d-1.0)/r2*(1-np.exp(-r2/eps**2))
u.d[:,:] = u.d[:,:] + dvx1l + dvx1r + dvx2
v.d[:,:] = v.d[:,:] + dvy1l + dvy1r + dvy2
print("extrema: ", u.min(), u.max())
示例10: init_data
def init_data(myd, rp):
"""initialize the acoustic_pulse problem. This comes from
McCourquodale & Coella 2011"""
msg.bold("initializing the acoustic pulse problem...")
# make sure that we are passed a valid patch object
if not isinstance(myd, fv.FV2d):
print("ERROR: patch invalid in acoustic_pulse.py")
print(myd.__class__)
sys.exit()
# get the density, momenta, and energy as separate variables
dens = myd.get_var("density")
xmom = myd.get_var("x-momentum")
ymom = myd.get_var("y-momentum")
ener = myd.get_var("energy")
# initialize the components, remember, that ener here is rho*eint
# + 0.5*rho*v**2, where eint is the specific internal energy
# (erg/g)
xmom[:, :] = 0.0
ymom[:, :] = 0.0
gamma = rp.get_param("eos.gamma")
rho0 = rp.get_param("acoustic_pulse.rho0")
drho0 = rp.get_param("acoustic_pulse.drho0")
xmin = rp.get_param("mesh.xmin")
xmax = rp.get_param("mesh.xmax")
ymin = rp.get_param("mesh.ymin")
ymax = rp.get_param("mesh.ymax")
xctr = 0.5*(xmin + xmax)
yctr = 0.5*(ymin + ymax)
dist = np.sqrt((myd.grid.x2d - xctr)**2 +
(myd.grid.y2d - yctr)**2)
dens[:, :] = rho0
idx = dist <= 0.5
dens[idx] = rho0 + drho0*np.exp(-16*dist[idx]**2) * np.cos(np.pi*dist[idx])**6
p = (dens/rho0)**gamma
ener[:, :] = p/(gamma - 1)
示例11: init_data
def init_data(my_data, rp):
""" initialize the slotted advection problem """
msg.bold("initializing the slotted advection problem...")
# make sure that we are passed a valid patch object
if not isinstance(my_data, patch.CellCenterData2d):
print(my_data.__class__)
msg.fail("ERROR: patch invalid in slotted.py")
offset = rp.get_param("slotted.offset")
omega = rp.get_param("slotted.omega")
myg = my_data.grid
xctr_dens = 0.5*(myg.xmin + myg.xmax)
yctr_dens = 0.5*(myg.ymin + myg.ymax) + offset
# setting initial condition for density
dens = my_data.get_var("density")
dens[:, :] = 0.0
R = 0.15
slot_width = 0.05
inside = (myg.x2d - xctr_dens)**2 + (myg.y2d - yctr_dens)**2 < R**2
slot_x = np.logical_and(myg.x2d > (xctr_dens - slot_width*0.5),
myg.x2d < (xctr_dens + slot_width*0.5))
slot_y = np.logical_and(myg.y2d > (yctr_dens - R),
myg.y2d < (yctr_dens))
slot = np.logical_and(slot_x, slot_y)
dens[inside] = 1.0
dens[slot] = 0.0
# setting initial condition for velocity
u = my_data.get_var("x-velocity")
v = my_data.get_var("y-velocity")
u[:, :] = omega*(myg.y2d - xctr_dens)
v[:, :] = -omega*(myg.x2d - (yctr_dens-offset))
print("extrema: ", np.amax(u), np.amin(u))
示例12: init_data
def init_data(my_data, rp):
""" initialize the incompressible shear problem """
msg.bold("initializing the incompressible shear problem...")
# make sure that we are passed a valid patch object
if not isinstance(my_data, patch.CellCenterData2d):
print(my_data.__class__)
msg.fail("ERROR: patch invalid in shear.py")
# get the necessary runtime parameters
rho_s = rp.get_param("shear.rho_s")
delta_s = rp.get_param("shear.delta_s")
# get the velocities
u = my_data.get_var("x-velocity")
v = my_data.get_var("y-velocity")
myg = my_data.grid
if (myg.xmin != 0 or myg.xmax != 1 or
myg.ymin != 0 or myg.ymax != 1):
msg.fail("ERROR: domain should be a unit square")
y_half = 0.5*(myg.ymin + myg.ymax)
print('y_half = ', y_half)
print('delta_s = ', delta_s)
print('rho_s = ', rho_s)
idx = myg.y2d <= y_half
u.d[idx] = np.tanh(rho_s*(myg.y2d[idx] - 0.25))
idx = myg.y2d > y_half
u.d[idx] = np.tanh(rho_s*(0.75 - myg.y2d[idx]))
v.d[:,:] = delta_s*np.sin(2.0*math.pi*myg.x2d)
print("extrema: ", u.min(), u.max())
示例13: init_data
def init_data(my_data, rp):
""" initialize the incompressible converge problem """
msg.bold("initializing the incompressible converge problem...")
# make sure that we are passed a valid patch object
if not isinstance(my_data, patch.CellCenterData2d):
print(my_data.__class__)
msg.fail("ERROR: patch invalid in converge.py")
# get the velocities
u = my_data.get_var("x-velocity")
v = my_data.get_var("y-velocity")
myg = my_data.grid
if (myg.xmin != 0 or myg.xmax != 1 or
myg.ymin != 0 or myg.ymax != 1):
msg.fail("ERROR: domain should be a unit square")
u[:, :] = 1.0 - 2.0*np.cos(2.0*math.pi*myg.x2d)*np.sin(2.0*math.pi*myg.y2d)
v[:, :] = 1.0 + 2.0*np.sin(2.0*math.pi*myg.x2d)*np.cos(2.0*math.pi*myg.y2d)
示例14: initData
def initData(my_data):
""" initialize the Gaussian diffusion problem """
msg.bold("initializing the Gaussian diffusion problem...")
rp = my_data.rp
# make sure that we are passed a valid patch object
if not isinstance(my_data, patch.CellCenterData2d):
print "ERROR: patch invalid in diffuse.py"
print my_data.__class__
sys.exit()
phi = my_data.get_var("phi")
xmin = my_data.grid.xmin
xmax = my_data.grid.xmax
ymin = my_data.grid.ymin
ymax = my_data.grid.ymax
xctr = 0.5*(xmin + xmax)
yctr = 0.5*(ymin + ymax)
k = rp.get_param("diffusion.k")
t_0 = rp.get_param("gaussian.t_0")
phi_max = rp.get_param("gaussian.phi_max")
phi_0 = rp.get_param("gaussian.phi_0")
dist = numpy.sqrt((my_data.grid.x2d - xctr)**2 +
(my_data.grid.y2d - yctr)**2)
phi[:,:] = phi_analytic(dist, 0.0, t_0, k, phi_0, phi_max)
# for later interpretation / analysis, store some auxillary data
my_data.set_aux("k", k)
my_data.set_aux("t_0", t_0)
my_data.set_aux("phi_0", phi_0)
my_data.set_aux("phi_max", phi_max)
示例15: init_data
def init_data(my_data, rp):
""" initialize the smooth advection problem """
msg.bold("initializing the smooth FV advection problem...")
# make sure that we are passed a valid patch object
# if not isinstance(my_data, patch.FV2d):
# print("ERROR: patch invalid in smooth.py")
# print(my_data.__class__)
# sys.exit()
xmin = my_data.grid.xmin
xmax = my_data.grid.xmax
ymin = my_data.grid.ymin
ymax = my_data.grid.ymax
xctr = 0.5*(xmin + xmax)
yctr = 0.5*(ymin + ymax)
# we need to initialize the cell-averages, so we will create
# a finer grid, initialize it, and then average down
mgf = my_data.grid.fine_like(4)
# since restrict operates in the data class, we need to
# create a FV2d object here
fine_data = fv.FV2d(mgf)
fine_data.register_var("density", my_data.BCs["density"])
fine_data.create()
dens_fine = fine_data.get_var("density")
dens_fine[:, :] = 1.0 + numpy.exp(-60.0*((mgf.x2d-xctr)**2 +
(mgf.y2d-yctr)**2))
dens = my_data.get_var("density")
dens[:, :] = fine_data.restrict("density", N=4)