Skip to content

Commit 70cd05d

Browse files
author
Michael Zingale
committed
lots of docstrings
1 parent 6961e02 commit 70cd05d

1 file changed

Lines changed: 89 additions & 38 deletions

File tree

mesh/patch.py

Lines changed: 89 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,34 @@ class Grid2d:
195195

196196
def __init__ (self, nx, ny, ng=1, \
197197
xmin=0.0, xmax=1.0, ymin=0.0, ymax=1.0):
198-
199198
"""
200-
The class constructor function.
199+
Create a Grid2d object.
201200
202201
The only data that we require is the number of points that
203-
make up the mesh.
202+
make up the mesh in each direction. Optionally we take the
203+
extrema of the domain (default is [0,1]x[0,1]) and number of
204+
ghost cells (default is 1).
205+
206+
Note that the Grid2d object only defines the discretization,
207+
it does not know about the boundary conditions, as these can
208+
vary depending on the variable.
204209
205-
We optionally take the extrema of the domain (assume it is
206-
[0,1]x[0,1]), number of ghost cells (assume 1), and the
207-
type of boundary conditions (assume reflecting).
210+
Parameters
211+
----------
212+
nx : int
213+
Number of zones in the x-direction
214+
ny : int
215+
Number of zones in the y-direction
216+
ng : int, optional
217+
Number of ghost cells
218+
xmin : float, optional
219+
Physical coordinate at the lower x boundary
220+
xmax : float, optional
221+
Physical coordinate at the upper x boundary
222+
ymin : float, optional
223+
Physical coordinate at the lower y boundary
224+
ymax : float, optional
225+
Physical coordinate at the upper y boundary
208226
"""
209227

210228
# time
@@ -258,13 +276,13 @@ def __init__ (self, nx, ny, ng=1, \
258276
self.y2d = y2d
259277

260278

261-
def scratch_array(self, dtype=numpy.float64):
279+
def scratch_array(self):
262280
"""
263281
return a standard numpy array dimensioned to have the size
264282
and number of ghostcells as the parent grid
265283
"""
266284

267-
return numpy.zeros((self.qx, self.qy), dtype=dtype)
285+
return numpy.zeros((self.qx, self.qy), dtype=numpy.float64)
268286

269287

270288
def __str__(self):
@@ -292,33 +310,31 @@ def __eq__(self, other):
292310

293311
class CellCenterData2d:
294312
"""
295-
the cell-centered data that lives on a grid.
296-
297-
a CellCenterData2d object is built in a multi-step process before
313+
A class to define cell-centered data that lives on a grid. A
314+
CellCenterData2d object is built in a multi-step process before
298315
it can be used.
299316
300-
create the object. We pass in a grid object to describe where the
301-
data lives:
302-
303-
my_data = patch.CellCenterData2d(myGrid)
317+
-- Create the object. We pass in a grid object to describe where
318+
the data lives:
304319
305-
register any variables that we expect to live on this patch. Here
306-
BCObject describes the boundary conditions for that variable.
320+
my_data = patch.CellCenterData2d(myGrid)
307321
308-
my_data.register_var('density', BCObject)
309-
my_data.register_var('x-momentum', BCObject)
310-
...
322+
-- Register any variables that we expect to live on this patch.
323+
Here BCObject describes the boundary conditions for that variable.
311324
325+
my_data.register_var('density', BCObject)
326+
my_data.register_var('x-momentum', BCObject)
327+
...
312328
313-
Register any auxillary data -- these are any parameters that are
314-
needed to interpret the data outside of the simulation (for
315-
example, the gamma for the equation of state).
329+
-- Register any auxillary data -- these are any parameters that are
330+
needed to interpret the data outside of the simulation (for
331+
example, the gamma for the equation of state).
316332
317-
mydata.set_aux(keyword, value)
333+
mydata.set_aux(keyword, value)
318334
319-
finally, finish the initialization of the patch
335+
-- Finish the initialization of the patch
320336
321-
myPatch.create()
337+
myPatch.create()
322338
323339
This last step actually allocates the storage for the state
324340
variables. Once this is done, the patch is considered to be
@@ -329,10 +345,18 @@ class CellCenterData2d:
329345
def __init__ (self, grid, dtype=numpy.float64, runtime_parameters=None):
330346

331347
"""
332-
The class constructor function.
348+
Initialize the CellCenterData2d object.
349+
350+
Parameters
351+
----------
352+
grid : Grid2d object
353+
The grid upon which the data will live
354+
dtype : NumPy data type, optional
355+
The datatype of the data we wish to create (defaults to
356+
numpy.float64
357+
runtime_parameters : RuntimeParameters object, optional
358+
The runtime parameters that go along with this data
333359
334-
The only data that we require is grid object that describes
335-
the geometry of the domain.
336360
"""
337361

338362
self.grid = grid
@@ -353,9 +377,16 @@ def __init__ (self, grid, dtype=numpy.float64, runtime_parameters=None):
353377

354378
def register_var(self, name, bc_object):
355379
"""
356-
register a variable with CellCenterData2d object. Here we pass in
357-
a BCObject that describes the boundary conditions for that
358-
variable.
380+
Register a variable with CellCenterData2d object.
381+
382+
Parameters
383+
----------
384+
name : str
385+
The variable name
386+
bc_object : BCObject object
387+
The boundary conditions that describe the actions to take
388+
for this variable at the physical domain boundaries.
389+
359390
"""
360391

361392
if self.initialized == 1:
@@ -369,15 +400,24 @@ def register_var(self, name, bc_object):
369400

370401
def set_aux(self, keyword, value):
371402
"""
372-
set any auxillary (scalar) data
403+
Set any auxillary (scalar) data. This data is simply carried
404+
along with the CellCenterData2d object
405+
406+
Parameters
407+
----------
408+
keyword : str
409+
The name of the datum
410+
value : any time
411+
The value to associate with the keyword
412+
373413
"""
374414
self.aux[keyword] = value
375415

376416

377417
def create(self):
378418
"""
379-
called after all the variables are registered and allocates
380-
the storage for the state data
419+
Called after all the variables are registered and allocates
420+
the storage for the state data.
381421
"""
382422

383423
if self.initialized == 1:
@@ -427,9 +467,20 @@ def __str__(self):
427467

428468
def get_var(self, name):
429469
"""
430-
return a pointer to the data array for the variable described
431-
by name. Any changes made to this are automatically reflected
432-
in the CellCenterData2d object
470+
Return a data array for the variable described by name.
471+
Any changes made to this are automatically reflected in the
472+
CellCenterData2d object.
473+
474+
Parameters
475+
----------
476+
name : str
477+
The name of the variable to access
478+
479+
Returns
480+
-------
481+
out : ndarray
482+
The array of data corresponding to the variable name
483+
433484
"""
434485
n = self.vars.index(name)
435486
return self.data[n,:,:]

0 commit comments

Comments
 (0)