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
Changes from 2 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
179 changes: 174 additions & 5 deletions pyro/mesh/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
import h5py
import numpy as np

import pyro.mesh.boundary as bnd
from pyro.mesh.array_indexer import ArrayIndexer, ArrayIndexerFC
from pyro.util import msg
# import pyro.mesh.boundary as bnd
# from pyro.mesh.array_indexer import ArrayIndexer, ArrayIndexerFC
# from pyro.util import msg
ssagynbayeva marked this conversation as resolved.
Show resolved Hide resolved


class Grid2d:
Expand Down Expand Up @@ -885,5 +885,174 @@ def do_demo():
mydata.pretty_print("a")


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

A basic (1-d) representation of the layout is::

| | | X | | | | X | | |
+--*--+- // -+--*--X--*--+--*--+- // -+--*--+--*--X--*--+- // -+--*--+
0 ng-1 ng ng+1 ... ng+nx-1 ng+nx 2ng+nx-1

ilo ihi

|<- ng guardcells->|<---- nx interior zones ----->|<- ng guardcells->|

The '*' marks the data locations.
"""

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

def __init__(self, nx, ny, ng=1,
xmin=0.0, xmax=1.0, ymin=0.0, ymax=1.0):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think you need init, since it looks the same as the base class

Copy link
Collaborator

Choose a reason for hiding this comment

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

:)

Copy link
Author

Choose a reason for hiding this comment

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

I left if for later if it will be needed to be changed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It might be better to call super().__init__(nx, ny, ...) in that case


"""
Create a PolarGrid object.

The only data that we require is the number of points that
make up the mesh in each direction. Optionally we take the
extrema of the domain (default is [0,1]x[0,1]) and number of
ghost cells (default is 1).

Note that the Grid2d object only defines the discretization,
it does not know about the boundary conditions, as these can
vary depending on the variable.

Parameters
----------
nx : int
Number of zones in the r-direction
ny : int
Number of zones in the theta-direction
ng : int, optional
Number of ghost cells
xmin : float, optional
Physical coordinate at the lower x boundary
xmax : float, optional
Physical coordinate at the upper x boundary
ymin : float, optional
Physical coordinate at the lower y boundary
ymax : float, optional
Physical coordinate at the upper y boundary
"""

# pylint: disable=too-many-arguments

# size of grid
self.nx = int(nx)
self.ny = int(ny)
self.ng = int(ng)

self.qx = int(2*ng + nx)
self.qy = int(2*ng + ny)

# domain extrema
self.xmin = xmin
self.xmax = xmax

self.ymin = ymin
self.ymax = ymax

# compute the indices of the block interior (excluding guardcells)
self.ilo = self.ng
self.ihi = self.ng + self.nx-1

self.jlo = self.ng
self.jhi = self.ng + self.ny-1

# center of the grid (for convenience)
self.ic = self.ilo + self.nx//2 - 1
self.jc = self.jlo + self.ny//2 - 1

# define the coordinate information at the left, center, and right
# zone coordinates
self.dx = (xmax - xmin)/nx

self.xl = (np.arange(self.qx) - ng)*self.dx + xmin
self.xr = (np.arange(self.qx) + 1.0 - ng)*self.dx + xmin
self.x = 0.5*(self.xl + self.xr)

self.dy = (ymax - ymin)/ny

self.yl = (np.arange(self.qy) - ng)*self.dy + ymin
self.yr = (np.arange(self.qy) + 1.0 - ng)*self.dy + ymin
self.y = 0.5*(self.yl + self.yr)

# 2-d versions of the zone coordinates (replace with meshgrid?)
x2d = np.repeat(self.x, self.qy)
x2d.shape = (self.qx, self.qy)
self.x2d = x2d

y2d = np.repeat(self.y, self.qx)
y2d.shape = (self.qy, self.qx)
y2d = np.transpose(y2d)
self.y2d = y2d


def face_area(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).
"""
tr = lambda arr: arr.transpose(1, 2, 0)
x = self.cell_vertices()[:,0]
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you use the data in the class instead of recomputing the vertices yourself?

y = self.cell_vertices()[0,:]
r0 = x[:-1, :-1]
r1 = x[+1:, :-1]
t0 = y[:-1, :-1]
t1 = y[+1:, +1:]

# ** the area of the arc

area_i = np.pi * (r0 * np.sin(t0) + r0 * np.sin(t1)) * np.sqrt(np.square(r0 * np.sin(t1) - r0 * np.sin(t0)) + np.square(r0 * np.cos(t1) - r0 * np.cos(t0)))
area_j = np.pi * (r0 * np.sin(t0) + r1 * np.sin(t0)) * np.sqrt(np.square(r1 * np.sin(t0) - r0 * np.sin(t0)) + np.square(r1 * np.cos(t0) - r0 * np.cos(t0)))
return tr(np.array([area_i, area_j]))

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).
"""

x = self.cell_vertices()[:,0]
y = self.cell_vertices()[0,:]

r0 = x[:-1, :-1]
r1 = x[+1:, :-1]
t0 = y[:-1, :-1]
t1 = y[+1:, +1:]

return (r1 ** 3 - r0 ** 3) * (np.cos(t1) - np.cos(t0)) * (-2.0 * np.pi) / 3.0
# return r1
Copy link
Collaborator

Choose a reason for hiding this comment

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

r**3 makes this a volume, not a face area, right? shouldn't this just be

dr * r (t1 - t0) ?

for the area of a wedge in the r-theta polar plane?

:)

Copy link
Collaborator

Choose a reason for hiding this comment

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

sorry, that would be the volume

for the area, you should have an area_x and area_y function
and those should give just r*theta and dr respectively.

Copy link
Collaborator

Choose a reason for hiding this comment

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

:)

Copy link
Author

Choose a reason for hiding this comment

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

This function computes dr and dtheta. :)


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

Choose a reason for hiding this comment

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

isn't this already what self.xl and self.xr provide?
:)

Copy link
Author

Choose a reason for hiding this comment

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

I did not really understand what they are, and decided to write my own function. ;)

Return the coordinates of cell vertices
The arrays range from 0 to 1 for now
"""
# if self.ng == 0:
# xv = np.linspace(0, 1, self.nx + 1)[:-1]
# yv = np.linspace(0, 1, self.ny + 1)[:-1]
# else:
# xv = np.linspace(0, 1, self.nx + 1)
# yv = np.linspace(0, 1, self.ny + 1)

xv = np.linspace(0, 1, self.nx + 1)[:-1]
yv = np.linspace(0, 1, self.ny + 1)[:-1]


tr = lambda arr: arr.transpose(1, 2, 0)
x, y = np.meshgrid(xv, yv, indexing="ij")
return tr(np.array([x, y]))







# if __name__ == "__main__":
# do_demo()
ssagynbayeva marked this conversation as resolved.
Show resolved Hide resolved