9 #ifndef _COMPADRE_SCALAR_TAYLORPOLYNOMIAL_BASIS_HPP_
10 #define _COMPADRE_SCALAR_TAYLORPOLYNOMIAL_BASIS_HPP_
22 namespace ScalarTaylorPolynomialBasis {
28 KOKKOS_INLINE_FUNCTION
29 int getSize(
const int degree,
const int dimension) {
30 if (dimension == 3)
return (degree+1)*(degree+2)*(degree+3)/6;
31 else if (dimension == 2)
return (degree+1)*(degree+2)/2;
49 KOKKOS_INLINE_FUNCTION
50 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) {
51 Kokkos::single(Kokkos::PerThread(teamMember), [&] () {
52 const double factorial[] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200};
60 for (
int i=1; i<=max_degree; ++i) {
61 x_over_h_to_i[i] = x_over_h_to_i[i-1]*(x/h);
62 y_over_h_to_i[i] = y_over_h_to_i[i-1]*(y/h);
63 z_over_h_to_i[i] = z_over_h_to_i[i-1]*(z/h);
66 int alphax, alphay, alphaz;
69 for (
int n = starting_order; n <= max_degree; n++){
70 for (alphaz = 0; alphaz <= n; alphaz++){
72 for (alphay = 0; alphay <= s; alphay++){
74 alphaf = factorial[alphax]*factorial[alphay]*factorial[alphaz];
75 *(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;
80 }
else if (dimension==2) {
85 for (
int i=1; i<=max_degree; ++i) {
86 x_over_h_to_i[i] = x_over_h_to_i[i-1]*(x/h);
87 y_over_h_to_i[i] = y_over_h_to_i[i-1]*(y/h);
93 for (
int n = starting_order; n <= max_degree; n++){
94 for (alphay = 0; alphay <= n; alphay++){
96 alphaf = factorial[alphax]*factorial[alphay];
97 *(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;
103 x_over_h_to_i[0] = 1;
104 for (
int i=1; i<=max_degree; ++i) {
105 x_over_h_to_i[i] = x_over_h_to_i[i-1]*(x/h);
108 for (
int i=starting_order; i<=max_degree; ++i) {
109 *(delta+i) = weight_of_original_value * *(delta+i) + weight_of_new_value * x_over_h_to_i[i]/factorial[i];
130 KOKKOS_INLINE_FUNCTION
131 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) {
132 Kokkos::single(Kokkos::PerThread(teamMember), [&] () {
133 const double factorial[] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200};
138 x_over_h_to_i[0] = 1;
139 y_over_h_to_i[0] = 1;
140 z_over_h_to_i[0] = 1;
141 for (
int i=1; i<=max_degree; ++i) {
142 x_over_h_to_i[i] = x_over_h_to_i[i-1]*(x/h);
143 y_over_h_to_i[i] = y_over_h_to_i[i-1]*(y/h);
144 z_over_h_to_i[i] = z_over_h_to_i[i-1]*(z/h);
147 int alphax, alphay, alphaz;
150 for (
int n = starting_order; n <= max_degree; n++){
151 for (alphaz = 0; alphaz <= n; alphaz++){
153 for (alphay = 0; alphay <= s; alphay++){
156 int var_pow[3] = {alphax, alphay, alphaz};
157 var_pow[partial_direction]--;
159 if (var_pow[0]<0 || var_pow[1]<0 || var_pow[2]<0) {
160 *(delta+i) = weight_of_original_value * *(delta+i) + weight_of_new_value * 0.0;
162 alphaf = factorial[var_pow[0]]*factorial[var_pow[1]]*factorial[var_pow[2]];
163 *(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;
169 }
else if (dimension==2) {
172 x_over_h_to_i[0] = 1;
173 y_over_h_to_i[0] = 1;
174 for (
int i=1; i<=max_degree; ++i) {
175 x_over_h_to_i[i] = x_over_h_to_i[i-1]*(x/h);
176 y_over_h_to_i[i] = y_over_h_to_i[i-1]*(y/h);
182 for (
int n = starting_order; n <= max_degree; n++){
183 for (alphay = 0; alphay <= n; alphay++){
186 int var_pow[2] = {alphax, alphay};
187 var_pow[partial_direction]--;
189 if (var_pow[0]<0 || var_pow[1]<0) {
190 *(delta+i) = weight_of_original_value * *(delta+i) + weight_of_new_value * 0.0;
192 alphaf = factorial[var_pow[0]]*factorial[var_pow[1]];
193 *(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;
200 x_over_h_to_i[0] = 1;
201 for (
int i=1; i<=max_degree; ++i) {
202 x_over_h_to_i[i] = x_over_h_to_i[i-1]*(x/h);
207 for (
int n = starting_order; n <= max_degree; n++){
210 int var_pow[1] = {alphax};
211 var_pow[partial_direction]--;
214 *(delta+i) = weight_of_original_value * *(delta+i) + weight_of_new_value * 0.0;
216 alphaf = factorial[var_pow[0]];
217 *(delta+i) = weight_of_original_value * *(delta+i) + weight_of_new_value * 1./h * x_over_h_to_i[var_pow[0]]/alphaf;
241 KOKKOS_INLINE_FUNCTION
242 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) {
243 Kokkos::single(Kokkos::PerThread(teamMember), [&] () {
244 const double factorial[] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200};
249 x_over_h_to_i[0] = 1;
250 y_over_h_to_i[0] = 1;
251 z_over_h_to_i[0] = 1;
252 for (
int i=1; i<=max_degree; ++i) {
253 x_over_h_to_i[i] = x_over_h_to_i[i-1]*(x/h);
254 y_over_h_to_i[i] = y_over_h_to_i[i-1]*(y/h);
255 z_over_h_to_i[i] = z_over_h_to_i[i-1]*(z/h);
258 int alphax, alphay, alphaz;
261 for (
int n = starting_order; n <= max_degree; n++){
262 for (alphaz = 0; alphaz <= n; alphaz++){
264 for (alphay = 0; alphay <= s; alphay++){
267 int var_pow[3] = {alphax, alphay, alphaz};
268 var_pow[partial_direction_1]--;
269 var_pow[partial_direction_2]--;
271 if (var_pow[0]<0 || var_pow[1]<0 || var_pow[2]<0) {
272 *(delta+i) = weight_of_original_value * *(delta+i) + weight_of_new_value * 0.0;
274 alphaf = factorial[var_pow[0]]*factorial[var_pow[1]]*factorial[var_pow[2]];
275 *(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;
281 }
else if (dimension==2) {
284 x_over_h_to_i[0] = 1;
285 y_over_h_to_i[0] = 1;
286 for (
int i=1; i<=max_degree; ++i) {
287 x_over_h_to_i[i] = x_over_h_to_i[i-1]*(x/h);
288 y_over_h_to_i[i] = y_over_h_to_i[i-1]*(y/h);
294 for (
int n = starting_order; n <= max_degree; n++){
295 for (alphay = 0; alphay <= n; alphay++){
298 int var_pow[2] = {alphax, alphay};
299 var_pow[partial_direction_1]--;
300 var_pow[partial_direction_2]--;
302 if (var_pow[0]<0 || var_pow[1]<0) {
303 *(delta+i) = weight_of_original_value * *(delta+i) + weight_of_new_value * 0.0;
305 alphaf = factorial[var_pow[0]]*factorial[var_pow[1]];
306 *(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;
313 x_over_h_to_i[0] = 1;
314 for (
int i=1; i<=max_degree; ++i) {
315 x_over_h_to_i[i] = x_over_h_to_i[i-1]*(x/h);
320 for (
int n = starting_order; n <= max_degree; n++){
323 int var_pow[1] = {alphax};
324 var_pow[partial_direction_1]--;
325 var_pow[partial_direction_2]--;
328 *(delta+i) = weight_of_original_value * *(delta+i) + weight_of_new_value * 0.0;
330 alphaf = factorial[var_pow[0]];
331 *(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