Created
October 8, 2023 06:40
-
-
Save ketch/ee9aedb7dd13968454b29c8449662b68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"id": "68dec962-d4fe-431f-bf63-2598a4894ad9", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from homog_pseudospectral import homogenized_coefficients\n", | |
"import numpy as np" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"id": "b4df0e30-f101-4c1f-81e7-4ea4ae400516", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def set_bathymetry(bathy, b_amp):\n", | |
" if bathy == 'sinusoidal':\n", | |
" b = lambda y: b_amp/2*np.sin(2*np.pi*y) - b_amp\n", | |
" elif bathy == 'tanh':\n", | |
" s = 1000 # Smoothing parameter\n", | |
" b = lambda y: -1+b_amp*(1+(np.tanh(s*(y-0.25))*(-np.tanh(s*(y-0.75)))))/2\n", | |
" elif bathy == 'pwc': # piecewise-constant\n", | |
" b = lambda y: -1 + b_amp*((y-np.floor(y))>0.25)*((y-np.floor(y))<=0.75)\n", | |
" n0 = 0\n", | |
" H = lambda y: n0-b(y)\n", | |
" return H" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 16, | |
"id": "29123500-3235-4209-ab99-652bc6c6f1ee", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"H1 2.1666666666666665\n", | |
"H2 6.0555555555555545\n", | |
"H3 19.01851851851851\n", | |
"H4 62.22839506172836\n", | |
"H5 206.26131687242784\n", | |
"alpha1 -19.48849441157132\n", | |
"alpha2 -79.54475308641969\n", | |
"alpha3 -0.44606281292671707\n", | |
"alpha4 69.26543209876543\n", | |
"alpha5 68.79141590384191\n", | |
"alpha6 132.4074074074074\n", | |
"alpha7 0.686250481425725\n", | |
"alpha8 0.012367091488393262\n", | |
"alpha9 0.005610097685655263\n", | |
"alpha10 0.0014514197682153984\n", | |
"alpha11 0.006077605826126535\n", | |
"delta 1.0\n", | |
"C11 -0.0033177083333333327\n", | |
"C3 -0.002552083333333333\n" | |
] | |
} | |
], | |
"source": [ | |
"bathy_type = 'pwc'\n", | |
"bathy_amp = 0.7\n", | |
"H = set_bathymetry(bathy_type,bathy_amp)\n", | |
"params = homogenized_coefficients(H, bathy_type,bathy_amp)\n", | |
"for key, value in params.items():\n", | |
" print(f'{key: <10} {value}')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 17, | |
"id": "502b94d9-c8aa-444a-bd92-043da4c992f3", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"H1 1.443375672974064\n", | |
"H2 2.405626121623441\n", | |
"H3 4.510548978043952\n", | |
"H4 9.188155325645084\n", | |
"H5 19.751053588271155\n", | |
"alpha1 -6.944444444444445\n", | |
"alpha2 -11.612094099578735\n", | |
"alpha3 -0.24056261216234365\n", | |
"alpha4 12.883579431507263\n", | |
"alpha5 16.203703703703695\n", | |
"alpha6 31.359239330450514\n", | |
"alpha7 0.40093768693723963\n", | |
"alpha8 0.01525547057765196\n", | |
"alpha9 0.03422277720453657\n", | |
"alpha10 -0.0032710442743610776\n", | |
"alpha11 0.024698162039319713\n", | |
"delta 1.0\n", | |
"C11 -0.02421350756283714\n", | |
"C3 -0.007718175637287405\n" | |
] | |
} | |
], | |
"source": [ | |
"bathy_type = 'sinusoidal'\n", | |
"bathy_amp = 0.8\n", | |
"H = set_bathymetry(bathy_type,bathy_amp)\n", | |
"params = homogenized_coefficients(H, bathy_type,bathy_amp)\n", | |
"for key, value in params.items():\n", | |
" print(f'{key: <10} {value}')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "600e8931-bd95-4ec4-9b96-b375db5478b6", | |
"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.11.4" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment