Giter VIP home page Giter VIP logo

fmm2d.jl's Introduction

FMM2D.jl

Build Status Coverage

FMM2D.jl is a Julia interface for computing N-body interactions using the Flatiron Institute's FMM2D library.

Currently, the wrapper only wraps the Helmholtz and Laplace functionalities.

Helmholtz FMM

Let $c_s \in \mathbb{C},\ s = 1,\dots,N$ denote a collection of charge strengths, $v_s \in \mathbb{C},\ s = 1,\dots,N$ denote a collection of dipole strengths, and $d_s\in\mathbb{R}^2,\ s = 1,\dots,N$ denote the corresponding dipole orientation vectors. Furthermore, $k \in \mathbb{C}$ denotes the wave number. The Helmholtz potential $u$ caused by the presence of a collection of $M$ sources ($x_s$) at $N$ target positions ($x_t$) is computed as

$$ u\left(x_t\right) = \sum_{s=1}^{M} c_sH_0^{(1)}(k|x_t - x_s|) - v_sd_s\cdot\nabla H_0^{(1)}(k|x_t - x_s|), \quad t = 1,\dots, N $$

where $H_0^{(1)}$ is the Hankel function of the first kind of order 0. When $x = x_j$ the $j$ th term is dropped from the sum. Performing this summation would scale as $O(NM)$, but using the Flatiron Insitutes Fast Multipole Library a linear scaling of $O((N + M)\text{log}(\varepsilon^{-1}))$ can be achieved with $\varepsilon$ being the desired relative precision. Note that the library also includes the option for computing the gradient and Hessian of the potential.

Example

using FMM2D

# Simple example for the FMM2D Library
thresh = 10.0^(-5)          # Tolerance
zk     = rand(ComplexF64)   # Wavenumber

# Source-to-source
n = 200
sources = rand(2,n)
charges = rand(ComplexF64,n)
pg = 3 # Evaluate potential, gradient, and Hessian at the sources
vals = hfmm2d(eps=thresh,zk=zk,sources=sources,charges=charges,pg=pg)
vals.pot
vals.grad
vals.hess

# Source-to-target
m = 200
targets = rand(2,m)
pgt = 3 # Evaluate potential, gradient, and Hessian at the targets
vals = hfmm2d(targets=targets,eps=thresh,zk=zk,sources=sources,charges=charges,pgt=pgt)
vals.pottarg
vals.gradtarg
vals.hesstarg

Laplace

The Laplace problem in 2D have the following form

$$ u(x) = \sum_{j=1}^{N} \left[c_{j} \text{log}\left(|x-x_{j}|\right) - d_{j}v_{j} \cdot \nabla( \text{log}(|x-x_{j}|) )\right], $$

In the case of complex charges and dipole strengths ($c_j, v_j \in \mathbb{C}^n$) the function call lfmm2d has to be used. In the case of real charges and dipole strengths ($c_j, v_j \in \mathbb{R}^n$) the function call rfmm2d has to be used.

Example

using FMM2D

# Simple example for the FMM2D Library
thresh = 10.0^(-5)          # Tolerance

# Source-to-source
n = 200
sources = rand(2,n)
charges = rand(ComplexF64,n)
dipvecs = randn(2,n)
dipstr = rand(ComplexF64,n)
pg = 3 # Evaluate potential, gradient, and Hessian at the sources
vals = lfmm2d(eps=thresh,sources=sources,charges=charges,dipvecs=dipvecs,dipstr=dipstr,pg=pg)
vals.pot
vals.grad
vals.hess

# Source-to-target
m = 100
targets = rand(2,m)
pgt = 3 # Evaluate potential, gradient, and Hessian at the targets
vals = lfmm2d(targets=targets,eps=thresh,sources=sources,charges=charges,dipvecs=dipvecs,dipstr=dipstr,pgt=pgt)
vals.pottarg
vals.gradtarg
vals.hesstarg

Stokes

$$ u(x) = \sum_{j=1}^NG^\text{stok}(x,x_j)c_j + d_j\cdot T^\text{stok}(x,x_j)\cdot v_j $$

$$ p(x) = \sum_{j=1}^NP^\text{stok}(x,x_j)c_j + d_j\cdot \Pi^\text{stok}(x,x_j)\cdot v_j^\top $$

Related Package

FMMLIB2D.jl interfaces the FMMLIB2D library which the FMM2D library improves on.

fmm2d.jl's People

Contributors

mipals avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

tanderson92

fmm2d.jl's Issues

Laplace & Stokes support

It would be useful to me if this package would wrap Laplace and Stokes. In addition to FMM2D being described as an improvement to FMMLIB2D it has clear API advantages: it does checking for $x == x_j$ and drops such terms from the sum. This would be useful in a project I am working on, except the julia package doesn't support Laplace or Stokes.

Not essential, but these features would be appreciated (by myself and @maltezfaria)!

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

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.