Actual source code: space.c

petsc-3.11.3 2019-06-26
Report Typos and Errors
  1:  #include <petsc/private/petscfeimpl.h>
  2:  #include <petscdmshell.h>

  4: PetscClassId PETSCSPACE_CLASSID = 0;

  6: PetscFunctionList PetscSpaceList              = NULL;
  7: PetscBool         PetscSpaceRegisterAllCalled = PETSC_FALSE;

  9: /*@C
 10:   PetscSpaceRegister - Adds a new PetscSpace implementation

 12:   Not Collective

 14:   Input Parameters:
 15: + name        - The name of a new user-defined creation routine
 16: - create_func - The creation routine for the implementation type

 18:   Notes:
 19:   PetscSpaceRegister() may be called multiple times to add several user-defined types of PetscSpaces.  The creation function is called
 20:   when the type is set to 'name'.

 22:   Sample usage:
 23: .vb
 24:     PetscSpaceRegister("my_space", MyPetscSpaceCreate);
 25: .ve

 27:   Then, your PetscSpace type can be chosen with the procedural interface via
 28: .vb
 29:     PetscSpaceCreate(MPI_Comm, PetscSpace *);
 30:     PetscSpaceSetType(PetscSpace, "my_space");
 31: .ve
 32:    or at runtime via the option
 33: .vb
 34:     -petscspace_type my_space
 35: .ve

 37:   Level: advanced

 39: .keywords: PetscSpace, register
 40: .seealso: PetscSpaceRegisterAll(), PetscSpaceRegisterDestroy()

 42: @*/
 43: PetscErrorCode PetscSpaceRegister(const char sname[], PetscErrorCode (*function)(PetscSpace))
 44: {

 48:   PetscFunctionListAdd(&PetscSpaceList, sname, function);
 49:   return(0);
 50: }

 52: /*@C
 53:   PetscSpaceSetType - Builds a particular PetscSpace

 55:   Collective on PetscSpace

 57:   Input Parameters:
 58: + sp   - The PetscSpace object
 59: - name - The kind of space

 61:   Options Database Key:
 62: . -petscspace_type <type> - Sets the PetscSpace type; use -help for a list of available types

 64:   Level: intermediate

 66: .keywords: PetscSpace, set, type
 67: .seealso: PetscSpaceGetType(), PetscSpaceCreate()
 68: @*/
 69: PetscErrorCode PetscSpaceSetType(PetscSpace sp, PetscSpaceType name)
 70: {
 71:   PetscErrorCode (*r)(PetscSpace);
 72:   PetscBool      match;

 77:   PetscObjectTypeCompare((PetscObject) sp, name, &match);
 78:   if (match) return(0);

 80:   PetscSpaceRegisterAll();
 81:   PetscFunctionListFind(PetscSpaceList, name, &r);
 82:   if (!r) SETERRQ1(PetscObjectComm((PetscObject) sp), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscSpace type: %s", name);

 84:   if (sp->ops->destroy) {
 85:     (*sp->ops->destroy)(sp);
 86:     sp->ops->destroy = NULL;
 87:   }
 88:   sp->dim = PETSC_DETERMINE;
 89:   (*r)(sp);
 90:   PetscObjectChangeTypeName((PetscObject) sp, name);
 91:   return(0);
 92: }

 94: /*@C
 95:   PetscSpaceGetType - Gets the PetscSpace type name (as a string) from the object.

 97:   Not Collective

 99:   Input Parameter:
100: . sp  - The PetscSpace

102:   Output Parameter:
103: . name - The PetscSpace type name

105:   Level: intermediate

107: .keywords: PetscSpace, get, type, name
108: .seealso: PetscSpaceSetType(), PetscSpaceCreate()
109: @*/
110: PetscErrorCode PetscSpaceGetType(PetscSpace sp, PetscSpaceType *name)
111: {

117:   if (!PetscSpaceRegisterAllCalled) {
118:     PetscSpaceRegisterAll();
119:   }
120:   *name = ((PetscObject) sp)->type_name;
121:   return(0);
122: }

124: /*@C
125:   PetscSpaceView - Views a PetscSpace

127:   Collective on PetscSpace

129:   Input Parameter:
130: + sp - the PetscSpace object to view
131: - v  - the viewer

133:   Level: developer

135: .seealso PetscSpaceDestroy()
136: @*/
137: PetscErrorCode PetscSpaceView(PetscSpace sp, PetscViewer v)
138: {
139:   PetscBool      iascii;

145:   if (!v) {PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject) sp), &v);}
146:   PetscObjectPrintClassNamePrefixType((PetscObject)sp,v);
147:   PetscObjectTypeCompare((PetscObject) v, PETSCVIEWERASCII, &iascii);
148:   PetscViewerASCIIPushTab(v);
149:   if (iascii) {PetscViewerASCIIPrintf(v, "Space in %D variables with %D components\n", sp->Nv, sp->Nc);}
150:   if (sp->ops->view) {(*sp->ops->view)(sp, v);}
151:   PetscViewerASCIIPopTab(v);
152:   return(0);
153: }

155: /*@
156:   PetscSpaceSetFromOptions - sets parameters in a PetscSpace from the options database

158:   Collective on PetscSpace

160:   Input Parameter:
161: . sp - the PetscSpace object to set options for

163:   Options Database:
164: . -petscspace_degree the approximation order of the space

166:   Level: developer

168: .seealso PetscSpaceView()
169: @*/
170: PetscErrorCode PetscSpaceSetFromOptions(PetscSpace sp)
171: {
172:   const char    *defaultType;
173:   char           name[256];
174:   PetscBool      flg, orderflg;

179:   if (!((PetscObject) sp)->type_name) {
180:     defaultType = PETSCSPACEPOLYNOMIAL;
181:   } else {
182:     defaultType = ((PetscObject) sp)->type_name;
183:   }
184:   if (!PetscSpaceRegisterAllCalled) {PetscSpaceRegisterAll();}

186:   PetscObjectOptionsBegin((PetscObject) sp);
187:   PetscOptionsFList("-petscspace_type", "Linear space", "PetscSpaceSetType", PetscSpaceList, defaultType, name, 256, &flg);
188:   if (flg) {
189:     PetscSpaceSetType(sp, name);
190:   } else if (!((PetscObject) sp)->type_name) {
191:     PetscSpaceSetType(sp, defaultType);
192:   }
193:   {
194:     PetscOptionsInt("-petscspace_order", "DEPRECATED: The approximation order", "PetscSpaceSetDegree", sp->degree, &sp->degree, &orderflg);
195:     if (orderflg) {
196:       int compare;

198:       MPI_Comm_compare(PetscObjectComm((PetscObject)sp), PETSC_COMM_WORLD, &compare);

200:       if (compare == MPI_IDENT || compare == MPI_CONGRUENT) {
201:         PetscPrintf(PetscObjectComm((PetscObject)sp), "Warning: -petscspace_order is deprecated.  Use -petscspace_degree\n");
202:       }
203:     }
204:   }
205:   PetscOptionsInt("-petscspace_degree", "The (maximally included) polynomial degree", "PetscSpaceSetDegree", sp->degree, &sp->degree, NULL);
206:   PetscOptionsInt("-petscspace_variables", "The number of different variables, e.g. x and y", "PetscSpaceSetNumVariables", sp->Nv, &sp->Nv, NULL);
207:   PetscOptionsInt("-petscspace_components", "The number of components", "PetscSpaceSetNumComponents", sp->Nc, &sp->Nc, NULL);
208:   if (sp->ops->setfromoptions) {
209:     (*sp->ops->setfromoptions)(PetscOptionsObject,sp);
210:   }
211:   /* process any options handlers added with PetscObjectAddOptionsHandler() */
212:   PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject) sp);
213:   PetscOptionsEnd();
214:   PetscSpaceViewFromOptions(sp, NULL, "-petscspace_view");
215:   return(0);
216: }

218: /*@C
219:   PetscSpaceSetUp - Construct data structures for the PetscSpace

221:   Collective on PetscSpace

223:   Input Parameter:
224: . sp - the PetscSpace object to setup

226:   Level: developer

228: .seealso PetscSpaceView(), PetscSpaceDestroy()
229: @*/
230: PetscErrorCode PetscSpaceSetUp(PetscSpace sp)
231: {

236:   if (sp->ops->setup) {(*sp->ops->setup)(sp);}
237:   return(0);
238: }

240: /*@
241:   PetscSpaceDestroy - Destroys a PetscSpace object

243:   Collective on PetscSpace

245:   Input Parameter:
246: . sp - the PetscSpace object to destroy

248:   Level: developer

250: .seealso PetscSpaceView()
251: @*/
252: PetscErrorCode PetscSpaceDestroy(PetscSpace *sp)
253: {

257:   if (!*sp) return(0);

260:   if (--((PetscObject)(*sp))->refct > 0) {*sp = 0; return(0);}
261:   ((PetscObject) (*sp))->refct = 0;
262:   DMDestroy(&(*sp)->dm);

264:   (*(*sp)->ops->destroy)(*sp);
265:   PetscHeaderDestroy(sp);
266:   return(0);
267: }

269: /*@
270:   PetscSpaceCreate - Creates an empty PetscSpace object. The type can then be set with PetscSpaceSetType().

272:   Collective on MPI_Comm

274:   Input Parameter:
275: . comm - The communicator for the PetscSpace object

277:   Output Parameter:
278: . sp - The PetscSpace object

280:   Level: beginner

282: .seealso: PetscSpaceSetType(), PETSCSPACEPOLYNOMIAL
283: @*/
284: PetscErrorCode PetscSpaceCreate(MPI_Comm comm, PetscSpace *sp)
285: {
286:   PetscSpace     s;

291:   PetscCitationsRegister(FECitation,&FEcite);
292:   *sp  = NULL;
293:   PetscFEInitializePackage();

295:   PetscHeaderCreate(s, PETSCSPACE_CLASSID, "PetscSpace", "Linear Space", "PetscSpace", comm, PetscSpaceDestroy, PetscSpaceView);

297:   s->degree    = 0;
298:   s->maxDegree = PETSC_DETERMINE;
299:   s->Nc        = 1;
300:   s->Nv        = 0;
301:   s->dim       = PETSC_DETERMINE;
302:   DMShellCreate(comm, &s->dm);
303:   PetscSpaceSetType(s, PETSCSPACEPOLYNOMIAL);

305:   *sp = s;
306:   return(0);
307: }

309: /*@
310:   PetscSpaceGetDimension - Return the dimension of this space, i.e. the number of basis vectors

312:   Input Parameter:
313: . sp - The PetscSpace

315:   Output Parameter:
316: . dim - The dimension

318:   Level: intermediate

320: .seealso: PetscSpaceGetDegree(), PetscSpaceCreate(), PetscSpace
321: @*/
322: PetscErrorCode PetscSpaceGetDimension(PetscSpace sp, PetscInt *dim)
323: {

329:   if (sp->dim == PETSC_DETERMINE) {
330:     if (sp->ops->getdimension) {(*sp->ops->getdimension)(sp, &sp->dim);}
331:   }
332:   *dim = sp->dim;
333:   return(0);
334: }

336: /*@
337:   PetscSpaceGetDegree - Return the polynomial degrees that characterize this space

339:   Input Parameter:
340: . sp - The PetscSpace

342:   Output Parameter:
343: + minDegree - The degree of the largest polynomial space contained in the space
344: - maxDegree - The degree of the smallest polynomial space containing the space


347:   Level: intermediate

349: .seealso: PetscSpaceSetDegree(), PetscSpaceGetDimension(), PetscSpaceCreate(), PetscSpace
350: @*/
351: PetscErrorCode PetscSpaceGetDegree(PetscSpace sp, PetscInt *minDegree, PetscInt *maxDegree)
352: {
357:   if (minDegree) *minDegree = sp->degree;
358:   if (maxDegree) *maxDegree = sp->maxDegree;
359:   return(0);
360: }

362: /*@
363:   PetscSpaceSetDegree - Set the degree of approximation for this space.

365:   Input Parameters:
366: + sp - The PetscSpace
367: . degree - The degree of the largest polynomial space contained in the space
368: - maxDegree - The degree of the largest polynomial space containing the space.  One of degree and maxDegree can be PETSC_DETERMINE.

370:   Level: intermediate

372: .seealso: PetscSpaceGetDegree(), PetscSpaceCreate(), PetscSpace
373: @*/
374: PetscErrorCode PetscSpaceSetDegree(PetscSpace sp, PetscInt degree, PetscInt maxDegree)
375: {
378:   sp->degree = degree;
379:   sp->maxDegree = maxDegree;
380:   return(0);
381: }

383: /*@
384:   PetscSpaceGetNumComponents - Return the number of components for this space

386:   Input Parameter:
387: . sp - The PetscSpace

389:   Output Parameter:
390: . Nc - The number of components

392:   Note: A vector space, for example, will have d components, where d is the spatial dimension

394:   Level: intermediate

396: .seealso: PetscSpaceSetNumComponents(), PetscSpaceGetDimension(), PetscSpaceCreate(), PetscSpace
397: @*/
398: PetscErrorCode PetscSpaceGetNumComponents(PetscSpace sp, PetscInt *Nc)
399: {
403:   *Nc = sp->Nc;
404:   return(0);
405: }

407: /*@
408:   PetscSpaceSetNumComponents - Set the number of components for this space

410:   Input Parameters:
411: + sp - The PetscSpace
412: - order - The number of components

414:   Level: intermediate

416: .seealso: PetscSpaceGetNumComponents(), PetscSpaceCreate(), PetscSpace
417: @*/
418: PetscErrorCode PetscSpaceSetNumComponents(PetscSpace sp, PetscInt Nc)
419: {
422:   sp->Nc = Nc;
423:   return(0);
424: }

426: PetscErrorCode PetscSpaceSetNumVariables(PetscSpace sp, PetscInt n)
427: {
430:   sp->Nv = n;
431:   return(0);
432: }

434: PetscErrorCode PetscSpaceGetNumVariables(PetscSpace sp, PetscInt *n)
435: {
439:   *n = sp->Nv;
440:   return(0);
441: }


444: /*@C
445:   PetscSpaceEvaluate - Evaluate the basis functions and their derivatives (jet) at each point

447:   Input Parameters:
448: + sp      - The PetscSpace
449: . npoints - The number of evaluation points, in reference coordinates
450: - points  - The point coordinates

452:   Output Parameters:
453: + B - The function evaluations in a npoints x nfuncs array
454: . D - The derivative evaluations in a npoints x nfuncs x dim array
455: - H - The second derivative evaluations in a npoints x nfuncs x dim x dim array

457:   Note: Above nfuncs is the dimension of the space, and dim is the spatial dimension. The coordinates are given
458:   on the reference cell, not in real space.

460:   Level: advanced

462: .seealso: PetscFEGetTabulation(), PetscFEGetDefaultTabulation(), PetscSpaceCreate()
463: @*/
464: PetscErrorCode PetscSpaceEvaluate(PetscSpace sp, PetscInt npoints, const PetscReal points[], PetscReal B[], PetscReal D[], PetscReal H[])
465: {

469:   if (!npoints) return(0);
475:   if (sp->ops->evaluate) {(*sp->ops->evaluate)(sp, npoints, points, B, D, H);}
476:   return(0);
477: }

479: /*@
480:   PetscSpaceGetHeightSubspace - Get the subset of the primal space basis that is supported on a mesh point of a given height.

482:   If the space is not defined on mesh points of the given height (e.g. if the space is discontinuous and
483:   pointwise values are not defined on the element boundaries), or if the implementation of PetscSpace does not
484:   support extracting subspaces, then NULL is returned.

486:   This does not increment the reference count on the returned space, and the user should not destroy it.

488:   Not collective

490:   Input Parameters:
491: + sp - the PetscSpace object
492: - height - the height of the mesh point for which the subspace is desired

494:   Output Parameter:
495: . subsp - the subspace

497:   Level: advanced

499: .seealso: PetscDualSpaceGetHeightSubspace(), PetscSpace
500: @*/
501: PetscErrorCode PetscSpaceGetHeightSubspace(PetscSpace sp, PetscInt height, PetscSpace *subsp)
502: {

508:   *subsp = NULL;
509:   if (sp->ops->getheightsubspace) {
510:     (*sp->ops->getheightsubspace)(sp, height, subsp);
511:   }
512:   return(0);
513: }