Git Product home page Git Product logo

rajeshrinet / pystokes Goto Github PK

View Code? Open in Web Editor NEW
44.0 7.0 17.0 54.21 MB

PyStokes: phoresis and Stokesian hydrodynamics in Python. github.com/rajeshrinet/pystokes

Home Page: https://pystokes.readthedocs.io

License: MIT License

Python 3.34% Makefile 0.25% Cython 96.41%
hydrodynamic-interactions phoretic-interactions force-fields stokesian-hydrodynamics active-particles colloids stokes-flow traction python cython

pystokes's Introduction

Imagel

PyStokes: phoresis and Stokesian hydrodynamics in Python

Installation Notebooks Documentation Status DOI PyPI Downloads Stars Forks

About | Installation | Documentation | Examples | Publications | Gallery | Support | License

About

PyStokes is a numerical library for phoresis and Stokesian hydrodynamics in Python. It uses a grid-free method, combining the integral representation of Laplace and Stokes equations, spectral expansion, and Galerkin discretization, to compute phoretic and hydrodynamic interactions between spheres with slip boundary conditions on their surfaces. The library also computes suspension scale quantities, such as rheological response, energy dissipation and fluid flow. The computational cost is quadratic in the number of particles and upto 1e5 particles have been accommodated on multicore computers. The library has been used to model suspensions of microorganisms, synthetic autophoretic particles and self-propelling droplets.

You can take PyStokes for a spin online using Google Colab: Open In Colab


Please read the PyStokes paper and Wiki before you use PyStokes for your research. Included below are some examples from PyStokes Gallery:

Periodic orbits of active particles

Image

Our work shows that the oscillatory dynamics of a pair of active particles near a boundary, best exemplified by the fascinating dance of the green algae Volvox, can be understood in terms of Hamiltonian mechanics, even though the system does not conserve energy. Read more in the PyStokes Gallery.

Crystallization at a plane no-slip surface

It is well-known that crystallization of colloids approximating hard spheres is due, paradoxically, to the higher entropy of the ordered crystalline state compared to that of the disordered liquid state. Out of equilibrium, no such general principle is available to rationalize crystallization. In this work, we identify a new non-equilibrium mechanism, associated with entropy production rather than entropy gain, which drives crystallization of active colloids near plane walls. Read more in the PyStokes Gallery.

Crystallization of active colloids

News

26th July 2019 -- PyStokes can compute hydrodynamic and phoretic interactions in autophoretic suspensions.

Installation

From a checkout of this repo

Install PyStokes and an extended list of dependencies using

>> git clone https://github.com/rajeshrinet/pystokes.git
>> cd pystokes
>> pip install -r requirements.txt
>> python setup.py install

Install PyStokes and its dependencies in an environment named "pystokes" via Anaconda

>> git clone https://github.com/rajeshrinet/pystokes.git
>> cd pystokes
>> make env
>> conda activate pystokes
>> make

Via pip

Install the latest PyPI version

>> pip install pystokes

Testing

Test installation and running

>> cd tests
>> python test_short.py

Long test of example notebooks

>> cd tests
>> python test_notebooks.py

Examples

# Example 1: Flow field due to $2s$ mode of active slip
import pystokes, numpy as np, matplotlib.pyplot as plt

# particle radius, self-propulsion speed, number and fluid viscosity
b, eta, N = 1.0, 1.0/6.0, 1

# initialize
r, p = np.array([0.0, 0.0, 3.4]), np.array([0.0, 1.0, 0])
V2s  = pystokes.utils.irreducibleTensors(2, p)

# space dimension , extent , discretization
dim, L, Ng = 3, 10, 64;

# instantiate the Flow class
flow = pystokes.wallBounded.Flow(radius=b, particles=N, viscosity=eta, gridpoints=Ng*Ng)

# create grid, evaluate flow and plot
rr, vv = pystokes.utils.gridYZ(dim, L, Ng)
flow.flowField2s(vv, rr, r, V2s)  
pystokes.utils.plotStreamlinesYZsurf(vv, rr, r, offset=6-1, density=1.4, title='2s')
#Example 2: Phoretic field due to active surface flux of l=0 mode
import pystokes, numpy as np, matplotlib.pyplot as plt
# particle radius, fluid viscosity, and number of particles
b, eta, N = 1.0, 1.0/6.0, 1

#initialise
r, p = np.array([0.0, 0.0, 5]), np.array([0.0, 0.0, 1])
J0 = np.ones(N)  # strength of chemical monopolar flux

# space dimension , extent , discretization
dim, L, Ng = 3, 10, 64;

# instantiate the Flow class
phoreticField = pystokes.phoretic.unbounded.Field(radius=b, particles=N, phoreticConstant=eta, gridpoints=Ng*Ng)

# create grid, evaluate phoretic field and plot
rr, vv = pystokes.utils.gridYZ(dim, L, Ng)
phoreticField.phoreticField0(vv, rr, r, J0)  
pystokes.utils.plotContoursYZ(vv, rr, r, density=.8, offset=1e-16,  title='l=0') 

Other examples include

Publications

A selected list of publications is given below. See full publication list here.

Support

  • For help with and questions about PyStokes, please post to the pystokes-users group.
  • For bug reports and feature requests, please use the issue tracker on GitHub.

License

We believe that openness and sharing improves the practice of science and increases the reach of its benefits. This code is released under the MIT license. Our choice is guided by the excellent article on Licensing for the scientist-programmer.

pystokes's People

Contributors

harpolea avatar khinsen avatar rajeshrinet avatar ronojoy avatar takodas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pystokes's Issues

Reporting coverage

I'm not sure how much effort would be required for this, but it would be great to automatically generate a code coverage report so you could see what proportion of the code is currently covered by tests.

If this was a pure Python library, it would be very straightforward using coverage to generate the coverage info and codecov to produce reports.

However, because this is a Cython library, I am not sure what would be required to get coverage reporting up-and-running, so for now this is only open as a suggestion.

Dependencies not specified in setup.py

Sorry for another (similar) issue!

When following instructions to install from a checkout of the repo:

>> git clone https://github.com/rajeshrinet/pystokes.git
>> cd pystokes
>> python setup.py install

I am unable to

>> make test

because Matplotlib is missing.

Not sure where the requirements are currently specified: matplotlib is in the requirements.txt it looks as though setup.py does not look in there by default.

I'm not sure exactly how to solve this. Easiest would be to document for users to run:

pip install -r requirements.txt

Else if using pip to install you could specify install_requires in setup.py (which I see is currently commented out).

installation via pip broken

Several months ago I managed to install pystokes using pip with no issue. Currently this is not working. Installation steps:

  1. Created a virtual enviroment and upgaded pip to 24.0
  2. pip install pystokes
    Relevant output:
Collecting pystokes
  Downloading pystokes-2.3.0.tar.gz (2.4 MB)
Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error
  
  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [27 lines of output]
      Traceback (most recent call last):
        File "/home/XXX/virtual/pystokes/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/home/XXX/virtual/pystokes/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/XXX/virtual/pystokes/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-notslatr/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 325, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-notslatr/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 295, in _get_build_requires
          self.run_setup()
        File "/tmp/pip-build-env-notslatr/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 487, in run_setup
          super().run_setup(setup_script=setup_script)
        File "/tmp/pip-build-env-notslatr/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 311, in run_setup
          exec(code, locals())
        File "<string>", line 98, in <module>
        File "/tmp/pip-build-env-notslatr/overlay/lib/python3.11/site-packages/Cython/Build/Dependencies.py", line 1010, in cythonize
          module_list, module_metadata = create_extension_list(
                                         ^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-notslatr/overlay/lib/python3.11/site-packages/Cython/Build/Dependencies.py", line 845, in create_extension_list
          for file in nonempty(sorted(extended_iglob(filepattern)), "'%s' doesn't match any files" % filepattern):
        File "/tmp/pip-build-env-notslatr/overlay/lib/python3.11/site-packages/Cython/Build/Dependencies.py", line 117, in nonempty
          raise ValueError(error_msg)
      ValueError: 'pystokes/power/*.pyx' doesn't match any files
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

pip install fails without cython installed

The instructions in the README to install using pip fail in a clean virtual environment. To reproduce:

python3 -m venv venv
source venv/bin/activate
pip install pystokes

This fails due to

ModuleNotFoundError: No module named 'Cython'

This is due to setup.py requiring Cython before it gets around to installing it as a dependency.

See here for more info about the problem:
http://docs.cython.org/en/latest/src/userguide/source_files_and_compilation.html#basic-setup-py

I've not dealt with this directly before, but it might be sufficient to create a pyproject.toml as suggested.

Provide instructions for contributing

JOSS requires "clear guidelines for third parties wishing to 1) Contribute to the software 2) Report issues or problems with the software 3) Seek support". 2) and 3) are discussed in the README, but I didn't find guidelines for potential contributors.

Update and document examples/other

The main example notebooks work fine, and are well documented. Under examples/other, there is additional example code that is not up to date (benchmarks/potDipole.py is for Python 2 and apparently a very old version of PyStokes, mima2d examples don't work for whatever reason). With the exception of periodic, there is no explanation either of what these examples are good for.

Request for forming the full linear system so that the full system can be solved through linear algebra solvers

We want to request the fully coupled linear system (say the 47N*47N dense matrix for l=3) to be solved (or at least get the linear system assembled and we can pass to an external solver) so that we can get desired accuracy.

Some comments from Aleks in a list of emails discussing with Ronojoy,

Note that even if mat-vec product is O(N^2) and you use an iterative method like Conjugate Gradient, there is no reason to believe it will converge in O(1) iterations and thus be O(N^2) overall (though the wall screens hydrodynamic interactions so it may be). We have had a lot of luck with block-diagonal preconditioners though as we have discussed in the past, and this should work here too and help a lot. So in principle if one can write a matrix-vector product (which sounds like you more or less have already) and just assemble the dense (47*N)^2 matrices for each particle (the block diagonal blocks), this should be good enough to get a full solve easily in python.

What we need is an accurate mobility solver, i.e., we know forces and torques and slip, and want to get motion. This may require perhaps slight massaging of the linear system.

License copyright information

@rajeshrinet just checking the license for the purpose of the JOSS review.

I see that the copyright information is Rajesh Singh, and this may be completely correct. I just wanted to double check this, and that it should not be an institution? (For instance, I know that at Oxford I do not own the copyright to projects I work on.)

Optional dependency OdesPy

The instructions for installation from source mention OdesPy as an optional dependency, but don't say what difference OdesPy makes. Does it add functionality? Improve performance? As a JOSS reviewer, should I test PyStokes with or without OdesPy?

Recommend Projects

  • React photo React

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

  • Vue.js photo Vue.js

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

  • Typescript photo Typescript

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

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

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

Recommend Topics

  • javascript

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

  • web

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

  • server

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

  • Machine learning

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

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

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

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.