spectral ewald documentation

21
Spectral Ewald Documentation Release 0.1 Ludvig af Klinteberg, Davoud Saffar Shamshirgar, Dag Lindbo Sep 10, 2018

Upload: others

Post on 23-Jun-2022

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Spectral Ewald Documentation

Spectral Ewald DocumentationRelease 0.1

Ludvig af Klinteberg, Davoud Saffar Shamshirgar, Dag Lindbo

Sep 10, 2018

Page 2: Spectral Ewald Documentation
Page 3: Spectral Ewald Documentation

Contents

1 Contents 31.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.2 Mathematical background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.3 Function reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.4 C interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

2 Indices 13

MATLAB Module Index 15

i

Page 4: Spectral Ewald Documentation

ii

Page 5: Spectral Ewald Documentation

Spectral Ewald Documentation, Release 0.1

This is the documentation for the unified Spectral Ewald package, available on GitHub at https://github.com/ludvigak/SE_unified . To obtain the lastest version simply execute

git clone https://github.com/ludvigak/SE_unified.git

Contents 1

Page 6: Spectral Ewald Documentation

Spectral Ewald Documentation, Release 0.1

2 Contents

Page 7: Spectral Ewald Documentation

CHAPTER 1

Contents

1.1 Introduction

The package provides a Matlab implementation of the Spectral Ewald method (SE) for fast Ewald summation relatedto six different kernels:

β€’ SE: 3-periodic Laplace (electrostatics)

β€’ SE2P: 2-periodic Laplace (electrostatics)

β€’ SE1P: 1-periodic Laplace (electrostatics)

β€’ SE0P: 0-periodic Laplace-Stokeslet-Stresslet-Rotlet (electrostatics and viscous flow)

β€’ SE_Stokes: 3-periodic Stokeslet (viscous flow)

β€’ SE2P_Stokes: 2-periodic Stokeslet (viscous flow)

β€’ SE_Stresslet: 3-periodic Stresslet (viscous flow)

β€’ SE_Rotlet: 3-periodic Rotlet (viscous flow)

The aim of this package is to provide fast routines for computing the Fourier space sums for the above kernels.Routines for the real space sums are provided for some kernels.

Most of the computational kernels are written in C, and quite some time has been spent optimizing them using explicitSIMD instructions and OpenMP shared-memory parallelism. The interfacing MEX layer is generally kept thin, sointerfacing to another language than Matlab should be quite straightforward.

1.1.1 Building

Most of the C/MEX code is now built with CMake. To build it open a terminal and do

cd buildcmake ..make

3

Page 8: Spectral Ewald Documentation

Spectral Ewald Documentation, Release 0.1

To run the test suite:

make test

Some of the C/MEX code is not yet integrated into CMake, and has to be built using Matlab build script. The buildscript is then called make.m and is located in the base folder for that kernel.

1.1.2 Getting started

Each directory contains the m-files related to that specific kernel. From any of these directories do

init % sets up paths

then depending on directory you can do

demo % Runs demo of spectral convergence + error estimates% for both real and Fourier space sums.

or

make % build C/MEX code for this directorytest_accuracy % should display plot of spectral convergence

Example (in Matlab):

cd SE_Rotletinitdemo

Most recent development has focused on 3P Stokes flow, so the directories related to that (SE_Stokes, SE_Rotlet,SE_Stresslet) are more developed.

Code examples for various are kernels can be found by looking at the tests, located in the folder mfile_tests ortests in the folder for the respective kernel.

1.1.3 Testing

Some directories contain a tests folder with unit tests. To run that test suite simply execute

initrun_unit_tests

To run the full suite, go to the root directory and run

run_unit_tests

This is recommended to do after building or before committing changes.

1.1.4 Additional files

The package also contains:

β€’ util: Common functions

β€’ SE_fast_gridding: C implementation of fast Gaussian gridding and fast Kaiser gridding

4 Chapter 1. Contents

Page 9: Spectral Ewald Documentation

Spectral Ewald Documentation, Release 0.1

β€’ SE_direct: C-code for direct Ewald sums for Laplace 2P/3P

β€’ SE_Stokes_direct: C-code for direct Ewald sums for Stokes 2P/P3

β€’ SE_leftovers: Spectral Ewald, fast real-space and k=0 codes for Laplace and Stokes. These are unmain-tained, but might prove useful.

1.2 Mathematical background

The Spectral Ewald method for the kernels included in this package is described in the below publications.

Electrostatics:

β€’ . D. Lindbo and A.-K. Tornberg, Spectral accuracy in fast Ewald-based methods for particle simulations,http://dx.doi.org/10.1016/j.jcp.2011.08.022

β€’ . D. Lindbo and A.-K. Tornberg, Fast and spectrally accurate Ewald summation for 2-periodic electrostaticsystems, http://dx.doi.org/10.1063/1.4704177

β€’ . A.-K. Tornberg, The Ewald sums for singly, doubly and triply periodic electrostatic systems, https://doi.org/10.1007/s10444-015-9422-3

β€’ . D. S. Shamshirgar and A.-K. Tornberg, The Spectral Ewald method for singly periodic domains, https://doi.org/10.1016/j.jcp.2017.07.001

β€’ . D. S. Shamshirgar and A.-K. Tornberg, Fast Ewald summation for electrostatic potentials with arbitraryperiodicity, https://arxiv.org/abs/1712.04732

Stokes:

β€’ . D. Lindbo and A.-K. Tornberg, Spectrally accurate fast summation for periodic Stokes potentials, http://dx.doi.org/10.1016/j.jcp.2010.08.026

β€’ . D. Lindbo and A.-K. Tornberg, Fast and spectrally accurate summation of 2-periodic Stokes potentials, http://arxiv.org/abs/1111.1815

β€’ . L. af Klinteberg and A.-K. Tornberg, Fast Ewald summation for Stokesian particle suspensions, http://dx.doi.org/10.1002/fld.3953

β€’ . L. af Klinteberg and D. S. Shamshirgar and A.-K. Tornberg, Fast Ewald summation for free-space Stokespotentials, https://doi.org/10.1186/s40687-016-0092-7

1.3 Function reference

Throughout this document the sumβˆ‘οΈ€

𝜏 implies the periodic sumβˆ‘οΈ€

π‘βˆˆZ3 with 𝜏 = (𝑝1𝐿1, 𝑝2𝐿2, 𝑝3𝐿3).

1.3.1 SE

Ewald summation for the 3-periodic electrostatic potential

𝑒(π‘₯) =βˆ‘οΈπœ

π‘βˆ‘οΈπ‘›=1

π‘žπ‘›|π‘₯βˆ’ π‘₯𝑛 + 𝜏 |

.

SE.se3p_fourier_space(x, f, opt)initialize time array

1.2. Mathematical background 5

Page 10: Spectral Ewald Documentation

Spectral Ewald Documentation, Release 0.1

SE.se3p_precomp(x, opt)SPECTRAL EWALD 3P, pre-computation of FGG vectors Fast Ewald method for electrostatic potential calcu-lation, k-space part.

SE.spectral_ewald(eval_idx, x, q, xi, opt)SPECTRAL EWALD Fast Ewald method for electrostatic potential calculation, k-space part.

phi = spectral_ewald(idx, x, q, xi, box, opt)

Returns phi – k-space part of periodic potential

Parameters

β€’ idx – evaluation indices (particle indices)

β€’ x – particle positions (N-by-3)

β€’ q – particle charge (N-by-1)

β€’ xi – Ewald parameter

β€’ opt – Options:

β€’ opt.M – grid size, eg. [31 31 31] (required)

β€’ opt.P – Gaussian support (required)

β€’ opt.box – Periodic cell, eg. [1 1 1]

β€’ opt.m – Gaussian shape function (default: m=m(P))

β€’ opt.w – Gaussian width (default: w=h*P/2)

1.3.2 SE2P

Ewald summation for the 2-periodic electrostatic potential.

1.3.3 SE1P

Ewald summation for the 1-periodic electrostatic potential.

1.3.4 SE0P

Ewald summation for the free-space electrostatic (stokeslet, stresslet, rotlet) potential.

1.3.5 SE_kaiser

Ewald summation for the electrostatic potential with arbitrary periodicity using Barnett-Magland kernel.

1.3.6 SE2P_Stokes

Ewald summation for the 2-periodic stokeslet potential.

SE2P_Stokes.SE2P_Stokes(eval_idx, x, f, xi, opt)SPECTRAL EWALD 2DP Fast Ewald method for electrostatic potential calculation, k-space part.

phi = spectral_ewald_2dp(idx, x, q, xi, opt)

6 Chapter 1. Contents

Page 11: Spectral Ewald Documentation

Spectral Ewald Documentation, Release 0.1

Dag Lindbo, [email protected], Jul. 2011

SE2P_Stokes.SE2P_Stokes_pre(x, xi, opt)SPECTRAL EWALD 2DP, pre-computation of FGG vectors

Dag Lindbo, [email protected], Jul. 2011

SE2P_Stokes.parse_params(opt)check that we have all mandatory options

1.3.7 SE_fast_gridding

Routines for fast gaussian gridding (FGG) and fast Kaiser gridding (FKG), which is central to Spectral Ewald.

SE_fast_gridding.SE_FGG_precomp(x, xi, opt)SPECTRAL EWALD 3P, pre-computation of FGG vectors Fast Ewald method for electrostatic potential calcu-lation, k-space part.

SE_fast_gridding.SE_fg_extend_fcn(F, opt)parameters and constants

SE_fast_gridding.SE_fg_int(x, U, opt)

u = SE_fg_int(x, U, opt) Return integration at x of on-grid values U

u = SE_fg_int(x, {U1, . . . , UN}, opt) Return integration at x of on-grid values U1,. . . ,UN u has N columns

SE_fast_gridding.SE_fg_int_extended(x, U, opt)parameters and constants

SE_fast_gridding.parse_params(opt)Parse parameter struct for fast Gaussian gridding

Mandatory parameters:

Parameters

β€’ opt.M – grid size (1 x 3)

β€’ opt.P – Gaussian width

β€’ opt.box – box size (1 x 3)

1.3.8 SE_Rotlet

Ewald summation for the 3-periodic rotlet potential

𝑒(π‘₯) =βˆ‘οΈπœ

π‘βˆ‘οΈπ‘›=1

𝑅(π‘₯βˆ’ π‘₯𝑛 + 𝜏)𝑑𝑛

where

𝑅𝑖𝑗(π‘Ÿ) = πœ–π‘–π‘—π‘˜π‘Ÿπ‘˜|π‘Ÿ|3

.

SE_Rotlet.SE_Rotlet(xe, x, f, xi, opt)

u = SE_Rotlet(x_targets, x_sources, f_sources, xi, opt) Returns the rotlet potential

[U1, U2, U3] = SE_Rotlet(x_targets, x_sources, f_sources, xi, opt) Returns the grid with Fourier coeffi-cients, π‘ˆπ‘– ∈ C𝑀1×𝑀2×𝑀3

1.3. Function reference 7

Page 12: Spectral Ewald Documentation

Spectral Ewald Documentation, Release 0.1

To compute u from U1,U2,U3:

F{1} = real( ifftn( ifftshift( U1 )));F{2} = real( ifftn( ifftshift( U2 )));F{3} = real( ifftn( ifftshift( U3 )));u = SE_fg_int(xe, F, opt);

opt must be identical to that passed to SE_Rotlet

TODO: Add possibility of passing precomputed structures

SE_Rotlet.rotlet_direct_fd(xe, x, f, xi, L, kmax)Direct summation of rotlet k-space part.

Parameters

β€’ xe – target positions, M-by-3

β€’ x – source positions, N-by-3

β€’ f – source strengths, N-by-3

β€’ xi – Ewald parameter,

β€’ L – box size, 1-by-3

β€’ kmax – k-space truncation

SE_Rotlet.rotlet_direct_real(idx, x, f, xi, L, varargin)Direct summation of rotlet real space part

phi = rotlet_direct_real(idx, x, t, xi, box, β€˜layers’, M, β€˜tol’, TOL); Compute interactions from all particleswithin M layers, stop at tolerance TOL.

phi = rotlet_direct_real(idx, x, t, xi, box, β€˜mode’,’cutoff’, β€˜rc’, rc); Compute interactions from all particleswithin cutoff radius rc.

SE_Rotlet.rotlet_direct_rsrc(xe, x, t, opt)Rotlet real space direct summation with cutoff radius, MEX implementation.

Parameters

β€’ xe – target locations

β€’ x – source locaitons

β€’ t – source strengths

β€’ opt – Ewald options

β€’ opt.box – box size

β€’ opt.xi – Ewald parameter πœ‰

β€’ opt.rc – Cutoff radius

SE_Rotlet.rotlet_ewald_sum(xe, x, t, opt)Ewald summation for 3P rotlet.

Parameters

β€’ xe – target locations

β€’ x – source locaitons

β€’ t – source strengths

β€’ opt – Ewald options

8 Chapter 1. Contents

Page 13: Spectral Ewald Documentation

Spectral Ewald Documentation, Release 0.1

β€’ opt.box – box size

β€’ opt.xi – Ewald parameter πœ‰

β€’ opt.M – Fourier space grid size

β€’ opt.P – Gaussian width

β€’ opt.rc – Real space cutoff radius

1.3.9 SE_Stokes

Ewald summation for the 3-periodic stokeslet potential

𝑒(π‘₯) =βˆ‘οΈπœ

π‘βˆ‘οΈπ‘›=1

𝑆(π‘₯βˆ’ π‘₯𝑛 + 𝜏)𝑓𝑛,

where

𝑆(π‘Ÿ) =𝐼

|π‘Ÿ|+

π‘Ÿ βŠ— π‘Ÿ

|π‘Ÿ|3.

SE_Stokes.SE_Stokes(eval_idx, x, f, xi, opt)Compute Fourier space part of Ewald sum for periodic stokeslet potential.

u = SE_Stokes(eval_idx,x,f,xi,opt) Return potential

[U1, U2, U3] = SE_Stokes(eval_idx,x,f,xi,opt) Return Fourier coefficients

Parameters

β€’ eval_idx – index of source locations where potential should be evaluated

β€’ x – source locations (Nx3)

β€’ f – source strengths (Nx3)

β€’ xi – Ewald paramter

β€’ opt – Ewald options

β€’ opt.M – grid size (M1, M2, M3)

β€’ opt.P – Gaussian width

β€’ opt.box – Box size (L1, L2, L3)

Returns phi – Fourier space potential

Returns U1,U2,U3 – Fourier space potential

SE_Stokes.SE_Stokes_ext(xe, xs, f, xi, opt)Evaluate Stokeslet at external points

SE_Stokes.SE_Stokes_par(eval_idx, x, f, xi, opt)parfor:ed version

1.3. Function reference 9

Page 14: Spectral Ewald Documentation

Spectral Ewald Documentation, Release 0.1

1.3.10 SE_Stresslet

Ewald summation for the 3-periodic stresslet potential

𝑒(π‘₯) =βˆ‘οΈπœ

π‘βˆ‘οΈπ‘š=1

π‘žπ‘šπ‘‡ (π‘₯βˆ’ π‘₯π‘š + 𝜏)οΏ½Μ‚οΏ½π‘š,

where

π‘‡π‘–π‘—π‘˜(π‘Ÿ) = βˆ’6π‘Ÿπ‘–π‘Ÿπ‘—π‘Ÿπ‘˜|π‘Ÿ|5

.

SE_Stresslet.SE_Stresslet(eval_idx, x, f, n, xi, opt, varargin)Compute Fourier space part of Ewald sum for periodic stresslet potential.

phi = SE_Stresslet(eval_idx,x,f,n,xi,opt) Return potential

[U1, U2, U3] = SE_Stresslet(eval_idx,x,f,n,xi,opt) Return Fourier coefficients

Parameters

β€’ eval_idx – index of source locations where potential should be evaluated

β€’ x – source locations (Nx3)

β€’ f – source strengths (Nx3)

β€’ n – source normals (Nx3)

β€’ xi – Ewald paramter

β€’ opt – Ewald options:

β€’ opt.M – grid size (M1, M2, M3)

β€’ opt.P – Gaussian width

β€’ opt.box – Box size (L1, L2, L3)

β€’ varargin=SE_static – Precomputations from SE_Stresslet_pre() to use SIMD FGGcode.

Returns phi – Fourier space potential

Returns U1,U2,U3 – Fourier space coefficients

SE_Stresslet.SE_Stresslet_pre(x, xi, opt)Precompute data for fast Gaussian gridding to enable optimized kernels

Returns SE_static

SE_Stresslet.generate_state(N, L, varargin)Returning x: Nx3 matrix with coords inside box L, f: Nx3 matrix with point forces. nvec: Nx3 matrix withassociated normal vectors.

SE_Stresslet.stresslet_direct_fd(idx, x, f, nvec, xi, L, kmax)Fourier space Ewald sum for stresslet, using (very slow) direct summation.

Parameters kmax – Fourier space truncation

SE_Stresslet.stresslet_direct_fd_zero(idx, xvec, fvec, nvec, L)Component for π‘˜ = 0 of stresslet Fourier sum.

Parameters

10 Chapter 1. Contents

Page 15: Spectral Ewald Documentation

Spectral Ewald Documentation, Release 0.1

β€’ idx – index of target positions (Nx1)

β€’ xvec – source positions (Nx3)

β€’ fvec – source strengths (Nx3)

β€’ nvec – normal vectors (Nx3)

β€’ L – box size (1x3)

Returns phi_k0 – (Nx3)

SE_Stresslet.stresslet_direct_real(idx, x, f, nvec, xi, L, nbox, TOL, varargin)Real space Ewald sum for stresslet, using (very slow) direct summation.

Parameters

β€’ nbox – Number of periodic replications in each direction.

β€’ TOL – Break when truncation error < TOL.

β€’ varargin=eval_x – Evaluate at eval_x instead of x(idx,:)

SE_Stresslet.stresslet_direct_real_fast(idx, x, f, nvec, xi, L, nbox, rc, varargin)Ewald summation for the stresslet – Real space part. Fast in the sense that it saves interactions as matrix forsubsequent iterations Sums over layers

β€’ [phi A] = stresslet_direct_real_fast( idx, x, f, nvec, xi, L, nbox, rc, [A, sing_sub, ns_quad_mtrx])

Parameters

β€’ x – positions :param (N-by-3)

β€’ f – source strengths (N-by-3)

β€’ nvec – normal vectors (N-by-3)

β€’ xi – Ewald parameter

β€’ L – Box size (3)

β€’ nbox – periodic replications

β€’ rc – cutoff radius

β€’ A – Precomputed matrix

β€’ sing_sub – Use singularity subtraction

β€’ ns_quad_mtrx – Correction matrices for nearly singular quadrature

SE_Stresslet.stresslet_op_fd(k, xi)Returns imaginary part of Bi(k, xi) ie B = 1i*Bi;

SE_Stresslet.stresslet_real_rc(x, q, nvec, xi, box, rc, varargin)Stresslet real space summation with truncation radius rc

Usage:

β€’ [res] = stresslet_real_rc( x, f, nvec, xi, box, rc);

β€’ [res AMAT] = stresslet_real_rc( x, f, nvec, xi, box, rc, [], sing_sub, ns_quad_mtrx);

β€’ [res AMAT] = stresslet_real_rc( x, f, nvec, xi, box, rc, AMAT, sing_sub, ns_quad_mtrx);

β€’ [res AMAT R C V PER] = stresslet_real_rc( x, f, nvec, xi, box, rc);

Parameters

1.3. Function reference 11

Page 16: Spectral Ewald Documentation

Spectral Ewald Documentation, Release 0.1

β€’ sing_sub – singularity subtraction, default 0. Only for matrix comp.

β€’ rc – cutoff radius, must be <= min(box)/2

1.4 C interface

TBD

12 Chapter 1. Contents

Page 17: Spectral Ewald Documentation

CHAPTER 2

Indices

β€’ genindex

β€’ modindex

13

Page 18: Spectral Ewald Documentation

Spectral Ewald Documentation, Release 0.1

14 Chapter 2. Indices

Page 19: Spectral Ewald Documentation

MATLAB Module Index

sSE, 5SE0P, 6SE1P, 6SE2P, 6SE2P_Stokes, 6SE_fast_gridding, 7SE_kaiser, 6SE_Rotlet, 7SE_Stokes, 9SE_Stresslet, 10

15

Page 20: Spectral Ewald Documentation

Spectral Ewald Documentation, Release 0.1

16 MATLAB Module Index

Page 21: Spectral Ewald Documentation

Index

Ggenerate_state() (in module SE_Stresslet), 10

Pparse_params() (in module SE2P_Stokes), 7parse_params() (in module SE_fast_gridding), 7

Rrotlet_direct_fd() (in module SE_Rotlet), 8rotlet_direct_real() (in module SE_Rotlet), 8rotlet_direct_rsrc() (in module SE_Rotlet), 8rotlet_ewald_sum() (in module SE_Rotlet), 8

SSE (module), 5SE0P (module), 6SE1P (module), 6SE2P (module), 6SE2P_Stokes (module), 6SE2P_Stokes() (in module SE2P_Stokes), 6SE2P_Stokes_pre() (in module SE2P_Stokes), 7se3p_fourier_space() (in module SE), 5se3p_precomp() (in module SE), 5SE_fast_gridding (module), 7SE_fg_extend_fcn() (in module SE_fast_gridding), 7SE_fg_int() (in module SE_fast_gridding), 7SE_fg_int_extended() (in module SE_fast_gridding), 7SE_FGG_precomp() (in module SE_fast_gridding), 7SE_kaiser (module), 6SE_Rotlet (module), 7SE_Rotlet() (in module SE_Rotlet), 7SE_Stokes (module), 9SE_Stokes() (in module SE_Stokes), 9SE_Stokes_ext() (in module SE_Stokes), 9SE_Stokes_par() (in module SE_Stokes), 9SE_Stresslet (module), 10SE_Stresslet() (in module SE_Stresslet), 10SE_Stresslet_pre() (in module SE_Stresslet), 10spectral_ewald() (in module SE), 6

stresslet_direct_fd() (in module SE_Stresslet), 10stresslet_direct_fd_zero() (in module SE_Stresslet), 10stresslet_direct_real() (in module SE_Stresslet), 11stresslet_direct_real_fast() (in module SE_Stresslet), 11stresslet_op_fd() (in module SE_Stresslet), 11stresslet_real_rc() (in module SE_Stresslet), 11

17