Giter Site home page Giter Site logo

Handling boundaries about parallelstencil.jl HOT 4 CLOSED

omlins avatar omlins commented on May 30, 2024
Handling boundaries

from parallelstencil.jl.

Comments (4)

ChrisRackauckas avatar ChrisRackauckas commented on May 30, 2024 1

Okay cool, thought that might be the case.

from parallelstencil.jl.

ChrisRackauckas avatar ChrisRackauckas commented on May 30, 2024 1

Ahh yes parallel_indices is the kind of primitive I was looking for, thanks.

from parallelstencil.jl.

luraess avatar luraess commented on May 30, 2024

Thanks @ChrisRackauckas for reporting and happy to see you could combine ParallelStencil to OrdinaryDiffEq!
Regarding the BCs, there is indeed no specific API available in ParallelStencil. The current example assumes implicitly that T on the boundaries is kept to its initial value, i.e. 0. Imposing Dirichlet BCs in x-direction and Neumann (no flux) in y-direction, leaving the z-direction to 0, one could write

@parallel diffusion3D_step!(du, u, Ci, lam, dx, dy, dz)
T[1  ,:  ,:  ] .= 4 # Dirichlet with value = 4
T[end,:  ,:  ] .= 3 # Dirichlet with value = 3
T[:  ,end,:  ] .= T[:,end-1,:] # Dirichlet
T[:  ,1  ,:  ] .= T[:,2,:] # Neumann no flux

or combine them in a more compact way (and eventually put them into kernels - currently needed for to enable @hide_communication to work with multi-GPUs).

-- EDIT --
When performance is relevant, BCs should be wrapped into a @parallel_indices call:

@parallel_indices (iy,iz) function bc_x!(A::Data.Array)
    A[1  , iy, iz] = 4
    A[end, iy, iz] = 3
    return
end

@parallel_indices (ix,iz) function bc_y!(A::Data.Array)
    A[ix, 1  , iz] = A[ix, 2    , iz]
    A[ix, end, iz] = A[ix, end-1, iz]
    return
end

and called with the according range:

@parallel diffusion3D_step!(du, u, Ci, lam, dx, dy, dz)
@parallel (1:size(du,2), 1:size(du,3)) bc_x!(du)
@parallel (1:size(du,1), 1:size(du,3)) bc_y!(du)

as in e.g. this 3D example.

from parallelstencil.jl.

luraess avatar luraess commented on May 30, 2024

My example was 2D while yours 3D - see EDITs, also for the kernel version.

from parallelstencil.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.