├── Python ├── Dependencies │ ├── finufft │ │ ├── requirements.txt │ │ ├── docs │ │ │ ├── requirements.txt │ │ │ ├── logo.png │ │ │ ├── spreadpic.png │ │ │ ├── pics │ │ │ │ ├── pois_fft.png │ │ │ │ ├── pois_fhat.png │ │ │ │ ├── pois_nufft.png │ │ │ │ └── pois_nugrid.png │ │ │ ├── genpdfmanual.sh │ │ │ ├── juliainterface.rst │ │ │ ├── genmatlabhelp.sh │ │ │ ├── matlab.rst │ │ │ ├── README │ │ │ ├── ackn.rst │ │ │ ├── dirs.rst │ │ │ ├── refs.rst │ │ │ ├── pythoninterface.rst │ │ │ ├── related.rst │ │ │ └── issues.rst │ │ ├── .gitignore │ │ ├── lib │ │ │ └── README │ │ ├── lib-static │ │ │ └── README │ │ ├── test │ │ │ ├── nuffttest2d.sh │ │ │ ├── nuffttest1d.sh │ │ │ ├── nuffttest3d.sh │ │ │ ├── dumbinputs │ │ │ ├── finufft1d_basicpassfail │ │ │ ├── results │ │ │ │ ├── README │ │ │ │ ├── testutils.refout │ │ │ │ ├── check1d.sh.refout │ │ │ │ ├── check3d.sh.refout │ │ │ │ ├── gcc_vs_icc_xeon.txt │ │ │ │ ├── check2d.sh.refout │ │ │ │ └── dumbinputs.refout │ │ │ ├── check1d.sh │ │ │ ├── check3d.sh │ │ │ ├── check2d.sh │ │ │ ├── highaspect3d_test.sh │ │ │ ├── testutils.cpp │ │ │ ├── checkallaccs.sh │ │ │ ├── README │ │ │ ├── mycpuinfo.sh │ │ │ ├── spreadtestnd.sh │ │ │ ├── nuffttestnd.sh │ │ │ ├── manysmallprobs.cpp │ │ │ └── finufft1d_basicpassfail.cpp │ │ ├── finufft-manual.pdf │ │ ├── make.inc.GCC7 │ │ ├── python_tests │ │ │ ├── run_accuracy_tests.py │ │ │ ├── run_speed_tests.py │ │ │ ├── README.md │ │ │ └── demo1d1.py │ │ ├── contrib │ │ │ └── legendre_rule_fast.h │ │ ├── devel │ │ │ ├── i7_1thr_ker_eval_speeds.png │ │ │ ├── gen_ker_horner_C_code.m │ │ │ ├── gen_all_horner_C_code.m │ │ │ ├── fig_speed_ker_ppval.m │ │ │ └── ker_ppval_coeff_mat.m │ │ ├── make.inc.linux_ICC │ │ ├── examples │ │ │ └── README │ │ ├── finufftpy │ │ │ ├── __init__.py │ │ │ └── ndarray.h │ │ ├── matlab │ │ │ ├── test_strictadjoint.m │ │ │ ├── fig_accuracy.m │ │ │ ├── finufft_opts.m │ │ │ ├── check_changenthreads.m │ │ │ ├── finufft1d3.m │ │ │ ├── finufft1d2.m │ │ │ ├── big1dtest.m │ │ │ ├── finufft2d3.m │ │ │ ├── finufft1d1.m │ │ │ ├── finufft_m.h │ │ │ ├── finufft2d2.m │ │ │ ├── finufft3d3.m │ │ │ ├── finufft2d2many.m │ │ │ ├── check_modeords.m │ │ │ ├── finufft3d2.m │ │ │ └── finufft2d1.m │ │ ├── src │ │ │ ├── utils.h │ │ │ ├── dirft.h │ │ │ └── common.h │ │ ├── LICENSE │ │ ├── fortran │ │ │ ├── README │ │ │ └── finufft_f.h │ │ ├── make.inc.macosx_clang │ │ ├── make.inc.macosx_gcc-8 │ │ └── README.md │ ├── mykrypy │ │ ├── recycling │ │ │ ├── __pycache__ │ │ │ │ ├── linsys.cpython-36.pyc │ │ │ │ ├── linsys.cpython-38.pyc │ │ │ │ ├── __init__.cpython-36.pyc │ │ │ │ ├── __init__.cpython-38.pyc │ │ │ │ ├── evaluators.cpython-36.pyc │ │ │ │ ├── evaluators.cpython-38.pyc │ │ │ │ ├── factories.cpython-36.pyc │ │ │ │ ├── factories.cpython-38.pyc │ │ │ │ ├── generators.cpython-36.pyc │ │ │ │ └── generators.cpython-38.pyc │ │ │ └── __init__.py │ │ ├── __about__.py │ │ └── __init__.py │ └── NeighborSearch │ │ ├── Makefile │ │ ├── nlistNew.py │ │ └── nlist.py ├── FileIO.py ├── cppmodules │ ├── types.h │ └── makefile ├── Examples │ └── SampleSlurmFile.sh └── makefile ├── .gitignore ├── docs ├── requirements.txt ├── DiscretizedFiber.rst ├── Domain.rst ├── fiberCollection.rst ├── StericForceEvaluator.rst ├── RPYVelocityEvaluator.rst ├── SpatialDatabase.rst ├── FibCollocationDiscretization.rst ├── CrossLinkedNetwork.rst ├── TemporalIntegrator.rst ├── Examples.rst ├── PythonClasses.rst ├── index.rst └── OtherExamples.rst ├── Matlab ├── functions-solvers │ ├── CPMatrix.m │ ├── linequad │ │ └── matlabcheb │ │ │ ├── bernstein_radius.m │ │ │ ├── sfigure.m │ │ │ ├── chebCoeffDiff.m │ │ │ ├── recursions │ │ │ ├── eval_series.m │ │ │ ├── rsqrt2_pow_integrals.m │ │ │ ├── coeffs_I3.m │ │ │ └── coeffs_I5.m │ │ │ ├── rsqrt_pow_weights.m │ │ │ ├── rootfinder_initial_guess.m │ │ │ └── RunIntegral.m │ ├── stackMatrix.m │ ├── FIMatrix.m │ ├── KonNp1.m │ ├── KRigidonNp1.m │ ├── Ewald │ │ ├── spread.m │ │ ├── RPYEwaldBlobs.m │ │ ├── EwaldNearPoisson.m │ │ ├── EwaldFarPoissonFI.m │ │ ├── EwaldFarPoisson.m │ │ ├── SMatLESlow.m │ │ ├── EwaldNearSum.m │ │ ├── EwaldFarVelFI.m │ │ └── EwaldFarVel.m │ ├── KInvonNp1.m │ ├── rotate.m │ ├── deltah.m │ ├── getModuli.m │ ├── rotateTau.m │ ├── FilterM.m │ ├── calcShifted.m │ ├── RPYTot.m │ ├── initFibs.m │ ├── EvalU0.m │ ├── getMlocRotlet.m │ ├── RegularizeS.m │ ├── getMlocDoublet.m │ ├── getMlocStokeslet.m │ ├── PolymerizeBarbed.m │ ├── computeBishopFrame.m │ ├── precomputeDoubletInts.m │ ├── updateX.m │ ├── PeriodicRPYSum.m │ ├── UnboundedRPYSum.m │ ├── TemporalIntegrator_TransDet.m │ ├── getCLforceEn.m │ ├── precomputeStokesletInts.m │ ├── StokesletFinitePartMatrix.m │ ├── DoubletFinitePartMatrix.m │ ├── getStress.m │ └── updateMovingLinks.m ├── BrownianFlucts │ ├── Membrane │ │ ├── PlotFil.m │ │ ├── computeMembraneEnergy.m │ │ ├── UpdateMembrane.m │ │ ├── PlotMem.m │ │ ├── InterpolatehNUFFT.m │ │ ├── SpreadStericForceToMem.m │ │ └── InterpFromGrid.m │ ├── ManualPinv.m │ ├── MCMC │ │ ├── BlobLink │ │ │ ├── KT_mat.m │ │ │ ├── Bishop.m │ │ │ └── Tau_Rot_Full.m │ │ └── MakeMCMCEEFig.m │ ├── LocalDragMob.m │ ├── RandomPolymerization.m │ └── TimescalesLinearized.m ├── NumericalSBT │ ├── FlorenFiberSpec.m │ ├── KMatBlobs.m │ ├── getGrandMBlobs.m │ ├── upsampleStokeslet.m │ ├── upsampleRPYRotRot.m │ ├── upsampleRPYRotTrans.m │ └── upsampleRPY.m ├── ChebyshevAndBlobs │ ├── Semiflexible │ │ └── rand_alpha.m │ ├── simpson_nonuniform.m │ └── ChebUniformLstSquares.m ├── MainPrograms │ ├── BishopFrameConvergence.m │ ├── Filopodium │ │ ├── StabilityThetConst.m │ │ ├── README.md │ │ └── PlotTraj.m │ ├── StraightMobility.m │ ├── SBTRelaxingFib.m │ └── InitializationNoTwist.m ├── README.md └── AnalyzePython │ └── MakePlotConfigs.m ├── .gitmodules ├── install.sh └── .readthedocs.yaml /Python/Dependencies/finufft/requirements.txt: -------------------------------------------------------------------------------- 1 | pybind11 2 | numpy 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.so 3 | *#* 4 | *~ 5 | *pyc 6 | *pycache* 7 | *bak 8 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | scipy 3 | numba 4 | sphinx_math_dollar 5 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/docs/requirements.txt: -------------------------------------------------------------------------------- 1 | texext 2 | sphinx_rtd_theme 3 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/.gitignore: -------------------------------------------------------------------------------- 1 | *_test 2 | *~ 3 | *.a 4 | *.so 5 | *.out 6 | *.o -------------------------------------------------------------------------------- /Python/Dependencies/finufft/lib/README: -------------------------------------------------------------------------------- 1 | This directory is where the shared libraries will appear. 2 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/lib-static/README: -------------------------------------------------------------------------------- 1 | This directory is where the static libraries will appear. 2 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/test/nuffttest2d.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # default 2d nufft test 3 | 4 | ./finufft2d_test 500 2e3 1e6 1e-6 $DEBUG 5 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/test/nuffttest1d.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # default 1d nufft test 3 | 4 | ./finufft1d_test 1e6 1e6 1e-6 $NUFFTTESTDEBUG 5 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/test/nuffttest3d.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # default 3d nufft test 3 | 4 | ./finufft3d_test 100 200 50 1e6 1e-6 $DEBUG 5 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/docs/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stochasticHydroTools/SlenderBody/HEAD/Python/Dependencies/finufft/docs/logo.png -------------------------------------------------------------------------------- /Python/Dependencies/finufft/test/dumbinputs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stochasticHydroTools/SlenderBody/HEAD/Python/Dependencies/finufft/test/dumbinputs -------------------------------------------------------------------------------- /Python/Dependencies/finufft/docs/spreadpic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stochasticHydroTools/SlenderBody/HEAD/Python/Dependencies/finufft/docs/spreadpic.png -------------------------------------------------------------------------------- /Python/Dependencies/finufft/finufft-manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stochasticHydroTools/SlenderBody/HEAD/Python/Dependencies/finufft/finufft-manual.pdf -------------------------------------------------------------------------------- /Python/Dependencies/finufft/make.inc.GCC7: -------------------------------------------------------------------------------- 1 | # example override compiler choices in makefile. Here we use GCC 7. 2 | 3 | CXX=g++-7 4 | CC=gcc-7 5 | FC=gfortran-7 6 | -------------------------------------------------------------------------------- /Matlab/functions-solvers/CPMatrix.m: -------------------------------------------------------------------------------- 1 | function ACross = CPMatrix(a) 2 | % ACross x b = a cross b 3 | ACross = [0 -a(3) a(2); a(3) 0 -a(1); -a(2) a(1) 0]; 4 | end -------------------------------------------------------------------------------- /Python/Dependencies/finufft/docs/pics/pois_fft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stochasticHydroTools/SlenderBody/HEAD/Python/Dependencies/finufft/docs/pics/pois_fft.png -------------------------------------------------------------------------------- /Python/Dependencies/finufft/docs/pics/pois_fhat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stochasticHydroTools/SlenderBody/HEAD/Python/Dependencies/finufft/docs/pics/pois_fhat.png -------------------------------------------------------------------------------- /Python/Dependencies/finufft/docs/pics/pois_nufft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stochasticHydroTools/SlenderBody/HEAD/Python/Dependencies/finufft/docs/pics/pois_nufft.png -------------------------------------------------------------------------------- /Python/Dependencies/finufft/python_tests/run_accuracy_tests.py: -------------------------------------------------------------------------------- 1 | from accuracy_speed_tests import accuracy_speed_tests 2 | 3 | accuracy_speed_tests(100000,100000,1e-6) 4 | -------------------------------------------------------------------------------- /Matlab/BrownianFlucts/Membrane/PlotFil.m: -------------------------------------------------------------------------------- 1 | function PlotFil(Disc) 2 | Rpl = Disc.RplNp1; 3 | plot3(Rpl*Disc.Xt(1:3:end),Rpl*Disc.Xt(2:3:end), Rpl*Disc.Xt(3:3:end)); 4 | end -------------------------------------------------------------------------------- /Matlab/functions-solvers/linequad/matlabcheb/bernstein_radius.m: -------------------------------------------------------------------------------- 1 | function rho = bernstein_radius(z) 2 | % rho = bernstein_radius(z) 3 | rho = abs(z + sqrt(z - 1).*sqrt(z+1)); -------------------------------------------------------------------------------- /Python/Dependencies/finufft/docs/pics/pois_nugrid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stochasticHydroTools/SlenderBody/HEAD/Python/Dependencies/finufft/docs/pics/pois_nugrid.png -------------------------------------------------------------------------------- /Python/Dependencies/finufft/test/finufft1d_basicpassfail: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stochasticHydroTools/SlenderBody/HEAD/Python/Dependencies/finufft/test/finufft1d_basicpassfail -------------------------------------------------------------------------------- /Python/Dependencies/finufft/python_tests/run_speed_tests.py: -------------------------------------------------------------------------------- 1 | from accuracy_speed_tests import accuracy_speed_tests 2 | 3 | accuracy_speed_tests(1e6,1e6,1e-6) # ahb lowered from 8e6 4 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/contrib/legendre_rule_fast.h: -------------------------------------------------------------------------------- 1 | #ifndef GAUSSQUAD_H 2 | #define GAUSSQUAD_H 3 | 4 | void legendre_compute_glr ( int n, double x[], double w[] ); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/devel/i7_1thr_ker_eval_speeds.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stochasticHydroTools/SlenderBody/HEAD/Python/Dependencies/finufft/devel/i7_1thr_ker_eval_speeds.png -------------------------------------------------------------------------------- /Matlab/functions-solvers/stackMatrix.m: -------------------------------------------------------------------------------- 1 | function Ds = stackMatrix(D) 2 | [N,C]=size(D); 3 | Ds = zeros(3*N,3*C); 4 | for iD=1:3 5 | Ds(iD:3:end,iD:3:end)=D; 6 | end 7 | end -------------------------------------------------------------------------------- /Python/Dependencies/finufft/test/results/README: -------------------------------------------------------------------------------- 1 | Results directory for tests. The *.refout are crucial for validation 2 | via numdiff and are not to be adjusted by users. 3 | 4 | Barnett 3/13/17 5 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/test/check1d.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Standard checker for all 1d routines. Sed removes the timing lines (w/ "NU") 3 | ./finufft1d_test 1e3 1e3 $FINUFFT_REQ_TOL 0 | sed '/NU/d' 4 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/test/check3d.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Standard checker for all 1d routines. Sed removes the timing lines (w/ "NU") 3 | ./finufft3d_test 5 10 20 1e3 $FINUFFT_REQ_TOL 0 | sed '/NU/d' 4 | -------------------------------------------------------------------------------- /Python/Dependencies/mykrypy/recycling/__pycache__/linsys.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stochasticHydroTools/SlenderBody/HEAD/Python/Dependencies/mykrypy/recycling/__pycache__/linsys.cpython-36.pyc -------------------------------------------------------------------------------- /Python/Dependencies/mykrypy/recycling/__pycache__/linsys.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stochasticHydroTools/SlenderBody/HEAD/Python/Dependencies/mykrypy/recycling/__pycache__/linsys.cpython-38.pyc -------------------------------------------------------------------------------- /Python/Dependencies/mykrypy/recycling/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stochasticHydroTools/SlenderBody/HEAD/Python/Dependencies/mykrypy/recycling/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /Python/Dependencies/mykrypy/recycling/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stochasticHydroTools/SlenderBody/HEAD/Python/Dependencies/mykrypy/recycling/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /Python/Dependencies/mykrypy/recycling/__pycache__/evaluators.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stochasticHydroTools/SlenderBody/HEAD/Python/Dependencies/mykrypy/recycling/__pycache__/evaluators.cpython-36.pyc -------------------------------------------------------------------------------- /Python/Dependencies/mykrypy/recycling/__pycache__/evaluators.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stochasticHydroTools/SlenderBody/HEAD/Python/Dependencies/mykrypy/recycling/__pycache__/evaluators.cpython-38.pyc -------------------------------------------------------------------------------- /Python/Dependencies/mykrypy/recycling/__pycache__/factories.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stochasticHydroTools/SlenderBody/HEAD/Python/Dependencies/mykrypy/recycling/__pycache__/factories.cpython-36.pyc -------------------------------------------------------------------------------- /Python/Dependencies/mykrypy/recycling/__pycache__/factories.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stochasticHydroTools/SlenderBody/HEAD/Python/Dependencies/mykrypy/recycling/__pycache__/factories.cpython-38.pyc -------------------------------------------------------------------------------- /Python/Dependencies/mykrypy/recycling/__pycache__/generators.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stochasticHydroTools/SlenderBody/HEAD/Python/Dependencies/mykrypy/recycling/__pycache__/generators.cpython-36.pyc -------------------------------------------------------------------------------- /Python/Dependencies/mykrypy/recycling/__pycache__/generators.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stochasticHydroTools/SlenderBody/HEAD/Python/Dependencies/mykrypy/recycling/__pycache__/generators.cpython-38.pyc -------------------------------------------------------------------------------- /Matlab/functions-solvers/linequad/matlabcheb/sfigure.m: -------------------------------------------------------------------------------- 1 | function h = sfigure(f) 2 | if nargin==0 3 | h = figure(); 4 | elseif ishandle(f) 5 | set(0, 'CurrentFigure', f); 6 | else 7 | h = figure(f); 8 | end 9 | -------------------------------------------------------------------------------- /docs/DiscretizedFiber.rst: -------------------------------------------------------------------------------- 1 | Generating and saving fiber positions (class DiscretizedFiber) 2 | =============================================================== 3 | .. autoclass:: DiscretizedFiber.DiscretizedFiber 4 | :members: 5 | -------------------------------------------------------------------------------- /docs/Domain.rst: -------------------------------------------------------------------------------- 1 | Periodic domains with shear (class Domain) 2 | =================================================== 3 | .. autoclass:: Domain.Domain 4 | :members: 5 | .. autoclass:: Domain.PeriodicShearedDomain 6 | :members: 7 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/docs/genpdfmanual.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This makes the PDF manual then moves it and renames to the top directory. 3 | # Barnett 12/6/17 4 | 5 | make latexpdf 6 | mv _build/latex/finufft.pdf ../finufft-manual.pdf 7 | -------------------------------------------------------------------------------- /Matlab/BrownianFlucts/ManualPinv.m: -------------------------------------------------------------------------------- 1 | function PInvSP = ManualPinv(Mat,maxRank) 2 | [U,S,V]=svd(Mat); 3 | S=diag(S); 4 | S(maxRank+1:end)=0; 5 | S(S/S(1)<1e-10)=0; 6 | pinvS = 1./S; 7 | pinvS(S==0)=0; 8 | PInvSP = V*diag(pinvS)*U'; 9 | end -------------------------------------------------------------------------------- /Matlab/BrownianFlucts/Membrane/computeMembraneEnergy.m: -------------------------------------------------------------------------------- 1 | function En = computeMembraneEnergy(Mem) 2 | hhat = fft2(reshape(Mem.h,Mem.M,Mem.M)); 3 | ksqhhat = conj(hhat).*Mem.FourierEnergyMat.*hhat; 4 | % Integrate and square 5 | En = 1/2*sum(ksqhhat(:)); 6 | end -------------------------------------------------------------------------------- /Matlab/functions-solvers/linequad/matlabcheb/chebCoeffDiff.m: -------------------------------------------------------------------------------- 1 | function Df = chebCoeffDiff(fhat,Nz) 2 | Df = zeros(size(fhat)); 3 | Df(Nz-1) = 2*(Nz-1)*fhat(Nz); 4 | for j = 2:Nz-1 5 | Df(Nz-j) = Df(Nz-j+2) + 2*(Nz-j)*fhat(Nz-j+1); 6 | end 7 | Df(1)=Df(1)/2; 8 | end -------------------------------------------------------------------------------- /Matlab/functions-solvers/FIMatrix.m: -------------------------------------------------------------------------------- 1 | % THE MATRIX FOR THE FIRST INTEGRAL 2 | function FIMat = FIMatrix(N) 3 | jj=(2:N-1)'; 4 | colm1=[0; 1; 1./(2*jj)]; 5 | colp1=[0; -1/2; -1./(2*jj).*(jj`_, an interface from the `Julia `_ language. This package will automatically download and build FINUFFT at installation, as long as GCC is available. It has been tested on Linux and Mac OS X (the latter with GCC 8). 5 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/test/highaspect3d_test.sh: -------------------------------------------------------------------------------- 1 | # test various poor aspect ratios in 3d 2 | # Barnett 2/6/17 3 | 4 | # fastest 5 | time ./finufft3d_test 10 400 400 1e6 1e-12 0 6 | 7 | # weird thing is this one is slowest even though z split is easy - RAM access? 8 | time ./finufft3d_test 400 10 400 1e6 1e-12 0 9 | 10 | # expect poor when split only along z: 11 | time ./finufft3d_test 400 400 10 1e6 1e-12 0 12 | -------------------------------------------------------------------------------- /docs/TemporalIntegrator.rst: -------------------------------------------------------------------------------- 1 | Temporal integration (class TemporalIntegrator) 2 | ================================================ 3 | .. autoclass:: TemporalIntegrator.TemporalIntegrator 4 | :members: 5 | .. autoclass:: TemporalIntegrator.BackwardEuler 6 | :members: 7 | .. autoclass:: TemporalIntegrator.CrankNicolson 8 | :members: 9 | .. autoclass:: TemporalIntegrator.MidpointDriftIntegrator 10 | :members: 11 | -------------------------------------------------------------------------------- /Matlab/BrownianFlucts/Membrane/UpdateMembrane.m: -------------------------------------------------------------------------------- 1 | function Mem = UpdateMembrane(Mem,Fext,kbT,dt) 2 | Fh = -Mem.Kh*Mem.h; 3 | RHSmem = Mem.Mmem*(Fext+Fh)... 4 | +sqrt(2*kbT/dt)*Mem.Mhalfmem*randn(Mem.M^2,1); 5 | % hnew = InvImpMatMem*(hmem/dt+RHSmem); 6 | % FFT way 7 | RHSHat = fft2(reshape(Mem.h/dt+RHSmem,Mem.M,Mem.M)); 8 | hNewHat = RHSHat./Mem.ImpfacFourier; 9 | hnew = ifft2(hNewHat); 10 | Mem.h = hnew(:); 11 | end -------------------------------------------------------------------------------- /Matlab/functions-solvers/FilterM.m: -------------------------------------------------------------------------------- 1 | function M = FilterM(M,thres) 2 | [V,D]=eig(M); 3 | D = real(diag(D)); 4 | D(D < thres) = thres; 5 | %DHalf = sqrt(D); 6 | %DMinusHalf = 1./DHalf; DMinusHalf(D < 1e-10) = 0; 7 | %Dinv = 1./D; Dinv(D < 1e-10) = 0; 8 | Vinv = V^(-1); 9 | M = V*diag(D)*Vinv; 10 | %Minv = V*diag(Dinv)*Vinv; 11 | %MHalf = V*diag(DHalf)*Vinv; 12 | %MMinusHalf = V*diag(DMinusHalf)*Vinv; 13 | end 14 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/python_tests/README.md: -------------------------------------------------------------------------------- 1 | ## Accuracy and speed tests using the python wrappers 2 | 3 | To install the python (or python3) wrappers for finufft, see ../docs/install.rst 4 | 5 | Then you may run the tests as follows 6 | 7 | ``` 8 | python3 demo1d1.py 9 | python3 run_accuracy_tests.py 10 | python3 run_speed_tests.py 11 | ``` 12 | 13 | The codes `demo1d1.py` and `accuracy_speed_tests.py` illustrate how to call 14 | FINUFFT from python. 15 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/docs/genmatlabhelp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # this cleans out just the MATLAB documentation blocks from the MWrap file 3 | # Three steps: 1) keep comment lines beginning with %, 2) remove the first 4 | # char of each line, then 3) remove the header (until the first line of ----). 5 | # This relies on having such a -------- line in the .mw file. 6 | # Barnett 11/2/17 7 | 8 | sed -n '/^%/p' ../matlab/finufft.mw | sed 's/^.//' | sed -n '/-----/,$p' > matlabhelp.raw 9 | -------------------------------------------------------------------------------- /docs/Examples.rst: -------------------------------------------------------------------------------- 1 | Running the examples 2 | =============================================================== 3 | The examples fall into two categories: cross-linked fiber 4 | networks that are meant to simulate in vitro actin suspensions, 5 | and systems of fibers that are used more for numerical testing. 6 | Click the corresponding link below for more information. 7 | 8 | 9 | Contents: 10 | 11 | .. toctree:: 12 | :maxdepth: 1 13 | 14 | CrossLinkedExamples 15 | OtherExamples 16 | -------------------------------------------------------------------------------- /Matlab/functions-solvers/calcShifted.m: -------------------------------------------------------------------------------- 1 | % Shift vector periodically along primed coordinates until it 2 | % is on [-L/2,L/2]^3 3 | function [dvec,shift] = calcShifted(dvec,g,Lx,Ly,Lz) 4 | % Shift in oblique y and z 5 | shift1 = round([0*dvec(:,1) dvec(:,2)/Ly dvec(:,3)/Lz]); 6 | dvec = dvec-([g*Ly*shift1(:,2) Ly*shift1(:,2) Lz*shift1(:,3)]); 7 | % Shift in x 8 | shift2 = round(dvec(:,1)/Lx); 9 | shift = [shift2 shift1(:,2:3)]; 10 | dvec = dvec-[shift2*Lx 0*shift2 0*shift2]; 11 | end -------------------------------------------------------------------------------- /Python/Dependencies/finufft/examples/README: -------------------------------------------------------------------------------- 1 | This directory contains simple calling examples from C++ (the .cpp files) 2 | and from C (the .c files). 3 | 4 | They are compiled by commands in ../makefile via "make examples". 5 | 6 | The suffix "f" which distinguishes example1d1f.cpp from example1d1.cpp 7 | indicates single-precision as opposed to double-precision. Which is 8 | compiled is controlled by ../makefile. 9 | 10 | For calling from Fortran, see the demos in ../fortran/ 11 | 12 | Alex Barnett 12/6/17 13 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/test/results/gcc_vs_icc_xeon.txt: -------------------------------------------------------------------------------- 1 | Comparing GCC 6.4.0 vs ICC 17.0.4, on xeon E5-2643 v3 @ 3.40GHz 2 | 3/28/18 3 | 4 | spreadtestnd d 1e7 1e7 1e-6 2 5 | 6 | Timings in sec: 7 | 8 | single-thread: 9 | 10 | t1 t2 11 | 12 | GCC ICC GCC ICC 13 | 14 | 1d 2.7 1.7 3.3 2.7 15 | 2d 4.5 2.7 5.0 4.5 16 | 3d 8.6 5.7 10.9 8.4 17 | 18 | 24-thread: 19 | 20 | 1d .49 .38 .48 .36 21 | 2d .5 .34 .48 .37 22 | 3d .82 .62 .76 .58 23 | 24 | Note: sorting a bit slower under ICC, but spreading is faster. 25 | 26 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/test/testutils.cpp: -------------------------------------------------------------------------------- 1 | #include "../src/utils.h" 2 | #include 3 | 4 | int main(int argc, char* argv[]) 5 | // test next235even. Barnett 2/9/17, made smaller range 3/28/17 6 | { 7 | for (BIGINT n=90;n<100;++n) 8 | printf("next235even(%lld) =\t%lld\n",(long long)n,(long long)next235even(n)); 9 | 10 | //printf("starting huge next235even...\n"); // 1e11 takes 1 sec 11 | //BIGINT n=(BIGINT)120573851963; 12 | //printf("next235even(%ld) =\t%ld\n",n,next235even(n)); 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /Python/FileIO.py: -------------------------------------------------------------------------------- 1 | """ 2 | Utilities for file input and output 3 | """ 4 | 5 | def prepareOutFile(name): 6 | outFile = name; 7 | of = open(outFile,'w'); 8 | of.close(); 9 | of = open(outFile,'a'); 10 | return of; 11 | 12 | def writeArray(name,stress,wora='w'): 13 | """ 14 | Write the locations to a file object of. 15 | """ 16 | outFile = name; 17 | of = open(outFile,wora); 18 | N = len(stress); # to save writing 19 | for i in range(N): 20 | of.write('%14.15f \n' % stress[i]); -------------------------------------------------------------------------------- /Matlab/BrownianFlucts/MCMC/BlobLink/KT_mat.m: -------------------------------------------------------------------------------- 1 | function [KT] = KT_mat(ds,U,V, clamp) 2 | % Compute the K matrix 3 | 4 | [m,n] = size(U); 5 | 6 | for j = 1:n+1 7 | blocks{1,j} = speye(3); 8 | end 9 | 10 | Ind = 0; 11 | if clamp 12 | Ind = 1; 13 | end 14 | 15 | for i= 2:(1+n) 16 | for j = 1:(1+n) 17 | if j < i 18 | blocks{i-Ind,j} = sparse(2,3); 19 | else 20 | blocks{i-Ind,j} = (-1)*ds*[V(:,i-1) -U(:,i-1)]'; %%% MODIFIED TO NEG 21 | end 22 | end 23 | end 24 | 25 | KT = cell2mat(blocks); 26 | 27 | end -------------------------------------------------------------------------------- /Matlab/BrownianFlucts/Membrane/PlotMem.m: -------------------------------------------------------------------------------- 1 | function PlotMem(Mem,xCt,yCt) 2 | for iX=xCt 3 | for iY=yCt 4 | XPl = [Mem.xgu Mem.xgu(:,1)+Mem.Lm]; 5 | XPl = [XPl; XPl(1,:)]; 6 | YPl = [Mem.ygu; Mem.ygu(1,:)+Mem.Lm]; 7 | YPl = [YPl YPl(:,1)]; 8 | hmempl = reshape(Mem.UpsamplingMatrix*Mem.h,Mem.Nu,Mem.Nu); 9 | hmempl = [hmempl hmempl(:,1)]; 10 | hmempl = [hmempl; hmempl(1,:)]; 11 | surf(XPl+Mem.Lm*iX,YPl+Mem.Lm*iY,hmempl,... 12 | 'FaceColor','interp','EdgeColor','interp','FaceAlpha',0.5) 13 | end 14 | end 15 | end -------------------------------------------------------------------------------- /Python/Dependencies/finufft/docs/matlab.rst: -------------------------------------------------------------------------------- 1 | MATLAB/octave interfaces 2 | ======================== 3 | 4 | .. literalinclude:: matlabhelp.raw 5 | 6 | A note on integer sizes: 7 | In Matlab/MEX, mwrap uses ``int`` types, so that output arrays can only 8 | be <2^31. 9 | However, input arrays >=2^31 have been tested, and while they don't crash, 10 | they result in wrong answers (all zeros). This has yet to be fixed 11 | (please help; an updated version of mwrap might be needed). 12 | 13 | For a full list of error codes see :ref:`errcodes`. 14 | 15 | 16 | -------------------------------------------------------------------------------- /Matlab/functions-solvers/Ewald/RPYEwaldBlobs.m: -------------------------------------------------------------------------------- 1 | % Testing 2 | Lx = 1.5; 3 | Ly = 2.0; 4 | Lz = 2.4; 5 | a=0.012; 6 | mu = 1.5; 7 | xi = 10; 8 | pts = load('PtsEwald.txt'); 9 | forces = load('ForcesEwald.txt'); 10 | g=0.3; 11 | 12 | [Npts,~]=size(pts); 13 | tic 14 | velfar = EwaldFarVel(pts,forces,mu,Lx,Ly,Lz,xi,a,g); 15 | toc 16 | tic 17 | velfar2 = EwaldFarVelFI(pts,forces,mu,Lx,Ly,Lz,xi,a,g)'; 18 | toc 19 | velNear = EwaldNearSum(Npts,pts,forces,xi,Lx,Ly,Lz,a,mu,g); 20 | velEwald=velNear+velfar2; 21 | UPy = load('EwaldVelocity.txt'); 22 | max(abs(velEwald-UPy)) 23 | -------------------------------------------------------------------------------- /Matlab/BrownianFlucts/LocalDragMob.m: -------------------------------------------------------------------------------- 1 | function MWsym = LocalDragMob(X,DNp1,const,WTilde_Np1_Inverse) 2 | % Compute tangent vector 3 | Nx = length(X)/3; 4 | Xs = DNp1*reshape(X,3,[])'; 5 | Xs = Xs./sqrt(sum(Xs.*Xs,2)); 6 | M = zeros(3*Nx); 7 | for j = 1:Nx 8 | M(3*j-2:3*j,3*j-2:3*j)=const*(eye(3)+Xs(j,:)'*Xs(j,:)); 9 | % Mhalf(3*j-2:3*j,3*j-2:3*j)=sqrt(const)*(eye(3)+... 10 | % (sqrt(2)-1)*Xs(j,:)'*Xs(j,:)); 11 | end 12 | MWsym = 1/2*(M*WTilde_Np1_Inverse ... 13 | + WTilde_Np1_Inverse*M'); 14 | end 15 | -------------------------------------------------------------------------------- /Matlab/BrownianFlucts/Membrane/InterpolatehNUFFT.m: -------------------------------------------------------------------------------- 1 | function hInterp = InterpolatehNUFFT(InterpPts,Mem) 2 | dx=Mem.x(2)-Mem.x(1); 3 | gw=Mem.dx; 4 | N = length(Mem.x); 5 | L = N*dx; 6 | hmem=Mem.hmem; 7 | if (size(hmem,1)~=size(hmem,2)) 8 | hmem=reshape(Mem.hmem,Mem.M,Mem.M); 9 | end 10 | hhat = fft2(hmem); 11 | ksqMult=Mem.ksq; 12 | %ksqMult(abs(ksqMult)>(3*N/8*2*pi/L)^2)=0; 13 | hhatConv = hhat.*exp(gw^2*ksqMult/2); 14 | hConv = ifft2(hhatConv); 15 | hInterp = InterpFromGrid(Mem.x,Mem.x,hConv,InterpPts,gw); 16 | end 17 | -------------------------------------------------------------------------------- /Python/cppmodules/types.h: -------------------------------------------------------------------------------- 1 | // TYPE DEFINITIONS FOR C++ code 2 | #pragma once 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include // std::sort, std::stable_sort 8 | #include // std::iota 9 | 10 | typedef std::vector vec; 11 | typedef std::array vec3; 12 | typedef std::vector intvec; 13 | typedef std::vector boolvec; 14 | typedef std::vector::iterator vec_iter; 15 | typedef std::complex complex; 16 | typedef std::array , 3> compvec3; 17 | -------------------------------------------------------------------------------- /Matlab/NumericalSBT/FlorenFiberSpec.m: -------------------------------------------------------------------------------- 1 | function [X,Xs, Xss, Xsss, Xssss] = FlorenFiberSpec(q,s,L,b,D,numerderivs) 2 | syms t 3 | XsSym = [cos(q*t.^3 .* (t-L).^3) sin(q*t.^3.*(t - L).^3) 1]/sqrt(2); 4 | Xss = double(subs(diff(XsSym,t),s)); 5 | Xsss = double(subs(diff(XsSym,t,2),s)); 6 | Xssss = double(subs(diff(XsSym,t,3),s)); 7 | Xs = [cos(q*s.^3 .* (s-L).^3) sin(q*s.^3.*(s - L).^3) ones(length(s),1)]/sqrt(2); 8 | if (numerderivs) 9 | Xss = D*Xs; 10 | Xsss=D^2*Xs; 11 | Xssss=D^3*Xs; 12 | end 13 | X = pinv(D)*Xs; 14 | X=X-barymat(0,s,b)*X; 15 | end -------------------------------------------------------------------------------- /Matlab/functions-solvers/linequad/matlabcheb/recursions/rsqrt2_pow_integrals.m: -------------------------------------------------------------------------------- 1 | function [I2] = rsqrt2_pow_integrals(z, N) 2 | % rsqrt_pow_integrals(z,N) 3 | % Recursively compute values of integrals 4 | % Ip(k) = \int_{-1}^{1} t^{k-1}/|t-z|^p dt 5 | % for k=0,...,N-1 and z not in [-1,1] 6 | % and p even 7 | % 8 | % Ludvig af Klinteberg 9 | 10 | I2 = zeros(N,1); 11 | a = real(z); 12 | b = imag(z); 13 | 14 | I2(1) = (atan((a+1)/b)-atan((a-1)/b))/b; 15 | I2(2) = log( ((a-1)^2+b^2) / ((a+1)^2+b^2) )/2 + a*I2(1); 16 | for j=2:N-1 17 | I2(j+1) = 2*a*I2(j) - (a^2+b^2)*I2(j-1) + (1+(-1)^j)/(j-1) ; 18 | end 19 | -------------------------------------------------------------------------------- /Python/Examples/SampleSlurmFile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | #SBATCH --nodes=1 4 | #SBATCH --ntasks-per-node=1 5 | #SBATCH --cpus-per-task=16 6 | #SBATCH --time=48:00:00 7 | ##SBATCH --gres=gpu:1 8 | #SBATCH --mem=8GB 9 | #SBATCH --job-name=BundleRigFl 10 | ##SBATCH --mail-type=END 11 | #SBATCH --mail-user=om759@nyu.edu 12 | #SBATCH --output=slurm_%j.out 13 | #SBATCH --array=1-5 14 | 15 | module purge 16 | module load python/intel/3.8.6 17 | module load cuda/11.6.2 18 | module load onetbb/intel/2021.1.1 19 | 20 | cd SlenderBody/Examples 21 | python FixedDynamicLinkNetwork.py $SLURM_ARRAY_TASK_ID 0.00005 2 22 | 23 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/finufftpy/__init__.py: -------------------------------------------------------------------------------- 1 | """Python wrappers to FINUFFT (Flatiron Institute nonuniform fast Fourier transform library). 2 | 3 | Authors: Daniel Foreman-Mackey, Jeremy Magland, and Alex Barnett 4 | 5 | Contents: 6 | 7 | nufft1d1 8 | nufft1d2 9 | nufft1d3 10 | nufft2d1 11 | nufft2d1many 12 | nufft2d2 13 | nufft2d2many 14 | nufft2d3 15 | nufft3d1 16 | nufft3d2 17 | nufft3d3 18 | 19 | """ 20 | 21 | # that was the docstring for the package finufftpy. 22 | 23 | from finufftpy._interfaces import nufft1d1,nufft1d2,nufft1d3,nufft2d1,nufft2d1many,nufft2d2,nufft2d2many,nufft2d3,nufft3d1,nufft3d2,nufft3d3 24 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/test/results/check2d.sh.refout: -------------------------------------------------------------------------------- 1 | test 2d type-1: 2 | one mode: rel err in F[37,2] is 0 3 | dirft2d: rel l2-err of result F is 0 4 | test 2d type-2: 5 | one targ: rel err in c[500] is 0 6 | dirft2d: rel l2-err of result c is 0 7 | test 2d type-3: 8 | one targ: rel err in F[500] is 0 9 | dirft2d: rel l2-err of result F is 0 10 | test 2dmany type-1: 11 | one mode: rel err in F[37,2] of data[5] is 0 12 | err check vs non-many: sup ( ||F_many-F||_2 / ||F||_2 ) = 0 13 | test 2dmany type-2: 14 | one targ: rel err in c[500] of data[5] is 0 15 | err check vs non-many: sup ( ||c_many-c||_2 / ||c||_2 ) = 0 16 | -------------------------------------------------------------------------------- /Matlab/ChebyshevAndBlobs/Semiflexible/rand_alpha.m: -------------------------------------------------------------------------------- 1 | function [out] = rand_alpha(gamma,Nsamp) 2 | % gamma = kappa_b/(ds*kT); 3 | 4 | P = @(a,x) exp(-a * 2 * sin(x./2).^2).*sin(x); 5 | Nquad = 1e3; 6 | alpha = linspace(0,pi,Nquad); 7 | p = cumtrapz(alpha,P(gamma,alpha)); 8 | p = p./p(end); 9 | 10 | 11 | trunc = find(p >= (1-1e-14)); 12 | alpha_new = alpha; 13 | p_new = p; 14 | p_new(trunc) = []; 15 | alpha_new(trunc) = []; 16 | CDFinv = @(y) interp1(p_new, alpha_new, y, 'pchip','extrap'); 17 | 18 | uni = rand(1,Nsamp); 19 | out = CDFinv(uni); 20 | 21 | end 22 | 23 | -------------------------------------------------------------------------------- /Matlab/functions-solvers/Ewald/EwaldNearPoisson.m: -------------------------------------------------------------------------------- 1 | % Now add the near field 2 | function nearphi = EwaldNearPoisson(pts,charges,xi,Lx,Ly,Lz,g) 3 | [nSource,~]=size(pts); 4 | nearphi=-2*xi/(4*pi*sqrt(pi))*charges; 5 | % Check that the Ewald parameter 6 | for iS=1:nSource 7 | for jS=1:nSource 8 | if (iS~=jS) 9 | % Find the nearest image p 10 | rvec=pts(iS,:)-pts(jS,:); 11 | rvec = calcShifted(rvec,g,Lx,Ly,Lz); 12 | r=norm(rvec); 13 | nearphi(iS)=nearphi(iS)+charges(jS)*erfc(xi*r)/(4*pi*r); 14 | end 15 | end 16 | end 17 | end -------------------------------------------------------------------------------- /Python/makefile: -------------------------------------------------------------------------------- 1 | all: UAMMD_PSE BatchedNBodyRPY cppfiles Neighbors finufft 2 | 3 | UAMMD_PSE: 4 | cd Dependencies/UAMMD_PSE_Python && $(MAKE) 5 | 6 | BatchedNBodyRPY: 7 | cd Dependencies/BatchedNBodyRPY && $(MAKE) 8 | 9 | cppfiles: 10 | cd cppmodules && $(MAKE) 11 | 12 | Neighbors: 13 | cd Dependencies/NeighborSearch && $(MAKE) 14 | 15 | finufft: 16 | cd Dependencies/finufft && $(MAKE) python3 17 | 18 | clean: 19 | $(MAKE) -C Dependencies/BatchedNBodyRPY clean 20 | $(MAKE) -C Dependencies/UAMMD_PSE_Python clean 21 | $(MAKE) -C cppmodules clean 22 | $(MAKE) -C Dependencies/NeighborSearch clean 23 | $(MAKE) -C Dependencies/finufft clean 24 | -------------------------------------------------------------------------------- /Matlab/functions-solvers/RPYTot.m: -------------------------------------------------------------------------------- 1 | % Formula for the unbounded RPY tensor 2 | function M = RPYTot(rvec,a,mu) 3 | r=norm(rvec); 4 | rhat=rvec/r; 5 | if (sum(isnan(rhat)) > 0) 6 | rhat=[0 0 0]; 7 | end 8 | RR = rhat'*rhat; 9 | M = 1/mu*(F(r,a)*(eye(3)-RR)+G(r,a)*RR); 10 | end 11 | 12 | function val = F(r,a) 13 | if (r>2*a) 14 | val = (2*a^2 + 3*r^2)/(24*pi*r^3); 15 | else 16 | val = (32*a - 9*r)/(192*a^2*pi); 17 | end 18 | end 19 | 20 | function val = G(r,a) 21 | if (r>2*a) 22 | val = (-2*a^2 + 3*r^2)/(12*pi*r^3); 23 | else 24 | val = (16*a - 3*r)/(96*a^2*pi); 25 | end 26 | end -------------------------------------------------------------------------------- /Matlab/BrownianFlucts/Membrane/SpreadStericForceToMem.m: -------------------------------------------------------------------------------- 1 | function Fgmem = SpreadStericForceToMem(xyForce,stForce,Mem) 2 | M = Mem.M; 3 | Fgmem = zeros(M); 4 | for iP=1:length(stForce) % Just put it on the nearest grid pt 5 | xpt = 1 + round(xyForce(iP,1)/Mem.dx); 6 | ypt = 1 + round(xyForce(iP,2)/Mem.dx); 7 | xpt(xpt>M)=mod(xpt(xpt>M),M); 8 | xpt(xpt<0)=mod(xpt(xpt<0),M); 9 | xpt(xpt==0)=xpt(xpt==0)+M; 10 | ypt(ypt>M)=mod(ypt(ypt>M),M); 11 | ypt(ypt<0)=mod(ypt(ypt<0),M); 12 | ypt(ypt==0)=ypt(ypt==0)+M; 13 | Fgmem(ypt,xpt) = Fgmem(ypt,xpt) + stForce(iP); 14 | end 15 | Fgmem=Fgmem(:); 16 | end -------------------------------------------------------------------------------- /Matlab/functions-solvers/initFibs.m: -------------------------------------------------------------------------------- 1 | % Function that initializes the fibers as an (Nfib x N) x 3 array of 2 | % points. Inputs = [a,b] = bounding box for the fibers (approximate), 3 | % Nfib = number of fibs, s = arclength coordinates for the fibers, 4 | % Lf = length of fibers 5 | function Xfib=initFibs(a,b,Nfib,s) 6 | Xfib = zeros(Nfib*length(s),3); 7 | for iFib=1:Nfib 8 | spt = a+rand(1,3)*(b-a); 9 | % Archmides? Don't remember what it's called. Projecting from 10 | % cylinder. 11 | u = 1-2*rand; 12 | v = sqrt(1-u^2); 13 | w=2*pi*rand; 14 | pts=spt+s.*[v*cos(w) v*sin(w) u]; 15 | Xfib(length(s)*(iFib-1)+1:length(s)*iFib,:)=pts; 16 | end 17 | end -------------------------------------------------------------------------------- /Python/Dependencies/finufft/matlab/test_strictadjoint.m: -------------------------------------------------------------------------------- 1 | % check t1 and t2 are adjoints to rounding error, not merely to requested tol. 2 | % 1d only for now. Barnett 8/27/18 3 | clear; addpath ~/numerics/finufft/matlab 4 | 5 | M=1e5; % pts 6 | N=1e4; % modes 7 | tol = 1e-6; 8 | x = pi*(2*rand(1,M)-1); 9 | % pick two vectors to check (u,F1 v) = (F2 u,v) with... 10 | v = randn(1,M)+1i*randn(1,M); 11 | u = randn(1,N)+1i*randn(1,N); 12 | ip1 = dot(u,finufft1d1(x,v,+1,tol,N)); 13 | ip2 = dot(finufft1d2(x,-1,tol,u),v); % note sign flips to be complex adjoint 14 | fprintf('M=%d,N=%d,tol=%.1g: rel err (u,F1 v) vs (F2 u,v): %.3g\n',M,N,tol,abs(ip1-ip2)/abs(ip1)) 15 | fprintf('cf estimated rounding err for this prob size; %.3g\n',0.2*eps*N) 16 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/finufftpy/ndarray.h: -------------------------------------------------------------------------------- 1 | // JFM's class for passing arrays between C++ and python 2 | 3 | #ifndef ndarray_h 4 | #define ndarray_h 5 | 6 | #include 7 | namespace py = pybind11; 8 | 9 | template 10 | struct NDArray { 11 | NDArray(py::array_t &X) { 12 | auto buf=X.request(); 13 | ndim=buf.ndim; 14 | size=buf.size; 15 | for (int d=0; d shape; // The sizes of the dimensions 24 | T *ptr=0; // Pointer to the actual data 25 | }; 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /Matlab/NumericalSBT/KMatBlobs.m: -------------------------------------------------------------------------------- 1 | function K = KMatBlobs(ds,Xs) 2 | [N,~]=size(Xs); 3 | K = zeros(3*N,2*N+3); 4 | [theta,phi,~] = cart2sph(Xs(:,1),Xs(:,2),Xs(:,3)); 5 | theta(abs((abs(phi)-pi/2)) < 1e-12) =0; 6 | n1 = [-sin(theta) cos(theta) 0*theta]; 7 | n2 = [-cos(theta).*sin(phi) -sin(theta).*sin(phi) cos(phi)]; 8 | for iD=1:3 9 | K(iD:3:end,iD)=1; % constant mode 10 | end 11 | for iCol=1:N 12 | K(3*iCol-2:end,3+iCol) = repmat(n1(iCol,:)',N-iCol+1,1)*ds; % n1's 13 | K(3*iCol-2:3*iCol,3+iCol) = K(3*iCol-2:3*iCol,3+iCol)*1/2; 14 | K(3*iCol-2:end,3+N+iCol) = repmat(n2(iCol,:)',N-iCol+1,1)*ds; % n2's 15 | K(3*iCol-2:3*iCol,3+N+iCol) = K(3*iCol-2:3*iCol,3+N+iCol)*1/2; 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /Matlab/BrownianFlucts/MCMC/BlobLink/Bishop.m: -------------------------------------------------------------------------------- 1 | function [U,V] = Bishop(T_hat,u1) 2 | % Generate the Bishop frame by paralel transporting u1 3 | % along T_hat 4 | 5 | t1 = T_hat(:,1); 6 | v1 = cross(t1,u1); 7 | 8 | U = [u1]; 9 | V = [v1]; 10 | 11 | [~,q] = size(T_hat); 12 | 13 | for k= 1:q-1 14 | % calc rot quantities 15 | t_k = T_hat(:,k); 16 | t_kp = T_hat(:,k+1); 17 | cos_th = dot(t_k,t_kp); 18 | rot_x = cross(t_k,t_kp); 19 | %rot_x = rot_x./norm(rot_x); 20 | 21 | % update bishop fram using Rod. formula 22 | u_k = U(:,k); 23 | v_k = V(:,k); 24 | u_kp = u_k + cross(rot_x,u_k) + (1./(1 + cos_th)) * cross(rot_x,cross(rot_x,u_k)); 25 | v_kp = cross(t_kp,u_kp); 26 | 27 | U = [U u_kp]; 28 | V = [V v_kp]; 29 | end 30 | 31 | end -------------------------------------------------------------------------------- /Matlab/MainPrograms/BishopFrameConvergence.m: -------------------------------------------------------------------------------- 1 | N=100; 2 | SBTRelaxingFib; 3 | refas=Rpl*bishA; 4 | Ns=4:4:80; 5 | for iN=1:length(Ns) 6 | N=Ns(iN); 7 | SBTRelaxingFib; 8 | Allas{iN}=Rpl*bishA; 9 | Allbs{iN}=Rpl*bishB; 10 | end 11 | ersA=zeros(length(Ns)-1,1); 12 | ersB=zeros(length(Ns)-1,1); 13 | erParallel = ersA; 14 | ersPerp = ersA; 15 | for iE=1:length(Ns) 16 | vecersA=Allas{iE}-refas; 17 | vecersParallel = sum(vecersA.*refas,2); 18 | erParallel(iE) = sqrt(wpl*sum(vecersParallel.*vecersParallel,2)); 19 | vecersPerp = vecersA-(vecersA.*refas).*refas; 20 | ersPerp(iE) = sqrt(wpl*sum(vecersPerp.*vecersPerp,2)); 21 | ersA(iE)=sqrt(wpl*sum(vecersA.*vecersA,2)); 22 | end 23 | semilogy(Ns,ersA,'-o') 24 | hold on 25 | semilogy(Ns,erParallel,'-.s') 26 | semilogy(Ns,ersPerp,'--d') 27 | 28 | 29 | -------------------------------------------------------------------------------- /docs/PythonClasses.rst: -------------------------------------------------------------------------------- 1 | Source code (Python) documentation 2 | =================================================== 3 | This page contains links to documentation of all 4 | the Python objects in SPHARCLE. Many of the Python 5 | classes also have a corresponding C++ class that 6 | actually does the grunt work. Here we provide 7 | documentation for all of the python classes; the 8 | corresponding C++ has the same functionality and can 9 | thus be understood using the Python documentation. 10 | 11 | Contents: 12 | 13 | .. toctree:: 14 | :maxdepth: 1 15 | 16 | TemporalIntegrator 17 | fiberCollection 18 | FibCollocationDiscretization 19 | CrossLinkedNetwork 20 | RPYVelocityEvaluator 21 | StericForceEvaluator 22 | SpatialDatabase 23 | DiscretizedFiber 24 | Domain 25 | -------------------------------------------------------------------------------- /Matlab/functions-solvers/EvalU0.m: -------------------------------------------------------------------------------- 1 | % Evaluate background flow and domain strain 2 | function [U0,g] = EvalU0(gam0,w,t,X,flowtype) 3 | U0 = zeros(length(X),1); 4 | if (flowtype=='Q') 5 | U0(1:3:end)=gam0*X(2:3:end).^2; % parabolic flow 6 | elseif (flowtype=='E') 7 | U0(1:3:end)=gam0*X(1:3:end); % extensional flow 8 | U0(2:3:end)=-gam0*X(2:3:end); 9 | elseif (flowtype=='D') 10 | U0(1:3:end)=gam0*X(1:3:end); % extensional flow 11 | U0(2:3:end)=-1/2*gam0*X(2:3:end); 12 | U0(3:3:end)=-1/2*gam0*X(3:3:end); 13 | else 14 | U0(1:3:end)=gam0*cos(w*t)*X(2:3:end); % shear flow 15 | end 16 | if (w==0) 17 | g=gam0*t; 18 | else 19 | g = gam0/w*sin(w*t); % total strain 20 | end 21 | g=g-round(g); 22 | end -------------------------------------------------------------------------------- /Python/Dependencies/finufft/test/checkallaccs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # test range of requested accuracies, for both spreader and nufft, for a given 3 | # single dimension. 4 | # Usage: ./checkallaccs.sh [dim] 5 | # where dim = 1, 2, or 3. 6 | # Barnett 2/17/17. Default dim=1 4/5/17 7 | 8 | DEFAULTDIM=1 9 | DIM=${1:-$DEFAULTDIM} 10 | echo checkallaccs for dim=$DIM : 11 | 12 | # finufft test size params 13 | TEST1="1e3 1e3" 14 | TEST2="1e2 1e1 1e3" 15 | TEST3="1e1 1e1 1e1 1e3" 16 | # bash hack to make DIM switch between one of the above 3 choices 17 | TESTD=TEST$DIM 18 | TEST=${!TESTD} 19 | 20 | SORT=2 21 | 22 | for acc in `seq 1 15`; 23 | do 24 | TOL=1e-$acc 25 | echo ----------requesting $TOL : 26 | ./spreadtestnd $DIM 1e6 1e6 $TOL $SORT 27 | ./finufft${DIM}d_test $TEST $TOL 0 $SORT 28 | done 29 | -------------------------------------------------------------------------------- /Matlab/functions-solvers/getMlocRotlet.m: -------------------------------------------------------------------------------- 1 | % The local drag (or leading order singular) expansion for the Rotlet term, 2 | % given in Appendix A of the paper. 3 | function MRT = getMlocRotlet(N,X,D,a,L,mu,s0) 4 | MRT = zeros(N,3*N); 5 | Xs = D*X; 6 | Xss = D*Xs; 7 | for iPt=1:N 8 | inds = (iPt-1)*3+1:3*iPt; 9 | t = s0(iPt); 10 | tau = Xs(iPt,:); 11 | nXs=norm(tau); 12 | Xsprime = Xss(iPt,:); 13 | if (t < 2*a) 14 | MRT(iPt,inds)=log((L-t)/(2*a))*1/(2*nXs^3)*cross(tau,Xsprime); 15 | elseif (t > L-2*a) 16 | MRT(iPt,inds)=log(t/(2*a))*1/(2*nXs^3)*cross(tau,Xsprime); 17 | else 18 | MRT(iPt,inds)=1/(2*nXs^3)*cross(tau,Xsprime)*log(t.*(L-t)./(4*a.^2)); 19 | end 20 | end 21 | MRT = 1/(8*pi*mu)*MRT; 22 | end -------------------------------------------------------------------------------- /Python/Dependencies/finufft/test/README: -------------------------------------------------------------------------------- 1 | Testing directory for FINUFFT. Barnett 3/14/17 2 | 3 | check_finufft.sh : validates the NUFFT library for correctness. 4 | results/*.refout : reference outputs that the generated outputs *,out will be compared against. 5 | spreadtestnd.sh : performance test of spreader only, in dims 1,2, or 3. 6 | nuffttestnd.sh : performance test of NUFFT library, in dims 1,2, or 3. 7 | mycpuinfo.sh : prints info about the CPU 8 | check?d.sh : used by check_finufft.sh 9 | 10 | Possibly obsolete scripts (for developers): 11 | nuffttest?d.sh : simple NUFFT test for each dim 12 | checkallaccs.sh : spreading and NUFFT at all #s of digits, for a single ndims 13 | highaspect3d_test.sh : comparing various pizza-box orientations for speed 14 | 15 | Also see: ../fortran for the Fortran driver demo scripts. 16 | -------------------------------------------------------------------------------- /Python/cppmodules/makefile: -------------------------------------------------------------------------------- 1 | all: RPYKernelEvaluator.so FiberCollectionC.so DomainC.so CrossLinkForceEvaluator.so EndedCrossLinkedNetwork.so StericForceEvaluatorC.so 2 | 3 | CXX=g++ 4 | PYTHON3=python3 5 | 6 | LDLIBS=-llapacke -lcblas -lgfortran -llapack 7 | OPENMP=-fopenmp 8 | PYBINDINCLUDE:=`$(PYTHON3) -m pybind11 --includes` 9 | 10 | CXXFLAGS=-Wall -O3 -std=c++11 -fPIC $(OPENMP) $(LDLIBS) $(PYBINDINCLUDE) 11 | 12 | SLENDER_ROOT=../../ 13 | %.so:%.cpp makefile 14 | $(CXX) -shared $< -o $@ $(CXXFLAGS) 15 | 16 | EndedCrossLinkedNetwork.so: FortranHeap.o EndedCrossLinkers.cpp 17 | $(CXX) -shared -o $@ $^ $(CXXFLAGS) 18 | 19 | FortranHeap.o: $(SLENDER_ROOT)/Fortran/MinHeapModule.f90 makefile 20 | $(CXX) -x f95 -O3 -c $< -o $@ -fPIC 21 | 22 | clean: 23 | rm -f *.so FortranHeap.o 24 | 25 | 26 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | set -e #End script if any command fails 2 | make -C Python 3 | #Check if slender is already present: 4 | echo "Compilation was successful" 5 | 6 | if grep -q "SLENDER_PYTHON" ~/.bashrc; then echo "Slender body already present in bashrc"; exit 0; fi 7 | #If SLENDER_PYTHON is not present in bashrc append these lines to it 8 | echo "Appending paths to .bashrc" 9 | cat <> ~/.bashrc 10 | # -------- ADDED BY SLENDERBODY INSTALLER --------------- 11 | export SLENDER_ROOT=$(pwd) 12 | export SLENDER_PYTHON=\$SLENDER_ROOT/Python 13 | export PYTHONPATH=\${PYTHONPATH}:\$SLENDER_PYTHON:\$SLENDER_PYTHON/Dependencies:\$SLENDER_PYTHON/Dependencies/BatchedNBodyRPY:\$SLENDER_PYTHON/Dependencies/UAMMD_PSE_Python:\$SLENDER_PYTHON/Dependencies/NeighborSearch:\$SLENDER_PYTHON/cppmodules 14 | # ---------------------------------------------------------- 15 | EOF 16 | -------------------------------------------------------------------------------- /Matlab/functions-solvers/RegularizeS.m: -------------------------------------------------------------------------------- 1 | % Function to compute a regularized coordinate sbar from the fiber 2 | % coordinates s over regularized length delta*L. 3 | % See Section 2.1 of Maxian et al. https://arxiv.org/pdf/2007.11728.pdf 4 | % for details 5 | function [sNew,regwt] = RegularizeS(s0,delta,L) 6 | sNew = s0; 7 | regwt = ones(length(s0),1); 8 | % Regularized version 9 | if (delta > 0 && delta < 0.5) 10 | x = 2*s0/L-1; 11 | regwt = tanh(((x+1)/delta))-tanh(((x-1)/delta))-1; 12 | sNew = s0; 13 | sNew(s0 < L/2) = regwt(s0 < L/2).*s0(s0 < L/2)+(1-regwt(s0 < L/2).^2).*delta*L/2; 14 | sNew(s0 > L/2) = L-flipud(sNew(s0 < L/2)); 15 | elseif (delta >= 0.5) 16 | x = 2*s0/L-1; 17 | regwt = tanh((x+1)/0.5)-tanh((x-1)/0.5)-1; 18 | sNew = L/2*ones(length(s0),1); 19 | end 20 | end -------------------------------------------------------------------------------- /Python/Dependencies/finufft/src/utils.h: -------------------------------------------------------------------------------- 1 | // Header for utils.cpp, a little library of low-level array and timer stuff. 2 | // (rest of finufft defs and types are now in defs.h) 3 | 4 | #ifndef UTILS_H 5 | #define UTILS_H 6 | 7 | #include "defs.h" 8 | 9 | // ahb's low-level array helpers 10 | FLT relerrtwonorm(BIGINT n, CPX* a, CPX* b); 11 | FLT errtwonorm(BIGINT n, CPX* a, CPX* b); 12 | FLT twonorm(BIGINT n, CPX* a); 13 | FLT infnorm(BIGINT n, CPX* a); 14 | void arrayrange(BIGINT n, FLT* a, FLT *lo, FLT *hi); 15 | void indexedarrayrange(BIGINT n, BIGINT* i, FLT* a, FLT *lo, FLT *hi); 16 | void arraywidcen(BIGINT n, FLT* a, FLT *w, FLT *c); 17 | BIGINT next235even(BIGINT n); 18 | 19 | // jfm's timer class 20 | #include 21 | class CNTime { 22 | public: 23 | void start(); 24 | double restart(); 25 | double elapsedsec(); 26 | private: 27 | struct timeval initial; 28 | }; 29 | 30 | #endif // UTILS_H 31 | -------------------------------------------------------------------------------- /Matlab/functions-solvers/getMlocDoublet.m: -------------------------------------------------------------------------------- 1 | % The local drag matrix for the doublet term. These formulas are given in 2 | % Appendix A of the paper. The input extraterms is when we want to carry the asymptotic 3 | % expansion to the next order, and is not used. 4 | function MTT = getMlocDoublet(N,Xs,a,L,mu,s0,delta) 5 | s = RegularizeS(s0,delta,L); 6 | MTT_f = zeros(3*N); 7 | intx3s = zeros(N,1); 8 | for iPt=1:N 9 | inds = (iPt-1)*3+1:3*iPt; 10 | t = s(iPt); 11 | nXs = norm(Xs(iPt,:)); 12 | Xshat = Xs(iPt,:)/nXs; 13 | if (t < 2*a) 14 | intx3 = 1/(8*a^2)-1/(2*(L-t)^2); 15 | elseif (t > L-2*a) 16 | intx3 = 1/(8*a^2)-1/(2*t^2); 17 | else 18 | intx3 = 1/(4*a^2)-1/(2*t^2)-1/(2*(L-t)^2); 19 | end 20 | MTT_f(inds,inds)=intx3*(eye(3)-3*(Xshat'*Xshat))/nXs^3; 21 | intx3s(iPt)=intx3; 22 | end 23 | MTT = 1/(8*pi*mu)*MTT_f; 24 | end -------------------------------------------------------------------------------- /Python/Dependencies/finufft/src/dirft.h: -------------------------------------------------------------------------------- 1 | #ifndef DIRFT_H 2 | #define DIRFT_H 3 | 4 | #include "utils.h" 5 | 6 | void dirft1d1(BIGINT nj,FLT* x,CPX* c,int isign,BIGINT ms, CPX* f); 7 | void dirft1d2(BIGINT nj,FLT* x,CPX* c,int iflag,BIGINT ms, CPX* f); 8 | void dirft1d3(BIGINT nj,FLT* x,CPX* c,int iflag,BIGINT nk, FLT* s, CPX* f); 9 | 10 | void dirft2d1(BIGINT nj,FLT* x,FLT *y,CPX* c,int iflag,BIGINT ms, BIGINT mt, CPX* f); 11 | void dirft2d2(BIGINT nj,FLT* x,FLT *y,CPX* c,int iflag,BIGINT ms, BIGINT mt, CPX* f); 12 | void dirft2d3(BIGINT nj,FLT* x,FLT *y,CPX* c,int iflag,BIGINT nk, FLT* s, FLT* t, CPX* f); 13 | 14 | void dirft3d1(BIGINT nj,FLT* x,FLT *y,FLT *z,CPX* c,int iflag,BIGINT ms, BIGINT mt, BIGINT mu, CPX* f); 15 | void dirft3d2(BIGINT nj,FLT* x,FLT *y,FLT *z,CPX* c,int iflag,BIGINT ms, BIGINT mt, BIGINT mu, CPX* f); 16 | void dirft3d3(BIGINT nj,FLT* x,FLT *y,FLT *z,CPX* c,int iflag,BIGINT nk, FLT* s, FLT* t, FLT *u, CPX* f); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # .readthedocs.yaml 2 | # Read the Docs configuration file 3 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 4 | 5 | # Required 6 | version: 2 7 | 8 | # Set the OS, Python version and other tools you might need 9 | build: 10 | os: ubuntu-22.04 11 | tools: 12 | python: "3.11" 13 | # You can also specify other tool versions: 14 | # nodejs: "19" 15 | # rust: "1.64" 16 | # golang: "1.19" 17 | 18 | # Build documentation in the "docs/" directory with Sphinx 19 | sphinx: 20 | configuration: docs/conf.py 21 | 22 | # Optionally build your docs in additional formats such as PDF and ePub 23 | # formats: 24 | # - pdf 25 | # - epub 26 | 27 | # Optional but recommended, declare the Python requirements required 28 | # to build your documentation 29 | # See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html 30 | python: 31 | install: 32 | - requirements: docs/requirements.txt 33 | -------------------------------------------------------------------------------- /Matlab/functions-solvers/Ewald/EwaldFarPoissonFI.m: -------------------------------------------------------------------------------- 1 | % Same file, but using FINUFFT library 2 | function ufarCH = EwaldFarPoissonFI(ptsxyz,charges,Lx,Ly,Lz,g,xi) 3 | % Compute the coordinates in the transformed basis 4 | L = [1 g 0; 0 1 0; 0 0 1]; 5 | pts = (L \ ptsxyz')'; 6 | % Rescale to [-pi,pi] 7 | pts = pts./[Lx Ly Lz]*2*pi; 8 | gw=1/(2*xi); 9 | h=gw/1.6; 10 | nx=2^(nextpow2(Lx/h)); 11 | ny=2^(nextpow2(Ly/h)); 12 | nz=2^(nextpow2(Lz/h)); 13 | kvx=[0:nx/2-1 -nx/2:-1]*2*pi/Lx; 14 | kvy=[0:ny/2-1 -ny/2:-1]*2*pi/Ly; 15 | kvz=[0:nz/2-1 -nz/2:-1]*2*pi/Lz; 16 | [ky,kx,kz]=meshgrid(kvy,kvx,kvz); 17 | opts.modeord=1; 18 | fhat = finufft3d1(pts(:,1),pts(:,2),pts(:,3),charges,-1,1e-10,nx,ny,nz,opts); 19 | mksq = -kx.^2-(ky-g*kx).^2-kz.^2; 20 | uhat = fhat./-mksq.*exp(mksq/(4*xi^2)); 21 | uhat(1,1,1)=0; 22 | ufarCH = real(finufft3d2(pts(:,1),pts(:,2),pts(:,3),1,1e-10,uhat,opts))/(Lx*Ly*Lz); 23 | end 24 | -------------------------------------------------------------------------------- /Matlab/BrownianFlucts/MCMC/BlobLink/Tau_Rot_Full.m: -------------------------------------------------------------------------------- 1 | function [T_out,U_out,V_out] = Tau_Rot_Full(dt,Omega,U,V,T_hat) 2 | % Update Fiber Positions from Omega 3 | % Omega is a full frame velocity in [T U V] coordinates 4 | 5 | 6 | T_out = NaN*T_hat; 7 | U_out = NaN*T_hat; 8 | V_out = NaN*T_hat; 9 | 10 | 11 | 12 | [~,q] = size(T_hat); 13 | 14 | Om = reshape(Omega,3,q); 15 | 16 | for jj = 1:q 17 | frame = [T_hat(:,jj) U(:,jj) V(:,jj)]; 18 | Omega_i = frame*Om(:,jj); 19 | mag_O = norm(Omega_i); 20 | if (mag_O > 1e-10) 21 | theta = dt*mag_O; 22 | axis = Omega_i./mag_O; 23 | axis = repmat(axis,1,3); 24 | 25 | new_frame = cos(theta)*frame + (sin(theta))*cross(axis,frame) + (1-cos(theta))*(axis(:,1)*axis(:,1)')*frame; 26 | new_frame = new_frame./sqrt(sum(new_frame.^2)); 27 | else 28 | new_frame=frame; 29 | end 30 | T_out(:,jj) = new_frame(:,1); 31 | U_out(:,jj) = new_frame(:,2); 32 | V_out(:,jj) = new_frame(:,3); 33 | end 34 | 35 | end 36 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2017-2018 The Simons Foundation, Inc. - All Rights Reserved. 2 | 3 | Main authors: Alex Barnett and Jeremy Magland 4 | 5 | FINUFFT is licensed under the Apache License, Version 2.0 (the 6 | "License"); you may not use this file except in compliance with the 7 | License. You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | ------ 18 | 19 | Also, if you find this library useful, or it helps you in creating 20 | software or publications, please acknowledge that fact by citing this 21 | repository along with the author names, and any corresponding journal 22 | article. 23 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/test/mycpuinfo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Barnett 2/2/17 3 | # Linux and OSX both, 11/1/18 4 | 5 | echo "what CPUs do I have?..." 6 | unameOut="$(uname -s)" 7 | case "${unameOut}" in 8 | Linux*) 9 | echo "(I'm in a linux OS)" 10 | grep "model name" /proc/cpuinfo | uniq 11 | if hash lscpu 2> /dev/null; then # only do it if cmd exists... 12 | lscpu 13 | fi 14 | ;; 15 | Darwin*) 16 | echo "(I'm in Mac OSX)" 17 | sysctl -n machdep.cpu.brand_string 18 | sysctl -a | grep machdep.cpu 19 | ;; 20 | *) 21 | echo "I'm in an unknown or unsupported operating system";; 22 | esac 23 | 24 | # help from: 25 | 26 | #lscpu | egrep 'Thread|Core|Socket|^CPU\(|MHz' 27 | # thanks to http://unix.stackexchange.com/questions/218074/how-to-know-number-of-cores-of-a-system-in-linux 28 | 29 | # https://www.cyberciti.biz/faq/lscpu-command-find-out-cpu-architecture-information/ 30 | 31 | # https://stackoverflow.com/questions/3466166/how-to-check-if-running-in-cygwin-mac-or-linux/27776822 32 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/test/spreadtestnd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # a basic quick set of quasi-uniform multidimensional spreader speed tests. 3 | # Barnett 2/2/17, 3/13/17. M,N indep 3/27/17, sort 3/28/17, xeon sort 11/7/17 4 | 5 | M=1e6 # problem size (# NU pts) 6 | N=1e6 # num U grid pts 7 | TOL=1e-6 # overall requested accuracy 8 | 9 | SORT=2 # default setting for sort 10 | if grep -q Xeon /proc/cpuinfo; then 11 | echo "Xeon detected" 12 | SORT=2 # xeon setting, also the default 13 | fi 14 | 15 | echo "spreadtestnd output:" 16 | ./mycpuinfo.sh 17 | 18 | echo 19 | echo "#NU = $M, #U = $N, tol = $TOL, sort = $SORT: multi-core tests..." 20 | ./spreadtestnd 1 $M $N $TOL $SORT 21 | ./spreadtestnd 2 $M $N $TOL $SORT 22 | ./spreadtestnd 3 $M $N $TOL $SORT 23 | 24 | echo 25 | echo "#NU = $M, #U = $N, tol = $TOL, sort = $SORT: single core tests..." 26 | export OMP_NUM_THREADS=1 27 | ./spreadtestnd 1 $M $N $TOL $SORT 28 | ./spreadtestnd 2 $M $N $TOL $SORT 29 | ./spreadtestnd 3 $M $N $TOL $SORT 30 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/docs/README: -------------------------------------------------------------------------------- 1 | README for FINUFFT documentation. 2 | 3 | Barnett 1/28/18 4 | 5 | 6 | 7 | The files in this directory are designed for sphinx to auto-generate 8 | documentation in HTML (including from the readthedocs.io site), and in PDF. 9 | 10 | To test the HTML generation locally, do: 11 | 12 | make html 13 | 14 | Then point your browser to the local file _build/html/index.html 15 | 16 | Before pushing to git after documentation changes, one should also do: 17 | 18 | ./genpdfmanual.sh 19 | 20 | This is a tiny bash script which builds the PDF manual then moves into 21 | the parent (main FINUFFT) directory for easy reading offline by 22 | non-browser-based humans who download the repo. The file ../README.md 23 | also exists for such humans, and those reading the github front page. 24 | 25 | finufft.readthedocs.io should have been set up to be triggered by 26 | pushes to the git repo to regenerate HTML documentation identical to the 27 | local copy, hosted there for the world to see. 28 | 29 | -------------------------------------------------------------------------------- /Matlab/ChebyshevAndBlobs/simpson_nonuniform.m: -------------------------------------------------------------------------------- 1 | function result = simpson_nonuniform(x, f) 2 | %Simpson rule for irregularly spaced data. 3 | N = length(x) - 1; 4 | h = x(2:end)-x(1:end-1); 5 | result = 0.0; 6 | for i=2:2:N 7 | hph = h(i) + h(i - 1); 8 | result=result+ f(i,:) * ( h(i).^3 + h(i - 1).^3+ 3. * h(i) * h(i - 1) * hph )... 9 | / ( 6 * h(i) * h(i - 1)); 10 | result =result+ f(i - 1,:) * ( 2. * h(i - 1).^3 - h(i).^3+ 3. * h(i) * h(i - 1).^2)... 11 | / ( 6 * h(i - 1) * hph); 12 | result =result+ f(i + 1,:) * ( 2. * h(i).^3 - h(i - 1).^3 + 3. * h(i - 1) * h(i).^2)... 13 | / ( 6 * h(i) * hph ); 14 | end 15 | if (mod((N + 1),2) == 0) 16 | result =result+ f(N+1,:) * ( 2 * h(N).^2 + 3. * h(N-1) * h(N))/ ( 6 *( h(N-1) + h(N))); 17 | result =result+ f(N,:)*(h(N).^2+ 3*h(N)* h(N-1))/( 6 * h(N-1)); 18 | result =result- f(N-1,:)* h(N).^3/( 6 * h(N-1) * (h(N-1) + h(N))); 19 | end 20 | end -------------------------------------------------------------------------------- /Matlab/functions-solvers/getMlocStokeslet.m: -------------------------------------------------------------------------------- 1 | % The local drag matrix for the Stokeslet term. These formulas are given in 2 | % Appendix A of the paper. The input delta is for the regularization of the 3 | % local drag term (i.e., to use SBT). 4 | function MTT = getMlocStokeslet(N,Xs,a,L,mu,s0,delta) 5 | s = RegularizeS(s0,delta,L); 6 | MTT = zeros(3*N); 7 | [~,b]=size(Xs); 8 | if (b < 3) 9 | error('Need to pass Xs as an N x 3 vector') 10 | end 11 | c=zeros(N,1); 12 | for iPt=1:N 13 | inds = (iPt-1)*3+1:3*iPt; 14 | t = s(iPt); 15 | tau = Xs(iPt,:); 16 | nXs = norm(tau); 17 | Xshat = tau/nXs; 18 | XsXs = Xshat'*Xshat; 19 | if (t < 2*a) 20 | c(iPt)=log((L-t)/(2*a)); 21 | elseif (t > L-2*a) 22 | c(iPt)=log(t/(2*a)); 23 | else 24 | % Trans-Trans 25 | c(iPt)=log(t*(L-t)/(4*a.^2)); 26 | end 27 | MTT(inds,inds)=c(iPt)*(eye(3)+XsXs)/nXs; 28 | end 29 | MTT = 1/(8*pi*mu)*MTT; 30 | end -------------------------------------------------------------------------------- /Matlab/functions-solvers/linequad/matlabcheb/recursions/coeffs_I3.m: -------------------------------------------------------------------------------- 1 | function coeffs = coeffs_I3(Ns) 2 | % Power series coeffs for p=3, k=0 3 | % 4 | % coeffs = []; 5 | % for n = 2:Ns+1 6 | % %B = 7 | % B = factorial(2*n)/factorial(n)^2; % nchoosek(2*n,n); 8 | % coeffs(end+1) = (-1)^n*B/4^n; 9 | % end 10 | % 11 | % Precomputed up to Ns=30 using Mathematica 12 | coeffs = [3/8, -(5/16), 35/128, -(63/256), 231/1024, -(429/2048), 6435/32768, -(12155/65536), 46189/262144, -(88179/524288), 676039/4194304, -(1300075/8388608), 5014575/33554432, -(9694845/67108864), 300540195/2147483648, -(583401555/4294967296), 2268783825/17179869184, -(4418157975/34359738368), 34461632205/274877906944, -(67282234305/549755813888), 263012370465/2199023255552, -(514589420475/4398046511104), 8061900920775/70368744177664, -(15801325804719/140737488355328), 61989816618513/562949953421312, -(121683714103007/1125899906842624), 956086325095055/9007199254740992, -(1879204156221315/18014398509481984), 7391536347803839/72057594037927936, -(14544636039226909/144115188075855872)]; 13 | coeffs = coeffs(1:Ns); 14 | end 15 | -------------------------------------------------------------------------------- /Matlab/MainPrograms/Filopodium/StabilityThetConst.m: -------------------------------------------------------------------------------- 1 | L = 2; 2 | eps = 4e-3/L; 3 | mu = 1; 4 | kbT = 4.1e-3; 5 | Eb = 17*kbT; % pN*um^2 (Lp=17 um) 6 | twmod = 10*kbT; % pN*um^2 (LpTwist = 10 um) 7 | N = 16; 8 | [spl,wpl,bpl] = chebpts(1000,[0 L]); 9 | c= log(1/eps^2)/(8*pi*mu); 10 | psi = 1.4*(2*pi/L)*(Eb/twmod); 11 | H = chebop(0,L); 12 | H.op = @(s,u) c*(-Eb*diff(u,4)+1i*twmod*psi*diff(u,3)); 13 | H.lbc = @(u) [diff(u,2); diff(u,3)]; 14 | H.rbc = @(u) [diff(u,2); diff(u,3)]; 15 | nEFs = N; 16 | [V,D] = eigs(H,nEFs,'SM'); 17 | eigfunctions = V.blocks; 18 | % Do the first two modes analyticallly (Chebfun not good at those for some 19 | % reason) 20 | FunctionValues = zeros(length(spl),nEFs); 21 | eigvalues=diag(D); 22 | eigvalues(3) 23 | for i=1:nEFs 24 | FunctionValues(:,i)=eigfunctions{1,i}(spl); 25 | end 26 | 27 | % Check the eigenfunctions 28 | % Nch=100; index=N-2; 29 | % [sch,wch,bch]=chebpts(Nch,[0 L]); 30 | % ch1 = barymat(sch,spl,bpl)*FunctionValues(:,index); 31 | % D = diffmat(Nch,[0 L]); 32 | % LHS = c*(-Eb*D^4*ch1+1i*twmod*psi*D^3*ch1); 33 | % plot(sch,LHS); 34 | % hold on 35 | % plot(sch,eigvalues(index)*ch1); -------------------------------------------------------------------------------- /Python/Dependencies/finufft/test/nuffttestnd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # a basic set of performance tests for Flatiron Institute NUFFT. 3 | # Barnett 2/2/17, tidied 3/13/17 4 | 5 | M=1e6 # problem size (sets both # NU pts and # U modes) 6 | TOL=1e-6 # overall requested accuracy 7 | DEBUG=0 # whether to see timing breakdowns 8 | SORT=1 # i7 better if sort 9 | if grep -q Xeon /proc/cpuinfo; then 10 | echo "Xeon detected, switching off spreader sorting..." 11 | SORT=1 # whether to sort (1 also for xeon) 12 | fi 13 | 14 | echo "nuffttestnd output:" 15 | ./mycpuinfo.sh 16 | 17 | echo 18 | echo "size = $M, tol = $TOL: multi-core tests..." 19 | # currently we run 1e6 modes in each case, in non-equal dims (more generic): 20 | ./finufft1d_test 1e6 $M $TOL $DEBUG $SORT 21 | ./finufft2d_test 500 2000 $M $TOL $DEBUG $SORT 22 | ./finufft3d_test 100 200 50 $M $TOL $DEBUG $SORT 23 | 24 | echo 25 | echo "size = $M, tol = $TOL: single core tests..." 26 | export OMP_NUM_THREADS=1 27 | ./finufft1d_test 1e6 $M $TOL $DEBUG $SORT 28 | ./finufft2d_test 500 2000 $M $TOL $DEBUG $SORT 29 | ./finufft3d_test 100 200 50 $M $TOL $DEBUG $SORT 30 | -------------------------------------------------------------------------------- /Matlab/functions-solvers/PolymerizeBarbed.m: -------------------------------------------------------------------------------- 1 | function [X3new,LfacNew]=PolymerizeBarbed(Lprime,Lfac,L,X,sNp1,bNp1,DNp1,dt) 2 | % Add the polymerization velocity and recompute center 3 | Lextra = dt*Lprime; 4 | % Extend the tangent vector at s = L outwards 5 | Xp13 = reshape(X,3,[])'; 6 | BLast = barymat(L,sNp1,bNp1); 7 | BFirst = barymat(0,sNp1,bNp1); 8 | TauLast =BLast*DNp1*Xp13; 9 | Xadded = TauLast/norm(TauLast)*Lextra+BLast*Xp13; 10 | % Solve for a new parameterization that ends at Xadded 11 | % and goes through the other points 12 | XWithAdd = [Xp13; Xadded]; 13 | sToEval = sNp1*Lfac; 14 | LfacNew=Lfac+Lextra/L; % add the extra length 15 | sToEval=[sToEval;L*LfacNew]; % pts where we evaluate new interp (max is L*Lfacs) 16 | Rnew = barymat(sToEval/LfacNew,sNp1,bNp1); % For the new parameterization [0,L] 17 | X3new = pinv(Rnew)*XWithAdd; 18 | % Aeq = stackMatrix([BFirst*DNp1; BFirst]); 19 | % beq = Aeq*X; 20 | % opts1= optimset('display','off'); 21 | % X3new = lsqlin(stackMatrix(Rnew),reshape(XWithAdd',[],1),... 22 | % [],[],Aeq,beq,[],[],[],opts1); 23 | end -------------------------------------------------------------------------------- /Matlab/functions-solvers/Ewald/EwaldFarPoisson.m: -------------------------------------------------------------------------------- 1 | function ufarCH = EwaldFarPoisson(pts,charges,Lx,Ly,Lz,g,xi) 2 | gw=1/(2*xi); 3 | h=gw/1.6; 4 | nx=2^(nextpow2(Lx/h)); 5 | ny=2^(nextpow2(Ly/h)); 6 | nz=2^(nextpow2(Lz/h)); 7 | hx=Lx/nx; 8 | hy=Ly/ny; 9 | hz=Lz/nz; 10 | xE=(0:nx-1)*hx; 11 | yE=(0:ny-1)*hy; 12 | zE=(0:nz-1)*hz; 13 | sup=nx; % Support of the Gaussian, 14 for 4 digits as Ewald changes (PLAY WITH THIS LATER) 14 | kvx=[0:nx/2-1 -nx/2:-1]*2*pi/Lx; 15 | kvy=[0:ny/2-1 -ny/2:-1]*2*pi/Ly; 16 | kvz=[0:nz/2-1 -nz/2:-1]*2*pi/Lz; 17 | [kx,ky,kz]=meshgrid(kvx,kvy,kvz); 18 | % tic 19 | S = SMatLE(xE,yE,zE,pts,sup,gw,g); 20 | % toc 21 | % tic 22 | % S2 = SMatLESlow(xE,yE,zE,pts,sup,gw,g); 23 | % toc 24 | % max(abs(S-S2)) 25 | gridf=full(S*charges); 26 | gridf=permute(reshape(gridf,nx,ny,nz),[2 1 3]); 27 | fhat = fftn(gridf); 28 | ksq = -kx.^2-(ky-g*kx).^2-kz.^2; 29 | uhat = fhat./-ksq; 30 | uhat(1,1,1)=0; 31 | ufargrid=real(ifftn(uhat)); % is u on the slanted grid 32 | ufarCH=hx*hy*hz*S'*reshape(permute(ufargrid,[2 1 3]),nx*ny*nz,1); 33 | end 34 | -------------------------------------------------------------------------------- /Matlab/functions-solvers/computeBishopFrame.m: -------------------------------------------------------------------------------- 1 | % Function to compute the Bishop frame by solving the ODE 2 | % da/ds = (tau cross tau_s) cross a 3 | % a(L/2) = D1mid 4 | % Returns the bishop frame (a,b) and material frame (D1,D2). The other axis 5 | % is Xs in both cases. 6 | function [bishA,bishB,D1,D2] = computeBishopFrame(N,Xs,Xss,Dinv,BMP,theta,D1mid) 7 | eyeC = zeros(3*N,3); 8 | for iC=1:N 9 | eyeC(3*iC-2:3*iC,:)=eye(3); 10 | end 11 | AllCPMat2 = zeros(3*N); % Matrix which gives (Xs x Xss) x a at all pts 12 | for iPt=1:N 13 | AllCPMat2(3*(iPt-1)+1:3*iPt,3*(iPt-1)+1:3*iPt)=CPMatrix(cross(Xs(iPt,:),Xss(iPt,:))); 14 | end 15 | Matrix2 = [eye(3*N)-stackMatrix(Dinv)*AllCPMat2 eyeC; stackMatrix(BMP) zeros(3)]; 16 | RHS2 = [zeros(3*N,1); D1mid]; 17 | a2=Matrix2\RHS2; 18 | allas = reshape(a2(1:3*N),3,N)'; 19 | bishA = allas./sqrt(sum(allas.*allas,2)); % NORMALIZE 20 | bishB = cross(Xs,bishA); 21 | bishB = bishB./sqrt(sum(bishB.*bishB,2)); 22 | % Material frame from Bishop frame 23 | D1 = bishA.*cos(theta)+bishB.*sin(theta); 24 | D2 = -bishA.*sin(theta)+bishB.*cos(theta); 25 | end 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/matlab/fig_accuracy.m: -------------------------------------------------------------------------------- 1 | % finufft accuracy test figs, deciding err norm to report. Barnett 6/6/17 2 | clear 3 | %M=1e5; N=1e2; % M = # NU pts, N = # modes. Note: keep MN<1e8 for now 4 | M=1e4; N=1e3; 5 | %M=1e2; N=1e5; % confusion about N vs M controlling err prefac 6 | isign = +1; % sign of imaginary unit in exponential 7 | o.debug = 0; % choose 1 for timing breakdown text output 8 | o.nthreads = 0; % omit, or use 0, to use default num threads. 9 | 10 | tols = 10.^(-1:-1:-14); 11 | %tols = 1e-6; 12 | errs = nan*tols; 13 | for t=1:numel(tols) 14 | x = pi*(2*rand(1,M)-1); 15 | c = randn(1,M)+1i*randn(1,M); 16 | [f ier] = finufft1d1(x,c,isign,tols(t),N,o); 17 | ns = (ceil(-N/2):floor((N-1)/2))'; % mode indices, col vec 18 | fe = exp(1i*isign*ns*x) * c.'; % exact (note mat fill, matvec) 19 | errs(t) = max(abs(f(:)-fe(:)))/norm(c,1); % eps as in err analysis... 20 | %p=2; errs(t) = norm(f(:)-fe(:),p)/norm(c,p); % ... or rel p-norm 21 | end 22 | figure; loglog(tols,errs,'+'); hold on; plot(tols,tols,'-'); 23 | axis tight; xlabel('tol'); ylabel('err'); 24 | title(sprintf('1d1: (maxerr)/||c||_1, M=%d, N=%d\n',M,N)); 25 | 26 | -------------------------------------------------------------------------------- /Matlab/README.md: -------------------------------------------------------------------------------- 1 | # Matlab codes for slender fibers 2 | These are standalone Matlab codes for slender body hydrodynamics. These matlab codes are used primarily 3 | in [4] (see main repo page for references), but can also be used for some of the examples in [1]. 4 | In particular, this repository contains the codes necessary to run the dynamic examples in [4]: 5 | 6 | # Main programs 7 | 1) SBTRelaxingFib.m simulates a relaxing fiber with nonzero twist modulus (Section 5.2 in [4]) 8 | 2) WhirlingFibInstability.m simulates a fiber spinning about its axis (to generate the twirling-whirling 9 | instability; Section 5.3 in [4]) 10 | 3) SBTGravity.m simulates four falling fibers in free space. This is Section 11 | 5.1.1 in [1]. 12 | 4) SBTThreeFibs.m simulates three fibers being sheared in a perioid domain. This is 13 | Section 5.1.2 in [1], and is equivalent to the [python version](https://github.com/stochasticHydroTools/SlenderBody/blob/master/Python/Examples/ThreeShearedFibs.py) 14 | up to errors in the solvers (GMRES for first 2 iterations, nonlocal hydro tolerances, etc.). Also, the matlab code 15 | only does direct upsampled quadrature, while the python code has special quadrature schemes. 16 | 17 | -------------------------------------------------------------------------------- /Matlab/NumericalSBT/getGrandMBlobs.m: -------------------------------------------------------------------------------- 1 | function [Mtt,Mrt,Mrr] = getGrandMBlobs(N,X,a,mu) 2 | Mtt = zeros(3*N); 3 | Mrt = zeros(3*N); 4 | Mrr = zeros(3*N); 5 | for iB=1:N 6 | for jB = 1:N 7 | R = X(iB,:)-X(jB,:); 8 | RR = (R'*R); 9 | r = norm(R); 10 | if (r > 2*a) 11 | TransTrans = (eye(3)/r+RR/r^3)+ 2*a^2/3 *(eye(3)/r^3-3*RR/r^5); 12 | RotTrans = -CPMatrix(R)/r^3; 13 | RotRot = -1/2*(eye(3)/r^3-3*RR/r^5); 14 | elseif (r > 0) 15 | TransTrans = (4/(3*a)-3*r/(8*a^2))*eye(3)+1/(8*a^2*r)*RR; 16 | RotTrans = -CPMatrix(R)*1/(2*a^2)*(1/a-3*r/(8*a^2)); 17 | RotRot = 1/a^3*((1-27*r/(32*a)+5*r^3/(64*a^3))*eye(3) + ... 18 | (9/(32*a*r)-3*r/(64*a^3))*RR); 19 | else 20 | TransTrans = 4/(3*a)*eye(3); 21 | RotTrans = 0; 22 | RotRot = 1/a^3*eye(3); 23 | end 24 | Mtt(3*iB-2:3*iB,3*jB-2:3*jB)=1/(8*pi*mu)*TransTrans; 25 | Mrt(3*iB-2:3*iB,3*jB-2:3*jB)=1/(8*pi*mu)*RotTrans; 26 | Mrr(3*iB-2:3*iB,3*jB-2:3*jB)=1/(8*pi*mu)*RotRot; 27 | end 28 | end 29 | end -------------------------------------------------------------------------------- /Matlab/NumericalSBT/upsampleStokeslet.m: -------------------------------------------------------------------------------- 1 | function U = upsampleStokeslet(Targs,starg,X0,f0,s0,b0,Nup,L,a) 2 | % Collocation pts 3 | U = 0*Targs; 4 | for iT=1:length(Targs) 5 | t = starg(iT); 6 | P = Targs(iT,:); 7 | 8 | % Two Stokeslet integrals 9 | int1 = zeros(1,3); 10 | if (t > 2*a) 11 | [s1,w1,~]=chebpts(Nup,[0 t-2*a],1); 12 | R1 = barymat(s1, s0, b0); 13 | X1 = R1*X0; 14 | f1 = R1*f0; 15 | R = P-X1; 16 | nR = sqrt(sum(R.*R,2)); 17 | Rdotf = sum(R.*f1,2); 18 | StokIG = f1./nR + Rdotf.*R./nR.^3; 19 | totIG = StokIG; 20 | int1=w1*totIG; 21 | end 22 | int2 = zeros(1,3); 23 | if (t < L-2*a) 24 | [s1,w1,~]=chebpts(Nup,[t+2*a L],1); 25 | R1 = barymat(s1,s0, b0); 26 | X1 = R1*X0; 27 | f1 = R1*f0; 28 | R = P-X1; 29 | nR = sqrt(sum(R.*R,2)); 30 | Rdotf = sum(R.*f1,2); 31 | StokIG = f1./nR + Rdotf.*R./nR.^3; 32 | totIG = StokIG; 33 | int2=w1*totIG; 34 | end 35 | U(iT,:)=int1+int2; 36 | end 37 | end -------------------------------------------------------------------------------- /Matlab/MainPrograms/Filopodium/README.md: -------------------------------------------------------------------------------- 1 | # MATLAB Code for filopodium simulations 2 | These are standalone Matlab codes for the simulations of filopodia that appear in 3 | "Helical motors and formins synergize to compact chiral filopodial bundles: a theoretical perspective," by O. Maxian and A. Mogilner, Oct. 2023. 4 | See [biorxiv](https://www.biorxiv.org/content/10.1101/2023.07.24.550422) for text. 5 | 6 | The simulations can be run and analyzed via the following files 7 | 1) FiberBundle.m - the main driver file where parameters are specified 8 | 2) FiloExtFT.m - file that computes the external (motor and cross linking) forces and torques on the filaments at each time step 9 | 3) RecomputeDiscMats.m - file that recomputes the discretization matrices (for polymerizing fibers) at each time step 10 | 4) TemporalIntegrator_Fil - file that computes the velocity on each filament from the forces and torques 11 | 5) AnalyzeTrajector.m and PloyTraj.m - for analysis of the statistics and plotting the filaments 12 | 13 | Files related to supercoiling actin filaments are: 14 | 1) StabilityThetConst.m - performs linear stability analysis on the model equations 15 | 2) TwistFiber.m - simulation of (potentially supercoiling) single actin filament with fixed twist density over time 16 | -------------------------------------------------------------------------------- /Matlab/AnalyzePython/MakePlotConfigs.m: -------------------------------------------------------------------------------- 1 | N = 13; 2 | FileName = 'FromSSConfinedLocFlowLdx5Mot0.3Turn10_Dt5e-05_1'; 3 | LoadFileName = strcat(FileName,'.txt'); % ALWAYS LOOK @ MOVIE! 4 | Locs=load(strcat('Locs',LoadFileName)); 5 | Labels=load(strcat('FinalLabels_Sep',LoadFileName)); 6 | cd '/home/ondrejmaxian/Documents/SLENDER_FIBERS/SlenderBody/Python/plots/Motors/' 7 | NBundlesPerstep_Sep = load(strcat('NumberOfBundles_Sep',LoadFileName)); 8 | 9 | 10 | [numTs, F] = size(Labels); 11 | newlabels=zeros(numTs,F); 12 | for iT=1:numTs 13 | lab=1; 14 | for iFib=1:F 15 | if (newlabels(iT,iFib)==0) 16 | iFiblab = Labels(iT,iFib); 17 | if (sum(Labels(iT,:)==iFiblab)==1) 18 | newlabels(iT,iFib)=-1; 19 | else 20 | newlabels(iT,Labels(iT,:)==iFiblab)=lab; 21 | lab=lab+1; 22 | end 23 | end 24 | end 25 | % Rearrange to sort bundles by size 26 | nPerLab=zeros(lab,1); 27 | for iL=1:lab 28 | nPerLab(iL)=sum(newlabels(iT,:)==iL); 29 | end 30 | temp = newlabels(iT,:); 31 | [vals,newInds]=sort(nPerLab,'descend'); 32 | for iL=1:lab 33 | temp(newlabels(iT,:)==newInds(iL))=iL; 34 | end 35 | newlabels(iT,:)=temp; 36 | end 37 | writematrix(newlabels,strcat('NewLabels_',FileName,'.txt'),'Delimiter','tab'); 38 | for iT=1:numTs 39 | step=F*N; 40 | X = Locs((iT-1)*step+1:iT*step,:); 41 | writematrix(X,strcat(FileName,'_',num2str(iT),'.txt'),'Delimiter','tab'); 42 | end -------------------------------------------------------------------------------- /Python/Dependencies/finufft/fortran/README: -------------------------------------------------------------------------------- 1 | This directory contains Fortran wrappers to the FINUFFT C++ library, 2 | and older test codes changed little from the CMCL NUFFT library apart from 3 | that they call the FINUFFT library. 4 | 5 | The interfaces are identical to those of CMCL (ie drop-in replacements), 6 | apart from the type-1 no longer have the 1/nj normalization. 7 | The naming is: 8 | finufftNdM_f(...) where N=dimensions (1,2 or 3) and M=type (1,2 or 3). 9 | 10 | Note that, on a linux system, to compile and 11 | link a Fortran program against the FINUFFT 12 | library, use the following: 13 | 14 | gfortran nufft1d_demo.f dirft1d.f -o nufft1d_demo ../lib/libfinufft.a -lstdc++ -lfftw3 -lfftw3_omp -lm -fopenmp 15 | 16 | For Mac OSX, replace fftw3_omp by fftw3_threads. 17 | Or, if you compiled a single-threaded version: 18 | 19 | gfortran nufft1d_demo.f dirft1d.f -o nufft1d_demo ../lib/libfinufft.a -lstdc++ -lfftw3 -lm 20 | 21 | Alternatively you may want to compile with g++ and use -lgfortran at the *end* of the compile statement. 22 | 23 | See ../makefile 24 | Eg 25 | (cd ..; make fortran) 26 | 27 | Finally, the default demos are double precision. The single-precision 28 | versions have an extra "f" after the name, ie as listed by: ls *f.f 29 | 30 | Barnett 3/21/17; normalization updated 6/6/17. Tweaked 9/24/18. 31 | 32 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/matlab/finufft_opts.m: -------------------------------------------------------------------------------- 1 | function opts = finufft_opts(o) 2 | % FINUFFTS_OPTS. Global set opts for matlab interface to FINUFFT, with defaults 3 | % Barnett. Added upsampfac 6/18/18. 4 | % Added many_seq 6/23/18, then removed 7/28/18. chkbnds=1 default 7/30/18. 5 | 6 | % sets defaults, used if field absent or empty, and handles fields in o... 7 | debug=0; if isfield(o,'debug') && ~isempty(o.debug), debug = o.debug; end 8 | nthreads=0; if isfield(o,'nthreads') && ~isempty(o.nthreads), nthreads = o.nthreads; end 9 | spread_sort=2; if isfield(o,'spread_sort') && ~isempty(o.spread_sort), spread_sort=o.spread_sort; end 10 | fftw=0; if isfield(o,'fftw') && ~isempty(o.fftw), fftw=o.fftw; end 11 | modeord=0; if isfield(o,'modeord') && ~isempty(o.modeord), modeord=o.modeord; end 12 | chkbnds=1; if isfield(o,'chkbnds') && ~isempty(o.chkbnds), chkbnds=o.chkbnds; end 13 | upsampfac=2.0; if isfield(o,'upsampfac') && ~isempty(o.upsampfac), upsampfac=o.upsampfac; end 14 | 15 | % pack up: ordering of opts must match that in finufft_m.cpp:finufft_mex_opts() 16 | % (placement in opts now explicit, catches errors if inputs are not 1x1 sized) 17 | opts = zeros(1,7,'double'); 18 | opts(1) = debug; 19 | opts(2) = nthreads; 20 | opts(3) = spread_sort; 21 | opts(4) = fftw; 22 | opts(5) = modeord; 23 | opts(6) = chkbnds; 24 | opts(7) = upsampfac; 25 | -------------------------------------------------------------------------------- /Matlab/functions-solvers/linequad/matlabcheb/rsqrt_pow_weights.m: -------------------------------------------------------------------------------- 1 | function [w1, w3, w5] = rsqrt_pow_weights(tj, troot, varargin) 2 | 3 | n = numel(tj); 4 | 5 | 6 | use_bjorck_pereyra = false; % Even faster than precomputed LU 7 | 8 | [p1, p3, p5] = rsqrt_pow_integrals(troot, n); 9 | %p3 10 | basis = tj; 11 | 12 | % Compute "modified quadrature weights" 13 | tdist = abs(tj-troot); 14 | if n < 33 && use_bjorck_pereyra 15 | % Using Bjorck-Pereyra to solve Vandermonde system 16 | w1 = pvand(basis, p1) .* tdist; % O(n^2) 17 | w3 = pvand(basis, p3) .* tdist.^3; 18 | w5 = pvand(basis, p5) .* tdist.^5; 19 | else 20 | % Direct solve with Vandermonde matrix is more stable for n>32 21 | % Still, n>40 is not a good idea 22 | pvec = [p1 p3 p5]; 23 | if isempty(varargin) 24 | A = ones(n); 25 | for j=2:n 26 | A(j,:) = A(j-1,:).*basis.'; % build transpose, O(n^2) 27 | end 28 | warning('off', 'MATLAB:nearlySingularMatrix') 29 | W = A \ pvec; % O(n^3) 30 | warning('on', 'MATLAB:nearlySingularMatrix') 31 | else 32 | L = varargin{1}; 33 | U = varargin{2}; 34 | luvec = varargin{3}; 35 | W = U\(L\pvec(luvec,:)); 36 | end 37 | w1 = W(:,1) .* tdist; 38 | w3 = W(:,2) .* tdist.^3; 39 | w5 = W(:,3) .* tdist.^5; 40 | end 41 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/docs/ackn.rst: -------------------------------------------------------------------------------- 1 | Acknowledgments 2 | =============== 3 | 4 | The main code and mathematical development is by: 5 | 6 | * Alex Barnett (Flatiron Institute) 7 | * Jeremy Magland (Flatiron Institute) 8 | 9 | Significant SIMD vectorization/acceleration of the spreader by: 10 | 11 | * Ludvig af Klinteberg (SFU) 12 | 13 | Other code contributions: 14 | 15 | * Yu-Hsuan ("Melody") Shih - 2d1many, 2d2many interface for many vectors same points 16 | * Leslie Greengard and June-Yub Lee - CMCL fortran drivers and test codes 17 | * Dan Foreman-Mackey - python wrappers 18 | * David Stein - python wrappers 19 | * Dylan Simon - sphinx help 20 | * Amit Moscovich - Mac OSX build 21 | 22 | Testing, bug reports: 23 | 24 | * Joakim Anden - catching memory leak, Matlab/FFTW issues, performance tests 25 | * Hannah Lawrence - user testing and finding bugs 26 | * Marina Spivak - fortran testing 27 | * Hugo Strand - python bugs 28 | 29 | Helpful discussions: 30 | 31 | * Charlie Epstein - analysis of kernel Fourier transform sums 32 | * Christian Muller - optimization (CMA-ES) for early kernel design 33 | * Andras Pataki - complex number speed in C++ 34 | * Timo Heister - pass/fail numdiff testing ideas 35 | * Zydrunas Gimbutas - explanation that NFFT uses Kaiser-Bessel backwards 36 | * Vladimir Rokhlin - piecewise polynomial approximation on complex boxes 37 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/matlab/check_changenthreads.m: -------------------------------------------------------------------------------- 1 | % check FINUFFT matlab interface doesn't change current # omp threads. 2 | % Barnett 9/20/18 3 | 4 | clear % choose params... 5 | isign = +1; % sign of imaginary unit in exponential 6 | eps = 1e-6; % requested accuracy 7 | o.fftw = 0; % style of FFTW: 0 (ESTIMATE) vs 1 (MEASURE, slow but reuses) 8 | o.upsampfac=1.25; % 2.0 (default) or 1.25 (low-RAM, small-FFT) 9 | M = 1e7; % # of NU pts (in all dims) 10 | N = 1e6; % # of modes (approx total, used in all dims) 11 | x = pi*(2*rand(1,M)-1); 12 | c = randn(1,M)+1i*randn(1,M); 13 | 14 | o.debug = 1; % choose 1 for timing breakdown text output 15 | matnthr = maxNumCompThreads(8); % measure matlab's state 16 | fprintf('maxNumCompThreads = %d\n',maxNumCompThreads) 17 | fprintf('1D: opts.nthreads=0\n') 18 | tic; [f ier] = finufft1d1(x,c,isign,eps,N,o); toc 19 | o.nthreads=1; fprintf('1D: opts.nthreads=1\n') 20 | tic; [f ier] = finufft1d1(x,c,isign,eps,N,o); toc 21 | o.nthreads=0; fprintf('1D: opts.nthreads=0\n') 22 | tic; [f ier] = finufft1d1(x,c,isign,eps,N,o); toc % should use all avail 23 | maxNumCompThreads(matnthr); % restore matlab's state 24 | 25 | % NOTE: the sad thing is that omp has an internal state (changed by 26 | % omp_set_max_threads) that Matlab cannot see with maxNumCompThreads ! 27 | % However, maxNumCompThreads(n) does change this state. 28 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/src/common.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_H 2 | #define COMMON_H 3 | 4 | #include "finufft.h" 5 | #include "defs.h" 6 | #include "spreadinterp.h" 7 | #include 8 | 9 | // defs internal to common.cpp... 10 | typedef std::complex dcomplex; 11 | // (slightly sneaky since name duplicated by mwrap - unrelated) 12 | 13 | 14 | // common.cpp provides... 15 | int setup_spreader_for_nufft(spread_opts &spopts, FLT eps, nufft_opts opts); 16 | void set_nf_type12(BIGINT ms, nufft_opts opts, spread_opts spopts,BIGINT *nf); 17 | void set_nhg_type3(FLT S, FLT X, nufft_opts opts, spread_opts spopts, 18 | BIGINT *nf, FLT *h, FLT *gam); 19 | void onedim_dct_kernel(BIGINT nf, FLT *fwkerhalf, spread_opts opts); 20 | void onedim_fseries_kernel(BIGINT nf, FLT *fwkerhalf, spread_opts opts); 21 | void onedim_nuft_kernel(BIGINT nk, FLT *k, FLT *phihat, spread_opts opts); 22 | void deconvolveshuffle1d(int dir,FLT prefac,FLT* ker,BIGINT ms,FLT *fk, 23 | BIGINT nf1,FFTW_CPX* fw,int modeord); 24 | void deconvolveshuffle2d(int dir,FLT prefac,FLT *ker1, FLT *ker2, 25 | BIGINT ms,BIGINT mt, 26 | FLT *fk, BIGINT nf1, BIGINT nf2, FFTW_CPX* fw, 27 | int modeord); 28 | void deconvolveshuffle3d(int dir,FLT prefac,FLT *ker1, FLT *ker2, 29 | FLT *ker3, BIGINT ms, BIGINT mt, BIGINT mu, 30 | FLT *fk, BIGINT nf1, BIGINT nf2, BIGINT nf3, 31 | FFTW_CPX* fw, int modeord); 32 | #endif // COMMON_H 33 | -------------------------------------------------------------------------------- /Matlab/functions-solvers/Ewald/SMatLESlow.m: -------------------------------------------------------------------------------- 1 | % Computes the spread and interpolation matrices without Gaussian gridding. 2 | % Vectorized and linear in the number of points. 3 | % This file is a SLOW loop that is used to check the fast Gaussian gridding 4 | % version SMatLE.m 5 | % Both are for SHEARED DOMAINS 6 | function SWeights = SMatLESlow(xEpts,yEpts,zEpts,IBpts,sup,gw,g) 7 | % Do the naive thing first 8 | [nP,~]=size(IBpts); 9 | hex=xEpts(2)-xEpts(1); 10 | hey=yEpts(2)-yEpts(1); 11 | hez=zEpts(2)-zEpts(1); 12 | Lx=max(xEpts)-min(xEpts)+hex; 13 | Ly=max(yEpts)-min(yEpts)+hey; 14 | Lz=max(zEpts)-min(zEpts)+hez; 15 | Nx = length(xEpts); 16 | Ny = length(yEpts); 17 | Nz = length(zEpts); 18 | SWeights=zeros(Nx*Ny*Nz,nP); 19 | for iPt=1:nP 20 | % The point will come in as (x,y,z) 21 | for iX=1:Nx 22 | for iY=1:Ny 23 | for iZ=1:Nz 24 | % Find the closest point 25 | gridpt = xEpts(iX)*[1 0 0]+yEpts(iY)*[g 1 0]+zEpts(iZ)*[0 0 1]; 26 | rvec=gridpt-IBpts(iPt,:); 27 | rvec = calcShifted(rvec,g,Lx,Ly,Lz); 28 | r=norm(rvec); 29 | ind = iX+Nx*(iY-1)+Nx*Ny*(iZ-1); 30 | SWeights(ind,iPt)=1/sqrt(8*pi^3*gw^6)*exp(-r^2/(2*gw^2)); 31 | end 32 | end 33 | end 34 | end 35 | end -------------------------------------------------------------------------------- /Matlab/functions-solvers/linequad/matlabcheb/rootfinder_initial_guess.m: -------------------------------------------------------------------------------- 1 | function tinit = rootfinder_initial_guess(tj, xj, yj, zj, x0, y0, z0) 2 | % Compute initial guess for 3D root finder 3 | 4 | guess_order = 2; 5 | 6 | if guess_order == 1 7 | % First order guess: 8 | % Initial guess based on location from closest point 9 | R2j = ( (xj-x0).^2 + (yj-y0).^2 + (zj-z0).^2 ); 10 | [Rmin, imin] = min(R2j); 11 | panel_length = sqrt( (xj(1)-xj(end)).^2 + (yj(1)-yj(end)).^2 + (zj(1)-zj(end)).^2 ); 12 | ainit = tj(imin); 13 | binit = Rmin*2/panel_length; 14 | tinit = ainit + 1i*binit; 15 | else 16 | % Second order guess; 17 | % Initial guess based on orientation relative to two closest points 18 | % Find indices of two closest points 19 | R2j = ( (xj-x0).^2 + (yj-y0).^2 + (zj-z0).^2 ); 20 | [~, isort] = mink(R2j, 2); 21 | i1 = isort(1); 22 | i2 = isort(2); 23 | % Locations of closest points in R3 and C 24 | v1 = [xj(i1) yj(i1) zj(i1)]; 25 | v2 = [xj(i2) yj(i2) zj(i2)]; 26 | t1 = tj(i1); 27 | t2 = tj(i2); 28 | p = v1-v2; 29 | pnorm = sqrt(p(1)^2 + p(2)^2 + p(3)^2); 30 | x = [x0 y0 z0]; 31 | r = x-v1; 32 | rdotp = r(1)*p(1) + r(2)*p(2) + r(3)*p(3); 33 | a = (t1-t2)*rdotp/pnorm^2; 34 | b = sqrt(norm(r)^2-rdotp^2/pnorm^2)*(t1-t2)/pnorm; 35 | tinit = complex(t1 + a + 1i*b); 36 | end 37 | end -------------------------------------------------------------------------------- /Matlab/functions-solvers/Ewald/EwaldNearSum.m: -------------------------------------------------------------------------------- 1 | % Ewald near field velocity for RPY 2 | function velNear = EwaldNearSum(Npts,pts,forces,xi,Lx,Ly,Lz,a,mu,g) 3 | velNear=zeros(3,Npts); 4 | % Check that the near field decays fast enough 5 | Mcheck = RPYNear([min([Lx Ly Lz])/2 0 0],xi,a,mu); 6 | if (max(max(abs(Mcheck))) > 1e-3) 7 | error("Increase the Ewald parameter or periodic length-interactions with more than 1 image") 8 | end 9 | % Compute r_cut (should really be done outside time loop) 10 | rcuts = 0.01:0.01:(min([Lx Ly Lz])/2); 11 | nzation = min(norm(RPYNear([0 0 0],xi,a,mu)*[1;0;0],'inf'),1); 12 | rcut = min([Lx Ly Lz])/2; 13 | for iCut=1:length(rcuts) 14 | if (norm(RPYNear([rcuts(iCut) 0 0],xi,a,mu)*[1;0;0],'inf')/nzation < 1e-8) 15 | rcut = rcuts(iCut); 16 | break; 17 | end 18 | end 19 | % Do neighbor search 20 | for iPt=1:Npts 21 | Mself = RPYNear([0 0 0],xi,a,mu); 22 | velNear(:,iPt)=velNear(:,iPt)+Mself*(forces(iPt,:)'); 23 | for jPt=iPt+1:Npts 24 | % Find the nearest image 25 | rvec=pts(iPt,:)-pts(jPt,:); 26 | rvec = calcShifted(rvec,g,Lx,Ly,Lz); 27 | if (norm(rvec) < rcut) 28 | Mother = RPYNear(rvec,xi,a,mu); 29 | velNear(:,iPt)=velNear(:,iPt)+Mother*(forces(jPt,:)'); 30 | velNear(:,jPt)=velNear(:,jPt)+Mother*(forces(iPt,:)'); 31 | end 32 | end 33 | end 34 | velNear = velNear'; 35 | end -------------------------------------------------------------------------------- /Matlab/functions-solvers/precomputeDoubletInts.m: -------------------------------------------------------------------------------- 1 | % Precomputes the integrals 2 | % int_D (eta'-eta)/abs(eta'-eta)^3*T_k(eta') deta' 3 | % involved in the nearly singular quadratures for the Doublet. 4 | % See Appendix F of the paper. 5 | % chebpoly = 0 for monomials, chebpoly=1 for Chebyshev polynomials 6 | function Allbs = precomputeDoubletInts(s0,L,a,N,chebpoly) 7 | k=0:N-1; 8 | sscale=-1+2*s0/L; 9 | for iPt=1:N 10 | s = s0(iPt); 11 | eta = sscale(iPt); 12 | sLow = max(s-2*a,0); 13 | sHi = min(s+2*a,L); 14 | etaLow = -1+2*sLow/L; 15 | etaHi = -1+2*sHi/L; 16 | % Compute integrals numerically to high accuracy 17 | q = zeros(1,N); 18 | for kk=k 19 | if (etaLow > -1) 20 | [n,w]=chebpts(200,[-1 etaLow],1); 21 | poly = n.^kk; 22 | if (chebpoly) 23 | poly = cos(kk*acos(n)); 24 | end 25 | q(kk+1)=w*((n-eta)./abs(n-eta).^3.*poly); 26 | end 27 | if (etaHi < 1) 28 | [n,w]=chebpts(200,[etaHi 1],1); 29 | poly = n.^kk; 30 | if (chebpoly) 31 | poly = cos(kk*acos(n)); 32 | end 33 | q(kk+1)=q(kk+1)+w*((n-eta)./abs(n-eta).^3.*poly); 34 | end 35 | end 36 | AllQs(iPt,:)=q; 37 | end 38 | PolyMat = fliplr(vander(sscale))'; 39 | if (chebpoly) 40 | PolyMat = cos(k.*acos(sscale))'; 41 | end 42 | Allbs= mldivide(PolyMat,AllQs'); 43 | end -------------------------------------------------------------------------------- /Matlab/MainPrograms/StraightMobility.m: -------------------------------------------------------------------------------- 1 | % Compute 6 x 6 mobility matrix forfiber 2 | mu =1; 3 | L = 2; 4 | eps=1e-2*4/exp(3/2); 5 | a=exp(3/2)/4*eps*L; 6 | N = 32; 7 | [s,w,b] = chebpts(N, [0 L], 1); % 1st-kind grid for ODE. 8 | % Falling fibers 9 | D = diffmat(N,1,[0 L],'chebkind1'); 10 | Ds=zeros(3*N); 11 | Ds(1:3:3*N,1:3:3*N)=D; 12 | Ds(2:3:3*N,2:3:3*N)=D; 13 | Ds(3:3:3*N,3:3:3*N)=D; 14 | X0 = [0 0 0]; 15 | XsOne = [1;0;0]; 16 | %XsOne = 1/sqrt(14)*[2;1;3]; 17 | Xs = repmat(XsOne,N,1); 18 | X = XsOne'.*s+X0; 19 | Xcenter = XsOne'*L/2; 20 | delta = 0.1; 21 | Mloc = getGrandMloc(N,Xs,zeros(3*N,1),a,L,mu,s,delta); 22 | Allb_trueFP = precomputeStokesletInts(s,L,0,N,1); 23 | AllbS = precomputeStokesletInts(s,L,a,N,1); 24 | AllbD = precomputeDoubletInts(s,L,a,N,1); 25 | MFP = StokesletFinitePartMatrix(X,reshape(Xs,3,N)',zeros(N,3),D,s,L,N,mu,Allb_trueFP); 26 | NForSmall = 8; 27 | MRPY = ExactRPYSpectralMobility(N,X,reshape(Xs,3,N)',zeros(N,3),a,L,mu,s,b,D,AllbS,AllbD,NForSmall); 28 | for doFp=[0,1,2] 29 | M = Mloc+doFp*MFP; 30 | if (doFp==2) 31 | M = MRPY; 32 | end 33 | K = zeros(3*N,6); 34 | Kt=zeros(6,3*N); 35 | for iR=1:N 36 | dX = X(iR,:)-Xcenter; 37 | cpmat = [0 dX(3) -dX(2); -dX(3) 0 dX(1); dX(2) -dX(1) 0]; 38 | K(3*(iR-1)+1:3*iR,1:3)=eye(3); 39 | K(3*(iR-1)+1:3*iR,4:6)=cpmat; % Omega x (X-Xcenter) 40 | Kt(1:3,3*(iR-1)+1:3*iR)=w(iR)*eye(3); 41 | Kt(4:6,3*(iR-1)+1:3*iR)=-w(iR)*cpmat; % (X-Xcenter) x f 42 | end 43 | GMob = pinv(Kt*(M\K)); % mobility matrix 44 | tableline(3*doFp+1:3*(doFp+1))= [GMob(2,2) GMob(1,1)-GMob(2,2) GMob(5,5)]; 45 | end 46 | tableline -------------------------------------------------------------------------------- /Matlab/ChebyshevAndBlobs/ChebUniformLstSquares.m: -------------------------------------------------------------------------------- 1 | % Least squares in L^2 to obtain Chebyshev coefficients of a function on a 2 | % uniform grid 3 | close all; 4 | 5 | % Build resampling matrices 6 | % Chebyshev coefficients to Chebyshev values 7 | NCheb = 16; 8 | th_Cheb =fliplr(2.0*(0:NCheb-1)'+1)*pi/(2*NCheb); 9 | sCheb = cos(th_Cheb); % this will come in from chebfun in the real solver 10 | % Chebyshev coefficients to uniform values 11 | Nuni = 10000; 12 | ds = 2/(Nuni-1); 13 | sUni = (1:-ds:-1)'; 14 | CoeffstoValsUniform = cos(acos(sUni).* (0:NCheb-1)); 15 | % Take 16 randomly decaying Chebyshev coefficients and sample that 16 | % Chebyshev series on the uniform grid 17 | rng(0); 18 | chat = rand(NCheb,1).*exp(-0.5*(0:NCheb-1)'); 19 | univals = CoeffstoValsUniform*chat; % values on uniform grid 20 | univalsPerturbed = univals+(rand(Nuni,1)-0.5)*0.1; % randomly perturbed 21 | plot(sUni,univalsPerturbed) 22 | hold on 23 | plot(sUni,univals,'LineWidth',2.0) 24 | legend('Perturbed data','Original series') 25 | 26 | % Compute coefficients by integration (Simpson's rule for theta) 27 | % Weights for trapezoidal rule 28 | [ChebVals,ChebIntsSimp] = ProjectToChebyshev(sCheb,sUni,univals,NCheb); 29 | [ChebValsPert,ChebIntsSimpPert] = ProjectToChebyshev(sCheb,sUni,univalsPerturbed,NCheb); 30 | % Error 31 | max(abs(ChebIntsSimp-chat)) 32 | % Plot normal and perturbed coefficients 33 | figure; 34 | semilogy(0:NCheb-1,abs(chat),'-o',0:NCheb-1,abs(ChebIntsSimp),'s',0:NCheb-1,abs(ChebIntsSimpPert),'d',... 35 | 'MarkerSize',8,'LineWidth',2.0) 36 | legend('Original','Simpson','Simpson for perturbed') 37 | 38 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/docs/dirs.rst: -------------------------------------------------------------------------------- 1 | Contents of the package 2 | ======================= 3 | 4 | - ``finufft-manual.pdf`` : the manual (auto-generated by sphinx) 5 | - ``docs`` : source files for documentation (.rst files are human-readable) 6 | - ``README.md`` : github-facing (and human text-reader) doc info 7 | - ``LICENSE`` : how you may use this software 8 | - ``CHANGELOG`` : list of changes, release notes 9 | - ``TODO`` : list of things needed to fix or extend (hackers please help) 10 | - ``makefile`` : GNU makefile (there are no makefiles in subdirectories) 11 | - ``src`` : main library source and headers. Compiled objects will be built here 12 | - ``lib`` : dynamic library will be built here 13 | - ``lib-static`` : static library will be built here 14 | - ``test`` : validation and performance tests, bash scripts driving compiled C++ 15 | 16 | - ``test/check_finufft.sh`` is the main pass-fail validation bash script 17 | - ``test/nuffttestnd.sh`` is a simple uniform-point performance test bash script 18 | - ``test/results`` : validation comparison outputs (\*.refout; do not remove these), and local test and performance outputs (\*.out; you may remove these) 19 | 20 | - ``examples`` : simple example codes for calling the library from C++ and C 21 | - ``fortran`` : wrappers and drivers for Fortran (see ``fortran/README``) 22 | - ``matlab`` : wrappers and examples for MATLAB/octave 23 | - ``finufftpy`` : python wrappers 24 | - ``python_tests`` : accuracy and speed tests and examples using the python wrappers 25 | - ``setup.py`` : needed so pip or pip3 can build and install the python wrappers 26 | - ``contrib`` : 3rd-party code 27 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/make.inc.macosx_clang: -------------------------------------------------------------------------------- 1 | # Makefile variable overrides for Mac OSX compilation with CLANG. 2 | # 3 | # Note that we have not been able to link against gfortran, so if you need 4 | # fortran interfaces, use make.inc.macosx_gcc-* instead. 5 | # 6 | # Copy this file to make.inc, and if needed edit for your setup. 7 | # Barnett 10/27/18. Input from Yu-Hsuan Shih, Amit Moskovich. 8 | 9 | # (note that /usr/bin/g++,gcc are aliased to clang/LLVM, so CXX,CC unchanged) 10 | 11 | # compile flags for use with clang: (note absence of -march, etc) 12 | CFLAGS = -fPIC -O3 13 | 14 | # If you're getting warning messages of the form: 15 | # ld: warning: object file (lib-static/libfinufft.a(finufft1d.o)) was built for 16 | # newer OSX version (10.13) than being linked (10.9) 17 | # Then you can uncomment the following two lines with the older version number 18 | # (in this example -mmacosx-version-min=10.9) 19 | # 20 | #CFLAGS += "-mmacosx-version-min=" 21 | 22 | # taken from makefile... 23 | CFLAGS += -I src 24 | FFLAGS = $(CFLAGS) 25 | CXXFLAGS = $(CFLAGS) -DNEED_EXTERN_C 26 | 27 | # OpenMP with clang needs following... 28 | OMPFLAGS = -Xpreprocessor -fopenmp 29 | OMPLIBS = -lomp 30 | # since fftw3_omp doesn't work in OSX, we need... 31 | FFTWOMPSUFFIX=threads 32 | 33 | # MATLAB interface: 34 | # some of these will depend on your FFTW library location... 35 | MFLAGS += -I/usr/local/include -L/usr/local/lib -lm 36 | # edit for your MATLAB version location... 37 | MEX = $(shell ls -d /Applications/MATLAB_R201*.app)/bin/mex 38 | # Also see docs/install.rst for possible edits to MATLAB's MEX XML file. 39 | -------------------------------------------------------------------------------- /Matlab/functions-solvers/updateX.m: -------------------------------------------------------------------------------- 1 | % Inextensible update by rotating tangent vectors and integrating 2 | function [Xnp1,Xsp1,Omega] = updateX(Xt,ut2,N,dt,Lf,Xsin,Xsm1,dU,solver,D,Omega) 3 | % Resampling matrices 4 | th=flipud(((2*(0:N-1)+1)*pi/(2*N))'); 5 | Lmat = (cos((0:N-1).*th)); 6 | Xsin =reshape(Xsin,3,N)'; 7 | Xsm1 =reshape(Xsm1,3,N)'; 8 | % Compute new Xs 9 | % g1=Lmat(:,1:N-1)*alphas(1:N-1); 10 | % g2=Lmat(:,1:N-1)*alphas(N:2*N-2); 11 | Xsk = Xsin; 12 | if (solver > 1) 13 | Xsk = 1.5*Xsin-0.5*Xsm1; 14 | end 15 | % [theta,phi,~] = cart2sph(Xsk(:,1),Xsk(:,2),Xsk(:,3)); 16 | % theta(abs((abs(phi)-pi/2)) < 1e-12) =0; 17 | % n1s=[-sin(theta) cos(theta) 0*theta]; 18 | % n2s=[-cos(theta).*sin(phi) -sin(theta).*sin(phi) cos(phi)]; 19 | % Omega=g1.*n2s-g2.*n1s; 20 | Omega = cross(Xsk,reshape(dU,3,N)'); 21 | %max(abs(Omega-Omega1)) 22 | % Increment Xs 23 | nOm = sqrt(sum(Omega.*Omega,2)); 24 | % Have to truncate somewhere to avoid instabilities 25 | k = Omega./nOm; 26 | k(nOm < 1e-12,:) = 0; 27 | % Rodriguez formula on the N grid. 28 | Xsp1 = Xsin.*cos(nOm*dt)+cross(k,Xsin).*sin(nOm*dt)+k.*sum(k.*Xsin,2).*(1-cos(nOm*dt)); 29 | Xnp1 = pinv(D)*Xsp1; 30 | % Make the velocity at s = the first s equal to the original solver 31 | Xnp1=Xnp1-Xnp1(1,:)+(Xt(1:3)'+dt*ut2(1:3)'); 32 | % [s,~,b]=chebpts(N,[0 Lf],1); 33 | % MPEval = barymat(Lf/2,s,b); 34 | % Xnp1=Xnp1-Xnp1(1,:)+(Xt(1:3)'+dt*MPEval*reshape(ut2,3,N)'); 35 | % Evaluate velocity at midpoint (TEMP) 36 | Xnp1=reshape(Xnp1',3*N,1); 37 | Xsp1=reshape(Xsp1',3*N,1); 38 | end -------------------------------------------------------------------------------- /Python/Dependencies/NeighborSearch/Makefile: -------------------------------------------------------------------------------- 1 | #Default log level is 5, which prints up to MESSAGE, 0 will only print critical errors and 14 will print everything up to the most low level debug information 2 | LOG_LEVEL=0 3 | 4 | CXX=g++ 5 | #If you define nvcc the code will compile in hybrid CPU/GPU mode, if this variable is empty 6 | # the code will be compiled in CPU only mode 7 | NVCC= 8 | CUDA_ROOT=/usr/local/cuda 9 | #Python is required for the python_wrappers example 10 | PYTHON=python3 11 | UAMMD_ROOT=../UAMMD_PSE_Python/uammd/ 12 | #Uncomment to compile in double precision mode 13 | #DOUBLE_PRECISION=-DDOUBLE_PRECISION 14 | INCLUDEFLAGS:=`python3 -m pybind11 --includes` 15 | CXXSTD=14 16 | OLEVEL=4 17 | CXXFLAGS:= -std=c++$(CXXSTD) -ffast-math -march=native -O$(OLEVEL) -fPIC -g -DPYTHON_LIBRARY_MODE 18 | ifneq ($(NVCC),) 19 | UAMMD_INCLUDES=-I$(UAMMD_ROOT)/src -I$(UAMMD_ROOT)/src/third_party 20 | INCLUDEFLAGS:=-I$(CUDA_ROOT)/include $(UAMMD_INCLUDES) $(INCLUDEFLAGS) 21 | NVCCFLAGS=-std=c++$(CXXSTD) -O$(OLEVEL) $(INCLUDEFLAGS) -DMAXLOGLEVEL=$(LOG_LEVEL) $(DOUBLE_PRECISION) --expt-extended-lambda --expt-relaxed-constexpr -Xcompiler "$(CXXFLAGS)" 22 | endif 23 | 24 | LDFLAGS= -ltbb 25 | 26 | PYTHON_MODULE_NAME=NeighborSearch 27 | PYTHON_LIBRARY_NAME=$(PYTHON_MODULE_NAME)$(shell $(PYTHON)-config --extension-suffix) 28 | all: $(PYTHON_LIBRARY_NAME) 29 | 30 | $(PYTHON_LIBRARY_NAME): nlist_py.cu Makefile 31 | ifneq ($(NVCC),) 32 | $(NVCC) $(NVCCFLAGS) $(INCLUDEFLAGS) $< -o $(PYTHON_LIBRARY_NAME) $(LDFLAGS) -shared 33 | else 34 | $(CXX) $(CXXFLAGS) $(INCLUDEFLAGS) -x c++ $< -o $(PYTHON_LIBRARY_NAME) $(LDFLAGS) -shared 35 | endif 36 | 37 | clean: 38 | rm -f $(PYTHON_LIBRARY_NAME) 39 | -------------------------------------------------------------------------------- /Matlab/functions-solvers/PeriodicRPYSum.m: -------------------------------------------------------------------------------- 1 | % Compute the action of the non-local mobility matrix in a periodic DOMAIN. 2 | % This code just performs an O(N^2) sum 3 | function U = PeriodicRPYSum(nFib,X,F,Lds,xi,g,a,mu,Rupsample,wup,WTildeInverse,directquad) 4 | FINUUFT=1; % use FINUFFT 5 | % Compile list of upsampled points and forces 6 | [Nup,Nx]=size(Rupsample); 7 | if (directquad) 8 | Nup=Nx; 9 | end 10 | Forces = zeros(Nup*nFib,3); 11 | UpPoints = zeros(Nup*nFib,3); 12 | U = zeros(Nx*nFib,3); 13 | for iFib=1:nFib 14 | inds = (iFib-1)*Nx+1:iFib*Nx; 15 | UpInds = (iFib-1)*Nup+1:iFib*Nup; 16 | if (directquad) 17 | Forces(inds,:)=F(inds,:); 18 | UpPoints(inds,:)=X(inds,:); 19 | else 20 | Forces(UpInds,:)=diag(wup)*Rupsample*WTildeInverse*F(inds,:); 21 | UpPoints(UpInds,:)=Rupsample*X(inds,:); 22 | end 23 | end 24 | % Ewald splitting calculation 25 | if (FINUUFT) 26 | velFar = EwaldFarVelFI(UpPoints,Forces,mu,Lds(1),Lds(2),Lds(3),xi,a,g)'; 27 | else 28 | velFar = EwaldFarVel(UpPoints,Forces,mu,Lds(1),Lds(2),Lds(3),xi,a,g); 29 | end 30 | velNear = EwaldNearSum(nFib*Nup,UpPoints,Forces,xi,Lds(1),Lds(2),Lds(3),a,mu,g); 31 | velEwald=velNear+velFar; % This is on the updampled grid 32 | % Apply L^2 downsampling to go back to the N point grid 33 | for iFib=1:nFib 34 | inds = (iFib-1)*Nx+1:iFib*Nx; 35 | UpInds = (iFib-1)*Nup+1:iFib*Nup; 36 | if (directquad) 37 | U(inds,:)=velEwald(UpInds,:); 38 | else 39 | U(inds,:) = WTildeInverse*Rupsample'*diag(wup)*velEwald(UpInds,:); 40 | end 41 | end 42 | end -------------------------------------------------------------------------------- /Matlab/functions-solvers/UnboundedRPYSum.m: -------------------------------------------------------------------------------- 1 | % Compute the action of the non-local mobility matrix in an UNBOUNDED DOMAIN. 2 | % This code just performs an O(N^2) sum 3 | function U = UnboundedRPYSum(nFib,X,F,a,mu,Rupsample,wup,WTildeInverse,direct,SelfOnly) 4 | % Contibutions from the other fibers 5 | [NupsampleforNL,Nx]=size(Rupsample); 6 | if (direct) 7 | NupsampleforNL=Nx; 8 | end 9 | U = zeros(Nx*nFib,3); 10 | for iFib=1:nFib 11 | U_up = zeros(NupsampleforNL,3); 12 | iinds = (iFib-1)*Nx+1:iFib*Nx; 13 | if (direct) 14 | ThisX = X(iinds,:); 15 | else 16 | ThisX = Rupsample*X(iinds,:); 17 | end 18 | for iPt=1:NupsampleforNL 19 | otherFibs = 1:nFib; 20 | if (SelfOnly) 21 | otherFibs=iFib; 22 | end 23 | for jFib=otherFibs 24 | jinds = (jFib-1)*Nx+1:jFib*Nx; 25 | if (direct) 26 | otherPts = X(jinds,:); 27 | otherForces = F(jinds,:); 28 | else 29 | otherPts = Rupsample*X(jinds,:); 30 | otherForces = diag(wup)*Rupsample*WTildeInverse*F(jinds,:); 31 | end 32 | for jPt=1:NupsampleforNL 33 | rvec = ThisX(iPt,:)-otherPts(jPt,:); 34 | MRPY = RPYTot(rvec,a,mu); 35 | U_up(iPt,:)=U_up(iPt,:)+otherForces(jPt,:)*MRPY; 36 | end 37 | end 38 | end 39 | % Downsample the velocity 40 | if (direct) 41 | U(iinds,:) = U_up; 42 | else 43 | U(iinds,:) = WTildeInverse*Rupsample'*diag(wup)*U_up; 44 | end 45 | end 46 | end -------------------------------------------------------------------------------- /Matlab/NumericalSBT/upsampleRPYRotRot.m: -------------------------------------------------------------------------------- 1 | function U = upsampleRPYRotRot(Targs,starg,X0,f0,s0,b0,Nup,L,a) 2 | % Collocation pts 3 | U = 0*Targs; 4 | for iT=1:length(Targs) 5 | t = starg(iT); 6 | P = Targs(iT,:); 7 | [ssm,wsm,~]=chebpts(Nup,[max(t-2*a,0) min(t+2*a,L)],2); 8 | Rsm = barymat(ssm, s0, b0); 9 | Xsm = Rsm*X0; 10 | fsm = Rsm*f0; 11 | R = P-Xsm; 12 | nR = sqrt(sum(R.*R,2)); 13 | Rhat = R./nR; 14 | Rdotf = sum(R.*fsm,2); 15 | K1 = (1-27*nR/(32*a)+5*nR.^3/(64*a^3)).*fsm; 16 | K2 = (9/(32*a)-3*nR.^2/(64*a^3)).*Rdotf.*Rhat; 17 | small = 1/a^3*(K1+K2); 18 | smallds=wsm*small; 19 | 20 | % Two Stokeslet integrals 21 | int1 = zeros(1,3); 22 | if (t > 2*a) 23 | [s1,w1,~]=chebpts(Nup,[0 t-2*a],1); 24 | R1 = barymat(s1, s0, b0); 25 | X1 = R1*X0; 26 | f1 = R1*f0; 27 | R = P-X1; 28 | nR = sqrt(sum(R.*R,2)); 29 | Rdotf = sum(R.*f1,2); 30 | DoubIG = f1./nR.^3-3*Rdotf.*R./nR.^5; 31 | totIG = -1/2*DoubIG; 32 | int1=w1*totIG; 33 | end 34 | 35 | int2 = zeros(1,3); 36 | if (t < L-2*a) 37 | [s1,w1,~]=chebpts(Nup,[t+2*a L],1); 38 | R1 = barymat(s1,s0, b0); 39 | X1 = R1*X0; 40 | f1 = R1*f0; 41 | R = P-X1; 42 | nR = sqrt(sum(R.*R,2)); 43 | Rdotf = sum(R.*f1,2); 44 | DoubIG = f1./nR.^3-3*Rdotf.*R./nR.^5; 45 | totIG = -1/2*DoubIG; 46 | int2=w1*totIG; 47 | end 48 | U(iT,:)=smallds+int1+int2; 49 | end 50 | end -------------------------------------------------------------------------------- /Python/Dependencies/finufft/python_tests/demo1d1.py: -------------------------------------------------------------------------------- 1 | # convert DFM's simple demo to JFM interface, include modeord test. 2 | # Barnett 10/25/17. Adde upsampfac, 6/18/18 3 | 4 | import time 5 | import finufftpy 6 | import numpy as np 7 | 8 | # print finufftpy.nufft1d1.__doc__ 9 | 10 | np.random.seed(42) 11 | 12 | acc = 1.e-9 13 | iflag = 1 14 | N = int(1e6) 15 | M = int(1e5) 16 | x = np.random.uniform(-np.pi, np.pi, M) 17 | c = np.random.randn(M) + 1.j * np.random.randn(M) 18 | F = np.zeros([N], dtype=np.complex128) # allocate F (modes out) 19 | 20 | strt = time.time() 21 | status = finufftpy.nufft1d1(x, c, iflag, acc, N, F) 22 | print("Finished nufft in {0:.2g} seconds. Checking..." 23 | .format(time.time()-strt)) 24 | 25 | n = 142519 # mode to check 26 | Ftest = 0.0 27 | # this is so slow... 28 | for j in range(M): 29 | Ftest += c[j] * np.exp(n * x[j] * 1.j) 30 | Fmax = np.max(np.abs(F)) 31 | err = np.abs((F[n + N // 2] - Ftest) / Fmax) 32 | print("Error relative to max of F: {0:.2e}".format(err)) 33 | 34 | # now test FFT mode output version, overwriting F... 35 | strt = time.time() 36 | status = finufftpy.nufft1d1(x, c, iflag, acc, N, F, modeord=1) 37 | print("Finished nufft in {0:.2g} seconds (modeord=1)" 38 | .format(time.time()-strt)) 39 | err = np.abs((F[n] - Ftest) / Fmax) # now zero offset in F array 40 | print("Error relative to max of F: {0:.2e}".format(err)) 41 | 42 | # now test low-upsampfac (sigma) version... 43 | strt = time.time() 44 | status = finufftpy.nufft1d1(x, c, iflag, acc, N, F, upsampfac=1.25) 45 | print("Finished nufft in {0:.2g} seconds (upsampfac=1.25)" 46 | .format(time.time()-strt)) 47 | err = np.abs((F[n + N // 2] - Ftest) / Fmax) # now zero offset in F array 48 | print("Error relative to max of F: {0:.2e}".format(err)) 49 | -------------------------------------------------------------------------------- /Matlab/functions-solvers/TemporalIntegrator_TransDet.m: -------------------------------------------------------------------------------- 1 | Xt = XonNp1Mat*[Xst;XMP]; 2 | Xs3 = reshape(Xst,3,N)'; 3 | OneXMob = reshape(Xt,3,[])'; 4 | XsK = Xs3; 5 | if (impcoeff ==1/2) 6 | XtPrev = XonNp1Mat*[XstPrev;XMPPrev]; 7 | OneXMob = reshape(3/2*Xt-1/2*XtPrev,3,[])'; 8 | Xs3Prev = reshape(XstPrev,3,N)'; 9 | XsK = 3/2*Xs3-1/2*Xs3Prev; 10 | end 11 | % Mobility evaluation 12 | if (upsamp==1) 13 | Xup =RupsampleHydro*reshape(Xt,3,[])'; 14 | MRPY=getGrandMBlobs(NupsampleHydro,Xup,a,mu); 15 | MWsym = WTilde_Np1_Inverse*stackMatrix(RupsampleHydro)'... 16 | *WUp*MRPY*WUp*stackMatrix(RupsampleHydro)*WTilde_Np1_Inverse; 17 | elseif (upsamp==-1) 18 | MWsym = getGrandMBlobs(Nx,reshape(Xt,3,Nx)',a,mu); 19 | else 20 | Binput = AllbS_Np1; 21 | if (~exactRPY) 22 | Binput = AllbS_TrueFP_Np1; 23 | end 24 | M = TransTransMobilityMatrix(OneXMob,a,L,mu,sNp1,bNp1,DNp1,Binput,... 25 | AllbD_Np1,NForSmall,~exactRPY,deltaLocal,TransTransLDOnly); 26 | MWsym = 1/2*(M*WTilde_Np1_Inverse + WTilde_Np1_Inverse*M'); 27 | MWsym = FilterM(1/2*(MWsym+MWsym'),eigThres); 28 | end 29 | % Saddle pt solve 30 | if (rigid) 31 | K = KRigidonNp1(XsK,XonNp1Mat,I); 32 | else 33 | K = KonNp1(XsK,XonNp1Mat,I); 34 | end 35 | B = K-impcoeff*dt*MWsym*BendForceMat*K; 36 | Force = ForceExt+BendForceMat*Xt+MWsym \ U0; 37 | RHS = K'*Force; 38 | Schur = K'*(MWsym \ B); 39 | alphaU = pinv(Schur)*RHS; 40 | Lambda = MWsym \ (B*alphaU)-Force; 41 | if (rigid) 42 | Omega = repmat(alphaU(1:3)',N,1); 43 | else 44 | Omega = reshape(alphaU(1:3*N),3,N)'; 45 | end 46 | newXs = rotateTau(Xs3,Omega,dt); 47 | Xsp1 = reshape(newXs',[],1); 48 | XMP_p1 = XMP+dt*alphaU(end-2:end); 49 | Xp1 = XonNp1Mat*[Xsp1;XMP_p1]; 50 | Xp1Star = Xt+dt*K*alphaU; -------------------------------------------------------------------------------- /Matlab/functions-solvers/getCLforceEn.m: -------------------------------------------------------------------------------- 1 | % Compute the force density due to cross-linking. 2 | % Inputs - the links as an nLink x 4 matrix, where each row looks like 3 | % (Fib1, s1star, Fib2, s2star), and the configuration X 4 | % X is assumed to be an (nFib x N) x 3 configuration 5 | % N = number of points per fiber, s = arclength coordinates of the points 6 | % on the fiber, w = Chebyshev wts, L=fiber length, K = spring constant, 7 | % rl = rest length of the cross linkers, 8 | % Outputs - force per length on the fibers. 9 | function [Clf,X1stars,X2stars] = getCLforceEn(links,X,Runi, K, rls,g,Ld) 10 | [nLink,~]=size(links); 11 | Clf=zeros(size(X)); 12 | X1stars = zeros(nLink,3); 13 | X2stars = zeros(nLink,3); 14 | [Nu,N]=size(Runi); 15 | for iL=1:nLink 16 | rl = rls(iL); 17 | u1Pt = links(iL,1); 18 | fib1 = floor((u1Pt-1)/Nu)+1; 19 | fib1pt = mod(u1Pt,Nu); 20 | fib1pt = fib1pt+Nu*(fib1pt==0); 21 | u2Pt = links(iL,2); 22 | fib2 = floor((u2Pt-1)/Nu)+1; 23 | fib2pt = mod(u2Pt,Nu); 24 | fib2pt = fib2pt+Nu*(fib2pt==0); 25 | shift = links(iL,3:5); 26 | % Calculate the force density on fiber 1 27 | inds1 = (fib1-1)*N+1:fib1*N; 28 | inds2 = (fib2-1)*N+1:fib2*N; 29 | X1=X(inds1,:); 30 | X1star = Runi(fib1pt,:)*X1; 31 | X1stars(iL,:)=X1star; 32 | X2=X(inds2,:)-[shift(1)+g*shift(2) shift(2) shift(3)]*Ld; 33 | X2star = Runi(fib2pt,:)*X2; 34 | X2stars(iL,:)=X2star; 35 | prefac = (norm(X1star-X2star)-rl)*(X1star-X2star)/norm(X1star-X2star); 36 | R1 = Runi(fib1pt,:); 37 | Clf(inds1,:)=Clf(inds1,:)-K*prefac.*R1'; 38 | R2 = Runi(fib2pt,:); 39 | Clf(inds2,:)=Clf(inds2,:)+K*prefac.*R2'; 40 | end 41 | end -------------------------------------------------------------------------------- /Python/Dependencies/finufft/matlab/finufft1d3.m: -------------------------------------------------------------------------------- 1 | function [f ier] = finufft1d3(x,c,isign,eps,s,o) 2 | % FINUFFT1D3 3 | % 4 | % [f ier] = finufft1d3(x,c,isign,eps,s) 5 | % [f ier] = finufft1d3(x,c,isign,eps,s,opts) 6 | % 7 | % nj 8 | % f[k] = SUM c[j] exp(+-i s[k] x[j]), for k = 1, ..., nk 9 | % j=1 10 | % Inputs: 11 | % x location of NU sources in R (real line). 12 | % c size-nj double complex array of source strengths 13 | % s frequency locations of NU targets in R. 14 | % isign if >=0, uses + sign in exponential, otherwise - sign. 15 | % eps precision requested (>1e-16) 16 | % opts.debug: 0 (silent, default), 1 (timing breakdown), 2 (debug info). 17 | % opts.nthreads sets requested number of threads (else automatic) 18 | % opts.spread_sort: 0 (don't sort NU pts), 1 (do), 2 (auto, default) 19 | % opts.fftw: 0 (use FFTW_ESTIMATE, default), 1 (use FFTW_MEASURE) 20 | % opts.upsampfac: either 2.0 (default), or 1.25 (low RAM, smaller FFT size) 21 | % Outputs: 22 | % f size-nk double complex Fourier transform values at target 23 | % frequencies s 24 | % returned value - 0 if success, else: 25 | % 1 : eps too small 26 | % 2 : size of arrays to malloc exceed MAX_NF 27 | 28 | if nargin<6, o=[]; end 29 | opts = finufft_opts(o); 30 | nj=numel(x); 31 | nk=numel(s); 32 | if numel(c)~=nj, error('c must have the same number of elements as x'); end 33 | 34 | mex_id_ = 'o int = finufft1d3m(i double, i double[], i dcomplex[x], i int, i double, i double, i double[], o dcomplex[x], i double[])'; 35 | [ier, f] = finufft(mex_id_, nj, x, c, isign, eps, nk, s, opts, nj, nk); 36 | 37 | % ------------------------------------------------------------------------ 38 | -------------------------------------------------------------------------------- /Matlab/NumericalSBT/upsampleRPYRotTrans.m: -------------------------------------------------------------------------------- 1 | function Om = upsampleRPYRotTrans(Targs,starg,X0,f0,s0,b0,Nup,L,a) 2 | % Collocation pts 3 | Om = 0*Targs; 4 | for iT=1:length(Targs) 5 | t = starg(iT); 6 | P = Targs(iT,:); 7 | smallds = zeros(1,3); 8 | for iD=0:1 9 | dom = [t min(t+2*a,L)]; 10 | if (iD==0) 11 | dom=[max(t-2*a,0) t]; 12 | end 13 | [ssm,wsm,~]=chebpts(Nup,dom,1); 14 | Rsm = barymat(ssm, s0, b0); 15 | Xsm = Rsm*X0; 16 | fsm = Rsm*f0; 17 | R = P-Xsm; 18 | nR = sqrt(sum(R.*R,2)); 19 | FcrossR = cross(fsm,R); 20 | K1 = (1/a-3*nR/(8*a^2)).*FcrossR; 21 | small = 1/(2*a^2)*K1; 22 | smallds=smallds+wsm*small; 23 | end 24 | 25 | % Two Stokeslet integrals 26 | int1 = zeros(1,3); 27 | if (t > 2*a) 28 | [s1,w1,~]=chebpts(Nup,[0 t-2*a],1); 29 | R1 = barymat(s1, s0, b0); 30 | X1 = R1*X0; 31 | f1 = R1*f0; 32 | R = P-X1; 33 | nR = sqrt(sum(R.*R,2)); 34 | FCrossR = cross(f1,R); 35 | totIG = FCrossR./nR.^3; 36 | int1=w1*totIG; 37 | end 38 | 39 | int2 = zeros(1,3); 40 | if (t < L-2*a) 41 | [s1,w1,~]=chebpts(Nup,[t+2*a L],1); 42 | R1 = barymat(s1,s0, b0); 43 | X1 = R1*X0; 44 | f1 = R1*f0; 45 | R = P-X1; 46 | nR = sqrt(sum(R.*R,2)); 47 | FCrossR = cross(f1,R); 48 | totIG = FCrossR./nR.^3; 49 | int2=w1*totIG; 50 | end 51 | Om(iT,:)=smallds+int1+int2; 52 | end 53 | end -------------------------------------------------------------------------------- /Python/Dependencies/finufft/make.inc.macosx_gcc-8: -------------------------------------------------------------------------------- 1 | # Makefile variable overrides for Mac OSX compilation with GCC v.8.* 2 | # 3 | # Use this if you'll need to link against gfortran. 4 | # 5 | # Copy this file to make.inc, and if needed edit for your setup. 6 | # 7 | # Don't forget also to adjust g++ to g++-8 at start of setup.py 8 | # 9 | # Barnett 10/27/18. Input from Yu-Hsuan Shih, Amit Moskovich. 10 | 11 | # By default we use clang/LLVM (which is aliased to /usr/lib/gcc, etc). 12 | # If you want to override this, get gcc from brew then use, eg: 13 | CXX=g++-8 14 | CC=gcc-8 15 | FC=gfortran 16 | 17 | # (compile flags for use with GCC are as in linux makefile) 18 | CFLAGS += 19 | 20 | # If you're getting warning messages of the form: 21 | # ld: warning: object file (lib-static/libfinufft.a(finufft1d.o)) was built for 22 | # newer OSX version (10.13) than being linked (10.9) 23 | # Then you can uncomment the following two lines with the older version number 24 | # (in this example -mmacosx-version-min=10.9) 25 | # 26 | #CFLAGS += "-mmacosx-version-min=" 27 | 28 | # as in makefile, but with the brew /usr/local/ stuff... 29 | CFLAGS += -I src -I/usr/local/include 30 | FFLAGS = $(CFLAGS) 31 | CXXFLAGS = $(CFLAGS) -DNEED_EXTERN_C 32 | LIBS += -L/usr/local/lib 33 | 34 | # OpenMP with GCC on OSX needs following... 35 | OMPFLAGS = -fopenmp 36 | OMPLIBS = -lomp 37 | # since fftw3_omp doesn't work in OSX, we need... 38 | FFTWOMPSUFFIX=threads 39 | 40 | # MATLAB interface: 41 | # some of these will depend on your FFTW library location... 42 | MFLAGS += -I/usr/local/include -L/usr/local/lib -lm 43 | # edit for your MATLAB version location... 44 | MEX = $(shell ls -d /Applications/MATLAB_R201*.app)/bin/mex 45 | # Also see docs/install.rst for possible edits to MATLAB's MEX XML file. 46 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/fortran/finufft_f.h: -------------------------------------------------------------------------------- 1 | #ifndef FINUFFT_F_H 2 | #define FINUFFT_F_H 3 | 4 | #include "../src/utils.h" 5 | 6 | // note FLT (= float or double) and CPX (= float complex or double complex) 7 | // used here. Make sure you call with appropriate fortran sizes. 8 | // All ints are int*4 for now in fortran interface, all nufft_opts default. 9 | 10 | extern "C" { 11 | void finufft1d1_f_(int *nj,FLT* xj,CPX* cj,int *iflag, FLT *eps, 12 | int *ms, CPX* fk, int *ier); 13 | void finufft1d2_f_(int *nj,FLT* xj,CPX* cj,int *iflag, FLT *eps, 14 | int *ms, CPX* fk, int *ier); 15 | void finufft1d3_f_(int *nj,FLT* xj,CPX* cj,int *iflag, FLT *eps, 16 | int *nk, FLT* s, CPX* fk, int *ier); 17 | void finufft2d1_f_(int *nj,FLT* xj,FLT *yj,CPX* cj,int *iflag, 18 | FLT *eps, int *ms, int *mt, CPX* fk, int *ier); 19 | void finufft2d2_f_(int *nj,FLT* xj,FLT *yj,CPX* cj,int *iflag, 20 | FLT *eps, int *ms, int *mt, CPX* fk, int *ier); 21 | void finufft2d3_f_(int *nj,FLT* xj,FLT* yj, CPX* cj,int *iflag, 22 | FLT *eps, int *nk, FLT* s, FLT* t, CPX* fk, 23 | int *ier); 24 | void finufft3d1_f_(int *nj,FLT* xj,FLT *yj,FLT* zj,CPX* cj, 25 | int *iflag, FLT *eps, int *ms, int *mt, int *mu, 26 | CPX* fk, int *ier); 27 | void finufft3d2_f_(int *nj,FLT* xj,FLT *yj,FLT* zj,CPX* cj, 28 | int *iflag, FLT *eps, int *ms, int *mt, int *mu, 29 | CPX* fk, int *ier); 30 | void finufft3d3_f_(int *nj,FLT* xj,FLT* yj, FLT*zj, CPX* cj, 31 | int *iflag, FLT *eps, int *nk, FLT* s, FLT* t, 32 | FLT* u, CPX* fk, int *ier); 33 | void finufft2d1many_f_(int *ndata, int *nj,FLT* xj,FLT *yj,CPX* cj,int *iflag, 34 | FLT *eps, int *ms, int *mt, CPX* fk, int *ier); 35 | void finufft2d2many_f_(int *ndata, int *nj,FLT* xj,FLT *yj,CPX* cj,int *iflag, 36 | FLT *eps, int *ms, int *mt, CPX* fk, int *ier); 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /Python/Dependencies/NeighborSearch/nlistNew.py: -------------------------------------------------------------------------------- 1 | import uammd 2 | import numpy as np 3 | import timeit 4 | 5 | numberParticles = 13840 6 | lx = ly = lz = 32.0 7 | rcut = 1 8 | NperFiber = 1 # Number of particles in each fiber, 1 is the minimum and excludes self interactions 9 | nlist = uammd.NList() 10 | np.random.seed(1234) 11 | precision = np.float32 12 | positions = np.array(np.random.rand(numberParticles, 3), precision) 13 | positions[:, 0] *= lx 14 | positions[:, 1] *= ly 15 | positions[:, 2] *= lz 16 | useGPU = False 17 | for i in range(0, 10): 18 | nlist.updateList(pos=positions, 19 | Lx=lx, Ly=ly, Lz=lz, 20 | numberParticles=numberParticles, 21 | NperFiber=NperFiber, 22 | rcut=rcut, 23 | useGPU=useGPU) 24 | 25 | Ntest = 100 26 | start = timeit.default_timer() 27 | for i in range(0, Ntest): 28 | nlist.updateList(pos=positions, 29 | Lx=lx, Ly=ly, Lz=lz, 30 | numberParticles=numberParticles, 31 | NperFiber=NperFiber, 32 | rcut=rcut, 33 | useGPU=useGPU) 34 | 35 | elapsed = timeit.default_timer() - start 36 | 37 | print("Elapsed: "+str(elapsed*1000/Ntest)+" ms per test") 38 | 39 | npairs = int(len(nlist.pairList)/2) 40 | print("Found ", npairs, "pairs") 41 | i = 1 42 | # Reshape and sort the list to check for correctness more easily 43 | nl = nlist.pairList.reshape((npairs, 2)) 44 | for i in range(0, npairs): 45 | if nl[i, 0] > nl[i, 1]: 46 | a = nl[i, 0] 47 | nl[i, 0] = nl[i, 1] 48 | nl[i, 1] = a 49 | nl = np.sort(nl, axis=0) 50 | 51 | # Print some particle pairs 52 | for j in range(0, 10): 53 | ii = nl[j, 0] 54 | jj = nl[j, 1] 55 | print(ii, jj) 56 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | Welcome to SPHARCLE's documentation! 2 | ===================================== 3 | SPHARCLE stands for Slender Particle Hydrodynamics 4 | And Reacting Cytoskeletal Linking Elements. 5 | 6 | The theory behind this software can be found in the concluding publication: 7 | 1) A simulation platform for slender, semiflexible, and inextensible fibers with Brownian hydrodynamics and steric repulsion, 8 | by O. Maxian and A. Donev, November 2024. 9 | See also some other references: 10 | 2) An integral-based spectral method for inextensible slender fibers in Stokes flow, 11 | by O. Maxian, A. Mogilner, and A. Donev, January 2021. 12 | 3) Simulations of dynamically cross-linked actin networks: morphology, rheology, and hydrodynamic interactions, 13 | by O. Maxian, R. P. Peláez, A. Mogilner, and A. Donev, December 2021. 14 | 4) Interplay between Brownian motion and cross-linking controls bundling dynamics in actin networks, 15 | by O. Maxian, A. Donev, and A. Mogilner, April 2022. 16 | 5) The hydrodynamics of a twisting, bending, inextensible fiber in Stokes flow, by O. Maxian, B. Sprinkle, 17 | C.S. Peskin, and A. Donev, July 2022. 18 | 6) Bending fluctuations in semiflexible, inextensible, slender filaments in Stokes flow: towards a spectral discretization, 19 | by O. Maxian, B. Sprinkle, and A. Donev, April 2023. 20 | 7) `Hydrodynamics of transiently cross-linked actin networks: theory, numerics, and emergent behaviors `_ 21 | (Ondrej Maxian's PhD thesis) 22 | 23 | Contents: 24 | 25 | .. toctree:: 26 | :maxdepth: 1 27 | 28 | Installation 29 | Examples 30 | PythonClasses 31 | 32 | 33 | 34 | Indices and tables 35 | ================== 36 | 37 | * :ref:`genindex` 38 | * :ref:`modindex` 39 | * :ref:`search` 40 | 41 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/docs/refs.rst: -------------------------------------------------------------------------------- 1 | References 2 | ========== 3 | 4 | References for this software and the underlying mathematics include: 5 | 6 | [FIN] 7 | A parallel non-uniform fast Fourier transform library based on an ``exponential of semicircle'' kernel. 8 | A. H. Barnett, J. F. Magland, and L. af Klinteberg. 9 | SIAM J. Sci. Comput. 41(5), C479-C504 (2019). arxiv:1808.06736v2 10 | 11 | [B20] 12 | Aliasing error of the exp$(\beta \sqrt{1-z^2})$ kernel in the nonuniform fast Fourier transform. 13 | A. H. Barnett. submitted, Appl. Comput. Harmon. Anal. (2020) arxiv:2001.09405 14 | 15 | [ORZ] Prolate Spheroidal Wave Functions of Order Zero: Mathematical Tools for Bandlimited Approximation. A. Osipov, V. Rokhlin, and H. Xiao. Springer (2013). 16 | 17 | [KK] Chapter 7. System Analysis By Digital Computer. F. Kuo and J. F. Kaiser. Wiley (1967). 18 | 19 | [FS] Nonuniform fast Fourier transforms using min-max interpolation. 20 | J. A. Fessler and B. P. Sutton. IEEE Trans. Sig. Proc., 51(2):560-74, (Feb. 2003) 21 | 22 | [KKP] Using NFFT3---a software library for various nonequispaced fast Fourier transforms. J. Keiner, S. Kunis and D. Potts. Trans. Math. Software 36(4) (2009). 23 | 24 | [F] Non-equispaced fast Fourier transforms with applications to tomography. 25 | K. Fourmont. 26 | J. Fourier Anal. Appl. 27 | 9(5) 431-450 (2003). 28 | 29 | This code builds upon the CMCL NUFFT, and the Fortran wrappers are very similar to its interfaces. For that the following are references: 30 | 31 | [GL] Accelerating the Nonuniform Fast Fourier Transform. L. Greengard and J.-Y. Lee. SIAM Review 46, 443 (2004). 32 | 33 | [LG] The type 3 nonuniform FFT and its applications. J.-Y. Lee and L. Greengard. J. Comput. Phys. 206, 1 (2005). 34 | 35 | The original NUFFT analysis using truncated Gaussians is: 36 | 37 | [DR] Fast Fourier Transforms for Nonequispaced data. A. Dutt and V. Rokhlin. SIAM J. Sci. Comput. 14, 1368 (1993). 38 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/matlab/finufft1d2.m: -------------------------------------------------------------------------------- 1 | function [c ier] = finufft1d2(x,isign,eps,f,o) 2 | % FINUFFT1D2 3 | % 4 | % [c ier] = finufft1d2(x,isign,eps,f) 5 | % [c ier] = finufft1d2(x,isign,eps,f,opts) 6 | % 7 | % Type-2 1D complex nonuniform FFT. 8 | % 9 | % c[j] = SUM f[k1] exp(+/-i k1 x[j]) for j = 1,...,nj 10 | % k1 11 | % where sum is over -ms/2 <= k1 <= (ms-1)/2. 12 | % 13 | % Inputs: 14 | % x location of NU targets on interval [-3pi,3pi], length nj 15 | % f complex Fourier transform values 16 | % isign if >=0, uses + sign in exponential, otherwise - sign. 17 | % eps precision requested (>1e-16) 18 | % opts.debug: 0 (silent, default), 1 (timing breakdown), 2 (debug info). 19 | % opts.nthreads sets requested number of threads (else automatic) 20 | % opts.spread_sort: 0 (don't sort NU pts), 1 (do), 2 (auto, default) 21 | % opts.fftw: 0 (use FFTW_ESTIMATE, default), 1 (use FFTW_MEASURE) 22 | % opts.modeord: 0 (CMCL increasing mode ordering, default), 1 (FFT ordering) 23 | % opts.chkbnds: 0 (don't check NU points valid), 1 (do, default). 24 | % opts.upsampfac: either 2.0 (default), or 1.25 (low RAM, smaller FFT size) 25 | % Outputs: 26 | % c complex double array of nj answers at targets 27 | % ier - 0 if success, else: 28 | % 1 : eps too small 29 | % 2 : size of arrays to malloc exceed MAX_NF 30 | % other codes: as returned by cnufftspread 31 | 32 | if nargin<5, o=[]; end 33 | opts = finufft_opts(o); 34 | nj=numel(x); 35 | ms=numel(f); 36 | % c = complex(zeros(nj,1)); % todo: change all output to inout & prealloc... 37 | 38 | mex_id_ = 'o int = finufft1d2m(i double, i double[], o dcomplex[x], i int, i double, i double, i dcomplex[], i double[])'; 39 | [ier, c] = finufft(mex_id_, nj, x, isign, eps, ms, f, opts, nj); 40 | 41 | % --------------------------------------------------------------------------- 42 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/devel/gen_ker_horner_C_code.m: -------------------------------------------------------------------------------- 1 | function str = gen_ker_horner_C_code(w,d,be,o) 2 | % GEN_KER_HORNER_C_CODE Write C code strings for Horner eval of ES kernel 3 | % 4 | % str = gen_ker_horner_C_code(w,d,be,o) 5 | % 6 | % Inputs: 7 | % w = integer kernel width in grid points, eg 10 8 | % d = poly degree to keep, eg 13 9 | % beta = kernel parameter, around 2.3*w 10 | % opts - optional struct (unused; could switch to cosh kernel variant, etc..) 11 | % 12 | % Outputs: 13 | % str = length-w cell array of C code strings to eval each segment of kernel 14 | % 15 | % Also see: KER_PPVAL_COEFF_MAT, FIG_SPEED_KER_PPVAL (which tests acc too) 16 | % 17 | % Note: # flops is same as filling a col vec of [1;z;z^2;..] & doing small BLAS2 18 | % but that might be a bit faster; not sure. Stuck to simple Horner for now, 19 | % not exploiting that there are w calls to different poly's w/ *same* z arg. 20 | 21 | % Barnett 4/23/18. 22 | if nargin==0, test_gen_ker_horner_C_code; return; end 23 | if nargin<4, o=[]; end 24 | 25 | C = ker_ppval_coeff_mat(w,d,be,o); 26 | str = cell(w,1); 27 | for i=1:w % loop over segments of kernel 28 | s = sprintf('ker[%d] = ',i-1); 29 | for n=1:d 30 | s = [s sprintf('%.16E + z*(',C(n,i))]; % (n-1)th coeff for i'th segment 31 | end 32 | s = [s sprintf('%.16E)',C(end,i))]; 33 | for n=1:d-1, s = [s sprintf(')')]; end % close all parens 34 | s = [s sprintf(';\n')]; % terminate the C line, CR 35 | str{i} = s; 36 | end 37 | 38 | %%%%%%%% 39 | function test_gen_ker_horner_C_code % writes C code to file but doesn't test. 40 | w=13; d=15; % pick a single kernel width and degree to write code for 41 | %w=7; d=10; 42 | %w=2; d=5; 43 | beta=2.3*w; 44 | str = gen_ker_horner_C_code(w,d,beta); 45 | % str{:} 46 | fnam = sprintf('ker_horner_w%d.c',w); 47 | fid = fopen(fnam,'w'); 48 | for i=1:numel(str); fwrite(fid,str{i}); end 49 | fclose(fid); 50 | system(['more ' fnam]) 51 | -------------------------------------------------------------------------------- /Matlab/functions-solvers/precomputeStokesletInts.m: -------------------------------------------------------------------------------- 1 | % Precomputes the integrals 2 | % int_D (eta'-eta)/abs(eta'-eta)*T_k(eta') deta' 3 | % involved in the nearly singular quadratures for the Stokeslet. 4 | % See Appendix F of the paper. 5 | % chebpoly = 0 for monomials (analytical solution exists), chebpoly=1 for 6 | % Chebyshev polynomials 7 | function Allbs = precomputeStokesletInts(s0,L,a,N,chebpoly) 8 | k=0:N-1; 9 | sscale=-1+2*s0/L; 10 | AllQs = zeros(N); 11 | for iPt=1:N 12 | s = s0(iPt); 13 | eta = sscale(iPt); 14 | sLow = max(s-2*a,0); 15 | sHi = min(s+2*a,L); 16 | etaLow = -1+2*sLow/L; 17 | etaHi = -1+2*sHi/L; 18 | % Compute integrals numerically to high accuracy 19 | q = zeros(1,N); 20 | for kk=k 21 | if (chebpoly) 22 | if (etaLow > -1) 23 | [n,w]=chebpts(200,[-1 etaLow],1); 24 | poly = n.^kk; 25 | if (chebpoly) 26 | poly = cos(kk*acos(n)); 27 | end 28 | q(kk+1)=w*((n-eta)./abs(n-eta).*poly); 29 | end 30 | if (etaHi < 1) 31 | [n,w]=chebpts(200,[etaHi 1],1); 32 | poly = n.^kk; 33 | if (chebpoly) 34 | poly = cos(kk*acos(n)); 35 | end 36 | q(kk+1)=q(kk+1)+w*((n-eta)./abs(n-eta).*poly); 37 | end 38 | else 39 | % Monomials - can do the integrals analytically 40 | q(kk+1) = -1./(kk+1).*(etaLow.^(kk+1)-(-1).^(kk+1))+1./(kk+1).*(1-etaHi.^(kk+1)); 41 | end 42 | end 43 | AllQs(iPt,:)=q; 44 | end 45 | PolyMat = fliplr(vander(sscale))'; 46 | if (chebpoly) 47 | PolyMat = cos(k.*acos(sscale))'; 48 | end 49 | Allbs= mldivide(PolyMat,AllQs'); 50 | end -------------------------------------------------------------------------------- /Python/Dependencies/finufft/docs/pythoninterface.rst: -------------------------------------------------------------------------------- 1 | Python interface 2 | ================ 3 | 4 | These python interfaces are by Daniel Foreman-Mackey, Jeremy Magland, and Alex Barnett, with help from David Stein. 5 | See the installation notes for how to install these interfaces; the main thing to remember is to compile the library before trying to `pip install`. Below is the documentation for the nine routines. The 2d1 and 2d2 6 | "many vector" interfaces are now also included. 7 | 8 | Notes: 9 | 10 | #. The module has been designed not to recompile the C++ library; rather, it links to the existing static library. Therefore this library must have been compiled before building python interfaces. 11 | 12 | #. In the below, "float" and "complex" refer to double-precision for the default library. One can compile the library for single-precision, but the python interfaces are untested in this case. 13 | 14 | #. NumPy input and output arrays are generally passed directly without copying, which helps efficiency in large low-accuracy problems. In 2D and 3D, copying is avoided when arrays are Fortran-ordered; hence choose this ordering in your python code if you are able (see ``python_tests/accuracy_speed_tests.py``). 15 | 16 | #. Fortran-style writing of the output to a preallocated NumPy input array is used. That is, such an array is treated as a pointer into which the output is written. This avoids creation of new arrays. The python call return value is merely a status indicator. 17 | 18 | .. autofunction:: finufftpy.nufft1d1 19 | .. autofunction:: finufftpy.nufft1d2 20 | .. autofunction:: finufftpy.nufft1d3 21 | .. autofunction:: finufftpy.nufft2d1 22 | .. autofunction:: finufftpy.nufft2d1many 23 | .. autofunction:: finufftpy.nufft2d2 24 | .. autofunction:: finufftpy.nufft2d2many 25 | .. autofunction:: finufftpy.nufft2d3 26 | .. autofunction:: finufftpy.nufft3d1 27 | .. autofunction:: finufftpy.nufft3d2 28 | .. autofunction:: finufftpy.nufft3d3 29 | -------------------------------------------------------------------------------- /Matlab/MainPrograms/Filopodium/PlotTraj.m: -------------------------------------------------------------------------------- 1 | %% Plotting a movie 2 | iTrial=1; 3 | AllLfacs = AllExtensions{iTrial}; 4 | Xpts = AllPositions{iTrial}; 5 | nLinksT = AllnLinks{iTrial}; 6 | AllLinks = AllLinksConfs{iTrial}; 7 | Thetass = AllAngles{iTrial}; 8 | D1s = AllMatFrames{iTrial}; 9 | %f=figure; 10 | %f.Position = [100 100 1000 1000]; 11 | savedt=saveEvery*dt; 12 | tmovies = 0:0.01:2; 13 | %tmovies = [0 0.01 0.02 0.04 0.06 0.08 0.1 0.15 0.2 0.3]; 14 | nSaves = length(nLinksT); 15 | for iT=nSaves 16 | %subplot(2,3,iT) 17 | nexttile 18 | saveIndex=iT;%tmovies(iT)/(savedt)+1; 19 | linkEnd = sum(nLinksT(1:saveIndex)); 20 | nLinks = nLinksT(saveIndex); 21 | links=AllLinks(linkEnd-nLinks+1:linkEnd,:); 22 | PtsThisT = Xpts((saveIndex-1)*nFib*Nx+1:saveIndex*nFib*Nx,:); 23 | D1sThisT = D1s((saveIndex-1)*nFib*N+1:saveIndex*nFib*N,:); 24 | for iFib=1:nFib 25 | fibInds = (iFib-1)*Nx+1:iFib*Nx; 26 | plot3(RplNp1*PtsThisT(fibInds,1),RplNp1*PtsThisT(fibInds,2),... 27 | RplNp1*PtsThisT(fibInds,3)); 28 | hold on 29 | FramePts = RNp1ToN*PtsThisT(fibInds,:); 30 | FrameToPlot = D1((iFib-1)*N+1:iFib*N,:); 31 | %set(gca,'ColorOrderIndex',iFib) 32 | %quiver3(FramePts(:,1),FramePts(:,2),FramePts(:,3),... 33 | % FrameToPlot(:,1),FrameToPlot(:,2),FrameToPlot(:,3),0.25,'LineWidth',1.0); 34 | end 35 | [nLinks,~]=size(links); 36 | [~,X1stars,X2stars] = getCLforceEn(links,PtsThisT,Runi,KCL, zeros(nLinks,1),0,0); 37 | for iLink=1:nLinks 38 | linkPts = [X1stars(iLink,:); X2stars(iLink,:)]; 39 | plot3(linkPts(:,1),linkPts(:,2),linkPts(:,3),':ko'); 40 | end 41 | %xlim([-0.25 0.5]) 42 | % ylim([-0.6 0.4]) 43 | %zlim([-0.5 0.9]) 44 | PlotAspect 45 | %view([ -59.1403 5.5726]) 46 | view([-109.5316 19.7340]) 47 | title(strcat('$t=$',num2str(tmovies(iT)))) 48 | hold off 49 | %movieframes(iT)=getframe(f); 50 | end 51 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/matlab/big1dtest.m: -------------------------------------------------------------------------------- 1 | % Explore large problems: timing, RAM usage, matlab interface. 2 | % Barnett 3/28/17 3 | clear 4 | isign = +1; % sign of imaginary unit in exponential 5 | eps = 1e-3; % requested accuracy 6 | o.debug = 1; % choose 1 for timing breakdown text output 7 | o.nthreads = 12; % omit, or use 0, to use default num threads (matlab chooses 8 | % equal to # physical cores, not # logical cores) 9 | o.spread_sort=0; 10 | M = 2.2e9; % # of NU pts - when >=2e31, answer is wrong, zero *** 11 | N = 1e6; % # of modes (approx total, used in all dims) 12 | 13 | j = ceil(0.93*M); % target pt index to test 14 | 15 | if 0 16 | fprintf('generating x & c data (single-threaded and slow)...\n') 17 | x = pi*(2*rand(1,M)-1); 18 | c = randn(1,M)+1i*randn(1,M); 19 | fprintf('1D type 1: using %d modes...\n',N) 20 | tic; 21 | [f ier] = finufft1d1(x,c,isign,eps,N,o); 22 | fprintf('done in %.3g s, ier=%d\n',toc,ier) 23 | if ~ier 24 | nt = ceil(0.37*N); % pick a mode index 25 | fe = sum(c.*exp(1i*isign*nt*x)); % exact 26 | of1 = floor(N/2)+1; % mode index offset 27 | fprintf('rel err in F[%d] is %.3g\n',nt,abs((fe-f(nt+of1))/fe)) 28 | end 29 | end 30 | 31 | if 1 32 | fprintf('generating x data (single-threaded and slow)...\n') 33 | x = pi*(2*rand(1,M)-1); 34 | f = randn(1,N)+1i*randn(1,N); 35 | fprintf('1D type 2: using %d modes...\n',N) 36 | tic 37 | [c ier] = finufft1d2(x,isign,eps,f,o); % Out of memory iff >=2^31 38 | fprintf('done in %.3g s, ier=%d\n',toc,ier) 39 | ms=numel(f); mm = ceil(-ms/2):floor((ms-1)/2); % mode index list 40 | ce = sum(f.*exp(1i*isign*mm*x(j))); % crucial f, mm same shape 41 | fprintf('1D type-2: rel err in c[%d] is %.3g\n',j,abs((ce-c(j))/ce)) 42 | end 43 | 44 | % conclusion: we get zeros output if >=2^31. Fix this issue w/ mex interface. 45 | -------------------------------------------------------------------------------- /Matlab/BrownianFlucts/RandomPolymerization.m: -------------------------------------------------------------------------------- 1 | deltaP = 0.1; 2 | Lfac = 1+deltaP/L; 3 | % Extend the last tangent vector 4 | TauLast = barymat(L,s,b)*reshape(Xst,3,[])'; 5 | X3 = reshape(Xt,3,[])'; 6 | XLast = barymat(L,sNp1,bNp1)*X3; 7 | Xadded = TauLast/norm(TauLast)*deltaP+XLast; 8 | 9 | % Assuming you can reuse the same grid (later can regenerate grid) 10 | s = Lfac*s; 11 | w = Lfac*w; 12 | sNp1 =Lfac*sNp1; 13 | wNp1 = Lfac*wNp1; 14 | DNp1 = DNp1/Lfac; 15 | IntDNp1 = IntDNp1*Lfac; 16 | XonNp1Mat = [(eye(3*(N+1))-repmat(BMNp1,N+1,1))*... 17 | stackMatrix(IntDNp1*RToNp1) I]; 18 | InvXonNp1Mat = [stackMatrix(RNp1ToN*DNp1); BMNp1]; 19 | % Bending energy matrix (2N+2 grid) 20 | s2Np2 = Lfac*s2Np2; 21 | w2Np2 = Lfac*w2Np2; 22 | W2Np2 = diag(w2Np2); 23 | D2Np2 = D2Np2/Lfac; 24 | WTilde_Np1 = WTilde_Np1*Lfac; 25 | WTilde_Np1_Inverse = WTilde_Np1_Inverse/Lfac; 26 | BendingEnergyMatrix_Np1 = BendingEnergyMatrix_Np1/Lfac^3; 27 | BendForceMat = -BendingEnergyMatrix_Np1; 28 | BendMatHalf_Np1 = BendMatHalf_Np1/Lfac^(3/2); 29 | L = L*Lfac; 30 | eps = rtrue/L; 31 | MobConst = -log(eps^2)/(8*pi*mu); 32 | 33 | 34 | PositionsToMatch = [sNp1/Lfac; L]; 35 | Rnew = stackMatrix(barymat(PositionsToMatch,sNp1,bNp1)); 36 | % Fill in what you know 37 | ErrorNew=@(NewDOF) (Rnew*NewPos(NewDOF,XonNp1Mat,Tau0BC',XTrk,N) - [Xt;Xadded']); 38 | [azimuth,elevation,r] = cart2sph(Xst(4:3:end),Xst(5:3:end),Xst(6:3:end)); 39 | x0=[azimuth;elevation]; 40 | NewDOFs = lsqnonlin(ErrorNew,x0,[-pi*ones(N-1,1); -pi/2*ones(N-1,1)],... 41 | [pi*ones(N-1,1); pi/2*ones(N-1,1)]); 42 | % Get new Tau's 43 | X = NewPos(NewDOFs,XonNp1Mat,Tau0BC',XTrk,N); 44 | TausTrk = XonNp1Mat \ X; 45 | Xt = X; 46 | Xst = TausTrk(1:3*N); 47 | 48 | function X = NewPos(DOFs,XonNp1Mat,Tau0,XTrk,N) 49 | azimuth = DOFs(1:N-1); 50 | elevation = DOFs(N:2*N-2); 51 | r = ones(N-1,1); 52 | [x,y,z] = sph2cart(azimuth,elevation,r); 53 | tau3 = [Tau0;[x y z]]; 54 | X = XonNp1Mat*[reshape(tau3',[],1);XTrk]; 55 | end 56 | -------------------------------------------------------------------------------- /Matlab/functions-solvers/StokesletFinitePartMatrix.m: -------------------------------------------------------------------------------- 1 | % 3N x 3N Matrix for the remaining Stokeslet contribution to the RPY 2 | % trans-trans mobility. Specifically, the integral of the Stokeslet is 3 | % written as int_D = M_stokeslet,loc + M_stokeslet, nonloc 4 | % This is the nonlocal part of that matrix. It uses the precomputed 5 | % integrals "Allbs" that are precomputed in precomputeStokesletInts.m 6 | function FPMat = StokesletFinitePartMatrix(X,Xs,Xss,D,s,L,N,mu,Allbs) 7 | FPMatrix = Allbs'; 8 | ActualFPMat = zeros(3*N); 9 | DfPart = zeros(3*N); 10 | for iPt=1:N 11 | indsi = 3*iPt-2:3*iPt; 12 | nXs = norm(Xs(iPt,:)); 13 | XsDotXss = dot(Xs(iPt,:),Xss(iPt,:)); 14 | Xshat = Xs(iPt,:)/nXs; 15 | for jPt=1:N 16 | indsj = 3*jPt-2:3*jPt; 17 | if (iPt==jPt) 18 | % Diagonal block 19 | DiagPart1 = 0.5*(Xs(iPt,:)'*Xss(iPt,:)+Xss(iPt,:)'*Xs(iPt,:))/nXs^3 ... 20 | - XsDotXss/(2*nXs^3)*eye(3)-3*XsDotXss/(2*nXs^5)*Xs(iPt,:)'*Xs(iPt,:); 21 | ActualFPMat(indsi,indsi) =ActualFPMat(indsi,indsi)+... 22 | DiagPart1*FPMatrix(iPt,iPt); 23 | % Derivative part 24 | DfPart(indsi,indsi) = (eye(3)+Xshat'*Xshat)/nXs*FPMatrix(iPt,iPt); 25 | else 26 | rvec = X(iPt,:)-X(jPt,:); 27 | r = norm(rvec); 28 | oneoverr = 1.0/r; 29 | ds = s(jPt)-s(iPt); 30 | oneoverds = 1.0/ds; 31 | ActualFPMat(indsi,indsj) = (eye(3) + rvec'*rvec*oneoverr^2)... 32 | *oneoverr*abs(ds)*oneoverds*FPMatrix(iPt,jPt); 33 | ActualFPMat(indsi,indsi)=ActualFPMat(indsi,indsi)-... 34 | (eye(3)+Xshat'*Xshat)*oneoverds/nXs*FPMatrix(iPt,jPt); 35 | end 36 | end 37 | end 38 | FPMat = 1/(8*pi*mu)*0.5*L*(ActualFPMat+DfPart*stackMatrix(D)); 39 | end -------------------------------------------------------------------------------- /Matlab/functions-solvers/linequad/matlabcheb/recursions/coeffs_I5.m: -------------------------------------------------------------------------------- 1 | function coeffs = coeffs_I5(Ns) 2 | % Power series coeffs for p=5, k=0 3 | % 4 | % TODO: Derive closed form expression 5 | % 6 | % Precomputed up to Ns=50 using Mathematica 7 | coeffs = [5/12,-(35/64),21/32,-(385/512),429/512,-(15015/16384),12155/12288,-(138567/131072),146965/131072,-(7436429/6291456),1300075/1048576,-(21729825/16777216),22621305/16777216,-(1502700975/1073741824),194467185/134217728,-(12856441675/8589934592),13254473925/8589934592,-(218257003965/137438953472),112137057175/68719476736,-(1841086593255/1099511627776),1886827875075/1099511627776,-(61807907059275/35184372088832),15801325804719/8796093022208,-(516581805154275/281474976710656),1581888283339091/844424930131968,-(8604776925855495/4503599627370496),4384809697849735/2251799813685248,-(214354554086311331/108086391056891904),72723180196134545/36028797018963968,-(9468558061536717759/4611686018427387904),601619036168022145/288230376151711744,-(78245864056911586035/36893488147419103232),79465280120136182181/36893488147419103232,-(3871984727422321818035/1770887431076116955136),654798961625859828687/295147905179352825856,-(10626123500068777921675/4722366482869645213696),32320205157173850518525/14167099448608935641088,-(349398428383342573500265/151115727451828646838272),88496787676831608672675/37778931862957161709568,-(2868138747278647279172505/1208925819614629174706176),2903929474697893019468475/1208925819614629174706176,-(47028572142185358380223225/19342813113834066795298816),23793784045064323438882965/9671406556917033397649408,-(385120733851930452498915975/154742504910672534362390528),389490898207697039193939135/154742504910672534362390528,-(25204012470976337391317945475/9903520314283042199192993792),3184701532372607112841303575/1237940039285380274899124224,-(205986495113860228058575515231/79228162514264337593543950336),208129611909762735433334604225/79228162514264337593543950336,-(3364014927267641997634789772289/1267650600228229401496703205376)]; 8 | coeffs = coeffs(1:Ns); 9 | end -------------------------------------------------------------------------------- /Python/Dependencies/finufft/matlab/finufft2d3.m: -------------------------------------------------------------------------------- 1 | function [f ier] = finufft2d3(x,y,c,isign,eps,s,t,o) 2 | % FINUFFT2D3 3 | % 4 | % [f ier] = finufft2d3(x,y,c,isign,eps,s,t) 5 | % [f ier] = finufft2d3(x,y,c,isign,eps,s,t,opts) 6 | % 7 | % nj 8 | % f[k] = SUM c[j] exp(+-i (s[k] x[j] + t[k] y[j])), for k = 1, ..., nk 9 | % j=1 10 | % Inputs: 11 | % x,y location of NU sources in R^2, each length nj. 12 | % c size-nj double complex array of source strengths 13 | % s,t frequency locations of NU targets in R^2. 14 | % isign if >=0, uses + sign in exponential, otherwise - sign. 15 | % eps precision requested (>1e-16) 16 | % opts.debug: 0 (silent, default), 1 (timing breakdown), 2 (debug info). 17 | % opts.nthreads sets requested number of threads (else automatic) 18 | % opts.spread_sort: 0 (don't sort NU pts), 1 (do), 2 (auto, default) 19 | % opts.fftw: 0 (use FFTW_ESTIMATE, default), 1 (use FFTW_MEASURE) 20 | % opts.upsampfac: either 2.0 (default), or 1.25 (low RAM, smaller FFT size) 21 | % Outputs: 22 | % f size-nk double complex Fourier transform values at target 23 | % frequencies s,t 24 | % returned value - 0 if success, else: 25 | % 1 : eps too small 26 | % 2 : size of arrays to malloc exceed MAX_NF 27 | 28 | if nargin<8, o=[]; end 29 | opts = finufft_opts(o); 30 | nj=numel(x); 31 | nk=numel(s); 32 | if numel(y)~=nj, error('y must have the same number of elements as x'); end 33 | if numel(c)~=nj, error('c must have the same number of elements as x'); end 34 | if numel(t)~=nk, error('t must have the same number of elements as s'); end 35 | 36 | mex_id_ = 'o int = finufft2d3m(i double, i double[], i double[], i dcomplex[x], i int, i double, i double, i double[], i double[], o dcomplex[x], i double[])'; 37 | [ier, f] = finufft(mex_id_, nj, x, y, c, isign, eps, nk, s, t, opts, nj, nk); 38 | 39 | % ------------------------------------------------------------------------ 40 | -------------------------------------------------------------------------------- /Matlab/functions-solvers/DoubletFinitePartMatrix.m: -------------------------------------------------------------------------------- 1 | % 3N x 3N Matrix for the remaining doublet contribution to the RPY 2 | % trans-trans mobility. Specifically, the integral of the doublet is 3 | % written as int_D = M_doub,loc + M_doub, nonloc 4 | % This is the nonlocal part of that matrix. It uses the precomputed 5 | % integrals "Allbs" that are precomputed in precomputeDoubletInts.m 6 | function FPMat = DoubletFinitePartMatrix(X,Xs,Xss,D,s,L,N,mu,Allbs) 7 | FPMatrix = Allbs'; 8 | ActualFPMat = zeros(3*N); 9 | DfPart = zeros(3*N); 10 | for iPt=1:N 11 | indsi = 3*iPt-2:3*iPt; 12 | nXs = norm(Xs(iPt,:)); 13 | XsDotXss = dot(Xs(iPt,:),Xss(iPt,:)); 14 | Xshat = Xs(iPt,:)/nXs; 15 | M1 = Xshat'*Xshat; 16 | M2 = 1/2*(Xs(iPt,:)'*Xss(iPt,:)+Xss(iPt,:)'*Xs(iPt,:)); 17 | for jPt=1:N 18 | indsj = 3*jPt-2:3*jPt; 19 | if (iPt==jPt) 20 | % Diagonal block 21 | DiagPart1 = -3*M2/nXs^5 - 3*XsDotXss/(2*nXs^5)*eye(3)... 22 | +15*XsDotXss/(2*nXs^7)*Xs(iPt,:)'*Xs(iPt,:); 23 | ActualFPMat(indsi,indsi) = ActualFPMat(indsi,indsi)+... 24 | DiagPart1*FPMatrix(iPt,iPt); 25 | % Derivative part 26 | DfPart(indsi,indsi) = (eye(3)-3*M1)/nXs^3*FPMatrix(iPt,iPt); 27 | else 28 | rvec = X(iPt,:)-X(jPt,:); 29 | r = norm(rvec); 30 | oneoverr = 1.0/r; 31 | ds = s(jPt)-s(iPt); 32 | oneoverds = 1.0/ds; 33 | ActualFPMat(indsi,indsj) = (eye(3) -3*(rvec'*rvec)*oneoverr^2)... 34 | *oneoverr^3*abs(ds)^3*oneoverds*FPMatrix(iPt,jPt); 35 | ActualFPMat(indsi,indsi)=ActualFPMat(indsi,indsi)-... 36 | (eye(3)-3*M1)/nXs^3*oneoverds*FPMatrix(iPt,jPt); 37 | end 38 | end 39 | end 40 | FPMat = 1/(8*pi*mu)*2/L*(ActualFPMat+DfPart*stackMatrix(D)); 41 | end -------------------------------------------------------------------------------- /Matlab/BrownianFlucts/MCMC/MakeMCMCEEFig.m: -------------------------------------------------------------------------------- 1 | names = ["SpecMCMCFreeL1_ConstKbT_N12_Lp2.mat" ]; 2 | for iName = 1:length(names) 3 | load(names(iName)) 4 | plotIndex=iName; 5 | nbins = 100; 6 | %AllEndToEndDists = AllEndToQuarterDists; 7 | %L = L; 8 | histedges=(0:nbins)*L/nbins; 9 | NumPerBin = 1000/nbins; 10 | dshist = histedges(2)-histedges(1); 11 | histmps = (histedges(1:end-1)+histedges(2:end))/2; 12 | ChebHistCounts = zeros(nTrial,length(histedges)-1); 13 | nSaveSamples=sum(AllEndToEndDists(1,:)); 14 | for iTrial=1:nTrial 15 | if (NumPerBin > 1) 16 | ChebHistCounts(iTrial,:) = sum(reshape(AllEndToEndDists(iTrial,:),NumPerBin,[]))/... 17 | (nSaveSamples*dshist); 18 | else 19 | ChebHistCounts(iTrial,:) = AllEndToEndDists(iTrial,:)/(nSaveSamples*dshist); 20 | end 21 | end 22 | if (plotIndex==length(names)) 23 | h(length(h)+1)=plot(histmps/L,mean(L*ChebHistCounts),'k'); 24 | else 25 | set(gca,'ColorOrderIndex',plotIndex) 26 | h(plotIndex)=plot(histmps/L,mean(L*ChebHistCounts)); 27 | end 28 | hold on 29 | errorBarEvery=2; 30 | if (plotIndex==length(names)) 31 | errorbar(histmps(plotIndex:errorBarEvery:end)/L,... 32 | mean(L*ChebHistCounts(:,plotIndex:errorBarEvery:end)),... 33 | 2*std(L*ChebHistCounts(:,plotIndex:errorBarEvery:end))/sqrt(nTrial),'ko','LineWidth',2.0,... 34 | 'MarkerSize',1); 35 | else 36 | set(gca,'ColorOrderIndex',plotIndex) 37 | errorbar(histmps(plotIndex:errorBarEvery:end)/L,... 38 | mean(L*ChebHistCounts(:,plotIndex:errorBarEvery:end)),... 39 | 2*std(L*ChebHistCounts(:,plotIndex:errorBarEvery:end))/sqrt(nTrial),'o','LineWidth',2.0,... 40 | 'MarkerSize',1); 41 | hold on 42 | end 43 | if (iName==length(names)-1 && L ==2)% Theory curve 44 | dr=1e-5; 45 | r = (0.5:1/dr)'*dr; 46 | G = zeros(length(r),1); 47 | for ell=1:3 48 | G=G+1./(lpstar*(1-r)).^(3/2).*exp(-(ell-1/2)^2./(lpstar*(1-r))).*... 49 | (4*((ell-1/2)./sqrt(lpstar*(1-r))).^2-2); 50 | end 51 | % Estimate integral of G, normalize to 1 52 | G=G.*r.^2; 53 | G = G/sum(G*dr); 54 | h(length(h)+1)=plot(r,G); 55 | end 56 | end -------------------------------------------------------------------------------- /Python/Dependencies/finufft/README.md: -------------------------------------------------------------------------------- 1 | # Flatiron Institute Nonuniform Fast Fourier Transform libraries: FINUFFT 2 | 3 | **Alex H. Barnett and Jeremy F. Magland**, with additional code by 4 | Ludvig af Klinteberg and Yu-hsuan "Melody" Shih. 5 | 6 |

7 | 8 | 9 |

10 | 11 | This is a lightweight library to compute the three standard types of nonuniform FFT to a specified precision, in one, two, or three dimensions. It is written in C++ with interfaces to C, Fortran, MATLAB/octave, and python. A julia interface 12 | also exists. 13 | 14 | Please see the [online documentation](http://finufft.readthedocs.io/en/latest/index.html), or its equivalent, the [user manual](finufft-manual.pdf). 15 | You will also want to see example codes in the directories 16 | `examples`, `test`, `fortran`, `matlab`, and `python_tests`. 17 | If you cannot compile, try our [precompiled binaries](http://users.flatironinstitute.org/~ahb/codes/finufft-binaries). 18 | 19 | If you prefer to read text files, the source to generate the above documentation is in human-readable (mostly .rst) files as follows: 20 | 21 | - `docs/install.rst` : installation and compilation instructions 22 | - `docs/math.rst` : mathematical definitions 23 | - `docs/dirs.rst` : explanation of directories and files in the package 24 | - `docs/usage.rst` : interfaces from C++, C and Fortran, notes on parameters 25 | - `docs/matlabhelp.raw` : MATLAB/octave interfaces 26 | - `finufftpy/_interfaces.py` : python interface docstrings 27 | - `docs/related.rst` : packages using FINUFFT 28 | - `docs/issues.rst` : known issues and bug reports 29 | - `docs/refs.rst` : journal article references 30 | - `docs/ackn.rst` : acknowledgments 31 | 32 | If you find FINUFFT useful in your work, please cite this code and 33 | our paper: 34 | 35 | A parallel non-uniform fast Fourier transform library based on an ``exponential of semicircle'' kernel. 36 | A. H. Barnett, J. F. Magland, and L. af Klinteberg. 37 | SIAM J. Sci. Comput. 41(5), C479-C504 (2019). 38 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/matlab/finufft1d1.m: -------------------------------------------------------------------------------- 1 | function [f ier] = finufft1d1(x,c,isign,eps,ms,o) 2 | % FINUFFT1D1 3 | % 4 | % [f ier] = finufft1d1(x,c,isign,eps,ms) 5 | % [f ier] = finufft1d1(x,c,isign,eps,ms,opts) 6 | % 7 | % Type-1 1D complex nonuniform FFT. 8 | % 9 | % nj 10 | % f(k1) = SUM c[j] exp(+/-i k1 x(j)) for -ms/2 <= k1 <= (ms-1)/2 11 | % j=1 12 | % Inputs: 13 | % x location of sources on interval [-3pi,3pi], length nj 14 | % c size-nj complex array of source strengths 15 | % isign if >=0, uses + sign in exponential, otherwise - sign. 16 | % eps precision requested (>1e-16) 17 | % ms number of Fourier modes computed, may be even or odd; 18 | % in either case the mode range is integers lying in [-ms/2, (ms-1)/2] 19 | % opts.debug: 0 (silent, default), 1 (timing breakdown), 2 (debug info). 20 | % opts.nthreads sets requested number of threads (else automatic) 21 | % opts.spread_sort: 0 (don't sort NU pts), 1 (do), 2 (auto, default) 22 | % opts.fftw: 0 (use FFTW_ESTIMATE, default), 1 (use FFTW_MEASURE) 23 | % opts.modeord: 0 (CMCL increasing mode ordering, default), 1 (FFT ordering) 24 | % opts.chkbnds: 0 (don't check NU points valid), 1 (do, default) 25 | % opts.upsampfac: either 2.0 (default), or 1.25 (low RAM, smaller FFT size) 26 | % Outputs: 27 | % f size-ms double complex array of Fourier transform values 28 | % ier - 0 if success, else: 29 | % 1 : eps too small 30 | % 2 : size of arrays to malloc exceed MAX_NF 31 | % other codes: as returned by cnufftspread 32 | 33 | if nargin<6, o=[]; end 34 | opts = finufft_opts(o); 35 | nj=numel(x); 36 | if numel(c)~=nj, error('c must have the same number of elements as x'); end 37 | 38 | mex_id_ = 'o int = finufft1d1m(i double, i double[], i dcomplex[], i int, i double, i double, o dcomplex[x], i double[])'; 39 | [ier, f] = finufft(mex_id_, nj, x, c, isign, eps, ms, opts, ms); 40 | 41 | % --------------------------------------------------------------------------- 42 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/matlab/finufft_m.h: -------------------------------------------------------------------------------- 1 | // declare interfaces that matlab/octave can call via MEX 2 | 3 | #ifndef FINUFFT_M_H 4 | #define FINUFFT_M_H 5 | 6 | // for the C++ complex type: 7 | #include 8 | 9 | // for matlab interface (always double prec for now) we use this left-over name, 10 | // which happens to be the same as what Mwrap calls double complex (but 11 | // this is not required): 12 | typedef std::complex dcomplex; 13 | 14 | // library provides (facing MEX).... 15 | int finufft1d1m(double nj,double* xj,dcomplex* cj,int iflag,double eps,double ms, dcomplex* fk, double* opts); 16 | int finufft1d2m(double nj,double* xj,dcomplex* cj,int iflag,double eps,double ms, dcomplex* fk, double* opts); 17 | int finufft1d3m(double nj,double* xj,dcomplex* cj,int iflag,double eps,double nk, double* s, dcomplex* f, double * opts); 18 | 19 | int finufft2d1m(double nj,double* xj,double* yj, dcomplex* cj,int iflag,double eps,double ms, double mt, dcomplex* fk, double* opts); 20 | int finufft2d1manym(double ndata,double nj,double* xj,double* yj, dcomplex* cj,int iflag,double eps,double ms, double mt, dcomplex* fk, double* opts); 21 | int finufft2d2m(double nj,double* xj,double* yj, dcomplex* cj,int iflag,double eps,double ms, double mt, dcomplex* fk, double* opts); 22 | int finufft2d2manym(double ndata,double nj,double* xj,double* yj, dcomplex* cj,int iflag,double eps,double ms, double mt, dcomplex* fk, double* opts); 23 | int finufft2d3m(double nj,double* xj,double* yj, dcomplex* cj,int iflag,double eps,double nk, double* s, double* t, dcomplex* f, double *opts); 24 | 25 | int finufft3d1m(double nj,double* xj,double* yj, double*zj, dcomplex* cj,int iflag,double eps,double ms, double mt, double mu, dcomplex* fk, double* opts); 26 | int finufft3d2m(double nj,double* xj,double* yj,double*zj, dcomplex* cj,int iflag,double eps,double ms, double mt, double mu, dcomplex* fk, double* opts); 27 | int finufft3d3m(double nj,double* xj,double* yj,double*zj, dcomplex* cj,int iflag,double eps,double nk, double* s, double* t, double* u, dcomplex* f, double* opts); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/test/manysmallprobs.cpp: -------------------------------------------------------------------------------- 1 | #include "finufft.h" 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main(int argc, char* argv[]) 8 | /* What is small-problem cost of FINUFFT library from C++, using plain 9 | arrays of C++ complex numbers? Barnett 10/31/17. 10 | for Xi Chen question. 11 | 12 | g++ -fopenmp manysmallprobs.cpp ../lib-static/libfinufft.a -o manysmallprobs -lfftw3 -lfftw3_omp -lm 13 | # multithreaded is much slower, due to overhead of starting threads... 14 | export OMP_NUM_THREADS=1 15 | time ./manysmallprobs 16 | 17 | Takes about 1.2s on single core. Ie, throughput is 3.3e6 pts/sec. 18 | */ 19 | { 20 | int M = 2e2; // number of nonuniform points 21 | int N = 2e2; // number of modes 22 | int reps = 2e4; // how many repetitions 23 | double acc = 1e-6; // desired accuracy 24 | 25 | nufft_opts opts; finufft_default_opts(&opts); 26 | complex I = complex(0.0,1.0); // the imaginary unit 27 | int ier; 28 | 29 | // generate some random nonuniform points (x) and complex strengths (c): 30 | double *x = (double *)malloc(sizeof(double)*M); 31 | complex* c = (complex*)malloc(sizeof(complex)*M); 32 | for (int j=0; j* F = (complex*)malloc(sizeof(complex)*N); 38 | 39 | 40 | for (int r=0;r y=F[0]; 47 | printf("%d reps of 1d1 done (last ier=%d): F[0]=%.6g + %.6gi\n",reps,ier,real(y),imag(y)); 48 | 49 | free(x); free(c); free(F); 50 | return ier; 51 | } 52 | -------------------------------------------------------------------------------- /Matlab/functions-solvers/getStress.m: -------------------------------------------------------------------------------- 1 | function stress=getStress(Xt,forces,w,N,nFib,links,nCL,rl,K,g,Ld,s,L) 2 | % AVERAGE STRESS 3 | stressInt=zeros(3); 4 | stressCL = zeros(3); 5 | interf=0; 6 | CLf=0; 7 | intertorq=0; 8 | CLtorq=0; 9 | % Forces from fibers 10 | for iFib=1:nFib 11 | for iPt=1:N 12 | inds=(iFib-1)*3*N+3*iPt-2:(iFib-1)*3*N+3*iPt; 13 | f=forces(inds); 14 | X=Xt(inds)'; 15 | stressInt=stressInt-w(iPt)*(f*X); 16 | interf=interf+w(iPt)*f; 17 | intertorq = intertorq + w(iPt)*cross(f,X); 18 | end 19 | end 20 | % Forces from cross linkers 21 | [numLinks,~]=size(links); 22 | for iL=1:numLinks 23 | fib1 = links(iL,1); 24 | s1star = links(iL,2); 25 | fib2 = links(iL,3); 26 | s2star = links(iL,4); 27 | shift = links(iL,5:7); 28 | % Calculate the force density on fiber 1 29 | inds1 = (fib1-1)*N+1:fib1*N; 30 | inds2 = (fib2-1)*N+1:fib2*N; 31 | X=reshape(Xt,3,N*nFib)'; 32 | X1=X(inds1,:); 33 | X2=X(inds2,:)-[shift(1)+g*shift(2) shift(2) shift(3)]*Ld; 34 | for iPt=1:N 35 | ds = X1(iPt,:)-X2; 36 | ig = ds-rl*(ds)./sqrt(sum(ds.*ds,2)); 37 | ig = ig.*deltah(s-s2star,N,L); 38 | f1=-K*w*ig*deltah(s(iPt)-s1star,N,L); 39 | stressCL=stressCL-w(iPt)*(f1'*X1(iPt,:)); 40 | CLf=CLf+w(iPt)*f1'; 41 | CLtorq = CLtorq + w(iPt)*cross(f1,X1(iPt,:)); 42 | end 43 | % Calculate the force density on fiber 2 44 | for iPt=1:N 45 | ds = X2(iPt,:)-X1; 46 | ig = ds-rl*(ds)./sqrt(sum(ds.*ds,2)); 47 | ig = ig.*deltah(s-s1star,N,L); 48 | f2=-K*w*ig*deltah(s(iPt)-s2star,N,L); 49 | stressCL=stressCL-w(iPt)*(f2'*X2(iPt,:)); 50 | CLf=CLf+w(iPt)*f2'; 51 | CLtorq = CLtorq + w(iPt)*cross(f2,X2(iPt,:)); 52 | end 53 | end 54 | stress = stressCL + stressInt; 55 | %stress = stress-1/3*trace(stress); 56 | end -------------------------------------------------------------------------------- /Matlab/functions-solvers/linequad/matlabcheb/RunIntegral.m: -------------------------------------------------------------------------------- 1 | addpath('configs') 2 | addpath('recursions') 3 | Nfib=100; 4 | Ntarg = 100; 5 | dist = 0.12; 6 | sperss=zeros(Nfib,Ntarg); 7 | dir16ers=zeros(Nfib,Ntarg); 8 | dir32ers=zeros(Nfib,Ntarg); 9 | unid16s=zeros(Nfib,Ntarg); 10 | unid32s=zeros(Nfib,Ntarg); 11 | groots = zeros(Nfib,Ntarg); 12 | specneeded = zeros(Nfib,Ntarg); 13 | ctures=zeros(Nfib,16); 14 | load('configs/targsOnFibs.mat'); 15 | tonFib=t; 16 | load('configs/randomvecs.mat'); 17 | randv = v; 18 | for iFib=1:100 19 | load(strcat('configs/Fib_',num2str(iFib),'.mat')); 20 | cFib = c; 21 | [spers,d16ers,d32ers,unid16, unid32,gs, specneed, C]=demo_long_fiber_Cheb(cFib,tonFib,randv,dist); 22 | sperss(iFib,:)=spers; dir16ers(iFib,:)=d16ers; dir32ers(iFib,:)=d32ers; 23 | unid16s(iFib,:) = unid16; unid32s(iFib,:) = unid32; groots(iFib,:)=gs; ctures(iFib,:)=C; 24 | specneeded(iFib,:) = specneed; 25 | % Test fibers 26 | K = 15; % max Chebyshev mode in derivatives 27 | k = 0:K-1; 28 | xpf = @(t) c(1,:)*(cos(k'.*acos(2*t(:)/Lf'-1))); 29 | ypf = @(t) c(2,:)*(cos(k'.*acos(2*t(:)/Lf'-1))); 30 | zpf = @(t) c(3,:)*(cos(k'.*acos(2*t(:)/Lf'-1))); 31 | s = @(t) sqrt(xpf(t(:)').^2+ypf(t(:)').^2+zpf(t(:)').^2); 32 | % Normalize 33 | Lf=2; 34 | xp = @(t) xpf(t)./(s(t)); 35 | yp = @(t) ypf(t)./(s(t)); 36 | zp = @(t) zpf(t)./(s(t)); 37 | N=16; 38 | tj = chebpts(N,[0 Lf],1); 39 | x = pos(tj,xp); 40 | y = pos(tj,yp); 41 | z = pos(tj,zp); 42 | th=flipud(((2*(0:N-1)+1)*pi/(2*N))'); 43 | tj1=cos(th); 44 | L = (cos((0:N-1).*th)); 45 | hats = L \ [x y z]; 46 | if (sum(sum(abs(hats(3:end,:)) > exp(-0.55*[k(3:end) K])')) > 0) 47 | keyboard 48 | end 49 | % hatsmax = [hatsmax max(abs(hats(end-1,end,:)))]; 50 | end 51 | 52 | function x = pos(t,xp) 53 | % Integrate to get position 54 | opts = odeset('RelTol',5e-14,'AbsTol',5e-14); 55 | [~,x] = ode45(@(t,x) xp(t),[0 t(:)'],0,opts); 56 | if (length(t) > 1) 57 | x=x(2:end); 58 | else 59 | x=x(end); 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/matlab/finufft2d2.m: -------------------------------------------------------------------------------- 1 | function [c ier] = finufft2d2(x,y,isign,eps,f,o) 2 | % FINUFFT2D2 3 | % 4 | % [c ier] = finufft2d2(x,y,isign,eps,f) 5 | % [c ier] = finufft2d2(x,y,isign,eps,f,opts) 6 | % 7 | % Type-2 2D complex nonuniform FFT. 8 | % 9 | % c[j] = SUM f[k1,k2] exp(+/-i (k1 x[j] + k2 y[j])) for j = 1,..,nj 10 | % k1,k2 11 | % where sum is over -ms/2 <= k1 <= (ms-1)/2, -mt/2 <= k2 <= (mt-1)/2, 12 | % 13 | % Inputs: 14 | % x,y location of NU targets on the square [-3pi,3pi]^2, each length nj 15 | % f size (ms,mt) complex Fourier transform value matrix 16 | % (mode ordering given by opts.modeord in each dimension) 17 | % isign if >=0, uses + sign in exponential, otherwise - sign. 18 | % eps precision requested (>1e-16) 19 | % opts.debug: 0 (silent, default), 1 (timing breakdown), 2 (debug info). 20 | % opts.nthreads sets requested number of threads (else automatic) 21 | % opts.spread_sort: 0 (don't sort NU pts), 1 (do), 2 (auto, default) 22 | % opts.fftw: 0 (use FFTW_ESTIMATE, default), 1 (use FFTW_MEASURE) 23 | % opts.modeord: 0 (CMCL increasing mode ordering, default), 1 (FFT ordering) 24 | % opts.chkbnds: 0 (don't check NU points valid), 1 (do, default). 25 | % opts.upsampfac: either 2.0 (default), or 1.25 (low RAM, smaller FFT size) 26 | % Outputs: 27 | % c complex double array of nj answers at the targets. 28 | % ier - 0 if success, else: 29 | % 1 : eps too small 30 | % 2 : size of arrays to malloc exceed MAX_NF 31 | % other codes: as returned by cnufftspread 32 | 33 | if nargin<6, o=[]; end 34 | opts = finufft_opts(o); 35 | nj=numel(x); 36 | if numel(y)~=nj, error('y must have the same number of elements as x'); end 37 | [ms,mt]=size(f); 38 | 39 | mex_id_ = 'o int = finufft2d2m(i double, i double[], i double[], o dcomplex[x], i int, i double, i double, i double, i dcomplex[], i double[])'; 40 | [ier, c] = finufft(mex_id_, nj, x, y, isign, eps, ms, mt, f, opts, nj); 41 | 42 | % --------------------------------------------------------------------------- 43 | -------------------------------------------------------------------------------- /Matlab/MainPrograms/SBTRelaxingFib.m: -------------------------------------------------------------------------------- 1 | % Main file for single relaxing fiber, to test the influence of twist 2 | % elasticity 3 | % This Section 5.2 in the paper Maxian et al. "The hydrodynamics of a 4 | % twisting, bending, inextensible filament in Stokes flow" 5 | %close all; 6 | addpath('../functions-solvers') 7 | %PenaltyForceInsteadOfFlow = 1; kbT=0; ModifyBE=1; gam0=2000*kbT; 8 | exactRPY=0; 9 | TransTransLDOnly=1; % Local drag only 10 | deltaLocal=1; % regularization for local drag 11 | upsamp=0; % no upsampling 12 | noRotTransAtAll=1; 13 | nonLocalRotTrans=0; 14 | N = 16; 15 | RectangularCollocation = 1; 16 | clamp0=0; 17 | twmod=0; 18 | L = 2; 19 | eps = 1e-2; 20 | a = exp(3/2)/4*eps*L; 21 | Eb=1; % Bending modulus 22 | mu=1; % Viscosity 23 | makeMovie = 1; 24 | if (makeMovie) 25 | f=figure; 26 | movieframes=getframe(f); 27 | end 28 | initZeroTheta=1; 29 | nFib=1; 30 | dt = 1e-4; 31 | tf = 0.01; 32 | stopcount = floor(1e-6+tf/dt); 33 | impcoeff = 1; 34 | t=0; 35 | [s,w,b] = chebpts(N, [0 L], 1); % 1st-kind grid for ODE 36 | D = diffmat(N, 1, [0 L], 'chebkind1'); 37 | % Fiber initialization 38 | q=7; 39 | X_s = [cos(q*s.^3 .* (s-L).^3) sin(q*s.^3.*(s - L).^3) ones(N,1)]/sqrt(2); 40 | XMPor0 = [0;0;0]; XMP=XMPor0; 41 | saveEvery=max(1e-4/dt,1); 42 | InitFiberVars; 43 | updateFrame=1; 44 | Xpts=[]; 45 | Thetass=[]; 46 | %% Computations 47 | for count=0:stopcount-1 48 | t=count*dt; 49 | if (mod(count,saveEvery)==0) 50 | if (makeMovie) 51 | clf; 52 | plot3(Xt(1:3:end),Xt(2:3:end),Xt(3:3:end)) 53 | movieframes(length(movieframes)+1)=getframe(f); 54 | end 55 | Xpts=[Xpts;reshape(Xt,3,N+1)']; 56 | Thetass = [Thetass; theta_s]; 57 | end 58 | U0 = zeros(3*Nx,1); 59 | n_ext = zeros(Npsi,1); 60 | f_ext = zeros(3*Nx,1); 61 | TemporalIntegrator_wTwist1Fib; 62 | Xt = Xp1; 63 | Xst = Xsp1; 64 | XMPor0 = XMPor0_p1; 65 | theta_s = theta_sp1; 66 | end 67 | Xpts=[Xpts;reshape(Xt,3,N+1)']; 68 | Thetass = [Thetass; theta_s]; 69 | if (makeMovie) 70 | movieframes(1)=[]; 71 | end -------------------------------------------------------------------------------- /Python/Dependencies/finufft/devel/gen_all_horner_C_code.m: -------------------------------------------------------------------------------- 1 | % Script to make all C code for looped Horner eval of kernels of all widths. 2 | % writes to "ker" array, from a variable "z", and switches by width "w". 3 | % Resulting C code needs only placing in a function. 4 | 5 | % Barnett 4/23/18; now calling Ludvig's loop version from 4/25/18. 6 | % version including low upsampfac, 6/17/18. 7 | % Ludvig put in w=4n padding, 1/31/20. Mystery about why d was bigger 2/6/20. 8 | clear 9 | opts = struct(); 10 | 11 | ws = 2:16; 12 | upsampfac = 2; % sigma (upsampling): either 2 (default) or low (eg 5/4). 13 | opts.wpad = true; % pad kernel eval to multiple of 4 14 | 15 | if upsampfac==2, fid = fopen('../src/ker_horner_allw_loop.c','w'); 16 | else, fid = fopen('../src/ker_lowupsampfac_horner_allw_loop.c','w'); 17 | end 18 | fwrite(fid,sprintf('// Code generated by gen_all_horner_C_code.m in finufft/devel\n')); 19 | fwrite(fid,sprintf('// Authors: Alex Barnett & Ludvig af Klinteberg.\n// (C) The Simons Foundation, Inc.\n')); 20 | for j=1:numel(ws) 21 | w = ws(j) 22 | if upsampfac==2 % hardwire the betas for this default case 23 | betaoverws = [2.20 2.26 2.38 2.30]; % matches setup_spreader 24 | beta = betaoverws(min(4,w-1)) * w; % uses last entry for w>=5 25 | d = w + 2 + (w<=8); % between 2-3 more degree than w 26 | else % use formulae, must match params in setup_spreader... 27 | gamma=0.97; % safety factor 28 | betaoverws = gamma*pi*(1-1/(2*upsampfac)); % from cutoff freq formula 29 | beta = betaoverws * w; 30 | d = w + 1 + (w<=8); % less, since beta smaller, smoother 31 | end 32 | str = gen_ker_horner_loop_C_code(w,d,beta,opts); 33 | if j==1 % write switch statement 34 | fwrite(fid,sprintf(' if (w==%d) {\n',w)); 35 | else 36 | fwrite(fid,sprintf(' } else if (w==%d) {\n',w)); 37 | end 38 | for i=1:numel(str); fwrite(fid,[' ',str{i}]); end 39 | end 40 | fwrite(fid,sprintf(' } else\n printf("width not implemented!\\n");\n')); 41 | fclose(fid); 42 | -------------------------------------------------------------------------------- /Matlab/BrownianFlucts/TimescalesLinearized.m: -------------------------------------------------------------------------------- 1 | % kbT = 4.1e-3; 2 | % lpstar = 10; 3 | % L = 2; 4 | % Eb = lpstar*L*kbT; 5 | % eps = 1e-3; 6 | % gam0=0*1.6e4*kbT/L^3; 7 | % IdForM = 0; 8 | % N = 24; 9 | % upsamp = 0; 10 | % if (eps == 1e-3) 11 | % if (N==12) 12 | % eigThres = 3.2/L; 13 | % elseif (N==24) 14 | % eigThres = 5.0/L; 15 | % elseif (N==36) 16 | % eigThres = 6.7/L; 17 | % end 18 | % elseif (eps==1e-2) 19 | % if (N==12) 20 | % eigThres = 1.6/L; 21 | % elseif (N==24) 22 | % eigThres = 1.0/L; 23 | % elseif (N==36) 24 | % eigThres = 0.34/L; 25 | % end 26 | % end 27 | % CurvedX0=0; 28 | % PenaltyForceInsteadOfFlow = 1; 29 | % RectangularCollocation = 0; 30 | a = eps*L; 31 | mu=1; % Viscosity 32 | nFib=1; 33 | [s,w,b] = chebpts(N, [0 L], 1); % 1st-kind grid for ODE 34 | % Fiber initialization 35 | if (CurvedX0) 36 | q=1; 37 | X_s = [cos(q*s.^3 .* (s-L).^3) sin(q*s.^3.*(s - L).^3) ones(N,1)]/sqrt(2); 38 | else 39 | X_s = [ones(N,1) zeros(N,2)]; 40 | end 41 | XMP=[0;0;0]; 42 | InitFiberVarsNew;% Generalized eigenvalues 43 | if (IdForM) 44 | M = eye(3*Nx)/(8*pi*mu); 45 | else 46 | M = computeRPYMobility(N,Xt,DNp1,a,L,mu,sNp1,... 47 | bNp1,AllbS_Np1,AllbD_Np1,NForSmall,0); 48 | end 49 | MWsym = 1/2*(M*WTilde_Np1_Inverse + WTilde_Np1_Inverse*M'); 50 | MWsym = FilterM(MWsym,eigThres); 51 | K = KonNp1(X_s,XonNp1Mat,I); 52 | Mob = K*pinv(K'*(MWsym \ K))*K'; 53 | MobInv = pinv(Mob); 54 | MobInv=(MobInv+MobInv')/2; % symmetrize 55 | EMat_Np1 = (EMat_Np1+EMat_Np1')/2; 56 | % Generalized eigenvalues 57 | [V,Lam] = eig(MobInv,EMat_Np1); 58 | %V = V(:,1:2*N+3); 59 | %Lam = Lam(1:2*N+3,1:2*N+3); 60 | % Check normalization 61 | % nzation=diag(V'*EMat_Np1*V); 62 | % V = V./sqrt(nzation)'; 63 | [Timescales,Inds] = sort(diag(Lam),'descend'); 64 | V=V(:,Inds); 65 | Lam = diag(Timescales); 66 | %er0 = MobInv*V-EMat_Np1*V*Lam; 67 | %er1=V'*EMat_Np1*V-eye(2*N+3); 68 | %er2 = V'*MobInv*V-Lam; 69 | %er3 = MobInv-EMat_Np1*V*Lam*V'*EMat_Np1; 70 | %tbar = L^4*5e-4/(Eb*log(1/eps)); 71 | tauSm = 8*pi*mu*L^4/(Eb*log(1/eps^2)); 72 | %loglog(1:2*N+3,Timescales(1:2*N+3)/tauSm,':s') 73 | %hold on -------------------------------------------------------------------------------- /Python/Dependencies/finufft/devel/fig_speed_ker_ppval.m: -------------------------------------------------------------------------------- 1 | % script to generate and plot timing of raw kernel evals via various methods. 2 | % Uses test_ker_ppval and its temp data file (see test_ker_ppval.cpp). 3 | % Barnett 4/23/18 4 | 5 | clear 6 | nam = '/tmp/test_ker_ppval.dat'; % wipes any old data; make header for humans: 7 | system(['echo "# M w t_plain t_horner relsuperr" > ' nam]); 8 | 9 | Mwant=1e7; % how many NU pts for a 1d1 or 1d2 NUFFT 10 | 11 | ws=2:16; % range of kernel widths, do timing tests... 12 | for j=1:numel(ws), w=ws(j) 13 | % glib via shell must matter here, since links to glibc(?) w/o fast simd... 14 | % system(sprintf('./test_ker_ppval %d %d',Mwant,w)); % links to slower glibc? 15 | system(sprintf('(unset LD_LIBRARY_PATH; ./test_ker_ppval %d %d)',Mwant,w)); 16 | end 17 | 18 | fid=fopen(nam,'r'); % read and make plot... 19 | fgets(fid); % ignore header line 20 | [y,count] = fscanf(fid, '%f', [5,inf]); 21 | fclose(fid); 22 | if (count~=5*numel(ws)), warning('file wrong number of lines!'); end 23 | y = y'; % since rows of text file come in as cols of array 24 | M = y(:,1); 25 | w = y(:,2); 26 | r = (M.*w)./y(:,3); % rate in evals/sec 27 | r2 = (M.*w)./y(:,4); % " 28 | e = y(:,5); % rel err 29 | figure; plot(w,[r r2]/1e6,'+-'); xlabel('w'); ylabel('eval rate (Meval/s)'); 30 | 31 | ylim([0, 700]) 32 | grid on 33 | 34 | legend('exp eval','Horner'); title(sprintf('1thr, with padding, M=%d',Mwant)) 35 | print -dpng 1thr_ker_eval_speeds_withpadding.png 36 | 37 | 38 | % xeon gcc6.4: exp max out at 40 Meval/s; horner 170-300 Meval/s. 39 | 40 | % cf ludvig's i7 results: 0.2 sec for 1e7*(w=12) = 600 Meval/s 41 | % (but that's special to m=12, also w/o the domain conditional?) 42 | % Wouldn't it be nice if could get that for all i7 cases. 43 | 44 | % Concl: for xeon w/ gcc, horner is much better! (5-10x) 45 | 46 | % Jan 2020: Ludvig padded the Horner loop too, giving a little boost for 47 | % w = 2,3 (mod 4) in GCC7,9, and big boost for old GCC5.4. 48 | % We're at 400-700 Meval/s on i7 for all compilers except GCC8 now, 49 | % in -O3 not -Ofast (which we can't use in FINUFFT). 50 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/docs/related.rst: -------------------------------------------------------------------------------- 1 | Related packages 2 | ================ 3 | 4 | Other recommended NUFFT libraries 5 | --------------------------------- 6 | 7 | - `NFFT3 `_: well-supported and multi-featured C++ library using FFTW. Has MATLAB interface. However, significantly slower and/or more memory-intensive than FINUFFT (see reference [FIN]). 8 | 9 | - `CMCL NUFFT `_: NYU single-threaded Fortran library using self-contained FFT, Gaussian kernel. Has MATLAB interface. Much slower than FINUFFT. 10 | 11 | - `MIRT `_ Michigan Image Reconstruction Toolbox. Native MATLAB, single-threaded sparse mat-vec, prestores all kernel evaluations, thus is memory-intensive. Slower than FINUFFT for all tolerances smaller than 0.1. 12 | 13 | - `PyNUFFT `_ Python code supporting CPU and GPU operation. Have not compared against FINUFFT yet. 14 | 15 | 16 | Also see the summary of library performances in our paper [FIN]. 17 | 18 | 19 | Interfaces to FINUFFT from other languages 20 | ------------------------------------------ 21 | 22 | - `FINUFFT.jl `_: a `julia `_ language wrapper by Ludvig af Klinteberg (SFU). This is actually a secondary wrapper around our python interface, so you should make sure that the latter is working first. 23 | 24 | - Vineet Bansal's pypi package https://pypi.org/project/finufftpy/ 25 | 26 | 27 | Packages making use of FINUFFT 28 | ------------------------------ 29 | 30 | Here are some packages dependent on FINUFFT (please let us know others): 31 | 32 | - `ASPIRE `_: software for cryo-EM, based at Amit Singer's group at Princeton. `github `_ 33 | 34 | - `sinctransform `_: C++ 35 | and MATLAB codes to evaluate sums of the sinc and sinc^2 kernels between arbitrary nonuniform points in 1,2, or 3 dimensions, by Hannah Lawrence (2017 summer intern at Flatiron). 36 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/matlab/finufft3d3.m: -------------------------------------------------------------------------------- 1 | function [f ier] = finufft3d3(x,y,z,c,isign,eps,s,t,u,o) 2 | % FINUFFT3D3 3 | % 4 | % [f ier] = finufft3d3(x,y,z,c,isign,eps,s,t,u) 5 | % [f ier] = finufft3d3(x,y,z,c,isign,eps,s,t,u,opts) 6 | % 7 | % nj 8 | % f[k] = SUM c[j] exp(+-i (s[k] x[j] + t[k] y[j] + u[k] z[j])), 9 | % j=1 10 | % for k = 1, ..., nk 11 | % Inputs: 12 | % x,y,z location of NU sources in R^3, each length nj. 13 | % c size-nj double complex array of source strengths 14 | % s,t,u frequency locations of NU targets in R^3. 15 | % isign if >=0, uses + sign in exponential, otherwise - sign. 16 | % eps precision requested (>1e-16) 17 | % opts.debug: 0 (silent, default), 1 (timing breakdown), 2 (debug info). 18 | % opts.nthreads sets requested number of threads (else automatic) 19 | % opts.spread_sort: 0 (don't sort NU pts), 1 (do), 2 (auto, default) 20 | % opts.fftw: 0 (use FFTW_ESTIMATE, default), 1 (use FFTW_MEASURE) 21 | % opts.upsampfac: either 2.0 (default), or 1.25 (low RAM, smaller FFT size) 22 | % Outputs: 23 | % f size-nk double complex Fourier transform values at target 24 | % frequencies s,t,u 25 | % returned value - 0 if success, else: 26 | % 1 : eps too small 27 | % 2 : size of arrays to malloc exceed MAX_NF 28 | 29 | if nargin<10, o=[]; end 30 | opts = finufft_opts(o); 31 | nj=numel(x); 32 | nk=numel(s); 33 | if numel(y)~=nj, error('y must have the same number of elements as x'); end 34 | if numel(z)~=nj, error('z must have the same number of elements as x'); end 35 | if numel(c)~=nj, error('c must have the same number of elements as x'); end 36 | if numel(t)~=nk, error('t must have the same number of elements as s'); end 37 | if numel(u)~=nk, error('u must have the same number of elements as s'); end 38 | 39 | mex_id_ = 'o int = finufft3d3m(i double, i double[], i double[], i double[], i dcomplex[x], i int, i double, i double, i double[], i double[], i double[], o dcomplex[x], i double[])'; 40 | [ier, f] = finufft(mex_id_, nj, x, y, z, c, isign, eps, nk, s, t, u, opts, nj, nk); 41 | -------------------------------------------------------------------------------- /Matlab/MainPrograms/InitializationNoTwist.m: -------------------------------------------------------------------------------- 1 | %% Preliminaries 2 | Nx = N+1; 3 | [sNp1,wNp1,bNp1]=chebpts(Nx,[0 L],2); 4 | DNp1 = diffmat(Nx,[0 L],'chebkind2'); 5 | RToNp1 = barymat(sNp1,s,b); 6 | RNp1ToN = barymat(s,sNp1,bNp1); 7 | IntDNp1 = pinv(DNp1); 8 | BMNp1 = stackMatrix(barymat(TrkLoc,sNp1,bNp1)); 9 | % Construct matrix that gives X on the N+1 grid from (X_s, X_MP) 10 | I=zeros(3*(N+1),3); 11 | for iR=1:N+1 12 | I(3*(iR-1)+1:3*iR,1:3)=eye(3); 13 | end 14 | Xst = zeros(3*N*nFib,1); 15 | Xt = zeros(3*Nx*nFib,1); 16 | XonNp1Mat = [(eye(3*(N+1))-repmat(BMNp1,N+1,1))*... 17 | stackMatrix(IntDNp1*RToNp1) I]; 18 | InvXonNp1Mat = [stackMatrix(RNp1ToN*DNp1); BMNp1]; 19 | for iFib=1:nFib 20 | Xst((iFib-1)*3*N+1:iFib*3*N) = ... 21 | reshape(X_s((iFib-1)*N+1:iFib*N,:)',[],1); 22 | Xt((iFib-1)*3*Nx+1:iFib*3*Nx) = XonNp1Mat*... 23 | [Xst((iFib-1)*3*N+1:iFib*3*N);XTrk(:,iFib)]; 24 | end 25 | % Bending energy matrix (2N+2 grid) 26 | [s2Np2, w2Np2, b2Np2] = chebpts(2*Nx, [0 L], 2); 27 | W2Np2 = diag(w2Np2); 28 | R_Np1_To_2Np2 = barymat(s2Np2,sNp1,bNp1); 29 | D2Np2 = diffmat(2*Nx,[0 L],'chebkind2'); 30 | WTilde_Np1 = stackMatrix((R_Np1_To_2Np2'*W2Np2*R_Np1_To_2Np2)); 31 | WTilde_Np1_Inverse = WTilde_Np1^(-1); 32 | BendingEnergyMatrix_Np1 = Eb*stackMatrix((R_Np1_To_2Np2*DNp1^2)'*... 33 | W2Np2*R_Np1_To_2Np2*DNp1^2); 34 | BendForceMat = -BendingEnergyMatrix_Np1; 35 | BendMatHalf_Np1 = real(BendingEnergyMatrix_Np1^(1/2)); 36 | % Hydrodynamics 37 | % NupsampleHydro = 200;%ceil(2/a); 38 | % [sup,wup,~] = chebpts(NupsampleHydro, [0 L],2); 39 | % RupsampleHydro = stackMatrix(barymat(sup,sNp1,bNp1)); 40 | % WUpHydro = stackMatrix(diag(wup)); 41 | % BDCell = repmat({RupsampleHydro},nFib,1); 42 | % RupsampleHydro_BD = blkdiag(BDCell{:}); 43 | % BDCell = repmat({WUpHydro},nFib,1); 44 | % WUpHydro_BD = blkdiag(BDCell{:}); 45 | % BDCell = repmat({WTilde_Np1_Inverse},nFib,1); 46 | % WTInv_BD = blkdiag(BDCell{:}); 47 | % AllbS_Np1 = precomputeStokesletInts(sNp1,L,a,N+1,1); 48 | % AllbD_Np1 = precomputeDoubletInts(sNp1,L,a,N+1,1); 49 | % NForSmall = 8; % # of pts for R < 2a integrals for exact RPY 50 | % eigThres = 1e-3; 51 | % Plotting 52 | Npl=100; 53 | [spl,wpl,bpl]=chebpts(Npl,[0 L]); 54 | RplNp1 = barymat(spl,sNp1,bNp1); -------------------------------------------------------------------------------- /Python/Dependencies/NeighborSearch/nlist.py: -------------------------------------------------------------------------------- 1 | #import NeighborSearch 2 | from SpatialDatabase import ckDSpatial, CellLinkedList 3 | from Domain import PeriodicShearedDomain 4 | from scipy.spatial import cKDTree 5 | import numpy as np 6 | import time 7 | 8 | numberParticles = 675*250 9 | lx = ly = lz = 2.4 10 | rcut = 0.07500000000000001 11 | 12 | #nlist = NeighborSearch.NList() 13 | 14 | np.random.seed(1) 15 | precision = np.float32 16 | positions = np.array(np.random.rand(numberParticles, 3), precision) 17 | positions[:, 0] *= 2*lx 18 | positions[:, 1] *= 2*ly 19 | positions[:, 2] *= 2*lz 20 | Neighbs2=np.savetxt('Positions.txt',positions) 21 | 22 | nThr=16; 23 | """ 24 | thist = time.time() 25 | 26 | nlist.updateList(pos=positions, 27 | Lx=lx, Ly=ly, Lz=lz, 28 | numberParticles=numberParticles, 29 | rcut=rcut,useGPU=False,maxNeighbors=25,nThr=nThr) 30 | print('GPU Update list time %f' %(time.time()-thist)) 31 | thist = time.time() 32 | neighbors=nlist.list; 33 | AllNeighbors = np.reshape(neighbors,(len(neighbors)//2,2)); 34 | print('GPU sort time %f' %(time.time()-thist)) 35 | print(AllNeighbors.shape) 36 | Neighbs1=np.savetxt('N1.txt',AllNeighbors) 37 | """ 38 | 39 | # Check with ckd tree 40 | Dom = PeriodicShearedDomain(lx,ly,lz); 41 | SpatialChk = ckDSpatial(positions,Dom); 42 | thist = time.time() 43 | SpatialChk.updateSpatialStructures(positions,Dom); 44 | AllNeighbors2 = SpatialChk.selfNeighborList(rcut*1.1) 45 | print('CPU Update list time %f' %(time.time()-thist)) 46 | print(AllNeighbors2.shape) 47 | Neighbs2=np.savetxt('N2.txt',AllNeighbors2) 48 | 49 | # Check with linked list class 50 | Dom = PeriodicShearedDomain(lx,ly,lz); 51 | SpatialChk = CellLinkedList(positions,Dom,nThr=nThr); 52 | thist = time.time() 53 | SpatialChk.updateSpatialStructures(positions,Dom); 54 | AllNeighbors2 = SpatialChk.selfNeighborList(rcut) 55 | print('Class LL Update list time %f' %(time.time()-thist)) 56 | SpatialChk.updateSpatialStructures(positions,Dom); 57 | thist = time.time() 58 | AllNeighbors2 = SpatialChk.selfNeighborList(rcut*1.1) 59 | print('Class LL 2nd Update list time %f' %(time.time()-thist)) 60 | print(AllNeighbors2.shape) 61 | Neighbs2=np.savetxt('N3.txt',AllNeighbors2) 62 | 63 | -------------------------------------------------------------------------------- /Matlab/NumericalSBT/upsampleRPY.m: -------------------------------------------------------------------------------- 1 | function U = upsampleRPY(Targs,starg,X0,f0,s0,b0,Nup,L,a) 2 | % Collocation pts 3 | U = 0*Targs; 4 | for iT=1:length(Targs) 5 | t = starg(iT); 6 | P = Targs(iT,:); 7 | smallds = zeros(1,3); 8 | for iD=0:1 9 | dom = [t min(t+2*a,L)]; 10 | if (iD==0) 11 | dom=[max(t-2*a,0) t]; 12 | end 13 | if (max(dom)-min(dom) > 0) 14 | [ssm,wsm,~]=chebpts(Nup,dom,1); 15 | Rsm = barymat(ssm, s0, b0); 16 | Xsm = Rsm*X0; 17 | fsm = Rsm*f0; 18 | R = P-Xsm; 19 | nR = sqrt(sum(R.*R,2)); 20 | Rhat = R./nR; 21 | Rdotf = sum(R.*fsm,2); 22 | K1 = (1-9*nR/(32*a)).*fsm; 23 | K2 = 3./(32*a).*Rdotf.*Rhat; 24 | small = 4/(3*a)*(K1+K2); 25 | smallds=smallds+wsm*small; 26 | end 27 | end 28 | 29 | % Two Stokeslet integrals 30 | int1 = zeros(1,3); 31 | if (t > 2*a) 32 | [s1,w1,~]=chebpts(Nup,[0 t-2*a],1); 33 | %[s1,w1,~]=chebpts(Nup,[0 t],1); 34 | R1 = barymat(s1, s0, b0); 35 | X1 = R1*X0; 36 | f1 = R1*f0; 37 | R = P-X1; 38 | nR = sqrt(sum(R.*R,2)); 39 | Rdotf = sum(R.*f1,2); 40 | StokIG = f1./nR + Rdotf.*R./nR.^3; 41 | DoubIG = f1./nR.^3-3*Rdotf.*R./nR.^5; 42 | totIG = StokIG+2*a^2/3*DoubIG; 43 | int1=w1*totIG; 44 | end 45 | 46 | int2 = zeros(1,3); 47 | if (t < L-2*a) 48 | [s1,w1,~]=chebpts(Nup,[t+2*a L],1); 49 | %[s1,w1,~]=chebpts(Nup,[t L],1); 50 | R1 = barymat(s1,s0, b0); 51 | X1 = R1*X0; 52 | f1 = R1*f0; 53 | R = P-X1; 54 | nR = sqrt(sum(R.*R,2)); 55 | Rdotf = sum(R.*f1,2); 56 | StokIG = f1./nR + Rdotf.*R./nR.^3; 57 | DoubIG = f1./nR.^3-3*Rdotf.*R./nR.^5; 58 | totIG = StokIG+2*a^2/3*DoubIG; 59 | int2=w1*totIG; 60 | end 61 | U(iT,:)=smallds+int1+int2; 62 | end 63 | end -------------------------------------------------------------------------------- /Python/Dependencies/finufft/matlab/finufft2d2many.m: -------------------------------------------------------------------------------- 1 | function [c ier] = finufft2d2many(x,y,isign,eps,f,o) 2 | % FINUFFT2D2MANY 3 | % 4 | % [c ier] = finufft2d2many(x,y,isign,eps,f) 5 | % [c ier] = finufft2d2many(x,y,isign,eps,f,opts) 6 | % 7 | % Type-2 2D complex nonuniform FFT. 8 | % 9 | % c[j,d] = SUM f[k1,k2,d] exp(+/-i (k1 x[j] + k2 y[j])) 10 | % k1,k2 11 | % for j = 1,..,nj, d = 1,...,ndata 12 | % where sum is over -ms/2 <= k1 <= (ms-1)/2, -mt/2 <= k2 <= (mt-1)/2, 13 | % 14 | % Inputs: 15 | % x,y location of NU targets on the square [-3pi,3pi]^2, each length nj 16 | % f size (ms,mt,ndata) complex Fourier transform value matrix 17 | % (mode ordering given by opts.modeord in each dimension) 18 | % isign if >=0, uses + sign in exponential, otherwise - sign. 19 | % eps precision requested (>1e-16) 20 | % opts.debug: 0 (silent, default), 1 (timing breakdown), 2 (debug info). 21 | % opts.nthreads sets requested number of threads (else automatic) 22 | % opts.spread_sort: 0 (don't sort NU pts), 1 (do), 2 (auto, default) 23 | % opts.fftw: 0 (use FFTW_ESTIMATE, default), 1 (use FFTW_MEASURE) 24 | % opts.modeord: 0 (CMCL increasing mode ordering, default), 1 (FFT ordering) 25 | % opts.chkbnds: 0 (don't check NU points valid), 1 (do, default). 26 | % opts.upsampfac: either 2.0 (default), or 1.25 (low RAM, smaller FFT size) 27 | % Outputs: 28 | % c complex double array of nj*ndata answers at the targets. 29 | % ier - 0 if success, else: 30 | % 1 : eps too small 31 | % 2 : size of arrays to malloc exceed MAX_NF 32 | % other codes: as returned by cnufftspread 33 | % 34 | % Note: nthreads copies of the fine grid are allocated, limiting this to smaller 35 | % problem sizes. 36 | 37 | if nargin<6, o=[]; end 38 | opts = finufft_opts(o); 39 | nj=numel(x); 40 | if numel(y)~=nj, error('y must have the same number of elements as x'); end 41 | [ms,mt,ndata]=size(f); 42 | 43 | mex_id_ = 'o int = finufft2d2manym(i double, i double, i double[], i double[], o dcomplex[xx], i int, i double, i double, i double, i dcomplex[], i double[])'; 44 | [ier, c] = finufft(mex_id_, ndata, nj, x, y, isign, eps, ms, mt, f, opts, nj, ndata); 45 | 46 | % --------------------------------------------------------------------------- 47 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/test/results/dumbinputs.refout: -------------------------------------------------------------------------------- 1 | 1D dumb cases ---------------- 2 | 1d1 tol=0: ier=1 (should complain) 3 | 1d1 N=0: ier=0 4 | 1d1 M=0: ier=0 nrm(F)=0 (should vanish) 5 | 1d2 tol=0: ier=1 (should complain) 6 | 1d2 N=0: ier=0 nrm(c)=0 (should vanish) 7 | 1d2 M=0: ier=0 8 | 1d3 tol=0: ier=1 (should complain) 9 | 1d3 nk=0: ier=0 10 | 1d3 M=0: ier=0 nrm(F)=0 (should vanish) 11 | 1d3 M=1: ier=0 nrm(err)=0.0000 12 | 1d3 N=1: ier=0 err=0.0000 13 | 1d3 M=N=1: ier=0 err=0.0000 14 | 1d3 XK prod too big: ier=2 (should complain) 15 | 2D dumb cases ---------------- 16 | 2d1 tol=0: ier=1 (should complain) 17 | 2d1 Ns=Nt=0: ier=0 18 | 2d1 Ns=0,Nt>0: ier=0 19 | 2d1 Ns>0,Ns=0: ier=0 20 | 2d1 M=0: ier=0 nrm(F)=0 (should vanish) 21 | 2d2 tol=0: ier=1 (should complain) 22 | 2d2 Ns=Nt=0: ier=0 nrm(c)=0 (should vanish) 23 | 2d2 Ns=0,Nt>0: ier=0 nrm(c)=0 (should vanish) 24 | 2d2 Ns>0,Nt=0: ier=0 nrm(c)=0 (should vanish) 25 | 2d2 M=0: ier=0 26 | 2d3 tol=0: ier=1 (should complain) 27 | 2d3 nk=0: ier=0 28 | 2d3 M=0: ier=0 nrm(F)=0 (should vanish) 29 | 2d3 M=1: ier=0 nrm(F)=3.16 30 | 2d3 XK prod too big: ier=2 (should complain) 31 | 2d1many ndata=0: ier=9 (should complain) 32 | 2d1many tol=0: ier=1 (should complain) 33 | 2d1many Ns=Nt=0: ier=0 34 | 2d1many Ns=0,Nt>0: ier=0 35 | 2d1many Ns>0,Ns=0: ier=0 36 | 2d1many M=0: ier=0 nrm(Fm)=0 (should vanish) 37 | 2d2many ndata=0: ier=9 (should complain) 38 | 2d2many tol=0: ier=1 (should complain) 39 | 2d2many Ns=Nt=0: ier=0 nrm(cm)=0 (should vanish) 40 | 2d2many Ns=0,Nt>0: ier=0 nrm(cm)=0 (should vanish) 41 | 2d2many Ns>0,Nt=0: ier=0 nrm(cm)=0 (should vanish) 42 | 2d2many M=0: ier=0 43 | 3D dumb cases ---------------- 44 | 3d1 tol=0: ier=1 (should complain) 45 | 3d1 Ns=Nt=Nu=0: ier=0 46 | 3d1 Ns,Nt>0,Nu=0: ier=0 47 | 3d1 Ns>0,Nt=0,Nu>0: ier=0 48 | 3d1 Ns,Nt>0,Nu=0: ier=0 49 | 3d1 M=0: ier=0 nrm(F)=0 (should vanish) 50 | 3d2 tol=0: ier=1 (should complain) 51 | 3d2 Ns=Nt=Nu=0: ier=0 nrm(c)=0 (should vanish) 52 | 3d2 Ns=0,Nt,Nu>0: ier=0 nrm(c)=0 (should vanish) 53 | 3d2 Ns>0,Nt=0,Nu>0: ier=0 nrm(c)=0 (should vanish) 54 | 3d2 Ns,Nt>0,Nu=0: ier=0 nrm(c)=0 (should vanish) 55 | 3d2 M=0: ier=0 56 | 3d3 tol=0: ier=1 (should complain) 57 | 3d3 nk=0: ier=0 58 | 3d3 M=0: ier=0 nrm(F)=0 (should vanish) 59 | 3d3 M=1: ier=0 nrm(F)=3.16 60 | 3d3 XK prod too big: ier=2 (should complain) 61 | freed. 62 | -------------------------------------------------------------------------------- /Matlab/functions-solvers/updateMovingLinks.m: -------------------------------------------------------------------------------- 1 | function links = updateMovingLinks(links,X,Xs,N,s,w,L, K, rl,g,Ld,dt) 2 | [nLink,~]=size(links); 3 | v0Myosin=1; 4 | fstall=1; % 5/25 5 | % Uniform points on [0, Lf] 6 | th=flipud(((2*(0:N-1)+1)*pi/(2*N))'); 7 | Lmat = (cos((0:N-1).*th)); 8 | for iL=1:nLink 9 | fib1 = links(iL,1); 10 | s1star = links(iL,2); 11 | fib2 = links(iL,3); 12 | s2star = links(iL,4); 13 | shift = links(iL,5:7); 14 | % Calculate the force density on fiber 1 15 | inds1 = (fib1-1)*N+1:fib1*N; 16 | inds2 = (fib2-1)*N+1:fib2*N; 17 | X1=X(inds1,:); 18 | th1 = acos(2*s1star/L-1)'; 19 | U1 = (cos((0:N-1).*th1)); 20 | X1star = U1*(Lmat \ X1); 21 | X2=X(inds2,:)-[shift(1)+g*shift(2) shift(2) shift(3)]*Ld; 22 | th2 = acos(2*s2star/L-1)'; 23 | U2 = (cos((0:N-1).*th2)); 24 | X2star = U2*(Lmat \ X2); 25 | renorm = w*deltah(s-s1star,N,L)*w*deltah(s-s2star,N,L); 26 | f1 = zeros(N,3); 27 | for iPt=1:N 28 | ds = X1(iPt,:)-X2; 29 | ig = ds*(1-rl/norm(X1star-X2star)); 30 | ig = ig.*deltah(s-s2star,N,L); 31 | f1(iPt,:)=-K*w*ig*deltah(s(iPt)-s1star,N,L); 32 | end 33 | % Renormalize f1 34 | f1=f1./renorm; 35 | % Compute tangential component of f1 36 | f1_t = w*(sum(f1.*Xs(inds1,:),2).*deltah(s-s1star,N,L))/(w*deltah(s-s1star,N,L)); 37 | % Compute velocity 38 | vLink1 = max(v0Myosin*(1-norm(f1_t)/fstall),0); 39 | links(iL,2)=min(links(iL,2)+vLink1*dt,L); 40 | % Calculate the force density on fiber 2 41 | f2 = zeros(N,3); 42 | for iPt=1:N 43 | ds = X2(iPt,:)-X1; 44 | ig = ds*(1-rl/norm(X1star-X2star)); 45 | ig = ig.*deltah(s-s1star,N,L); 46 | f2(iPt,:)=-K*w*ig*deltah(s(iPt)-s2star,N,L); 47 | end 48 | % Renormalize 49 | f2=f2./renorm; 50 | % Calculate tangential component 51 | f2_t = w*(sum(f2.*Xs(inds2,:),2).*deltah(s-s2star,N,L))/(w*deltah(s-s2star,N,L)); 52 | vLink2 = max(v0Myosin*(1-norm(f2_t)/fstall),0); 53 | links(iL,4)=min(links(iL,4)+vLink2*dt,L); 54 | end 55 | % Total force and torque are 0 AFTER ACCOUNTING FOR SHIFT. 56 | end -------------------------------------------------------------------------------- /Python/Dependencies/finufft/docs/issues.rst: -------------------------------------------------------------------------------- 1 | Known Issues 2 | ============ 3 | 4 | One should also check the github issues for the project page, 5 | https://github.com/flatironinstitute/finufft/issues 6 | 7 | Also see notes in the ``TODO`` file. 8 | 9 | Issues with library 10 | ******************* 11 | 12 | - When requested accuracy is ``1e-14`` or less, it is sometimes not possible to match this, especially when there are a large number of input and/or output points. This is believed to be unavoidable round-off error. 13 | 14 | - Currently in Mac OSX, ``make lib`` fails to make the shared object library (.so). 15 | 16 | - The timing of the first FFTW call is complicated, depending on whether FFTW_ESTIMATE (the default) or FFTW_MEASURE is used. Such issues are known, and discussed in other documentation, eg https://pythonhosted.org/poppy/fft_optimization.html . 17 | We would like to find a way of pre-storing some Intel-specific FFTW plans (as MATLAB does) to avoid the large FFTW planning times. 18 | 19 | - Currently, a single library name is used for single- and multi-threaded versions. Thus, i) you need to ``make clean`` before changing such make options, and ii) if you wish to maintain multiple such versions you need to move them around and maintain them yourself, eg by duplicating the directory. 20 | 21 | - The overhead for small problem sizes (<10000 data points) is too high, due to things such as the delay in FFTW looking up pre-stored wisdom. A unified advanced interface with a plan stage is in the works. 22 | 23 | 24 | Issues with interfaces 25 | ********************** 26 | 27 | - MATLAB, octave and python cannot exceed input or output data sizes of 2^31. 28 | 29 | - MATLAB, octave and python interfaces do not handle single precision. 30 | 31 | - Fortran interface does not allow control of options, nor data sizes exceeding 2^31. 32 | 33 | 34 | 35 | Bug reports 36 | *********** 37 | 38 | If you think you have found a bug, please 39 | file an issue on the github project page, 40 | https://github.com/flatironinstitute/finufft/issues . 41 | Include a minimal code which reproduces the bug, along with 42 | details about your machine, operating system, compiler, and version of FINUFFT. 43 | 44 | You may also contact Alex Barnett (``abarnett`` 45 | at-sign ``flatironinstitute.org``) with FINUFFT in the subject line. 46 | 47 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/matlab/check_modeords.m: -------------------------------------------------------------------------------- 1 | % check the two mode-orderings are consistent, via fftshift, 3D type-1 and 2. 2 | % Barnett 10/25/17 3 | 4 | clear % choose params... 5 | isign = +1; % sign of imaginary unit in exponential 6 | eps = 1e-6; % requested accuracy 7 | o.debug = 0; % choose 1 for timing breakdown text output 8 | o.nthreads = 0; % omit, or use 0, to use default num threads. 9 | o.fftw = 0; % style of FFTW: 0 (ESTIMATE) vs 1 (MEASURE, slow but reuses) 10 | M = 1e5; % # of NU pts 11 | N1 = 123; N2=58; N3=24; % # of modes in each dim (try even & odd) 12 | j = ceil(0.93*M); % target pt index to test 13 | 14 | tic; % --------- 3D 15 | fprintf('3D: using %d*%d*%d modes (total %d)...\n',N1,N2,N3,N1*N2*N3) 16 | x = pi*(2*rand(1,M)-1); y = pi*(2*rand(1,M)-1); z = pi*(2*rand(1,M)-1); 17 | c = randn(1,M)+1i*randn(1,M); 18 | o.modeord = 0; 19 | [f ier] = finufft3d1(x,y,z,c,isign,eps,N1,N2,N3,o); 20 | nt1 = ceil(0.45*N1); nt2 = ceil(-0.35*N2); nt3 = ceil(0.17*N3); % mode to check 21 | fe = sum(c.*exp(1i*isign*(nt1*x+nt2*y+nt3*z))); % exact 22 | of1 = floor(N1/2)+1; of2 = floor(N2/2)+1; of3 = floor(N3/2)+1; % index offsets 23 | fprintf('3D type-1 modeord=0: rel err in F[%d,%d,%d] is %.3g\n',nt1,nt2,nt3,abs((fe-f(nt1+of1,nt2+of2,nt3+of3))/fe)) 24 | o.modeord = 1; 25 | [f1 ier] = finufft3d1(x,y,z,c,isign,eps,N1,N2,N3,o); 26 | f1 = fftshift(f1); % handles odd dimension lengths Ns same as we do 27 | fprintf('\t modeord=1 vs 0: max error = %g\n',norm(f1(:)-f(:),Inf)) 28 | % it's still a mystery how there can be any nonzero difference here - 29 | % maybe the compiler is reordering the calcs, so roundoff appears, somehow? 30 | 31 | f = randn(N1,N2,N3)+1i*randn(N1,N2,N3); 32 | o.modeord = 0; 33 | [c ier] = finufft3d2(x,y,z,isign,eps,f,o); 34 | [ms mt mu]=size(f); 35 | % ndgrid loops over ms fastest, mu slowest: 36 | [mm1,mm2,mm3] = ndgrid(ceil(-ms/2):floor((ms-1)/2),ceil(-mt/2):floor((mt-1)/2),ceil(-mu/2):floor((mu-1)/2)); 37 | ce = sum(f(:).*exp(1i*isign*(mm1(:)*x(j)+mm2(:)*y(j)+mm3(:)*z(j)))); 38 | fprintf('3D type-2 modeord=0: rel err in c[%d] is %.3g\n',j,abs((ce-c(j))/ce)) 39 | o.modeord = 1; 40 | [c1 ier] = finufft3d2(x,y,z,isign,eps,ifftshift(f),o); 41 | % note for odd Ns, ifftshift is correct inverse of fftshift 42 | fprintf('\t modeord=1 vs 0: max error = %g\n',norm(c-c1,Inf)) 43 | -------------------------------------------------------------------------------- /Matlab/functions-solvers/Ewald/EwaldFarVelFI.m: -------------------------------------------------------------------------------- 1 | % Far field velocity with PSE RPY tensor using FINUFFT 2 | function velfar = EwaldFarVelFI(ptsxyz,forces,mu,Lx,Ly,Lz,xi,a,g) 3 | % Compute the coordinates in the transformed basis 4 | L = [1 g 0; 0 1 0; 0 0 1]; 5 | pts = (L \ ptsxyz')'; 6 | % Rescale to [-pi,pi] 7 | pts = pts./[Lx Ly Lz]*2*pi; 8 | gw=1/(2*xi); 9 | h=gw/1.6; 10 | nx=2^(nextpow2(Lx/h)); 11 | ny=2^(nextpow2(Ly/h)); 12 | nz=2^(nextpow2(Lz/h)); 13 | kvx=[0:nx/2-1 -nx/2:-1]*2*pi/Lx; 14 | kvy=[0:ny/2-1 -ny/2:-1]*2*pi/Ly; 15 | kvz=[0:nz/2-1 -nz/2:-1]*2*pi/Lz; 16 | [ky,kx,kz]=meshgrid(kvy,kvx,kvz); 17 | opts.modeord=1; 18 | fxhat = finufft3d1(pts(:,1),pts(:,2),pts(:,3),forces(:,1),-1,1e-10,nx,ny,nz,opts); 19 | fyhat = finufft3d1(pts(:,1),pts(:,2),pts(:,3),forces(:,2),-1,1e-10,nx,ny,nz,opts); 20 | fzhat = finufft3d1(pts(:,1),pts(:,2),pts(:,3),forces(:,3),-1,1e-10,nx,ny,nz,opts); 21 | k = sqrt(kx.^2+(ky-g*kx).^2+kz.^2); 22 | % Factor is Eq. (9) in the paper 23 | % Careful: matlab has an extra pi in the sinc function 24 | factor = 1/mu*1./k.^2.*(sinc(k*a/pi).^2).*(1+(k.^2)/(4*xi^2)).*exp(-k.^2/(4*xi^2)); 25 | factor(1,1,1)=0; 26 | uxhat=factor.*fxhat; 27 | uyhat=factor.*fyhat; 28 | uzhat=factor.*fzhat; 29 | % Project off to get a divergence free field 30 | for iX=1:nx 31 | for iY=1:ny 32 | for iZ=1:nz 33 | if (k(iX,iY,iZ)>0) 34 | ks=[kx(iX,iY,iZ) ky(iX,iY,iZ)-g*kx(iX,iY,iZ) kz(iX,iY,iZ)]; 35 | ks=ks/norm(ks); 36 | usofar=[uxhat(iX,iY,iZ); uyhat(iX,iY,iZ); ... 37 | uzhat(iX,iY,iZ)]; 38 | u_off = (eye(3)-(ks'*ks))*usofar; 39 | uxhat(iX,iY,iZ)=u_off(1); 40 | uyhat(iX,iY,iZ)=u_off(2); 41 | uzhat(iX,iY,iZ)=u_off(3); 42 | end 43 | end 44 | end 45 | end 46 | % IFFT back and interpolate to get the far field 47 | uxpts=real(finufft3d2(pts(:,1),pts(:,2),pts(:,3),1,1e-10,uxhat,opts))/(Lx*Ly*Lz); 48 | uypts=real(finufft3d2(pts(:,1),pts(:,2),pts(:,3),1,1e-10,uyhat,opts))/(Lx*Ly*Lz); 49 | uzpts=real(finufft3d2(pts(:,1),pts(:,2),pts(:,3),1,1e-10,uzhat,opts))/(Lx*Ly*Lz); 50 | velfar=[uxpts'; uypts'; uzpts']; 51 | end 52 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/matlab/finufft3d2.m: -------------------------------------------------------------------------------- 1 | function [c ier] = finufft3d2(x,y,z,isign,eps,f,o) 2 | % FINUFFT3D2 3 | % 4 | % [c ier] = finufft3d2(x,y,z,isign,eps,f) 5 | % [c ier] = finufft3d2(x,y,z,isign,eps,f,opts) 6 | % 7 | % Type-2 3D complex nonuniform FFT. 8 | % 9 | % c[j] = SUM f[k1,k2,k3] exp(+/-i (k1 x[j] + k2 y[j] + k3 z[j])) 10 | % k1,k2,k3 11 | % for j = 1,..,nj 12 | % where sum is over -ms/2 <= k1 <= (ms-1)/2, -mt/2 <= k2 <= (mt-1)/2, 13 | % -mu/2 <= k3 <= (mu-1)/2. 14 | % 15 | % Inputs: 16 | % x,y,z location of NU targets on cube [-3pi,3pi]^3, each length nj 17 | % f size (ms,mt,mu) complex Fourier transform value matrix 18 | % (ordering given by opts.modeord in each dimension; ms fastest to mu 19 | % slowest). 20 | % isign if >=0, uses + sign in exponential, otherwise - sign. 21 | % eps precision requested (>1e-16) 22 | % opts.debug: 0 (silent, default), 1 (timing breakdown), 2 (debug info). 23 | % opts.nthreads sets requested number of threads (else automatic) 24 | % opts.spread_sort: 0 (don't sort NU pts), 1 (do), 2 (auto, default) 25 | % opts.fftw: 0 (use FFTW_ESTIMATE, default), 1 (use FFTW_MEASURE) 26 | % opts.modeord: 0 (CMCL increasing mode ordering, default), 1 (FFT ordering) 27 | % opts.chkbnds: 0 (don't check NU points valid), 1 (do, default). 28 | % opts.upsampfac: either 2.0 (default), or 1.25 (low RAM, smaller FFT size) 29 | % Outputs: 30 | % c complex double array of nj answers at the targets. 31 | % ier - 0 if success, else: 32 | % 1 : eps too small 33 | % 2 : size of arrays to malloc exceed MAX_NF 34 | % other codes: as returned by cnufftspread 35 | 36 | if nargin<7, o=[]; end 37 | opts = finufft_opts(o); 38 | nj=numel(x); 39 | if numel(y)~=nj, error('y must have the same number of elements as x'); end 40 | if numel(z)~=nj, error('z must have the same number of elements as x'); end 41 | [ms,mt,mu]=size(f); 42 | 43 | mex_id_ = 'o int = finufft3d2m(i double, i double[], i double[], i double[], o dcomplex[x], i int, i double, i double, i double, i double, i dcomplex[], i double[])'; 44 | [ier, c] = finufft(mex_id_, nj, x, y, z, isign, eps, ms, mt, mu, f, opts, nj); 45 | 46 | % --------------------------------------------------------------------------- 47 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/matlab/finufft2d1.m: -------------------------------------------------------------------------------- 1 | function [f ier] = finufft2d1(x,y,c,isign,eps,ms,mt,o) 2 | % FINUFFT2D1 3 | % 4 | % [f ier] = finufft2d1(x,y,c,isign,eps,ms,mt) 5 | % [f ier] = finufft2d1(x,y,c,isign,eps,ms,mt,opts) 6 | % 7 | % Type-1 2D complex nonuniform FFT. 8 | % 9 | % nj 10 | % f[k1,k2] = SUM c[j] exp(+-i (k1 x[j] + k2 y[j])) 11 | % j=1 12 | % 13 | % for -ms/2 <= k1 <= (ms-1)/2, -mt/2 <= k2 <= (mt-1)/2. 14 | % 15 | % Inputs: 16 | % x,y locations of NU sources on the square [-3pi,3pi]^2, each length nj 17 | % c size-nj complex array of source strengths 18 | % isign if >=0, uses + sign in exponential, otherwise - sign. 19 | % eps precision requested (>1e-16) 20 | % ms,mt number of Fourier modes requested in x & y; each may be even or odd 21 | % in either case the mode range is integers lying in [-m/2, (m-1)/2] 22 | % opts.debug: 0 (silent, default), 1 (timing breakdown), 2 (debug info). 23 | % opts.nthreads sets requested number of threads (else automatic) 24 | % opts.spread_sort: 0 (don't sort NU pts), 1 (do), 2 (auto, default) 25 | % opts.fftw: 0 (use FFTW_ESTIMATE, default), 1 (use FFTW_MEASURE) 26 | % opts.modeord: 0 (CMCL increasing mode ordering, default), 1 (FFT ordering) 27 | % opts.chkbnds: 0 (don't check NU points valid), 1 (do, default). 28 | % opts.upsampfac: either 2.0 (default), or 1.25 (low RAM, smaller FFT size) 29 | % Outputs: 30 | % f size (ms*mt) double complex array of Fourier transform values 31 | % (ordering given by opts.modeord in each dimension, ms fast, mt slow) 32 | % ier - 0 if success, else: 33 | % 1 : eps too small 34 | % 2 : size of arrays to malloc exceed MAX_NF 35 | % other codes: as returned by cnufftspread 36 | 37 | if nargin<8, o=[]; end 38 | opts = finufft_opts(o); 39 | nj=numel(x); 40 | if numel(y)~=nj, error('y must have the same number of elements as x'); end 41 | if numel(c)~=nj, error('c must have the same number of elements as x'); end 42 | 43 | mex_id_ = 'o int = finufft2d1m(i double, i double[], i double[], i dcomplex[], i int, i double, i double, i double, o dcomplex[xx], i double[])'; 44 | [ier, f] = finufft(mex_id_, nj, x, y, c, isign, eps, ms, mt, opts, ms, mt); 45 | 46 | % ------------------------------------------------------------------------ 47 | -------------------------------------------------------------------------------- /Matlab/functions-solvers/Ewald/EwaldFarVel.m: -------------------------------------------------------------------------------- 1 | % Far field velocity with PSE RPY tensor 2 | function velfar = EwaldFarVel(pts,forces,mu,Lx,Ly,Lz,xi,a,g) 3 | gw=1/(2*xi); 4 | h=gw/1.6; 5 | nx=2^(nextpow2(Lx/h)); 6 | ny=2^(nextpow2(Ly/h)); 7 | nz=2^(nextpow2(Lz/h)); 8 | hx=Lx/nx; 9 | hy=Ly/ny; 10 | hz=Lz/nz; 11 | xE=(0:nx-1)*hx; 12 | yE=(0:ny-1)*hy; 13 | zE=(0:nz-1)*hz; 14 | sup=min(20,nx); % Support of the Gaussian, 12 for 3 digits as Ewald changes 15 | kvx=[0:nx/2-1 -nx/2:-1]*2*pi/Lx; 16 | kvy=[0:ny/2-1 -ny/2:-1]*2*pi/Ly; 17 | kvz=[0:nz/2-1 -nz/2:-1]*2*pi/Lz; 18 | [kx,ky,kz]=meshgrid(kvx,kvy,kvz); 19 | %k=sqrt(kx.^2+ky.^2+kz.^2); 20 | k = sqrt(kx.^2+(ky-g*kx).^2+kz.^2); 21 | %S = SMat(xE,xE,xE,pts,sup,gw); 22 | S = SMatLE(xE,yE,zE,pts,sup,gw,g); 23 | [gridfx, gridfy, gridfz] = spread(S,forces,nx,ny,nz); 24 | fxhat = fftn(gridfx); 25 | fyhat = fftn(gridfy); 26 | fzhat = fftn(gridfz); 27 | % Factor is Eq. (9) in the PSE paper, but removing the Gaussian 28 | % since we are doing that in the spread and interpolate steps 29 | % Careful: matlab has an extra pi in the sinc function 30 | factor = 1/mu*1./k.^2.*(sinc(k*a/pi).^2).*(1+(k.^2)/(4*xi^2)); 31 | factor(1,1,1)=0; 32 | uxhat=factor.*fxhat; 33 | uyhat=factor.*fyhat; 34 | uzhat=factor.*fzhat; 35 | % Project off to get a divergence free field 36 | for iX=1:nx 37 | for iY=1:ny 38 | for iZ=1:nz 39 | if (k(iY,iX,iZ)>0) 40 | ks=[kx(iY,iX,iZ) ky(iY,iX,iZ)-g*kx(iY,iX,iZ) kz(iY,iX,iZ)]; 41 | ks=ks/norm(ks); 42 | usofar=[uxhat(iY,iX,iZ); uyhat(iY,iX,iZ); ... 43 | uzhat(iY,iX,iZ)]; 44 | u_off = (eye(3)-(ks'*ks))*usofar; 45 | uxhat(iY,iX,iZ)=u_off(1); 46 | uyhat(iY,iX,iZ)=u_off(2); 47 | uzhat(iY,iX,iZ)=u_off(3); 48 | end 49 | end 50 | end 51 | end 52 | % IFFT back and interpolate to get the far field 53 | ux=real(ifftn(uxhat)); 54 | uy=real(ifftn(uyhat)); 55 | uz=real(ifftn(uzhat)); 56 | uxpts=interpolate(hx*hy*hz*S,ux,nx,ny,nz); 57 | uypts=interpolate(hx*hy*hz*S,uy,nx,ny,nz); 58 | uzpts=interpolate(hx*hy*hz*S,uz,nx,ny,nz); 59 | velfar=[uxpts uypts uzpts]; 60 | end -------------------------------------------------------------------------------- /Python/Dependencies/finufft/devel/ker_ppval_coeff_mat.m: -------------------------------------------------------------------------------- 1 | function C = ker_ppval_coeff_mat(w,d,be,o) 2 | % KER_PPVAL_COEFF_MAT matrix of piecewise poly ES kernel coeffs 3 | % 4 | % C = ker_ppval_coeff_mat(w,nterms,beta,opts) 5 | % 6 | % Inputs: 7 | % w = integer kernel width in grid points, eg 10 8 | % d = poly degree to keep, eg 13 9 | % beta = kernel parameter, around 2.3*w 10 | % opts - optional struct 11 | % Outputs: 12 | % C = (d+1)*w double-precision matrix of coeffs for ppval 13 | % Each col is (c_0...c_d) in c_0 + c_1z + ... + c_dz^d where |z|<=1 14 | % is the local variable in 1/w units about each grid pt. 15 | 16 | % Barnett 4/23/18 17 | if nargin==0, test_ker_ppval_coeff_mat; return; end 18 | if nargin<4, o=[]; end 19 | 20 | f = @(z) exp(be*sqrt(1-z.^2)); % ES kernel on [-1,1], handles complex 21 | 22 | fitd = 20; % fit degree 23 | m = 7; % colloc pts per wall (4m>deg) 24 | h = 1/w; % size of half a grid spacing, in units where [-1,1] is kernel supp. 25 | C = nan(fitd+1,w); % alloc output 26 | % set up collocation linear sys on a box... 27 | l = 2*((1:m)'-0.5)/m-1; % colloc pts on [-1,1], col vec 28 | z = [l-1i; 1+1i*l; l+1i; -1+1i*l]; % colloc pts on complex bdry box [-1,1]^2 29 | V = ones(4*m,fitd+1); 30 | for k=1:fitd, V(:,k+1) = V(:,k) .* z; end % fill Vandermonde 31 | R = nan(4*m,w); % stack all RHS in the lin sys... 32 | for i=1:w 33 | xi = -1+h*(2*i-1); % center of the i'th expansion, in [-1,1] supp. 34 | R(:,i) = f(xi+z*h); 35 | end 36 | C = V\R; % do all solves for poly coeffs (multiple RHS) 37 | C = C(1:d+1,:); % keep only up to requested eval degree (coeffs 0 to d) 38 | 39 | %%%%%% 40 | function test_ker_ppval_coeff_mat 41 | w=7; d=11; 42 | %w=13; d=15; 43 | beta=2.3*w; % sigma=2 44 | %beta=1.83*w; w=7; d=9; % sigma=5/4 45 | f = @(z) exp(beta*sqrt(1-z.^2)); % must match the above 46 | 47 | C = ker_ppval_coeff_mat(w,d,beta); 48 | %C/exp(beta) % shows that no advantage to truncating any tails... 49 | t = linspace(-1,1,30); % list of offsets in 1/w units 50 | h = 1/w; 51 | maxerr = 0; % track max error of evaluation in pts in all intervals 52 | for i=1:w 53 | xi = -1+h*(2*i-1); % center of the i'th expansion, in [-1,1] supp. 54 | erri = max(abs(f(xi+t*h) - polyval(C(end:-1:1,i),t))); 55 | erri = erri / exp(beta); % scale to rel err to kernel peak 56 | maxerr = max(erri,maxerr); 57 | end 58 | maxerr 59 | -------------------------------------------------------------------------------- /Python/Dependencies/finufft/test/finufft1d_basicpassfail.cpp: -------------------------------------------------------------------------------- 1 | #include "../src/finufft.h" 2 | #include 3 | #include 4 | #include 5 | 6 | // Basic pass-fail test of library. exit code 0 success, failure otherwise. 7 | // This is useful for brew recipe. 8 | // Doesn't use any macros other than finufft.h 9 | // Works for single/double or multi-/single-thread. 10 | // Simplified from Amit Moscovitz and example1d1. Barnett 11/1/18. 11 | 12 | int main() 13 | { 14 | BIGINT M = 1e3, N = 1e3; // defaults: M = # srcs, N = # modes out 15 | double tol = 1e-5; // req tol, covers both single & double prec cases 16 | nufft_opts opts; finufft_default_opts(&opts); // set default opts 17 | int isign = +1; // exponential sign for NUFFT 18 | static const CPX I = CPX(0.0,1.0); // imaginary unit. Note: avoid (CPX) 19 | CPX* F = (CPX*)malloc(sizeof(CPX)*N); // alloc output mode coeffs 20 | 21 | // Make the input data.................................... 22 | FLT* x = (FLT*)malloc(sizeof(FLT)*M); // NU pts locs 23 | CPX* c = (CPX*)malloc(sizeof(CPX)*M); // strengths 24 | for (BIGINT j=0; jFinfnrm) Finfnrm=aF; 44 | } 45 | FLT relerr = abs(F[nout] - Ftest)/Finfnrm; 46 | //printf("requested tol %.3g: rel err for one mode %.3g\n",tol,relerr); 47 | free(x); free(c); free(F); 48 | return (std::isnan(relerr) || relerr > 10.0*tol); // ne.0 -> make test error 49 | } 50 | -------------------------------------------------------------------------------- /docs/OtherExamples.rst: -------------------------------------------------------------------------------- 1 | Examples for numerical tests 2 | =============================== 3 | - CheckStability.py: this example is Section 7.4.3 in `Maxian's PhD thesis `_ 4 | and simulates 1000 fibers in an oscillatory shear flow. This can be used to look at convergence of GMRES at t = 0, or to look at the stability of the hydrodynamics 5 | over time. This is for deterministic suspensions. 6 | - EndToEndFlucts.py: this example is in Section 8.4-5 of Maxian's PhD thesis, and is for fluctuating fibers. 7 | The idea is to simulate the equilibrium fluctuations of 100 (or more/less) fibers, and 8 | look at the equilibrium distribution of end-to-end distance, to check if it matches MCMC. Thus, this file allows you to take an arbitrary mobility and simply 9 | simulate free fluctuations until a certain end time. It will write 2 outputs: the locations of the fibers (for you to analyze end-to-end distance offline), and the 10 | number of GMRES iterations required at each time step to solve the saddle point system (for the constraint forces and mobility). This will be zero if the mobility 11 | is local (on each fiber individually). 12 | - LinearizedFluctuations.py: this example is Section 8.3 of Maxian's PhD thesis, and simulates equilibrium fluctuations of a curved fiber around a base state. 13 | There is a penalty energy which holds the fiber in the base state. It will write the locations of the fiber(s) at every time step, to confirm that the covariance 14 | of the (small) fluctuations is equivalent to what we would expect theoretically (though this comparison would happen offline). 15 | - ThreeShearedFibs.py: this example is Section 7.4.2 in Maxian's PhD thesis 16 | and simulates three fibers being advected by a shear flow. The fibers are not rigid, and so the disturbance flow created from advecting the central fiber 17 | is enough to deform the two fibers outside of it. This represents a good example to test the accuracy of nonlocal hydrodynamic interactions (as is presented 18 | in that section of the thesis). It will write the output file ThreeShearedLocations.txt, which gives the collocation points of each of the three fibers at every 19 | time step. This can be used for convergence plots, etc. This is for deterministic suspensions. 20 | -------------------------------------------------------------------------------- /Matlab/BrownianFlucts/Membrane/InterpFromGrid.m: -------------------------------------------------------------------------------- 1 | % Computes the spread and interpolation matrices by fast Gaussian gridding. 2 | % Vectorized and linear in the number of points. 3 | function InterpVals = InterpFromGrid(xEpts,yEpts,ValsOnGrid,IBpts,gw) 4 | [nPts,~]=size(IBpts); 5 | InterpVals=zeros(nPts,1); 6 | dx=xEpts(2)-xEpts(1); 7 | dy=yEpts(2)-yEpts(1); 8 | sup=2*floor(6*gw/dx); 9 | Nx=length(xEpts); 10 | Ny=length(yEpts); 11 | hex=xEpts(2)-xEpts(1); 12 | hey=yEpts(2)-yEpts(1); 13 | aex=min(xEpts); 14 | aey=min(yEpts); 15 | Lx=max(xEpts)-min(xEpts)+hex; 16 | Ly=max(yEpts)-min(yEpts)+hey; 17 | IBpts = IBpts-floor(IBpts./[Lx Ly]).*[Lx Ly]; % Puts them on [0,L] 18 | down=sup/2-1; 19 | up=sup/2; 20 | oddsup = false; 21 | if (mod(sup,2) == 1) 22 | down = floor(sup/2); 23 | up = down; 24 | oddsup = true; 25 | end 26 | mvals=-down:up; 27 | for ilam=1:nPts 28 | % Fast Gaussian gridding in x and y 29 | floory=mod(floor((IBpts(ilam,2)-aey)/hey+1e-10),Ny)+1; 30 | % correct mvals for when particle is closer to right face of cell i 31 | if oddsup && abs(yEpts(floory) - IBpts(ilam,2)) > hey/2 32 | floory = floory + 1; 33 | end 34 | yclose=yEpts(floory); 35 | % Compute the y weights 36 | E1y = exp(-(IBpts(ilam,2)-yclose)^2/(2*gw^2)); 37 | E2y = exp((IBpts(ilam,2)-yclose)*Ly/(Ny*gw^2)); 38 | ywts = E1y.*E2y.^mvals.*exp(-(mvals.*Ly/Ny).^2/(2*gw^2)); 39 | ypts=floory-down:floory+up; 40 | ypts=mod(ypts,Ny); 41 | ypts(ypts==0)=Ny; 42 | % Compute the x weights 43 | floorx=mod(floor((IBpts(ilam,1)-aex)/hex+1e-10),Nx)+1; 44 | % correct mvals for when particle is closer to right face of cell i 45 | if oddsup && abs(xEpts(floorx) - IBpts(ilam,1)) > hex/2 46 | floorx = floorx + 1; 47 | end 48 | xclose=xEpts(floorx); 49 | E1x = exp(-(IBpts(ilam,1)-xclose)^2/(2*gw^2)); 50 | E2x = exp((IBpts(ilam,1)-xclose)*Lx/(Nx*gw^2)); 51 | xwts = E1x.*E2x.^mvals.*exp(-(mvals.*Lx/Nx).^2/(2*gw^2)); 52 | xpts=floorx-down:floorx+up; 53 | xpts=mod(xpts,Nx); 54 | xpts(xpts==0)=Nx; 55 | xywts=1/(2*pi*gw^2)*(ywts'*xwts).*ValsOnGrid(ypts,xpts)*dx*dy; 56 | InterpVals(ilam)=sum(xywts(:)); 57 | end 58 | end 59 | 60 | --------------------------------------------------------------------------------