Class CBlockGrid handles grid organised into a 3D AMR octal tree (forrest) of blocks (tree nodes). The whole grid covers a cuboid computational domain. Blocks consist of grid cells and all blocks have the same shape (number of cells along the three coordinates). Blocks have assigned refinement levels, its value 1 corresponds to the root block (or blocks) and higher values denote more and more refined blocks. Each grid cell includes several quantities (float64 numbers).
The grid can be read from hdf files (written by Flash) or ascii files (in prep). The file must include certain basic properties that can be read by function readPFMetadata. The remaining data (content of blocks) can be read by parts (by individual blocks and quantities) by function readBlocks.
The CBlockGrid class includes functions that allow to trasform blocks to a given refinement level, calculate their slices and integrals in a given direction and insert block data into a uniform grid (class CUniformGrid): cuboid, plane or line segment, aligned with the axes of the grid. The CBlockGrid is always 3-dimensional, its axes have indeces XAXIS, YAXIS and YAXIS; contrary to the uniform grid, which can be 1-, 2-, or 3-dimensional and its axes have indeces AXIS1, AXIS2 and AXIS3. The correspondence between the two systems of coordinates is controlled by the --mode command line argument and the axord - the uniform grid property and an argument of several methods.
Basic grid properties
Basic grid properties are set once by the readPFMetadat function. They are essential, each grid must provide them, all other grid metadata can be calculated from them. They can be accessed using functions (named as them) marked by the python "@property" decorator.
- bb - Bounding boxes of all blocks. Ret: npa(block, direction, LO/HI).
- blkshape - Shape of blocks (same for all of them) - number of grid cells in all directions. Ret: npa(dir).
- nblocks - Number of blocks. Ret: integer.
- nodetype - Returns nodetypes of all blocks (1 = leaf block). Ret: npa(block).
- rlevel - Refinement levels for all blocks. Ret: npa(block).
- vnames - List of field variables names available in the grid datafile. Ret: python list of (preferentially 4 character) strings.
Derived grid properties
Properties of the grid that can be derived from the above basic grid properties. They are calculated only once, at the first call of the function. They are marked by the "@cached_property" decorator.
- bc - Coordinates of block centres. Ret: npa(block, dir).
- bs - Sizes of all blocks in all directions. Ret: npa(block, dir).
- CD - Computational domain (calculated from bb of all blocks). Ret: npa(block, dir, LO/HI).
- cs - Cell sizes of all blocks. Ret: npa(block, dir).
- maxrl - Maximum refinement level in the grid. Ret: int.
- minbs - Size of the smallest block. Ret: npa(dir).
- mincs - Size of the smallest grid cell. Ret: npa(dir).
Calculating various values from metadata
- blkCellCoords(b, direction) - Calculates coordinates for all cells of a blocks along a given direction. Args: b is block number, direction is XAXIS, YAXIS or ZAXIS. Ret: npa(cell).
- blkCellCoords3d(b, coordType) - Calculates cell coordinates and other quantities derived from them and returns npa with the same shape as the block filled with the generalised coordinate. The possible generalised coordinates are: 'x', 'y', 'z', 'vol', 'r3', 'r2x', 'r2y', and 'r2z'. Args: b is block number; coordType is a string denoting the coordinate type. Ret: npa(XAXIS,YAXIS,ZAXIS).
- blocksIntersectingBox(box) - Returns list of blocks intersecting with a given box. box is 3x2 (dim, LO/HI) numpy array.
- csrl - Size of a cell at given refinement level. 1dim: direction.
- getDict - Returns dictionary various grid properties assigned actual values. 'xmin', 'xmax', 'xcen', 'ymin', ...
Input / output
- readPFMetadata(fn) - Reads metadata defining the grid using the plotfile object. Argument "fn" denotes the filename. Currently uses flashpf Plotfile class based on the pytables library to interact with the hdf file.
- readBlocks(blocks, quans) - Reads selected blocks and selected quantities into memory. Creates/updates array bIdx and dictionary qIdx providing indeces of a given block and quantity into the 'data' array.
- writeBlk(fn, UG) - Writes edges of blocks intersecting with a given uniform grid into ascii file. Works for 1, 2 or 3-dimensionsional uniform grids. Ordering of axes is the same as in the related uniform grid. Args: fn is the ascii output file nmae (string); UG is the related uniform grid (CUniformGrid class object). Ret: nothing.
Block transformation
- blkCut(b, axord, pos) - Returns a cut (2d slice or 1d line segment) from 3d block at a given position. Does not interpolate, just finds the closest coordinate and copies the data. Args: b is block number, axord is an array (npa(3)) defining ordering of axes of the cut; pos is a 3 element list defining the position of the cutting object in the grid (None means this dimension has only 1 element in the AMR grid, "RANGE" means that it is copied, a number defines the position). Ret: npa(dir1[, dir2]) - cutting object: plane or line segment.
- blkIntegrate(b, axord, pos, bbox, quans, weights) - Integrates a block along a given direction(s) and returns a block with smaller dimension. Only certain quantities (given by list quans) are integrated. The integrated quantities are multiplied by number/array weights. Args: b is the block number; axord is an array (npa(3)) defining ordering of axes of the cut; pos is a 3 element list defining the position of the cutting object in the grid (None means this dimension has only 1 element in the AMR grid, "RANGE" means that it is copied, a number defines the position); bbox is the bounding box of the integrated grid (npa(dir,LO/HI)) ; quans is a list of quantities (strings) to be integrated; and weights are integration weights - a number or npa with the same shape (appart form the last dimension - quantities) as the original block b. Ret: a block with shape (dir1[, dir2], len(quans)) where dir1, and dir2 are dimensions of the original block in non-integration dimensions.
- blkToRefLevel(blk, rlDiff, axes) - Converts block blk to a different resolution by changing its size by a power of 2 (both shrink and grow). The values are simply copied or deleted, no interpolation is made. Args: blk is a block (npa with appropriate dimension + 1), rlDiff is a difference in the refinement level (integer), argument axes defines along which coords the growth/shrinking should be made. Ret: new block (npa with the same dim as blk.
Interaction with uniform grid
- createUniformGrid(self, dim, axord, pos, reflevel, quans, bbox) - Creates a uniform grid (class CUniformGrid) covering the AMR grid, with coordinates aligned with it, restricted with given arguments. Args: dim - dimension (1, 2 or 3); axord - ordering of axes (npa(3)); pos - 3-element list defining the position of the cutting object in the grid (None means this dimension has only 1 element in the AMR grid, "RANGE" means that it is copied, a number defines the position of a cut); reflevel - refinement level determining size of UG cells; quans - quantities to be stored in the UG, encapsulated in the CQList object; bbox - bounding box, npa(dir,LO/HI).
- insRanges(axis, bounds, ncells) - Determines sets of indices in a block (bIdx) and in an axis (aIdx) for the situation when a block (defined with bounds and ncells) is inserted into a uniform grid (defined with axis). Args: axis - axis of a uniform grid; bounds - min & max of an inserted block along the given axis; ncells - number of cells of a block in a given direction. Ret: tuple of two npa - bIdx and aIdx.
- fillUG(self, UG, qpref, qn, UGQSlice, wn = None) - Fills the uniform grid (CUniformGrid) with the block data. At first it determines which blocks and quantities will be needed depending on the AMR and uniform grid's bboxes and whether it should integrate in the other (two) directions or just make a cut. Then, it reads all necessary blocks from file, makes cuts or integrals, transforms them to the same rlevel as the uniform grid, and inserts them into it. Args: UG is the CUniformGrid object; qpref is the quantity prefix: 's;' for slice, 'i;' for integration, 'd;' for density weigthed integration, and 'c;' for cumulative sum or product; qn is the CQList object with all quantities that will be stored in the uniform grid; UGQSlice sets range of indeces in the uniform grid where the quantities will be inserted; and wn is the name an eventual weighting quantity (integrals can be weighted). Ret: None.
- ugAxis(direction, reflevel, bounds) - Creates an np array with grid cells coords along certain direction (0,1,2 = x, y, z), at a certain refinement level and restricted with bounds npa(2) - min, max).