minor tweaks simplify algorithm

This commit is contained in:
Axel Kohlmeyer
2022-05-07 17:08:22 -04:00
parent bcfb6734f3
commit 60b9fd2db8
4 changed files with 38 additions and 31 deletions

View File

@ -1023,17 +1023,18 @@ For more details please see the README.md file in that folder.
stl_bin2txt tool
----------------
The file stl_bin2txt.cpp converts binary STL files - like they are frequently
offered for download on the web - into ASCII format STL files that LAMMPS
can read with the :doc:`create_atoms mesh <create_atoms>` or the
:doc:`fix smd/wall_surface` commands. The syntax for running the tool is
The file stl_bin2txt.cpp converts binary STL files - like they are
frequently offered for download on the web - into ASCII format STL files
that LAMMPS can read with the :doc:`create_atoms mesh <create_atoms>` or
the :doc:`fix smd/wall_surface <fix_smd_wall_surface>` commands. The syntax
for running the tool is
.. code-block:: bash
stl_bin2txt infile.stl outfile.stl
which creates outfile.stl from infile.stl. This tool must be compiled
on a platform compatible with the byteordering that was used to create
on a platform compatible with the byte-ordering that was used to create
the binary file. This usually is a so-called little endian hardware
(like x86).

View File

@ -21,7 +21,7 @@ Syntax
*single* args = x y z
x,y,z = coordinates of a single particle (distance units)
*mesh* args = STL-file
STL-file = file with triangle mesh in STL format
STL-file = file with triangle mesh in ASCII STL format
*random* args = N seed region-ID
N = number of particles to create
seed = random # seed (positive integer)
@ -73,7 +73,7 @@ Examples
create_atoms 3 single 0 0 5
create_atoms 1 box var v set x xpos set y ypos
create_atoms 2 random 50 12345 NULL overlap 2.0 maxtry 50
create_atoms 1 mesh funnel.stl units box radiusscale 1.5
create_atoms 1 mesh funnel.stl units box radiusscale 1.1
Description
"""""""""""
@ -86,7 +86,7 @@ alternative to reading in atom coordinates explicitly via a
command. A simulation box must already exist, which is typically
created via the :doc:`create_box <create_box>` command. Before using
this command, a lattice must also be defined using the :doc:`lattice
<lattice>` command, unless you specify the *single* or *mesh* style with
<lattice>` command, unless you specify the *single* style with
units = box or the *random* style. For the remainder of this doc page,
a created atom or molecule is referred to as a "particle".
@ -124,12 +124,20 @@ the specified coordinates. This can be useful for debugging purposes
or to create a tiny system with a handful of particles at specified
positions.
For the *mesh* style, a file with a triangle mesh in `STL format
For the *mesh* style, a file with a triangle mesh in `ASCII STL format
<https://en.wikipedia.org/wiki/STL_(file_format)#ASCII_STL>`_ is read
and a particle is placed into the center of each triangle. If the atom
style in use allows to set a per-atom radius this radius is set to the
largest distance of any of the triangle vertices from its center. The
radius can be adjusted with the *radiussscale* option.
and one or more particles are placed into the area of each triangle.
Binary STL files (e.g. as frequently offered for 3d-printing) can be
converted to ASCII with the :ref:`stl_bin2txt tool <stlconvert>`. The
use of the *units box* option is required and also a :doc:`lattice
<lattice>` must be defined. A particle is created at the center of the
triangle unless the average distance of the triangle vertices from its
center is larger than the lattice spacing in x direction. In that case
the triangle is split into two halves along the its longest side and
each of those two triangles considered for particle insertion. If the
atom style in use allows to set a per-atom radius this radius is set to
the average distance of the triangle vertices from its center times the
value of the *radiussscale* keyword (default: 1.0).
For the *random* style, *N* particles are added to the system at
randomly generated coordinates, which can be useful for generating an

View File

@ -3216,6 +3216,7 @@ Stesmans
stiffnesses
Stillinger
stk
stl
stochastically
stochasticity
Stockmayer

View File

@ -41,12 +41,14 @@
#include <cstring>
using namespace LAMMPS_NS;
using namespace MathConst;
using MathConst::MY_2PI;
using MathConst::MY_PI;
using MathConst::THIRD;
#define BIG 1.0e30
#define EPSILON 1.0e-6
#define LB_FACTOR 1.1
#define DEFAULT_MAXTRY 1000
static constexpr double BIG = 1.0e30;
static constexpr double EPSILON = 1.0e-6;
static constexpr double LB_FACTOR = 1.1;
static constexpr int DEFAULT_MAXTRY = 1000;
enum { BOX, REGION, SINGLE, RANDOM, MESH };
enum { ATOM, MOLECULE };
@ -846,26 +848,21 @@ int CreateAtoms::add_tricenter(const double vert[3][3], tagint molid, double rad
MathExtra::add3(vert[0], vert[1], center);
MathExtra::add3(center, vert[2], temp);
MathExtra::scale3(1.0 / 3.0, temp, center);
MathExtra::scale3(THIRD, temp, center);
MathExtra::sub3(center, vert[0], temp);
const double r1 = MathExtra::len3(temp);
double ravg = MathExtra::len3(temp);
MathExtra::sub3(center, vert[1], temp);
const double r2 = MathExtra::len3(temp);
ravg += MathExtra::len3(temp);
MathExtra::sub3(center, vert[2], temp);
const double r3 = MathExtra::len3(temp);
const double rmin = MIN(MIN(r1, r2), r3);
const double rmax = MAX(MAX(r1, r2), r3);
const double ravg = 1.0 / 3.0 * (r1 + r2 + r3);
ravg += MathExtra::len3(temp);
ravg *= THIRD;
// if the triangle is too large, split it in half along the longest side and recurse
//
// the triangle is considered too large if either the shortest vertex distance from the
// center is larger than lattice parameter or the ratio between longest and shortest is
// larger than 2.0 *and* the longest distance from the center is larger than lattice parameter
// if the average distance of the vertices from the center is larger than the
// lattice parameter, the triangle is split it in half along its longest side
int ilocal = 0;
if ((rmin >= xlat) || ((rmax / rmin >= 1.5) && (rmax >= xlat))) {
if (ravg > xlat) {
double vert1[3][3], vert2[3][3], side[3][3];
// determine side vectors and longest side