11 #ifndef vtk_m_worklet_gradient_StructuredPointGradient_h
12 #define vtk_m_worklet_gradient_StructuredPointGradient_h
37 template <
typename Po
intsIn,
typename FieldIn,
typename GradientOutType>
39 const PointsIn& inputPoints,
41 GradientOutType& outputGradient)
const
43 using CoordType =
typename PointsIn::ValueType;
45 using OT =
typename GradientOutType::ComponentType;
52 this->
Jacobian(inputPoints, onBoundary, xi, eta, zeta);
54 auto dxi = inputField.Get(1, 0, 0) - inputField.Get(-1, 0, 0);
55 auto deta = inputField.Get(0, 1, 0) - inputField.Get(0, -1, 0);
56 auto dzeta = inputField.Get(0, 0, 1) - inputField.Get(0, 0, -1);
58 dxi = (onBoundary[0] ? dxi : dxi * 0.5f);
59 deta = (onBoundary[1] ? deta : deta * 0.5f);
60 dzeta = (onBoundary[2] ? dzeta : dzeta * 0.5f);
62 outputGradient[0] =
static_cast<OT
>(xi[0] * dxi + eta[0] * deta + zeta[0] * dzeta);
63 outputGradient[1] =
static_cast<OT
>(xi[1] * dxi + eta[1] * deta + zeta[1] * dzeta);
64 outputGradient[2] =
static_cast<OT
>(xi[2] * dxi + eta[2] * deta + zeta[2] * dzeta);
67 template <
typename FieldIn,
typename GradientOutType>
73 GradientOutType& outputGradient)
const
80 using CoordType =
typename PointsIn::ValueType;
81 using OT =
typename GradientOutType::ComponentType;
83 CoordType r = inputPoints.Portal.GetSpacing();
85 #if (defined(VTKM_CUDA) && defined(VTKM_GCC))
86 #pragma GCC diagnostic push
87 #pragma GCC diagnostic ignored "-Wconversion"
91 auto dx = inputField.GetUnchecked(1, 0, 0) - inputField.GetUnchecked(-1, 0, 0);
92 outputGradient[0] =
static_cast<OT
>((dx * 0.5f) / r[0]);
96 auto dx = inputField.Get(1, 0, 0) - inputField.Get(-1, 0, 0);
97 outputGradient[0] =
static_cast<OT
>(dx / r[0]);
102 auto dy = inputField.GetUnchecked(0, 1, 0) - inputField.GetUnchecked(0, -1, 0);
103 outputGradient[1] =
static_cast<OT
>((dy * 0.5f) / r[1]);
107 auto dy = inputField.Get(0, 1, 0) - inputField.Get(0, -1, 0);
108 outputGradient[1] =
static_cast<OT
>(dy / (r[1]));
113 auto dz = inputField.GetUnchecked(0, 0, 1) - inputField.GetUnchecked(0, 0, -1);
114 outputGradient[2] =
static_cast<OT
>((dz * 0.5f) / r[2]);
118 auto dz = inputField.Get(0, 0, 1) - inputField.Get(0, 0, -1);
119 outputGradient[2] =
static_cast<OT
>(dz / (r[2]));
121 #if (defined(VTKM_CUDA) && defined(VTKM_GCC))
122 #pragma GCC diagnostic pop
129 template <
typename Po
intsIn,
typename CT>
136 using CoordType =
typename PointsIn::ValueType;
137 CoordType xi, eta, zeta;
142 xi = (inputPoints.Get(1, 0, 0) - inputPoints.Get(-1, 0, 0));
146 xi = (inputPoints.GetUnchecked(1, 0, 0) - inputPoints.GetUnchecked(-1, 0, 0)) * 0.5f;
151 eta = (inputPoints.Get(0, 1, 0) - inputPoints.Get(0, -1, 0));
155 eta = (inputPoints.GetUnchecked(0, 1, 0) - inputPoints.GetUnchecked(0, -1, 0)) * 0.5f;
160 zeta = (inputPoints.Get(0, 0, 1) - inputPoints.Get(0, 0, -1));
164 zeta = (inputPoints.GetUnchecked(0, 0, 1) - inputPoints.GetUnchecked(0, 0, -1)) * 0.5f;
167 CT aj = xi[0] * eta[1] * zeta[2] + xi[1] * eta[2] * zeta[0] + xi[2] * eta[0] * zeta[1] -
168 xi[2] * eta[1] * zeta[0] - xi[1] * eta[0] * zeta[2] - xi[0] * eta[2] * zeta[1];
170 aj = (aj != 0.0) ? 1.f / aj : aj;
173 m_xi[0] = aj * (eta[1] * zeta[2] - eta[2] * zeta[1]);
174 m_xi[1] = -aj * (eta[0] * zeta[2] - eta[2] * zeta[0]);
175 m_xi[2] = aj * (eta[0] * zeta[1] - eta[1] * zeta[0]);
178 m_eta[0] = -aj * (xi[1] * zeta[2] - xi[2] * zeta[1]);
179 m_eta[1] = aj * (xi[0] * zeta[2] - xi[2] * zeta[0]);
180 m_eta[2] = -aj * (xi[0] * zeta[1] - xi[1] * zeta[0]);
183 m_zeta[0] = aj * (xi[1] * eta[2] - xi[2] * eta[1]);
184 m_zeta[1] = -aj * (xi[0] * eta[2] - xi[2] * eta[0]);
185 m_zeta[2] = aj * (xi[0] * eta[1] - xi[1] * eta[0]);