{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "\n", "# Numerical Grids in NRPy+\n", "\n", "## Author: Zach Etienne\n", "\n", "### NRPy+ Source Code for this module: [grid.py](../edit/grid.py)\n", "\n", "Solving partial differential equations on the computer with finite difference techniques requires that we sample our solutions to these equations on numerical grids. We call all sampled functions that are stored on our numerical grid *gridfunctions*. NRPy+'s grid module adds the capability of registering gridfunctions in NRPy, setting basic parameters of a numerical grid, and providing functions to other modules regarding reading and writing of gridfunctions to memory in the C code.\n", "\n", "Parameters in this module include:\n", "* **grid::DIM** -- the dimension of the grid (e.g., a 3D numerical grid will have grid::DIM=3).\n", "* **grid::Nx\\[DIM\\]** -- an integer array yielding the size of the grid in each direction. E.g., in Cartesian coordinates Nx\\[0\\] will be set to the number of grid points in the x direction. *This is a parameter that is set at C runtime, not in NRPy+; NRPy+ simply generates the declaration of this parameter in the C code.*\n", "* **grid::MemAllocStyle** -- how the gridfunction is allocated in memory in the C code. This is used when generating the C code to ensure that gridfunctions are read as sequentially in memory as possible, to avoid [cache misses](https://en.wikipedia.org/wiki/CPU_cache#CACHE-MISS). There are currently two MemAllocStyles supported:\n", " * If the following loop accesses the grid function in a contiguous manner in memory, we set \"grid::MemAllocStyle=012\":\n", " * for(int i0=0;i0