|
540 | 540 | " # Note: I didn't realize this when I originally wrote the class, but we won't actually need dz\n",
|
541 | 541 | " # Want to know why? Check out the documentation for np.gradient -> https://numpy.org/doc/stable/reference/generated/numpy.gradient.html\n",
|
542 | 542 | " # (What does the second argument to np.gradient do?)\n",
|
543 |
| - " \n", |
| 543 | + "\n", |
544 | 544 | " # We'll need attributes for rho, c, and k\n",
|
545 | 545 | " # You could also store info about boundary conditions at this point, if you want\n",
|
546 | 546 | " self.rho = 917\n",
|
547 | 547 | " self.c = 2093\n",
|
548 | 548 | " self.k = 2.1\n",
|
549 | 549 | "\n",
|
550 | 550 | " # Let's store boundary conditions too\n",
|
551 |
| - " \n", |
| 551 | + "\n", |
552 | 552 | " # Maybe we should go ahead and calculate diffusivity right away?\n",
|
553 |
| - " \n", |
| 553 | + "\n", |
554 | 554 | " # Let's keep track of the elapsed time\n",
|
555 | 555 | "\n",
|
556 | 556 | " def calc_diffusivity(self) -> float:\n",
|
|
559 | 559 | "\n",
|
560 | 560 | " def calc_heat_flux(self) -> np.ndarray:\n",
|
561 | 561 | " \"\"\"The heat flux is -kappa * dT / dz.\"\"\"\n",
|
562 |
| - " \n", |
| 562 | + "\n", |
563 | 563 | " # How should we calculate the difference in temperature with depth? (hint: see dz, above)\n",
|
564 | 564 | "\n",
|
565 | 565 | " # Are dT and dz the same size? Are they the same size as z?\n",
|
|
634 | 634 | "\n",
|
635 | 635 | "dt = 60 * 60 * 24 * 20\n",
|
636 | 636 | "\n",
|
637 |
| - "for i in range(30000): \n", |
| 637 | + "for i in range(30000):\n", |
638 | 638 | " model.run_one_step(dt)\n",
|
639 | 639 | "\n",
|
640 | 640 | " if i % 1000 == 0:\n",
|
641 |
| - " print(f'{model.time_elapsed / 31556926} years.')\n", |
| 641 | + " print(f\"{model.time_elapsed / 31556926} years.\")\n", |
642 | 642 | "\n",
|
643 | 643 | "plt.plot(model.temperature, model.z)\n",
|
644 |
| - "plt.xlabel('Temperature ($^\\circ$ C)')\n", |
645 |
| - "plt.ylabel('Depth (m)')\n", |
646 |
| - "plt.gca().invert_yaxis() # This forces matplotlib to invert the y-axis\n", |
| 644 | + "plt.xlabel(r\"Temperature ($^\\circ$ C)\")\n", |
| 645 | + "plt.ylabel(\"Depth (m)\")\n", |
| 646 | + "plt.gca().invert_yaxis() # This forces matplotlib to invert the y-axis\n", |
647 | 647 | "plt.show()"
|
648 | 648 | ]
|
649 | 649 | },
|
|
662 | 662 | "metadata": {},
|
663 | 663 | "outputs": [],
|
664 | 664 | "source": [
|
665 |
| - "# Initialize your model with a new bottom boundary condition\n", |
666 |
| - "\n" |
| 665 | + "# Initialize your model with a new bottom boundary condition" |
667 | 666 | ]
|
668 | 667 | },
|
669 | 668 | {
|
|
675 | 674 | "source": [
|
676 | 675 | "dt = 60 * 60 * 24 * 20\n",
|
677 | 676 | "\n",
|
678 |
| - "for i in range(30000): \n", |
| 677 | + "for i in range(30000):\n", |
679 | 678 | " model.run_one_step(dt)\n",
|
680 | 679 | "\n",
|
681 | 680 | " if i % 1000 == 0:\n",
|
682 |
| - " print(f'{model.time_elapsed / 31556926} years.')\n", |
| 681 | + " print(f\"{model.time_elapsed / 31556926} years.\")\n", |
683 | 682 | "\n",
|
684 | 683 | "plt.plot(model.temperature, model.z)\n",
|
685 |
| - "plt.xlabel('Temperature ($^\\circ$ C)')\n", |
686 |
| - "plt.ylabel('Depth (m)')\n", |
687 |
| - "plt.gca().invert_yaxis() # This forces matplotlib to invert the y-axis\n", |
| 684 | + "plt.xlabel(r\"Temperature ($^\\circ$ C)\")\n", |
| 685 | + "plt.ylabel(\"Depth (m)\")\n", |
| 686 | + "plt.gca().invert_yaxis() # This forces matplotlib to invert the y-axis\n", |
688 | 687 | "plt.show()"
|
689 | 688 | ]
|
690 | 689 | },
|
|
717 | 716 | "source": [
|
718 | 717 | "class SimpleGlacier:\n",
|
719 | 718 | " \"\"\"Models the temperature profile with a glacier.\n",
|
720 |
| - " \n", |
721 |
| - " This model is based off of: \n", |
| 719 | + "\n", |
| 720 | + " This model is based off of:\n", |
722 | 721 | " The Physics of Glaciers (Cuffey and Paterson, 2010).\n",
|
723 | 722 | " Lecture notes from Andy Aschwanden (McCarthy school, summer 2012).\n",
|
724 | 723 | "\n",
|
|
736 | 735 | " self.dz = np.gradient(self.z)\n",
|
737 | 736 | " # Note: I didn't realize this when I originally wrote the class, but we won't need dz\n",
|
738 | 737 | " # Want to know why? Check out the documentation for np.gradient -> https://numpy.org/doc/stable/reference/generated/numpy.gradient.html\n",
|
739 |
| - " \n", |
| 738 | + "\n", |
740 | 739 | " # We'll need attributes for rho, c, and k\n",
|
741 | 740 | " # You could also store info about boundary conditions at this point, if you want\n",
|
742 | 741 | " self.rho = 917\n",
|
|
746 | 745 | " # Let's store boundary conditions too\n",
|
747 | 746 | " self.surface_temperature = -10.0\n",
|
748 | 747 | " self.basal_heat_flux = 0.0\n",
|
749 |
| - " \n", |
| 748 | + "\n", |
750 | 749 | " # Maybe we should go ahead and calculate diffusivity right away?\n",
|
751 | 750 | " self.kappa = self.calc_diffusivity()\n",
|
752 |
| - " \n", |
| 751 | + "\n", |
753 | 752 | " # Let's keep track of the elapsed time\n",
|
754 | 753 | " self.time_elapsed = 0.0\n",
|
755 | 754 | "\n",
|
|
759 | 758 | "\n",
|
760 | 759 | " def calc_heat_flux(self) -> np.ndarray:\n",
|
761 | 760 | " \"\"\"The heat flux is -kappa * dT / dz.\"\"\"\n",
|
762 |
| - " \n", |
| 761 | + "\n", |
763 | 762 | " # How should we calculate the difference in temperature with depth? (hint: see dz, above)\n",
|
764 | 763 | " temperature_gradient = np.gradient(self.temperature, self.z)\n",
|
765 | 764 | "\n",
|
|
770 | 769 | " temperature_gradient[-1] = self.basal_heat_flux\n",
|
771 | 770 | "\n",
|
772 | 771 | " return -self.kappa * temperature_gradient\n",
|
773 |
| - " \n", |
| 772 | + "\n", |
774 | 773 | " def calc_divergence(self) -> np.ndarray:\n",
|
775 | 774 | " \"\"\"In 1D, divergence is just the derivative. yay!\"\"\"\n",
|
776 | 775 | " heat_flux = self.calc_heat_flux()\n",
|
777 |
| - " \n", |
| 776 | + "\n", |
778 | 777 | " flux_divergence = np.gradient(heat_flux, self.z)\n",
|
779 |
| - " \n", |
| 778 | + "\n", |
780 | 779 | " return flux_divergence\n",
|
781 |
| - " \n", |
| 780 | + "\n", |
782 | 781 | " def run_one_step(self, dt: float):\n",
|
783 | 782 | " \"\"\"Advance the model by one step of size dt.\"\"\"\n",
|
784 | 783 | " flux_divergence = self.calc_divergence()\n",
|
|
0 commit comments