Skip to content

Commit

Permalink
Add function to estimate number of cells as power of 2 (#36)
Browse files Browse the repository at this point in the history
- Add small function to get closest power of 2
- Update live notebook
  • Loading branch information
santisoler authored Jan 29, 2024
1 parent 047ba56 commit dde2665
Show file tree
Hide file tree
Showing 2 changed files with 185 additions and 136 deletions.
27 changes: 20 additions & 7 deletions live/01-forward-dc-resisitivity-2d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,31 @@
"metadata": {},
"outputs": [],
"source": [
"# Number of base cells along x and y\n",
"nbcx = 2 ** int(np.round(np.log(dom_width_x / dh) / np.log(2.0)))\n",
"nbcy = 2 ** int(np.round(np.log(dom_width_y / dh) / np.log(2.0)))\n",
"def get_closest_power_of_2(x):\n",
" \"\"\"\n",
" Get the closest power of 2 to the given x\n",
" \"\"\"\n",
" return 2 ** int(np.round(np.log(x) / np.log(2.0)))\n",
"\n",
"# Number of base cells along x and y\n",
"n_base_cells_x = get_closest_power_of_2(n_cells_x)\n",
"n_base_cells_y = get_closest_power_of_2(n_cells_y)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Define the base mesh with top at z = 0 m.\n",
"hx = [(dh, nbcx)]\n",
"hy = [(dh, nbcy)]\n",
"hx = [(dh, n_base_cells_x)]\n",
"hy = [(dh, n_base_cells_y)]\n",
"mesh = TreeMesh([hx, hy], origin=\"CN\")\n",
"\n",
"# Shift top to maximum topography and center of survey line\n",
"y_topo_max = np.max(topo_2d[:, -1])\n",
"mesh.origin = mesh.origin + np.r_[0, y_topo_max]"
"x_center = survey.unique_electrode_locations[:, 0].mean()\n",
"mesh.origin = mesh.origin + np.r_[x_center, y_topo.max()]"
]
},
{
Expand Down
Loading

0 comments on commit dde2665

Please sign in to comment.