6 #ifndef PORTAGE_SUPPORT_WEIGHT_H_ 7 #define PORTAGE_SUPPORT_WEIGHT_H_ 17 #include "wonton/support/Point.h" 19 namespace Portage {
namespace Meshfree {
namespace Weight {
29 double const normconst[4] = { 2./3., 1./(.7 * M_PI), 1./M_PI, 1./M_PI };
42 inline double sign(
double x) {
return x > 0. ? 1. : (x < 0. ? -1. : 0.); }
57 inline double b4(
double x) {
58 return (std::pow(2. - std::abs(x), 3) *
unit_step(2. - std::abs(x))
60 + (1. - 1.5 * std::pow(x, 2)
61 + 0.75 * std::pow(std::abs(x), 3)) *
unit_step(1. - std::abs(x));
70 inline double db4(
double x) {
71 return (-3. * x + (9. * std::pow(x, 2) *
sign(x)) / 4.)
72 *
unit_step(1. - std::abs(x)) - (3. * std::pow(2. - std::abs(x), 2)
82 inline double ddb4(
double x) {
83 return (-3. + (9. * x *
sign(x)) / 2.) *
unit_step(1. - std::abs(x))
84 + (3. * (2. - std::abs(x)) *
unit_step(2. - std::abs(x))
94 inline double ib4(
double x) {
95 return unit_step(-2. + x) + 0.6666666666666666 *
96 ((1.4375 + (0.25 - std::pow(-2. + x, 4) / 4.) / 4.) *
98 (0.75 + x - std::pow(x, 3) / 2. + (3. * std::pow(x, 4)) / 16.) *
100 (0.75 + x - std::pow(x, 3) / 2. - (3. * std::pow(x, 4)) / 16.) *
112 return 0.0625 * std::pow(2. - std::abs(x), 3) * (1. +
sign(-1. - x)) *
113 (1. +
sign(2. + x)) +
114 0.5 * (1. - (3. * std::pow(x, 2)) / 2. + (3. * std::pow(std::abs(x), 3)) / 4.) *
125 return 0.0625 * std::pow(2. - std::abs(x), 3) * (1. +
sign(2. - x)) *
126 (1. +
sign(-1. + x)) +
127 0.5 * (1. - (3. * std::pow(x, 2)) / 2. + (3. * std::pow(std::abs(x), 3)) / 4.) *
138 return std::abs(x) >= 2. ? 0. : 0.375 * (1. - x * x * 0.25);
147 inline double depanechnikov(
double x) {
return std::abs(x) >= 2. ? 0. : -.1875 * x; }
155 inline double ddepanechnikov(
double x) {
return std::abs(x) >= 2. ? 0. : -.1875; }
163 inline double square(
double x) {
return std::abs(x) <= 2. ? 1. : 0.; }
171 inline double dsquare(
double x) {
return 0.; }
189 : (((1.5 - x) * (1. +
sign(1. - x))) * .5
190 + ((2. + (-2. + .5 * x) * x) * (1. +
sign(2. - x))
191 * (1. +
sign(-1. + x))) * .25) / 1.5);
201 return (((-1.) * (1. +
sign(1. - x))) * .5 +
202 ((-2. + x) * (1. +
sign(2. - x)) * (1. +
sign(-1. + x))) / 4.) / 1.5;
212 return (((0.) * (1. +
sign(1. - x))) * .5 +
213 ((1.) * (1. +
sign(2. - x)) * (1. +
sign(-1. + x))) / 4.) / 1.5;
223 double const ax = std::abs(x);
224 return 0.5 * (1. +
sign(2. - ax)) * ((ax - 2.) * ax + 4.) *
225 pow(ax + epsilon, -0.5);
235 double const sx = 1.;
236 double const ax = std::abs(x);
237 return 0.25 * (1. +
sign(2. - ax)) * sx * ((3. * ax - 4.) * ax - 4.) *
238 std::pow(ax + epsilon, -1.5);
248 double const ax = std::abs(x);
249 return 0.125 * (1. +
sign(2. - ax)) * ((3. * ax + 4.) * ax + 12.) *
250 std::pow(ax + epsilon, -2.5);
283 inline double step(
double x) {
return x <= 2 ? 1. : 0.; }
291 inline double dstep(
double x) {
return 0.; }
299 inline double ddstep(
double x) {
return 0.; }
315 case B4:
return b4(x);
346 Wonton::Point<dim>
const& y,
347 std::array<double,dim>
const& h) {
348 double distance = 0.;
349 for (
int i = 0; i < dim; i++) {
350 distance += (x[i] - y[i]) * (x[i] - y[i]) / (h[i] * h[i]);
352 return std::sqrt(distance);
365 std::array<double,dim>
tensor(Wonton::Point<dim>
const& x,
366 Wonton::Point<dim>
const& y,
367 std::array<double,dim>
const& h) {
368 std::array<double,dim> result;
369 for (
int i = 0; i < dim; i++) {
370 result[i] = (x[i] - y[i]) / h[i];
389 Wonton::Point<dim>
const& x,
390 Wonton::Point<dim>
const& y,
391 std::array<double,dim>
const& h) {
393 double const norm =
kernel(kern, 0.0);
396 auto const arg = elliptic<dim>(x, y, h);
397 result =
kernel(kern, arg) / norm;
402 auto const arg = tensor<dim>(x, y, h);
403 for (
int i = 0; i < dim; i++)
404 result *=
kernel(kern, arg[i]) / norm;
408 throw std::runtime_error(
"invalid weight geometry");
437 Wonton::Point<dim>
const& x,
438 Wonton::Point<dim>
const& y,
441 assert(kern ==
POLYRAMP or kern == STEP);
443 for (
size_t i = 0; i < nsides; i++) {
445 for (
size_t j = 0; j < dim; j++)
446 arg += facets[i].
normal[j] * (y[j] - x[j]);
447 arg /= facets[i].smoothing;
448 result *=
kernel(kern, arg);
467 Wonton::Point<dim>
const& x,
468 Wonton::Point<dim>
const& y,
473 std::array<double,dim> h;
474 for (
size_t i = 0; i < dim; i++)
476 return eval<dim>(geo, kern, x, y, h);
479 int const nsides = vh.size();
480 std::vector<FacetData<dim>> facets(nsides);
481 for (
int i = 0; i < nsides; i++) {
482 for (
int j = 0; j < dim; j++)
483 facets[i].
normal[j] = vh[i][j];
484 facets[i].smoothing = vh[i][dim];
486 return faceted<dim>(kern, x, y, facets, nsides);
489 throw std::runtime_error(
"invalid weight geometry");
495 #endif // PORTAGE_SUPPORT_WEIGHT_H_ double dcoulomb(double x)
coulomb weight derivative.
Definition: weight.h:267
double square(double x)
scalar square kernel.
Definition: weight.h:163
std::vector< T > vector
Definition: portage.h:238
double depanechnikov(double x)
scalar epanechnikov kernel derivative.
Definition: weight.h:147
double polyramp(double x)
scalar smooth ramp for faceted weight.
Definition: weight.h:187
double ddinvsqrt(double x)
second derivative of inverse square root kernel.
Definition: weight.h:247
double b4(double x)
scalar cubic b-spline.
Definition: weight.h:57
std::array< double, dim > normal
Definition: weight.h:421
data for specifying a faceted weight.
Definition: weight.h:419
double invsqrt(double x)
inverse square root kernel.
Definition: weight.h:222
double coulomb(double x)
coulomb weight.
Definition: weight.h:259
double ddsquare(double x)
scalar square kernel second derivative.
Definition: weight.h:179
double ddstep(double x)
step weight second derivative.
Definition: weight.h:299
double const epsilon
Numerical tolerance.
Definition: weight.h:34
double db4(double x)
scalar cubic b-spline derivative.
Definition: weight.h:70
double elliptic(Wonton::Point< dim > const &x, Wonton::Point< dim > const &y, std::array< double, dim > const &h)
generic elliptically symmetric weight function argument.
Definition: weight.h:345
double eval(Geometry const geometry, Kernel const kern, Wonton::Point< dim > const &x, Wonton::Point< dim > const &y, std::array< double, dim > const &h)
evaluation function for elliptic or tensor product weights.
Definition: weight.h:387
double epanechnikov(double x)
scalar epanechnikov kernel.
Definition: weight.h:137
Geometry
Geometry types.
Definition: weight.h:333
double b4lh(double x)
scalar left half cubic b-spline.
Definition: weight.h:111
double ddcoulomb(double x)
coulomb weight second derivative.
Definition: weight.h:275
double smoothing
Definition: weight.h:420
double ib4(double x)
scalar cubic b-spline anti-derivative.
Definition: weight.h:94
Definition: coredriver.h:42
double ddb4(double x)
scalar cubic b-spline second derivative.
Definition: weight.h:82
double dinvsqrt(double x)
derivative of inverse square root kernel.
Definition: weight.h:234
double kernel(const Kernel kern, double x)
General kernel function.
Definition: weight.h:313
double ddepanechnikov(double x)
scalar epanechnikov kernel second derivative.
Definition: weight.h:155
double dstep(double x)
step weight derivative.
Definition: weight.h:291
std::array< double, dim > tensor(Wonton::Point< dim > const &x, Wonton::Point< dim > const &y, std::array< double, dim > const &h)
generic tensor weight function arguments.
Definition: weight.h:365
double const normconst[4]
normalization constants for cubic B-spline (linear, cylindrical, and spherical).
Definition: weight.h:29
Kernel
Kernel types.
Definition: weight.h:304
double sign(double x)
scalar sign function.
Definition: weight.h:42
double ddpolyramp(double x)
scalar smooth ramp for faceted weight derivative.
Definition: weight.h:211
double faceted(Kernel const kern, Wonton::Point< dim > const &x, Wonton::Point< dim > const &y, std::vector< FacetData< dim >> const &facets, size_t nsides)
faceted weight function
Definition: weight.h:436
double step(double x)
step weight.
Definition: weight.h:283
double dsquare(double x)
scalar square kernel derivative.
Definition: weight.h:171
double dpolyramp(double x)
scalar smooth ramp for faceted weight derivative.
Definition: weight.h:200
double b4rh(double x)
scalar right half cubic b-spline.
Definition: weight.h:124
double unit_step(double x)
scalar step function
Definition: weight.h:45