14 #include "../../../linalg/sparsemat.hpp" 15 #include "../interface/util.hpp" 16 #include "../interface/ceed.hpp" 28 *(
void **)
p = realloc(*(
void **)
p, n*unit);
29 if (n && unit && !*(
void **)
p)
30 return CeedError(NULL, 1,
"realloc failed to allocate %zd members of size " 35 #define CeedHackRealloc(n, p) CeedHackReallocArray((n), sizeof(**(p)), p) 48 ierr = CeedOperatorGetCeed(op, &ceed); CeedChk(ierr);
52 ierr = CeedOperatorGetQFunction(op, &qf); CeedChk(ierr);
53 CeedInt numinputfields, numoutputfields;
55 CeedVector assembledqf;
56 CeedElemRestriction rstr_q;
57 ierr = CeedOperatorLinearAssembleQFunction(
58 op, &assembledqf, &rstr_q, CEED_REQUEST_IMMEDIATE); CeedChk(ierr);
61 ierr = CeedVectorGetLength(assembledqf, &qflength); CeedChk(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); CeedChk(ierr);
82 if (vec == CEED_VECTOR_ACTIVE)
84 ierr = CeedOperatorFieldGetBasis(input_fields[i], &basisin);
86 ierr = CeedBasisGetNumComponents(basisin, &ncomp); CeedChk(ierr);
87 ierr = CeedBasisGetDimension(basisin, &
dim); CeedChk(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); CeedChk(ierr);
98 emodein[numemodein] = emode;
102 ierr = CeedHackRealloc(numemodein +
dim, &emodein); CeedChk(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); CeedChk(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); CeedChk(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); CeedChk(ierr);
143 emodeout[numemodeout] = emode;
147 ierr = CeedHackRealloc(numemodeout +
dim, &emodeout); CeedChk(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); CeedChk(ierr);
165 ierr = CeedElemRestrictionGetElementSize(rstrin, &elemsize); CeedChk(ierr);
166 ierr = CeedElemRestrictionGetLVectorSize(rstrin, &nnodes); CeedChk(ierr);
167 ierr = CeedBasisGetNumQuadraturePoints(basisin, &nqpts); CeedChk(ierr);
170 CeedVector index_vec;
171 ierr = CeedVectorCreate(ceed, nnodes, &index_vec); CeedChk(ierr);
173 ierr = CeedVectorGetArrayWrite(index_vec, CEED_MEM_HOST, &array);
175 for (CeedSize i = 0; i < nnodes; ++i)
179 ierr = CeedVectorRestoreArray(index_vec, &array); CeedChk(ierr);
181 ierr = CeedVectorCreate(ceed, nelem * elemsize, &elem_dof); CeedChk(ierr);
182 ierr = CeedVectorSetValue(elem_dof, 0.0); CeedChk(ierr);
183 CeedElemRestrictionApply(rstrin, CEED_NOTRANSPOSE, index_vec,
184 elem_dof, CEED_REQUEST_IMMEDIATE); CeedChk(ierr);
185 const CeedScalar * elem_dof_a;
186 ierr = CeedVectorGetArrayRead(elem_dof, CEED_MEM_HOST, &elem_dof_a);
188 ierr = CeedVectorDestroy(&index_vec); CeedChk(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); CeedChk(ierr);
196 ierr = CeedBasisGetGrad(basisin, &gradin); CeedChk(ierr);
198 const CeedScalar * assembledqfarray;
199 ierr = CeedVectorGetArrayRead(assembledqf, CEED_MEM_HOST, &assembledqfarray);
203 ierr = CeedElemRestrictionGetELayout(rstr_q, &layout); CeedChk(ierr);
204 ierr = CeedElemRestrictionDestroy(&rstr_q); CeedChk(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); CeedChk(ierr);
284 ierr = CeedVectorDestroy(&elem_dof); CeedChk(ierr);
285 ierr = CeedVectorRestoreArrayRead(assembledqf, &assembledqfarray);
287 ierr = CeedVectorDestroy(&assembledqf); CeedChk(ierr);
298 CeedSize in_len, out_len;
299 ierr = CeedOperatorGetActiveVectorLengths(op, &in_len, &out_len);
301 const int nnodes = in_len;
302 MFEM_VERIFY(in_len == out_len,
"not a square CeedOperator");
303 MFEM_VERIFY(in_len == nnodes,
"size overflow");
308 ierr = CeedOperatorIsComposite(op, &isComposite); CeedChk(ierr);
312 CeedOperator *subops;
313 #if CEED_VERSION_GE(0, 10, 2) 314 CeedCompositeOperatorGetNumSub(op, &numsub);
315 ierr = CeedCompositeOperatorGetSubList(op, &subops); CeedChk(ierr);
317 CeedOperatorGetNumSub(op, &numsub);
318 ierr = CeedOperatorGetSubList(op, &subops); CeedChk(ierr);
320 for (
int i = 0; i < numsub; ++i)
330 const int skip_zeros = 0;
331 out->Finalize(skip_zeros);
int CeedHackReallocArray(size_t n, size_t unit, void *p)
void Mult(const Table &A, const Table &B, Table &C)
C = A * B (as boolean matrices)
Data type dense matrix using column-major storage.
int CeedSingleOperatorFullAssemble(CeedOperator op, SparseMatrix *out)
double p(const Vector &x, double t)
int CeedHackFree(void *p)
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
int CeedOperatorFullAssemble(CeedOperator op, SparseMatrix **mat)
Assembles a CeedOperator as an mfem::SparseMatrix.
int index(int i, int j, int nx, int ny)
Rank 3 tensor (array of matrices)