xref: /libCEED/tests/t209-elemrestriction.c (revision 2b730f8b5a9c809740a0b3b302db43a719c636b1)
11469ee4dSjeremylt /// @file
21469ee4dSjeremylt /// Test calculation of dof multiplicity in element restriction
31469ee4dSjeremylt /// \test Test calculation of dof multiplicity in element restriction
41469ee4dSjeremylt #include <ceed.h>
51469ee4dSjeremylt 
61469ee4dSjeremylt int main(int argc, char **argv) {
71469ee4dSjeremylt   Ceed                ceed;
81469ee4dSjeremylt   CeedVector          mult;
9d1d35e2fSjeremylt   CeedInt             num_elem = 3;
10d1d35e2fSjeremylt   CeedInt             ind[4 * num_elem];
111469ee4dSjeremylt   const CeedScalar   *mm;
121469ee4dSjeremylt   CeedElemRestriction r;
131469ee4dSjeremylt 
141469ee4dSjeremylt   CeedInit(argv[1], &ceed);
151469ee4dSjeremylt 
16d1d35e2fSjeremylt   CeedVectorCreate(ceed, 3 * num_elem + 1, &mult);
171469ee4dSjeremylt   CeedVectorSetValue(mult, 0);  // Allocates array
181469ee4dSjeremylt 
19d1d35e2fSjeremylt   for (CeedInt i = 0; i < num_elem; i++) {
201469ee4dSjeremylt     ind[4 * i + 0] = i * 3 + 0;
211469ee4dSjeremylt     ind[4 * i + 1] = i * 3 + 1;
221469ee4dSjeremylt     ind[4 * i + 2] = i * 3 + 2;
231469ee4dSjeremylt     ind[4 * i + 3] = i * 3 + 3;
241469ee4dSjeremylt   }
25*2b730f8bSJeremy L Thompson   CeedElemRestrictionCreate(ceed, num_elem, 4, 1, 1, 3 * num_elem + 1, CEED_MEM_HOST, CEED_USE_POINTER, ind, &r);
261469ee4dSjeremylt 
27a8d32208Sjeremylt   CeedElemRestrictionGetMultiplicity(r, mult);
281469ee4dSjeremylt 
291469ee4dSjeremylt   CeedVectorGetArrayRead(mult, CEED_MEM_HOST, &mm);
30*2b730f8bSJeremy L Thompson   for (CeedInt i = 0; i < 3 * num_elem + 1; i++) {
31*2b730f8bSJeremy L Thompson     if ((1 + (i > 0 && i < 3 * num_elem && (i % 3 == 0) ? 1 : 0)) != mm[i]) {
32a2546046Sjeremylt       // LCOV_EXCL_START
33*2b730f8bSJeremy L Thompson       printf("Error in multiplicity vector: mult[%" CeedInt_FMT "] = %f\n", i, (CeedScalar)mm[i]);
34de996c55Sjeremylt       // LCOV_EXCL_STOP
35*2b730f8bSJeremy L Thompson     }
36*2b730f8bSJeremy L Thompson   }
371469ee4dSjeremylt   CeedVectorRestoreArrayRead(mult, &mm);
381469ee4dSjeremylt 
391469ee4dSjeremylt   CeedVectorDestroy(&mult);
401469ee4dSjeremylt   CeedElemRestrictionDestroy(&r);
411469ee4dSjeremylt   CeedDestroy(&ceed);
421469ee4dSjeremylt   return 0;
431469ee4dSjeremylt }
44