1d3f518cbSJeremy L Thompson /// @file 2d3f518cbSJeremy L Thompson /// Test high order interpolation in multiple dimensions 3d3f518cbSJeremy L Thompson /// \test Test high order interpolation in multiple dimensions 4d3f518cbSJeremy L Thompson #include <ceed.h> 5d3f518cbSJeremy L Thompson #include <math.h> 6*49aac155SJeremy L Thompson #include <stdio.h> 7d3f518cbSJeremy L Thompson 8d3f518cbSJeremy L Thompson static CeedScalar Eval(CeedInt dim, const CeedScalar x[]) { 9d3f518cbSJeremy L Thompson CeedScalar result = 1, center = 0.1; 10d3f518cbSJeremy L Thompson for (CeedInt d = 0; d < dim; d++) { 11d3f518cbSJeremy L Thompson result *= tanh(x[d] - center); 12d3f518cbSJeremy L Thompson center += 0.1; 13d3f518cbSJeremy L Thompson } 14d3f518cbSJeremy L Thompson return result; 15d3f518cbSJeremy L Thompson } 16d3f518cbSJeremy L Thompson 17d3f518cbSJeremy L Thompson int main(int argc, char **argv) { 18d3f518cbSJeremy L Thompson Ceed ceed; 19d3f518cbSJeremy L Thompson 20d3f518cbSJeremy L Thompson CeedInit(argv[1], &ceed); 21d3f518cbSJeremy L Thompson for (CeedInt dim = 1; dim <= 3; dim++) { 224fee36f0SJeremy L Thompson CeedVector x, x_q, u, u_q; 23d1d35e2fSjeremylt CeedBasis basis_x_lobatto, basis_u_lobatto, basis_x_gauss, basis_u_gauss; 244fee36f0SJeremy L Thompson CeedInt q = 11, q_dim = CeedIntPow(q, dim), x_dim = CeedIntPow(2, dim); 25d3f518cbSJeremy L Thompson 264fee36f0SJeremy L Thompson CeedVectorCreate(ceed, x_dim * dim, &x); 274fee36f0SJeremy L Thompson { 284fee36f0SJeremy L Thompson CeedScalar x_array[x_dim * dim]; 29d3f518cbSJeremy L Thompson 304fee36f0SJeremy L Thompson for (CeedInt d = 0; d < dim; d++) { 314fee36f0SJeremy L Thompson for (CeedInt i = 0; i < x_dim; i++) x_array[d * x_dim + i] = (i % CeedIntPow(2, dim - d)) / CeedIntPow(2, dim - d - 1) ? 1 : -1; 32d3f518cbSJeremy L Thompson } 334fee36f0SJeremy L Thompson CeedVectorSetArray(x, CEED_MEM_HOST, CEED_COPY_VALUES, x_array); 344fee36f0SJeremy L Thompson } 354fee36f0SJeremy L Thompson CeedVectorCreate(ceed, q_dim * dim, &x_q); 364fee36f0SJeremy L Thompson CeedVectorSetValue(x_q, 0); 374fee36f0SJeremy L Thompson CeedVectorCreate(ceed, q_dim, &u); 384fee36f0SJeremy L Thompson CeedVectorSetValue(u, 0); 394fee36f0SJeremy L Thompson CeedVectorCreate(ceed, q_dim, &u_q); 404fee36f0SJeremy L Thompson 414fee36f0SJeremy L Thompson CeedBasisCreateTensorH1Lagrange(ceed, dim, dim, 2, q, CEED_GAUSS_LOBATTO, &basis_x_lobatto); 424fee36f0SJeremy L Thompson CeedBasisCreateTensorH1Lagrange(ceed, dim, 1, q, q, CEED_GAUSS_LOBATTO, &basis_u_lobatto); 434fee36f0SJeremy L Thompson 444fee36f0SJeremy L Thompson CeedBasisApply(basis_x_lobatto, 1, CEED_NOTRANSPOSE, CEED_EVAL_INTERP, x, x_q); 454fee36f0SJeremy L Thompson 464fee36f0SJeremy L Thompson { 474fee36f0SJeremy L Thompson const CeedScalar *x_q_array; 484fee36f0SJeremy L Thompson CeedScalar u_q_array[q_dim]; 494fee36f0SJeremy L Thompson 504fee36f0SJeremy L Thompson CeedVectorGetArrayRead(x_q, CEED_MEM_HOST, &x_q_array); 514fee36f0SJeremy L Thompson for (CeedInt i = 0; i < q_dim; i++) { 524fee36f0SJeremy L Thompson CeedScalar coord[dim]; 534fee36f0SJeremy L Thompson for (CeedInt d = 0; d < dim; d++) coord[d] = x_q_array[d * q_dim + i]; 544fee36f0SJeremy L Thompson u_q_array[i] = Eval(dim, coord); 554fee36f0SJeremy L Thompson } 564fee36f0SJeremy L Thompson CeedVectorRestoreArrayRead(x_q, &x_q_array); 574fee36f0SJeremy L Thompson CeedVectorSetArray(u_q, CEED_MEM_HOST, CEED_COPY_VALUES, u_q_array); 584fee36f0SJeremy L Thompson } 59d3f518cbSJeremy L Thompson 60d3f518cbSJeremy L Thompson // This operation is the identity because the quadrature is collocated 614fee36f0SJeremy L Thompson CeedBasisApply(basis_u_lobatto, 1, CEED_TRANSPOSE, CEED_EVAL_INTERP, u_q, u); 62d3f518cbSJeremy L Thompson 634fee36f0SJeremy L Thompson CeedBasisCreateTensorH1Lagrange(ceed, dim, dim, 2, q, CEED_GAUSS, &basis_x_gauss); 644fee36f0SJeremy L Thompson CeedBasisCreateTensorH1Lagrange(ceed, dim, 1, q, q, CEED_GAUSS, &basis_u_gauss); 65d3f518cbSJeremy L Thompson 664fee36f0SJeremy L Thompson CeedBasisApply(basis_x_gauss, 1, CEED_NOTRANSPOSE, CEED_EVAL_INTERP, x, x_q); 674fee36f0SJeremy L Thompson CeedBasisApply(basis_u_gauss, 1, CEED_NOTRANSPOSE, CEED_EVAL_INTERP, u, u_q); 68d3f518cbSJeremy L Thompson 694fee36f0SJeremy L Thompson { 704fee36f0SJeremy L Thompson const CeedScalar *x_q_array, *u_array; 714fee36f0SJeremy L Thompson 724fee36f0SJeremy L Thompson CeedVectorGetArrayRead(x_q, CEED_MEM_HOST, &x_q_array); 734fee36f0SJeremy L Thompson CeedVectorGetArrayRead(u_q, CEED_MEM_HOST, &u_array); 744fee36f0SJeremy L Thompson for (CeedInt i = 0; i < q_dim; i++) { 754fee36f0SJeremy L Thompson CeedScalar coord[dim]; 764fee36f0SJeremy L Thompson for (CeedInt d = 0; d < dim; d++) coord[d] = x_q_array[d * q_dim + i]; 774fee36f0SJeremy L Thompson CeedScalar fx = Eval(dim, coord); 784fee36f0SJeremy L Thompson if (fabs(u_array[i] - fx) > 1E-4) { 79d3f518cbSJeremy L Thompson // LCOV_EXCL_START 804fee36f0SJeremy L Thompson printf("[%" CeedInt_FMT "] %f != %f = f(%f", dim, u_array[i], fx, coord[0]); 814fee36f0SJeremy L Thompson for (CeedInt d = 1; d < dim; d++) printf(",%f", coord[d]); 82d3f518cbSJeremy L Thompson puts(")"); 83d3f518cbSJeremy L Thompson // LCOV_EXCL_STOP 84d3f518cbSJeremy L Thompson } 85d3f518cbSJeremy L Thompson } 864fee36f0SJeremy L Thompson CeedVectorRestoreArrayRead(x_q, &x_q_array); 874fee36f0SJeremy L Thompson CeedVectorRestoreArrayRead(u_q, &u_array); 884fee36f0SJeremy L Thompson } 89d3f518cbSJeremy L Thompson 904fee36f0SJeremy L Thompson CeedVectorDestroy(&x); 914fee36f0SJeremy L Thompson CeedVectorDestroy(&x_q); 924fee36f0SJeremy L Thompson CeedVectorDestroy(&u); 934fee36f0SJeremy L Thompson CeedVectorDestroy(&u_q); 94d1d35e2fSjeremylt CeedBasisDestroy(&basis_x_lobatto); 95d1d35e2fSjeremylt CeedBasisDestroy(&basis_u_lobatto); 96d1d35e2fSjeremylt CeedBasisDestroy(&basis_x_gauss); 97d1d35e2fSjeremylt CeedBasisDestroy(&basis_u_gauss); 98d3f518cbSJeremy L Thompson } 99d3f518cbSJeremy L Thompson CeedDestroy(&ceed); 100d3f518cbSJeremy L Thompson return 0; 101d3f518cbSJeremy L Thompson } 102