Code Monkey home page Code Monkey logo

pygran's Introduction

Welcome to the PyGran webpage!

PyGran is an open-source toolkit primarily designed for analyzing DEM simulation data. In addition to performing basic and custom post-processing, PyGran enables running DEM simulation with LIGGGHTS in Python. It's recommended to use PyGran with Python 3.7 or higher versions. If you wish to use PyGran's mesh capabilities via VTK, Python<=3.8 is recommended.

The main features of PyGran:

  • Interactive DEM simulation and/or analysis using Python
  • Parallel "multiple parameter, single script" simulation for parametrization and sensitivity analysis
  • Intuitive syntax for particle manipulation and analysis (e.g. slicing, concatenating, etc.)
  • Post-processing coupled particle-mesh DEM simulation with VTK
  • Quick and easy plotting of DEM data with matplotlib
  • Support for high-performance computing with MPI

The core modules in PyGran utilize the following stand-alone packages:

  • simulation: provides APIs for running DEM simulation based on the pygran_sim package.
  • analysis: provides routines for post-processing DEM data based on the pygran_analysis package.

If you find PyGran useful in your research, please consider citing the following paper:

DOI for Citing PyGran

@article{aam2019pygran,
  title={PyGran: An object-oriented library for DEM simulation and analysis},
  author={Abi-Mansour, Andrew},
  journal={SoftwareX},
  volume={9},
  pages={168--174},
  year={2019},
  publisher={Elsevier},
  doi={10.1016/j.softx.2019.01.016}
}

Quick Installation

Installing PyGran is quite straight forward on a Unix/Unix-like machine. Just fire up a terminal and then use pip to install PyGran:

pip install pygran

This will install a basic version of pygran. For a full installation (that includes mpi4py, vtk, etc.), run:

pip install pygran[extra]

Basic Usage

Running DEM simulation with LIGGGHTS

PyGran also provides an interface for running DEM simulation with LIGGGHTS. This is achieved by importing the simulation module as shown in the script below for simulating granular flow in a hopper.

from pygran import simulation, params

# Create a DEM object for simulation
sim = simulation.DEM(
    boundary=("f", "f", "f"),
    box=(-1e-3, 1e-3, -1e-3, 1e-3, 0, 4e-3),
    species=(
        {
            "material": params.stearicAcid, 
            "radius": ("constant", 5e-5)},
        ),
    gravity=(9.81, 0, 0, -1),
    mesh={
        "hopper": { # arbitrary mesh name
            "file": "silo.stl", # mesh filename
            "mtype": "mesh/surface", # mesh type
            "material": params.steel, # mesh material
        }
    },
)

# Insert 1000 particles for species 1 (stearic acid)
insert = sim.insert(species=1, value=1000)

# Evolve the system in time
sim.run(nsteps=1e6, dt=1e-7)

Post-processing DEM output data

Using PyGran for doing post-analysis is also quite straight forward. Computing particle overlaps shown below for instance can be done in few lines of code:

from pygran import analysis

# Instantiate a System class from a dump file
sys = analysis.System(Particles='granular.dump')

# Instantiate a nearest-neighbors class
nns = analysis.Neighbors(Particles=sys.Particles)
overlaps = nns.overlaps

For more examples on using PyGran for running DEM simulation, check out the examples page.

Questions or suggestions?

For reporting bugs or suggesting new features/improvements to the code, please open an issue.

pygran's People

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  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

pygran's Issues

bug with pygran

Hello, I already have LIGGHTS installed on my computer, run the examples and display them in ParaView and it worked perfectly. Understanding the LIGGGHTS scripts is difficult, that's why I'm trying to install pygran but it's not working.

Traceback (most recent call last):
File "compaction.py", line 1, in
from pygran import simulation
ModuleNotFoundError: No module named 'pygran'

I read the comments of the other reported bugs and tried this:

pip uninstall pygran -y
pip install pygran[extra]

To confirm you have the right version, run: python -c "import pygran; print('pygran version = ', pygran.version)"

But it still doesn't work:

Traceback (most recent call last):
File "", line 1, in
AttributeError: module 'pygran' has no attribute 'version'

Using pip list yes i see pygran 1.4.0

My goal is to run a triaxial compression test of a sand.

I have windows 11 and install ubuntu from the microsoft store:
Ubuntu 2204.2.33.0
In ubuntu I have two versions of python 3.10.6 and 3.7.17, for recommendations I set version 3.7.17 as the default

I hope you can help me with this installation or give me advice to reach my goal.

Thank you so much.

Esteban Patiño
[email protected]
Civil engineering student
National university of Colombia

"module_list" not defined.

Describe the bug
after:
git clone https://github.com/anabiman/pygran.git
cd pygran
and installing PyGran dependencies with pip:
pip3 install .[extra]

when building 'liggghts' with cython I the following error "Could not cythonize due to error: name 'module_list' is not defined. Make sure Cython is properly installed." Cython has been installed (removed and reinstalled).

Code snippet
python3 setup.py build_liggghts

Expected behavior
'liggghts' should have been cloned and built

Environment (please complete the following information):

  • OS: Windows 11
  • PyGran version: 1.1
  • Python version: [e.g. 3.10.10]

Problems to install

I am using Ubuntu 16.04 LTS and I wasn't able to install PyGran.

I am using the following command:
pip install pygran pygran[extras] pygran[analysis] pygran[sim]

The outcome is the following:

Collecting pygran
Using cached https://files.pythonhosted.org/packages/2c/ee/41befa0979a32ccb9330d7dea64344f8e8beb7f8b7dce0be9ae2030e3809/pygran-1.4.0.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-build-a4koWO/pygran/setup.py", line 97
sys.stdout.write(f"\r{prefix} {percents}% {suffix}")
^
SyntaxError: invalid syntax

----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-a4koWO/pygran/

Could you help me?

ModuleNotFoundError: No module named 'pygran_sim'

I was trying to install PyGran on my laptop following the instructions (Installation example: ubuntu 18.04) from here:
http://andrew-abimansour.github.io/PyGran/docs/introduction.html.
However, on the very last step while making pytest to check if everything was installed properly, next error happened:

pytest -v pygran/tests/test_sim

======================================== test session starts ========================================
platform linux -- Python 3.8.10, pytest-7.1.2, pluggy-1.0.0 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /home/pavel/Desktop/PyGran
plugins: cov-3.0.0
collected 0 items / 1 error

============================================== ERRORS ===============================================
______________________ ERROR collecting pygran/tests/test_sim/test_sim_flow.py ______________________
ImportError while importing test module '/home/pavel/Desktop/PyGran/pygran/tests/test_sim/test_sim_flow.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.8/importlib/init.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
pygran/tests/test_sim/test_sim_flow.py:1: in
from pygran import simulation
../../.local/lib/python3.8/site-packages/pygran/init.py:32: in
from pygran_sim.tools import configure
E ModuleNotFoundError: No module named 'pygran_sim'
========================================= warnings summary ==========================================
../../.local/lib/python3.8/site-packages/pygran/analysis.py:35
/home/pavel/.local/lib/python3.8/site-packages/pygran/analysis.py:35: UserWarning: pygran_analysis uninstalled. Solve by: pip install pygran_analysis.
warnings.warn("pygran_analysis uninstalled. Solve by: pip install pygran_analysis.")

../../.local/lib/python3.8/site-packages/pygran/params.py:35
/home/pavel/.local/lib/python3.8/site-packages/pygran/params.py:35: UserWarning: pygran_params uninstalled. Solve by: pip install pygran_params.
warnings.warn("pygran_params uninstalled. Solve by: pip install pygran_params.")

../../.local/lib/python3.8/site-packages/pygran/simulation.py:35
/home/pavel/.local/lib/python3.8/site-packages/pygran/simulation.py:35: UserWarning: pygran_simulation uninstalled. Solve by: pip install pygran_simulation.
warnings.warn(

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
====================================== short test summary info ======================================
ERROR pygran/tests/test_sim/test_sim_flow.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
=================================== 3 warnings, 1 error in 0.07s ====================================

Environment:

  • OS: Ubuntu 20.04 LTS
  • PyGran version: 1.3.1
  • CPython version: 3.8.10

I would be very thankful for any help with this issue!

Data type bug in cohesionEnergyDensity running hopper demo from installation page

I tried to run the basic hopper simulation demo on the installation page, and it immediately caused errors. I had to change **param['model'] to **param in the DEM instantiation in order to get the input parameters to expand correctly, and to be safe ensured a float type for parameter values that were intended to be floats. (Note: I also had to try to install PyGran using Anaconda (Ubuntu 18.04) and pip, since the pip-only installation example for Ubuntu 18.04 (LTS) resulted in an empty PyGran module being installed, with no parameters or methods, and no "simulation", etc. submodules or demo scripts.) Installation by Anaconda appeared to go well until I tried to validate the code using the basic hopper simulation. The DEM object instantiation failed with the following error trace:

Traceback (most recent call last):
File "hopper_demo.py", line 23, in
sim = simulation.DEM( model=param['model'], boundary=param['boundary'], box=param['box'], species=param['species'], gravity=param['gravity'], mesh=param['mesh'])
File "/home/rose396/.local/lib/python3.7/site-packages/PyGran/simulation/dem.py", line 48, in init
pargs = pargs'model'.params
File "/home/rose396/.local/lib/python3.7/site-packages/PyGran/simulation/models.py", line 439, in init
super(SpringDashpot, self).init(**params)
File "/home/rose396/.local/lib/python3.7/site-packages/PyGran/simulation/models.py", line 166, in init
if type(ss['material'][item]) is not float:
KeyError: 'cohesionEnergyDensity'
(PyGran) rose396@we36233:/PyGran$ gedit hopper_demo.py
(PyGran) rose396@we36233:
/PyGran$ python3 hopper_demo.py
Traceback (most recent call last):
File "hopper_demo.py", line 23, in
sim = simulation.DEM( model=param['model'], boundary=param['boundary'], box=param['box'], species=param['species'], gravity=param['gravity'], mesh=param['mesh'])
File "/home/rose396/.local/lib/python3.7/site-packages/PyGran/simulation/dem.py", line 48, in init
pargs = pargs'model'.params
File "/home/rose396/.local/lib/python3.7/site-packages/PyGran/simulation/models.py", line 439, in init
super(SpringDashpot, self).init(**params)
File "/home/rose396/.local/lib/python3.7/site-packages/PyGran/simulation/models.py", line 166, in init
if type(ss['material'][item]) is not float:
KeyError: 'cohesionEnergyDensity'

Unable to create custom multispheres

I'm trying to create custom non-spherical particles using multispheres. When I run compaction.py (replacing the original species parameters with the line below)

'species': ({'material': organic, 'style': 'multisphere', 'args': ('nspheres 2', 'ntry 1000000 spheres', '0. 0. 0. 0.0002   0. 0. 0.0002 0.0002', 'type 1')}, ),

I get the following stack trace:

Traceback (most recent call last):
  File "multisphere_from_compaction.py", line 53, in <module>
    run(**params)
  File "multisphere_from_compaction.py", line 33, in run
    sim = simulation.DEM(**params)
  File "/home/<user>/.local/lib/python3.6/site-packages/PyGran/simulation/PyGranSim/dem.py", line 192, in __init__
    self.initialize()
  File "/home/<user>/.local/lib/python3.6/site-packages/PyGran/simulation/PyGranSim/dem.py", line 270, in initialize
    self.dem.initialize()
  File "/home/<user>/.local/lib/python3.6/site-packages/PyGran/simulation/PyGranSim/engine_liggghts.py", line 974, in initialize
    self.setupParticles()
  File "/home/<user>/.local/lib/python3.6/site-packages/PyGran/simulation/PyGranSim/engine_liggghts.py", line 530, in setupParticles
    if radius[0] == 'constant':
UnboundLocalError: local variable 'radius' referenced before assignment

On another note, I noticed you put up a new multisphere.py example, but it seems like template_multisphere() is not quite fully functional yet?

Traceback (most recent call last):
  File "multisphere.py", line 68, in <module>
    run(**params)
  File "multisphere.py", line 47, in run
    sim = simulation.DEM(**params)
  File "/home/<user>/.local/lib/python3.6/site-packages/PyGran/simulation/PyGranSim/dem.py", line 70, in __init__
    pargs = pargs['model'](**pargs).params
  File "/home/<user>/.local/lib/python3.6/site-packages/PyGran/simulation/PyGranSim/models.py", line 558, in __init__
    super(SpringDashpot, self).__init__(**params)
  File "/home/<user>/.local/lib/python3.6/site-packages/PyGran/simulation/PyGranSim/models.py", line 242, in __init__
    ss['args'] = template_tablet(ss['nspheres'], ss['radius'], ss['length'])
KeyError: 'nspheres'

I was wondering if this more general template was going to be added to PyGranSim/models.py in the near future.

ValueError: Could not convert string to float #help #value_error

Hi
I am working with Pygran in WSL. Initially I faced the error of latex could not be found. I installed latex then I was able to perform visco elastic and elastoplastic models.
When I try to run an actual dem such as multi-sphere case or another from PyGran examples, I face value error. Please help how this can be resolved.
image

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.