00001 #include "copyright.h" 00002 /*============================================================================*/ 00003 /*! \file cc_pos.c 00004 * \brief Functions to compute (x1,x2,x3) positions of cells i,j,k. 00005 * 00006 * PURPOSE: Functions to compute (x1,x2,x3) positions of cells i,j,k. 00007 * In a nested grid, each Grid structure is a patch in a larger computational 00008 * domain (with the exception of the level0 grid). The displacement of the 00009 * origin of the Grid from the origin of the computational domain (level0 00010 * grid) is x1_{disp} = idisp*dx1. Furthermore, the origin of the level0 00011 * grid can be displaced by a distance x1_{0} from the origin of x1. Thus, 00012 * the x1 position of the center of cell i (x1_{cc,i}) in any level Grid is 00013 * x1_{cc,i} = x1_{0} + ((i + idisp) + 0.5)*dx1 00014 * Similarly for x2 and x3. 00015 * 00016 * CONTAINS PUBLIC FUNCTIONS: 00017 * - cc_pos() - given i,j,k returns cell-centered x1,x2,x3 00018 * - fc_pos() - given i,j,k returns face-centered x1,x2,x3 00019 * - x1cc() - given i, returns cell-centered x1. 00020 * - x2cc() - given j, returns cell-centered x2. 00021 * - x3cc() - given k, returns cell-centered x3. 00022 * - celli() - given x, returns containing cell first index. 00023 * - cellj() - given y, returns containing cell first index. 00024 * - cellk() - given y, returns containing cell first index. */ 00025 /*============================================================================*/ 00026 00027 #include "athena.h" 00028 #include "defs.h" 00029 #include "prototypes.h" 00030 00031 /*----------------------------------------------------------------------------*/ 00032 /*! \fn void cc_pos(const GridS *pG, const int i, const int j,const int k, 00033 * Real *px1, Real *px2, Real *px3) 00034 * \brief given i,j,k returns cell-centered x1,x2,x3 00035 */ 00036 void cc_pos(const GridS *pG, const int i, const int j,const int k, 00037 Real *px1, Real *px2, Real *px3) 00038 { 00039 *px1 = pG->MinX[0] + ((Real)(i - pG->is) + 0.5)*pG->dx1; 00040 *px2 = pG->MinX[1] + ((Real)(j - pG->js) + 0.5)*pG->dx2; 00041 *px3 = pG->MinX[2] + ((Real)(k - pG->ks) + 0.5)*pG->dx3; 00042 return; 00043 } 00044 00045 /*----------------------------------------------------------------------------*/ 00046 /*! \fn void fc_pos(const GridS *pG, const int i, const int j,const int k, 00047 * Real *px1, Real *px2, Real *px3) 00048 * \brief given i,j,k returns face-centered x1,x2,x3 00049 */ 00050 00051 void fc_pos(const GridS *pG, const int i, const int j,const int k, 00052 Real *px1, Real *px2, Real *px3) 00053 { 00054 *px1 = pG->MinX[0] + ((Real)(i - pG->is))*pG->dx1; 00055 *px2 = pG->MinX[1] + ((Real)(j - pG->js))*pG->dx2; 00056 *px3 = pG->MinX[2] + ((Real)(k - pG->ks))*pG->dx3; 00057 return; 00058 } 00059 00060 #ifdef CYLINDRICAL 00061 Real x1vc(const GridS* pG, const int i) 00062 { 00063 Real x1cc = pG->MinX[0] + ((Real)(i - pG->is) + 0.5)*pG->dx1; 00064 return x1cc + SQR(pG->dx1)/(12.0*x1cc); 00065 } 00066 #endif 00067 00068 #ifdef PARTICLES 00069 /*============================================================================ 00070 cell-location functions 00071 Created: Emmanuel Jacquet, Mar. 2008 00072 Modified: Xuening Bai, Dec. 2008 00073 ============================================================================*/ 00074 00075 /*----------------------------------------------------------------------------*/ 00076 /* Input: pGrid: grid; x: global x coordinate; 00077 * dx1_1: 1/dx1 (to improve performance) 00078 * Output: i: i-index containing x; a: grid index coordinate of x; 00079 * Return: 0: x is on the left of the ith cell; 00080 * 1: x is on the right of the ith cell; 00081 */ 00082 00083 /*! \fn int celli(const GridS* pGrid, const Real x, const Real dx1_1, 00084 * int *i, Real *a) 00085 * \brief given x, returns containing cell first index. */ 00086 int celli(const GridS* pGrid, const Real x, const Real dx1_1, int *i, Real *a) 00087 { 00088 *a = (x - pGrid->x1_0) * dx1_1 - pGrid->idisp; 00089 *i = (int)(*a); 00090 if (((*a)-(*i)) < 0.5) return 0; /* in the left half of the cell*/ 00091 else return 1; /* in the right half of the cell*/ 00092 } 00093 00094 /*! \fn Real x1cc(const Grid* pGrid, const int i) 00095 * \brief given i, returns cell-centered x1. */ 00096 Real x1cc(const Grid* pGrid, const int i) 00097 { 00098 return (pGrid->x1_0 + (i + pGrid->idisp + 0.5) * pGrid->dx1); 00099 } 00100 00101 /*! \fn cellj(const Grid* pGrid, const Real y, const Real dx2_1, 00102 * int *j, Real *b) 00103 * \brief given y, returns containing cell first index. */ 00104 int cellj(const Grid* pGrid, const Real y, const Real dx2_1, int *j, Real *b) 00105 { 00106 *b = (y - pGrid->x2_0) * dx2_1 - pGrid->jdisp; 00107 *j = (int)(*b); 00108 if (((*b)-(*j)) < 0.5) return 0; /* in the left half of the cell*/ 00109 else return 1; /* in the right half of the cell*/ 00110 } 00111 00112 /*! \fn Real x2cc(const Grid* pGrid, const int j) 00113 * \brief given j, returns cell-centered x2. */ 00114 Real x2cc(const Grid* pGrid, const int j) 00115 { 00116 return (pGrid->x2_0 + (j + pGrid->jdisp + 0.5) * pGrid->dx2); 00117 } 00118 00119 /*! \fn int cellk(const Grid* pGrid, const Real z, const Real dx3_1, 00120 * int *k, Real *c) 00121 * \brief given z, returns containing cell first index. */ 00122 int cellk(const Grid* pGrid, const Real z, const Real dx3_1, int *k, Real *c) 00123 { 00124 *c = (z - pGrid->x3_0) * dx3_1 - pGrid->kdisp; 00125 *k = (int)(*c); 00126 if (((*c)-(*k)) < 0.5) return 0; /* in the left half of the cell*/ 00127 else return 1; /* in the right half of the cell*/ 00128 } 00129 00130 /*! \fn Real x3cc(const Grid* pGrid, const int k) 00131 * \brief given k, returns cell-centered x3. */ 00132 Real x3cc(const Grid* pGrid, const int k) 00133 { 00134 return (pGrid->x3_0 + (k + pGrid->kdisp + 0.5) * pGrid->dx3); 00135 } 00136 00137 #endif /* PARTICLES */