{ "thorn_name": "CactusExamples/Poisson", "url": "https://bitbucket.org/cactuscode/cactusexamples.git", "configuration": "# Configuration definition for thorn Poisson\n\nREQUIRES Boundary Carpet CartGrid3D TATelliptic\n", "interface": "# Interface definition for thorn Poisson\n\nIMPLEMENTS: Poisson\n\nINHERITS: boundary grid\n\nUSES INCLUDE HEADER: carpet.h\nUSES INCLUDE HEADER: TATelliptic.h\n\n\n\nCCTK_INT FUNCTION Boundary_SelectGroupForBC \\\n (CCTK_POINTER_TO_CONST IN cctkGH, \\\n CCTK_INT IN faces, \\\n CCTK_INT IN boundary_width, \\\n CCTK_INT IN table_handle, \\\n CCTK_STRING IN group_name, \\\n CCTK_STRING IN bc_name)\nREQUIRES FUNCTION Boundary_SelectGroupForBC\n\n\n\nCCTK_REAL potential TYPE=gf\n{\n phi\n} \"Potential for elliptic equation\"\n\nCCTK_REAL residual TYPE=gf\n{\n res\n} \"Residual for elliptic equation\"\n", "param": "# Parameter definitions for thorn Poisson\n\nSTRING solver \"Name of TATelliptic solver that should be used\"\n{\n .* :: \"must be an activated TATelliptic solver\"\n} \"TATJacobi\"\n\nSTRING options \"Options for the solver\"\n{\n .* :: \"no restriction\"\n} \"\"\n\n\n\nREAL radius \"Radius of uniformly charged sphere\"\n{\n 0:* :: \"\"\n} 1.0\n\nREAL charge \"Charge of uniformly charged sphere\"\n{\n *:* :: \"\"\n} 1.0\n", "schedule": "# Schedule definitions for thorn Poisson\n\nSTORAGE: potential residual\n\nSCHEDULE Poisson_prepare AT initial\n{\n LANG: C\n WRITES: Poisson::phi(Everywhere)\n} \"Set up initial guess for initial data\"\n\nSCHEDULE Poisson_solve AT postinitial\n{\n LANG: C\n WRITES: Poisson::res(Interior)\n READS: Poisson::phi(Everywhere)\n READS: Grid::coordinates(Interior)\n # OPTIONS: global\n} \"Calculate uniform charge initial data\"\n\nSCHEDULE GROUP Poisson_boundaries\n{\n} \"Apply boundary conditions to initial data\"\n\nSCHEDULE Poisson_boundaries_select IN Poisson_boundaries\n{\n LANG: C\n OPTIONS: level\n SYNC: potential\n} \"Select boundary conditions for initial data\"\n\nSCHEDULE GROUP ApplyBCs AS Poisson_boundaries_apply IN Poisson_boundaries AFTER Poisson_boundaries_select\n{\n} \"Apply boundary conditions to initial data\"\n", "src": { "make.code.defn": "# Main make.code.defn file for thorn Poisson\n\n# Source files in this directory\nSRCS = uniform_charge.c\n\n# Subdirectories containing source files\nSUBDIRS = \n\n", "uniform_charge.c": "#include \n#include \n#include \n#include \n\n#include \n#include \n#include \n\n#include \n#include \n\n#include \n\n#include \n\n\n\nstatic int calc_residual (const cGH * const cctkGH,\n int const options_table,\n void * const userdata);\nstatic int apply_bounds (const cGH * const cctkGH,\n int const options_table,\n void * const userdata);\nstatic void apply_bounds_level (CCTK_ARGUMENTS);\n\n\n\nvoid Poisson_prepare (CCTK_ARGUMENTS)\n{\n DECLARE_CCTK_ARGUMENTS_Poisson_prepare;\n DECLARE_CCTK_PARAMETERS;\n \n /* Initial data for the solver */\n#pragma omp parallel for collapse(3)\n for (int k=0; k=0);\n \n /* Call solver */\n ierr = TATelliptic_CallSolver (cctkGH, var_ind, res_ind, NVAR,\n\t\t\t\t options_table,\n\t\t\t\t calc_residual, apply_bounds, 0,\n\t\t\t\t solver);\n if (ierr!=0) {\n CCTK_WARN (CCTK_WARN_ALERT, \"Failed to solve elliptic equation\");\n }\n \n ierr = Util_TableDestroy (options_table);\n assert (!ierr);\n}\n\n\n\n/* Caculate the residual */\nint calc_residual (const cGH * const cctkGH,\n int const options_table,\n void * const userdata)\n{\n DECLARE_CCTK_ARGUMENTS_Poisson_solve;\n DECLARE_CCTK_PARAMETERS;\n \n /* charge density */\n CCTK_REAL rho = charge / (4.0/3.0 * M_PI * pow(radius,3));\n \n /* offsets for 3D array layout */\n int di = CCTK_GFINDEX3D(cctkGH,1,0,0) - CCTK_GFINDEX3D(cctkGH,0,0,0);\n int dj = CCTK_GFINDEX3D(cctkGH,0,1,0) - CCTK_GFINDEX3D(cctkGH,0,0,0);\n int dk = CCTK_GFINDEX3D(cctkGH,0,0,1) - CCTK_GFINDEX3D(cctkGH,0,0,0);\n \n CCTK_REAL idx2[3];\t\t/* inverse squared grid spacing */\n for (int d=0; d<3; ++d) {\n idx2[d] = 1.0 / pow(CCTK_DELTA_SPACE(d), 2);\n }\n \n for (int d=0; d<3; ++d) {\n assert (cctk_nghostzones[d] >= 1);\n }\n\n /* Initialize residual to zero:\n We only do this to ensure the boundaries of the residual are\n defined, and are not nan. That in turn is only needed to make\n output look nicer. */\n#pragma omp parallel for collapse(3)\n for (int k=0; kR\n \\end{array}\n \\right.\n\\end{eqnarray}\nfor the charge $Q$ and the radius $R$, with $V=4\\pi R^3/3$. We use\nDirichlet boundary conditions $\\Phi(x)=0$.\n\n\\section{Numerical Implementation}\n\nPETSc supports a large number of options to choose solvers. Here we\nuse PETSc's default settings.\n\n\\section{Using This Thorn}\n\nIn the example parameter file, we set the parameter\n\\texttt{TATPETSc::options} to select the following PETSc options:\n\\begin{itemize}\n\\item \\verb+-snes_atol 1e-8+: set absolute tolerance for residual\n\\item \\verb+-snes_stol 1e-8+: set relative tolerance for residual\n\\item \\verb+-snes_monitor+: output progress information at each\n iteration of the non-linear solver\n\\item \\verb+-ksp_monitor+: output progress information at each\n iteration of the linear (Krylov subspace) solver\n\\end{itemize}\n\n\\subsection{Examples}\n\nThe solution (the potential $\\Phi(x)$) is stored in the grid function\n\\texttt{potential}, the residual (a measure for the error) in the grid\nfunction \\texttt{residual}.\n\n% Do not delete next line\n% END CACTUS THORNGUIDE\n\n\\end{document}\n" } }