import%20marimo%0A%0A__generated_with%20%3D%20%220.19.11%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Curvilinear%20coordinates%20in%20Jaxfun%0A%0A%20%20%20%20Jaxfun%20is%20developed%20to%20work%20with%20any%20curvilinear%20coordinate%20system%20and%20not%20just%20the%20regular%20Cartesian.%20A%20user%20should%20describe%20equations%20for%20a%20generic%20coordinate%20system%20using%20operators%20like%20%60div%60%2C%20%60grad%60%2C%20%60dot%60%2C%20%60outer%60%2C%20%60cross%60%20and%20%60curl%60.%20The%20correct%20equations%20in%20curvilinear%20coordinates%20should%20then%20be%20automatically%20derived%20by%20Jaxfun%20under%20the%20hood.%20What%20goes%20on%20under%20the%20hood%20is%20described%20in%20more%20detail%20in%20this%20article.%0A%0A%20%20%20%20There%20is%20not%20really%20enough%20time%20or%20space%20to%20go%20through%20all%20details%20regarding%20curvilinear%20coordinates%20here%2C%20so%20the%20interested%20reader%20is%20referred%20to%20the%20excellent%20online%20textbook%20by%20Kelly%2C%20PA.%20Mechanics%20Lecture%20Notes%3A%20An%20introduction%20to%20Solid%20Mechanics.%20%20Available%20from%20%5Bhere%5D(http%3A%2F%2Fhomepages.engineering.auckland.ac.nz%2F~pkel015%2FSolidMechanicsBooks%2Findex.html)%0A%0A%20%20%20%20In%20the%20following%20we%20will%20consider%20two%20coordinate%20systems%2C%20the%20Cartesian%20with%20coordinates%0A%0A%20%20%20%20%5Cbegin%7Bequation%7D%0A%20%20%20%20%20%20%20%20%5Cmathbf%7Bx%7D%20%3D%20%5C%7Bx%5E%7Bi%7D%5C%7D_%7Bi%5Cin%5Cmathcal%7BI%7D%5En%7D%2C%0A%20%20%20%20%5Cend%7Bequation%7D%0A%0A%20%20%20%20and%20the%20computational%2C%20with%20coordinates%0A%0A%20%20%20%20%5Cbegin%7Bequation%7D%0A%20%20%20%20%20%20%20%20%5Cmathbf%7BX%7D%20%3D%20%5C%7BX%5E%7Bi%7D%5C%7D_%7Bi%5Cin%5Cmathcal%7BI%7D%5Em%7D.%0A%20%20%20%20%5Cend%7Bequation%7D%0A%0A%20%20%20%20Here%20%24%5Cmathcal%7BI%7D%5Em%24%20and%20%24%5Cmathcal%7BI%7D%5En%24%20are%20two%20index%20sets%20for%20the%20number%20of%20computational%20coordinates%2C%20and%20the%20dimension%20of%20the%20physical%20space%2C%20respectively%2C%20and%20%24m%5Cleq%20n%24.%20Throughout%20this%20article%20an%20index%20set%20will%20be%20denoted%20as%20%24%5Cmathcal%7BI%7D%5E%7BN%7D%3D%5C%7B0%2C%201%2C%20%5Cldots%2C%20N-1%5C%7D%24%2C%20where%20%24N%5Cin%20%5Cmathbb%7BZ%7D%5E%2B%24.%0A%0A%20%20%20%20The%20physical%20domain%20will%20be%20denoted%20as%20%24%5COmega%5Em%20%5Csubseteq%20%5Cmathbb%7BR%7D%5En%24%2C%20where%20%24m%3D1%2C2%24%20and%203%20represents%20curves%2C%20surfaces%20and%20volumes%2C%20respectively.%20Likewise%2C%20the%20computational%20domain%20will%20be%20denoted%20as%20%24%5Cmathbb%7BI%7D%5Em%20%5Csubseteq%20%5Cmathbb%7BR%7D%5Em%24.%20The%20computational%20domain%20is%20a%20hypercube%2C%20with%20%24%5Cmathbb%7BI%7D%5E2%20%3D%20%5Ctext%7BI%7D%5E0%20%5Ctimes%20%5Ctext%7BI%7D%5E1%24%20and%20%24%5Cmathbb%7BI%7D%5E3%20%3D%20%5Ctext%7BI%7D%5E0%20%5Ctimes%20%5Ctext%7BI%7D%5E1%20%5Ctimes%20%5Ctext%7BI%7D%5E2%24%2C%20where%20%24%5Ctext%7BI%7D%5Em%24%20is%20the%20interval%20used%20for%20computational%20dimension%20%24m%24.%20Hence%2C%20computations%20are%20always%20performed%20on%20hypercubes.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20coordinate%20curves%20%24X%5E%7Bi%7D%24%20are%20functions%20of%20the%20Cartesian%20coordinates%0A%0A%20%20%20%20%5Cbegin%7Bequation%7D%0A%20%20%20%20%20X%5E%7Bi%7D%20%3D%20X%5E%7Bi%7D(%5Cmathbf%7Bx%7D)%2C%20%5Cquad%20%5Ctext%7Bfor%20%7D%20i%20%5Cin%20%5Cmathcal%7BI%7D%5Em%2C%20%5Ctag%7B3%7D%0A%20%20%20%20%5Cend%7Bequation%7D%0A%0A%20%20%20%20and%20we%20get%20the%20Cartesian%20coordinates%20through%20the%20inverse%20maps%0A%0A%20%20%20%20%5Cbegin%7Bequation%7D%0A%20%20%20%20x%5Ei%3Dx%5Ei(%5Cmathbf%7BX%7D)%2C%20%5Cquad%20%5Ctext%7Bfor%20%7D%20i%20%5Cin%20%5Cmathcal%7BI%7D%5En.%5Ctag%7B4%7D%0A%20%20%20%20%5Cend%7Bequation%7D%0A%0A%20%20%20%20Using%20these%20generic%20maps%20a%20function%20%24u%20%3A%20%5COmega%5Em%20%5Crightarrow%20%5Cmathbb%7BK%7D%24%2C%20where%20%24%5Cmathbb%7BK%7D%24%20may%20be%20either%20%24%5Cmathbb%7BR%7D%24%20or%20%24%5Cmathbb%7BC%7D%24%2C%20may%20now%20be%20transformed%20from%20physical%20to%20computational%20space%20through%20a%20change%20of%20variables%20as%0A%0A%20%20%20%20%5Cbegin%7Bequation%7D%0A%20%20%20%20u(%5Cmathbf%7Bx%7D)%20%3D%20u(%5Cmathbf%7Bx%7D(%5Cmathbf%7BX%7D))%20%3D%20U(%5Cmathbf%7BX%7D)%2C%5Ctag%7B5%7D%0A%20%20%20%20%5Cend%7Bequation%7D%0A%0A%20%20%20%20A%20simple%20and%20well%20known%20example%20is%20for%20polar%20coordinates%2C%20where%20the%20Cartesian%20coordinates%20%24x%24%20and%20%24y%24%20are%20mapped%20to%20the%20polar%20coordinates%20%24r%24%20and%20%24%5Ctheta%24%20as%0A%0A%20%20%20%20%24%24%0A%20%20%20%20x(r%2C%20%5Ctheta)%20%3D%20r%20%5Ccos%20%5Ctheta%20%5Cquad%20%5Ctext%7Band%7D%20%5Cquad%20%20y(r%2C%20%5Ctheta)%20%3D%20r%20%5Csin%20%5Ctheta%0A%20%20%20%20%24%24%0A%0A%20%20%20%20A%20Cartesian%20function%20for%20a%20circle%20of%20radius%20one%20is%20%24u(x%2C%20y)%20%3D%20%5Csqrt%7Bx%5E2%20%2B%20y%5E2%7D%20-1%24.%20Inserting%20for%20the%20polar%20maps%20we%20get%20%24u(x(r%2C%20%5Ctheta)%2C%20y(r%2C%20%5Ctheta))%20%3D%20%5Csqrt%7B(r%20%5Ccos%20%5Ctheta)%5E2%20%2B%20(r%20%5Csin%20%5Ctheta)%5E2%7D%20-%201%20%3D%20r%20-%201%20%3D%20U(r%2C%20%5Ctheta)%24.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20transformation%20for%20any%20curvilinear%20coordinate%20system%20will%20be%20defined%20through%20the%20use%20of%20a%20position%20vector%2C%20which%20can%20be%20written%20as%20a%20function%20of%20the%20new%20coordinates%0A%0A%20%20%20%20%5Cbegin%7Bequation%7D%0A%20%20%20%20%20%20%20%20%5Cmathbf%7Br%7D(%5Cmathbf%7BX%7D)%20%3D%20x%5Ei(%5Cmathbf%7BX%7D)%20%5C%2C%5Cmathbf%7Bi%7D_i%2C%5Ctag%7B6%7D%0A%20%20%20%20%5Cend%7Bequation%7D%0A%0A%20%20%20%20where%20there%20is%20here%2C%20and%20throughout%20this%20article%2C%20summation%20implied%20by%20repeating%20indices.%20The%20Cartesian%20unit%20basis%20vectors%20are%20denoted%20as%20%24%5Cmathbf%7Bi%7D_i%5Cin%5Cmathbb%7BR%7D%5En%24%20for%20%24i%5Cin%20%5Cmathcal%7BI%7D%5En%24.%20The%20position%20vector%20can%20describe%20any%20point%20in%20the%20physical%20domain%20%24%5COmega%5Em%24.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20A%20curvilinear%20coordinate%20system%20can%20be%20described%20using%20two%20different%20sets%20of%20basis%20vectors%2C%20the%20co-%20or%20contravariant%20basis%20vectors.%0A%0A%20%20%20%20The%20covariant%20basis%20vectors%20are%20defined%20as%0A%0A%20%20%20%20%5Cbegin%7Bequation%7D%0A%20%20%20%20%20%20%20%20%5Cmathbf%7Bb%7D_i(%5Cmathbf%7BX%7D)%20%3D%20%5Cfrac%7B%5Cpartial%20%5Cmathbf%7Br%7D%7D%7B%5Cpartial%20X%5E%7Bi%7D%7D%2C%20%5Cquad%20%5Ctext%7Bfor%20%7D%20i%20%5C%2C%20%5Cin%20%5Cmathcal%7BI%7D%5Em%2C%5Ctag%7B8%7D%0A%20%20%20%20%5Cend%7Bequation%7D%0A%0A%20%20%20%20The%20covariant%20basis%20vectors%20%24%5Cmathbf%7Bb%7D_i%24%20are%20tangent%20to%20the%20%24m%24%20coordinate%20curves%20%24X%5Ei(%5Cmathbf%7Bx%7D)%24.%0A%0A%20%20%20%20The%20contravariant%20basis%20vectors%20are%20defined%20as%0A%0A%20%20%20%20%5Cbegin%7Bequation%7D%0A%20%20%20%20%20%20%20%20%5Cmathbf%7Bb%7D%5E%7Bi%7D(%5Cmathbf%7BX%7D)%20%3D%20%20%5Cmathbf%7Bi%7D_j%5Cfrac%7B%5Cpartial%20X%5E%7Bi%7D%7D%7B%5Cpartial%20x%5Ej%7D%2C%20%5Cquad%20%5Ctext%7Bfor%20%7D%20i%20%5C%2C%20%5Cin%20%5Cmathcal%7BI%7D%5Em.%5Ctag%7B9%7D%0A%20%20%20%20%5Cend%7Bequation%7D%0A%0A%20%20%20%20The%20contravariant%20basis%20vectors%20are%20orthogonal%20to%20the%20covariant%20basis%20vectors%0A%0A%20%20%20%20%5Cbegin%7Bequation%7D%0A%20%20%20%20%20%20%20%20%5Cmathbf%7Bb%7D%5E%7Bi%7D%20%5Ccdot%20%5Cmathbf%7Bb%7D_%7Bj%7D%20%3D%20%5Cdelta_%7Bj%7D%5E%7Bi%7D%2C%20%5Cquad%20%5Ctext%7Bfor%20%7D%20i%2C%20j%20%5C%2C%20%5Cin%20%5Cmathcal%7BI%7D%5E%7Bm%20%5Ctimes%20m%7D.%5Ctag%7B10%7D%0A%20%20%20%20%5Cend%7Bequation%7D%0A%0A%20%20%20%20Any%20vector%20%24%5Cmathbf%7Bv%7D(%5Cmathbf%7BX%7D)%24%20(boldface%20lower%20case%20letter)%20can%20be%20given%20with%20either%20co-%20or%20contravariant%20basis%20functions%20in%20the%20computational%20domain%20and%20we%20write%20them%20as%0A%0A%20%20%20%20%5Cbegin%7Bequation%7D%0A%20%20%20%20%20%20%20%20%5Cmathbf%7Bv%7D%20%3D%20%7Bv%7D%5E%7Bi%7D%20%5Cmathbf%7Bb%7D_i%20%3D%20%7Bv%7D_i%20%5Cmathbf%7Bb%7D%5E%7Bi%7D%2C%5Ctag%7B11%7D%0A%20%20%20%20%5Cend%7Bequation%7D%0A%0A%20%20%20%20where%20%24%7Bv%7D_%7Bi%7D(%5Cmathbf%7BX%7D)%24%20and%20%24%7Bv%7D%5E%7Bi%7D(%5Cmathbf%7BX%7D)%24%20are%20co-%20and%20contravariant%20vector%20components%2C%20respectively.%20The%20sub-%20or%20superscript%20of%20the%20coefficient%20are%20used%20to%20recognise%20which%20basis%20functions%20are%20used.%20The%20vector%20%24%5Cmathbf%7Bv%7D%24%20can%20also%20be%20given%20in%20Cartesian%20basis%20vectors%2C%20but%20since%20both%20sub-%20and%20superscripts%20are%20taken%2C%20we%20must%20make%20use%20of%20an%20alternative%20notation%20that%20includes%20the%20Cartesian%20variables%20%24%5Cmathbf%7Bv%7D(%5Cmathbf%7Bx%7D)%20%3D%20v%5E%7Bi%7D(%5Cmathbf%7Bx%7D)%20%5Cmathbf%7Bi%7D_i%24.%0A%0A%20%20%20%20When%20a%20vector%20is%20written%20with%20contravariant%20vector%20components%20%24%5Cmathbf%7Bv%7D%20%3D%20%7Bv%7D%5E%7Bi%7D%20%5Cmathbf%7Bb%7D_i%24%2C%20the%20vector%20is%20called%20a%20contravariant%20vector.%20This%20is%20the%20default%20used%20by%20Jaxfun.%20When%20the%20vector%20is%20written%20with%20covariant%20components%20%24%5Cmathbf%7Bv%7D%20%3D%20%7Bv%7D_i%20%5Cmathbf%7Bb%7D%5E%7Bi%7D%24%20it%20is%20called%20a%20covariant%20vector.%20This%20is%20a%20bit%20confusing%20since%20a%20contravariant%20vector%20is%20using%20covariant%20basis%20vectors%20and%20vice%20versa!%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20In%20Jaxfun%20we%20work%20by%20default%20in%20the%20covariant%20basis%20with%20contravariant%20vector%20components.%20However%2C%20we%20can%20obtain%20the%20covariant%20components%20%24%7Bv%7D_%7Bi%7D%24%20as%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%7Bv%7D_%7Bi%7D%20%3D%20%7Bv%7D%5Ej%20%5Cmathbf%7Bb%7D_j%20%5Ccdot%20%5Cmathbf%7Bb%7D_i%20%3D%20%7Bv%7D%5Ej%20g_%7Bji%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20The%20co-%20and%20contravariant%20metric%20tensors%20are%20defined%20as%0A%0A%20%20%20%20%5Cbegin%7Balign%7D%0A%20%20%20%20g_%7Bij%7D(%5Cmathbf%7BX%7D)%20%26%3D%20%5Cmathbf%7Bb%7D_i%20%5Ccdot%20%5Cmathbf%7Bb%7D_j%20%5Cquad%20%5Ctext%7Bfor%20%7D%20i%2C%20j%20%5Cin%20%5Cmathcal%7BI%7D%5E%7Bm%20%5Ctimes%20m%7D%2C%20%5Ctag%7B12%7D%20%5C%5C%0A%20%20%20%20g%5E%7Bij%7D(%5Cmathbf%7BX%7D)%20%26%3D%20%5Cmathbf%7Bb%7D%5E%7Bi%7D%20%5Ccdot%20%5Cmathbf%7Bb%7D%5E%7Bj%7D%20%5Cquad%20%5Ctext%7Bfor%20%7D%20i%2C%20j%20%5Cin%20%5Cmathcal%7BI%7D%5E%7Bm%20%5Ctimes%20m%7D%2C%20%5Ctag%7B13%7D%0A%20%20%20%20%5Cend%7Balign%7D%0A%0A%20%20%20%20respectively.%20Finally%2C%20the%20determinant%20of%20the%20covariant%20metric%20tensor%20is%20given%20as%0A%0A%20%20%20%20%5Cbegin%7Bequation%7D%0A%20%20%20%20%20%20%20%20g(%5Cmathbf%7BX%7D)%20%3D%20%5Cdet(%5Bg_%7Bij%7D%5D)%2C%5Ctag%7B14%7D%0A%20%20%20%20%5Cend%7Bequation%7D%0A%0A%20%20%20%20where%20%24%5Bg_%7Bij%7D%5D%24%20represents%20the%20tensor%20with%20components%20%24g_%7Bij%7D%24.%0A%20%20%20%20Note%20that%20if%20%24m%3Dn%24%2C%20then%20%24%5Csqrt%7Bg%7D%24%20is%20equal%20to%20the%20determinant%20of%20the%20Jacobian%20matrix.%20Also%20note%20that%20if%20the%20basis%20vectors%20are%20orthogonal%2C%20then%20%24%5Bg_%7Bij%7D%5D%24%20and%20%24%5Bg%5E%7Bij%7D%5D%24%20are%20diagonal%20matrices%20and%20the%20co-%20and%20contravariant%20basis%20vectors%20%20%24%5Cmathbf%7Bb%7D_%7Bi%7D%24%20and%20%24%5Cmathbf%7Bb%7D%5E%7Bi%7D%24%20are%20parallel.%0A%0A%20%20%20%20We%20can%20get%20the%20contravariant%20basis%20vectors%20from%20the%20covariant%20and%20vice%20versa%20using%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Balign*%7D%0A%20%20%20%20%5Cmathbf%7Bb%7D%5E%7Bi%7D%20%26%3D%20g%5E%7Bij%7D%20%5Cmathbf%7Bb%7D_%7Bj%7D%20%5C%5C%0A%20%20%20%20%5Cmathbf%7Bb%7D_%7Bi%7D%20%26%3D%20g_%7Bij%7D%20%5Cmathbf%7Bb%7D%5E%7Bj%7D%0A%20%20%20%20%5Cend%7Balign*%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20The%20metric%20tensors%20are%20available%20in%20Jaxfun%20using%20methods%20%60get_covariant_metric_tensor%60%20and%20%60get_contravariant_metric_tensor%60%20on%20the%20given%20curvilinear%20coordinate%20system.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20vector%20dot%20product%20can%20be%20defined%20for%20curvilinear%20coordinates%20as%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cmathbf%7Bu%7D%20%5Ccdot%20%5Cmathbf%7Bv%7D%20%3D%20%7Bu%7D%5E%7Bi%7D%5Cmathbf%7Bb%7D_i%20%5Ccdot%20%7Bv%7D_j%20%5Cmathbf%7Bb%7D%5E%7Bj%7D%20%3D%20%7Bu%7D%5E%7Bi%7D%20%7Bv%7D_i%0A%20%20%20%20%24%24%0A%0A%20%20%20%20because%20of%20Eq.%20(10).%0A%0A%20%20%20%20The%20dot%20product%20between%20two%20vectors%20both%20expressed%20in%20a%20covariant%20basis%20can%20be%20computed%20as%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%7Bu%7D%5E%7Bi%7D%5Cmathbf%7Bb%7D_i%20%5Ccdot%20%7Bv%7D%5E%7Bj%7D%20%5Cmathbf%7Bb%7D_%7Bj%7D%20%3D%20%7Bu%7D%5E%7Bi%7D%20%7Bv%7D%5E%7Bj%7D%20g_%7Bij%7D%0A%20%20%20%20%24%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20We%20illustrate%20first%20with%20a%20simple%20example.%20Consider%20a%20simple%20skewed%20coordinate%20system%20defined%20by%20%24x(u%2C%20v)%20%3D%20u%20%2B%20v%24%20and%20%24y(u%2C%20v)%20%3D%20v%24%2C%20with%20curvilinear%20coordinates%20%24u%2C%20v%20%5Cin%20%5B0%2C%202%5D%5Ctimes%20%5B0%2C%202%5D%24%2C%20such%20that%20the%20position%20vector%20is%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cmathbf%7Br%7D(u%2C%20v)%20%3D%20(u%2Bv)%20%5Cmathbf%7Bi%7D%20%2B%20v%20%5Cmathbf%7Bj%7D%2C%0A%20%20%20%20%24%24%0A%0A%20%20%20%20where%20%24%5Cmathbf%7Bi%7D%24%20and%20%24%5Cmathbf%7Bj%7D%24%20are%20the%20Cartesian%20unit%20basis%20vectors.%20The%20coordinate%20curves%20are%20straight%20lines%2C%20but%20they%20are%20not%20orthogonal%20to%20each%20other.%20The%20covariant%20basis%20vectors%20are%20%24%5Cmathbf%7Bb%7D_u%20%3D%20%5Cfrac%7B%5Cpartial%20%5Cmathbf%7Br%7D%7D%7B%5Cpartial%20u%7D%20%3D%20%5Cmathbf%7Bi%7D%24%20and%20%24%5Cmathbf%7Bb%7D_v%20%3D%20%5Cfrac%7B%5Cpartial%20%5Cmathbf%7Br%7D%7D%7B%20%5Cpartial%20v%7D%20%3D%20%5Cmathbf%7Bi%7D%20%2B%20%5Cmathbf%7Bj%7D%24%2C%20and%20the%20contravariant%20basis%20vectors%20are%20%24%5Cmathbf%7Bb%7D%5Eu%20%3D%20%5Cmathbf%7Bi%7D%20-%20%5Cmathbf%7Bj%7D%24%20and%20%24%5Cmathbf%7Bb%7D%5Ev%20%3D%20%5Cmathbf%7Bj%7D%24.%20The%20basis%20vectors%20are%20illustrated%20in%20the%20figure%20below.%20Note%20that%20the%20covariant%20base%20vectors%20align%20with%20the%20constant%20gridlines%20(the%20coordinate%20curves%20of%20%24u%24%20and%20%24v%24)%20and%20the%20contravariant%20base%20vectors%20are%20orthogonal%20to%20the%20gridlines.%20The%20contravariant%20vectors%20are%20as%20such%20the%20vectors%20that%20point%20orthogonally%20out%20from%20the%20physical%20domain%20%24%5COmega%24.%20That%20is%2C%20%24%5Cmathbf%7Bb%7D%5E%7Bu%7D%24%20points%20out%20of%20the%20domain%20below%20defined%20by%20the%20curveline%20drawn%20at%20constant%20%24v%3D2%24%2C%20i.e.%2C%20%24u%20%3D%20x%20-%202%24.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(get_CoordSys%2C%20np%2C%20sp)%3A%0A%20%20%20%20from%20jaxfun.utils%20import%20lambdify%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%0A%20%20%20%20def%20plot()%3A%0A%20%20%20%20%20%20%20%20u%2C%20v%20%3D%20sp.symbols(%22u%2C%20v%22%2C%20real%3DTrue%2C%20positive%3DTrue)%0A%20%20%20%20%20%20%20%20P%20%3D%20get_CoordSys(%22P%22%2C%20sp.Lambda((u%2C%20v)%2C%20(u%20%2B%20v%2C%20v)))%0A%20%20%20%20%20%20%20%20u%2C%20v%20%3D%20P.base_scalars()%0A%20%20%20%20%20%20%20%20rv%20%3D%20P.position_vector(False)%0A%20%20%20%20%20%20%20%20assert%20isinstance(rv%2C%20sp.Tuple)%0A%0A%20%20%20%20%20%20%20%20b%20%3D%20P.get_covariant_basis()%0A%20%20%20%20%20%20%20%20bt%20%3D%20P.get_contravariant_basis()%0A%0A%20%20%20%20%20%20%20%20r0%20%3D%202.0%0A%20%20%20%20%20%20%20%20t0%20%3D%201.0%0A%20%20%20%20%20%20%20%20pos%20%3D%20np.array(%0A%20%20%20%20%20%20%20%20%20%20%20%20%5Blambdify((u%2C%20v)%2C%20rv%5B0%5D)(r0%2C%20t0)%2C%20lambdify((u%2C%20v)%2C%20rv%5B1%5D)(r0%2C%20t0)%5D%0A%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20%20%20%20%20b_num%20%3D%20np.array(%0A%20%20%20%20%20%20%20%20%20%20%20%20%5B%5Blambdify((u%2C%20v)%2C%20b%5Bi%2C%20j%5D)(r0%2C%20t0)%20for%20j%20in%20range(2)%5D%20for%20i%20in%20range(2)%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20dtype%3Dfloat%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20bt_num%20%3D%20np.array(%0A%20%20%20%20%20%20%20%20%20%20%20%20%5B%5Blambdify((u%2C%20v)%2C%20bt%5Bi%2C%20j%5D)(r0%2C%20t0)%20for%20j%20in%20range(2)%5D%20for%20i%20in%20range(2)%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20dtype%3Dfloat%2C%0A%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20%20%20%20%20fig%2C%20ax%20%3D%20plt.subplots(figsize%3D(5%2C%205))%0A%20%20%20%20%20%20%20%20ax.set_aspect(%22equal%22)%0A%20%20%20%20%20%20%20%20ax.set_title(%22Gridlines%20and%20basis%20vectors%22)%0A%0A%20%20%20%20%20%20%20%20u_grid%20%3D%20np.linspace(0.0%2C%202.0%2C%207)%0A%20%20%20%20%20%20%20%20v_grid%20%3D%20np.linspace(0.0%2C%202.0%2C%207)%0A%20%20%20%20%20%20%20%20v_line%20%3D%20np.linspace(0.0%2C%202.0%2C%20100)%0A%20%20%20%20%20%20%20%20u_line%20%3D%20np.linspace(0.0%2C%202.0%2C%20100)%0A%0A%20%20%20%20%20%20%20%20for%20u0%20in%20u_grid%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20x_line%20%3D%20lambdify((u%2C%20v)%2C%20rv%5B0%5D)(u0%2C%20v_line)%0A%20%20%20%20%20%20%20%20%20%20%20%20y_line%20%3D%20lambdify((u%2C%20v)%2C%20rv%5B1%5D)(u0%2C%20v_line)%0A%20%20%20%20%20%20%20%20%20%20%20%20ax.plot(x_line%2C%20y_line%2C%20color%3D%220.85%22%2C%20linewidth%3D1)%0A%0A%20%20%20%20%20%20%20%20for%20v0%20in%20v_grid%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20x_line%20%3D%20np.atleast_1d(lambdify((u%2C%20v)%2C%20rv%5B0%5D)(u_line%2C%20v0))%0A%20%20%20%20%20%20%20%20%20%20%20%20y_line%20%3D%20np.atleast_1d(lambdify((u%2C%20v)%2C%20rv%5B1%5D)(u_line%2C%20v0))%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20y_line.shape%5B0%5D%20%3D%3D%201%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20y_line%20%3D%20np.full_like(x_line%2C%20y_line.item())%0A%20%20%20%20%20%20%20%20%20%20%20%20ax.plot(x_line%2C%20y_line%2C%20color%3D%220.85%22%2C%20linewidth%3D1)%0A%0A%20%20%20%20%20%20%20%20ax.quiver(%0A%20%20%20%20%20%20%20%20%20%20%20%20*pos%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20*b_num%5B0%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20color%3D%22tab%3Ablue%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20angles%3D%22xy%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20scale_units%3D%22xy%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20scale%3D1%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20label%3Dr%22%24%5Cmathbf%7Bb%7D_u%24%22%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20ax.quiver(%0A%20%20%20%20%20%20%20%20%20%20%20%20*pos%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20*b_num%5B1%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20color%3D%22tab%3Ablue%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20angles%3D%22xy%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20scale_units%3D%22xy%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20scale%3D1%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20alpha%3D0.5%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20label%3Dr%22%24%5Cmathbf%7Bb%7D_v%24%22%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20ax.quiver(%0A%20%20%20%20%20%20%20%20%20%20%20%20*pos%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20*bt_num%5B0%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20color%3D%22tab%3Aorange%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20angles%3D%22xy%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20scale_units%3D%22xy%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20scale%3D1%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20label%3Dr%22%24%5Cmathbf%7Bb%7D%5Eu%24%22%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20ax.quiver(%0A%20%20%20%20%20%20%20%20%20%20%20%20*pos%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20*bt_num%5B1%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20color%3D%22tab%3Aorange%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20angles%3D%22xy%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20scale_units%3D%22xy%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20scale%3D1%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20alpha%3D0.5%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20label%3Dr%22%24%5Cmathbf%7Bb%7D%5Ev%24%22%2C%0A%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20%20%20%20%20ax.set_xlim(-0.2%2C%204.2)%0A%20%20%20%20%20%20%20%20ax.set_ylim(-0.2%2C%202.2)%0A%20%20%20%20%20%20%20%20ax.legend(loc%3D%22upper%20left%22)%0A%20%20%20%20%20%20%20%20plt.show()%0A%0A%20%20%20%20plot()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Cylindrical%20coordinate%20system%0A%0A%20%20%20%20We%20will%20illustrate%20further%20by%20creating%20an%20orthogonal%20cylindrical%20coordinate%20system%2C%20defined%20from%20the%20position%20vector%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cmathbf%7Br%7D(r%2C%20%5Ctheta%2C%20z)%20%3D%20r%20%5Ccos%20%5Ctheta%20%5Cmathbf%7Bi%7D%20%2B%20r%20%5Csin%20%5Ctheta%20%5Cmathbf%7Bj%7D%20%2B%20z%20%5Cmathbf%7Bk%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20where%20%24r%20%5Cin%20%5B0%2C%201%5D%24%20and%20%24%5Ctheta%20%5Cin%20(0%2C%202%20%5Cpi%5D%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20from%20IPython.display%20import%20display%0A%20%20%20%20from%20jaxfun.operators%20import%20Dot%2C%20dot%0A%20%20%20%20from%20jaxfun.coordinates%20import%20get_CoordSys%0A%20%20%20%20import%20sympy%20as%20sp%0A%0A%20%20%20%20r%2C%20theta%2C%20z%20%3D%20sp.symbols(%22r%2Ctheta%2Cz%22%2C%20real%3DTrue%2C%20positive%3DTrue)%0A%20%20%20%20C%20%3D%20get_CoordSys(%0A%20%20%20%20%20%20%20%20%22C%22%2C%20sp.Lambda((r%2C%20theta%2C%20z)%2C%20(r%20*%20sp.cos(theta)%2C%20r%20*%20sp.sin(theta)%2C%20z))%0A%20%20%20%20)%0A%20%20%20%20r%2C%20theta%2C%20z%20%3D%20C.base_scalars()%0A%20%20%20%20return%20C%2C%20Dot%2C%20display%2C%20dot%2C%20get_CoordSys%2C%20r%2C%20sp%2C%20theta%2C%20z%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Note%20that%20the%20curvilinear%20coordinate%20system%20is%20created%20from%20only%20the%20forward%20map%20%24%5Cmathbf%7Bx%7D(%5Cmathbf%7BX%7D)%24%20and%20we%20do%20not%20need%20to%20provide%20the%20reverse%20map%20%24%5Cmathbf%7BX%7D(%5Cmathbf%7Bx%7D)%24%2C%20which%20for%20the%20cylinder%20coordinates%20would%20be%0A%0A%20%20%20%20%24%24%0A%20%20%20%20r%20%3D%20%5Csqrt%7Bx%5E2%2By%5E2%7D%2C%20%5Cquad%20%5Ctheta%20%3D%20%5Ctan%5E%7B-1%7D(y%2Fx)%2C%20%5Cquad%20z%20%3D%20z.%0A%20%20%20%20%24%24%0A%0A%20%20%20%20This%20is%20because%20Jaxfun%20is%20using%20the%20covariant%20basis%20vectors%20computed%20from%20the%20forward%20map%2C%20and%20the%20contravariant%20basis%20vector%20may%20then%20be%20computed%20simply%20from%20the%20%24%5Cmathbf%7Bb%7D%5Ei%20%3D%20g%5E%7Bij%7D%20%5Cmathbf%7Bb%7D_j%24%2C%20where%20%24%5Bg%5E%7Bij%7D%5D%20%3D%20%5Bg_%7Bij%7D%5D%5E%7B-1%7D%24.%20So%20the%20reverse%20map%20is%20not%20explicitly%20used%20and%20as%20such%20it%20does%20not%20have%20to%20be%20provided%20by%20the%20user.%0A%0A%20%20%20%20Note%20that%20on%20the%20last%20line%20in%20the%20code%20section%20above%20we%20overwrite%20the%20sympy%20symbols%20%60r%60%2C%20%60theta%60%2C%20%60z%60%20with%20objects%20of%20type%20%60BaseScalar%60.%0A%0A%20%20%20%20As%20a%20first%20example%20create%20two%20contravariant%20vectors%20and%20take%20the%20dot%20product%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(C%2C%20Dot%2C%20display)%3A%0A%20%20%20%20u%20%3D%204%20*%20C.b_r%20%2B%203%20*%20C.b_theta%20%2B%202%20*%20C.b_z%0A%20%20%20%20v%20%3D%20C.b_r%0A%20%20%20%20d%20%3D%20Dot(u%2C%20v)%0A%20%20%20%20display(d)%0A%20%20%20%20display(d.doit())%0A%20%20%20%20return%20u%2C%20v%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Note%20that%20%60Dot%60%20represents%20an%20unevaluated%20dot%20product.%20It%20is%20evaluated%20by%20calling%20%60doit()%60.%20Under%20the%20hood%20this%20invokes%20the%20%60dot%60%20function.%20We%20could%20alternatively%20just%20use%20the%20%60dot%60function%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(dot%2C%20u%2C%20v)%3A%0A%20%20%20%20dot(u%2C%20v)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20covariant%20metric%20tensor%20is%20given%20for%20cylindrical%20coordinates%20as%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(C)%3A%0A%20%20%20%20print(C.get_covariant_metric_tensor())%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20metric%20tensor%20is%20diagonal%20since%20the%20cylindrical%20coordinates%20are%20orthogonal.%0A%0A%20%20%20%20We%20can%20also%20create%20vectors%20in%20Cartesian%20Coordinates%20and%20transform%20them%20into%20the%20curvilinear%20system.%20For%20example%2C%20the%20position%20vector%20in%20Cartesian%20coordinates%20is%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(C%2C%20display)%3A%0A%20%20%20%20R%20%3D%20C._parent%20%20%23%20The%20Cartesian%20coordinate%20system%0A%20%20%20%20p%20%3D%20R.x%20*%20R.i%20%2B%20R.y%20*%20R.j%20%2B%20R.z%20*%20R.k%0A%20%20%20%20display(p)%0A%20%20%20%20return%20(p%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Running%20%60doit%60%20on%20this%20vector%20transforms%20the%20components%20into%20computational%20coordinates%2C%20but%20does%20not%20change%20basis%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(display%2C%20p)%3A%0A%20%20%20%20display(p.doit())%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20We%20can%20get%20this%20vector%20%24%5Cmathbf%7Bp%7D%24%20as%20fully%20contravariant%20by%20computing%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cboldsymbol%7Bp%7D%20%3D%20(%5Cboldsymbol%7Bp%7D%20%5Ccdot%20%5Cboldsymbol%7Bb%7D_r)%20%5Cboldsymbol%7Bb%7D_r%20%2B%20(%5Cboldsymbol%7Bp%7D%20%5Ccdot%20%5Cboldsymbol%7Bb%7D_%7B%5Ctheta%7D)%20%5Cboldsymbol%7Bb%7D_%7B%5Ctheta%7D%20%2B%20(%5Cboldsymbol%7Bp%7D%20%5Ccdot%20%5Cboldsymbol%7Bb%7D_%7Bz%7D)%20%5Cboldsymbol%7Bb%7D_%7Bz%7D%20%3D%20r%20%5Cboldsymbol%7Bb%7D_r%20%2B%20z%20%5Cmathbf%7Bb%7D_z%0A%20%20%20%20%24%24%0A%0A%20%20%20%20This%20is%20called%20a%20projection%20of%20the%20vector%20%24%5Cboldsymbol%7Bp%7D%24%20onto%20the%20covariant%20cylinder%20basis.%20The%20projection%20can%20be%20computed%20with%20method%20%60from_cartesian%60%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(C%2C%20display%2C%20p)%3A%0A%20%20%20%20display(C.from_cartesian(p))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20We%20can%20also%20go%20the%20other%20way%20and%20compute%20a%20Cartesian%20vector%20from%20a%20contravariant%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(C)%3A%0A%20%20%20%20C.to_cartesian(C.b_theta)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20And%20we%20can%20look%20at%20the%20contravariant%20basis%20vectors%20in%20terms%20of%20Cartesian%20coordinates%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(C)%3A%0A%20%20%20%20C.get_contravariant_basis(True)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20point%20is%20that%20a%20vector%20%24%5Cmathbf%7Bv%7D%24%20can%20be%20formulated%20using%20several%20different%20basis%20vectors%20and%20there%20may%20be%20advantages%20or%20disadvantages%20to%20all%20of%20them.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Cross%20product%0A%0A%20%20%20%20The%20cross%20product%20between%20two%20vectors%20can%20be%20obtained%20as%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cmathbf%7Bu%7D%20%5Ctimes%20%5Cmathbf%7Bv%7D%20%3D%20%5Cvarepsilon_%7Bijk%7D%20%5Csqrt%7Bg%7D%20%7Bu%7D%5Ej%20%7Bv%7D%5Ek%20%5Cmathbf%7Bb%7D%5E%7Bi%7D%20%3D%20%5Cvarepsilon_%7Bijk%7D%20%5Csqrt%7Bg%7D%20%7Bu%7D%5Ej%20%7Bv%7D%5Ek%20g%5E%7Bil%7D%5Cmathbf%7Bb%7D_l%0A%20%20%20%20%24%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(C%2C%20display)%3A%0A%20%20%20%20from%20jaxfun.operators%20import%20Cross%0A%0A%20%20%20%20cr%20%3D%20Cross(C.b_r%2C%20C.b_theta)%0A%20%20%20%20display(cr)%0A%20%20%20%20display(cr.doit())%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Dyadics%0A%0A%20%20%20%20The%20tensor%20product%20(or%20outer%20product)%20of%20two%20vectors%20is%20written%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cmathbf%7BA%7D%20%3D%20%5Cmathbf%7Bu%7D%20%5Cotimes%20%5Cmathbf%7Bv%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20The%20second%20order%20tensor%20%24%5Cmathbf%7BA%7D%24%20is%20called%20a%20dyad.%20There%20are%20four%20possible%20basis%20configurations%20for%20dyads%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Balign*%7D%0A%20%20%20%20%5Cmathbf%7Bb%7D%5E%7Bi%7D%20%26%5Cotimes%20%5Cmathbf%7Bb%7D%5E%7Bj%7D%20%5C%5C%0A%20%20%20%20%5Cmathbf%7Bb%7D%5E%7Bi%7D%20%26%5Cotimes%20%5Cmathbf%7Bb%7D_%7Bj%7D%20%5C%5C%0A%20%20%20%20%5Cmathbf%7Bb%7D_%7Bi%7D%20%26%5Cotimes%20%5Cmathbf%7Bb%7D%5E%7Bj%7D%20%5C%5C%0A%20%20%20%20%5Cmathbf%7Bb%7D_%7Bi%7D%20%26%5Cotimes%20%5Cmathbf%7Bb%7D_%7Bj%7D%20%5C%5C%0A%20%20%20%20%5Cend%7Balign*%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20In%20Jaxfun%20we%20use%20the%20last%20one%2C%20with%20two%20covariant%20base%20vectors%20%24%5Cmathbf%7Bb%7D_%7Bi%7D%20%5Cotimes%20%5Cmathbf%7Bb%7D_%7Bj%7D%24.%20In%20this%20case%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cmathbf%7BA%7D%20%3D%20A%5E%7Bij%7D%20%5Cmathbf%7Bb%7D_i%20%5Cotimes%20%5Cmathbf%7Bb%7D_j.%0A%20%20%20%20%24%24%0A%0A%20%20%20%20where%20%24A%5E%7Bij%7D%24%20are%20called%20the%20contravariant%20components.%0A%0A%20%20%20%20The%20outer%20product%20of%20two%20vectors%20is%20computed%20as%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cmathbf%7Bu%7D%20%5Cotimes%20%5Cmathbf%7Bv%7D%20%3D%20%7Bu%7D%5E%7Bi%7D%20%5Cmathbf%7Bb%7D_%7Bi%7D%20%5Cotimes%20%7Bv%7D%5E%7Bj%7D%20%5Cmathbf%7Bb%7D_%7Bj%7D%20%3D%20%7Bu%7D%5E%7Bi%7D%20%7Bv%7D%5E%7Bj%7D%20%5Cmathbf%7Bb%7D_%7Bi%7D%20%5Cotimes%20%5Cmathbf%7Bb%7D_%7Bj%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Dyads%20are%20actually%20defined%20by%20how%20they%20contract%20with%20vectors%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Balign*%7D%0A%20%20%20%20(%5Cmathbf%7Bu%7D%20%5Cotimes%20%5Cmathbf%7Bv%7D)%20%5Ccdot%20%5Cmathbf%7Bw%7D%20%26%3D%20(%5Cmathbf%7Bv%7D%20%5Ccdot%20%5Cmathbf%7Bw%7D)%20%5Cmathbf%7Bu%7D%5C%5C%0A%20%20%20%20%5Cmathbf%7Bw%7D%20%5Ccdot%20(%5Cmathbf%7Bu%7D%20%5Cotimes%20%5Cmathbf%7Bv%7D)%20%26%3D%20(%5Cmathbf%7Bw%7D%20%5Ccdot%20%5Cmathbf%7Bu%7D)%20%5Cmathbf%7Bv%7D%0A%20%20%20%20%5Cend%7Balign*%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Note%20that%20some%20authors%20do%20not%20use%20a%20dot%20for%20the%20contraction%20of%20a%20dyad%20with%20a%20vector%20and%20would%20write%20instead%20%24(%5Cmathbf%7Bu%7D%20%5Cotimes%20%5Cmathbf%7Bv%7D)%20%5Cmathbf%7Bw%7D%24.%20Since%20we%20use%20the%20%60Dot%2Fdot%60%20in%20Jaxfun%20to%20represent%20the%20contraction%20of%20both%20dyadics%20and%20vectors%2C%20we%20find%20it%20more%20appropriate%20to%20include%20the%20dot%20also%20for%20contraction%20of%20higher%20order%20tensors.%0A%0A%20%20%20%20A%20linear%20combination%20of%20dyads%20is%20called%20a%20dyadic.%20For%20example%20%24%5Cmathbf%7BA%7D%20%3D%202(%5Cmathbf%7Bu%7D%20%5Cotimes%20%5Cmathbf%7Bv%7D)%20%2B%203%20(%5Cmathbf%7Bw%7D%20%5Cotimes%20%5Cmathbf%7Bz%7D)%24.%20Note%20that%20even%20though%20a%20dyad%20is%20a%20second%20order%20tensor%2C%20not%20all%20second%20order%20tensors%20are%20dyads.%20That%20is%2C%20we%20cannot%20always%20write%20the%20tensor%20%24%5Cmathbf%7BA%7D%24%20as%20the%20tensor%20product%20of%20two%20vectors%20%24%5Cmathbf%7Bu%7D%20%5Cotimes%20%5Cmathbf%7Bv%7D%24.%0A%0A%20%20%20%20The%20contraction%20of%20two%20dyads%20leads%20to%20a%20dyad%0A%0A%20%20%20%20%24%24%0A%20%20%20%20(%5Cmathbf%7Bu%7D%20%5Cotimes%20%5Cmathbf%7Bv%7D)%20%5Ccdot%20(%5Cmathbf%7Bw%7D%20%5Cotimes%20%5Cmathbf%7Bz%7D)%20%3D%20(%5Cmathbf%7Bv%7D%20%5Ccdot%20%5Cmathbf%7Bw%7D)%20(%5Cmathbf%7Bu%7D%20%5Cotimes%20%5Cmathbf%7Bz%7D)%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Let%20create%20some%20dyadics%20in%20Jaxfun%20and%20illustrate.%20First%2C%20the%209%20dyad%20base%20vectors%20can%20be%20obtained%20as%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(C%2C%20display)%3A%0A%20%20%20%20bb%20%3D%20C.base_dyadics()%0A%20%20%20%20display(bb)%0A%20%20%20%20return%20(bb%2C)%0A%0A%0A%40app.cell%0Adef%20_(bb%2C%20display%2C%20r%2C%20theta)%3A%0A%20%20%20%20import%20numpy%20as%20np%0A%0A%20%20%20%20bv%20%3D%20np.array(bb%2C%20dtype%3Dobject).reshape((3%2C%203))%0A%20%20%20%20A%20%3D%202%20*%20bv%5B0%2C%201%5D%20%2B%203%20*%20bv%5B1%2C%202%5D%0A%20%20%20%20B%20%3D%20r%20*%20bv%5B1%2C%201%5D%20%2B%20theta%20*%20bv%5B2%2C%202%5D%0A%20%20%20%20display(A)%0A%20%20%20%20display(B)%0A%20%20%20%20return%20A%2C%20B%2C%20bv%2C%20np%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Contract%20%60A%60%20with%20%60B%60%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(A%2C%20B%2C%20Dot%2C%20display)%3A%0A%20%20%20%20H%20%3D%20Dot(A%2C%20B)%0A%20%20%20%20display(H)%0A%20%20%20%20display(H.doit())%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Operators%20in%20curvilinear%20coordinates%0A%0A%20%20%20%20%23%23%23%20Vector%20operations%0A%0A%20%20%20%20The%20gradient%20of%20a%20scalar%20field%20%24f(%5Cmathbf%7Bx%7D)%20(%3DF(%5Cmathbf%7BX%7D))%24%20is%20termed%20%24%5Ctext%7Bgrad%7D(f)%24%20and%20equals%0A%0A%20%20%20%20%5Cbegin%7Bequation%7D%0A%20%20%20%20%5Ctext%7Bgrad%7D(f)%20%3D%20%5Cnabla%20f%20%3D%20%5Cfrac%7B%5Cpartial%20%7BF%7D%7D%7B%5Cpartial%20X%5E%7Bi%7D%7D%5C%2C%5Cmathbf%7Bb%7D%5E%7Bi%7D%20%3D%20%5Cfrac%7B%5Cpartial%20%7BF%7D%7D%7B%5Cpartial%20X%5E%7Bi%7D%7D%20g%5E%7Bij%7D%20%5C%2C%5Cmathbf%7Bb%7D_%7Bj%7D.%20%5Ctag%7B15%7D%0A%20%20%20%20%5Cend%7Bequation%7D%0A%0A%20%20%20%20Note%20that%20the%20computation%20in%20curvilinear%20coordinates%20is%20simply%20using%20a%20change%20of%20variables%20and%20the%20chain%20rule%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cnabla%20f%20%3D%20%5Cfrac%7B%5Cpartial%20f(%5Cmathbf%7Bx%7D)%7D%7B%5Cpartial%20x_i%7D%20%5Cmathbf%7Bi%7D_%7Bi%7D%20%3D%20%5Cfrac%7B%5Cpartial%20F(%5Cmathbf%7BX%7D)%7D%7B%5Cpartial%20X%5Ej%7D%20%5Cfrac%7B%5Cpartial%20X%5Ej%7D%7B%5Cpartial%20x_i%7D%20%5Cmathbf%7Bi%7D_%7Bi%7D%20%3D%20%5Cfrac%7B%5Cpartial%20F%7D%7B%5Cpartial%20X%5Ej%7D%20%5Cmathbf%7Bb%7D%5Ej.%0A%20%20%20%20%24%24%0A%0A%20%20%20%20The%20divergence%20of%20a%20vector%20%24%5Cmathbf%7Bv%7D%24%2C%20in%20terms%20of%20its%20contravariant%20components%2C%20is%20given%20as%0A%0A%20%20%20%20%5Cbegin%7Bequation%7D%0A%20%20%20%20%5Ctext%7Bdiv%7D(%5Cmathbf%7Bv%7D)%20%3D%20%5Cnabla%20%5Ccdot%20%5Cmathbf%7Bv%7D%20%3D%20%5Cfrac%7B%5Cpartial%20%5Cmathbf%7Bv%7D%7D%7B%5Cpartial%20X%5Ej%7D%20%5Ccdot%20%5Cmathbf%7Bb%7D%5Ej%20%3D%20%5Cfrac%7B1%7D%7B%5Csqrt%7Bg%7D%7D%20%5Cfrac%7B%5Cpartial%20%7Bv%7D%5E%7Bi%7D%20%5Csqrt%7Bg%7D%7D%7B%5Cpartial%20X%5E%7Bi%7D%7D%2C%5Ctag%7B16%7D%0A%20%20%20%20%5Cend%7Bequation%7D%0A%0A%20%20%20%20and%20the%20Laplacian%20of%20the%20scalar%20field%20%24f%24%20can%20be%20written%20as%0A%0A%20%20%20%20%5Cbegin%7Bequation%7D%0A%20%20%20%20%5Ctext%7Bdiv%7D(%5Ctext%7Bgrad%7D(f))%20%3D%20%5Cnabla%5E2%20f%20%20%3D%20%5Cfrac%7B1%7D%7B%5Csqrt%7Bg%7D%7D%5Cfrac%7B%5Cpartial%7D%7B%5Cpartial%20X%5E%7Bi%7D%7D%5Cleft(%20g%5E%7Bij%7D%20%5Csqrt%7Bg%7D%20%5Cfrac%7B%5Cpartial%20%7BF%7D%7D%7B%5Cpartial%20X%5E%7Bj%7D%7D%5Cright).%20%5Ctag%7B17%7D%0A%20%20%20%20%5Cend%7Bequation%7D%0A%0A%20%20%20%20Note%20that%20%24g%5E%7Bij%7D%24%20and%20%24%5Csqrt%7Bg%7D%24%20will%20act%20as%20variable%20coefficients%20when%20the%20operators%20are%20used%20in%20differential%20equations.%0A%0A%20%20%20%20The%20curl%20of%20a%20vector%20is%20defined%20as%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Ctext%7Bcurl%7D(%5Cmathbf%7Bv%7D)%20%3D%20%5Cnabla%20%5Ctimes%20%5Cmathbf%7Bv%7D%20%3D%20%5Cmathbf%7Bb%7D%5E%7Bj%7D%20%5Ctimes%20%5Cfrac%7B%5Cpartial%20%5Cmathbf%7Bv%7D%7D%7B%5Cpartial%20X%5Ej%7D%20%3D%20%5Cfrac%7B%5Cvarepsilon_%7Bijk%7D%7D%7B%5Csqrt%7Bg%7D%7D%20%5Cfrac%7B%5Cpartial%20%7Bv%7D_k%7D%7B%5Cpartial%20X%5Ej%7D%20%5Cmathbf%7Bb%7D_i%20%5Ctag%7B18%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20The%20partial%20derivative%20%24%5Cfrac%7B%5Cpartial%20%5Cmathbf%7Bv%7D%7D%7B%5Cpartial%20X%5Ej%7D%24%20is%20implemented%20in%20Jaxfun%20as%20the%20%60diff%60%20operator%20working%20on%20vectors.%20The%20partial%20derivative%20can%20be%20computed%20as%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cfrac%7B%5Cpartial%20%5Cmathbf%7Bv%7D%7D%7B%5Cpartial%20X%5Ej%7D%20%3D%20%5Cleft(%5Cfrac%7B%5Cpartial%20%7Bv%7D%5E%7Bi%7D%7D%7B%5Cpartial%20X%5Ej%7D%20%2B%20%5CGamma%5E%7Bi%7D_%7Bkj%7D%20%7Bv%7D%5Ek%5Cright)%20%5Cmathbf%7Bb%7D_i%20%5Ctag%7B19%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20where%20%24%5CGamma%5E%7Bi%7D_%7Bkj%7D%24%20is%20the%20Christoffel%20symbol%20of%20the%20second%20kind%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5CGamma%5E%7Bk%7D_%7Bji%7D%20%3D%20%5Cfrac%7B%5Cpartial%20%5Cmathbf%7Bb%7D_%7Bi%7D%7D%7B%5Cpartial%20X%5Ej%7D%20%5Ccdot%20%5Cmathbf%7Bb%7D%5Ek%20%5Ctag%7B20%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20available%20in%20Jaxfun%20as%20method%20%60get_christoffel_second%60.%0A%0A%20%20%20%20The%20term%20%24%5Cfrac%7B%5Cpartial%20%7Bv%7D%5E%7Bi%7D%7D%7B%5Cpartial%20X%5Ej%7D%20%2B%20%5CGamma%5E%7Bi%7D_%7Bkj%7D%20%7Bv%7D%5Ek%24%20is%20called%20the%20covariant%20derivative%20of%20vector%20components.%0A%0A%20%20%20%20The%20Christoffel%20symbol%20falls%20out%20of%20the%20last%20identity%20for%20the%20curl%20due%20to%20the%20symmetry%20%24%5CGamma%5E%7Bk%7D_%7Bji%7D%20%3D%20%5CGamma%5Ek_%7Bij%7D%24.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Tensor%20operations%0A%0A%20%20%20%20The%20gradient%20of%20a%20vector%20is%20a%20second%20order%20tensor%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Ctext%7Bgrad%7D(%5Cmathbf%7Bv%7D)%20%3D%20%5Cfrac%7B%5Cpartial%20%5Cmathbf%7Bv%7D%7D%7B%5Cpartial%20X%5Ej%7D%20%5Cotimes%20%5Cmathbf%7Bb%7D%5Ej%20%5Ctag%7B21%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Note%20that%20if%20%24%5Cnabla%24%20is%20interpreted%20as%20a%20vector%2C%20then%20this%20corresponds%20to%20%24(%5Cnabla%20%5Cotimes%20%5Cmathbf%7Bv%7D)%5ET%24.%20However%2C%20in%20Jaxfun%20printing%20we%20interpret%20%24%5Cnabla%24%20as%20an%20operator%20and%20as%20such%20%24%5Ctext%7Bgrad%7D(%5Cmathbf%7Bv%7D)%24%20is%20printed%20as%20%24%5Cnabla%20%5Cmathbf%7Bv%7D%24.%0A%0A%20%20%20%20The%20divergence%20of%20a%20second%20order%20tensor%20%24%5Cmathbf%7BA%7D%24%20is%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Ctext%7Bdiv%7D(%5Cmathbf%7BA%7D)%20%3D%20%5Cfrac%7B%5Cpartial%20%5Cmathbf%7BA%7D%7D%7B%5Cpartial%20X%5Ej%7D%20%5Ccdot%20%5Cmathbf%7Bb%7D%5Ej%20%5Ctag%7B22%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Again%2C%20if%20%24%5Cnabla%24%20is%20interpreted%20as%20a%20vector%2C%20then%20%24%5Ctext%7Bdiv%7D(%5Cmathbf%7BA%7D)%20%3D%20%5Cnabla%20%5Ccdot%20%5Cmathbf%7BA%7D%5ET%24.%20But%20in%20Jaxfun's%20printing%20%24%5Cnabla%24%20is%20an%20operator%20acting%20over%20the%20last%20axis%20of%20its%20input%20tensor.%20Hence%20the%20divergence%20of%20a%20tensor%20is%20printed%20as%20%24%5Cnabla%20%5Ccdot%20%5Cmathbf%7BA%7D%24.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(C%2C%20display%2C%20r%2C%20theta)%3A%0A%20%20%20%20from%20jaxfun.operators%20import%20Grad%2C%20Div%0A%0A%20%20%20%20w%20%3D%20r%20*%20C.b_r%20%2B%20theta%20*%20C.b_z%0A%20%20%20%20g%20%3D%20Grad(w)%0A%20%20%20%20display(g)%0A%20%20%20%20display(g.doit())%0A%20%20%20%20return%20Div%2C%20Grad%0A%0A%0A%40app.cell%0Adef%20_(Div%2C%20bv%2C%20display%2C%20r%2C%20z)%3A%0A%20%20%20%20D%20%3D%20r%20*%20bv%5B0%2C%200%5D%20%2B%20z%20*%20bv%5B1%2C%202%5D%0A%20%20%20%20q%20%3D%20Div(D)%0A%20%20%20%20display(q)%0A%20%20%20%20display(q.doit())%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Curvilinear%20equations%0A%0A%20%20%20%20Lets%20consider%20the%20Laplace%20operator%20in%20curvilinear%20coordinates.%20For%20this%20we%20use%20a%20%60ScalarFunction%60%20and%20Jaxfun%20operators%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(C%2C%20Div%2C%20Grad%2C%20display)%3A%0A%20%20%20%20from%20jaxfun.galerkin.arguments%20import%20ScalarFunction%0A%0A%20%20%20%20u_%20%3D%20ScalarFunction(name%3D%22u%22%2C%20system%3DC)%0A%20%20%20%20Lu%20%3D%20Div(Grad(u_))%0A%20%20%20%20display(Lu)%0A%20%20%20%20return%20Lu%2C%20u_%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20Laplace%20operator%20is%20displayed%20in%20Cartesian%20coordinates.%20When%20evaluated%2C%20we%20get%20the%20operator%20in%20cylinder%20coordinates%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Lu%2C%20display)%3A%0A%20%20%20%20display(Lu.doit())%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Note%20the%20map%20from%20Cartesian%20function%20%24u(x%2C%20y%2C%20z)%24%20for%20the%20generic%20(unevaluated)%20operator%20to%20computational%20%24U(r%2C%20%5Ctheta%2C%20z)%24%20in%20the%20evaluated%20domain.%0A%0A%20%20%20%20We%20can%20also%20look%20at%20the%20gradient%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Grad%2C%20display%2C%20u_)%3A%0A%20%20%20%20display(Grad(u_))%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Grad%2C%20display%2C%20u_)%3A%0A%20%20%20%20display(Grad(u_).doit())%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Note%20the%20small%20difference%20here%20from%20most%20textbooks%20that%20present%20the%20gradient%20as%20(see%2C%20e.g.%2C%20%5Bwikipedia%5D(https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FGradient))%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cnabla%20u%20%3D%20%5Cfrac%7B%5Cpartial%20U%7D%7B%5Cpartial%20r%7D%20%5Chat%7B%5Cmathbf%7Bb%7D%7D_r%20%2B%20%5Cfrac%7B1%7D%7Br%7D%5Cfrac%7B%5Cpartial%20U%7D%7B%5Cpartial%20%5Ctheta%7D%20%5Chat%7B%5Cmathbf%7Bb%7D%7D_%7B%5Ctheta%7D%20%2B%20%5Cfrac%7B%5Cpartial%20U%7D%7B%5Cpartial%20z%7D%5Chat%7B%5Cmathbf%7Bb%7D%7D_z%0A%20%20%20%20%24%24%0A%0A%20%20%20%20using%20normalized%20(unit)%20basis%20vectors%20%24%5Chat%7B%5Cmathbf%7Bb%7D%7D_r%20%3D%20%7B%5Cmathbf%7Bb%7D%7D_r%2C%20%5Chat%7B%5Cmathbf%7Bb%7D%7D_%7B%5Ctheta%7D%20%3D%20%5Cmathbf%7Bb%7D_%7B%5Ctheta%7D%20%2F%20r%24%20and%20%24%5Chat%7B%5Cmathbf%7Bb%7D%7D_z%20%3D%20%5Cmathbf%7Bb%7D_z%24.%20Replacing%20the%20hat%20vectors%20above%20with%20the%20covariant%20basis%20vectors%20leads%20to%20the%20same%20result.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20curl%20of%20a%20gradient%20should%20be%20zero.%20Lets%20verify%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Grad%2C%20display%2C%20u_)%3A%0A%20%20%20%20from%20jaxfun.operators%20import%20Curl%0A%0A%20%20%20%20display(Curl(Grad(u_)))%0A%20%20%20%20return%20(Curl%2C)%0A%0A%0A%40app.cell%0Adef%20_(Curl%2C%20Grad%2C%20display%2C%20u_)%3A%0A%20%20%20%20display(Curl(Grad(u_)).doit())%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Inner%20products%0A%0A%20%20%20%20The%20weighted%20%24L_%7B%5Comega%7D%5E2(%5COmega%5Em)%24%20inner%20product%20is%20defined%20as%0A%0A%20%20%20%20%24%24%0A%20%20%20%20(u(%5Cmathbf%7Bx%7D)%2C%20v(%5Cmathbf%7Bx%7D))_%7BL_%7B%5Comega%7D%5E2(%5COmega%5Em)%7D%20%3D%20%5Cint_%7B%5COmega%5Em%7Du(%5Cmathbf%7Bx%7D)%20%5Coverline%7Bv%7D(%5Cmathbf%7Bx%7D)%20%5Comega(%5Cmathbf%7Bx%7D)%20d%5Clambda%5Em%20%5Ctag%7B23%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20where%20as%20before%20%24m%24%3D%201%2C%202%20or%203%20represents%20a%20curve%2C%20surface%20or%20volume%2C%20and%20%20%24d%5Clambda%5Em%24%20represents%20an%20infinitesimal%20line%2C%20surface%20or%20volume%20element.%20The%20overline%20on%20%24%5Coverline%7Bv%7D%24%20represents%20a%20complex%20conjugate.%0A%0A%20%20%20%20The%20computational%20domain%20is%20a%20hypercube%2C%20with%20%24%5Cmathbb%7BI%7D%5E2%20%3D%20%5Ctext%7BI%7D%5E0%20%5Ctimes%20%5Ctext%7BI%7D%5E1%24%20and%20%24%5Cmathbb%7BI%7D%5E3%20%3D%20%5Ctext%7BI%7D%5E0%20%5Ctimes%20%5Ctext%7BI%7D%5E1%20%5Ctimes%20%5Ctext%7BI%7D%5E2%24%2C%20where%20%24%5Ctext%7BI%7D%5Em%24%20is%20the%20interval%20used%20for%20computational%20dimension%20%24m%24.%20When%20computing%20the%20inner%20product%2C%20we%20first%20transform%20the%20integral%20to%20computational%20coordinates.%20We%20use%20the%20following%20mapped%20tensor%20product%20function%20approximations%0A%0A%20%20%20%20%24%24%0A%20%20%20%20u(%5Cmathbf%7Bx%7D)%20%3D%20U(X%5E0)%20%3D%20%5Csum_%7Bk%3D0%7D%5E%7BN-1%7D%20%5Chat%7Bu%7D_k%20%5Cphi_k(X%5E0)%2C%0A%20%20%20%20%24%24%0A%0A%20%20%20%20%24%24%0A%20%20%20%20u(%5Cmathbf%7Bx%7D)%20%3D%20U(X%5E0%2C%20X%5E1)%20%3D%20%5Csum_%7Bk%3D0%7D%5E%7BN_0-1%7D%5Csum_%7Bj%3D0%7D%5E%7BN_1-1%7D%20%5Chat%7Bu%7D_%7Bkj%7D%20%5Cphi_k(X%5E0)%20%5Cpsi_j(X%5E1)%2C%0A%20%20%20%20%24%24%0A%0A%20%20%20%20%24%24%0A%20%20%20%20u(%5Cmathbf%7Bx%7D)%20%3D%20U(X%5E0%2C%20X%5E1%2C%20X%5E2)%20%3D%20%5Csum_%7Bk%3D0%7D%5E%7BN_0-1%7D%5Csum_%7Bj%3D0%7D%5E%7BN_1-1%7D%20%5Csum_%7Bi%3D0%7D%5E%7BN_2-1%7D%5Chat%7Bu%7D_%7Bkji%7D%20%5Cphi_k(X%5E0)%20%5Cpsi_j(X%5E1)%20%5Cgamma_i(X%5E2)%2C%0A%20%20%20%20%24%24%0A%0A%20%20%20%20for%20curves%2C%20surfaces%20or%20volumes.%0A%0A%20%20%20%20Consider%20a%20differential%20equation%20of%20the%20form%0A%0A%20%20%20%20%5Cbegin%7Bequation%7D%0A%20%20%20%20%20%20%20%20L%20u(%5Cmathbf%7Bx%7D)%20%3D%20f(%5Cmathbf%7Bx%7D)%2C%20%5Cquad%20%5Ctext%7Bfor%20%7D%20%5Cmathbf%7Bx%7D%20%5Cin%20%5COmega%5Em%2C%20%5Ctag%7B24%7D%0A%20%20%20%20%5Cend%7Bequation%7D%0A%0A%20%20%20%20where%20%24L%24%20is%20a%20linear%20operator%2C%20%24f(%5Cmathbf%7Bx%7D)%20%5Cin%20L%5E2_%7B%5Comega%7D(%5COmega%5Em)%24%2C%20and%20%24u(%5Cmathbf%7Bx%7D)%20%5Cin%20%5Ctext%7BV%7D(%5COmega%5Em)%24.%20The%20weighted%20variational%20forms%20obtained%20by%20multiplying%20the%20differential%20equation%20by%20a%20test%20function%20and%20integrating%20over%20the%20domain%20are%0A%0A%20%20%20%20%5Cbegin%7Balign%7D%0A%20%20%20%20%20%20%20%20a(u%2C%20v)_%7B%7BL_%7B%5Comega%7D%5E2(%5COmega%5Em)%7D%7D%20%26%3D%20%5Cint_%7B%5COmega%5Em%7D%20L%20u(%5Cmathbf%7Bx%7D)%20%5C%2C%5Coverline%7Bv%7D(%5Cmathbf%7Bx%7D)%20%5C%2C%20%5Comega(%5Cmathbf%7Bx%7D)%20%5C%2C%20d%5Clambda%5Em%2C%20%5Ctag%7B25%7D%20%5C%5C%0A%20%20%20%20%20%20%20%20(f%2C%20v)_%7BL_%7B%5Comega%7D%5E2(%5COmega%5Em)%7D%20%26%3D%20%5Cint_%7B%5COmega%5Em%7D%20f(%5Cmathbf%7Bx%7D)%20%5C%2C%5Coverline%7Bv%7D(%5Cmathbf%7Bx%7D)%20%5C%2C%20%5Comega(%5Cmathbf%7Bx%7D)%20%5C%2C%20d%5Clambda%5Em%2C%20%5Ctag%7B26%7D%0A%20%20%20%20%5Cend%7Balign%7D%0A%0A%20%20%20%20and%20the%20weighted%20Galerkin%20method%20is%20to%20find%20%24u%20%5Cin%20%5Ctext%7BV%7D(%5COmega%5Em)%24%20such%20that%0A%0A%20%20%20%20%5Cbegin%7Bequation%7D%0A%20%20%20%20%20%20%20%20a(u%2C%20v)_%7BL_%7B%5Comega%7D%5E2(%5COmega%5Em)%7D%20%3D%20(f%2C%20v)_%7BL_%7B%5Comega%7D%5E2(%5COmega%5Em)%7D%2C%20%5Cquad%20%5Cforall%20%5C%2C%20v%20%5Cin%20%5Ctext%7BV%7D(%5COmega%5Em).%20%5Ctag%7B27%7D%0A%20%20%20%20%5Cend%7Bequation%7D%0A%0A%20%20%20%20For%20either%20curves%2C%20surfaces%20or%20volumes%2C%20the%20integrals%20are%20transformed%20to%0A%0A%20%20%20%20%5Cbegin%7Balign%7D%0A%20%20%20%20%20%20%20%20a(u%2C%20v)_%7BL_%7B%5Comega%7D%5E2(%5COmega%5Em)%7D%20%26%3D%20%20%5Cint_%7B%5Cmathbb%7BI%7D%5Em%7D%20%7BL%7D%20U%20%5C%2C%20%5Coverline%7BV%7D%20%5C%2C%20W%20%5C%2C%20%5Csqrt%7Bg%7D%20d%7BX%7D%2C%20%5Ctag%7B28%7D%5C%5C%0A%20%20%20%20%20%20%20%20(f%2C%20v)_%7BL_%7B%5Comega%7D%5E2(%5COmega%5Em)%7D%20%26%3D%20%5Cint_%7B%5Cmathbb%7BI%7D%5Em%7D%20F%20%5C%2C%5Coverline%7BV%7D%20%5C%2C%20W%20%5C%2C%20%5Csqrt%7Bg%7D%20d%7BX%7D%2C%20%5Ctag%7B29%7D%0A%20%20%20%20%5Cend%7Balign%7D%0A%0A%20%20%20%20where%20%24d%7BX%7D%3D%5Cprod_%7Bi%5Cin%20%5Cmathcal%7BI%7D%5Em%7D%20dX%5E%7Bi%7D%24%20and%20%24%7BL%7DU%24%20is%20an%20operator%20transformed%20to%20computational%20space%2C%20like%20Eqs.%20(17).%20The%20computational%20weights%20%24W(%5Cmathbf%7BX%7D)%24%20are%20determined%20by%20the%20choice%20of%20basis%20functions.%20Note%20that%20the%20transformation%20makes%20use%20of%20%24d%5Clambda%5Em%20%3D%20%5Csqrt%7Bg%7Dd%7BX%7D%24%20for%20all%20%24m%20%5Cle%20n%24.%0A%0A%20%20%20%20An%20example%20solving%20Helmholtz%20equation%20on%20an%20annulus%20is%20given%20in%20the%20following%20%20%5Bnotebook%5D(https%3A%2F%2Fspectraldns.github.io%2Fjaxfun%2Fannulus.html).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20return%20(mo%2C)%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
ab30538231878be4cd77322c5e8e5226