MADNESS  version 0.9
sdf_shape_2D.h
Go to the documentation of this file.
1 /*
2  This file is part of MADNESS.
3 
4  Copyright (C) 2007,2010 Oak Ridge National Laboratory
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 
20  For more information please contact:
21 
22  Robert J. Harrison
23  Oak Ridge National Laboratory
24  One Bethel Valley Road
25  P.O. Box 2008, MS-6367
26 
27  email: harrisonrj@ornl.gov
28  tel: 865-241-3937
29  fax: 865-572-0680
30 
31  $Id$
32 */
33 
51 #ifndef MADNESS_MRA_SDF_SHAPE_2D_H__INCLUDED
52 #define MADNESS_MRA_SDF_SHAPE_2D_H__INCLUDED
53 
55 
56 namespace madness {
57 
59  class SDFCircle : public SignedDFInterface<2> {
60  protected:
61  const double radius;
62  const coord_2d center;
63 
64  public:
69  SDFCircle(const double radius, const coord_2d &center)
70  : radius(radius)
71  , center(center)
72  {}
73 
80  double sdf(const coord_2d& pt) const {
81  double temp, r;
82  int i;
83 
84  r = 0.0;
85  for(i = 0; i < 2; ++i) {
86  temp = pt[i] - center[i];
87  r += temp * temp;
88  }
89 
90  return sqrt(r) - radius;
91  }
92 
97  coord_2d grad_sdf(const coord_2d& pt) const {
98  double x = pt[0] - center[0];
99  double y = pt[1] - center[1];
100  double r = sqrt(x*x + y*y);
101  coord_2d g;
102  if(r < 1.0e-6) {
103  g[0] = g[1] = 0.0;
104  }
105  else {
106  g[0] = x/r;
107  g[1] = y/r;
108  }
109  return g;
110  }
111  };
112 
119  class SDFRectangle : public SignedDFInterface<2> {
120  protected:
122  const coord_2d center;
123 
124  public:
129  SDFRectangle(const coord_2d& length, const coord_2d& center)
130  : lengths(length*0.5), center(center)
131  {}
132 
137  double sdf(const coord_2d& pt) const {
138  double diff, max;
139 
140  max = fabs(pt[0] - center[0]) - lengths[0];
141  diff = fabs(pt[1] - center[1]) - lengths[1];
142  if(diff > max)
143  max = diff;
144 
145  return max;
146  }
147 
152  coord_2d grad_sdf(const coord_2d& pt) const {
153  MADNESS_EXCEPTION("gradient method is not yet implemented for this shape",0);
154  }
155  };
156 
157 } // end of madness namespace
158 
159 #endif // MADNESS_MRA_SDF_SHAPE_2D_H__INCLUDED
coord_2d grad_sdf(const coord_2d &pt) const
Computes the gradient of the SDF.
Definition: sdf_shape_2D.h:97
double sdf(const coord_2d &pt) const
Computes the normal distance.
Definition: sdf_shape_2D.h:137
NDIM const Function< R, NDIM > & g
Definition: mra.h:2179
SDFCircle(const double radius, const coord_2d &center)
SDF for a sphere.
Definition: sdf_shape_2D.h:69
A simple, fixed dimension Coordinate.
Definition: array.h:99
const double radius
Radius of circle.
Definition: sdf_shape_2D.h:61
const coord_2d lengths
Half the length of each side.
Definition: sdf_shape_2D.h:121
A circle (2 dimensions)
Definition: sdf_shape_2D.h:59
Defines abstract interfaces and concrete classes signed distance functions and domain masks...
SDFRectangle(const coord_2d &length, const coord_2d &center)
Constructor for rectangle.
Definition: sdf_shape_2D.h:129
coord_2d grad_sdf(const coord_2d &pt) const
Definition: sdf_shape_2D.h:152
const coord_2d center
Center of circle.
Definition: sdf_shape_2D.h:62
The interface for a signed distance function (sdf).
Definition: sdf_domainmask.h:74
#define max(a, b)
Definition: lda.h:53
double sdf(const coord_2d &pt) const
Computes the normal distance.
Definition: sdf_shape_2D.h:80
const coord_2d center
the center
Definition: sdf_shape_2D.h:122
tensorT sqrt(const tensorT &s, double tol=1e-8)
Computes matrix square root (not used any more?)
Definition: DFcode/moldft.cc:446
#define MADNESS_EXCEPTION(msg, value)
Definition: worldexc.h:88
A rectangle (2 dimensions)
Definition: sdf_shape_2D.h:119
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