59#ifndef MADNESS_MRA_SDF_SHAPE_3D_H__INCLUDED
60#define MADNESS_MRA_SDF_SHAPE_3D_H__INCLUDED
129 for(i = 0; i < 3; ++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)
196 for(i = 0; i < 3; ++i)
236 ,
dir(direc*(1.0/sqrt(direc[0]*direc[0] + direc[1]*direc[1] + direc[2]*direc[2])))
290 std::vector<long double> roots;
297 long double c = (
long double)this->c;
299 for(i = 0; i < 3; ++i)
304 for(i = 0; i < 3; ++i)
316 upper = (4.0L*dotp +
c) * 0.5L /
c;
318 for(std::vector<long double>::iterator iter = roots.begin();
319 iter != roots.end(); ++iter) {
324 if(temp[0] <=
upper) {
327 temp[1] =
c*(dotp - temp[0]*
c*0.5L +
c*0.25L);
334 temp[1] =
std::abs(temp[0])*sqrt(temp[1]);
357 return (
double)(-
dist);
396 const long double d,
const long double z)
const {
399 std::vector<long double> roots(0);
400 long double derivroot1, derivroot2, temp;
401 bool hasregion2, keepgoing, foundroot;
406 hasregion2 = (
upper >= 1.0e-10L);
419 roots.push_back(
upper);
432 roots.push_back(
lower);
437 keepgoing = (bound > 0.0L);
446 roots.push_back(temp);
462 roots.push_back(temp);
474 roots.push_back(
lower);
486 roots.push_back(
upper);
491 keepgoing = (bound < 0.0L);
500 roots.push_back(temp);
523 const long double c,
const long double d,
524 const long double z,
bool dir)
const {
526 long double value, middle;
564 const long double d,
const long double z)
566 return ((
c*0.5L*x - (
c + z))*x + (2.0L*z +
c*0.5L))*
c*x +
d;
586 const long double d,
const long double z)
588 return c*((1.5L*
c*x - 2.0L*(
c+z))*x + 2.0L*z + 0.5L*
c);
622 for(i = 1; i < 3; ++i) {
684 for(i = 0; i < 3; ++i) {
738 for(i = 0; i < 3; ++i) {
739 rel[i] = pt[i] -
center[i];
744 for(i = 0; i < 3; ++i)
745 radial[i] = rel[i] -
dist *
axis[i];
747 return std::max(fabs(
dist) -
a, sqrt(radial[0]*radial[0] + radial[1]*radial[1]
748 + radial[2]*radial[2]) -
radius);
A box (3 dimensions)
Definition sdf_shape_3D.h:595
double sdf(const coord_3d &pt) const
Computes the normal distance.
Definition sdf_shape_3D.h:617
coord_3d grad_sdf(const coord_3d &pt) const
Definition sdf_shape_3D.h:635
const coord_3d lengths
Half the length of each side of the box.
Definition sdf_shape_3D.h:597
const coord_3d center
the center of the box
Definition sdf_shape_3D.h:598
SDFBox(const coord_3d &length, const coord_3d ¢er)
Constructor for box.
Definition sdf_shape_3D.h:605
A cone (3 dimensions)
Definition sdf_shape_3D.h:161
const coord_3d dir
The direction of the axis, from the apex INSIDE.
Definition sdf_shape_3D.h:165
double sdf(const coord_3d &pt) const
Computes the normal distance.
Definition sdf_shape_3D.h:186
SDFCone(const double c, const coord_3d &apex, const coord_3d &direc)
Constructor for cone.
Definition sdf_shape_3D.h:173
const coord_3d apex
The apex.
Definition sdf_shape_3D.h:163
const double c
The radius.
Definition sdf_shape_3D.h:164
coord_3d grad_sdf(const coord_3d &pt) const
Computes the gradient of the SDF.
Definition sdf_shape_3D.h:207
A cube (3 dimensions)
Definition sdf_shape_3D.h:643
SDFCube(const double length, const coord_3d ¢er)
Constructor for box.
Definition sdf_shape_3D.h:649
A cylinder (3 dimensions)
Definition sdf_shape_3D.h:702
double radius
the radius of the cylinder
Definition sdf_shape_3D.h:704
coord_3d grad_sdf(const coord_3d &pt) const
Definition sdf_shape_3D.h:755
coord_3d center
the central axial point of the cylinder (distance a from both ends)
Definition sdf_shape_3D.h:706
double sdf(const coord_3d &pt) const
Computes the normal distance.
Definition sdf_shape_3D.h:731
double a
half the length of the cylinder
Definition sdf_shape_3D.h:705
coord_3d axis
the axial direction of the cylinder
Definition sdf_shape_3D.h:707
SDFCylinder(const double radius, const double length, const coord_3d &axpt, const coord_3d &axis)
Constructor for cylinder.
Definition sdf_shape_3D.h:717
An ellipsoid (3 dimensions)
Definition sdf_shape_3D.h:657
coord_3d center
the center
Definition sdf_shape_3D.h:660
double sdf(const coord_3d &pt) const
Computes the normal distance.
Definition sdf_shape_3D.h:679
coord_3d grad_sdf(const coord_3d &pt) const
Definition sdf_shape_3D.h:696
coord_3d radii
the directional radii
Definition sdf_shape_3D.h:659
SDFEllipsoid(const coord_3d &radii, const coord_3d ¢er)
Constructor for ellipsoid.
Definition sdf_shape_3D.h:667
A paraboloid (3 dimensions)
Definition sdf_shape_3D.h:219
coord_3d grad_sdf(const coord_3d &pt) const
Computes the gradient of the SDF.
Definition sdf_shape_3D.h:364
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:522
const double c
Curvature/radius of the surface.
Definition sdf_shape_3D.h:222
const long double rootzero
Numerical zero for the roots.
Definition sdf_shape_3D.h:225
SDFParaboloid(const double c, const coord_3d &apex, const coord_3d &direc)
Constructor for paraboloid.
Definition sdf_shape_3D.h:233
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:563
const coord_3d apex
The apex.
Definition sdf_shape_3D.h:221
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:395
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:585
double sdf(const coord_3d &pt) const
Computes the normal distance.
Definition sdf_shape_3D.h:282
const long double zero
Numerical zero for root-finding in sdf.
Definition sdf_shape_3D.h:224
const coord_3d dir
The direction of the axis, from the apex INSIDE.
Definition sdf_shape_3D.h:223
A plane surface (3 dimensions)
Definition sdf_shape_3D.h:67
const coord_3d normal
The normal vector pointing OUTSIDE the surface.
Definition sdf_shape_3D.h:69
coord_3d grad_sdf(const coord_3d &pt) const
Computes the gradient of the SDF.
Definition sdf_shape_3D.h:97
const coord_3d point
A point in the plane.
Definition sdf_shape_3D.h:70
double sdf(const coord_3d &pt) const
Computes the normal distance.
Definition sdf_shape_3D.h:89
SDFPlane(const coord_3d &normal, const coord_3d &point)
SDF for a plane transecting the entire simulation volume.
Definition sdf_shape_3D.h:78
A spherical surface (3 dimensions)
Definition sdf_shape_3D.h:103
SDFSphere(const double radius, const coord_3d ¢er)
SDF for a sphere.
Definition sdf_shape_3D.h:113
const double radius
Radius of sphere.
Definition sdf_shape_3D.h:105
const coord_3d center
Center of sphere.
Definition sdf_shape_3D.h:106
double sdf(const coord_3d &pt) const
Computes the normal distance.
Definition sdf_shape_3D.h:124
coord_3d grad_sdf(const coord_3d &pt) const
Computes the gradient of the SDF.
Definition sdf_shape_3D.h:141
The interface for a signed distance function (sdf).
Definition sdf_domainmask.h:74
@ upper
Definition dirac-hatom.cc:15
@ lower
Definition dirac-hatom.cc:15
static const double length
Definition hedft.cc:48
#define max(a, b)
Definition lda.h:51
#define MADNESS_EXCEPTION(msg, value)
Macro for throwing a MADNESS exception.
Definition madness_exception.h:119
#define MADNESS_ASSERT(condition)
Assert a condition that should be free of side-effects since in release builds this might be a no-op.
Definition madness_exception.h:134
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
NDIM const Function< R, NDIM > & g
Definition mra.h:2416
static long abs(long a)
Definition tensor.h:218
static Function< T, NDIM > diff(const Function< T, NDIM > &f, int axis)
Definition navstokes_cosines.cc:119
static const double d
Definition nonlinschro.cc:121
Defines abstract interfaces and concrete classes signed distance functions and domain masks.
AtomicInt sum
Definition test_atomicint.cc:46
double dist(const Vector< double, 3 > v1, const Vector< double, 3 > v2)
distance between v1 and v2
Definition test_localizer.cc:38