VTK-m  2.0
KernelBase.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef VTKM_KERNELBASE_HPP
11 #define VTKM_KERNELBASE_HPP
12 
13 #include <vtkm/Math.h>
14 #include <vtkm/Types.h>
15 
16 namespace vtkm
17 {
18 namespace worklet
19 {
20 namespace splatkernels
21 {
22 
23 // Vector class used in the kernels
25 // Pi compatibility
26 #ifndef M_PI
27 #define M_PI vtkm::Pi()
28 #endif
29 
30 // templated utility to generate expansions at compile time for x^N
31 template <vtkm::IdComponent N>
33 {
34  return x * PowerExpansion<N - 1>(x);
35 }
36 
37 template <>
39 {
40  return x;
41 }
42 
43 template <>
45 {
46  return 1;
47 }
48 
49 //---------------------------------------------------------------------
50 // Base class for Kernels
51 // We use CRTP to avoid virtual function calls.
52 template <typename Kernel>
53 struct KernelBase
54 {
55  //---------------------------------------------------------------------
56  // Constructor
57  // Calculate coefficients used repeatedly when evaluating the kernel
58  // value or gradient
59  // The smoothing length is usually denoted as 'h' in SPH literature
61  KernelBase(double smoothingLength)
62  : smoothingLength_(smoothingLength)
63  {
64  }
65 
66  //---------------------------------------------------------------------
67  // The functions below are placeholders which should be provided by
68  // concrete implementations of this class.
69  // The KernelBase versions will not be called when algorithms are
70  // templated over a concrete implementation.
71  //---------------------------------------------------------------------
72 
73  //---------------------------------------------------------------------
74  // compute w(h) for the given distance
76  double w(double distance) { return static_cast<Kernel*>(this)->w(distance); }
77 
78  //---------------------------------------------------------------------
79  // compute w(h) for the given squared distance
80  // this version takes the distance squared as a convenience/optimization
81  // but not all implementations will benefit from it
83  double w2(double distance2) { return static_cast<Kernel*>(this)->w2(distance2); }
84 
85  //---------------------------------------------------------------------
86  // compute w(h) for a variable h kernel
87  // this is less efficient than the fixed radius version as coefficients
88  // must be calculatd on the fly, but it is required when all particles
89  // have different smoothing lengths
91  double w(double h, double distance) { return static_cast<Kernel*>(this)->w(h, distance); }
92 
93  //---------------------------------------------------------------------
94  // compute w(h) for a variable h kernel using distance squared
95  // this version takes the distance squared as a convenience/optimization
97  double w2(double h, double distance2) { return static_cast<Kernel*>(this)->w2(h, distance2); }
98 
99  //---------------------------------------------------------------------
100  // Calculates the kernel derivative for a distance {x,y,z} vector
101  // from the centre.
103  vector_type gradW(double distance, const vector_type& pos)
104  {
105  return static_cast<Kernel*>(this)->gradW(distance, pos);
106  }
107 
108  // Calculates the kernel derivative at the given distance using a variable h value
109  // this is less efficient than the fixed radius version as coefficients
110  // must be calculatd on the fly
112  vector_type gradW(double h, double distance, const vector_type& pos)
113  {
114  return static_cast<Kernel*>(this)->gradW(h, distance, pos);
115  }
116 
117  // return the multiplier between smoothing length and max cutoff distance
119  double getDilationFactor() const { return static_cast<Kernel*>(this)->getDilationFactor; }
120 
121  // return the maximum cutoff distance over which the kernel acts,
122  // beyond this distance the kernel value is zero
124  double maxDistance() { return static_cast<Kernel*>(this)->maxDistance(); }
125 
126  // return the maximum cutoff distance over which the kernel acts,
127  // beyond this distance the kernel value is zero
129  double maxDistanceSquared() { return static_cast<Kernel*>(this)->maxDistanceSquared(); }
130 
131 protected:
132  const double smoothingLength_;
133 };
134 }
135 }
136 }
137 #endif
vtkm::worklet::splatkernels::KernelBase::w2
VTKM_EXEC_CONT double w2(double h, double distance2)
Definition: KernelBase.h:97
vtkm::worklet::splatkernels::PowerExpansion< 0 >
VTKM_EXEC_CONT vtkm::Float64 PowerExpansion< 0 >(vtkm::Float64)
Definition: KernelBase.h:44
vtkm::worklet::splatkernels::KernelBase::getDilationFactor
VTKM_EXEC_CONT double getDilationFactor() const
Definition: KernelBase.h:119
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
Types.h
vtkm::worklet::splatkernels::KernelBase::gradW
VTKM_EXEC_CONT vector_type gradW(double h, double distance, const vector_type &pos)
Definition: KernelBase.h:112
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::worklet::splatkernels::KernelBase::maxDistanceSquared
VTKM_EXEC_CONT double maxDistanceSquared()
Definition: KernelBase.h:129
vtkm::worklet::splatkernels::PowerExpansion< 1 >
VTKM_EXEC_CONT vtkm::Float64 PowerExpansion< 1 >(vtkm::Float64 x)
Definition: KernelBase.h:38
vtkm::worklet::splatkernels::KernelBase::w2
VTKM_EXEC_CONT double w2(double distance2)
Definition: KernelBase.h:83
vtkm::Vec3f_64
vtkm::Vec< vtkm::Float64, 3 > Vec3f_64
Vec3f_64 corresponds to a 3-dimensional vector of 64-bit floating point values.
Definition: Types.h:1026
Math.h
vtkm::worklet::splatkernels::KernelBase::KernelBase
VTKM_EXEC_CONT KernelBase(double smoothingLength)
Definition: KernelBase.h:61
vtkm::worklet::splatkernels::KernelBase
Definition: KernelBase.h:53
vtkm::worklet::splatkernels::PowerExpansion
VTKM_EXEC_CONT vtkm::Float64 PowerExpansion(vtkm::Float64 x)
Definition: KernelBase.h:32
vtkm::worklet::splatkernels::KernelBase::w
VTKM_EXEC_CONT double w(double h, double distance)
Definition: KernelBase.h:91
vtkm::worklet::splatkernels::KernelBase::gradW
VTKM_EXEC_CONT vector_type gradW(double distance, const vector_type &pos)
Definition: KernelBase.h:103
vtkm::worklet::splatkernels::KernelBase::w
VTKM_EXEC_CONT double w(double distance)
Definition: KernelBase.h:76
vtkm::Vec< vtkm::Float64, 3 >
vtkm::worklet::splatkernels::KernelBase::maxDistance
VTKM_EXEC_CONT double maxDistance()
Definition: KernelBase.h:124
vtkm::Float64
double Float64
Definition: Types.h:155
vtkm::worklet::splatkernels::KernelBase::smoothingLength_
const double smoothingLength_
Definition: KernelBase.h:132