{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 17188 characters]",
      "text/plain": [
       "<Figure size 640x480 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 39080 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=[500, 500])\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.1)\n",
    "sim.set_save_path(\"data/diffusion_test\")\n",
    "sim.set_autosave_flag(True)\n",
    "sim.set_autosave_save_images_flag(True)\n",
    "sim.set_autosave_rate(2000)\n",
    "sim.set_boundary_conditions(\"PERIODIC\")\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_fields_and_imported_data()\n",
    "\n",
    "#change array data here, for custom simulations\n",
    "\n",
    "#set the field values manually using numpy slicing\n",
    "sim.fields[0].data[:] = 0.\n",
    "length = sim.dimensions[0]\n",
    "width = sim.dimensions[1]\n",
    "sim.fields[0].data[length // 4:3 * length // 4, width // 4:3 * width // 4] = 1.\n",
    "\n",
    "\n",
    "\n",
    "#initial conditions\n",
    "sim.plot_simulation()\n",
    "\n",
    "#run simulation\n",
    "sim.simulate(2000)\n",
    "\n",
    "#final conditions\n",
    "sim.plot_simulation()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "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": 4
}
