This file is indexed.

/usr/include/madness/mra/sdf_domainmask.h is in libmadness-dev 0.10.1~gite4aa500e-10.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
/*
  This file is part of MADNESS.

  Copyright (C) 2007,2010 Oak Ridge National Laboratory

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program 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. See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

  For more information please contact:

  Robert J. Harrison
  Oak Ridge National Laboratory
  One Bethel Valley Road
  P.O. Box 2008, MS-6367

  email: harrisonrj@ornl.gov
  tel:   865-241-3937
  fax:   865-572-0680

  $Id: sdf_shape.h 1792 2010-01-26 12:58:18Z rjharrison $
*/

/*!
  \file mra/sdf_domainmask.h
  \brief Defines abstract interfaces and concrete classes signed distance
         functions and domain masks.

  Interfaces for a signed distance function (sdf) and a domain mask are
  made.  The original conception of these interfaces was for doing
  shapes and interior boundary conditions in MADNESS; however, the
  interfaces were abstracted for other applications.

  The domain mask builds on a sdf such that \f$0 <=  \mbox{mask(sdf)} <= 1\f$
  for smooth switching between domains.  That said, a mask needs a sdf.

  A general-purpose functor is given that combines a sdf and mask
  to produce MADNESS functions for various entities including
      - The domain mask (trace is the volume)
      - The gradient of mask (related to the surface)
      - The surface (trace is the surface area)
      - The normal derivative of the surface

  \ingroup mrabcint
*/

#ifndef MADNESS_MRA_SDF_DOMAINMASK_H__INCLUDED
#define MADNESS_MRA_SDF_DOMAINMASK_H__INCLUDED

#include <madness/mra/mra.h>

namespace madness {

    /** \brief The interface for a signed distance function (sdf).

        A class implementing this interface will need to provide the sdf
        given a point in coordinate space, and also the gradient of the
        sdf at this point.

        \c NDIM is the dimensionality of the coordinate space.

        \ingroup mrabcint */
    template <std::size_t NDIM>
    class SignedDFInterface {
    public:
        /** \brief Returns the signed distance from the surface,
               - Positive is ``inside''
               - Negative is ``outside''

            \param[in] x The coordinate
            \return The signed distance */
        virtual double sdf(const Vector<double,NDIM>& x) const = 0;

        /** \brief Returns the gradient of the signed distance from the
                   surface (i.e., \c dsdf(x)/dx[i] )

            \param[in] x The coordinate
            \return The gradient */
        virtual Vector<double,NDIM> grad_sdf(const Vector<double,NDIM>& x)
            const = 0;

        virtual ~SignedDFInterface() {}
    };

    /** \brief The interface for masking functions defined by signed distance
               functions.

        This interface was initially conceived for using shapes in MADNESS
        to specify internal boundary conditions.  The signed distance function
        defines the shape, and this mask allows calculations of volumes,
        surfaces, etc.

        \ingroup mrabcint */
    class DomainMaskInterface {
    public:
        /** \brief Returns the characteristic mask function
                - 1 in interior
                - 0 in exterior
                - 1/2 on boundary

            \param[in] d The signed distance from the surface
            \return The mask or characteristic function */
        virtual double mask(double d) const = 0;

        /** \brief Returns the derivative of the characteristic mask function
                   with respect to the distance (from the surface)

            \param[in] d The signed normal distance from the surface
            \return Derivative of the characteristic mask function */
        virtual double dmask(double d) const = 0;

        /** \brief Returns the value of the normalized surface layer function

            Normalized means the volume integral of this function should
            converge to the surface area in the limit of a either an infinitely
            thin surface or zero curvature.  The function thus acts as a
            ``delta function'' located at the boundary.

            \param[in] d The signed normal distance from the surface
            \return Normalized surface layer function */
        virtual double surface(double d) const = 0;

        /** \brief Returns the derivative of the normalized surface layer
                   function

            \param[in] d The signed normal distance from the surface
            \return Derivative of the normalized surface layer function */
        virtual double dsurface(double d) const = 0;

        virtual ~DomainMaskInterface() {}
    };

    /** \brief Framework for combining a signed distance function (sdf)
               with a domain mask to produce MADNESS functions.

        This interface provides functor functionality to produce MADNESS
        functions for
           - the domain mask (given the sdf)
           - the derivative of the domain mask
           - the surface (given the sdf)
           - the normal derivative of the surface layer

        The functor defaults to the domain mask; however, member functions
        can toggle between the other options.

        \ingroup mrabcint */
    template <std::size_t NDIM>
    class DomainMaskSDFFunctor : public FunctionFunctorInterface<double,NDIM> {

    private:
        /// \brief Bury the default constructor
        DomainMaskSDFFunctor() {}

    private: // protected may be better if this becomes highly inherited
        /// The domain mask to use
        std::shared_ptr<DomainMaskInterface> mask;

        /// The signed distance function
        std::shared_ptr<SignedDFInterface<NDIM> > sdf;

        int mswitch; ///< Which masking function to use (mask, surface, etc.)

    public:
        // switch values
        static const int MASK; ///< Use the \c mask() function in \c mask
        static const int MASK_COMPLEMENT; ///< Get the complement of \c mask()
        static const int DMASK; ///< Use the \c dmask() function in \c mask
        static const int SURFACE; ///< Use the \c surface() function in \c mask
        static const int DSURFACE; ///< Use the \c dsurface() function in \c mask

        /** \brief Constructor for mask/sdf functor

            \param mask Pointer to the domain mask
            \param sdf Pointer to the signed distance function */
        DomainMaskSDFFunctor(std::shared_ptr<DomainMaskInterface> mask,
                std::shared_ptr<SignedDFInterface<NDIM> > sdf)
            : mask(mask), sdf(sdf), mswitch(MASK)
        {}

        /** \brief Constructor for mask/sdf function specifying the desired
                   function (mask, surface, etc.)

            \param mask Pointer to the domain mask
            \param sdf Pointer to the signed distance function
            \param[in] _mswitch Which function to use (MASK, DMASK, SURFACE,
                       DSURFACE, or MASK_COMPLEMENT) */
        DomainMaskSDFFunctor(std::shared_ptr<DomainMaskInterface> mask,
                std::shared_ptr<SignedDFInterface<NDIM> > sdf, int _mswitch)
            : mask(mask), sdf(sdf), mswitch(MASK) {
            if(_mswitch == MASK || _mswitch == DMASK || _mswitch == SURFACE ||
               _mswitch == DSURFACE || _mswitch == MASK_COMPLEMENT) {
                mswitch = _mswitch;
            }
            else {
                error("Unrecognized function option in DomainMaskSDFFunctor" \
                      "::DomainMaskSDFFunctor()");
            }
        }

        /** \brief Uses the functor interface to make a MADNESS function

            \param x Point to compute value
            \return Value of the desired function */
        double operator()(const Vector<double,NDIM>& x) const {
            if(mswitch == DomainMaskSDFFunctor<NDIM>::MASK)
                return mask->mask(sdf->sdf(x));
            else if(mswitch == DomainMaskSDFFunctor<NDIM>::MASK_COMPLEMENT)
                return 1.0 - mask->mask(sdf->sdf(x));
            else if(mswitch == DomainMaskSDFFunctor<NDIM>::DMASK)
                return mask->dmask(sdf->sdf(x));
            else if(mswitch == DomainMaskSDFFunctor<NDIM>::SURFACE)
                return mask->surface(sdf->sdf(x));
            else if(mswitch == DomainMaskSDFFunctor<NDIM>::DSURFACE)
                return mask->dsurface(sdf->sdf(x));
            else {
                error("Unknown function from DomainMaskInterface in " \
                      "DomainMaskSDFFunctor::operator()");
                return 0.0;
            }
        }

        /** \brief Toggles which function from DomainMaskInterface to use when
                   making the MADNESS function.

            \param _mswitch The function to use (should be MASK, DMASK,
                   SURFACE, DSURFACE, or MASK_COMPLEMENT) */
        void setMaskFunction(int _mswitch) {
            if(_mswitch == MASK || _mswitch == DMASK || _mswitch == SURFACE ||
               _mswitch == DSURFACE || _mswitch == MASK_COMPLEMENT) {
                mswitch = _mswitch;
            }
            else {
                error("Unrecognized function option in DomainMaskSDFFunctor" \
                      "::setMaskFunction()");
            }
        }

        virtual ~DomainMaskSDFFunctor() {}
    };

    template<std::size_t NDIM>
    const int DomainMaskSDFFunctor<NDIM>::MASK = 1;

    template<std::size_t NDIM>
    const int DomainMaskSDFFunctor<NDIM>::MASK_COMPLEMENT = 2;

    template<std::size_t NDIM>
    const int DomainMaskSDFFunctor<NDIM>::DMASK = 3;

    template<std::size_t NDIM>
    const int DomainMaskSDFFunctor<NDIM>::SURFACE = 4;

    template<std::size_t NDIM>
    const int DomainMaskSDFFunctor<NDIM>::DSURFACE = 5;

    /** \brief Provides the Li-Lowengrub-Ratz-Voight (LLRV) domain mask
               characteristic functions.

        \ingroup mrabcint

        See X. Li, J. Lowengrub, A. R&auml;tz, and A. Voight, ``Solving PDEs in
        Complex Geometries: A Diffuse Domain Approach,'' Commun. Math. Sci., 7,
        p81-107, 2009.

        Given a signed distance, this class implements in the domain mask
        and surface functions from the above reference.  For the domain mask,

        \f[ \varphi(d) = \frac{1}{2}\left( 1 - \tanh\left(
                         \frac{3d}{\varepsilon} \right) \right) \f]

        where \f$d\f$ is the signed distance.  The normalized surface function
        is

        \f[ B(\varphi) = \frac{36}{\varepsilon} \varphi^2 (1-\varphi)^2. \f]

        The constant \f$36/\varepsilon\f$ is chosen to fulfill

        \f[ \int_{-\infty}^\infty B(s) \, ds = 1 \f]

        This class assumes the domain mask is uniformly 0 or 1 outside
        signed distances \f$ |8 \epsilon| \f$ since the switching function
        becomes 0/1 to machine precision at these levels.  Specifically,
        for this function the parameter \f$ \epsilon \f$ is an effective
        measure of the full width of the surface layer since

        \f[ \int_{-\epsilon/2}^{\epsilon/2} B(s) \, ds \doteq 0.987 \f]

        and

        \f[ \int_{-\epsilon}^{\epsilon} B(s) \, ds \doteq 0.999963 \f] */
    class LLRVDomainMask : public DomainMaskInterface {
    private:
        LLRVDomainMask() : epsilon(0.0) {} ///< Forbidden

    protected:
        const double epsilon; ///< The width of the transition region

    public:
        /** \brief Constructor for the domain mask

            \param[in] epsilon The effective width of the surface */
        LLRVDomainMask(double epsilon)
            : epsilon(epsilon)
        {}

        /** \brief Value of characteristic function at normal distance d from
                   the surface

            \param[in] d The signed distance.  Negative is ``inside,''
                         positive is ``outside.''
            \return The domain mask */
        double mask(double d) const {
            if (d > 8.0*epsilon) {
                return 0.0; // we're safely outside
            }
            else if (d < -8.0*epsilon) {
                return 1.0; // inside
            }
            else {
                return 0.5 * (1.0 - tanh(3.0 * d / epsilon));
            }
        }

        /** \brief Derivative of characteristic function with respect to the
                   normal distance

            \param[in] d The signed distance
            \return The derivative */
        double dmask(double d) const {
            if (fabs(d) > 8.0*epsilon) {
                return 0.0; // we're safely outside or inside
            }
            else {
                double tanh3d = tanh(3.0*d/epsilon);
                return 1.5*(tanh3d*tanh3d - 1.0) / epsilon;
            }
        }

        /** \brief Value of surface function at distance d normal to surface

            \param[in] d The signed distance
            \return The value of the surface function */
        double surface(double d) const {
            double phi = mask(d);
            double phic = 1.0 - phi;
            return 36.0*phi*phi*phic*phic/epsilon;
        }

        /** \brief Value of d(surface)/ddistance

            \param[in] d The signed distance
            \return The derivative of the surface function */
        double dsurface(double d) const {
            double phi = mask(d);
            double dphi = dmask(d);
            return 72.0*phi*(1.0-phi)*dphi*(1.0 - 2.0*phi)/epsilon;
        }

        virtual ~LLRVDomainMask() {}
    };

    /** \brief Use a Gaussian for the surface function and the corresponding erf
               for the domain mask. */
    class GaussianDomainMask : public DomainMaskInterface {
    private:
        GaussianDomainMask() : epsilon(0.0) {} ///< Forbidden

    protected:
        const double epsilon; ///< The width of the transition region

    public:
        /** \brief Constructor for the domain mask

            \param[in] epsilon The effective width of the surface */
        GaussianDomainMask(double epsilon)
            : epsilon(epsilon)
        {}

        /** \brief Value of characteristic function at normal distance d from
                   the surface

            \param[in] d The signed distance.  Negative is ``inside,''
                         positive is ``outside.''
            \return The domain mask */
        double mask(double d) const {
            if (d > 8.0*epsilon) {
                return 0.0; // we're safely outside
            }
            else if (d < -8.0*epsilon) {
                return 1.0; // inside
            }
            else {
                return (1.0 - erf(d / (sqrt(2.0) * epsilon))) * 0.5;
            }
        }

        /** \brief Derivative of characteristic function with respect to the
                   normal distance

            \param[in] d The signed distance
            \return The derivative */
        double dmask(double d) const {
            if (fabs(d) > 8.0*epsilon) {
                return 0.0; // we're safely outside or inside
            }
            else {
                return -exp(-d*d*0.5/(epsilon*epsilon)) / (sqrt(2.0*constants::pi)
                    * epsilon);
            }
        }

        /** \brief Value of surface function at distance d normal to surface

            \param[in] d The signed distance
            \return The value of the surface function */
        double surface(double d) const {
            return exp(-d*d*0.5/(epsilon*epsilon)) / (sqrt(2.0*constants::pi)
                * epsilon);
        }

        /** \brief Value of d(surface)/ddistance

            \param[in] d The signed distance
            \return The derivative of the surface function */
        double dsurface(double d) const {
            return -exp(-d*d*0.5/(epsilon*epsilon)) * d / (sqrt(2.0*constants::pi)
                * epsilon*epsilon*epsilon);
        }

        virtual ~GaussianDomainMask() {}
    };

} // end of madness namespace

#endif // MADNESS_MRA_SDF_DOMAINMASK_H__INCLUDED