From 4b30c98f026d091473cbae0a7cc850d2b4a6dca9 Mon Sep 17 00:00:00 2001 From: Pantelis Sopasakis Date: Wed, 27 Nov 2024 17:25:27 +0000 Subject: [PATCH 1/3] implement grid class --- pdesolvers/__init__.py | 1 + .../__pycache__/__init__.cpython-39.pyc | Bin 0 -> 182 bytes pdesolvers/__pycache__/grid.cpython-39.pyc | Bin 0 -> 3270 bytes pdesolvers/grid.py | 86 ++++++++++++++++++ requirements.txt | 1 + 5 files changed, 88 insertions(+) create mode 100644 pdesolvers/__init__.py create mode 100644 pdesolvers/__pycache__/__init__.cpython-39.pyc create mode 100644 pdesolvers/__pycache__/grid.cpython-39.pyc create mode 100644 pdesolvers/grid.py create mode 100644 requirements.txt diff --git a/pdesolvers/__init__.py b/pdesolvers/__init__.py new file mode 100644 index 0000000..f4a65f3 --- /dev/null +++ b/pdesolvers/__init__.py @@ -0,0 +1 @@ +from .grid import * \ No newline at end of file diff --git a/pdesolvers/__pycache__/__init__.cpython-39.pyc b/pdesolvers/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2014acad842ba456ec7997f2c1ec9202e3719578 GIT binary patch literal 182 zcmYe~<>g`kf*IcK>B2zzF^Gc(44TX@8G%BYjJFuI z{4^P(Skj9!Q&ut*F#`p`#4k7f(BjmhVtr!+Qxjt|V||zWeK3qqGOZHS%y0G-%xbX)a7%mgcTxIuxnw zQm!S)m)bylD$r}ugMG|j;w$)G;TwY zKY-wxO_*lujKD0lf^G5wJI@NNxKH+oU4&MNS^FB)OHiL+WmUJ>B&+Oe_5_<^)9@~{ zGi(Ollk6-z2k#0q0mFr)^kDUyhr(z5J7o&b9om8hZAOC1DA@MH7Ja;WU(%oac#}5$ z(2qG~ezVC14?Qkvo5!0GlWML<0C4`G6;k!v8BHqe|@f<;i*l{8}Wuy6#Yby3?T zP%jP$(=TdAWLF=MtetkJ+caf{6!lSoIp5W9Z4psVg`|7y3<~GrG}JqplEcFC{YWxdU#B+SCmhRO2XJGwilE zxWM%~kq>U5ZV*9)aM#;}s6Z^>d$oMa-{v7ukA_aFS}zaHdF&zqVsO&1>&EaIb}e;K zEyJ-y6`wF1JCXEp8wnui6zJ-kbK+=;a)3Uje2Q+4Z;8HP+$l4>C=$#MA>N$8-Qa;- zqN6UFcGW1ax9TzRv#_WauMb7(f;P=79DtYy}h~#MP`#WyC6YwFTp#yFVyBVXjAs`77Xt?c&NOPle zt=1@uM(9^oR&s`ZNyAQE@n85vd}8A6Huh7>Me)TF!*ysu|?Q;%nL%iYkkO zdY(SgEbL@asz&G1II5{2stu!IwDYk`Lx<#IK{*daUIWpBi(>r>TnySFIUobLBo5$O z0I8uoGJe%xz%{0lWmQk~uwz>Rrf1jV*sd=m#D8TZR&HBTOz|Wp2DO?ereL3>yd3y4 z_M&!Y0f%w*&OpJ zUeH+XL6HaoymLb{wmVmy@GabqV-<~_x!6-QlP3t zITuc9@&sVTH2pmo0wDeA96&nsE*qhH#AhdLV>> x_start = np.array([0, 0, 0]) + >>> x_end = np.array([1, 2, 3]) + >>> num_points = np.array([10, 20, 31]) + >>> unif_grid = FDMGrid.create_uniform_grid(x_start, x_end, num_points) + """ + gr = FDMGrid() + n = x_from.size + gr.__grid = np.meshgrid(*[np.linspace(x_from[i], x_to[i], n_points[i]) for i in range(n)]) + gr.__values = np.zeros(n_points) + gr.__geometry = {"geometry": "rectangular", + "grid_type": "uniform", + "from": x_from, + "to": x_to} + if coordinate_labels is not None: + gr.__geometry["coordinate_labels"] = coordinate_labels + return gr + + @classmethod + def create_dense_at_boundary_grid(cls, x_from, x_to, n_points, density_boosting=2.0, coordinate_labels=None): + pass + + @classmethod + def create_grid_nonsquare_geometry(cls): + pass + + def values(self): + return self.__values + + def mesh(self): + return self.__grid + + def mask(self): + return self.__mask + + def plot(self): + # Plot the values on your grid + # You'll need a different implementation for different dimensions + # The user could be given the option to see a plot or an animation + # The plot should be configurable by the user + pass + + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..296d654 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +numpy \ No newline at end of file From ea8a185967339894fafa21ca0477785ef235c0ec Mon Sep 17 00:00:00 2001 From: Pantelis Sopasakis Date: Wed, 27 Nov 2024 17:54:27 +0000 Subject: [PATCH 2/3] proposed structure --- pdesolvers/__init__.py | 3 ++- .../__pycache__/__init__.cpython-39.pyc | Bin 182 -> 206 bytes pdesolvers/__pycache__/grid.cpython-39.pyc | Bin 3270 -> 3512 bytes .../__pycache__/heat_solvers.cpython-39.pyc | Bin 0 -> 1321 bytes pdesolvers/black_scholes_solvers.py | 5 ++++ pdesolvers/grid.py | 6 +++++ pdesolvers/heat_solvers.py | 22 ++++++++++++++++++ 7 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 pdesolvers/__pycache__/heat_solvers.cpython-39.pyc create mode 100644 pdesolvers/black_scholes_solvers.py create mode 100644 pdesolvers/heat_solvers.py diff --git a/pdesolvers/__init__.py b/pdesolvers/__init__.py index f4a65f3..46c586d 100644 --- a/pdesolvers/__init__.py +++ b/pdesolvers/__init__.py @@ -1 +1,2 @@ -from .grid import * \ No newline at end of file +from .grid import * +from .heat_solvers import * \ No newline at end of file diff --git a/pdesolvers/__pycache__/__init__.cpython-39.pyc b/pdesolvers/__pycache__/__init__.cpython-39.pyc index 2014acad842ba456ec7997f2c1ec9202e3719578..1110019bf7f6d9c5d0161087309cc700ee9f125c 100644 GIT binary patch delta 92 zcmdnSc#e@bk(ZZ?0SK;zxu@$-LLf9FkY);I&}4qe2$a%fyv3;H lr^yt>l3tXV62+5|nphHFoS##cT2wsIKZ(7V38;vJ5df9K6!riB delta 68 zcmX@dxQ&rFk(ZZ?0SIPzyQd3JLKsq*f*CZKUorxPG#PI(YWZn0 SMzN$9Wu{C_O=A5F(gpy_SPlFD diff --git a/pdesolvers/__pycache__/grid.cpython-39.pyc b/pdesolvers/__pycache__/grid.cpython-39.pyc index 0bc0030beecb95ab89e0a40dff5481848ddc3deb..812f652a7f8b2714f22cd46a7d74379a5c7ad963 100644 GIT binary patch delta 554 zcmX|7Jx|;~5Zzt-_UyHNd_!^xkq;e-9HDe6=r}0?8jj-fp;(cS@5Ta4u#VO~DYytl zPKlHbZ9$(VbwopzGCzWX0tq2S%74h%$1$sYvv1za?Ckz|c=4zad7dC>Ki_WczjjU= zaB_ewCLsk9GN7RW42%&8&A0}OPy;@qUuejYErA7g#p=ieI3t3J1ul4)Z$ks7&; zZ?oZ%zUJ>{Dq+q4w1@FEUk;DXH|sZa>9%|c+Qxv74;6B~Za;n=aJ7t7&6luH!W=?4 z4YACU{CKaQrdgiIebvvo>fw`|d$JT|4*i3ewS+KKPRC+-xetJm}h_A|}zjUbC?=syK9i^|EG zw5gsUrir@d-3-pXGHXL7X;s(hJ=mrPEktQjq?e`W-=z5gedq=l`q3A(Wuiu%QxAmj Rv<-U02IZ9FRZV@f_YXQGMa2LB diff --git a/pdesolvers/__pycache__/heat_solvers.cpython-39.pyc b/pdesolvers/__pycache__/heat_solvers.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d31a423cd657356a24ed2dd154b7395be34a7a66 GIT binary patch literal 1321 zcmbtT%Wl&^6rJ%aY5L$HV8Mo$D9t8D3a~<`QWJuZh>#*S7ShP_46UhSn>$VgQFi1r z_<{VAx2*aLthjfANrKWw6<3<8x#PKybLKeQ-EA;5{;_wwZ!z|hf@QNYIK-t7&`BnF z!UEP~(vtR+N&CAMaEu)3V&r0ENj_jr?;LNlenfuR91IR|=@vT00xlV5Y$^M*Bds4? z+R~Z2foozHV^7wmPT9(Yei?;DoTc5bc@jr)G02iL1?LeKZ!)V9iZmQ5A pdesolvers.FDMGrid: + # This method solves the heat equation. Then, the user can take the grid (using .grid()) and plot it + pass + + +class HeatEquationCrankNicolsonSolver: + + def __init__(self, grid: pdesolvers.FDMGrid, kappa=1): + self.__kappa = kappa + self.__grid = grid + + def solve(self) -> pdesolvers.FDMGrid: + pass From ecb63f3deb35e1c00d71cd01ff12bcf7456d007f Mon Sep 17 00:00:00 2001 From: Pantelis Sopasakis Date: Wed, 27 Nov 2024 18:45:27 +0000 Subject: [PATCH 3/3] rm __pycache__ --- pdesolvers/__pycache__/__init__.cpython-39.pyc | Bin 206 -> 0 bytes pdesolvers/__pycache__/grid.cpython-39.pyc | Bin 3512 -> 0 bytes .../__pycache__/heat_solvers.cpython-39.pyc | Bin 1321 -> 0 bytes 3 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 pdesolvers/__pycache__/__init__.cpython-39.pyc delete mode 100644 pdesolvers/__pycache__/grid.cpython-39.pyc delete mode 100644 pdesolvers/__pycache__/heat_solvers.cpython-39.pyc diff --git a/pdesolvers/__pycache__/__init__.cpython-39.pyc b/pdesolvers/__pycache__/__init__.cpython-39.pyc deleted file mode 100644 index 1110019bf7f6d9c5d0161087309cc700ee9f125c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 206 zcmYe~<>g`kf@@*!>H0wWF^Gck!&EQv49&nZhSDqhJ@#0*pdCVsi;hZY0H^o`6mP4jwTAH>41BRJW4uXtOv};GHESX(7 z)E?(TGSi%x;m#pBG5wcx<-qj7i5oM_@ZPRur)^RO*?QWKw|c*~@3-&CpP8u|aQ*hp z-Okt3hVeUgPF@ytZon-UKrn-m$Z++OxaM7hnanycn6+=Z79;nJy8Q(7j8=g1pI|j0FSVYaIf240 z2ZH-4A71K9PTPKvCSp)PqhTyl?z8$-HtXfidLDY2%}x5de$?mkq(;}553>1*Mu#Wh ztQce!cwvtRX;zY{A3SiUIy~(rtRHdLY4_tG4U;&l!kkDYZd={XY{{dxTMPUs;=*eS zzsucOFYo4Sr}J(MlaCEi1HbC-#x* z@_P`ev2W~^4#^JLE2rj;^~iWc9+_<*I5Q8N)E<@h$p(<|XJb_IN~w8NK7@cmyTUAH zACg0pm43CM?~H6#?i2Cd2zomXt6YZ_5M0Oq6O1WRAt`UE=u)5d;}DqH)f`P?7!eQ% zKkoD+U(g~#P5SjVr&~!sX1)l4q)D5mFjCA@U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