This (untested) should work, as it is a fairly direct translation of the 
formula:

$pP = $vec->slice('(0)')->diffover; # no mv as x dim already bottom
$px = $coords->slice('(0)')->diffover;
$pQ = $vec->slice('(1)')->mv(1,0)->diffover->mv(0,1);
$py = $coords->slice('(1)')->mv(1,0)->diffover->mv(0,1);
$pR = $vec->slice('(2)')->mv(2,0)->diffover->mv(0,2);
$pz = $coords->slice('(2)')->mv(2,0)->diffover->mv(0,2);

$curl = $vec->zeroes;
$curl->slice('(0)') .= $pR/$py - $pQ/$pz;
$curl->slice('(1)') .= $pP/$pz - $pR/$px;
$curl->slice('(2)') .= $pQ/$px - $pP/$py;

The $curl could be a cat of those 3 expressions, with ->mv(-1,0); there's 
probably a clever way to make one copy of each ndarray and then do inplace 
operations with less mving, and the whole thing could become a PP operation, 
but let's see if this is conceptually correct first!

Best regards,
Ed

________________________________
From: Ed . <ej...@hotmail.com>
Sent: 20 November 2024 9:54 AM
To: perldl <pdl-gene...@lists.sourceforge.net>; pdl-devel 
<pdl-devel@lists.sourceforge.net>; Ingo Schmid <ingo...@gmx.at>
Subject: Re: [Pdl-devel] curl of vector

Hi Ingo,

I'm not aware of any, but I had a quick google to find the formula (I know 
vaguely what divergence and curl are having watched a 3blue1brown video about 
it some time ago). I couldn't find any implementations in Python or Fortran.

This 
(https://openstax.org/books/calculus-volume-3/pages/6-5-divergence-and-curl 
formula 6.17) indicates the formula for curl is:

If  F=⟨P,Q,R⟩ is a vector field in  R3, and  Px, Py, Pz, Qy, Qx, Qz, Rz, Rx, 
and Ry all exist, then the curl of F is defined by

curl F = (Ry−Qz)i + (Pz−Rx)j + (Qx−Py)k
       = (∂R/∂y − ∂Q/∂z)i + (∂P/∂z − ∂R/∂x)j + (∂Q/∂x − ∂P/∂y)k

This suggests to me that for a 3D problem, you need a coordinates ndarray dim 
(3,x,y,z) and a vector field ndarray with the same dims. You can do the partial 
differentiation numerically by some mv-ing and then diffover 
(https://metacpan.org/pod/PDL::Ufunc#diffover), then the notional i,j,k above 
obviously indicate the final components of curl vector at each point. More to 
follow after I've figured out how to do the partial stuff!

Best regards,
Ed

________________________________
From: Ingo Schmid via pdl-devel <pdl-devel@lists.sourceforge.net>
Sent: 19 November 2024 6:06 PM
To: perldl <pdl-gene...@lists.sourceforge.net>; pdl-devel 
<pdl-devel@lists.sourceforge.net>
Subject: [Pdl-devel] curl of vector


Hi,

is there any implementations of calculating the curl of a vector field around?

Best wishes

Ingo
_______________________________________________
pdl-devel mailing list
pdl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pdl-devel

Reply via email to