120cf1dd8SToby Isaac #include <petsc/private/petscfeimpl.h> /*I "petscfe.h" I*/ 220cf1dd8SToby Isaac #include <petscblaslapack.h> 320cf1dd8SToby Isaac 420cf1dd8SToby Isaac PetscErrorCode PetscFEDestroy_Basic(PetscFE fem) 520cf1dd8SToby Isaac { 620cf1dd8SToby Isaac PetscFE_Basic *b = (PetscFE_Basic *) fem->data; 720cf1dd8SToby Isaac PetscErrorCode ierr; 820cf1dd8SToby Isaac 920cf1dd8SToby Isaac PetscFunctionBegin; 1020cf1dd8SToby Isaac ierr = PetscFree(b);CHKERRQ(ierr); 1120cf1dd8SToby Isaac PetscFunctionReturn(0); 1220cf1dd8SToby Isaac } 1320cf1dd8SToby Isaac 14d9bac1caSLisandro Dalcin PetscErrorCode PetscFEView_Basic_Ascii(PetscFE fe, PetscViewer v) 1520cf1dd8SToby Isaac { 16d9bac1caSLisandro Dalcin PetscInt dim, Nc; 17d9bac1caSLisandro Dalcin PetscSpace basis = NULL; 18d9bac1caSLisandro Dalcin PetscDualSpace dual = NULL; 19d9bac1caSLisandro Dalcin PetscQuadrature quad = NULL; 2020cf1dd8SToby Isaac PetscErrorCode ierr; 2120cf1dd8SToby Isaac 2220cf1dd8SToby Isaac PetscFunctionBegin; 23d9bac1caSLisandro Dalcin ierr = PetscFEGetSpatialDimension(fe, &dim);CHKERRQ(ierr); 24d9bac1caSLisandro Dalcin ierr = PetscFEGetNumComponents(fe, &Nc);CHKERRQ(ierr); 2520cf1dd8SToby Isaac ierr = PetscFEGetBasisSpace(fe, &basis);CHKERRQ(ierr); 2620cf1dd8SToby Isaac ierr = PetscFEGetDualSpace(fe, &dual);CHKERRQ(ierr); 27d9bac1caSLisandro Dalcin ierr = PetscFEGetQuadrature(fe, &quad);CHKERRQ(ierr); 28d9bac1caSLisandro Dalcin ierr = PetscViewerASCIIPushTab(v);CHKERRQ(ierr); 29d9bac1caSLisandro Dalcin ierr = PetscViewerASCIIPrintf(v, "Basic Finite Element in %D dimensions with %D components\n",dim,Nc);CHKERRQ(ierr); 30d9bac1caSLisandro Dalcin if (basis) {ierr = PetscSpaceView(basis, v);CHKERRQ(ierr);} 31d9bac1caSLisandro Dalcin if (dual) {ierr = PetscDualSpaceView(dual, v);CHKERRQ(ierr);} 32d9bac1caSLisandro Dalcin if (quad) {ierr = PetscQuadratureView(quad, v);CHKERRQ(ierr);} 33d9bac1caSLisandro Dalcin ierr = PetscViewerASCIIPopTab(v);CHKERRQ(ierr); 3420cf1dd8SToby Isaac PetscFunctionReturn(0); 3520cf1dd8SToby Isaac } 3620cf1dd8SToby Isaac 37d9bac1caSLisandro Dalcin PetscErrorCode PetscFEView_Basic(PetscFE fe, PetscViewer v) 3820cf1dd8SToby Isaac { 3920cf1dd8SToby Isaac PetscBool iascii; 4020cf1dd8SToby Isaac PetscErrorCode ierr; 4120cf1dd8SToby Isaac 4220cf1dd8SToby Isaac PetscFunctionBegin; 43d9bac1caSLisandro Dalcin ierr = PetscObjectTypeCompare((PetscObject) v, PETSCVIEWERASCII, &iascii);CHKERRQ(ierr); 44d9bac1caSLisandro Dalcin if (iascii) {ierr = PetscFEView_Basic_Ascii(fe, v);CHKERRQ(ierr);} 4520cf1dd8SToby Isaac PetscFunctionReturn(0); 4620cf1dd8SToby Isaac } 4720cf1dd8SToby Isaac 4820cf1dd8SToby Isaac /* Construct the change of basis from prime basis to nodal basis */ 4920cf1dd8SToby Isaac PetscErrorCode PetscFESetUp_Basic(PetscFE fem) 5020cf1dd8SToby Isaac { 5120cf1dd8SToby Isaac PetscScalar *work, *invVscalar; 5220cf1dd8SToby Isaac PetscBLASInt *pivots; 5320cf1dd8SToby Isaac PetscBLASInt n, info; 5420cf1dd8SToby Isaac PetscInt pdim, j; 5520cf1dd8SToby Isaac PetscErrorCode ierr; 5620cf1dd8SToby Isaac 5720cf1dd8SToby Isaac PetscFunctionBegin; 5820cf1dd8SToby Isaac ierr = PetscDualSpaceGetDimension(fem->dualSpace, &pdim);CHKERRQ(ierr); 5920cf1dd8SToby Isaac ierr = PetscMalloc1(pdim*pdim,&fem->invV);CHKERRQ(ierr); 6020cf1dd8SToby Isaac #if defined(PETSC_USE_COMPLEX) 6120cf1dd8SToby Isaac ierr = PetscMalloc1(pdim*pdim,&invVscalar);CHKERRQ(ierr); 6220cf1dd8SToby Isaac #else 6320cf1dd8SToby Isaac invVscalar = fem->invV; 6420cf1dd8SToby Isaac #endif 6520cf1dd8SToby Isaac for (j = 0; j < pdim; ++j) { 6620cf1dd8SToby Isaac PetscReal *Bf; 6720cf1dd8SToby Isaac PetscQuadrature f; 6820cf1dd8SToby Isaac const PetscReal *points, *weights; 6920cf1dd8SToby Isaac PetscInt Nc, Nq, q, k, c; 7020cf1dd8SToby Isaac 7120cf1dd8SToby Isaac ierr = PetscDualSpaceGetFunctional(fem->dualSpace, j, &f);CHKERRQ(ierr); 7220cf1dd8SToby Isaac ierr = PetscQuadratureGetData(f, NULL, &Nc, &Nq, &points, &weights);CHKERRQ(ierr); 7320cf1dd8SToby Isaac ierr = PetscMalloc1(Nc*Nq*pdim,&Bf);CHKERRQ(ierr); 7420cf1dd8SToby Isaac ierr = PetscSpaceEvaluate(fem->basisSpace, Nq, points, Bf, NULL, NULL);CHKERRQ(ierr); 7520cf1dd8SToby Isaac for (k = 0; k < pdim; ++k) { 7620cf1dd8SToby Isaac /* V_{jk} = n_j(\phi_k) = \int \phi_k(x) n_j(x) dx */ 7720cf1dd8SToby Isaac invVscalar[j*pdim+k] = 0.0; 7820cf1dd8SToby Isaac 7920cf1dd8SToby Isaac for (q = 0; q < Nq; ++q) { 8020cf1dd8SToby Isaac for (c = 0; c < Nc; ++c) invVscalar[j*pdim+k] += Bf[(q*pdim + k)*Nc + c]*weights[q*Nc + c]; 8120cf1dd8SToby Isaac } 8220cf1dd8SToby Isaac } 8320cf1dd8SToby Isaac ierr = PetscFree(Bf);CHKERRQ(ierr); 8420cf1dd8SToby Isaac } 8520cf1dd8SToby Isaac ierr = PetscMalloc2(pdim,&pivots,pdim,&work);CHKERRQ(ierr); 8620cf1dd8SToby Isaac n = pdim; 8720cf1dd8SToby Isaac PetscStackCallBLAS("LAPACKgetrf", LAPACKgetrf_(&n, &n, invVscalar, &n, pivots, &info)); 8820cf1dd8SToby Isaac PetscStackCallBLAS("LAPACKgetri", LAPACKgetri_(&n, invVscalar, &n, pivots, work, &n, &info)); 8920cf1dd8SToby Isaac #if defined(PETSC_USE_COMPLEX) 9020cf1dd8SToby Isaac for (j = 0; j < pdim*pdim; j++) fem->invV[j] = PetscRealPart(invVscalar[j]); 9120cf1dd8SToby Isaac ierr = PetscFree(invVscalar);CHKERRQ(ierr); 9220cf1dd8SToby Isaac #endif 9320cf1dd8SToby Isaac ierr = PetscFree2(pivots,work);CHKERRQ(ierr); 9420cf1dd8SToby Isaac PetscFunctionReturn(0); 9520cf1dd8SToby Isaac } 9620cf1dd8SToby Isaac 9720cf1dd8SToby Isaac PetscErrorCode PetscFEGetDimension_Basic(PetscFE fem, PetscInt *dim) 9820cf1dd8SToby Isaac { 9920cf1dd8SToby Isaac PetscErrorCode ierr; 10020cf1dd8SToby Isaac 10120cf1dd8SToby Isaac PetscFunctionBegin; 10220cf1dd8SToby Isaac ierr = PetscDualSpaceGetDimension(fem->dualSpace, dim);CHKERRQ(ierr); 10320cf1dd8SToby Isaac PetscFunctionReturn(0); 10420cf1dd8SToby Isaac } 10520cf1dd8SToby Isaac 10620cf1dd8SToby Isaac PetscErrorCode PetscFEGetTabulation_Basic(PetscFE fem, PetscInt npoints, const PetscReal points[], PetscReal *B, PetscReal *D, PetscReal *H) 10720cf1dd8SToby Isaac { 10820cf1dd8SToby Isaac DM dm; 10920cf1dd8SToby Isaac PetscInt pdim; /* Dimension of FE space P */ 11020cf1dd8SToby Isaac PetscInt dim; /* Spatial dimension */ 11120cf1dd8SToby Isaac PetscInt Nc; /* Field components */ 11220cf1dd8SToby Isaac PetscReal *tmpB, *tmpD, *tmpH; 11320cf1dd8SToby Isaac PetscInt p, d, j, k, c; 11420cf1dd8SToby Isaac PetscErrorCode ierr; 11520cf1dd8SToby Isaac 11620cf1dd8SToby Isaac PetscFunctionBegin; 11720cf1dd8SToby Isaac ierr = PetscDualSpaceGetDM(fem->dualSpace, &dm);CHKERRQ(ierr); 11820cf1dd8SToby Isaac ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 11920cf1dd8SToby Isaac ierr = PetscDualSpaceGetDimension(fem->dualSpace, &pdim);CHKERRQ(ierr); 12020cf1dd8SToby Isaac ierr = PetscFEGetNumComponents(fem, &Nc);CHKERRQ(ierr); 12120cf1dd8SToby Isaac /* Evaluate the prime basis functions at all points */ 12220cf1dd8SToby Isaac if (B) {ierr = DMGetWorkArray(dm, npoints*pdim*Nc, MPIU_REAL, &tmpB);CHKERRQ(ierr);} 12320cf1dd8SToby Isaac if (D) {ierr = DMGetWorkArray(dm, npoints*pdim*Nc*dim, MPIU_REAL, &tmpD);CHKERRQ(ierr);} 12420cf1dd8SToby Isaac if (H) {ierr = DMGetWorkArray(dm, npoints*pdim*Nc*dim*dim, MPIU_REAL, &tmpH);CHKERRQ(ierr);} 12520cf1dd8SToby Isaac ierr = PetscSpaceEvaluate(fem->basisSpace, npoints, points, B ? tmpB : NULL, D ? tmpD : NULL, H ? tmpH : NULL);CHKERRQ(ierr); 12620cf1dd8SToby Isaac /* Translate to the nodal basis */ 12720cf1dd8SToby Isaac for (p = 0; p < npoints; ++p) { 12820cf1dd8SToby Isaac if (B) { 12920cf1dd8SToby Isaac /* Multiply by V^{-1} (pdim x pdim) */ 13020cf1dd8SToby Isaac for (j = 0; j < pdim; ++j) { 13120cf1dd8SToby Isaac const PetscInt i = (p*pdim + j)*Nc; 13220cf1dd8SToby Isaac 13320cf1dd8SToby Isaac for (c = 0; c < Nc; ++c) { 13420cf1dd8SToby Isaac B[i+c] = 0.0; 13520cf1dd8SToby Isaac for (k = 0; k < pdim; ++k) { 13620cf1dd8SToby Isaac B[i+c] += fem->invV[k*pdim+j] * tmpB[(p*pdim + k)*Nc+c]; 13720cf1dd8SToby Isaac } 13820cf1dd8SToby Isaac } 13920cf1dd8SToby Isaac } 14020cf1dd8SToby Isaac } 14120cf1dd8SToby Isaac if (D) { 14220cf1dd8SToby Isaac /* Multiply by V^{-1} (pdim x pdim) */ 14320cf1dd8SToby Isaac for (j = 0; j < pdim; ++j) { 14420cf1dd8SToby Isaac for (c = 0; c < Nc; ++c) { 14520cf1dd8SToby Isaac for (d = 0; d < dim; ++d) { 14620cf1dd8SToby Isaac const PetscInt i = ((p*pdim + j)*Nc + c)*dim + d; 14720cf1dd8SToby Isaac 14820cf1dd8SToby Isaac D[i] = 0.0; 14920cf1dd8SToby Isaac for (k = 0; k < pdim; ++k) { 15020cf1dd8SToby Isaac D[i] += fem->invV[k*pdim+j] * tmpD[((p*pdim + k)*Nc + c)*dim + d]; 15120cf1dd8SToby Isaac } 15220cf1dd8SToby Isaac } 15320cf1dd8SToby Isaac } 15420cf1dd8SToby Isaac } 15520cf1dd8SToby Isaac } 15620cf1dd8SToby Isaac if (H) { 15720cf1dd8SToby Isaac /* Multiply by V^{-1} (pdim x pdim) */ 15820cf1dd8SToby Isaac for (j = 0; j < pdim; ++j) { 15920cf1dd8SToby Isaac for (c = 0; c < Nc; ++c) { 16020cf1dd8SToby Isaac for (d = 0; d < dim*dim; ++d) { 16120cf1dd8SToby Isaac const PetscInt i = ((p*pdim + j)*Nc + c)*dim*dim + d; 16220cf1dd8SToby Isaac 16320cf1dd8SToby Isaac H[i] = 0.0; 16420cf1dd8SToby Isaac for (k = 0; k < pdim; ++k) { 16520cf1dd8SToby Isaac H[i] += fem->invV[k*pdim+j] * tmpH[((p*pdim + k)*Nc + c)*dim*dim + d]; 16620cf1dd8SToby Isaac } 16720cf1dd8SToby Isaac } 16820cf1dd8SToby Isaac } 16920cf1dd8SToby Isaac } 17020cf1dd8SToby Isaac } 17120cf1dd8SToby Isaac } 17220cf1dd8SToby Isaac if (B) {ierr = DMRestoreWorkArray(dm, npoints*pdim*Nc, MPIU_REAL, &tmpB);CHKERRQ(ierr);} 17320cf1dd8SToby Isaac if (D) {ierr = DMRestoreWorkArray(dm, npoints*pdim*Nc*dim, MPIU_REAL, &tmpD);CHKERRQ(ierr);} 17420cf1dd8SToby Isaac if (H) {ierr = DMRestoreWorkArray(dm, npoints*pdim*Nc*dim*dim, MPIU_REAL, &tmpH);CHKERRQ(ierr);} 17520cf1dd8SToby Isaac PetscFunctionReturn(0); 17620cf1dd8SToby Isaac } 17720cf1dd8SToby Isaac 1784bee2e38SMatthew G. Knepley PetscErrorCode PetscFEIntegrate_Basic(PetscDS ds, PetscInt field, PetscInt Ne, PetscFEGeom *cgeom, 1794bee2e38SMatthew G. Knepley const PetscScalar coefficients[], PetscDS dsAux, const PetscScalar coefficientsAux[], PetscScalar integral[]) 18020cf1dd8SToby Isaac { 18120cf1dd8SToby Isaac const PetscInt debug = 0; 1824bee2e38SMatthew G. Knepley PetscFE fe; 18320cf1dd8SToby Isaac PetscPointFunc obj_func; 18420cf1dd8SToby Isaac PetscQuadrature quad; 1854bee2e38SMatthew G. Knepley PetscScalar *u, *u_x, *a, *a_x; 18620cf1dd8SToby Isaac const PetscScalar *constants; 18720cf1dd8SToby Isaac PetscReal *x; 18820cf1dd8SToby Isaac PetscReal **B, **D, **BAux = NULL, **DAux = NULL; 18920cf1dd8SToby Isaac PetscInt *uOff, *uOff_x, *aOff = NULL, *aOff_x = NULL, *Nb, *Nc, *NbAux = NULL, *NcAux = NULL; 19020cf1dd8SToby Isaac PetscInt dim, dE, Np, numConstants, Nf, NfAux = 0, totDim, totDimAux = 0, cOffset = 0, cOffsetAux = 0, e; 19120cf1dd8SToby Isaac PetscBool isAffine; 19220cf1dd8SToby Isaac const PetscReal *quadPoints, *quadWeights; 19320cf1dd8SToby Isaac PetscInt qNc, Nq, q; 19420cf1dd8SToby Isaac PetscErrorCode ierr; 19520cf1dd8SToby Isaac 19620cf1dd8SToby Isaac PetscFunctionBegin; 1974bee2e38SMatthew G. Knepley ierr = PetscDSGetObjective(ds, field, &obj_func);CHKERRQ(ierr); 19820cf1dd8SToby Isaac if (!obj_func) PetscFunctionReturn(0); 1994bee2e38SMatthew G. Knepley ierr = PetscDSGetDiscretization(ds, field, (PetscObject *) &fe);CHKERRQ(ierr); 2004bee2e38SMatthew G. Knepley ierr = PetscFEGetSpatialDimension(fe, &dim);CHKERRQ(ierr); 2014bee2e38SMatthew G. Knepley ierr = PetscFEGetQuadrature(fe, &quad);CHKERRQ(ierr); 2024bee2e38SMatthew G. Knepley ierr = PetscDSGetNumFields(ds, &Nf);CHKERRQ(ierr); 2034bee2e38SMatthew G. Knepley ierr = PetscDSGetTotalDimension(ds, &totDim);CHKERRQ(ierr); 2044bee2e38SMatthew G. Knepley ierr = PetscDSGetDimensions(ds, &Nb);CHKERRQ(ierr); 2054bee2e38SMatthew G. Knepley ierr = PetscDSGetComponents(ds, &Nc);CHKERRQ(ierr); 2064bee2e38SMatthew G. Knepley ierr = PetscDSGetComponentOffsets(ds, &uOff);CHKERRQ(ierr); 2074bee2e38SMatthew G. Knepley ierr = PetscDSGetComponentDerivativeOffsets(ds, &uOff_x);CHKERRQ(ierr); 2084bee2e38SMatthew G. Knepley ierr = PetscDSGetEvaluationArrays(ds, &u, NULL, &u_x);CHKERRQ(ierr); 2094bee2e38SMatthew G. Knepley ierr = PetscDSGetWorkspace(ds, &x, NULL, NULL, NULL, NULL);CHKERRQ(ierr); 2104bee2e38SMatthew G. Knepley ierr = PetscDSGetTabulation(ds, &B, &D);CHKERRQ(ierr); 2114bee2e38SMatthew G. Knepley ierr = PetscDSGetConstants(ds, &numConstants, &constants);CHKERRQ(ierr); 2124bee2e38SMatthew G. Knepley if (dsAux) { 2134bee2e38SMatthew G. Knepley ierr = PetscDSGetNumFields(dsAux, &NfAux);CHKERRQ(ierr); 2144bee2e38SMatthew G. Knepley ierr = PetscDSGetTotalDimension(dsAux, &totDimAux);CHKERRQ(ierr); 2154bee2e38SMatthew G. Knepley ierr = PetscDSGetDimensions(dsAux, &NbAux);CHKERRQ(ierr); 2164bee2e38SMatthew G. Knepley ierr = PetscDSGetComponents(dsAux, &NcAux);CHKERRQ(ierr); 2174bee2e38SMatthew G. Knepley ierr = PetscDSGetComponentOffsets(dsAux, &aOff);CHKERRQ(ierr); 2184bee2e38SMatthew G. Knepley ierr = PetscDSGetComponentDerivativeOffsets(dsAux, &aOff_x);CHKERRQ(ierr); 2194bee2e38SMatthew G. Knepley ierr = PetscDSGetEvaluationArrays(dsAux, &a, NULL, &a_x);CHKERRQ(ierr); 2204bee2e38SMatthew G. Knepley ierr = PetscDSGetTabulation(dsAux, &BAux, &DAux);CHKERRQ(ierr); 22120cf1dd8SToby Isaac } 22220cf1dd8SToby Isaac ierr = PetscQuadratureGetData(quad, NULL, &qNc, &Nq, &quadPoints, &quadWeights);CHKERRQ(ierr); 2234bee2e38SMatthew G. Knepley if (qNc != 1) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_SUP, "Only supports scalar quadrature, not %D components\n", qNc); 22420cf1dd8SToby Isaac Np = cgeom->numPoints; 22520cf1dd8SToby Isaac dE = cgeom->dimEmbed; 22620cf1dd8SToby Isaac isAffine = cgeom->isAffine; 22720cf1dd8SToby Isaac for (e = 0; e < Ne; ++e) { 2284bee2e38SMatthew G. Knepley PetscFEGeom fegeom; 22920cf1dd8SToby Isaac 23020cf1dd8SToby Isaac if (isAffine) { 2314bee2e38SMatthew G. Knepley fegeom.v = x; 2324bee2e38SMatthew G. Knepley fegeom.xi = cgeom->xi; 2334bee2e38SMatthew G. Knepley fegeom.J = &cgeom->J[e*dE*dE]; 2344bee2e38SMatthew G. Knepley fegeom.invJ = &cgeom->invJ[e*dE*dE]; 2354bee2e38SMatthew G. Knepley fegeom.detJ = &cgeom->detJ[e]; 23620cf1dd8SToby Isaac } 2374bee2e38SMatthew G. Knepley for (q = 0; q < Nq; ++q) { 2384bee2e38SMatthew G. Knepley PetscScalar integrand; 2394bee2e38SMatthew G. Knepley PetscReal w; 2404bee2e38SMatthew G. Knepley 2414bee2e38SMatthew G. Knepley if (isAffine) { 2424bee2e38SMatthew G. Knepley CoordinatesRefToReal(dE, dim, fegeom.xi, &cgeom->v[e*dE], fegeom.J, &quadPoints[q*dim], x); 2434bee2e38SMatthew G. Knepley } else { 2444bee2e38SMatthew G. Knepley fegeom.v = &cgeom->v[(e*Np+q)*dE]; 2454bee2e38SMatthew G. Knepley fegeom.J = &cgeom->J[(e*Np+q)*dE*dE]; 2464bee2e38SMatthew G. Knepley fegeom.invJ = &cgeom->invJ[(e*Np+q)*dE*dE]; 2474bee2e38SMatthew G. Knepley fegeom.detJ = &cgeom->detJ[e*Np+q]; 2484bee2e38SMatthew G. Knepley } 2494bee2e38SMatthew G. Knepley w = fegeom.detJ[0]*quadWeights[q]; 25020cf1dd8SToby Isaac if (debug > 1 && q < Np) { 2514bee2e38SMatthew G. Knepley ierr = PetscPrintf(PETSC_COMM_SELF, " detJ: %g\n", fegeom.detJ[0]);CHKERRQ(ierr); 2527be5e748SToby Isaac #if !defined(PETSC_USE_COMPLEX) 2534bee2e38SMatthew G. Knepley ierr = DMPrintCellMatrix(e, "invJ", dim, dim, fegeom.invJ);CHKERRQ(ierr); 25420cf1dd8SToby Isaac #endif 25520cf1dd8SToby Isaac } 25620cf1dd8SToby Isaac if (debug) {ierr = PetscPrintf(PETSC_COMM_SELF, " quad point %d\n", q);CHKERRQ(ierr);} 257a8f1f9e5SMatthew G. Knepley ierr = PetscFEEvaluateFieldJets_Internal(ds, dim, Nf, Nb, Nc, q, B, D, &fegeom, &coefficients[cOffset], NULL, u, u_x, NULL);CHKERRQ(ierr); 258a8f1f9e5SMatthew G. Knepley if (dsAux) {ierr = PetscFEEvaluateFieldJets_Internal(dsAux, dim, NfAux, NbAux, NcAux, q, BAux, DAux, &fegeom, &coefficientsAux[cOffsetAux], NULL, a, a_x, NULL);CHKERRQ(ierr);} 2594bee2e38SMatthew G. Knepley obj_func(dim, Nf, NfAux, uOff, uOff_x, u, NULL, u_x, aOff, aOff_x, a, NULL, a_x, 0.0, fegeom.v, numConstants, constants, &integrand); 2604bee2e38SMatthew G. Knepley integrand *= w; 26120cf1dd8SToby Isaac integral[e*Nf+field] += integrand; 26220cf1dd8SToby Isaac if (debug > 1) {ierr = PetscPrintf(PETSC_COMM_SELF, " int: %g %g\n", (double) PetscRealPart(integrand), (double) PetscRealPart(integral[field]));CHKERRQ(ierr);} 26320cf1dd8SToby Isaac } 26420cf1dd8SToby Isaac cOffset += totDim; 26520cf1dd8SToby Isaac cOffsetAux += totDimAux; 26620cf1dd8SToby Isaac } 26720cf1dd8SToby Isaac PetscFunctionReturn(0); 26820cf1dd8SToby Isaac } 26920cf1dd8SToby Isaac 2704bee2e38SMatthew G. Knepley PetscErrorCode PetscFEIntegrateBd_Basic(PetscDS ds, PetscInt field, 271afe6d6adSToby Isaac PetscBdPointFunc obj_func, 2724bee2e38SMatthew G. Knepley PetscInt Ne, PetscFEGeom *fgeom, const PetscScalar coefficients[], PetscDS dsAux, const PetscScalar coefficientsAux[], PetscScalar integral[]) 273afe6d6adSToby Isaac { 274afe6d6adSToby Isaac const PetscInt debug = 0; 2754bee2e38SMatthew G. Knepley PetscFE fe; 276afe6d6adSToby Isaac PetscQuadrature quad; 2774bee2e38SMatthew G. Knepley PetscScalar *u, *u_x, *a, *a_x, *basisReal, *basisDerReal; 278afe6d6adSToby Isaac const PetscScalar *constants; 279afe6d6adSToby Isaac PetscReal *x; 280afe6d6adSToby Isaac PetscReal **B, **D, **BAux = NULL, **DAux = NULL; 281afe6d6adSToby Isaac PetscInt *uOff, *uOff_x, *aOff = NULL, *aOff_x = NULL, *Nb, *Nc, *NbAux = NULL, *NcAux = NULL; 282afe6d6adSToby Isaac PetscBool isAffine, auxOnBd; 283afe6d6adSToby Isaac const PetscReal *quadPoints, *quadWeights; 284afe6d6adSToby Isaac PetscInt qNc, Nq, q, Np, dE; 285afe6d6adSToby Isaac PetscInt dim, dimAux, numConstants, Nf, NfAux = 0, totDim, totDimAux = 0, cOffset = 0, cOffsetAux = 0, e; 286afe6d6adSToby Isaac PetscErrorCode ierr; 287afe6d6adSToby Isaac 288afe6d6adSToby Isaac PetscFunctionBegin; 289afe6d6adSToby Isaac if (!obj_func) PetscFunctionReturn(0); 2904bee2e38SMatthew G. Knepley ierr = PetscDSGetDiscretization(ds, field, (PetscObject *) &fe);CHKERRQ(ierr); 2914bee2e38SMatthew G. Knepley ierr = PetscFEGetSpatialDimension(fe, &dim);CHKERRQ(ierr); 2924bee2e38SMatthew G. Knepley ierr = PetscFEGetFaceQuadrature(fe, &quad);CHKERRQ(ierr); 2934bee2e38SMatthew G. Knepley ierr = PetscDSGetNumFields(ds, &Nf);CHKERRQ(ierr); 2944bee2e38SMatthew G. Knepley ierr = PetscDSGetTotalDimension(ds, &totDim);CHKERRQ(ierr); 2954bee2e38SMatthew G. Knepley ierr = PetscDSGetDimensions(ds, &Nb);CHKERRQ(ierr); 2964bee2e38SMatthew G. Knepley ierr = PetscDSGetComponents(ds, &Nc);CHKERRQ(ierr); 2974bee2e38SMatthew G. Knepley ierr = PetscDSGetComponentOffsets(ds, &uOff);CHKERRQ(ierr); 2984bee2e38SMatthew G. Knepley ierr = PetscDSGetComponentDerivativeOffsets(ds, &uOff_x);CHKERRQ(ierr); 2994bee2e38SMatthew G. Knepley ierr = PetscDSGetEvaluationArrays(ds, &u, NULL, &u_x);CHKERRQ(ierr); 3004bee2e38SMatthew G. Knepley ierr = PetscDSGetWorkspace(ds, &x, &basisReal, &basisDerReal, NULL, NULL);CHKERRQ(ierr); 3014bee2e38SMatthew G. Knepley ierr = PetscDSGetFaceTabulation(ds, &B, &D);CHKERRQ(ierr); 3024bee2e38SMatthew G. Knepley ierr = PetscDSGetConstants(ds, &numConstants, &constants);CHKERRQ(ierr); 3034bee2e38SMatthew G. Knepley if (dsAux) { 3044bee2e38SMatthew G. Knepley ierr = PetscDSGetSpatialDimension(dsAux, &dimAux);CHKERRQ(ierr); 3054bee2e38SMatthew G. Knepley ierr = PetscDSGetNumFields(dsAux, &NfAux);CHKERRQ(ierr); 3064bee2e38SMatthew G. Knepley ierr = PetscDSGetTotalDimension(dsAux, &totDimAux);CHKERRQ(ierr); 3074bee2e38SMatthew G. Knepley ierr = PetscDSGetDimensions(dsAux, &NbAux);CHKERRQ(ierr); 3084bee2e38SMatthew G. Knepley ierr = PetscDSGetComponents(dsAux, &NcAux);CHKERRQ(ierr); 3094bee2e38SMatthew G. Knepley ierr = PetscDSGetComponentOffsets(dsAux, &aOff);CHKERRQ(ierr); 3104bee2e38SMatthew G. Knepley ierr = PetscDSGetComponentDerivativeOffsets(dsAux, &aOff_x);CHKERRQ(ierr); 3114bee2e38SMatthew G. Knepley ierr = PetscDSGetEvaluationArrays(dsAux, &a, NULL, &a_x);CHKERRQ(ierr); 312afe6d6adSToby Isaac auxOnBd = dimAux < dim ? PETSC_TRUE : PETSC_FALSE; 3134bee2e38SMatthew G. Knepley if (auxOnBd) {ierr = PetscDSGetTabulation(dsAux, &BAux, &DAux);CHKERRQ(ierr);} 3144bee2e38SMatthew G. Knepley else {ierr = PetscDSGetFaceTabulation(dsAux, &BAux, &DAux);CHKERRQ(ierr);} 315afe6d6adSToby Isaac } 316afe6d6adSToby Isaac ierr = PetscQuadratureGetData(quad, NULL, &qNc, &Nq, &quadPoints, &quadWeights);CHKERRQ(ierr); 317afe6d6adSToby Isaac if (qNc != 1) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_SUP, "Only supports scalar quadrature, not %D components\n", qNc); 318afe6d6adSToby Isaac Np = fgeom->numPoints; 319afe6d6adSToby Isaac dE = fgeom->dimEmbed; 320afe6d6adSToby Isaac isAffine = fgeom->isAffine; 321afe6d6adSToby Isaac for (e = 0; e < Ne; ++e) { 3229f209ee4SMatthew G. Knepley PetscFEGeom fegeom, cgeom; 323afe6d6adSToby Isaac const PetscInt face = fgeom->face[e][0]; /* Local face number in cell */ 324afe6d6adSToby Isaac 3254bee2e38SMatthew G. Knepley if (isAffine) { 3264bee2e38SMatthew G. Knepley fegeom.v = x; 3274bee2e38SMatthew G. Knepley fegeom.xi = fgeom->xi; 3284bee2e38SMatthew G. Knepley fegeom.J = &fgeom->J[e*dE*dE]; 3299f209ee4SMatthew G. Knepley fegeom.invJ = &fgeom->invJ[e*dE*dE]; 3304bee2e38SMatthew G. Knepley fegeom.detJ = &fgeom->detJ[e]; 3314bee2e38SMatthew G. Knepley fegeom.n = &fgeom->n[e*dE]; 3329f209ee4SMatthew G. Knepley 3339f209ee4SMatthew G. Knepley cgeom.J = &fgeom->suppJ[0][e*dE*dE]; 3349f209ee4SMatthew G. Knepley cgeom.invJ = &fgeom->suppInvJ[0][e*dE*dE]; 3359f209ee4SMatthew G. Knepley cgeom.detJ = &fgeom->suppDetJ[0][e]; 3364bee2e38SMatthew G. Knepley } 337afe6d6adSToby Isaac for (q = 0; q < Nq; ++q) { 338afe6d6adSToby Isaac PetscScalar integrand; 3394bee2e38SMatthew G. Knepley PetscReal w; 340afe6d6adSToby Isaac 341afe6d6adSToby Isaac if (isAffine) { 3424bee2e38SMatthew G. Knepley CoordinatesRefToReal(dE, dim-1, fegeom.xi, &fgeom->v[e*dE], fegeom.J, &quadPoints[q*(dim-1)], x); 343afe6d6adSToby Isaac } else { 344*3fe841f2SMatthew G. Knepley fegeom.v = &fgeom->v[(e*Np+q)*dE]; 3459f209ee4SMatthew G. Knepley fegeom.J = &fgeom->J[(e*Np+q)*dE*dE]; 3469f209ee4SMatthew G. Knepley fegeom.invJ = &fgeom->invJ[(e*Np+q)*dE*dE]; 3474bee2e38SMatthew G. Knepley fegeom.detJ = &fgeom->detJ[e*Np+q]; 3484bee2e38SMatthew G. Knepley fegeom.n = &fgeom->n[(e*Np+q)*dE]; 3499f209ee4SMatthew G. Knepley 3509f209ee4SMatthew G. Knepley cgeom.J = &fgeom->suppJ[0][(e*Np+q)*dE*dE]; 3519f209ee4SMatthew G. Knepley cgeom.invJ = &fgeom->suppInvJ[0][(e*Np+q)*dE*dE]; 3529f209ee4SMatthew G. Knepley cgeom.detJ = &fgeom->suppDetJ[0][e*Np+q]; 353afe6d6adSToby Isaac } 3544bee2e38SMatthew G. Knepley w = fegeom.detJ[0]*quadWeights[q]; 355afe6d6adSToby Isaac if (debug > 1 && q < Np) { 3564bee2e38SMatthew G. Knepley ierr = PetscPrintf(PETSC_COMM_SELF, " detJ: %g\n", fegeom.detJ[0]);CHKERRQ(ierr); 357afe6d6adSToby Isaac #ifndef PETSC_USE_COMPLEX 3584bee2e38SMatthew G. Knepley ierr = DMPrintCellMatrix(e, "invJ", dim, dim, fegeom.invJ);CHKERRQ(ierr); 359afe6d6adSToby Isaac #endif 360afe6d6adSToby Isaac } 361afe6d6adSToby Isaac if (debug > 1) {ierr = PetscPrintf(PETSC_COMM_SELF, " quad point %d\n", q);CHKERRQ(ierr);} 3629f209ee4SMatthew G. Knepley ierr = PetscFEEvaluateFieldJets_Internal(ds, dim, Nf, Nb, Nc, face*Nq+q, B, D, &cgeom, &coefficients[cOffset], NULL, u, u_x, NULL);CHKERRQ(ierr); 3639f209ee4SMatthew G. Knepley if (dsAux) {ierr = PetscFEEvaluateFieldJets_Internal(dsAux, dimAux, NfAux, NbAux, NcAux, face*Nq+q, BAux, DAux, &cgeom, &coefficientsAux[cOffsetAux], NULL, a, a_x, NULL);CHKERRQ(ierr);} 3644bee2e38SMatthew G. Knepley obj_func(dim, Nf, NfAux, uOff, uOff_x, u, NULL, u_x, aOff, aOff_x, a, NULL, a_x, 0.0, fegeom.v, fegeom.n, numConstants, constants, &integrand); 3654bee2e38SMatthew G. Knepley integrand *= w; 366afe6d6adSToby Isaac integral[e*Nf+field] += integrand; 367afe6d6adSToby Isaac if (debug > 1) {ierr = PetscPrintf(PETSC_COMM_SELF, " int: %g %g\n", (double) PetscRealPart(integrand), (double) PetscRealPart(integral[e*Nf+field]));CHKERRQ(ierr);} 368afe6d6adSToby Isaac } 369afe6d6adSToby Isaac cOffset += totDim; 370afe6d6adSToby Isaac cOffsetAux += totDimAux; 371afe6d6adSToby Isaac } 372afe6d6adSToby Isaac PetscFunctionReturn(0); 373afe6d6adSToby Isaac } 374afe6d6adSToby Isaac 3754bee2e38SMatthew G. Knepley PetscErrorCode PetscFEIntegrateResidual_Basic(PetscDS ds, PetscInt field, PetscInt Ne, PetscFEGeom *cgeom, 3764bee2e38SMatthew G. Knepley const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS dsAux, const PetscScalar coefficientsAux[], PetscReal t, PetscScalar elemVec[]) 37720cf1dd8SToby Isaac { 37820cf1dd8SToby Isaac const PetscInt debug = 0; 3794bee2e38SMatthew G. Knepley PetscFE fe; 38020cf1dd8SToby Isaac PetscPointFunc f0_func; 38120cf1dd8SToby Isaac PetscPointFunc f1_func; 38220cf1dd8SToby Isaac PetscQuadrature quad; 3834bee2e38SMatthew G. Knepley PetscScalar *f0, *f1, *u, *u_t = NULL, *u_x, *a, *a_x, *basisReal, *basisDerReal; 38420cf1dd8SToby Isaac const PetscScalar *constants; 38520cf1dd8SToby Isaac PetscReal *x; 38620cf1dd8SToby Isaac PetscReal **B, **D, **BAux = NULL, **DAux = NULL, *BI, *DI; 38720cf1dd8SToby Isaac PetscInt *uOff, *uOff_x, *aOff = NULL, *aOff_x = NULL, *Nb, *Nc, *NbAux = NULL, *NcAux = NULL; 38820cf1dd8SToby Isaac PetscInt dim, numConstants, Nf, NfAux = 0, totDim, totDimAux = 0, cOffset = 0, cOffsetAux = 0, fOffset, e, NbI, NcI; 38920cf1dd8SToby Isaac PetscBool isAffine; 39020cf1dd8SToby Isaac const PetscReal *quadPoints, *quadWeights; 3914bee2e38SMatthew G. Knepley PetscInt qNc, Nq, q, Np, dE; 39220cf1dd8SToby Isaac PetscErrorCode ierr; 39320cf1dd8SToby Isaac 39420cf1dd8SToby Isaac PetscFunctionBegin; 3954bee2e38SMatthew G. Knepley ierr = PetscDSGetDiscretization(ds, field, (PetscObject *) &fe);CHKERRQ(ierr); 3964bee2e38SMatthew G. Knepley ierr = PetscFEGetSpatialDimension(fe, &dim);CHKERRQ(ierr); 3974bee2e38SMatthew G. Knepley ierr = PetscFEGetQuadrature(fe, &quad);CHKERRQ(ierr); 3984bee2e38SMatthew G. Knepley ierr = PetscDSGetNumFields(ds, &Nf);CHKERRQ(ierr); 3994bee2e38SMatthew G. Knepley ierr = PetscDSGetTotalDimension(ds, &totDim);CHKERRQ(ierr); 4004bee2e38SMatthew G. Knepley ierr = PetscDSGetDimensions(ds, &Nb);CHKERRQ(ierr); 4014bee2e38SMatthew G. Knepley ierr = PetscDSGetComponents(ds, &Nc);CHKERRQ(ierr); 4024bee2e38SMatthew G. Knepley ierr = PetscDSGetComponentOffsets(ds, &uOff);CHKERRQ(ierr); 4034bee2e38SMatthew G. Knepley ierr = PetscDSGetComponentDerivativeOffsets(ds, &uOff_x);CHKERRQ(ierr); 4044bee2e38SMatthew G. Knepley ierr = PetscDSGetFieldOffset(ds, field, &fOffset);CHKERRQ(ierr); 4054bee2e38SMatthew G. Knepley ierr = PetscDSGetResidual(ds, field, &f0_func, &f1_func);CHKERRQ(ierr); 4064bee2e38SMatthew G. Knepley ierr = PetscDSGetEvaluationArrays(ds, &u, coefficients_t ? &u_t : NULL, &u_x);CHKERRQ(ierr); 4074bee2e38SMatthew G. Knepley ierr = PetscDSGetWorkspace(ds, &x, &basisReal, &basisDerReal, NULL, NULL);CHKERRQ(ierr); 4084bee2e38SMatthew G. Knepley ierr = PetscDSGetWeakFormArrays(ds, &f0, &f1, NULL, NULL, NULL, NULL);CHKERRQ(ierr); 4094bee2e38SMatthew G. Knepley if (!f0_func && !f1_func) PetscFunctionReturn(0); 4104bee2e38SMatthew G. Knepley ierr = PetscDSGetTabulation(ds, &B, &D);CHKERRQ(ierr); 4114bee2e38SMatthew G. Knepley ierr = PetscDSGetConstants(ds, &numConstants, &constants);CHKERRQ(ierr); 4124bee2e38SMatthew G. Knepley if (dsAux) { 4134bee2e38SMatthew G. Knepley ierr = PetscDSGetNumFields(dsAux, &NfAux);CHKERRQ(ierr); 4144bee2e38SMatthew G. Knepley ierr = PetscDSGetTotalDimension(dsAux, &totDimAux);CHKERRQ(ierr); 4154bee2e38SMatthew G. Knepley ierr = PetscDSGetDimensions(dsAux, &NbAux);CHKERRQ(ierr); 4164bee2e38SMatthew G. Knepley ierr = PetscDSGetComponents(dsAux, &NcAux);CHKERRQ(ierr); 4174bee2e38SMatthew G. Knepley ierr = PetscDSGetComponentOffsets(dsAux, &aOff);CHKERRQ(ierr); 4184bee2e38SMatthew G. Knepley ierr = PetscDSGetComponentDerivativeOffsets(dsAux, &aOff_x);CHKERRQ(ierr); 4194bee2e38SMatthew G. Knepley ierr = PetscDSGetEvaluationArrays(dsAux, &a, NULL, &a_x);CHKERRQ(ierr); 4204bee2e38SMatthew G. Knepley ierr = PetscDSGetTabulation(dsAux, &BAux, &DAux);CHKERRQ(ierr); 42120cf1dd8SToby Isaac } 42220cf1dd8SToby Isaac NbI = Nb[field]; 42320cf1dd8SToby Isaac NcI = Nc[field]; 42420cf1dd8SToby Isaac BI = B[field]; 42520cf1dd8SToby Isaac DI = D[field]; 42620cf1dd8SToby Isaac ierr = PetscQuadratureGetData(quad, NULL, &qNc, &Nq, &quadPoints, &quadWeights);CHKERRQ(ierr); 4274bee2e38SMatthew G. Knepley if (qNc != 1) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_SUP, "Only supports scalar quadrature, not %D components\n", qNc); 42820cf1dd8SToby Isaac Np = cgeom->numPoints; 42920cf1dd8SToby Isaac dE = cgeom->dimEmbed; 43020cf1dd8SToby Isaac isAffine = cgeom->isAffine; 43120cf1dd8SToby Isaac for (e = 0; e < Ne; ++e) { 4324bee2e38SMatthew G. Knepley PetscFEGeom fegeom; 43320cf1dd8SToby Isaac 4344bee2e38SMatthew G. Knepley if (isAffine) { 4354bee2e38SMatthew G. Knepley fegeom.v = x; 4364bee2e38SMatthew G. Knepley fegeom.xi = cgeom->xi; 4374bee2e38SMatthew G. Knepley fegeom.J = &cgeom->J[e*dE*dE]; 4384bee2e38SMatthew G. Knepley fegeom.invJ = &cgeom->invJ[e*dE*dE]; 4394bee2e38SMatthew G. Knepley fegeom.detJ = &cgeom->detJ[e]; 4404bee2e38SMatthew G. Knepley } 44120cf1dd8SToby Isaac ierr = PetscMemzero(f0, Nq*NcI* sizeof(PetscScalar));CHKERRQ(ierr); 44220cf1dd8SToby Isaac ierr = PetscMemzero(f1, Nq*NcI*dim * sizeof(PetscScalar));CHKERRQ(ierr); 44320cf1dd8SToby Isaac for (q = 0; q < Nq; ++q) { 4444bee2e38SMatthew G. Knepley PetscReal w; 4454bee2e38SMatthew G. Knepley PetscInt c, d; 44620cf1dd8SToby Isaac 44720cf1dd8SToby Isaac if (isAffine) { 4484bee2e38SMatthew G. Knepley CoordinatesRefToReal(dE, dim, fegeom.xi, &cgeom->v[e*dE], fegeom.J, &quadPoints[q*dim], x); 44920cf1dd8SToby Isaac } else { 4504bee2e38SMatthew G. Knepley fegeom.v = &cgeom->v[(e*Np+q)*dE]; 4514bee2e38SMatthew G. Knepley fegeom.J = &cgeom->J[(e*Np+q)*dE*dE]; 4524bee2e38SMatthew G. Knepley fegeom.invJ = &cgeom->invJ[(e*Np+q)*dE*dE]; 4534bee2e38SMatthew G. Knepley fegeom.detJ = &cgeom->detJ[e*Np+q]; 45420cf1dd8SToby Isaac } 4554bee2e38SMatthew G. Knepley w = fegeom.detJ[0]*quadWeights[q]; 45620cf1dd8SToby Isaac if (debug > 1 && q < Np) { 4574bee2e38SMatthew G. Knepley ierr = PetscPrintf(PETSC_COMM_SELF, " detJ: %g\n", fegeom.detJ[0]);CHKERRQ(ierr); 4587be5e748SToby Isaac #if !defined(PETSC_USE_COMPLEX) 4594bee2e38SMatthew G. Knepley ierr = DMPrintCellMatrix(e, "invJ", dim, dim, fegeom.invJ);CHKERRQ(ierr); 46020cf1dd8SToby Isaac #endif 46120cf1dd8SToby Isaac } 46220cf1dd8SToby Isaac if (debug) {ierr = PetscPrintf(PETSC_COMM_SELF, " quad point %d\n", q);CHKERRQ(ierr);} 463a8f1f9e5SMatthew G. Knepley ierr = PetscFEEvaluateFieldJets_Internal(ds, dim, Nf, Nb, Nc, q, B, D, &fegeom, &coefficients[cOffset], &coefficients_t[cOffset], u, u_x, u_t);CHKERRQ(ierr); 464a8f1f9e5SMatthew G. Knepley if (dsAux) {ierr = PetscFEEvaluateFieldJets_Internal(dsAux, dim, NfAux, NbAux, NcAux, q, BAux, DAux, &fegeom, &coefficientsAux[cOffsetAux], NULL, a, a_x, NULL);CHKERRQ(ierr);} 4654bee2e38SMatthew G. Knepley if (f0_func) { 4664bee2e38SMatthew G. Knepley f0_func(dim, Nf, NfAux, uOff, uOff_x, u, u_t, u_x, aOff, aOff_x, a, NULL, a_x, t, fegeom.v, numConstants, constants, &f0[q*NcI]); 4674bee2e38SMatthew G. Knepley for (c = 0; c < NcI; ++c) f0[q*NcI+c] *= w; 4684bee2e38SMatthew G. Knepley } 46920cf1dd8SToby Isaac if (f1_func) { 4704bee2e38SMatthew G. Knepley f1_func(dim, Nf, NfAux, uOff, uOff_x, u, u_t, u_x, aOff, aOff_x, a, NULL, a_x, t, fegeom.v, numConstants, constants, &f1[q*NcI*dim]); 4714bee2e38SMatthew G. Knepley for (c = 0; c < NcI; ++c) for (d = 0; d < dim; ++d) f1[(q*NcI+c)*dim+d] *= w; 47220cf1dd8SToby Isaac } 47320cf1dd8SToby Isaac } 474a8f1f9e5SMatthew G. Knepley ierr = PetscFEUpdateElementVec_Internal(fe, dim, Nq, NbI, NcI, BI, DI, basisReal, basisDerReal, &fegeom, f0, f1, &elemVec[cOffset+fOffset]);CHKERRQ(ierr); 47520cf1dd8SToby Isaac cOffset += totDim; 47620cf1dd8SToby Isaac cOffsetAux += totDimAux; 47720cf1dd8SToby Isaac } 47820cf1dd8SToby Isaac PetscFunctionReturn(0); 47920cf1dd8SToby Isaac } 48020cf1dd8SToby Isaac 4814bee2e38SMatthew G. Knepley PetscErrorCode PetscFEIntegrateBdResidual_Basic(PetscDS ds, PetscInt field, PetscInt Ne, PetscFEGeom *fgeom, 4824bee2e38SMatthew G. Knepley const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS dsAux, const PetscScalar coefficientsAux[], PetscReal t, PetscScalar elemVec[]) 48320cf1dd8SToby Isaac { 48420cf1dd8SToby Isaac const PetscInt debug = 0; 4854bee2e38SMatthew G. Knepley PetscFE fe; 48620cf1dd8SToby Isaac PetscBdPointFunc f0_func; 48720cf1dd8SToby Isaac PetscBdPointFunc f1_func; 48820cf1dd8SToby Isaac PetscQuadrature quad; 4894bee2e38SMatthew G. Knepley PetscScalar *f0, *f1, *u, *u_t = NULL, *u_x, *a, *a_x, *basisReal, *basisDerReal; 49020cf1dd8SToby Isaac const PetscScalar *constants; 49120cf1dd8SToby Isaac PetscReal *x; 49220cf1dd8SToby Isaac PetscReal **B, **D, **BAux = NULL, **DAux = NULL, *BI, *DI; 49320cf1dd8SToby Isaac PetscInt *uOff, *uOff_x, *aOff = NULL, *aOff_x = NULL, *Nb, *Nc, *NbAux = NULL, *NcAux = NULL; 4947be5e748SToby Isaac PetscInt dim, dimAux, numConstants, Nf, NfAux = 0, totDim, totDimAux = 0, cOffset = 0, cOffsetAux = 0, fOffset, e, NbI, NcI; 495b07bd890SMatthew G. Knepley PetscBool isAffine, auxOnBd = PETSC_FALSE; 49620cf1dd8SToby Isaac const PetscReal *quadPoints, *quadWeights; 49720cf1dd8SToby Isaac PetscInt qNc, Nq, q, Np, dE; 49820cf1dd8SToby Isaac PetscErrorCode ierr; 49920cf1dd8SToby Isaac 50020cf1dd8SToby Isaac PetscFunctionBegin; 5014bee2e38SMatthew G. Knepley ierr = PetscDSGetDiscretization(ds, field, (PetscObject *) &fe);CHKERRQ(ierr); 5024bee2e38SMatthew G. Knepley ierr = PetscFEGetSpatialDimension(fe, &dim);CHKERRQ(ierr); 5034bee2e38SMatthew G. Knepley ierr = PetscFEGetFaceQuadrature(fe, &quad);CHKERRQ(ierr); 5044bee2e38SMatthew G. Knepley ierr = PetscDSGetNumFields(ds, &Nf);CHKERRQ(ierr); 5054bee2e38SMatthew G. Knepley ierr = PetscDSGetTotalDimension(ds, &totDim);CHKERRQ(ierr); 5064bee2e38SMatthew G. Knepley ierr = PetscDSGetDimensions(ds, &Nb);CHKERRQ(ierr); 5074bee2e38SMatthew G. Knepley ierr = PetscDSGetComponents(ds, &Nc);CHKERRQ(ierr); 5084bee2e38SMatthew G. Knepley ierr = PetscDSGetComponentOffsets(ds, &uOff);CHKERRQ(ierr); 5094bee2e38SMatthew G. Knepley ierr = PetscDSGetComponentDerivativeOffsets(ds, &uOff_x);CHKERRQ(ierr); 5104bee2e38SMatthew G. Knepley ierr = PetscDSGetFieldOffset(ds, field, &fOffset);CHKERRQ(ierr); 5114bee2e38SMatthew G. Knepley ierr = PetscDSGetBdResidual(ds, field, &f0_func, &f1_func);CHKERRQ(ierr); 51220cf1dd8SToby Isaac if (!f0_func && !f1_func) PetscFunctionReturn(0); 5134bee2e38SMatthew G. Knepley ierr = PetscDSGetEvaluationArrays(ds, &u, coefficients_t ? &u_t : NULL, &u_x);CHKERRQ(ierr); 5144bee2e38SMatthew G. Knepley ierr = PetscDSGetWorkspace(ds, &x, &basisReal, &basisDerReal, NULL, NULL);CHKERRQ(ierr); 5154bee2e38SMatthew G. Knepley ierr = PetscDSGetWeakFormArrays(ds, &f0, &f1, NULL, NULL, NULL, NULL);CHKERRQ(ierr); 5164bee2e38SMatthew G. Knepley ierr = PetscDSGetFaceTabulation(ds, &B, &D);CHKERRQ(ierr); 5174bee2e38SMatthew G. Knepley ierr = PetscDSGetConstants(ds, &numConstants, &constants);CHKERRQ(ierr); 5184bee2e38SMatthew G. Knepley if (dsAux) { 5194bee2e38SMatthew G. Knepley ierr = PetscDSGetSpatialDimension(dsAux, &dimAux);CHKERRQ(ierr); 5204bee2e38SMatthew G. Knepley ierr = PetscDSGetNumFields(dsAux, &NfAux);CHKERRQ(ierr); 5214bee2e38SMatthew G. Knepley ierr = PetscDSGetTotalDimension(dsAux, &totDimAux);CHKERRQ(ierr); 5224bee2e38SMatthew G. Knepley ierr = PetscDSGetDimensions(dsAux, &NbAux);CHKERRQ(ierr); 5234bee2e38SMatthew G. Knepley ierr = PetscDSGetComponents(dsAux, &NcAux);CHKERRQ(ierr); 5244bee2e38SMatthew G. Knepley ierr = PetscDSGetComponentOffsets(dsAux, &aOff);CHKERRQ(ierr); 5254bee2e38SMatthew G. Knepley ierr = PetscDSGetComponentDerivativeOffsets(dsAux, &aOff_x);CHKERRQ(ierr); 5264bee2e38SMatthew G. Knepley ierr = PetscDSGetEvaluationArrays(dsAux, &a, NULL, &a_x);CHKERRQ(ierr); 5277be5e748SToby Isaac auxOnBd = dimAux < dim ? PETSC_TRUE : PETSC_FALSE; 5284bee2e38SMatthew G. Knepley if (auxOnBd) {ierr = PetscDSGetTabulation(dsAux, &BAux, &DAux);CHKERRQ(ierr);} 5294bee2e38SMatthew G. Knepley else {ierr = PetscDSGetFaceTabulation(dsAux, &BAux, &DAux);CHKERRQ(ierr);} 53020cf1dd8SToby Isaac } 53120cf1dd8SToby Isaac NbI = Nb[field]; 53220cf1dd8SToby Isaac NcI = Nc[field]; 53320cf1dd8SToby Isaac BI = B[field]; 53420cf1dd8SToby Isaac DI = D[field]; 53520cf1dd8SToby Isaac ierr = PetscQuadratureGetData(quad, NULL, &qNc, &Nq, &quadPoints, &quadWeights);CHKERRQ(ierr); 536afe6d6adSToby Isaac if (qNc != 1) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_SUP, "Only supports scalar quadrature, not %D components\n", qNc); 53720cf1dd8SToby Isaac Np = fgeom->numPoints; 53820cf1dd8SToby Isaac dE = fgeom->dimEmbed; 53920cf1dd8SToby Isaac isAffine = fgeom->isAffine; 54020cf1dd8SToby Isaac for (e = 0; e < Ne; ++e) { 5419f209ee4SMatthew G. Knepley PetscFEGeom fegeom, cgeom; 54220cf1dd8SToby Isaac const PetscInt face = fgeom->face[e][0]; 54320cf1dd8SToby Isaac 5444bee2e38SMatthew G. Knepley if (isAffine) { 5454bee2e38SMatthew G. Knepley fegeom.v = x; 5464bee2e38SMatthew G. Knepley fegeom.xi = fgeom->xi; 5474bee2e38SMatthew G. Knepley fegeom.J = &fgeom->J[e*dE*dE]; 5489f209ee4SMatthew G. Knepley fegeom.invJ = &fgeom->invJ[e*dE*dE]; 5494bee2e38SMatthew G. Knepley fegeom.detJ = &fgeom->detJ[e]; 5504bee2e38SMatthew G. Knepley fegeom.n = &fgeom->n[e*dE]; 5519f209ee4SMatthew G. Knepley 5529f209ee4SMatthew G. Knepley cgeom.J = &fgeom->suppJ[0][e*dE*dE]; 5539f209ee4SMatthew G. Knepley cgeom.invJ = &fgeom->suppInvJ[0][e*dE*dE]; 5549f209ee4SMatthew G. Knepley cgeom.detJ = &fgeom->suppDetJ[0][e]; 5554bee2e38SMatthew G. Knepley } 55620cf1dd8SToby Isaac ierr = PetscMemzero(f0, Nq*NcI* sizeof(PetscScalar));CHKERRQ(ierr); 55720cf1dd8SToby Isaac ierr = PetscMemzero(f1, Nq*NcI*dim * sizeof(PetscScalar));CHKERRQ(ierr); 55820cf1dd8SToby Isaac for (q = 0; q < Nq; ++q) { 5594bee2e38SMatthew G. Knepley PetscReal w; 5604bee2e38SMatthew G. Knepley PetscInt c, d; 5614bee2e38SMatthew G. Knepley 56220cf1dd8SToby Isaac if (isAffine) { 5634bee2e38SMatthew G. Knepley CoordinatesRefToReal(dE, dim-1, fegeom.xi, &fgeom->v[e*dE], fegeom.J, &quadPoints[q*(dim-1)], x); 56420cf1dd8SToby Isaac } else { 565*3fe841f2SMatthew G. Knepley fegeom.v = &fgeom->v[(e*Np+q)*dE]; 5669f209ee4SMatthew G. Knepley fegeom.J = &fgeom->J[(e*Np+q)*dE*dE]; 5679f209ee4SMatthew G. Knepley fegeom.invJ = &fgeom->invJ[(e*Np+q)*dE*dE]; 5684bee2e38SMatthew G. Knepley fegeom.detJ = &fgeom->detJ[e*Np+q]; 5694bee2e38SMatthew G. Knepley fegeom.n = &fgeom->n[(e*Np+q)*dE]; 5709f209ee4SMatthew G. Knepley 5719f209ee4SMatthew G. Knepley cgeom.J = &fgeom->suppJ[0][(e*Np+q)*dE*dE]; 5729f209ee4SMatthew G. Knepley cgeom.invJ = &fgeom->suppInvJ[0][(e*Np+q)*dE*dE]; 5739f209ee4SMatthew G. Knepley cgeom.detJ = &fgeom->suppDetJ[0][e*Np+q]; 57420cf1dd8SToby Isaac } 5754bee2e38SMatthew G. Knepley w = fegeom.detJ[0]*quadWeights[q]; 57620cf1dd8SToby Isaac if (debug > 1 && q < Np) { 5774bee2e38SMatthew G. Knepley ierr = PetscPrintf(PETSC_COMM_SELF, " detJ: %g\n", fegeom.detJ[0]);CHKERRQ(ierr); 5787be5e748SToby Isaac #if !defined(PETSC_USE_COMPLEX) 5794bee2e38SMatthew G. Knepley ierr = DMPrintCellMatrix(e, "invJ", dim, dim, fegeom.invJ);CHKERRQ(ierr); 58020cf1dd8SToby Isaac #endif 58120cf1dd8SToby Isaac } 58220cf1dd8SToby Isaac if (debug) {ierr = PetscPrintf(PETSC_COMM_SELF, " quad point %d\n", q);CHKERRQ(ierr);} 5839f209ee4SMatthew G. Knepley ierr = PetscFEEvaluateFieldJets_Internal(ds, dim, Nf, Nb, Nc, face*Nq+q, B, D, &cgeom, &coefficients[cOffset], &coefficients_t[cOffset], u, u_x, u_t);CHKERRQ(ierr); 5849f209ee4SMatthew G. Knepley if (dsAux) {ierr = PetscFEEvaluateFieldJets_Internal(dsAux, dimAux, NfAux, NbAux, NcAux, auxOnBd ? q : face*Nq+q, BAux, DAux, &cgeom, &coefficientsAux[cOffsetAux], NULL, a, a_x, NULL);CHKERRQ(ierr);} 5854bee2e38SMatthew G. Knepley if (f0_func) { 5864bee2e38SMatthew G. Knepley f0_func(dim, Nf, NfAux, uOff, uOff_x, u, u_t, u_x, aOff, aOff_x, a, NULL, a_x, t, fegeom.v, fegeom.n, numConstants, constants, &f0[q*NcI]); 5874bee2e38SMatthew G. Knepley for (c = 0; c < NcI; ++c) f0[q*NcI+c] *= w; 5884bee2e38SMatthew G. Knepley } 58920cf1dd8SToby Isaac if (f1_func) { 5904bee2e38SMatthew G. Knepley f1_func(dim, Nf, NfAux, uOff, uOff_x, u, u_t, u_x, aOff, aOff_x, a, NULL, a_x, t, fegeom.v, fegeom.n, numConstants, constants, &f1[q*NcI*dim]); 5914bee2e38SMatthew G. Knepley for (c = 0; c < NcI; ++c) for (d = 0; d < dim; ++d) f1[(q*NcI+c)*dim+d] *= w; 59220cf1dd8SToby Isaac } 59320cf1dd8SToby Isaac } 5949f209ee4SMatthew G. Knepley ierr = PetscFEUpdateElementVec_Internal(fe, dim, Nq, NbI, NcI, &BI[face*Nq*NbI*NcI], &DI[face*Nq*NbI*NcI*dim], basisReal, basisDerReal, &cgeom, f0, f1, &elemVec[cOffset+fOffset]);CHKERRQ(ierr); 59520cf1dd8SToby Isaac cOffset += totDim; 59620cf1dd8SToby Isaac cOffsetAux += totDimAux; 59720cf1dd8SToby Isaac } 59820cf1dd8SToby Isaac PetscFunctionReturn(0); 59920cf1dd8SToby Isaac } 60020cf1dd8SToby Isaac 6014bee2e38SMatthew G. Knepley PetscErrorCode PetscFEIntegrateJacobian_Basic(PetscDS ds, PetscFEJacobianType jtype, PetscInt fieldI, PetscInt fieldJ, PetscInt Ne, PetscFEGeom *cgeom, 6024bee2e38SMatthew G. Knepley const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS dsAux, const PetscScalar coefficientsAux[], PetscReal t, PetscReal u_tshift, PetscScalar elemMat[]) 60320cf1dd8SToby Isaac { 60420cf1dd8SToby Isaac const PetscInt debug = 0; 6054bee2e38SMatthew G. Knepley PetscFE feI, feJ; 6064bee2e38SMatthew G. Knepley PetscPointJac g0_func, g1_func, g2_func, g3_func; 60720cf1dd8SToby Isaac PetscInt cOffset = 0; /* Offset into coefficients[] for element e */ 60820cf1dd8SToby Isaac PetscInt cOffsetAux = 0; /* Offset into coefficientsAux[] for element e */ 60920cf1dd8SToby Isaac PetscInt eOffset = 0; /* Offset into elemMat[] for element e */ 61020cf1dd8SToby Isaac PetscInt offsetI = 0; /* Offset into an element vector for fieldI */ 61120cf1dd8SToby Isaac PetscInt offsetJ = 0; /* Offset into an element vector for fieldJ */ 61220cf1dd8SToby Isaac PetscQuadrature quad; 6134bee2e38SMatthew G. Knepley PetscScalar *g0, *g1, *g2, *g3, *u, *u_t = NULL, *u_x, *a, *a_x, *basisReal, *basisDerReal, *testReal, *testDerReal; 61420cf1dd8SToby Isaac const PetscScalar *constants; 61520cf1dd8SToby Isaac PetscReal *x; 61620cf1dd8SToby Isaac PetscReal **B, **D, **BAux = NULL, **DAux = NULL, *BI, *DI, *BJ, *DJ; 61720cf1dd8SToby Isaac PetscInt *uOff, *uOff_x, *aOff = NULL, *aOff_x = NULL, *Nb, *Nc, *NbAux = NULL, *NcAux = NULL; 61820cf1dd8SToby Isaac PetscInt NbI = 0, NcI = 0, NbJ = 0, NcJ = 0; 61920cf1dd8SToby Isaac PetscInt dim, numConstants, Nf, NfAux = 0, totDim, totDimAux = 0, e; 62020cf1dd8SToby Isaac PetscInt dE, Np; 62120cf1dd8SToby Isaac PetscBool isAffine; 62220cf1dd8SToby Isaac const PetscReal *quadPoints, *quadWeights; 62320cf1dd8SToby Isaac PetscInt qNc, Nq, q; 62420cf1dd8SToby Isaac PetscErrorCode ierr; 62520cf1dd8SToby Isaac 62620cf1dd8SToby Isaac PetscFunctionBegin; 6274bee2e38SMatthew G. Knepley ierr = PetscDSGetDiscretization(ds, fieldI, (PetscObject *) &feI);CHKERRQ(ierr); 6284bee2e38SMatthew G. Knepley ierr = PetscDSGetDiscretization(ds, fieldJ, (PetscObject *) &feJ);CHKERRQ(ierr); 6294bee2e38SMatthew G. Knepley ierr = PetscFEGetSpatialDimension(feI, &dim);CHKERRQ(ierr); 6304bee2e38SMatthew G. Knepley ierr = PetscFEGetQuadrature(feI, &quad);CHKERRQ(ierr); 6314bee2e38SMatthew G. Knepley ierr = PetscDSGetNumFields(ds, &Nf);CHKERRQ(ierr); 6324bee2e38SMatthew G. Knepley ierr = PetscDSGetTotalDimension(ds, &totDim);CHKERRQ(ierr); 6334bee2e38SMatthew G. Knepley ierr = PetscDSGetDimensions(ds, &Nb);CHKERRQ(ierr); 6344bee2e38SMatthew G. Knepley ierr = PetscDSGetComponents(ds, &Nc);CHKERRQ(ierr); 6354bee2e38SMatthew G. Knepley ierr = PetscDSGetComponentOffsets(ds, &uOff);CHKERRQ(ierr); 6364bee2e38SMatthew G. Knepley ierr = PetscDSGetComponentDerivativeOffsets(ds, &uOff_x);CHKERRQ(ierr); 63720cf1dd8SToby Isaac switch(jtype) { 6384bee2e38SMatthew G. Knepley case PETSCFE_JACOBIAN_DYN: ierr = PetscDSGetDynamicJacobian(ds, fieldI, fieldJ, &g0_func, &g1_func, &g2_func, &g3_func);CHKERRQ(ierr);break; 6394bee2e38SMatthew G. Knepley case PETSCFE_JACOBIAN_PRE: ierr = PetscDSGetJacobianPreconditioner(ds, fieldI, fieldJ, &g0_func, &g1_func, &g2_func, &g3_func);CHKERRQ(ierr);break; 6404bee2e38SMatthew G. Knepley case PETSCFE_JACOBIAN: ierr = PetscDSGetJacobian(ds, fieldI, fieldJ, &g0_func, &g1_func, &g2_func, &g3_func);CHKERRQ(ierr);break; 64120cf1dd8SToby Isaac } 64220cf1dd8SToby Isaac if (!g0_func && !g1_func && !g2_func && !g3_func) PetscFunctionReturn(0); 6434bee2e38SMatthew G. Knepley ierr = PetscDSGetEvaluationArrays(ds, &u, coefficients_t ? &u_t : NULL, &u_x);CHKERRQ(ierr); 6444bee2e38SMatthew G. Knepley ierr = PetscDSGetWorkspace(ds, &x, &basisReal, &basisDerReal, &testReal, &testDerReal);CHKERRQ(ierr); 6454bee2e38SMatthew G. Knepley ierr = PetscDSGetWeakFormArrays(ds, NULL, NULL, &g0, &g1, &g2, &g3);CHKERRQ(ierr); 6464bee2e38SMatthew G. Knepley ierr = PetscDSGetTabulation(ds, &B, &D);CHKERRQ(ierr); 6474bee2e38SMatthew G. Knepley ierr = PetscDSGetFieldOffset(ds, fieldI, &offsetI);CHKERRQ(ierr); 6484bee2e38SMatthew G. Knepley ierr = PetscDSGetFieldOffset(ds, fieldJ, &offsetJ);CHKERRQ(ierr); 6494bee2e38SMatthew G. Knepley ierr = PetscDSGetConstants(ds, &numConstants, &constants);CHKERRQ(ierr); 6504bee2e38SMatthew G. Knepley if (dsAux) { 6514bee2e38SMatthew G. Knepley ierr = PetscDSGetNumFields(dsAux, &NfAux);CHKERRQ(ierr); 6524bee2e38SMatthew G. Knepley ierr = PetscDSGetTotalDimension(dsAux, &totDimAux);CHKERRQ(ierr); 6534bee2e38SMatthew G. Knepley ierr = PetscDSGetDimensions(dsAux, &NbAux);CHKERRQ(ierr); 6544bee2e38SMatthew G. Knepley ierr = PetscDSGetComponents(dsAux, &NcAux);CHKERRQ(ierr); 6554bee2e38SMatthew G. Knepley ierr = PetscDSGetComponentOffsets(dsAux, &aOff);CHKERRQ(ierr); 6564bee2e38SMatthew G. Knepley ierr = PetscDSGetComponentDerivativeOffsets(dsAux, &aOff_x);CHKERRQ(ierr); 6574bee2e38SMatthew G. Knepley ierr = PetscDSGetEvaluationArrays(dsAux, &a, NULL, &a_x);CHKERRQ(ierr); 6584bee2e38SMatthew G. Knepley ierr = PetscDSGetTabulation(dsAux, &BAux, &DAux);CHKERRQ(ierr); 65920cf1dd8SToby Isaac } 66020cf1dd8SToby Isaac NbI = Nb[fieldI], NbJ = Nb[fieldJ]; 66120cf1dd8SToby Isaac NcI = Nc[fieldI], NcJ = Nc[fieldJ]; 66220cf1dd8SToby Isaac BI = B[fieldI], BJ = B[fieldJ]; 66320cf1dd8SToby Isaac DI = D[fieldI], DJ = D[fieldJ]; 66420cf1dd8SToby Isaac /* Initialize here in case the function is not defined */ 66520cf1dd8SToby Isaac ierr = PetscMemzero(g0, NcI*NcJ * sizeof(PetscScalar));CHKERRQ(ierr); 66620cf1dd8SToby Isaac ierr = PetscMemzero(g1, NcI*NcJ*dim * sizeof(PetscScalar));CHKERRQ(ierr); 66720cf1dd8SToby Isaac ierr = PetscMemzero(g2, NcI*NcJ*dim * sizeof(PetscScalar));CHKERRQ(ierr); 66820cf1dd8SToby Isaac ierr = PetscMemzero(g3, NcI*NcJ*dim*dim * sizeof(PetscScalar));CHKERRQ(ierr); 66920cf1dd8SToby Isaac ierr = PetscQuadratureGetData(quad, NULL, &qNc, &Nq, &quadPoints, &quadWeights);CHKERRQ(ierr); 67020cf1dd8SToby Isaac if (qNc != 1) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_SUP, "Only supports scalar quadrature, not %D components\n", qNc); 6714bee2e38SMatthew G. Knepley Np = cgeom->numPoints; 6724bee2e38SMatthew G. Knepley dE = cgeom->dimEmbed; 6734bee2e38SMatthew G. Knepley isAffine = cgeom->isAffine; 6744bee2e38SMatthew G. Knepley for (e = 0; e < Ne; ++e) { 6754bee2e38SMatthew G. Knepley PetscFEGeom fegeom; 6764bee2e38SMatthew G. Knepley 6774bee2e38SMatthew G. Knepley if (isAffine) { 6784bee2e38SMatthew G. Knepley fegeom.v = x; 6794bee2e38SMatthew G. Knepley fegeom.xi = cgeom->xi; 6804bee2e38SMatthew G. Knepley fegeom.J = &cgeom->J[e*dE*dE]; 6814bee2e38SMatthew G. Knepley fegeom.invJ = &cgeom->invJ[e*dE*dE]; 6824bee2e38SMatthew G. Knepley fegeom.detJ = &cgeom->detJ[e]; 6834bee2e38SMatthew G. Knepley } 68420cf1dd8SToby Isaac for (q = 0; q < Nq; ++q) { 68520cf1dd8SToby Isaac const PetscReal *BIq = &BI[q*NbI*NcI], *BJq = &BJ[q*NbJ*NcJ]; 68620cf1dd8SToby Isaac const PetscReal *DIq = &DI[q*NbI*NcI*dim], *DJq = &DJ[q*NbJ*NcJ*dim]; 68720cf1dd8SToby Isaac PetscReal w; 6884bee2e38SMatthew G. Knepley PetscInt c; 68920cf1dd8SToby Isaac 69020cf1dd8SToby Isaac if (debug) {ierr = PetscPrintf(PETSC_COMM_SELF, " quad point %d\n", q);CHKERRQ(ierr);} 69120cf1dd8SToby Isaac if (isAffine) { 6924bee2e38SMatthew G. Knepley CoordinatesRefToReal(dE, dim, fegeom.xi, &cgeom->v[e*dE], fegeom.J, &quadPoints[q*dim], x); 69320cf1dd8SToby Isaac } else { 6944bee2e38SMatthew G. Knepley fegeom.v = &cgeom->v[(e*Np+q)*dE]; 6954bee2e38SMatthew G. Knepley fegeom.J = &cgeom->J[(e*Np+q)*dE*dE]; 6964bee2e38SMatthew G. Knepley fegeom.invJ = &cgeom->invJ[(e*Np+q)*dE*dE]; 6974bee2e38SMatthew G. Knepley fegeom.detJ = &cgeom->detJ[e*Np+q]; 69820cf1dd8SToby Isaac } 6994bee2e38SMatthew G. Knepley w = fegeom.detJ[0]*quadWeights[q]; 700a8f1f9e5SMatthew G. Knepley if (coefficients) {ierr = PetscFEEvaluateFieldJets_Internal(ds, dim, Nf, Nb, Nc, q, B, D, &fegeom, &coefficients[cOffset], &coefficients_t[cOffset], u, u_x, u_t);CHKERRQ(ierr);} 701a8f1f9e5SMatthew G. Knepley if (dsAux) {ierr = PetscFEEvaluateFieldJets_Internal(dsAux, dim, NfAux, NbAux, NcAux, q, BAux, DAux, &fegeom, &coefficientsAux[cOffsetAux], NULL, a, a_x, NULL);CHKERRQ(ierr);} 70220cf1dd8SToby Isaac if (g0_func) { 70320cf1dd8SToby Isaac ierr = PetscMemzero(g0, NcI*NcJ * sizeof(PetscScalar));CHKERRQ(ierr); 7044bee2e38SMatthew G. Knepley g0_func(dim, Nf, NfAux, uOff, uOff_x, u, u_t, u_x, aOff, aOff_x, a, NULL, a_x, t, u_tshift, fegeom.v, numConstants, constants, g0); 70520cf1dd8SToby Isaac for (c = 0; c < NcI*NcJ; ++c) g0[c] *= w; 70620cf1dd8SToby Isaac } 70720cf1dd8SToby Isaac if (g1_func) { 7084bee2e38SMatthew G. Knepley ierr = PetscMemzero(g1, NcI*NcJ*dim * sizeof(PetscScalar));CHKERRQ(ierr); 7094bee2e38SMatthew G. Knepley g1_func(dim, Nf, NfAux, uOff, uOff_x, u, u_t, u_x, aOff, aOff_x, a, NULL, a_x, t, u_tshift, fegeom.v, numConstants, constants, g1); 7104bee2e38SMatthew G. Knepley for (c = 0; c < NcI*NcJ*dim; ++c) g1[c] *= w; 71120cf1dd8SToby Isaac } 71220cf1dd8SToby Isaac if (g2_func) { 7134bee2e38SMatthew G. Knepley ierr = PetscMemzero(g2, NcI*NcJ*dim * sizeof(PetscScalar));CHKERRQ(ierr); 7144bee2e38SMatthew G. Knepley g2_func(dim, Nf, NfAux, uOff, uOff_x, u, u_t, u_x, aOff, aOff_x, a, NULL, a_x, t, u_tshift, fegeom.v, numConstants, constants, g2); 7154bee2e38SMatthew G. Knepley for (c = 0; c < NcI*NcJ*dim; ++c) g2[c] *= w; 71620cf1dd8SToby Isaac } 71720cf1dd8SToby Isaac if (g3_func) { 7184bee2e38SMatthew G. Knepley ierr = PetscMemzero(g3, NcI*NcJ*dim*dim * sizeof(PetscScalar));CHKERRQ(ierr); 7194bee2e38SMatthew G. Knepley g3_func(dim, Nf, NfAux, uOff, uOff_x, u, u_t, u_x, aOff, aOff_x, a, NULL, a_x, t, u_tshift, fegeom.v, numConstants, constants, g3); 7204bee2e38SMatthew G. Knepley for (c = 0; c < NcI*NcJ*dim*dim; ++c) g3[c] *= w; 72120cf1dd8SToby Isaac } 72220cf1dd8SToby Isaac 723a8f1f9e5SMatthew G. Knepley ierr = PetscFEUpdateElementMat_Internal(feI, feJ, dim, NbI, NcI, BIq, DIq, basisReal, basisDerReal, NbJ, NcJ, BJq, DJq, testReal, testDerReal, &fegeom, g0, g1, g2, g3, eOffset, totDim, offsetI, offsetJ, elemMat);CHKERRQ(ierr); 72420cf1dd8SToby Isaac } 72520cf1dd8SToby Isaac if (debug > 1) { 72620cf1dd8SToby Isaac PetscInt fc, f, gc, g; 72720cf1dd8SToby Isaac 72820cf1dd8SToby Isaac ierr = PetscPrintf(PETSC_COMM_SELF, "Element matrix for fields %d and %d\n", fieldI, fieldJ);CHKERRQ(ierr); 72920cf1dd8SToby Isaac for (fc = 0; fc < NcI; ++fc) { 73020cf1dd8SToby Isaac for (f = 0; f < NbI; ++f) { 73120cf1dd8SToby Isaac const PetscInt i = offsetI + f*NcI+fc; 73220cf1dd8SToby Isaac for (gc = 0; gc < NcJ; ++gc) { 73320cf1dd8SToby Isaac for (g = 0; g < NbJ; ++g) { 73420cf1dd8SToby Isaac const PetscInt j = offsetJ + g*NcJ+gc; 73520cf1dd8SToby Isaac ierr = PetscPrintf(PETSC_COMM_SELF, " elemMat[%d,%d,%d,%d]: %g\n", f, fc, g, gc, PetscRealPart(elemMat[eOffset+i*totDim+j]));CHKERRQ(ierr); 73620cf1dd8SToby Isaac } 73720cf1dd8SToby Isaac } 73820cf1dd8SToby Isaac ierr = PetscPrintf(PETSC_COMM_SELF, "\n");CHKERRQ(ierr); 73920cf1dd8SToby Isaac } 74020cf1dd8SToby Isaac } 74120cf1dd8SToby Isaac } 74220cf1dd8SToby Isaac cOffset += totDim; 74320cf1dd8SToby Isaac cOffsetAux += totDimAux; 74420cf1dd8SToby Isaac eOffset += PetscSqr(totDim); 74520cf1dd8SToby Isaac } 74620cf1dd8SToby Isaac PetscFunctionReturn(0); 74720cf1dd8SToby Isaac } 74820cf1dd8SToby Isaac 7494bee2e38SMatthew G. Knepley PetscErrorCode PetscFEIntegrateBdJacobian_Basic(PetscDS ds, PetscInt fieldI, PetscInt fieldJ, PetscInt Ne, PetscFEGeom *fgeom, 7504bee2e38SMatthew G. Knepley const PetscScalar coefficients[], const PetscScalar coefficients_t[], PetscDS dsAux, const PetscScalar coefficientsAux[], PetscReal t, PetscReal u_tshift, PetscScalar elemMat[]) 75120cf1dd8SToby Isaac { 75220cf1dd8SToby Isaac const PetscInt debug = 0; 7534bee2e38SMatthew G. Knepley PetscFE feI, feJ; 7544bee2e38SMatthew G. Knepley PetscBdPointJac g0_func, g1_func, g2_func, g3_func; 75520cf1dd8SToby Isaac PetscInt cOffset = 0; /* Offset into coefficients[] for element e */ 75620cf1dd8SToby Isaac PetscInt cOffsetAux = 0; /* Offset into coefficientsAux[] for element e */ 75720cf1dd8SToby Isaac PetscInt eOffset = 0; /* Offset into elemMat[] for element e */ 75820cf1dd8SToby Isaac PetscInt offsetI = 0; /* Offset into an element vector for fieldI */ 75920cf1dd8SToby Isaac PetscInt offsetJ = 0; /* Offset into an element vector for fieldJ */ 76020cf1dd8SToby Isaac PetscQuadrature quad; 7614bee2e38SMatthew G. Knepley PetscScalar *g0, *g1, *g2, *g3, *u, *u_t = NULL, *u_x, *a, *a_x, *basisReal, *basisDerReal, *testReal, *testDerReal; 76220cf1dd8SToby Isaac const PetscScalar *constants; 76320cf1dd8SToby Isaac PetscReal *x; 76420cf1dd8SToby Isaac PetscReal **B, **D, **BAux = NULL, **DAux = NULL, *BI, *DI, *BJ, *DJ; 76520cf1dd8SToby Isaac PetscInt *uOff, *uOff_x, *aOff = NULL, *aOff_x = NULL, *Nb, *Nc, *NbAux = NULL, *NcAux = NULL; 76620cf1dd8SToby Isaac PetscInt NbI = 0, NcI = 0, NbJ = 0, NcJ = 0; 76720cf1dd8SToby Isaac PetscInt dim, numConstants, Nf, NfAux = 0, totDim, totDimAux = 0, e; 76820cf1dd8SToby Isaac PetscBool isAffine; 76920cf1dd8SToby Isaac const PetscReal *quadPoints, *quadWeights; 77020cf1dd8SToby Isaac PetscInt qNc, Nq, q, Np, dE; 77120cf1dd8SToby Isaac PetscErrorCode ierr; 77220cf1dd8SToby Isaac 77320cf1dd8SToby Isaac PetscFunctionBegin; 7744bee2e38SMatthew G. Knepley ierr = PetscDSGetDiscretization(ds, fieldI, (PetscObject *) &feI);CHKERRQ(ierr); 7754bee2e38SMatthew G. Knepley ierr = PetscDSGetDiscretization(ds, fieldJ, (PetscObject *) &feJ);CHKERRQ(ierr); 7764bee2e38SMatthew G. Knepley ierr = PetscFEGetSpatialDimension(feI, &dim);CHKERRQ(ierr); 7774bee2e38SMatthew G. Knepley ierr = PetscFEGetFaceQuadrature(feI, &quad);CHKERRQ(ierr); 7784bee2e38SMatthew G. Knepley ierr = PetscDSGetNumFields(ds, &Nf);CHKERRQ(ierr); 7794bee2e38SMatthew G. Knepley ierr = PetscDSGetTotalDimension(ds, &totDim);CHKERRQ(ierr); 7804bee2e38SMatthew G. Knepley ierr = PetscDSGetDimensions(ds, &Nb);CHKERRQ(ierr); 7814bee2e38SMatthew G. Knepley ierr = PetscDSGetComponents(ds, &Nc);CHKERRQ(ierr); 7824bee2e38SMatthew G. Knepley ierr = PetscDSGetComponentOffsets(ds, &uOff);CHKERRQ(ierr); 7834bee2e38SMatthew G. Knepley ierr = PetscDSGetComponentDerivativeOffsets(ds, &uOff_x);CHKERRQ(ierr); 7844bee2e38SMatthew G. Knepley ierr = PetscDSGetFieldOffset(ds, fieldI, &offsetI);CHKERRQ(ierr); 7854bee2e38SMatthew G. Knepley ierr = PetscDSGetFieldOffset(ds, fieldJ, &offsetJ);CHKERRQ(ierr); 7864bee2e38SMatthew G. Knepley ierr = PetscDSGetBdJacobian(ds, fieldI, fieldJ, &g0_func, &g1_func, &g2_func, &g3_func);CHKERRQ(ierr); 7874bee2e38SMatthew G. Knepley ierr = PetscDSGetEvaluationArrays(ds, &u, coefficients_t ? &u_t : NULL, &u_x);CHKERRQ(ierr); 7884bee2e38SMatthew G. Knepley ierr = PetscDSGetWorkspace(ds, &x, &basisReal, &basisDerReal, &testReal, &testDerReal);CHKERRQ(ierr); 7894bee2e38SMatthew G. Knepley ierr = PetscDSGetWeakFormArrays(ds, NULL, NULL, &g0, &g1, &g2, &g3);CHKERRQ(ierr); 7904bee2e38SMatthew G. Knepley ierr = PetscDSGetFaceTabulation(ds, &B, &D);CHKERRQ(ierr); 7914bee2e38SMatthew G. Knepley ierr = PetscDSGetConstants(ds, &numConstants, &constants);CHKERRQ(ierr); 7924bee2e38SMatthew G. Knepley if (dsAux) { 7934bee2e38SMatthew G. Knepley ierr = PetscDSGetNumFields(dsAux, &NfAux);CHKERRQ(ierr); 7944bee2e38SMatthew G. Knepley ierr = PetscDSGetTotalDimension(dsAux, &totDimAux);CHKERRQ(ierr); 7954bee2e38SMatthew G. Knepley ierr = PetscDSGetDimensions(dsAux, &NbAux);CHKERRQ(ierr); 7964bee2e38SMatthew G. Knepley ierr = PetscDSGetComponents(dsAux, &NcAux);CHKERRQ(ierr); 7974bee2e38SMatthew G. Knepley ierr = PetscDSGetComponentOffsets(dsAux, &aOff);CHKERRQ(ierr); 7984bee2e38SMatthew G. Knepley ierr = PetscDSGetComponentDerivativeOffsets(dsAux, &aOff_x);CHKERRQ(ierr); 7994bee2e38SMatthew G. Knepley ierr = PetscDSGetEvaluationArrays(dsAux, &a, NULL, &a_x);CHKERRQ(ierr); 8004bee2e38SMatthew G. Knepley ierr = PetscDSGetFaceTabulation(dsAux, &BAux, &DAux);CHKERRQ(ierr); 80120cf1dd8SToby Isaac } 80220cf1dd8SToby Isaac NbI = Nb[fieldI], NbJ = Nb[fieldJ]; 80320cf1dd8SToby Isaac NcI = Nc[fieldI], NcJ = Nc[fieldJ]; 80420cf1dd8SToby Isaac BI = B[fieldI], BJ = B[fieldJ]; 80520cf1dd8SToby Isaac DI = D[fieldI], DJ = D[fieldJ]; 80620cf1dd8SToby Isaac /* Initialize here in case the function is not defined */ 80720cf1dd8SToby Isaac ierr = PetscMemzero(g0, NcI*NcJ * sizeof(PetscScalar));CHKERRQ(ierr); 80820cf1dd8SToby Isaac ierr = PetscMemzero(g1, NcI*NcJ*dim * sizeof(PetscScalar));CHKERRQ(ierr); 80920cf1dd8SToby Isaac ierr = PetscMemzero(g2, NcI*NcJ*dim * sizeof(PetscScalar));CHKERRQ(ierr); 81020cf1dd8SToby Isaac ierr = PetscMemzero(g3, NcI*NcJ*dim*dim * sizeof(PetscScalar));CHKERRQ(ierr); 81120cf1dd8SToby Isaac ierr = PetscQuadratureGetData(quad, NULL, &qNc, &Nq, &quadPoints, &quadWeights);CHKERRQ(ierr); 8124bee2e38SMatthew G. Knepley if (qNc != 1) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_SUP, "Only supports scalar quadrature, not %D components\n", qNc); 81320cf1dd8SToby Isaac Np = fgeom->numPoints; 81420cf1dd8SToby Isaac dE = fgeom->dimEmbed; 81520cf1dd8SToby Isaac isAffine = fgeom->isAffine; 81620cf1dd8SToby Isaac for (e = 0; e < Ne; ++e) { 8179f209ee4SMatthew G. Knepley PetscFEGeom fegeom, cgeom; 81820cf1dd8SToby Isaac const PetscInt face = fgeom->face[e][0]; 81920cf1dd8SToby Isaac 8204bee2e38SMatthew G. Knepley if (isAffine) { 8214bee2e38SMatthew G. Knepley fegeom.v = x; 8224bee2e38SMatthew G. Knepley fegeom.xi = fgeom->xi; 8234bee2e38SMatthew G. Knepley fegeom.J = &fgeom->J[e*dE*dE]; 8249f209ee4SMatthew G. Knepley fegeom.invJ = &fgeom->invJ[e*dE*dE]; 8254bee2e38SMatthew G. Knepley fegeom.detJ = &fgeom->detJ[e]; 8264bee2e38SMatthew G. Knepley fegeom.n = &fgeom->n[e*dE]; 8279f209ee4SMatthew G. Knepley 8289f209ee4SMatthew G. Knepley cgeom.J = &fgeom->suppJ[0][e*dE*dE]; 8299f209ee4SMatthew G. Knepley cgeom.invJ = &fgeom->suppInvJ[0][e*dE*dE]; 8309f209ee4SMatthew G. Knepley cgeom.detJ = &fgeom->suppDetJ[0][e]; 8314bee2e38SMatthew G. Knepley } 83220cf1dd8SToby Isaac for (q = 0; q < Nq; ++q) { 83320cf1dd8SToby Isaac const PetscReal *BIq = &BI[(face*Nq+q)*NbI*NcI], *BJq = &BJ[(face*Nq+q)*NbJ*NcJ]; 83420cf1dd8SToby Isaac const PetscReal *DIq = &DI[(face*Nq+q)*NbI*NcI*dim], *DJq = &DJ[(face*Nq+q)*NbJ*NcJ*dim]; 83520cf1dd8SToby Isaac PetscReal w; 8364bee2e38SMatthew G. Knepley PetscInt c; 83720cf1dd8SToby Isaac 83820cf1dd8SToby Isaac if (debug) {ierr = PetscPrintf(PETSC_COMM_SELF, " quad point %d\n", q);CHKERRQ(ierr);} 83920cf1dd8SToby Isaac if (isAffine) { 8404bee2e38SMatthew G. Knepley CoordinatesRefToReal(dE, dim-1, fegeom.xi, &fgeom->v[e*dE], fegeom.J, &quadPoints[q*(dim-1)], x); 84120cf1dd8SToby Isaac } else { 842*3fe841f2SMatthew G. Knepley fegeom.v = &fgeom->v[(e*Np+q)*dE]; 8439f209ee4SMatthew G. Knepley fegeom.J = &fgeom->J[(e*Np+q)*dE*dE]; 8449f209ee4SMatthew G. Knepley fegeom.invJ = &fgeom->invJ[(e*Np+q)*dE*dE]; 8454bee2e38SMatthew G. Knepley fegeom.detJ = &fgeom->detJ[e*Np+q]; 8464bee2e38SMatthew G. Knepley fegeom.n = &fgeom->n[(e*Np+q)*dE]; 8479f209ee4SMatthew G. Knepley 8489f209ee4SMatthew G. Knepley cgeom.J = &fgeom->suppJ[0][(e*Np+q)*dE*dE]; 8499f209ee4SMatthew G. Knepley cgeom.invJ = &fgeom->suppInvJ[0][(e*Np+q)*dE*dE]; 8509f209ee4SMatthew G. Knepley cgeom.detJ = &fgeom->suppDetJ[0][e*Np+q]; 85120cf1dd8SToby Isaac } 8524bee2e38SMatthew G. Knepley w = fegeom.detJ[0]*quadWeights[q]; 8539f209ee4SMatthew G. Knepley if (coefficients) {ierr = PetscFEEvaluateFieldJets_Internal(ds, dim, Nf, Nb, Nc, face*Nq+q, B, D, &cgeom, &coefficients[cOffset], &coefficients_t[cOffset], u, u_x, u_t);CHKERRQ(ierr);} 8549f209ee4SMatthew G. Knepley if (dsAux) {ierr = PetscFEEvaluateFieldJets_Internal(dsAux, dim, NfAux, NbAux, NcAux, face*Nq+q, BAux, DAux, &cgeom, &coefficientsAux[cOffsetAux], NULL, a, a_x, NULL);CHKERRQ(ierr);} 85520cf1dd8SToby Isaac if (g0_func) { 85620cf1dd8SToby Isaac ierr = PetscMemzero(g0, NcI*NcJ * sizeof(PetscScalar));CHKERRQ(ierr); 8574bee2e38SMatthew G. Knepley g0_func(dim, Nf, NfAux, uOff, uOff_x, u, u_t, u_x, aOff, aOff_x, a, NULL, a_x, t, u_tshift, fegeom.v, fegeom.n, numConstants, constants, g0); 85820cf1dd8SToby Isaac for (c = 0; c < NcI*NcJ; ++c) g0[c] *= w; 85920cf1dd8SToby Isaac } 86020cf1dd8SToby Isaac if (g1_func) { 8614bee2e38SMatthew G. Knepley ierr = PetscMemzero(g1, NcI*NcJ*dim * sizeof(PetscScalar));CHKERRQ(ierr); 8624bee2e38SMatthew G. Knepley g1_func(dim, Nf, NfAux, uOff, uOff_x, u, u_t, u_x, aOff, aOff_x, a, NULL, a_x, t, u_tshift, fegeom.v, fegeom.n, numConstants, constants, g1); 8634bee2e38SMatthew G. Knepley for (c = 0; c < NcI*NcJ*dim; ++c) g1[c] *= w; 86420cf1dd8SToby Isaac } 86520cf1dd8SToby Isaac if (g2_func) { 8664bee2e38SMatthew G. Knepley ierr = PetscMemzero(g2, NcI*NcJ*dim * sizeof(PetscScalar));CHKERRQ(ierr); 8674bee2e38SMatthew G. Knepley g2_func(dim, Nf, NfAux, uOff, uOff_x, u, u_t, u_x, aOff, aOff_x, a, NULL, a_x, t, u_tshift, fegeom.v, fegeom.n, numConstants, constants, g2); 8684bee2e38SMatthew G. Knepley for (c = 0; c < NcI*NcJ*dim; ++c) g2[c] *= w; 86920cf1dd8SToby Isaac } 87020cf1dd8SToby Isaac if (g3_func) { 8714bee2e38SMatthew G. Knepley ierr = PetscMemzero(g3, NcI*NcJ*dim*dim * sizeof(PetscScalar));CHKERRQ(ierr); 8724bee2e38SMatthew G. Knepley g3_func(dim, Nf, NfAux, uOff, uOff_x, u, u_t, u_x, aOff, aOff_x, a, NULL, a_x, t, u_tshift, fegeom.v, fegeom.n, numConstants, constants, g3); 8734bee2e38SMatthew G. Knepley for (c = 0; c < NcI*NcJ*dim*dim; ++c) g3[c] *= w; 87420cf1dd8SToby Isaac } 87520cf1dd8SToby Isaac 8769f209ee4SMatthew G. Knepley ierr = PetscFEUpdateElementMat_Internal(feI, feJ, dim, NbI, NcI, BIq, DIq, basisReal, basisDerReal, NbJ, NcJ, BJq, DJq, testReal, testDerReal, &cgeom, g0, g1, g2, g3, eOffset, totDim, offsetI, offsetJ, elemMat);CHKERRQ(ierr); 87720cf1dd8SToby Isaac } 87820cf1dd8SToby Isaac if (debug > 1) { 87920cf1dd8SToby Isaac PetscInt fc, f, gc, g; 88020cf1dd8SToby Isaac 88120cf1dd8SToby Isaac ierr = PetscPrintf(PETSC_COMM_SELF, "Element matrix for fields %d and %d\n", fieldI, fieldJ);CHKERRQ(ierr); 88220cf1dd8SToby Isaac for (fc = 0; fc < NcI; ++fc) { 88320cf1dd8SToby Isaac for (f = 0; f < NbI; ++f) { 88420cf1dd8SToby Isaac const PetscInt i = offsetI + f*NcI+fc; 88520cf1dd8SToby Isaac for (gc = 0; gc < NcJ; ++gc) { 88620cf1dd8SToby Isaac for (g = 0; g < NbJ; ++g) { 88720cf1dd8SToby Isaac const PetscInt j = offsetJ + g*NcJ+gc; 88820cf1dd8SToby Isaac ierr = PetscPrintf(PETSC_COMM_SELF, " elemMat[%d,%d,%d,%d]: %g\n", f, fc, g, gc, PetscRealPart(elemMat[eOffset+i*totDim+j]));CHKERRQ(ierr); 88920cf1dd8SToby Isaac } 89020cf1dd8SToby Isaac } 89120cf1dd8SToby Isaac ierr = PetscPrintf(PETSC_COMM_SELF, "\n");CHKERRQ(ierr); 89220cf1dd8SToby Isaac } 89320cf1dd8SToby Isaac } 89420cf1dd8SToby Isaac } 89520cf1dd8SToby Isaac cOffset += totDim; 89620cf1dd8SToby Isaac cOffsetAux += totDimAux; 89720cf1dd8SToby Isaac eOffset += PetscSqr(totDim); 89820cf1dd8SToby Isaac } 89920cf1dd8SToby Isaac PetscFunctionReturn(0); 90020cf1dd8SToby Isaac } 90120cf1dd8SToby Isaac 90220cf1dd8SToby Isaac PetscErrorCode PetscFEInitialize_Basic(PetscFE fem) 90320cf1dd8SToby Isaac { 90420cf1dd8SToby Isaac PetscFunctionBegin; 90520cf1dd8SToby Isaac fem->ops->setfromoptions = NULL; 90620cf1dd8SToby Isaac fem->ops->setup = PetscFESetUp_Basic; 90720cf1dd8SToby Isaac fem->ops->view = PetscFEView_Basic; 90820cf1dd8SToby Isaac fem->ops->destroy = PetscFEDestroy_Basic; 90920cf1dd8SToby Isaac fem->ops->getdimension = PetscFEGetDimension_Basic; 91020cf1dd8SToby Isaac fem->ops->gettabulation = PetscFEGetTabulation_Basic; 91120cf1dd8SToby Isaac fem->ops->integrate = PetscFEIntegrate_Basic; 912afe6d6adSToby Isaac fem->ops->integratebd = PetscFEIntegrateBd_Basic; 91320cf1dd8SToby Isaac fem->ops->integrateresidual = PetscFEIntegrateResidual_Basic; 91420cf1dd8SToby Isaac fem->ops->integratebdresidual = PetscFEIntegrateBdResidual_Basic; 91520cf1dd8SToby Isaac fem->ops->integratejacobianaction = NULL/* PetscFEIntegrateJacobianAction_Basic */; 91620cf1dd8SToby Isaac fem->ops->integratejacobian = PetscFEIntegrateJacobian_Basic; 91720cf1dd8SToby Isaac fem->ops->integratebdjacobian = PetscFEIntegrateBdJacobian_Basic; 91820cf1dd8SToby Isaac PetscFunctionReturn(0); 91920cf1dd8SToby Isaac } 92020cf1dd8SToby Isaac 92120cf1dd8SToby Isaac /*MC 92220cf1dd8SToby Isaac PETSCFEBASIC = "basic" - A PetscFE object that integrates with basic tiling and no vectorization 92320cf1dd8SToby Isaac 92420cf1dd8SToby Isaac Level: intermediate 92520cf1dd8SToby Isaac 92620cf1dd8SToby Isaac .seealso: PetscFEType, PetscFECreate(), PetscFESetType() 92720cf1dd8SToby Isaac M*/ 92820cf1dd8SToby Isaac 92920cf1dd8SToby Isaac PETSC_EXTERN PetscErrorCode PetscFECreate_Basic(PetscFE fem) 93020cf1dd8SToby Isaac { 93120cf1dd8SToby Isaac PetscFE_Basic *b; 93220cf1dd8SToby Isaac PetscErrorCode ierr; 93320cf1dd8SToby Isaac 93420cf1dd8SToby Isaac PetscFunctionBegin; 93520cf1dd8SToby Isaac PetscValidHeaderSpecific(fem, PETSCFE_CLASSID, 1); 93620cf1dd8SToby Isaac ierr = PetscNewLog(fem,&b);CHKERRQ(ierr); 93720cf1dd8SToby Isaac fem->data = b; 93820cf1dd8SToby Isaac 93920cf1dd8SToby Isaac ierr = PetscFEInitialize_Basic(fem);CHKERRQ(ierr); 94020cf1dd8SToby Isaac PetscFunctionReturn(0); 94120cf1dd8SToby Isaac } 942