Skip to content

Commit e66505c

Browse files
Merge pull request #373 from nauaneed/minor-fixes
Minor fixes and enhancements
2 parents 2660af4 + 4f74095 commit e66505c

File tree

5 files changed

+63
-32
lines changed

5 files changed

+63
-32
lines changed

pysph/examples/gas_dynamics/shocktube.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,15 @@
3636
# domain size
3737
xmin = 0.
3838
xmax = 1
39-
dx = 0.002
40-
ny = 50
4139
ymin = 0
42-
ymax = ny * dx
43-
x0 = 0.5 # initial discontuinity
40+
ymax = 0.1
41+
x0 = 0.5 # initial discontinuity
4442

4543
# scheme constants
4644
alpha1 = 1.0
4745
alpha2 = 1.0
4846
beta = 2.0
4947
kernel_factor = 1.5
50-
h0 = kernel_factor * dx
5148

5249

5350
class ShockTube2D(Application):
@@ -56,10 +53,8 @@ def initialize(self):
5653
self.xmax = xmax
5754
self.ymin = ymin
5855
self.ymax = ymax
59-
self.dx = dx
6056
self.hdx = 1.7
6157
self.x0 = x0
62-
self.ny = ny
6358
self.pl = 1000
6459
self.pr = 0.01
6560
self.rhol = 1.0
@@ -72,17 +67,22 @@ def initialize(self):
7267
def add_user_options(self, group):
7368
add_bool_argument(group, 'smooth-ic', dest='smooth_ic', default=False,
7469
help="Smooth the initial condition.")
70+
group.add_argument(
71+
"--dx", action="store", type=float, dest="dx",
72+
default=0.002, help="Particle spacing"
73+
)
7574

7675
def consume_user_options(self):
7776
self.smooth_ic = self.options.smooth_ic
77+
self.dx = self.options.dx
7878

7979
def create_domain(self):
8080
return DomainManager(
8181
xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
8282
periodic_in_x=True, periodic_in_y=True)
8383

8484
def create_particles(self):
85-
global dx
85+
dx = self.dx
8686
data = ud.uniform_distribution_cubic2D(dx, xmin, xmax, ymin, ymax)
8787

8888
x = data[0]
@@ -110,7 +110,7 @@ def create_particles(self):
110110
p[right_indices] = self.pr
111111

112112
# const h and mass
113-
h = numpy.ones_like(x) * self.hdx * self.dx
113+
h = numpy.ones_like(x) * self.hdx * dx
114114
m = numpy.ones_like(x) * volume * rho
115115

116116
# ul = ur = 0

pysph/sph/gas_dynamics/magma2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ def loop(self, d_idx, s_m, s_idx, XIJ, s_rho, d_cm, WI):
708708
drowcol = dsi2 + row * dim + col
709709
d_cm[drowcol] += mbbyrhob * XIJ[row] * XIJ[col] * WI
710710

711-
def post_loop(self, d_idx, d_dv, d_divv, d_cm):
711+
def post_loop(self, d_idx, d_cm):
712712
invcm, cm, idmat = declare('matrix(9)', 3)
713713
augcm = declare('matrix(18)')
714714
dsi2, row, col, rowcol, dim, dimsq = declare('int', 6)
@@ -926,7 +926,7 @@ def post_loop(self, d_h, d_idx, d_cs, d_alpha, d_s, d_p, d_rho, dt,
926926
class WallBoundary(Equation):
927927
""":class:`WallBoundary
928928
<pysph.sph.gas_dynamics.boundary_equations.WallBoundary>` modified
929-
for GADGET2.
929+
for MAGMA2.
930930
"""
931931

932932
def __init__(self, dest, sources, dim):
@@ -1058,7 +1058,7 @@ def post_loop(self, d_idx, d_p, d_rho, d_e, d_m, d_cs, d_divv, d_h, d_u,
10581058
class UpdateGhostProps(Equation):
10591059
"""
10601060
:class:`MPMUpdateGhostProps
1061-
<pysph.sph.gas_dynamics.basic.MPMUpdateGhostProps>` modified for GADGET2.
1061+
<pysph.sph.gas_dynamics.basic.MPMUpdateGhostProps>` modified for MAGMA2.
10621062
"""
10631063

10641064
def __init__(self, dest, dim, sources=None):

pysph/sph/gas_dynamics/psph.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,9 @@ def get_equations(self):
201201
dest=fluid, sources=all_pa, hfact=self.hfact,
202202
density_iterations=True, dim=self.dim,
203203
htol=self.density_iteration_tolerance, gamma=self.gamma))
204-
equations.append(
205-
Group(equations=g1, update_nnps=True, iterate=True,
206-
max_iterations=self.max_density_iterations))
204+
equations.append(
205+
Group(equations=g1, update_nnps=True, iterate=True,
206+
max_iterations=self.max_density_iterations))
207207

208208
g2 = []
209209
for fluid in self.fluids:

pysph/sph/gas_dynamics/tsph.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ def get_equations(self):
161161
dest=fluid, sources=all_pa, hfact=self.hfact,
162162
density_iterations=True, dim=self.dim,
163163
htol=self.density_iteration_tolerance))
164-
equations.append(Group(
165-
equations=g1, update_nnps=True, iterate=True,
166-
max_iterations=self.max_density_iterations))
164+
equations.append(Group(
165+
equations=g1, update_nnps=True, iterate=True,
166+
max_iterations=self.max_density_iterations))
167167

168168
g2 = []
169169
for fluid in self.fluids:

pysph/sph/scheme.py

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,8 +1171,8 @@ def __init__(self, fluids, solids, dim, gamma, kernel_factor, g1=0.0,
11711171
monotonicity : int
11721172
Type of monotonicity algorithm to use:
11731173
0 : First order GSPH
1174-
1 : I02 algorithm
1175-
2 : IwIn algorithm
1174+
1 : I02 algorithm # https://doi.org/10.1006/jcph.2002.7053
1175+
2 : IwIn algorithm # https://doi.org/10.1111/j.1365-2966.2011.19588.x # noqa: E501
11761176
interface_zero : bool
11771177
Set Interface position s^*_{ij} = 0 for the Riemann problem.
11781178
hybrid, blend_alpha : bool, double
@@ -1204,22 +1204,42 @@ def __init__(self, fluids, solids, dim, gamma, kernel_factor, g1=0.0,
12041204
self.niter = niter
12051205
self.tol = tol
12061206
self.has_ghosts = has_ghosts
1207+
self.rsolver_choices = {'non_diffusive': 0,
1208+
'van_leer': 1,
1209+
'exact': 2,
1210+
'hllc': 3,
1211+
'ducowicz': 4,
1212+
'hlle': 5,
1213+
'roe': 6,
1214+
'llxf': 7,
1215+
'hllc_ball': 8,
1216+
'hll_ball': 9,
1217+
'hllsy': 10}
1218+
self.interpolation_choices = {'delta': 0,
1219+
'linear': 1,
1220+
'cubic': 2}
1221+
self.monotonicity_choices = {'first_order': 0,
1222+
'i02': 1,
1223+
'iwin': 2}
12071224

12081225
def add_user_options(self, group):
12091226
group.add_argument(
1210-
"--rsolver", action="store", type=int, dest="rsolver",
1211-
default=None,
1212-
help="Riemann solver to use."
1227+
"--rsolver", action="store", type=str, dest="rsolver",
1228+
default=None, choices=set(self.rsolver_choices.keys()),
1229+
help=f"Riemann solver to use, one of :"
1230+
f"{set(self.rsolver_choices.keys())}"
12131231
)
12141232
group.add_argument(
1215-
"--interpolation", action="store", type=int, dest="interpolation",
1216-
default=None,
1217-
help="Interpolation algorithm to use."
1233+
"--interpolation", action="store", type=str, dest="interpolation",
1234+
default=None, choices=set(self.interpolation_choices.keys()),
1235+
help=f"Interpolation algorithm to use, one of :"
1236+
f"{set(self.interpolation_choices.keys())}"
12181237
)
12191238
group.add_argument(
1220-
"--monotonicity", action="store", type=int, dest="monotonicity",
1221-
default=None,
1222-
help="Monotonicity algorithm to use."
1239+
"--monotonicity", action="store", type=str, dest="monotonicity",
1240+
default=None, choices=set(self.monotonicity_choices.keys()),
1241+
help=f"Monotonicity algorithm to use, one of :"
1242+
f"{set(self.monotonicity_choices.keys())}"
12231243
)
12241244
group.add_argument(
12251245
"--g1", action="store", type=float, dest="g1",
@@ -1253,13 +1273,24 @@ def add_user_options(self, group):
12531273
)
12541274

12551275
def consume_user_options(self, options):
1256-
vars = ['gamma', 'g1', 'g2', 'rsolver', 'interpolation',
1257-
'monotonicity', 'interface_zero', 'hybrid',
1258-
'blend_alpha']
1276+
vars = ['gamma', 'g1', 'g2', 'interface_zero',
1277+
'hybrid', 'blend_alpha']
12591278
data = dict((var, self._smart_getattr(options, var))
12601279
for var in vars)
1280+
map_vars = ['monotonicity', 'rsolver', 'interpolation']
1281+
for var in map_vars:
1282+
data[var] = self._smart_getattr_mapped(options, var)
12611283
self.configure(**data)
12621284

1285+
def _smart_getattr_mapped(self, obj, var):
1286+
res = getattr(obj, var)
1287+
if res is None:
1288+
return getattr(self, var)
1289+
else:
1290+
choices = getattr(self, f'{var}_choices')
1291+
return choices[res]
1292+
1293+
12631294
def configure_solver(self, kernel=None, integrator_cls=None,
12641295
extra_steppers=None, **kw):
12651296
"""Configure the solver to be generated.

0 commit comments

Comments
 (0)