Skip to content

Add granular surfaces built from triangles (3d) or line segments (2d)#4213

Merged
akohlmey merged 335 commits into
developfrom
granular-triangles
Jun 20, 2026
Merged

Add granular surfaces built from triangles (3d) or line segments (2d)#4213
akohlmey merged 335 commits into
developfrom
granular-triangles

Conversation

@sjplimp

@sjplimp sjplimp commented Jul 1, 2024

Copy link
Copy Markdown
Contributor

Summary

Add capability for granular surfaces to be used in conjunction with granular particle models. Surface in this context mean a collection of triangles (3d) or line segments (2d). This is to allow more geometrically complex objects and boundary conditions to be represented within granular models.

Two flavors of surfaces are planned.

(1) Global surfaces, where a copy of the collection of (large) triangles is stored by every processor.
(2) Local surfaces, where the collection of (small, roughly particle-sized) triangles is distributed across processors
in the same way that particles are.

Related Issue(s)

N/A

Author(s)

Steve, Joel Clemmer (SNL), Dan Bolintineanu (SNL)

Licensing

By submitting this pull request, I agree, that my contribution will be included in LAMMPS and redistributed under either the GNU General Public License version 2 (GPL v2) or the GNU Lesser General Public License version 2.1 (LGPL v2.1).

Backward Compatibility

N/A

Implementation Notes

Post Submission Checklist

  • The feature or features in this pull request is complete
  • Licensing information is complete
  • Corresponding author information is complete
  • The source code follows the LAMMPS formatting guidelines
  • Suitable new documentation files and/or updates to the existing docs are included
  • The added/updated documentation is integrated and tested with the documentation build system
  • The feature has been verified to work with the conventional build system
  • The feature has been verified to work with the CMake based build system
  • Suitable tests have been added to the unittest tree.
  • A package specific README file has been included or updated
  • One or more example input decks are included

Further Information, Files, and Links

@sjplimp sjplimp self-assigned this Jul 1, 2024
@sjplimp sjplimp changed the title Add granular sufaces built from triangles (3d) or line segments (2d) Add granular surfaces built from triangles (3d) or line segments (2d) Jul 1, 2024
@sjplimp
sjplimp requested a review from jtclemm as a code owner July 2, 2024 13:18
@akohlmey

akohlmey commented Jul 3, 2024

Copy link
Copy Markdown
Member

FYI, translating the manual results in the following reported issues:

Fix style entry surface/global is missing or incomplete in Commands_fix.rst
Fix style entry surface/global is missing or incomplete in fix.rst
Found 2 issue(s) with style lists
fix index entry surface/global is missing
Found 1 issue(s) with style index
Found 92 packages
Package GRANSURF missing in Packages_list.rst
Package GRANSURF missing in Packages_details.rst
Found 2 issue(s) with package lists

@akohlmey

akohlmey commented Jul 3, 2024

Copy link
Copy Markdown
Member

All doc pages for new commands should have a .. versionadded:: TBD so that they'll list the version where this feature appeared. For new sections to existing commands, e.g. molecule, the tag should be added with the new paragraph describing the added feature.

@akohlmey

akohlmey commented Jul 3, 2024

Copy link
Copy Markdown
Member

@sjplimp FYI, I updated the failing death test for the molecule command to check for the modified error message.

@akohlmey

akohlmey commented Jul 3, 2024

Copy link
Copy Markdown
Member

I would expect that support for reading triangles from STL files (or converting them to a molecule file?) would be highly desirable by users of this feature. The file format is quite simple and may be text or binary. A simple reader is in tools/std_bin2text.cpp and also in create_atoms.cpp.

@sjplimp

sjplimp commented Jul 5, 2024

Copy link
Copy Markdown
Contributor Author

@akohlmey - responses to your comments
yes, I haven't started working on doc pages yet
re: STL, I agree this is a good idea, I'll add it to the to-do list

@akohlmey akohlmey mentioned this pull request Jul 5, 2024
9 tasks
@akohlmey

Copy link
Copy Markdown
Member

@sjplimp You should merge with upstream now so you have the enhanced tokenizer class for more specific pattern matching of molecule file keywords.
Because of these changes, there is now a merge conflict. I you would prefer to have me do the merge and resolve the conflict, just let me know.

@sjplimp

sjplimp commented Jul 17, 2024

Copy link
Copy Markdown
Contributor Author

@akohlmey done - thanks for the updated Molecule class

@jtclemm
jtclemm marked this pull request as draft November 11, 2024 16:36
@akohlmey

Copy link
Copy Markdown
Member

Here is an attempt for using LAMMPS' graphics facilities with the second demo system.
The added command lines for dump image are:

dump viz all image 1000 myimage-*.png diameter diameter tri index 1 1.0 size 800 600 zoom 3.1 &
   shiny 0.1 fsaa yes view 80 -20 box no 0.0 fix 1 const 2 0.5 center s 0.49883 0.55 0.495547 &
   ssao no 13251 0.3

dump_modify viz pad 9 backcolor black backcolor2 white lights 0.2 0.8 0.6 0.9 fcolor 1 silver &
   color map1 0.282 0.129 0.451 color map2 0.435 0.435 0.556 color map3 0.161 0.686 0.498 &
   color map4 0.741 0.875 0.149 amap min 20 cf 0.0 4 min map1 0.333 map2 0.667 map3 max map4
image
itokawa.webm

@akohlmey

Copy link
Copy Markdown
Member

The one thing I am realizing that we could add to dump image is an option to limit additional graphics elements with a region so you can "cut an STL object open". For the first example this can work already because you have typed tri particles.

@jtclemm

jtclemm commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

The one thing I am realizing that we could add to dump image is an option to limit additional graphics elements with a region so you can "cut an STL object open". For the first example this can work already because you have typed tri particles.

That would be a nice little option. Particularly for containers. Does that exist for fix wall/region with geometric primitives?

And nice images/videos! I'm thinking there might be value using your images in the doc files since they are all-lammps. Thoughts @sjplimp?

Edit: I don't think the asteroid makes for a good LAMMPS example since it's a bit expensive and complicated, but should I add the screw feeder with the dump image commands as an example?

@sjplimp

sjplimp commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

All the new images look nice, both from @jtclemm and @akohlmey I like the screw feeder from Joel best, b/c it shows the triangulation of the feeder more clearly. Maybe that is a setting for the in situ graphics. For the asteroid, both Joel's and Axel's (the one with colored particles) are good. I think the "cut STL open" as in Joel's pic can be done simply by using a geometric region to limit the dump image graphics? Which may be what Joel has done with OVITO? For the images added to the doc page, we should say what graphics tool produced them.

Adding the screw feeder as a LAMMPS example would be good, so that the Howto page pics could point to it.
It could include the dump image commands from Axel.

Finally, I don't think any of this needs to be perfect, we can just go with what you have. It is more important to have the PR released and we can add better or newer images later.

@sjplimp

sjplimp commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

Re: cut the image - what I mean is, doesn't dump_modify region already work with dump image? I thought it did at least for particles.

@jtclemm

jtclemm commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Finally, I don't think any of this needs to be perfect, we can just go with what you have. It is more important to have the PR released and we can add better or newer images later.

Agreed. I'll opt for Axel's current images and include the example with the dump image command. The other Ovito images I generated for the granular paper so those will be used there. As you say, can always improve the dump commands to slice regions later.

I'll work on those updates. In the meantime I also replied to your comments above to fix some issues.

Edit: added the new examples, please let me know what you think.

@akohlmey

Copy link
Copy Markdown
Member

Re: cut the image - what I mean is, doesn't dump_modify region already work with dump image? I thought it did at least for particles.

for particles, you can already control what is output by defining the dump group.
but that would be different by graphics objects that are added through a fix or compute.
I have to review the code.

To answer the question about fix wall/gran/region. We don't have a fix visualization for that but you can visualize the region directly and region visualizations are a totally different beast. I have to re-read the code about how this would work.

Bottom line: the feeder example should be able to "slice" the surfaces with creative definition of the dump group, but the other example not.

I will investigate. It certainly is not something that belongs in this pull request but is a later add-on. Right now everything seems to work well enough for using dump image as it is. Another later option to explore would be to add an option to compute a gradient map as an additional option for smoother surfaces.

@sjplimp

sjplimp commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

@jtclemm new feeder example looks good including adding commented-out in situ graphics
@akohlmey per previous email, from my POV this is ready to merge when Joel approves the PR

@jtclemm

jtclemm commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

@akohlmey per previous email, from my POV this is ready to merge when Joel approves the PR

I made a few more final clean ups and think the PR is ready to be merged (assuming I didn't break any tests). There's undoubtedly more work that could be done, but this PR is big enough so best to save that for later.

@akohlmey akohlmey moved this from In Progress to Ready for Review or Merge in LAMMPS Pull Requests Jun 19, 2026
@akohlmey

Copy link
Copy Markdown
Member

but this PR is big enough so best to save that for later.

There is one annoying detail. This adds the third STL file reader/parser and I would like to consolidate that and use the safer/cleaner text processing tools/classes we have available in LAMMPS.

akohlmey and others added 4 commits June 19, 2026 19:58
LAMMPS had three near-identical STL parsers (copy-and-paste lineage): the
STLReader class used by GRANSURF fix surface/global, an inline parser in
CreateAtoms::add_mesh(), and the text-only parser in MACHDYN
fix smd/wall_surface.  They duplicated the same hand-rolled C-style parsing
(and the same latent bugs -- a collective error->all() call reached from a
single rank and an `fread() <= 0` check on an unsigned result), and only two
of the three supported binary STL.

Replace them with a single STLReader that:

  * exposes a stand-alone, MPI-free, exception-throwing static parser,
    STLReader::parse(), that auto-detects ASCII vs binary STL.  Binary
    detection uses the exact-file-size rule (84 + 50*ntri bytes) rather than
    the fragile "starts with solid" heuristic;
  * builds the ASCII path on the LAMMPS TextFileReader / ValueTokenizer
    infrastructure instead of raw fgets/strtok-style processing, and avoids
    the out-of-bounds pointer arithmetic of the old `line += 6` title parsing
    by using std::string;
  * returns triangles as {normal, 3 vertices}, so all consumers -- including
    MACHDYN, which needs the facet normal -- can share it.  fix surface/global
    keeps its existing read_file() (rank-0 parse + broadcast) API, now
    implemented on top of parse().

CreateAtoms::add_mesh() and fix smd/wall_surface now call the shared parser;
the latter gains binary STL support for free.  Adds unittest/utils/
test_stl_reader.cpp (ASCII, binary, empty solid name, missing file, and several
malformed inputs).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019nii2NLXtpCD2oqS4rrYAX
(cherry picked from commit c2a2ebd841c02c1e69c8ccabcc7c051aeb155dc1)
fix surface/global creates ghost copies of the global surface elements using
orthogonal box-length offsets, so it does not support triclinic boxes.  The
existing check for this was buried inside the first-time ghost-setup branch of
pre_neighbor(); move it to init() so it is verified up front on every run setup
regardless of the ghost code path, with a clearer "not yet supported" message.
fix surface/local genuinely supports triclinic (it distributes particles using
lamda coordinates) and is unaffected.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019nii2NLXtpCD2oqS4rrYAX
test_stl_reader.cpp uses std::array<float,12> but only got the definition
transitively under libstdc++.  MSVC does not pull it in, so the build failed
with C2027/C2036 ("use of undefined type std::array").  Include <array>
explicitly.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019nii2NLXtpCD2oqS4rrYAX
@akohlmey
akohlmey merged commit f2f2286 into develop Jun 20, 2026
9 checks passed
@akohlmey
akohlmey deleted the granular-triangles branch June 20, 2026 00:29
@github-project-automation github-project-automation Bot moved this from Ready for Review or Merge to Done in LAMMPS Pull Requests Jun 20, 2026
@jtclemm

jtclemm commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator

There is one annoying detail. This adds the third STL file reader/parser and I would like to consolidate that and use the safer/cleaner text processing tools/classes we have available in LAMMPS.

Oof that is annoying, I didn't know that. Thanks for cleaning up! Nice to finally have this off my plate.

For now...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

4 participants