1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
/* ----------------------------------------------------------------------
This is the
██╗ ██╗ ██████╗ ██████╗ ██████╗ ██╗ ██╗████████╗███████╗
██║ ██║██╔════╝ ██╔════╝ ██╔════╝ ██║ ██║╚══██╔══╝██╔════╝
██║ ██║██║ ███╗██║ ███╗██║ ███╗███████║ ██║ ███████╗
██║ ██║██║ ██║██║ ██║██║ ██║██╔══██║ ██║ ╚════██║
███████╗██║╚██████╔╝╚██████╔╝╚██████╔╝██║ ██║ ██║ ███████║
╚══════╝╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝®
DEM simulation engine, released by
DCS Computing Gmbh, Linz, Austria
http://www.dcs-computing.com, office@dcs-computing.com
LIGGGHTS® is part of CFDEM®project:
http://www.liggghts.com | http://www.cfdem.com
Core developer and main author:
Christoph Kloss, christoph.kloss@dcs-computing.com
LIGGGHTS® is open-source, distributed under the terms of the GNU Public
License, version 2 or later. It is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. You should have
received a copy of the GNU General Public License along with LIGGGHTS®.
If not, see http://www.gnu.org/licenses . See also top-level README
and LICENSE files.
LIGGGHTS® and CFDEM® are registered trade marks of DCS Computing GmbH,
the producer of the LIGGGHTS® software and the CFDEM®coupling software
See http://www.cfdem.com/terms-trademark-policy for details.
-------------------------------------------------------------------------
Contributing author and copyright for this file:
This file is from LAMMPS
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
------------------------------------------------------------------------- */
#include <cmath>
#include <stdlib.h>
#include <string.h>
#include "region_sphere.h"
#include "update.h"
#include "input.h"
#include "variable.h"
#include "error.h"
#include "force.h"
using namespace LAMMPS_NS;
enum{CONSTANT,VARIABLE};
/* ---------------------------------------------------------------------- */
RegSphere::RegSphere(LAMMPS *lmp, int narg, char **arg) :
Region(lmp, narg, arg)
{
options(narg-6,&arg[6]);
xc = xscale*force->numeric(FLERR,arg[2]);
yc = yscale*force->numeric(FLERR,arg[3]);
zc = zscale*force->numeric(FLERR,arg[4]);
rstr = NULL;
if (strstr(arg[5],"v_") == arg[5]) {
int n = strlen(&arg[5][2]) + 1;
rstr = new char[n];
strcpy(rstr,&arg[5][2]);
radius = 0.0;
rstyle = VARIABLE;
varshape = 1;
variable_check();
shape_update();
} else {
radius = xscale*force->numeric(FLERR,arg[5]);
rstyle = CONSTANT;
}
// error check
if (radius < 0.0) error->all(FLERR,"Illegal region sphere command");
// extent of sphere
// for variable radius, uses initial radius
if (interior) {
bboxflag = 1;
extent_xlo = xc - radius;
extent_xhi = xc + radius;
extent_ylo = yc - radius;
extent_yhi = yc + radius;
extent_zlo = zc - radius;
extent_zhi = zc + radius;
} else bboxflag = 0;
cmax = 1;
contact = new Contact[cmax];
}
/* ---------------------------------------------------------------------- */
RegSphere::~RegSphere()
{
delete [] rstr;
delete [] contact;
}
/* ---------------------------------------------------------------------- */
void RegSphere::init()
{
Region::init();
if (rstr) variable_check();
}
/* ----------------------------------------------------------------------
inside = 1 if x,y,z is inside or on surface
inside = 0 if x,y,z is outside and not on surface
------------------------------------------------------------------------- */
int RegSphere::inside(double x, double y, double z)
{
double delx = x - xc;
double dely = y - yc;
double delz = z - zc;
double r = sqrt(delx*delx + dely*dely + delz*delz);
if (r <= radius) return 1;
return 0;
}
/* ----------------------------------------------------------------------
one contact if 0 <= x < cutoff from inner surface of sphere
no contact if outside (possible if called from union/intersect)
delxyz = vector from nearest point on sphere to x
special case: no contact if x is at center of sphere
------------------------------------------------------------------------- */
int RegSphere::surface_interior(double *x, double cutoff)
{
double delx = x[0] - xc;
double dely = x[1] - yc;
double delz = x[2] - zc;
double r = sqrt(delx*delx + dely*dely + delz*delz);
if (r > radius || r == 0.0) return 0;
double delta = radius - r;
if (delta < cutoff) {
contact[0].r = delta;
contact[0].delx = delx*(1.0-radius/r);
contact[0].dely = dely*(1.0-radius/r);
contact[0].delz = delz*(1.0-radius/r);
return 1;
}
return 0;
}
/* ----------------------------------------------------------------------
one contact if 0 <= x < cutoff from outer surface of sphere
no contact if inside (possible if called from union/intersect)
delxyz = vector from nearest point on sphere to x
------------------------------------------------------------------------- */
int RegSphere::surface_exterior(double *x, double cutoff)
{
double delx = x[0] - xc;
double dely = x[1] - yc;
double delz = x[2] - zc;
double r = sqrt(delx*delx + dely*dely + delz*delz);
if (r < radius) return 0;
double delta = r - radius;
if (delta < cutoff) {
contact[0].r = delta;
contact[0].delx = delx*(1.0-radius/r);
contact[0].dely = dely*(1.0-radius/r);
contact[0].delz = delz*(1.0-radius/r);
return 1;
}
return 0;
}
/* ----------------------------------------------------------------------
change region shape via variable evaluation
------------------------------------------------------------------------- */
void RegSphere::shape_update()
{
radius = xscale * input->variable->compute_equal(rvar);
if (radius < 0.0)
error->one(FLERR,"Variable evaluation in region gave bad value");
}
/* ----------------------------------------------------------------------
error check on existence of variable
------------------------------------------------------------------------- */
void RegSphere::variable_check()
{
rvar = input->variable->find(rstr);
if (rvar < 0)
error->all(FLERR,"Variable name for region sphere does not exist");
if (!input->variable->equalstyle(rvar))
error->all(FLERR,"Variable for region sphere is invalid style");
}
|