{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "33d2a615-7e14-4f64-912f-f60c8e4f7dba",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 23812 characters]",
      "text/plain": [
       "<Figure size 640x480 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 64100 characters]",
      "text/plain": [
       "<Figure size 640x480 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 69380 characters]",
      "text/plain": [
       "<Figure size 640x480 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import pyphasefield.Engines as engines\n",
    "\n",
    "sim = engines.Diffusion(dimensions=[200, 200])\n",
    "\n",
    "#initialize non-array parameters\n",
    "sim.set_framework(\"CPU_SERIAL\") #\"CPU_SERIAL\", \"GPU_SERIAL\" (GPU_SERIAL requires numba)\n",
    "sim.set_dx(1.)\n",
    "sim.set_dt(0.2)\n",
    "sim.set_save_path(\"data/boundary_conditions_test\")\n",
    "sim.set_autosave_flag(False)\n",
    "sim.set_boundary_conditions([[\"DIRICHLET\", \"NEUMANN\"], [\"DIRICHLET\", \"NEUMANN\"]])\n",
    "\n",
    "data = {\n",
    "    \"D\":1.\n",
    "}\n",
    "sim.set_user_data(data)\n",
    "\n",
    "#initialize simulation arrays, all parameter changes should be BEFORE this point!\n",
    "sim.initialize_engine()\n",
    "\n",
    "#change array data here, for custom simulations\n",
    "\n",
    "#set the field values manually using numpy slicing, setting it to one everywhere\n",
    "sim.fields[0].data[:] = 1.\n",
    "\n",
    "#set the boundary fields!\n",
    "#X-axis Dirichlet, commented lines are default behavior\n",
    "#sim.boundary_fields[0].data[:50, 0] = 0.\n",
    "sim.boundary_fields[0].data[50:100, 0] = 2.\n",
    "#sim.boundary_fields[0].data[100:150, 0] = 0.\n",
    "sim.boundary_fields[0].data[150:, 0] = 2.\n",
    "\n",
    "#Y-axis Dirichlet\n",
    "sim.boundary_fields[0].data[0, :66] = 1.\n",
    "sim.boundary_fields[0].data[0, 133:] = 1.\n",
    "sim.boundary_fields[0].data[0, 66:133] = 4.\n",
    "\n",
    "#Neumann X-axis has no change, equivalent to the bottom line\n",
    "#sim.boundary_fields[0].data[:, -1] = 0.\n",
    "\n",
    "#Neumann Y-axis\n",
    "sim.boundary_fields[0].data[-1, :40] = 0.05\n",
    "sim.boundary_fields[0].data[-1, 40:80] = -0.05\n",
    "sim.boundary_fields[0].data[-1, 80:120] = 0.05\n",
    "sim.boundary_fields[0].data[-1, 120:160] = -0.05\n",
    "sim.boundary_fields[0].data[-1, 160:] = 0.05\n",
    "\n",
    "#initial conditions\n",
    "sim.plot_simulation()\n",
    "\n",
    "#run simulation\n",
    "sim.simulate(2000)\n",
    "\n",
    "#final conditions\n",
    "sim.plot_simulation()\n",
    "\n",
    "#run simulation\n",
    "sim.simulate(48000)\n",
    "\n",
    "#final conditions\n",
    "sim.plot_simulation()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e568a6b4-82d3-41c0-bab6-8270323fd2a7",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
