1a8de75f0Sjeremylt /// @file 252bfb9bbSJeremy L Thompson /// Test interpolation in multiple dimensions 352bfb9bbSJeremy L Thompson /// \test Test interpolation in multiple dimensions 4a8de75f0Sjeremylt #include <ceed.h> 5a8de75f0Sjeremylt #include <math.h> 6a8de75f0Sjeremylt 752bfb9bbSJeremy L Thompson static CeedScalar Eval(CeedInt dim, const CeedScalar x[]) { 852bfb9bbSJeremy L Thompson CeedScalar result = 1, center = 0.1; 952bfb9bbSJeremy L Thompson for (CeedInt d=0; d<dim; d++) { 1052bfb9bbSJeremy L Thompson result *= tanh(x[d] - center); 1152bfb9bbSJeremy L Thompson center += 0.1; 12a8de75f0Sjeremylt } 1352bfb9bbSJeremy L Thompson return result; 14a8de75f0Sjeremylt } 15a8de75f0Sjeremylt 16a8de75f0Sjeremylt int main(int argc, char **argv) { 17a8de75f0Sjeremylt Ceed ceed; 18a8de75f0Sjeremylt 19a8de75f0Sjeremylt CeedInit(argv[1], &ceed); 2052bfb9bbSJeremy L Thompson for (CeedInt dim=1; dim<=3; dim++) { 2152bfb9bbSJeremy L Thompson CeedVector X, Xq, U, Uq; 2252bfb9bbSJeremy L Thompson CeedBasis bxl, bul, bxg, bug; 2352bfb9bbSJeremy L Thompson CeedInt Q = 10, Qdim = CeedIntPow(Q, dim), Xdim = CeedIntPow(2, dim); 2452bfb9bbSJeremy L Thompson CeedScalar x[Xdim*dim]; 2552bfb9bbSJeremy L Thompson const CeedScalar *xq, *u; 2652bfb9bbSJeremy L Thompson CeedScalar uq[Qdim]; 27aedaa0e5Sjeremylt 2852bfb9bbSJeremy L Thompson for (CeedInt d=0; d<dim; d++) 2952bfb9bbSJeremy L Thompson for (CeedInt i=0; i<Xdim; i++) 3052bfb9bbSJeremy L Thompson x[d*Xdim + i] = (i % CeedIntPow(2, dim-d)) / CeedIntPow(2, dim-d-1) ? 1 : -1; 31a8de75f0Sjeremylt 3252bfb9bbSJeremy L Thompson CeedVectorCreate(ceed, Xdim*dim, &X); 3352bfb9bbSJeremy L Thompson CeedVectorSetArray(X, CEED_MEM_HOST, CEED_USE_POINTER, x); 3452bfb9bbSJeremy L Thompson CeedVectorCreate(ceed, Qdim*dim, &Xq); 3552bfb9bbSJeremy L Thompson CeedVectorSetValue(Xq, 0); 3652bfb9bbSJeremy L Thompson CeedVectorCreate(ceed, Qdim, &U); 3752bfb9bbSJeremy L Thompson CeedVectorSetValue(U, 0); 3852bfb9bbSJeremy L Thompson CeedVectorCreate(ceed, Qdim, &Uq); 39aedaa0e5Sjeremylt 4052bfb9bbSJeremy L Thompson CeedBasisCreateTensorH1Lagrange(ceed, dim, dim, 2, Q, CEED_GAUSS_LOBATTO, &bxl); 4152bfb9bbSJeremy L Thompson CeedBasisCreateTensorH1Lagrange(ceed, dim, 1, Q, Q, CEED_GAUSS_LOBATTO, &bul); 42aedaa0e5Sjeremylt 4352bfb9bbSJeremy L Thompson CeedBasisApply(bxl, 1, CEED_NOTRANSPOSE, CEED_EVAL_INTERP, X, Xq); 44a8de75f0Sjeremylt 4552bfb9bbSJeremy L Thompson CeedVectorGetArrayRead(Xq, CEED_MEM_HOST, &xq); 4652bfb9bbSJeremy L Thompson for (CeedInt i=0; i<Qdim; i++) { 4752bfb9bbSJeremy L Thompson CeedScalar xx[dim]; 4852bfb9bbSJeremy L Thompson for (CeedInt d=0; d<dim; d++) 4952bfb9bbSJeremy L Thompson xx[d] = xq[d*Qdim + i]; 5052bfb9bbSJeremy L Thompson uq[i] = Eval(dim, xx); 5152bfb9bbSJeremy L Thompson } 5252bfb9bbSJeremy L Thompson CeedVectorRestoreArrayRead(Xq, &xq); 5352bfb9bbSJeremy L Thompson CeedVectorSetArray(Uq, CEED_MEM_HOST, CEED_USE_POINTER, uq); 5452bfb9bbSJeremy L Thompson 5552bfb9bbSJeremy L Thompson // This operation is the identity because the quadrature is collocated 5652bfb9bbSJeremy L Thompson CeedBasisApply(bul, 1, CEED_TRANSPOSE, CEED_EVAL_INTERP, Uq, U); 5752bfb9bbSJeremy L Thompson 5852bfb9bbSJeremy L Thompson CeedBasisCreateTensorH1Lagrange(ceed, dim, dim, 2, Q, CEED_GAUSS, &bxg); 5952bfb9bbSJeremy L Thompson CeedBasisCreateTensorH1Lagrange(ceed, dim, 1, Q, Q, CEED_GAUSS, &bug); 6052bfb9bbSJeremy L Thompson 6152bfb9bbSJeremy L Thompson CeedBasisApply(bxg, 1, CEED_NOTRANSPOSE, CEED_EVAL_INTERP, X, Xq); 6252bfb9bbSJeremy L Thompson CeedBasisApply(bug, 1, CEED_NOTRANSPOSE, CEED_EVAL_INTERP, U, Uq); 6352bfb9bbSJeremy L Thompson 6452bfb9bbSJeremy L Thompson CeedVectorGetArrayRead(Xq, CEED_MEM_HOST, &xq); 6552bfb9bbSJeremy L Thompson CeedVectorGetArrayRead(Uq, CEED_MEM_HOST, &u); 6652bfb9bbSJeremy L Thompson for (CeedInt i=0; i<Qdim; i++) { 6752bfb9bbSJeremy L Thompson CeedScalar xx[dim]; 6852bfb9bbSJeremy L Thompson for (CeedInt d=0; d<dim; d++) 6952bfb9bbSJeremy L Thompson xx[d] = xq[d*Qdim + i]; 7052bfb9bbSJeremy L Thompson CeedScalar fx = Eval(dim, xx); 71*e41a9036Svaleriabarra if (fabs(u[i] - fx) > 1E-4) { 72a2546046Sjeremylt // LCOV_EXCL_START 7352bfb9bbSJeremy L Thompson printf("[%d] %f != %f=f(%f", dim, u[i], fx, xx[0]); 7452bfb9bbSJeremy L Thompson for (CeedInt d=1; d<dim; d++) printf(",%f", xx[d]); 7552bfb9bbSJeremy L Thompson puts(")"); 76de996c55Sjeremylt // LCOV_EXCL_STOP 77a8de75f0Sjeremylt } 7852bfb9bbSJeremy L Thompson } 7952bfb9bbSJeremy L Thompson CeedVectorRestoreArrayRead(Xq, &xq); 8052bfb9bbSJeremy L Thompson CeedVectorRestoreArrayRead(Uq, &u); 81a8de75f0Sjeremylt 8252bfb9bbSJeremy L Thompson CeedVectorDestroy(&X); 8352bfb9bbSJeremy L Thompson CeedVectorDestroy(&Xq); 8452bfb9bbSJeremy L Thompson CeedVectorDestroy(&U); 8552bfb9bbSJeremy L Thompson CeedVectorDestroy(&Uq); 8652bfb9bbSJeremy L Thompson CeedBasisDestroy(&bxl); 8752bfb9bbSJeremy L Thompson CeedBasisDestroy(&bul); 8852bfb9bbSJeremy L Thompson CeedBasisDestroy(&bxg); 8952bfb9bbSJeremy L Thompson CeedBasisDestroy(&bug); 9052bfb9bbSJeremy L Thompson } 91a8de75f0Sjeremylt CeedDestroy(&ceed); 92a8de75f0Sjeremylt return 0; 93a8de75f0Sjeremylt } 94