48 ierr = CeedOperatorGetCeed(op, &ceed); PCeedChk(ierr);
52 ierr = CeedOperatorGetQFunction(op, &qf); PCeedChk(ierr);
53 CeedInt numinputfields, numoutputfields;
55 CeedVector assembledqf;
56 CeedElemRestriction rstr_q;
57 ierr = CeedOperatorLinearAssembleQFunction(
58 op, &assembledqf, &rstr_q, CEED_REQUEST_IMMEDIATE); PCeedChk(ierr);
61 ierr = CeedVectorGetLength(assembledqf, &qflength); PCeedChk(ierr);
63 CeedOperatorField *input_fields;
64 CeedOperatorField *output_fields;
65 ierr = CeedOperatorGetFields(op, &numinputfields, &input_fields,
66 &numoutputfields, &output_fields);
70 CeedQFunctionField *qffields;
71 ierr = CeedQFunctionGetFields(qf, &numinputfields, &qffields,
72 &numoutputfields, NULL);
74 CeedInt numemodein = 0, ncomp,
dim = 1;
75 CeedEvalMode *emodein = NULL;
76 CeedBasis basisin = NULL;
77 CeedElemRestriction rstrin = NULL;
78 for (CeedInt i=0; i<numinputfields; i++)
81 ierr = CeedOperatorFieldGetVector(input_fields[i], &vec); PCeedChk(ierr);
82 if (vec == CEED_VECTOR_ACTIVE)
84 ierr = CeedOperatorFieldGetBasis(input_fields[i], &basisin);
86 ierr = CeedBasisGetNumComponents(basisin, &ncomp); PCeedChk(ierr);
87 ierr = CeedBasisGetDimension(basisin, &
dim); PCeedChk(ierr);
88 ierr = CeedOperatorFieldGetElemRestriction(input_fields[i], &rstrin);
91 ierr = CeedQFunctionFieldGetEvalMode(qffields[i], &emode);
96 case CEED_EVAL_INTERP:
97 ierr = CeedHackRealloc(numemodein + 1, &emodein); PCeedChk(ierr);
98 emodein[numemodein] = emode;
102 ierr = CeedHackRealloc(numemodein +
dim, &emodein); PCeedChk(ierr);
103 for (CeedInt d=0; d<
dim; d++)
105 emodein[numemodein+d] = emode;
109 case CEED_EVAL_WEIGHT:
118 ierr = CeedQFunctionGetFields(qf, &numinputfields, NULL, &numoutputfields,
119 &qffields); PCeedChk(ierr);
120 CeedInt numemodeout = 0;
121 CeedEvalMode *emodeout = NULL;
122 CeedBasis basisout = NULL;
123 CeedElemRestriction rstrout = NULL;
124 for (CeedInt i=0; i<numoutputfields; i++)
127 ierr = CeedOperatorFieldGetVector(output_fields[i], &vec); PCeedChk(ierr);
128 if (vec == CEED_VECTOR_ACTIVE)
130 ierr = CeedOperatorFieldGetBasis(output_fields[i], &basisout);
132 ierr = CeedOperatorFieldGetElemRestriction(output_fields[i], &rstrout);
136 ierr = CeedQFunctionFieldGetEvalMode(qffields[i], &emode);
141 case CEED_EVAL_INTERP:
142 ierr = CeedHackRealloc(numemodeout + 1, &emodeout); PCeedChk(ierr);
143 emodeout[numemodeout] = emode;
147 ierr = CeedHackRealloc(numemodeout +
dim, &emodeout); PCeedChk(ierr);
148 for (CeedInt d=0; d<
dim; d++)
150 emodeout[numemodeout+d] = emode;
154 case CEED_EVAL_WEIGHT:
162 CeedInt nelem, elemsize, nqpts;
164 ierr = CeedElemRestrictionGetNumElements(rstrin, &nelem); PCeedChk(ierr);
165 ierr = CeedElemRestrictionGetElementSize(rstrin, &elemsize); PCeedChk(ierr);
166 ierr = CeedElemRestrictionGetLVectorSize(rstrin, &nnodes); PCeedChk(ierr);
167 ierr = CeedBasisGetNumQuadraturePoints(basisin, &nqpts); PCeedChk(ierr);
170 CeedVector index_vec;
171 ierr = CeedVectorCreate(ceed, nnodes, &index_vec); PCeedChk(ierr);
173 ierr = CeedVectorGetArrayWrite(index_vec, CEED_MEM_HOST, &array);
175 for (CeedSize i = 0; i < nnodes; ++i)
179 ierr = CeedVectorRestoreArray(index_vec, &array); PCeedChk(ierr);
181 ierr = CeedVectorCreate(ceed, nelem * elemsize, &elem_dof); PCeedChk(ierr);
182 ierr = CeedVectorSetValue(elem_dof, 0.0); PCeedChk(ierr);
183 CeedElemRestrictionApply(rstrin, CEED_NOTRANSPOSE, index_vec,
184 elem_dof, CEED_REQUEST_IMMEDIATE); PCeedChk(ierr);
185 const CeedScalar * elem_dof_a;
186 ierr = CeedVectorGetArrayRead(elem_dof, CEED_MEM_HOST, &elem_dof_a);
188 ierr = CeedVectorDestroy(&index_vec); PCeedChk(ierr);
192 MFEM_ASSERT(
out->Height() == nnodes,
"Sizes don't match!");
193 MFEM_ASSERT(
out->Width() == nnodes,
"Sizes don't match!");
194 const CeedScalar *interpin, *gradin;
195 ierr = CeedBasisGetInterp(basisin, &interpin); PCeedChk(ierr);
196 ierr = CeedBasisGetGrad(basisin, &gradin); PCeedChk(ierr);
198 const CeedScalar * assembledqfarray;
199 ierr = CeedVectorGetArrayRead(assembledqf, CEED_MEM_HOST, &assembledqfarray);
203 ierr = CeedElemRestrictionGetELayout(rstr_q, &layout); PCeedChk(ierr);
204 ierr = CeedElemRestrictionDestroy(&rstr_q); PCeedChk(ierr);
207 const int skip_zeros = 0;
208 MFEM_ASSERT(numemodein == numemodeout,
209 "Ceed full assembly not implemented for this case.");
210 for (
int e = 0; e < nelem; ++e)
214 for (
int i = 0; i < elemsize; ++i)
216 rows[i] = elem_dof_a[e * elemsize + i];
227 for (
int q = 0; q < nqpts; ++q)
229 for (
int n = 0; n < elemsize; ++n)
232 for (
int ein = 0; ein < numemodein; ++ein)
234 if (emodein[ein] == CEED_EVAL_INTERP)
236 Bmat(numemodein * q + ein, n) += interpin[q * elemsize + n];
238 else if (emodein[ein] == CEED_EVAL_GRAD)
241 Bmat(numemodein * q + ein, n) += gradin[(din*nqpts+q) * elemsize + n];
245 MFEM_ASSERT(
false,
"Not implemented!");
249 for (
int ei = 0; ei < numemodein; ++ei)
251 for (
int ej = 0; ej < numemodein; ++ej)
253 const int comp = ei * numemodein + ej;
254 const int index = q*layout[0] + comp*layout[1] + e*layout[2];
255 Dmat(ei, ej, q) += assembledqfarray[
index];
262 for (
int j=0; j<elemsize; ++j)
264 for (
int q=0; q<nqpts; ++q)
266 int qq = numemodein*q;
267 for (
int ei = 0; ei < numemodein; ++ei)
269 for (
int ej = 0; ej < numemodein; ++ej)
271 BTD(j,qq+ei) += Bmat(qq+ej,j)*Dmat(ej,ei,q);
277 Mult(BTD, Bmat, elem_mat);
280 out->AddSubMatrix(rows, rows, elem_mat, skip_zeros);
283 ierr = CeedVectorRestoreArrayRead(elem_dof, &elem_dof_a); PCeedChk(ierr);
284 ierr = CeedVectorDestroy(&elem_dof); PCeedChk(ierr);
285 ierr = CeedVectorRestoreArrayRead(assembledqf, &assembledqfarray);
287 ierr = CeedVectorDestroy(&assembledqf); PCeedChk(ierr);