Hi Ed, Luis and Boyd,

thanks for the replies, I haven't had the time to look into the proposed solution yet. The problem behind this is to separate the shear component (curl) from the compressional (div) component of sound waves travelling through a liquid/solid medium, i.e. tissue.

Ingo

On 20.11.24 6:22 PM, Boyd Duffee wrote:
Hi Ingo,

I'm quite interested in what your use case is. It sounds like a great Advent Calendar entry (simple question, complete answer) if I could base it on an actual need. People don't get excited about "an exercise" as much as they do about someone trying to solve a problem, whether it's circulation in a fluid or some EM field calculation. As any that I could think of would be rather artificial, can you tell us yours?

Knowing the use case would also help with giving it a name in case someone decides that their Christmas project is writing a module that computes div, grad, curl and whether to name it PDL::Fields or PDL::VectorCalc.

(I'm now wondering if a curl over a 2D or 5D vector field makes any sense)

cheers,
Boyd

On Wed, 20 Nov 2024 at 10:18, Ed . <ej...@hotmail.com> wrote:

    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 |mv|ing, 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
_______________________________________________
pdl-devel mailing list
pdl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pdl-devel

Reply via email to