1 #ifndef _COMPADRE_SCALAR_TAYLORPOLYNOMIAL_BASIS_HPP_
2 #define _COMPADRE_SCALAR_TAYLORPOLYNOMIAL_BASIS_HPP_
14 namespace ScalarTaylorPolynomialBasis {
20 KOKKOS_INLINE_FUNCTION
21 int getSize(
const int degree,
const int dimension) {
22 if (dimension == 3)
return (degree+1)*(degree+2)*(degree+3)/6;
23 else if (dimension == 2)
return (degree+1)*(degree+2)/2;
41 KOKKOS_INLINE_FUNCTION
42 void evaluate(
const member_type& teamMember,
double* delta,
double* workspace,
const int dimension,
const int max_degree,
const double h,
const double x,
const double y,
const double z,
const int starting_order = 0,
const double weight_of_original_value = 0.0,
const double weight_of_new_value = 1.0) {
43 Kokkos::single(Kokkos::PerThread(teamMember), [&] () {
44 const double factorial[] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200};
52 for (
int i=1; i<=max_degree; ++i) {
53 x_over_h_to_i[i] = x_over_h_to_i[i-1]*(x/h);
54 y_over_h_to_i[i] = y_over_h_to_i[i-1]*(y/h);
55 z_over_h_to_i[i] = z_over_h_to_i[i-1]*(z/h);
58 int alphax, alphay, alphaz;
61 for (
int n = starting_order; n <= max_degree; n++){
62 for (alphaz = 0; alphaz <= n; alphaz++){
64 for (alphay = 0; alphay <= s; alphay++){
66 alphaf = factorial[alphax]*factorial[alphay]*factorial[alphaz];
67 *(delta+i) = weight_of_original_value * *(delta+i) + weight_of_new_value * x_over_h_to_i[alphax]*y_over_h_to_i[alphay]*z_over_h_to_i[alphaz]/alphaf;
72 }
else if (dimension==2) {
77 for (
int i=1; i<=max_degree; ++i) {
78 x_over_h_to_i[i] = x_over_h_to_i[i-1]*(x/h);
79 y_over_h_to_i[i] = y_over_h_to_i[i-1]*(y/h);
85 for (
int n = starting_order; n <= max_degree; n++){
86 for (alphay = 0; alphay <= n; alphay++){
88 alphaf = factorial[alphax]*factorial[alphay];
89 *(delta+i) = weight_of_original_value * *(delta+i) + weight_of_new_value * x_over_h_to_i[alphax]*y_over_h_to_i[alphay]/alphaf;
96 for (
int i=1; i<=max_degree; ++i) {
97 x_over_h_to_i[i] = x_over_h_to_i[i-1]*(x/h);
100 for (
int i=starting_order; i<=max_degree; ++i) {
101 *(delta+i) = weight_of_original_value * *(delta+i) + weight_of_new_value * x_over_h_to_i[i]/factorial[i];
122 KOKKOS_INLINE_FUNCTION
123 void evaluatePartialDerivative(
const member_type& teamMember,
double* delta,
double* workspace,
const int dimension,
const int max_degree,
const int partial_direction,
const double h,
const double x,
const double y,
const double z,
const int starting_order = 0,
const double weight_of_original_value = 0.0,
const double weight_of_new_value = 1.0) {
124 Kokkos::single(Kokkos::PerThread(teamMember), [&] () {
125 const double factorial[] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200};
130 x_over_h_to_i[0] = 1;
131 y_over_h_to_i[0] = 1;
132 z_over_h_to_i[0] = 1;
133 for (
int i=1; i<=max_degree; ++i) {
134 x_over_h_to_i[i] = x_over_h_to_i[i-1]*(x/h);
135 y_over_h_to_i[i] = y_over_h_to_i[i-1]*(y/h);
136 z_over_h_to_i[i] = z_over_h_to_i[i-1]*(z/h);
139 int alphax, alphay, alphaz;
142 for (
int n = starting_order; n <= max_degree; n++){
143 for (alphaz = 0; alphaz <= n; alphaz++){
145 for (alphay = 0; alphay <= s; alphay++){
148 int var_pow[3] = {alphax, alphay, alphaz};
149 var_pow[partial_direction]--;
151 if (var_pow[0]<0 || var_pow[1]<0 || var_pow[2]<0) {
152 *(delta+i) = weight_of_original_value * *(delta+i) + weight_of_new_value * 0.0;
154 alphaf = factorial[var_pow[0]]*factorial[var_pow[1]]*factorial[var_pow[2]];
155 *(delta+i) = weight_of_original_value * *(delta+i) + weight_of_new_value * 1./h * x_over_h_to_i[var_pow[0]]*y_over_h_to_i[var_pow[1]]*z_over_h_to_i[var_pow[2]]/alphaf;
161 }
else if (dimension==2) {
164 x_over_h_to_i[0] = 1;
165 y_over_h_to_i[0] = 1;
166 for (
int i=1; i<=max_degree; ++i) {
167 x_over_h_to_i[i] = x_over_h_to_i[i-1]*(x/h);
168 y_over_h_to_i[i] = y_over_h_to_i[i-1]*(y/h);
174 for (
int n = starting_order; n <= max_degree; n++){
175 for (alphay = 0; alphay <= n; alphay++){
178 int var_pow[2] = {alphax, alphay};
179 var_pow[partial_direction]--;
181 if (var_pow[0]<0 || var_pow[1]<0) {
182 *(delta+i) = weight_of_original_value * *(delta+i) + weight_of_new_value * 0.0;
184 alphaf = factorial[var_pow[0]]*factorial[var_pow[1]];
185 *(delta+i) = weight_of_original_value * *(delta+i) + weight_of_new_value * 1./h * x_over_h_to_i[var_pow[0]]*y_over_h_to_i[var_pow[1]]/alphaf;
192 x_over_h_to_i[0] = 1;
193 for (
int i=1; i<=max_degree; ++i) {
194 x_over_h_to_i[i] = x_over_h_to_i[i-1]*(x/h);
199 for (
int n = starting_order; n <= max_degree; n++){
202 int var_pow[1] = {alphax};
203 var_pow[partial_direction]--;
206 *(delta+i) = weight_of_original_value * *(delta+i) + weight_of_new_value * 0.0;
208 alphaf = factorial[var_pow[0]];
209 *(delta+i) = weight_of_original_value * *(delta+i) + weight_of_new_value * 1./h * x_over_h_to_i[var_pow[0]]/alphaf;
233 KOKKOS_INLINE_FUNCTION
234 void evaluateSecondPartialDerivative(
const member_type& teamMember,
double* delta,
double* workspace,
const int dimension,
const int max_degree,
const int partial_direction_1,
const int partial_direction_2,
const double h,
const double x,
const double y,
const double z,
const int starting_order = 0,
const double weight_of_original_value = 0.0,
const double weight_of_new_value = 1.0) {
235 Kokkos::single(Kokkos::PerThread(teamMember), [&] () {
236 const double factorial[] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200};
241 x_over_h_to_i[0] = 1;
242 y_over_h_to_i[0] = 1;
243 z_over_h_to_i[0] = 1;
244 for (
int i=1; i<=max_degree; ++i) {
245 x_over_h_to_i[i] = x_over_h_to_i[i-1]*(x/h);
246 y_over_h_to_i[i] = y_over_h_to_i[i-1]*(y/h);
247 z_over_h_to_i[i] = z_over_h_to_i[i-1]*(z/h);
250 int alphax, alphay, alphaz;
253 for (
int n = starting_order; n <= max_degree; n++){
254 for (alphaz = 0; alphaz <= n; alphaz++){
256 for (alphay = 0; alphay <= s; alphay++){
259 int var_pow[3] = {alphax, alphay, alphaz};
260 var_pow[partial_direction_1]--;
261 var_pow[partial_direction_2]--;
263 if (var_pow[0]<0 || var_pow[1]<0 || var_pow[2]<0) {
264 *(delta+i) = weight_of_original_value * *(delta+i) + weight_of_new_value * 0.0;
266 alphaf = factorial[var_pow[0]]*factorial[var_pow[1]]*factorial[var_pow[2]];
267 *(delta+i) = weight_of_original_value * *(delta+i) + weight_of_new_value * 1./h * x_over_h_to_i[var_pow[0]]*y_over_h_to_i[var_pow[1]]*z_over_h_to_i[var_pow[2]]/alphaf;
273 }
else if (dimension==2) {
276 x_over_h_to_i[0] = 1;
277 y_over_h_to_i[0] = 1;
278 for (
int i=1; i<=max_degree; ++i) {
279 x_over_h_to_i[i] = x_over_h_to_i[i-1]*(x/h);
280 y_over_h_to_i[i] = y_over_h_to_i[i-1]*(y/h);
286 for (
int n = starting_order; n <= max_degree; n++){
287 for (alphay = 0; alphay <= n; alphay++){
290 int var_pow[2] = {alphax, alphay};
291 var_pow[partial_direction_1]--;
292 var_pow[partial_direction_2]--;
294 if (var_pow[0]<0 || var_pow[1]<0) {
295 *(delta+i) = weight_of_original_value * *(delta+i) + weight_of_new_value * 0.0;
297 alphaf = factorial[var_pow[0]]*factorial[var_pow[1]];
298 *(delta+i) = weight_of_original_value * *(delta+i) + weight_of_new_value * 1./h * x_over_h_to_i[var_pow[0]]*y_over_h_to_i[var_pow[1]]/alphaf;
305 x_over_h_to_i[0] = 1;
306 for (
int i=1; i<=max_degree; ++i) {
307 x_over_h_to_i[i] = x_over_h_to_i[i-1]*(x/h);
312 for (
int n = starting_order; n <= max_degree; n++){
315 int var_pow[1] = {alphax};
316 var_pow[partial_direction_1]--;
317 var_pow[partial_direction_2]--;
320 *(delta+i) = weight_of_original_value * *(delta+i) + weight_of_new_value * 0.0;
322 alphaf = factorial[var_pow[0]];
323 *(delta+i) = weight_of_original_value * *(delta+i) + weight_of_new_value * 1./h * x_over_h_to_i[var_pow[0]]/alphaf;
KOKKOS_INLINE_FUNCTION int getSize(const int degree, const int dimension)
Returns size of basis.
KOKKOS_INLINE_FUNCTION void evaluatePartialDerivative(const member_type &teamMember, double *delta, double *workspace, const int dimension, const int max_degree, const int partial_direction, const double h, const double x, const double y, const double z, const int starting_order=0, const double weight_of_original_value=0.0, const double weight_of_new_value=1.0)
Evaluates the first partial derivatives of scalar Taylor polynomial basis delta[j] = weight_of_origin...
team_policy::member_type member_type
KOKKOS_INLINE_FUNCTION void evaluate(const member_type &teamMember, double *delta, double *workspace, const int dimension, const int max_degree, const double h, const double x, const double y, const double z, const int starting_order=0, const double weight_of_original_value=0.0, const double weight_of_new_value=1.0)
Evaluates the scalar Taylor polynomial basis delta[j] = weight_of_original_value * delta[j] + weight_...
KOKKOS_INLINE_FUNCTION void evaluateSecondPartialDerivative(const member_type &teamMember, double *delta, double *workspace, const int dimension, const int max_degree, const int partial_direction_1, const int partial_direction_2, const double h, const double x, const double y, const double z, const int starting_order=0, const double weight_of_original_value=0.0, const double weight_of_new_value=1.0)
Evaluates the second partial derivatives of scalar Taylor polynomial basis delta[j] = weight_of_origi...
Kokkos::View< double *, Kokkos::MemoryTraits< Kokkos::Unmanaged > > scratch_vector_type