59 #ifndef MADNESS_MRA_SDF_SHAPE_3D_H__INCLUDED
60 #define MADNESS_MRA_SDF_SHAPE_3D_H__INCLUDED
79 : normal(normal*(1.0/
sqrt(normal[0]*normal[0] + normal[1]*normal[1] + normal[2]*normal[2])))
90 return (pt[0]-point[0])*normal[0] + (pt[1]-point[1])*normal[1] + (pt[2]-point[2])*normal[2];
129 for(i = 0; i < 3; ++i) {
130 temp = pt[i] - center[i];
142 double x = pt[0] - center[0];
143 double y = pt[1] - center[1];
144 double z = pt[2] - center[2];
145 double r =
sqrt(x*x + y*y + z*z);
176 , dir(direc*(1.0/
sqrt(direc[0]*direc[0] + direc[1]*direc[1] + direc[2]*direc[2])))
191 for(i = 0; i < 3; ++i)
192 diff[i] = pt[i] - apex[i];
194 dotp = diff[0]*dir[0] + diff[1]*dir[1] + diff[2]*dir[2];
196 for(i = 0; i < 3; ++i)
197 diff[i] -= dotp * dir[i];
199 return sqrt(diff[0]*diff[0] + diff[1]*diff[1] + diff[2]*diff[2])
236 , dir(direc*(1.0/
sqrt(direc[0]*direc[0] + direc[1]*direc[1] + direc[2]*direc[2])))
288 long double lambda, dist, temp[2], upper;
289 std::vector<long double> roots;
296 long double c = (
long double)this->c;
298 for(i = 0; i < 3; ++i)
299 diff[i] = pt[i] - apex[i];
301 dotp = diff[0]*dir[0] + diff[1]*dir[1] + diff[2]*dir[2];
303 for(i = 0; i < 3; ++i)
304 diff[i] -= dotp * dir[i];
306 d = diff[0]*diff[0] + diff[1]*diff[1] + diff[2]*diff[2]
315 upper = (4.0L*dotp +
c) * 0.5
L / c;
317 for(std::vector<long double>::iterator iter = roots.begin();
318 iter != roots.end(); ++iter) {
323 if(temp[0] <= upper) {
326 temp[1] = c*(dotp - temp[0]*c*0.5L + c*0.25L);
333 temp[1] =
fabs(temp[0])*
sqrt(temp[1]);
351 MADNESS_ASSERT(n > 0);
356 return (
double)(-dist);
395 const long double d,
const long double z)
const {
397 long double lower, upper, bound;
398 std::vector<long double> roots(0);
399 long double derivroot1, derivroot2, temp;
400 bool hasregion2, keepgoing, foundroot;
404 upper =
fabs(c - 2.0
L*z);
405 hasregion2 = (upper >= 1.0e-10
L);
407 derivroot1 = (lower - upper) / (3.0
L*c);
408 derivroot2 = (lower + upper) / (3.0
L*c);
416 if(
fabs(bound) < zero) {
418 roots.push_back(upper);
427 lower = upper + temp;
429 if(
fabs(bound) < zero) {
431 roots.push_back(lower);
436 keepgoing = (bound > 0.0L);
444 temp =
find_root(lower, upper, c, d, z,
true);
445 roots.push_back(temp);
459 if(lower > 0.0
L && upper < 0.0
L) {
460 temp =
find_root(lower, upper, c, d, z,
false);
461 roots.push_back(temp);
471 if(
fabs(bound) < zero) {
473 roots.push_back(lower);
481 upper = lower + temp;
483 if(
fabs(bound) < zero) {
485 roots.push_back(upper);
490 keepgoing = (bound < 0.0L);
498 temp =
find_root(lower, upper, c, d, z,
true);
499 roots.push_back(temp);
521 long double find_root(
long double lower,
long double upper,
522 const long double c,
const long double d,
523 const long double z,
bool dir)
const {
525 long double value, middle;
527 middle = 0.5L*(upper + lower);
530 if(
fabs(value) < zero)
545 }
while(
fabs(upper-lower) > rootzero);
562 long double eval_cubic(
const long double x,
const long double c,
563 const long double d,
const long double z)
565 return ((c*0.5
L*x - (c + z))*x + (2.0
L*z + c*0.5
L))*c*x + d;
585 const long double d,
const long double z)
587 return c*((1.5L*c*x - 2.0L*(c+z))*x + 2.0L*z + 0.5L*
c);
605 : lengths(length*0.5), center(center)
620 max =
fabs(pt[0] - center[0]) - lengths[0];
621 for(i = 1; i < 3; ++i) {
622 diff =
fabs(pt[i] - center[i]) - lengths[i];
683 for(i = 0; i < 3; ++i) {
684 quot = (pt[i] - center[i]) / radii[i];
720 , axis(axis*(1.0/
sqrt(axis[0]*axis[0] + axis[1]*axis[1] + axis[2]*axis[2])))
737 for(i = 0; i < 3; ++i) {
738 rel[i] = pt[i] - center[i];
739 dist += rel[i] * axis[i];
743 for(i = 0; i < 3; ++i)
744 radial[i] = rel[i] - dist * axis[i];
746 return std::max(
fabs(dist) - a,
sqrt(radial[0]*radial[0] + radial[1]*radial[1]
747 + radial[2]*radial[2]) - radius);
761 #endif // MADNESS_MRA_SDF_SHAPE_3D_H__INCLUDED
const coord_3d center
the center of the box
Definition: sdf_shape_3D.h:597
SDFParaboloid(const double c, const coord_3d &apex, const coord_3d &direc)
Constructor for paraboloid.
Definition: sdf_shape_3D.h:233
const coord_3d normal
The normal vector pointing OUTSIDE the surface.
Definition: sdf_shape_3D.h:69
const long double zero
Numerical zero for root-finding in sdf.
Definition: sdf_shape_3D.h:224
double sdf(const coord_3d &pt) const
Computes the normal distance.
Definition: sdf_shape_3D.h:730
const double radius
Radius of sphere.
Definition: sdf_shape_3D.h:105
A spherical surface (3 dimensions)
Definition: sdf_shape_3D.h:103
coord_3d grad_sdf(const coord_3d &pt) const
Definition: sdf_shape_3D.h:695
NDIM const Function< R, NDIM > & g
Definition: mra.h:2179
A paraboloid (3 dimensions)
Definition: sdf_shape_3D.h:219
const coord_3d lengths
Half the length of each side of the box.
Definition: sdf_shape_3D.h:596
const coord_3d point
A point in the plane.
Definition: sdf_shape_3D.h:70
const double c
Curvature/radius of the surface.
Definition: sdf_shape_3D.h:222
const double L
Definition: 3dharmonic.cc:123
SDFPlane(const coord_3d &normal, const coord_3d &point)
SDF for a plane transecting the entire simulation volume.
Definition: sdf_shape_3D.h:78
const coord_3d center
Center of sphere.
Definition: sdf_shape_3D.h:106
coord_3d grad_sdf(const coord_3d &pt) const
Definition: sdf_shape_3D.h:754
SDFSphere(const double radius, const coord_3d ¢er)
SDF for a sphere.
Definition: sdf_shape_3D.h:113
coord_3d grad_sdf(const coord_3d &pt) const
Computes the gradient of the SDF.
Definition: sdf_shape_3D.h:207
double sdf(const coord_3d &pt) const
Computes the normal distance.
Definition: sdf_shape_3D.h:678
SDFCube(const double length, const coord_3d ¢er)
Constructor for box.
Definition: sdf_shape_3D.h:648
Defines abstract interfaces and concrete classes signed distance functions and domain masks...
const long double rootzero
Numerical zero for the roots.
Definition: sdf_shape_3D.h:225
SDFCylinder(const double radius, const double length, const coord_3d &axpt, const coord_3d &axis)
Constructor for cylinder.
Definition: sdf_shape_3D.h:716
const coord_3d apex
The apex.
Definition: sdf_shape_3D.h:221
An ellipsoid (3 dimensions)
Definition: sdf_shape_3D.h:656
A cone (3 dimensions)
Definition: sdf_shape_3D.h:161
double sdf(const coord_3d &pt) const
Computes the normal distance.
Definition: sdf_shape_3D.h:616
const coord_3d dir
The direction of the axis, from the apex INSIDE.
Definition: sdf_shape_3D.h:165
const coord_3d apex
The apex.
Definition: sdf_shape_3D.h:163
SDFBox(const coord_3d &length, const coord_3d ¢er)
Constructor for box.
Definition: sdf_shape_3D.h:604
coord_3d radii
the directional radii
Definition: sdf_shape_3D.h:658
coord_3d center
the central axial point of the cylinder (distance a from both ends)
Definition: sdf_shape_3D.h:705
long double eval_cubic_deriv(const long double x, const long double c, const long double d, const long double z) const
Evaluates the derivative of the cubic equation for the Lagrangian multipliers.
Definition: sdf_shape_3D.h:584
The interface for a signed distance function (sdf).
Definition: sdf_domainmask.h:74
SDFEllipsoid(const coord_3d &radii, const coord_3d ¢er)
Constructor for ellipsoid.
Definition: sdf_shape_3D.h:666
const double c
The radius.
Definition: sdf_shape_3D.h:164
#define max(a, b)
Definition: lda.h:53
SDFCone(const double c, const coord_3d &apex, const coord_3d &direc)
Constructor for cone.
Definition: sdf_shape_3D.h:173
double a
half the length of the cylinder
Definition: sdf_shape_3D.h:704
std::vector< long double > get_roots(const long double c, const long double d, const long double z) const
Finds real root(s) of the cubic polynomial in the sdf function.
Definition: sdf_shape_3D.h:394
A cube (3 dimensions)
Definition: sdf_shape_3D.h:642
A cylinder (3 dimensions)
Definition: sdf_shape_3D.h:701
double sdf(const coord_3d &pt) const
Computes the normal distance.
Definition: sdf_shape_3D.h:186
coord_3d grad_sdf(const coord_3d &pt) const
Computes the gradient of the SDF.
Definition: sdf_shape_3D.h:363
double sdf(const coord_3d &pt) const
Computes the normal distance.
Definition: sdf_shape_3D.h:124
coord_3d center
the center
Definition: sdf_shape_3D.h:659
tensorT sqrt(const tensorT &s, double tol=1e-8)
Computes matrix square root (not used any more?)
Definition: DFcode/moldft.cc:446
coord_3d grad_sdf(const coord_3d &pt) const
Computes the gradient of the SDF.
Definition: sdf_shape_3D.h:97
coord_3d grad_sdf(const coord_3d &pt) const
Definition: sdf_shape_3D.h:634
double sdf(const coord_3d &pt) const
Computes the normal distance.
Definition: sdf_shape_3D.h:282
long double find_root(long double lower, long double upper, const long double c, const long double d, const long double z, bool dir) const
Definition: sdf_shape_3D.h:521
const mpreal sum(const mpreal tab[], unsigned long int n, mp_rnd_t rnd_mode)
Definition: mpreal.cc:241
double sdf(const coord_3d &pt) const
Computes the normal distance.
Definition: sdf_shape_3D.h:89
A box (3 dimensions)
Definition: sdf_shape_3D.h:594
A plane surface (3 dimensions)
Definition: sdf_shape_3D.h:67
coord_3d grad_sdf(const coord_3d &pt) const
Computes the gradient of the SDF.
Definition: sdf_shape_3D.h:141
coord_3d axis
the axial direction of the cylinder
Definition: sdf_shape_3D.h:706
#define MADNESS_EXCEPTION(msg, value)
Definition: worldexc.h:88
long double eval_cubic(const long double x, const long double c, const long double d, const long double z) const
Evaluates the cubic equation for the Lagrangian multipliers.
Definition: sdf_shape_3D.h:562
const coord_3d dir
The direction of the axis, from the apex INSIDE.
Definition: sdf_shape_3D.h:223
double radius
the radius of the cylinder
Definition: sdf_shape_3D.h:703
const mpreal fabs(const mpreal &v, mp_rnd_t rnd_mode)
Definition: mpreal.h:2187
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45