{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<script async src=\"https://www.googletagmanager.com/gtag/js?id=UA-59152712-8\"></script>\n",
    "<script>\n",
    "  window.dataLayer = window.dataLayer || [];\n",
    "  function gtag(){dataLayer.push(arguments);}\n",
    "  gtag('js', new Date());\n",
    "\n",
    "  gtag('config', 'UA-59152712-8');\n",
    "</script>\n",
    "\n",
    "# The NRPy+ code required to generate the needed C code for the lowering operator: $g_{ij} \\beta^i$, with the result set to C variables \"`betaD0out`\", \"`betaD1out`\", and \"`betaD2out`\" \n",
    "\n",
    "## *Courtesy Zach Etienne*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-03-07T17:12:01.961884Z",
     "iopub.status.busy": "2021-03-07T17:12:01.960660Z",
     "iopub.status.idle": "2021-03-07T17:12:02.366355Z",
     "shell.execute_reply": "2021-03-07T17:12:02.365760Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/*\n",
      " *  Original SymPy expressions:\n",
      " *  \"[betaD0out = betaU0*hDD00 + betaU1*hDD01 + betaU2*hDD02,\n",
      " *    betaD1out = betaU0*hDD01 + betaU1*hDD11 + betaU2*hDD12,\n",
      " *    betaD2out = betaU0*hDD02 + betaU1*hDD12 + betaU2*hDD22]\"\n",
      " */\n",
      "{\n",
      "  betaD0out = betaU0*hDD00 + betaU1*hDD01 + betaU2*hDD02;\n",
      "  betaD1out = betaU0*hDD01 + betaU1*hDD11 + betaU2*hDD12;\n",
      "  betaD2out = betaU0*hDD02 + betaU1*hDD12 + betaU2*hDD22;\n",
      "}\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# The NRPy_param_funcs module sets up global structures that manage free parameters within NRPy+\n",
    "import NRPy_param_funcs as par   # NRPy+: Parameter interface\n",
    "# The indexedexp module defines various functions for defining and managing indexed quantities like tensors and pseudotensors\n",
    "import indexedexp as ixp         # NRPy+: Symbolic indexed expression (e.g., tensors, vectors, etc.) support\n",
    "# The grid module defines various parameters related to a numerical grid or the dimensionality of indexed expressions\n",
    "# For example, it declares the parameter DIM, which specifies the dimensionality of the indexed expression\n",
    "import grid as gri               # NRPy+: Functions having to do with numerical grids\n",
    "from outputC import outputC      # NRPy+: Basic C code output functionality\n",
    "\n",
    "# Set the dimension to 3\n",
    "par.set_parval_from_str(\"DIM\",3)\n",
    "\n",
    "# Declare rank-1 contravariant (\"U\" and \"D\") vectors\n",
    "betaU = ixp.declarerank1(\"betaU\")\n",
    "betaD = ixp.zerorank1()\n",
    "\n",
    "# Declare h_{ij}=hDD[i][j] and h^{ij}=hUU[i][j]\n",
    "hDD = ixp.declarerank2(\"hDD\",\"sym01\")\n",
    "\n",
    "# Get the dimension we just set (should be set to 3).\n",
    "DIM = par.parval_from_str(\"DIM\")\n",
    "\n",
    "for i in range(DIM):\n",
    "    for j in range(DIM):\n",
    "        betaD[j] += betaU[i]*hDD[i][j]\n",
    "\n",
    "outputC(betaD,[\"betaD0out\",\"betaD1out\",\"betaD2out\"])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}