Add granular surfaces built from triangles (3d) or line segments (2d)#4213
Conversation
|
FYI, translating the manual results in the following reported issues: |
|
All doc pages for new commands should have a |
|
@sjplimp FYI, I updated the failing death test for the molecule command to check for the modified error message. |
|
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. |
|
@akohlmey - responses to your comments |
|
@sjplimp You should merge with upstream now so you have the enhanced tokenizer class for more specific pattern matching of molecule file keywords. |
|
@akohlmey done - thanks for the updated Molecule class |
|
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? |
|
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. 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. |
|
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. |
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. |
for particles, you can already control what is output by defining the dump group. 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. |
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. |
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. |
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
Oof that is annoying, I didn't know that. Thanks for cleaning up! Nice to finally have this off my plate. For now... |

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
Further Information, Files, and Links