Skip to content

Commit

Permalink
deploy: 1c6a41b
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchengtkc committed Nov 16, 2023
1 parent f58625e commit 933f2d3
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 25 deletions.
65 changes: 56 additions & 9 deletions _sources/notebooks/3D_simulation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@
"outputs": [],
"source": [
"for i in model.builder.iter_node():\n",
" i.rift=[[182,175]]"
" i.rift=[[182,175]]\n",
" i.bflux = False\n",
" i.adiab = 0.3e-3 "
]
},
{
Expand All @@ -158,7 +160,9 @@
"metadata": {},
"outputs": [],
"source": [
"model.simulator.simulate_every = 1"
"model.simulator.simulate_every = 1\n",
"model.parameters.HPdcr = 1e11 # set to \"infinite\" decay\n",
"model.parameters.bflux = False # set to \"infinite\" decay\n"
]
},
{
Expand Down Expand Up @@ -230,7 +234,7 @@
"# interpolate and extrapolate the missing nodes\n",
"# find nearby nodes from the array indexer_full_sim, which is sorted by x-index\n",
"import itertools\n",
"from subsheat3D.fixed_mesh_model import interpolateNode\n",
"from warmth3d.fixed_mesh_model import interpolateNode\n",
"for ni in range(len(model.builder.nodes)):\n",
" for nj in range(len(model.builder.nodes[ni])):\n",
" if model.builder.nodes[ni][nj] is False:\n",
Expand Down Expand Up @@ -269,8 +273,7 @@
" model.builder.nodes[ni][nj] = node\n",
" # if (model.builder.nodes[ni][nj].Y>12000):\n",
" # model.builder.nodes[ni][nj].crustRHP = (2e-6) * 4\n",
" # model.builder.nodes[ni][nj].rhp = (2e-6) * 4\n",
" model.builder.nodes[ni][nj].crustRHP = (2e0) * 1\n"
" # model.builder.nodes[ni][nj].rhp = (2e-6) * 4\n"
]
},
{
Expand Down Expand Up @@ -308,7 +311,7 @@
" os.mkdir('temp')\n",
"except FileExistsError:\n",
" pass\n",
"run(model,start_time=model.parameters.time_start,end_time=0)\n",
"mm2 = run(model,start_time=model.parameters.time_start,end_time=0)\n",
"\n"
]
},
Expand All @@ -317,12 +320,51 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"import numpy as np\n",
"hx = model.builder.grid.num_nodes_x // 2\n",
"hy = model.builder.grid.num_nodes_y // 2\n",
"# hx = model.builder.grid.num_nodes_x - 1 - pad\n",
"# hy = model.builder.grid.num_nodes_y - 1 - pad\n",
"\n",
"nn = model.builder.nodes[hy][hx]\n",
"dd = nn._depth_out[:,0]\n",
"\n",
"node_ind = hy*model.builder.grid.num_nodes_x + hx\n",
"v_per_n = int(mm2.mesh_vertices.shape[0]/(model.builder.grid.num_nodes_y*model.builder.grid.num_nodes_x))\n",
"\n",
"temp_1d = np.nan_to_num(nn.temperature_out[:,0], nan=5.0)\n",
"temp_3d_ind = np.array([ np.where([mm2.mesh_reindex==i])[1][0] for i in range(node_ind*v_per_n, (node_ind+1)*v_per_n) ] )\n",
"dd_mesh = mm2.mesh.geometry.x[temp_3d_ind,2]\n",
"temp_3d_mesh = mm2.u_n.x.array[temp_3d_ind]\n",
"\n",
"temp_1d_at_mesh_pos = np.interp(dd_mesh, dd, temp_1d)\n",
"dd_subset = np.where(dd_mesh<5000)\n",
"print(f'Max. absolute error in temperature at 3D mesh vertex positions: {np.amax(np.abs(temp_1d_at_mesh_pos-temp_3d_mesh))}')\n",
"print(f'Max. absolute error at depths < 5000m: {np.amax(np.abs(temp_1d_at_mesh_pos[dd_subset]-temp_3d_mesh[dd_subset]))}')\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib\n",
"import matplotlib as plt\n",
"plt.use('TkAgg')\n",
"\n",
"plt.pyplot.plot( dd, temp_1d, label=f'1D simulation'); \n",
"# plt.pyplot.plot( dd, temp_3d, label=f'3D simulation'); \n",
"plt.pyplot.plot( dd_mesh, temp_3d_mesh, 'o', label=f'3D simulation (nodes)'); \n",
"plt.pyplot.legend(loc=\"lower right\", prop={'size': 7})\n",
"plt.pyplot.show()\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"display_name": "Python 3.9.10 64-bit",
"language": "python",
"name": "python3"
},
Expand All @@ -336,7 +378,12 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
"version": "3.9.10"
},
"vscode": {
"interpreter": {
"hash": "e51a2b4e99f2ffc4c1b139fefabaf83a9a6f27184f9cac248baef6121453d47a"
}
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion apireference.html
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ <h1>API Reference<a class="headerlink" href="#api-reference" title="Link to this

<dl class="py method">
<dt class="sig sig-object py" id="warmth.forward_modelling.Forward_model.implicit_euler_solve">
<span class="sig-name descname"><span class="pre">implicit_euler_solve</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">T_start</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">ndarray</span><span class="p"><span class="pre">[</span></span><span class="pre">float64</span><span class="p"><span class="pre">]</span></span></span></em>, <em class="sig-param"><span class="n"><span class="pre">coord_all</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">ndarray</span><span class="p"><span class="pre">[</span></span><span class="pre">float64</span><span class="p"><span class="pre">]</span></span></span></em>, <em class="sig-param"><span class="n"><span class="pre">density_all</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">ndarray</span><span class="p"><span class="pre">[</span></span><span class="pre">float64</span><span class="p"><span class="pre">]</span></span></span></em>, <em class="sig-param"><span class="n"><span class="pre">conductivity_packed</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">ndarray</span><span class="p"><span class="pre">[</span></span><span class="pre">float64</span><span class="p"><span class="pre">]</span></span></span></em>, <em class="sig-param"><span class="n"><span class="pre">source</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">ndarray</span><span class="p"><span class="pre">[</span></span><span class="pre">float64</span><span class="p"><span class="pre">]</span></span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k_last_node</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">float</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">HP_last_node</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">float</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">tuple</span><span class="p"><span class="pre">[</span></span><span class="pre">ndarray</span><span class="p"><span class="pre">[</span></span><span class="pre">float64</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="pre">ndarray</span><span class="p"><span class="pre">[</span></span><span class="pre">float64</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></span></span><a class="headerlink" href="#warmth.forward_modelling.Forward_model.implicit_euler_solve" title="Link to this definition"></a></dt>
<span class="sig-name descname"><span class="pre">implicit_euler_solve</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">T_start</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">ndarray</span><span class="p"><span class="pre">[</span></span><span class="pre">float64</span><span class="p"><span class="pre">]</span></span></span></em>, <em class="sig-param"><span class="n"><span class="pre">coord_all</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">ndarray</span><span class="p"><span class="pre">[</span></span><span class="pre">float64</span><span class="p"><span class="pre">]</span></span></span></em>, <em class="sig-param"><span class="n"><span class="pre">density_all</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">ndarray</span><span class="p"><span class="pre">[</span></span><span class="pre">float64</span><span class="p"><span class="pre">]</span></span></span></em>, <em class="sig-param"><span class="n"><span class="pre">conductivity_packed</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">ndarray</span><span class="p"><span class="pre">[</span></span><span class="pre">float64</span><span class="p"><span class="pre">]</span></span></span></em>, <em class="sig-param"><span class="n"><span class="pre">source</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">ndarray</span><span class="p"><span class="pre">[</span></span><span class="pre">float64</span><span class="p"><span class="pre">]</span></span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k_last_node</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">float</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">HP_last_node</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">float</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">T_base</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">float</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">tuple</span><span class="p"><span class="pre">[</span></span><span class="pre">ndarray</span><span class="p"><span class="pre">[</span></span><span class="pre">float64</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="pre">ndarray</span><span class="p"><span class="pre">[</span></span><span class="pre">float64</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></span></span><a class="headerlink" href="#warmth.forward_modelling.Forward_model.implicit_euler_solve" title="Link to this definition"></a></dt>
<dd><p>Solve heat equation using backward Euler scheme</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
Expand Down
Loading

0 comments on commit 933f2d3

Please sign in to comment.