9 #ifndef _COMPADRE_FUNCTORS_HPP_
10 #define _COMPADRE_FUNCTORS_HPP_
20 #include "KokkosBatched_Gemm_Decl.hpp"
122 KOKKOS_INLINE_FUNCTION
125 const int local_index = teamMember.league_rank();
150 KOKKOS_INLINE_FUNCTION
156 const int local_index = teamMember.league_rank();
187 KOKKOS_INLINE_FUNCTION
195 const int local_index = teamMember.league_rank();
211 dimensions-1, dimensions);
216 for (
int j = 0; j < delta.extent_int(0); ++j) {
219 for (
int j = 0; j < thread_workspace.extent_int(0); ++j) {
220 thread_workspace(j) = 0;
232 dimensions, dimensions);
242 Kokkos::single(Kokkos::PerTeam(teamMember), [&] () {
243 Kokkos::single(Kokkos::PerThread(teamMember), [&] () {
249 Kokkos::single(Kokkos::PerTeam(teamMember), [&] () {
250 Kokkos::single(Kokkos::PerThread(teamMember), [&] () {
251 for (
int j=0; j<dimensions; ++j) {
252 for (
int k=0; k<dimensions-1; ++k) {
260 &&
"StaggeredEdgeIntegralSample prestencil weight only written for manifolds.");
261 Kokkos::parallel_for(Kokkos::TeamThreadRange(teamMember,
263 Kokkos::single(Kokkos::PerThread(teamMember), [&] () {
264 for (int quadrature = 0; quadrature<_data._qm.getNumberOfQuadraturePoints(); ++quadrature) {
265 XYZ tangent_quadrature_coord_2d;
266 for (int j=0; j<dimensions-1; ++j) {
267 tangent_quadrature_coord_2d[j] = _data._pc.getTargetCoordinate(target_index, j, &T);
268 tangent_quadrature_coord_2d[j] -= _data._pc.getNeighborCoordinate(target_index, m, j, &T);
270 double tangent_vector[3];
271 tangent_vector[0] = tangent_quadrature_coord_2d[0]*T(0,0) + tangent_quadrature_coord_2d[1]*T(1,0);
272 tangent_vector[1] = tangent_quadrature_coord_2d[0]*T(0,1) + tangent_quadrature_coord_2d[1]*T(1,1);
273 tangent_vector[2] = tangent_quadrature_coord_2d[0]*T(0,2) + tangent_quadrature_coord_2d[1]*T(1,2);
275 for (int j=0; j<dimensions; ++j) {
276 _data._prestencil_weights(0,target_index,m,0,j) += (1-_data._qm.getSite(quadrature,0))*tangent_vector[j]*_data._qm.getWeight(quadrature);
277 _data._prestencil_weights(1,target_index,m,0,j) += _data._qm.getSite(quadrature,0)*tangent_vector[j]*_data._qm.getWeight(quadrature);
284 Kokkos::parallel_for(Kokkos::TeamThreadRange(teamMember,
287 Kokkos::single(Kokkos::PerThread(teamMember), [&] () {
288 calcGradientPij(_data, teamMember, delta.data(), thread_workspace.data(), target_index,
289 m, 0 , 0 , dimensions-1, _data._curvature_poly_order,
290 false , &T, ReconstructionSpace::ScalarTaylorPolynomial,
294 double grad_xi1 = 0, grad_xi2 = 0;
295 Kokkos::parallel_reduce(Kokkos::ThreadVectorRange(teamMember,
298 for (int l=0; l<_data.manifold_NP; ++l) {
299 alpha_ij += delta(l)*Q(l,i);
302 double normal_coordinate = rel_coord[dimensions-1];
305 t_grad_xi1 += alpha_ij * normal_coordinate;
309 Kokkos::single(Kokkos::PerThread(teamMember), [&] () {
315 Kokkos::parallel_reduce(Kokkos::ThreadVectorRange(teamMember,
318 for (int l=0; l<_data.manifold_NP; ++l) {
319 alpha_ij += delta(l)*Q(l,i);
322 double normal_coordinate = rel_coord[dimensions-1];
325 if (dimensions>2) t_grad_xi2 += alpha_ij * normal_coordinate;
330 teamMember.team_barrier();
332 Kokkos::parallel_for(Kokkos::TeamThreadRange(teamMember,
335 Kokkos::single(Kokkos::PerThread(teamMember), [&] () {
336 for (int j=0; j<dimensions; ++j) {
337 tangent(0,j) = t1(m)*T(dimensions-1,j) + T(0,j);
338 tangent(1,j) = t2(m)*T(dimensions-1,j) + T(1,j);
343 for (int j=0; j<dimensions; ++j) {
344 norm += tangent(0,j)*tangent(0,j);
348 norm = std::sqrt(norm);
349 for (int j=0; j<dimensions; ++j) {
350 tangent(0,j) /= norm;
354 if (dimensions-1 == 2) {
355 double dot_product = tangent(0,0)*tangent(1,0)
356 + tangent(0,1)*tangent(1,1)
357 + tangent(0,2)*tangent(1,2);
358 for (int j=0; j<dimensions; ++j) {
359 tangent(1,j) -= dot_product*tangent(0,j);
363 for (int j=0; j<dimensions; ++j) {
364 norm += tangent(1,j)*tangent(1,j);
366 norm = std::sqrt(norm);
367 for (int j=0; j<dimensions; ++j) {
368 tangent(1,j) /= norm;
373 for (int j=0; j<dimensions; ++j) {
374 for (int k=0; k<dimensions-1; ++k) {
375 _data._prestencil_weights(0,target_index,m,k,j) = tangent(k,j);
381 teamMember.team_barrier();
392 KOKKOS_INLINE_FUNCTION
400 const int local_index = teamMember.league_rank();
434 double * rhs_data = RHS.data();
435 Kokkos::parallel_for(Kokkos::TeamVectorRange(teamMember, this_num_rows), [&] (
const int i) {
436 rhs_data[i] = std::sqrt(w(i));
444 KokkosBatched::TeamVectorGemm<member_type,KokkosBatched::Trans::Transpose,KokkosBatched::Trans::NoTranspose,KokkosBatched::Algo::Gemm::Unblocked>
451 teamMember.team_barrier();
454 Kokkos::parallel_for(Kokkos::TeamThreadRange(teamMember, _data.
max_num_rows), [&] (
const int i) {
455 for (int j=0; j < _data.this_num_cols; j++) {
456 PsqrtW(i,j) = PsqrtW(i,j)*std::sqrt(w(i));
459 teamMember.team_barrier();
470 double cutoff_p = _data.
_epsilons(target_index);
476 teamMember.team_barrier();
493 KOKKOS_INLINE_FUNCTION
501 const int local_index = teamMember.league_rank();
516 dimensions, dimensions);
519 dimensions, dimensions);
535 KokkosBatched::TeamVectorGemm<member_type,KokkosBatched::Trans::Transpose,KokkosBatched::Trans::NoTranspose,KokkosBatched::Algo::Gemm::Unblocked>
542 teamMember.team_barrier();
546 const_cast<pool_type&
>(_random_number_pool));
548 teamMember.team_barrier();
559 KOKKOS_INLINE_FUNCTION
567 const int local_index = teamMember.league_rank();
604 double * rhs_data = RHS.data();
605 Kokkos::parallel_for(Kokkos::TeamVectorRange(teamMember, this_num_neighbors), [&] (
const int i) {
606 rhs_data[i] = std::sqrt(w(i));
615 KokkosBatched::TeamVectorGemm<
member_type,KokkosBatched::Trans::Transpose,
616 KokkosBatched::Trans::NoTranspose,KokkosBatched::Algo::Gemm::Unblocked>
623 teamMember.team_barrier();
626 Kokkos::parallel_for(Kokkos::TeamThreadRange(teamMember, this_num_neighbors), [&] (
const int i) {
628 CurvaturePsqrtW(i, j) = CurvaturePsqrtW(i, j)*std::sqrt(w(i));
632 teamMember.team_barrier();
643 KOKKOS_INLINE_FUNCTION
651 const int local_index = teamMember.league_rank();
663 dimensions, dimensions);
687 teamMember.team_barrier();
689 double grad_xi1 = 0, grad_xi2 = 0;
691 for (
int k=0; k<dimensions-1; ++k) {
694 Kokkos::parallel_reduce(Kokkos::TeamThreadRange(teamMember,
695 _data.
manifold_NP), [&] (
const int l,
double &talpha_ij) {
696 Kokkos::single(Kokkos::PerThread(teamMember), [&] () {
697 talpha_ij += P_target_row(offset,l)*Q(l,i);
700 teamMember.team_barrier();
701 Kokkos::single(Kokkos::PerTeam(teamMember), [&] () {
703 manifold_gradient(i*(dimensions-1) + k) = alpha_ij;
706 teamMember.team_barrier();
709 double normal_coordinate = rel_coord[dimensions-1];
712 grad_xi1 += manifold_gradient(i*(dimensions-1)) * normal_coordinate;
713 if (dimensions>2) grad_xi2 += manifold_gradient(i*(dimensions-1)+1) * normal_coordinate;
714 teamMember.team_barrier();
718 Kokkos::single(Kokkos::PerTeam(teamMember), [&] () {
720 double grad_xi[2] = {grad_xi1, grad_xi2};
724 for (
int i=0; i<dimensions-1; ++i) {
725 for (
int j=0; j<dimensions; ++j) {
729 for (
int j=0; j<dimensions; ++j) {
730 T(i,j) = grad_xi[i]*T(dimensions-1,j);
737 for (
int j=0; j<dimensions; ++j) {
738 norm += T(0,j)*T(0,j);
742 norm = std::sqrt(norm);
743 for (
int j=0; j<dimensions; ++j) {
748 if (dimensions-1 == 2) {
749 double dot_product = T(0,0)*T(1,0) + T(0,1)*T(1,1) + T(0,2)*T(1,2);
750 for (
int j=0; j<dimensions; ++j) {
751 T(1,j) -= dot_product*T(0,j);
755 for (
int j=0; j<dimensions; ++j) {
756 norm += T(1,j)*T(1,j);
758 norm = std::sqrt(norm);
759 for (
int j=0; j<dimensions; ++j) {
765 double norm_t_normal = 0;
767 T(dimensions-1,0) = T(0,1)*T(1,2) - T(1,1)*T(0,2);
768 norm_t_normal += T(dimensions-1,0)*T(dimensions-1,0);
769 T(dimensions-1,1) = -(T(0,0)*T(1,2) - T(1,0)*T(0,2));
770 norm_t_normal += T(dimensions-1,1)*T(dimensions-1,1);
771 T(dimensions-1,2) = T(0,0)*T(1,1) - T(1,0)*T(0,1);
772 norm_t_normal += T(dimensions-1,2)*T(dimensions-1,2);
774 T(dimensions-1,0) = T(1,1) - T(0,1);
775 norm_t_normal += T(dimensions-1,0)*T(dimensions-1,0);
776 T(dimensions-1,1) = T(0,0) - T(1,0);
777 norm_t_normal += T(dimensions-1,1)*T(dimensions-1,1);
779 norm_t_normal = std::sqrt(norm_t_normal);
780 for (
int i=0; i<dimensions-1; ++i) {
781 T(dimensions-1,i) /= norm_t_normal;
784 teamMember.team_barrier();
796 KOKKOS_INLINE_FUNCTION
816 Kokkos::single(Kokkos::PerTeam(teamMember), [&] () {
818 &&
"FixTangentDirectionOrder called on manifold with a dimension of 0.");
819 double dot_product = 0;
820 for (
int i=0; i<dimensions; ++i) {
821 dot_product += T(dimensions-1,i) * N(i);
824 if (dot_product < 0) {
826 for (
int i=0; i<dimensions; ++i) {
833 for (
int i=0; i<dimensions; ++i) {
835 T(dimensions-1,i) *= -1;
840 teamMember.team_barrier();
851 KOKKOS_INLINE_FUNCTION
859 const int local_index = teamMember.league_rank();
872 dimensions, dimensions);
894 Kokkos::single(Kokkos::PerTeam(teamMember), [&] () {
896 manifold_coeffs(j) = 0;
899 teamMember.team_barrier();
902 double normal_coordinate = rel_coord[dimensions-1];
904 Kokkos::single(Kokkos::PerTeam(teamMember), [&] () {
905 Kokkos::single(Kokkos::PerTeam(teamMember), [&] () {
908 manifold_coeffs(j) += Q(j,i) * normal_coordinate;
912 teamMember.team_barrier();
924 KOKKOS_INLINE_FUNCTION
932 const int local_index = teamMember.league_rank();
961 createWeightsAndP(_data, teamMember, delta, thread_workspace, PsqrtW, w, dimensions-1,
967 double * Q_data = Q.data();
968 Kokkos::parallel_for(Kokkos::TeamVectorRange(teamMember,this_num_rows), [&] (
const int i) {
969 Q_data[i] = std::sqrt(w(i));
979 KokkosBatched::TeamVectorGemm<member_type,KokkosBatched::Trans::Transpose,KokkosBatched::Trans::NoTranspose,KokkosBatched::Algo::Gemm::Unblocked>
986 teamMember.team_barrier();
989 Kokkos::parallel_for(Kokkos::TeamThreadRange(teamMember, _data.
max_num_rows), [&] (
const int i) {
990 Kokkos::parallel_for(Kokkos::ThreadVectorRange(teamMember, _data.this_num_cols), [&] (const int j) {
991 PsqrtW(i, j) = PsqrtW(i, j)*std::sqrt(w(i));
995 teamMember.team_barrier();
1006 KOKKOS_INLINE_FUNCTION
1014 const int local_index = teamMember.league_rank();
#define compadre_kernel_assert_debug(condition)
Kokkos::View< double *, Kokkos::MemoryTraits< Kokkos::Unmanaged > > scratch_vector_type
Kokkos::Random_XorShift64_Pool pool_type
team_policy::member_type member_type
#define TO_GLOBAL(variable)
Kokkos::View< double **, layout_right, Kokkos::MemoryTraits< Kokkos::Unmanaged > > scratch_matrix_right_type
if(some_conditions_for_a_user_defined_operation)
KOKKOS_INLINE_FUNCTION int getThreadScratchLevel(const int level) const
KOKKOS_INLINE_FUNCTION int getTeamScratchLevel(const int level) const
KOKKOS_INLINE_FUNCTION void largestTwoEigenvectorsThreeByThreeSymmetric(const member_type &teamMember, scratch_matrix_right_type V, scratch_matrix_right_type PtP, const int dimensions, pool_type &random_number_pool)
Calculates two eigenvectors corresponding to two dominant eigenvalues.
KOKKOS_INLINE_FUNCTION void computeCurvatureFunctionals(const TargetData &data, const member_type &teamMember, scratch_vector_type delta, scratch_vector_type thread_workspace, scratch_matrix_right_type P_target_row, const scratch_matrix_right_type *V, const local_index_type local_neighbor_index=-1)
Evaluates a polynomial basis for the curvature with a gradient target functional applied.
constexpr SamplingFunctional VaryingManifoldVectorPointSample
For integrating polynomial dotted with normal over an edge.
KOKKOS_INLINE_FUNCTION void computeTargetFunctionals(const TargetData &data, const member_type &teamMember, scratch_vector_type delta, scratch_vector_type thread_workspace, scratch_matrix_right_type P_target_row)
Evaluates a polynomial basis with a target functional applied to each member of the basis.
ConstraintType
Constraint type.
@ NEUMANN_GRAD_SCALAR
Neumann Gradient Scalar Type.
@ NO_CONSTRAINT
No constraint.
constexpr SamplingFunctional StaggeredEdgeIntegralSample
Samples consist of the result of integrals of a vector dotted with the tangent along edges between ne...
KOKKOS_INLINE_FUNCTION void createWeightsAndP(const BasisData &data, const member_type &teamMember, scratch_vector_type delta, scratch_vector_type thread_workspace, scratch_matrix_right_type P, scratch_vector_type w, const int dimension, int polynomial_order, bool weight_p=false, scratch_matrix_right_type *V=NULL, const ReconstructionSpace reconstruction_space=ReconstructionSpace::ScalarTaylorPolynomial, const SamplingFunctional polynomial_sampling_functional=PointSample)
Fills the _P matrix with either P or P*sqrt(w)
constexpr SamplingFunctional PointSample
Available sampling functionals.
ReconstructionSpace
Space in which to reconstruct polynomial.
@ ScalarTaylorPolynomial
Scalar polynomial basis centered at the target site and scaled by sum of basis powers e....
constexpr SamplingFunctional StaggeredEdgeAnalyticGradientIntegralSample
Analytical integral of a gradient source vector is just a difference of the scalar source at neighbor...
KOKKOS_INLINE_FUNCTION void createWeightsAndPForCurvature(const BasisData &data, const member_type &teamMember, scratch_vector_type delta, scratch_vector_type thread_workspace, scratch_matrix_right_type P, scratch_vector_type w, const int dimension, bool only_specific_order, scratch_matrix_right_type *V=NULL)
Fills the _P matrix with P*sqrt(w) for use in solving for curvature.
ProblemType
Problem type, that optionally can handle manifolds.
@ MANIFOLD
Solve GMLS problem on a manifold (will use QR or SVD to solve the resultant GMLS problem dependent on...
constexpr SamplingFunctional ManifoldVectorPointSample
Point evaluations of the entire vector source function (but on a manifold, so it includes a transform...
DenseSolverType
Dense solver type.
@ LU
LU factorization performed on P^T*W*P matrix.
KOKKOS_INLINE_FUNCTION void applyTargetsToCoefficients(const SolutionData &data, const member_type &teamMember, scratch_matrix_right_type Q, scratch_matrix_right_type P_target_row)
For applying the evaluations from a target functional to the polynomial coefficients.
KOKKOS_INLINE_FUNCTION void evaluateConstraints(scratch_matrix_right_type M, scratch_matrix_right_type PsqrtW, const ConstraintType constraint_type, const ReconstructionSpace reconstruction_space, const int NP, const double cutoff_p, const int dimension, const int num_neighbors=0, scratch_matrix_right_type *T=NULL)
KOKKOS_INLINE_FUNCTION void calcGradientPij(const BasisData &data, const member_type &teamMember, double *delta, double *thread_workspace, const int target_index, int neighbor_index, const double alpha, const int partial_direction, const int dimension, const int poly_order, bool specific_order_only, const scratch_matrix_right_type *V, const ReconstructionSpace reconstruction_space, const SamplingFunctional polynomial_sampling_functional, const int evaluation_site_local_index=0)
Evaluates the gradient of a polynomial basis under the Dirac Delta (pointwise) sampling function.
KOKKOS_INLINE_FUNCTION void computeTargetFunctionalsOnManifold(const TargetData &data, const member_type &teamMember, scratch_vector_type delta, scratch_vector_type thread_workspace, scratch_matrix_right_type P_target_row, scratch_matrix_right_type V, scratch_vector_type curvature_coefficients)
Evaluates a polynomial basis with a target functional applied, using information from the manifold cu...
WeightingFunctionType
Available weighting kernel function types.
Functor to evaluate curvature targets and apply to coefficients of curvature reconstruction.
KOKKOS_INLINE_FUNCTION void operator()(const member_type &teamMember) const
ApplyCurvatureTargets(GMLSBasisData data)
Functor to apply target evaluation to polynomial coefficients to store in _alphas.
KOKKOS_INLINE_FUNCTION void operator()(const member_type &teamMember) const
ApplyTargets(GMLSSolutionData data)
Functor to assemble the P*sqrt(weights) matrix and construct sqrt(weights)*Identity for curvature.
AssembleCurvaturePsqrtW(GMLSBasisData data)
KOKKOS_INLINE_FUNCTION void operator()(const member_type &teamMember) const
Functor to assemble the P*sqrt(weights) matrix and construct sqrt(weights)*Identity.
AssembleManifoldPsqrtW(GMLSBasisData data)
KOKKOS_INLINE_FUNCTION void operator()(const member_type &teamMember) const
Functor to assemble the P*sqrt(weights) matrix and construct sqrt(weights)*Identity.
KOKKOS_INLINE_FUNCTION void operator()(const member_type &teamMember) const
AssembleStandardPsqrtW(GMLSBasisData data)
Functor to create a coarse tangent approximation from a given neighborhood of points.
ComputeCoarseTangentPlane(GMLSBasisData data)
KOKKOS_INLINE_FUNCTION void operator()(const member_type &teamMember) const
pool_type _random_number_pool
Functor to calculate prestencil weights to apply to data to transform into a format expected by a GML...
KOKKOS_INLINE_FUNCTION void operator()(const member_type &teamMember) const
ComputePrestencilWeights(GMLSBasisData data)
Functor to evaluate targets on a manifold.
EvaluateManifoldTargets(GMLSBasisData data)
KOKKOS_INLINE_FUNCTION void operator()(const member_type &teamMember) const
Functor to evaluate targets operations on the basis.
KOKKOS_INLINE_FUNCTION void operator()(const member_type &teamMember) const
EvaluateStandardTargets(GMLSBasisData data)
Functor to determine if tangent directions need reordered, and to reorder them if needed We require t...
KOKKOS_INLINE_FUNCTION void operator()(const member_type &teamMember) const
FixTangentDirectionOrdering(GMLSBasisData data)
double * P_target_row_data
int _reconstruction_space_rank
int manifold_gradient_dim
GMLS::point_connections_type _pc
SamplingFunctional _polynomial_sampling_functional
int _initial_index_for_batch
ReconstructionSpace _reconstruction_space
DenseSolverType _dense_solver_type
SolutionSet< device_memory_space > _d_ss
Kokkos::View< double **, layout_right > _source_extra_data
double * manifold_curvature_coefficients_data
ProblemType _problem_type
int _data_sampling_multiplier
WeightingFunctionType _curvature_weighting_type
int _curvature_weighting_n
int _order_of_quadrature_points
GMLS::point_connections_type _additional_pc
Kokkos::View< double *****, layout_right > _prestencil_weights
Kokkos::View< TargetOperation * > _curvature_support_operations
Kokkos::View< double * > _epsilons
Kokkos::View< TargetOperation * > _operations
WeightingFunctionType _weighting_type
Kokkos::View< double **, layout_right > _target_extra_data
SamplingFunctional _data_sampling_functional
int _curvature_poly_order
int _curvature_weighting_p
ConstraintType _constraint_type
int _dimension_of_quadrature_points
double * P_target_row_data
Kokkos::View< int * > additional_number_of_neighbors_list
Kokkos::View< int * > number_of_neighbors_list
SolutionSet< device_memory_space > _d_ss
int _initial_index_for_batch
Functor to evaluate curvature targets and construct accurate tangent direction approximation for mani...
KOKKOS_INLINE_FUNCTION void operator()(const member_type &teamMember) const
GetAccurateTangentDirections(GMLSBasisData data)
KOKKOS_INLINE_FUNCTION int getNumberOfNeighborsDevice(int target_index) const
Get number of neighbors for a given target (device)
KOKKOS_INLINE_FUNCTION XYZ getRelativeCoord(const int target_index, const int neighbor_list_num, const int dimension, const scratch_matrix_right_type *V=NULL) const
Returns the relative coordinate as a vector between the target site and the neighbor site.
KOKKOS_INLINE_FUNCTION int getTargetOffsetIndex(const int lro_num, const int input_component, const int output_component, const int evaluation_site_local_index=0) const
Handles offset from operation input/output + extra evaluation sites.