anabiman / pygran

A DEM toolkit for rapid simulation & quantitative analysis of granular systems
http://pygran.org
GNU General Public License v2.0
75 stars 16 forks source link

Unable to create custom multispheres #5

Closed fcgrogan closed 4 years ago

fcgrogan commented 4 years ago

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.

anabiman commented 4 years ago

Your code should work just fine. Can you please specify which version of PyGran you're using? The recently added "multisphere.py" example also works without any problems in v1.2.2 and above.

fcgrogan commented 4 years ago

I'm using v1.2.1 on Ubuntu 18.04.

I just noticed in "CHANGELOG.md" it says "New interface for user-defined functions used in multisphere particles" under v1.2.2. I updated PyGran according to the instructions you provided on another issue (or at least thought I did) as the final step pip3 install . --upgrade gave me the following

Processing /home/<user>/PyGran
Collecting numpy (from PyGran==1.2.2)
  Using cached https://files.pythonhosted.org/packages/62/20/4d43e141b5bc426ba38274933ef8e76e85c7adea2c321ecf9ebf7421cedf/numpy-1.18.1-cp36-cp36m-manylinux1_x86_64.whl
Collecting scipy (from PyGran==1.2.2)
  Using cached https://files.pythonhosted.org/packages/dc/29/162476fd44203116e7980cfbd9352eef9db37c49445d1fec35509022f6aa/scipy-1.4.1-cp36-cp36m-manylinux1_x86_64.whl
Installing collected packages: numpy, scipy, PyGran
  Running setup.py install for PyGran ... done
Successfully installed PyGran-1.2.2 numpy-1.18.1 scipy-1.4.1

However, "multisphere.py" still failed in the same way, and when I checked

import PyGran._version
PyGran._version.__version__

it still said I had v1.2.1. I'm assuming this means I messed up the upgrade and am still only on v1.2.1. However, I'm still unable to get "multisphere.py" to work on v1.2.1 (stack trace the same as the above post).

anabiman commented 4 years ago

I see where the problem is right now. v1.2.2 is still experimental, i.e. I have not yet packaged it via pypi. It's only available from github for now. Plz try to remove pygran completely via: "pip uninstall pygran". Then clone the pygran repo and run from the source dir: "pip install . --user".

anabiman commented 4 years ago
pip uninstall pygran
git clone https://github.com/Andrew-AbiMansour/PyGran
cd PyGran
git submodule init
git submodule update
pip install . --user
fcgrogan commented 4 years ago

Thank you for your help! I upgraded to v1.2.2 and was able to run 'multisphere.py' (it did give me "WARNING: Energy calculated for multisphere particles is currently not correct (../fix_multisphere.cpp:1312)", but this is from LIGGGHTS.log, not PyGran).

anabiman commented 4 years ago

Yup that's a feature still in the works in LIGGGHTS v3.8.0. If you encounter any other problems, plz feel free to report them as new issues.