Skip to content

Commit 9f497fa

Browse files
authored
add dloga in grid (#298)
adds dloga in grid, mainly used for primitive geometric terms later
1 parent fdc1e59 commit 9f497fa

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

pyro/mesh/patch.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,13 @@ def __init__(self, nx, ny, *, ng=1,
220220

221221
self.Ay = self.Lx
222222

223+
# Spatial derivative of log(area). It's zero for Cartesian
224+
225+
self.dlogAx = ArrayIndexer(np.zeros_like(self.Ax),
226+
grid=self)
227+
self.dlogAy = ArrayIndexer(np.zeros_like(self.Ay),
228+
grid=self)
229+
223230
# Volume of the cell.
224231

225232
self.V = ArrayIndexer(np.full((self.qx, self.qy), self.dx * self.dy),
@@ -235,7 +242,9 @@ def __str__(self):
235242
class SphericalPolar(Grid2d):
236243
"""
237244
This class defines a spherical polar grid.
238-
This is technically a 2D geometry but assumes azimuthal symmetry.
245+
This is technically a 3D geometry but assumes azimuthal symmetry,
246+
and zero velocity in phi-direction.
247+
Hence 2D.
239248
240249
Define:
241250
r = x
@@ -279,6 +288,12 @@ def __init__(self, nx, ny, *, ng=1,
279288
self.Ay = np.abs(np.pi * np.sin(self.yl2d) *
280289
(self.xr2d**2 - self.xl2d**2))
281290

291+
# dlogAx = 1 / r^2 d( r^2 ) / dr = 2 / r
292+
self.dlogAx = 2.0 / self.x2d
293+
294+
# dlogAy = 1 / (r sin(theta)) d( sin(theta) )/dtheta = cot(theta) / r
295+
self.dlogAy = 1.0 / (np.tan(self.y2d) * self.x2d)
296+
282297
# Returns an array of the volume of each cell.
283298
# dV = dL_r * dL_theta * dL_phi
284299
# = (dr) * (r * dtheta) * (r * sin(theta) * dphi)

pyro/mesh/tests/test_patch.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ def test_Ax(self):
9292
def test_Ay(self):
9393
assert np.all(self.g.Ay.v() == 0.25)
9494

95+
def test_dlogAx(self):
96+
assert np.all(self.g.dlogAx.v() == 0.0)
97+
98+
def test_dlogAy(self):
99+
assert np.all(self.g.dlogAy.v() == 0.0)
100+
95101
def test_V(self):
96102
assert np.all(self.g.V.v() == 0.1 * 0.25)
97103

@@ -135,6 +141,21 @@ def test_Ay(self):
135141
(self.g.xr2d.v()**2 - self.g.xl2d.v()**2))
136142
assert_array_equal(self.g.Ay.jp(1), area_y_r)
137143

144+
def test_dlogAx(self):
145+
i = 4
146+
r = self.g.xmin + (i + 0.5 - self.g.ng) * self.g.dx
147+
dlogAx = 2.0 / r
148+
assert (self.g.dlogAx[i, :] == dlogAx).all()
149+
150+
def test_dlogAy(self):
151+
i = 4
152+
j = 6
153+
r = self.g.xmin + (i + 0.5 - self.g.ng) * self.g.dx
154+
tan = np.tan(self.g.ymin + (j + 0.5 - self.g.ng) * self.g.dy)
155+
dlogAy = 1.0 / (r * tan)
156+
157+
assert self.g.dlogAy[i, j] == dlogAy
158+
138159
def test_V(self):
139160
volume = np.abs(-2.0 * np.pi / 3.0 *
140161
(np.cos(self.g.yr2d.v()) - np.cos(self.g.yl2d.v())) *

0 commit comments

Comments
 (0)