Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Included PolarGrid class. right now it assumes no ghost cells #136

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e0b136f
Included PolarGrid class. right now it assumes no ghost cells
ssagynbayeva Mar 9, 2023
982e449
Merge remote-tracking branch 'upstream/main' into polar-coords
ssagynbayeva Mar 9, 2023
eb71efc
Update pyro/mesh/patch.py
ssagynbayeva Mar 9, 2023
b716ca3
Update pyro/mesh/patch.py
ssagynbayeva Mar 9, 2023
196e9df
added A_x and A_y
ssagynbayeva Mar 15, 2023
f2367c1
Merge remote-tracking branch 'upstream/main' into polar-coords
ssagynbayeva Mar 15, 2023
7466128
Merge branch 'main' into polar-coords
zingale Mar 17, 2023
bbe762d
fixed the areas. They are now using self.xr and self.yr instead of ce…
ssagynbayeva Mar 21, 2023
f9afaa6
Merge branch 'polar-coords' of https://github.com/ssagynbayeva/pyro2 …
ssagynbayeva Mar 21, 2023
a8f9b65
Merge branch 'main' into polar-coords
ssagynbayeva Mar 21, 2023
c377f3b
removed _init_
ssagynbayeva Mar 21, 2023
f0f089b
Merge branch 'polar-coords' of https://github.com/ssagynbayeva/pyro2 …
ssagynbayeva Mar 21, 2023
7405339
changed areas and the cell volume
ssagynbayeva Apr 3, 2023
d2d5712
Merge branch 'main' into polar-coords
ssagynbayeva Apr 3, 2023
df648dc
fixed flake8 errors
ssagynbayeva Apr 3, 2023
f98abf7
Merge branch 'polar-coords' of https://github.com/ssagynbayeva/pyro2 …
ssagynbayeva Apr 3, 2023
8e8e0d6
added a line before main
ssagynbayeva Apr 3, 2023
ffdce53
Merge branch 'main' into polar-coords
zingale Apr 4, 2023
55c8377
recomputed areas
ssagynbayeva Apr 5, 2023
d076961
Merge branch 'polar-coords' of https://github.com/ssagynbayeva/pyro2 …
ssagynbayeva Apr 5, 2023
8fa6b97
ASCII picture
ssagynbayeva Apr 5, 2023
54ecf2d
added unit tests for the PolarGrid()
ssagynbayeva Apr 5, 2023
6173abd
changes
ssagynbayeva Apr 6, 2023
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
61 changes: 61 additions & 0 deletions pyro/mesh/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,5 +884,66 @@ def do_demo():
mydata.pretty_print("a")


# **c checking
class PolarGrid(Grid2d):
"""
the 2-d grid class. The grid object will contain the coordinate
information (at various centerings).

A basic representation of the layout is::

*---* \theta_{i+1/2}
/ |
/ |
/ * \theta_i
/ |
/ |
*____*____* \theta_{i-1/2}
r_{i-1/2} r_i r_{i+1/2}

The '*' marks represent the vertices; i index is the data location.
"""

# pylint: disable=too-many-instance-attributes

def area_x(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is the area through a y (theta) face. area_x() should return the area through the x faces, which is r_{i-1/2} dtheta

"""
Return an array of the face areas.
The shape of the returned array is (ni, nj).
"""
r1, t1 = np.meshgrid(self.xr, self.yr)
r0, t0 = np.meshgrid(self.xl, self.yl)

# ** this is just 1/2*r*d\theta

area = 0.5 * r0 * (t1 - t0)
return area

def area_y(self):
"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should be the area through a y face, which is just dr

Copy link
Author

Choose a reason for hiding this comment

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

but y face is dtheta

Return an array of the face areas.
The shape of the returned array is (ni, nj).
"""
r1, t1 = np.meshgrid(self.xr, self.yr)
r0, t0 = np.meshgrid(self.xl, self.yl)

# ** this is just dr

area = r1 - r0
return area

def cell_volumes(self):
"""
Return an array of the cell volume data for the given coordinate box
The shape of the returned array is (ni, nj).
"""
r1, t1 = np.meshgrid(self.xr, self.yr)
r0, t0 = np.meshgrid(self.xl, self.yl)

# ** this is just the face area

return 0.5 * (r1 ** 2 - r0 ** 2) * (t1 - t0)


if __name__ == "__main__":
do_demo()
76 changes: 76 additions & 0 deletions pyro/mesh/tests/test_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,79 @@ def test_bcs():
# top
assert_array_equal(d[myg.ilo:myg.ihi+1, myg.jhi-1:myg.jhi+1],
-np.fliplr(d[myg.ilo:myg.ihi+1, myg.jhi+1:myg.jhi+3]))


# PolarGrid tests
class TestPolarGrid(object):
@classmethod
def setup_class(cls):
""" this is run once for each class before any tests """
pass

@classmethod
def teardown_class(cls):
""" this is run once for each class after all tests """
pass

def setup_method(self):
""" this is run before each test """
self.g = patch.PolarGrid(4, 6, ng=2, ymax=1.5)

def teardown_method(self):
""" this is run after each test """
self.g = None

def test_dx_dy(self):
assert self.g.dx == 0.25
assert self.g.dy == 0.25

def test_grid_coords(self):
assert_array_equal(self.g.x[self.g.ilo:self.g.ihi+1],
np.array([0.125, 0.375, 0.625, 0.875]))
assert_array_equal(self.g.y[self.g.jlo:self.g.jhi+1],
np.array([0.125, 0.375, 0.625, 0.875, 1.125, 1.375]))

def test_grid_2d_coords(self):
assert_array_equal(self.g.x, self.g.x2d[:, self.g.jc])
assert_array_equal(self.g.y, self.g.y2d[self.g.ic, :])

def test_scratch_array(self):
q = self.g.scratch_array()
assert q.shape == (self.g.qx, self.g.qy)

def test_coarse_like(self):
q = self.g.coarse_like(2)
assert q.qx == 2*self.g.ng + self.g.nx//2
assert q.qy == 2*self.g.ng + self.g.ny//2

def test_fine_like(self):
q = self.g.fine_like(2)
assert q.qx == 2*self.g.ng + 2*self.g.nx
assert q.qy == 2*self.g.ng + 2*self.g.ny

def test_norm(self):
q = self.g.scratch_array()
# there are 24 elements, the norm L2 norm is
# sqrt(dx*dy*24)
q.v()[:, :] = np.array([[1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1]])

assert q.norm() == np.sqrt(24*self.g.dx*self.g.dy)

def test_equality(self):
g2 = patch.PolarGrid(2, 5, ng=1)
assert g2 != self.g

def test_area_x(self):
A = self.g.area_x()
assert A[0,0] == (self.g.yr[0] - self.g.yl[0]) * (self.g.xr[0] - self.g.xl[0]) * 0.5

def test_area_y(self):
A = self.g.area_y()
assert A[0] == (self.g.xr - self.g.xl)

def test_cell_volumes(self):
V = self.g.cell_volumes()
assert V[0,0] == (self.g.yr[0] - self.g.yl[0]) * (self.g.xr[0] ** 2 - self.g.xl[0] ** 2) * 0.5