xref: /petsc/src/dm/dt/space/interface/space.c (revision 63a3b9bc7a1f24f247904ccba9383635fe6abade)
120cf1dd8SToby Isaac #include <petsc/private/petscfeimpl.h>     /*I  "petscfe.h"  I*/
220cf1dd8SToby Isaac #include <petscdmshell.h>
320cf1dd8SToby Isaac 
420cf1dd8SToby Isaac PetscClassId PETSCSPACE_CLASSID = 0;
520cf1dd8SToby Isaac 
620cf1dd8SToby Isaac PetscFunctionList PetscSpaceList              = NULL;
720cf1dd8SToby Isaac PetscBool         PetscSpaceRegisterAllCalled = PETSC_FALSE;
820cf1dd8SToby Isaac 
920cf1dd8SToby Isaac /*@C
1020cf1dd8SToby Isaac   PetscSpaceRegister - Adds a new PetscSpace implementation
1120cf1dd8SToby Isaac 
1220cf1dd8SToby Isaac   Not Collective
1320cf1dd8SToby Isaac 
1420cf1dd8SToby Isaac   Input Parameters:
1520cf1dd8SToby Isaac + name        - The name of a new user-defined creation routine
1620cf1dd8SToby Isaac - create_func - The creation routine for the implementation type
1720cf1dd8SToby Isaac 
1820cf1dd8SToby Isaac   Notes:
1920cf1dd8SToby Isaac   PetscSpaceRegister() may be called multiple times to add several user-defined types of PetscSpaces.  The creation function is called
2020cf1dd8SToby Isaac   when the type is set to 'name'.
2120cf1dd8SToby Isaac 
2220cf1dd8SToby Isaac   Sample usage:
2320cf1dd8SToby Isaac .vb
2420cf1dd8SToby Isaac     PetscSpaceRegister("my_space", MyPetscSpaceCreate);
2520cf1dd8SToby Isaac .ve
2620cf1dd8SToby Isaac 
2720cf1dd8SToby Isaac   Then, your PetscSpace type can be chosen with the procedural interface via
2820cf1dd8SToby Isaac .vb
2920cf1dd8SToby Isaac     PetscSpaceCreate(MPI_Comm, PetscSpace *);
3020cf1dd8SToby Isaac     PetscSpaceSetType(PetscSpace, "my_space");
3120cf1dd8SToby Isaac .ve
3220cf1dd8SToby Isaac    or at runtime via the option
3320cf1dd8SToby Isaac .vb
3420cf1dd8SToby Isaac     -petscspace_type my_space
3520cf1dd8SToby Isaac .ve
3620cf1dd8SToby Isaac 
3720cf1dd8SToby Isaac   Level: advanced
3820cf1dd8SToby Isaac 
3920cf1dd8SToby Isaac .seealso: PetscSpaceRegisterAll(), PetscSpaceRegisterDestroy()
4020cf1dd8SToby Isaac 
4120cf1dd8SToby Isaac @*/
4220cf1dd8SToby Isaac PetscErrorCode PetscSpaceRegister(const char sname[], PetscErrorCode (*function)(PetscSpace))
4320cf1dd8SToby Isaac {
4420cf1dd8SToby Isaac   PetscFunctionBegin;
459566063dSJacob Faibussowitsch   PetscCall(PetscFunctionListAdd(&PetscSpaceList, sname, function));
4620cf1dd8SToby Isaac   PetscFunctionReturn(0);
4720cf1dd8SToby Isaac }
4820cf1dd8SToby Isaac 
4920cf1dd8SToby Isaac /*@C
5020cf1dd8SToby Isaac   PetscSpaceSetType - Builds a particular PetscSpace
5120cf1dd8SToby Isaac 
52d083f849SBarry Smith   Collective on sp
5320cf1dd8SToby Isaac 
5420cf1dd8SToby Isaac   Input Parameters:
5520cf1dd8SToby Isaac + sp   - The PetscSpace object
5620cf1dd8SToby Isaac - name - The kind of space
5720cf1dd8SToby Isaac 
5820cf1dd8SToby Isaac   Options Database Key:
5920cf1dd8SToby Isaac . -petscspace_type <type> - Sets the PetscSpace type; use -help for a list of available types
6020cf1dd8SToby Isaac 
6120cf1dd8SToby Isaac   Level: intermediate
6220cf1dd8SToby Isaac 
6320cf1dd8SToby Isaac .seealso: PetscSpaceGetType(), PetscSpaceCreate()
6420cf1dd8SToby Isaac @*/
6520cf1dd8SToby Isaac PetscErrorCode PetscSpaceSetType(PetscSpace sp, PetscSpaceType name)
6620cf1dd8SToby Isaac {
6720cf1dd8SToby Isaac   PetscErrorCode (*r)(PetscSpace);
6820cf1dd8SToby Isaac   PetscBool      match;
6920cf1dd8SToby Isaac 
7020cf1dd8SToby Isaac   PetscFunctionBegin;
7120cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
729566063dSJacob Faibussowitsch   PetscCall(PetscObjectTypeCompare((PetscObject) sp, name, &match));
7320cf1dd8SToby Isaac   if (match) PetscFunctionReturn(0);
7420cf1dd8SToby Isaac 
759566063dSJacob Faibussowitsch   PetscCall(PetscSpaceRegisterAll());
769566063dSJacob Faibussowitsch   PetscCall(PetscFunctionListFind(PetscSpaceList, name, &r));
772c71b3e2SJacob Faibussowitsch   PetscCheck(r,PetscObjectComm((PetscObject) sp), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscSpace type: %s", name);
7820cf1dd8SToby Isaac 
7920cf1dd8SToby Isaac   if (sp->ops->destroy) {
809566063dSJacob Faibussowitsch     PetscCall((*sp->ops->destroy)(sp));
8120cf1dd8SToby Isaac     sp->ops->destroy = NULL;
8220cf1dd8SToby Isaac   }
8343bfef1cSToby Isaac   sp->dim = PETSC_DETERMINE;
849566063dSJacob Faibussowitsch   PetscCall((*r)(sp));
859566063dSJacob Faibussowitsch   PetscCall(PetscObjectChangeTypeName((PetscObject) sp, name));
8620cf1dd8SToby Isaac   PetscFunctionReturn(0);
8720cf1dd8SToby Isaac }
8820cf1dd8SToby Isaac 
8920cf1dd8SToby Isaac /*@C
9020cf1dd8SToby Isaac   PetscSpaceGetType - Gets the PetscSpace type name (as a string) from the object.
9120cf1dd8SToby Isaac 
9220cf1dd8SToby Isaac   Not Collective
9320cf1dd8SToby Isaac 
9420cf1dd8SToby Isaac   Input Parameter:
9520cf1dd8SToby Isaac . sp  - The PetscSpace
9620cf1dd8SToby Isaac 
9720cf1dd8SToby Isaac   Output Parameter:
9820cf1dd8SToby Isaac . name - The PetscSpace type name
9920cf1dd8SToby Isaac 
10020cf1dd8SToby Isaac   Level: intermediate
10120cf1dd8SToby Isaac 
10220cf1dd8SToby Isaac .seealso: PetscSpaceSetType(), PetscSpaceCreate()
10320cf1dd8SToby Isaac @*/
10420cf1dd8SToby Isaac PetscErrorCode PetscSpaceGetType(PetscSpace sp, PetscSpaceType *name)
10520cf1dd8SToby Isaac {
10620cf1dd8SToby Isaac   PetscFunctionBegin;
10720cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
10820cf1dd8SToby Isaac   PetscValidPointer(name, 2);
10920cf1dd8SToby Isaac   if (!PetscSpaceRegisterAllCalled) {
1109566063dSJacob Faibussowitsch     PetscCall(PetscSpaceRegisterAll());
11120cf1dd8SToby Isaac   }
11220cf1dd8SToby Isaac   *name = ((PetscObject) sp)->type_name;
11320cf1dd8SToby Isaac   PetscFunctionReturn(0);
11420cf1dd8SToby Isaac }
11520cf1dd8SToby Isaac 
11620cf1dd8SToby Isaac /*@C
117fe2efc57SMark    PetscSpaceViewFromOptions - View from Options
118fe2efc57SMark 
119fe2efc57SMark    Collective on PetscSpace
120fe2efc57SMark 
121fe2efc57SMark    Input Parameters:
122fe2efc57SMark +  A - the PetscSpace object
123736c3998SJose E. Roman .  obj - Optional object
124736c3998SJose E. Roman -  name - command line option
125fe2efc57SMark 
126fe2efc57SMark    Level: intermediate
127fe2efc57SMark .seealso:  PetscSpace, PetscSpaceView, PetscObjectViewFromOptions(), PetscSpaceCreate()
128fe2efc57SMark @*/
129fe2efc57SMark PetscErrorCode  PetscSpaceViewFromOptions(PetscSpace A,PetscObject obj,const char name[])
130fe2efc57SMark {
131fe2efc57SMark   PetscFunctionBegin;
132fe2efc57SMark   PetscValidHeaderSpecific(A,PETSCSPACE_CLASSID,1);
1339566063dSJacob Faibussowitsch   PetscCall(PetscObjectViewFromOptions((PetscObject)A,obj,name));
134fe2efc57SMark   PetscFunctionReturn(0);
135fe2efc57SMark }
136fe2efc57SMark 
137fe2efc57SMark /*@C
13820cf1dd8SToby Isaac   PetscSpaceView - Views a PetscSpace
13920cf1dd8SToby Isaac 
140d083f849SBarry Smith   Collective on sp
14120cf1dd8SToby Isaac 
142d8d19677SJose E. Roman   Input Parameters:
14320cf1dd8SToby Isaac + sp - the PetscSpace object to view
14420cf1dd8SToby Isaac - v  - the viewer
14520cf1dd8SToby Isaac 
14629b5c115SMatthew G. Knepley   Level: beginner
14720cf1dd8SToby Isaac 
14820cf1dd8SToby Isaac .seealso PetscSpaceDestroy()
14920cf1dd8SToby Isaac @*/
15020cf1dd8SToby Isaac PetscErrorCode PetscSpaceView(PetscSpace sp, PetscViewer v)
15120cf1dd8SToby Isaac {
1520aec8e07SMatthew G. Knepley   PetscInt       pdim;
15320cf1dd8SToby Isaac   PetscBool      iascii;
15420cf1dd8SToby Isaac 
15520cf1dd8SToby Isaac   PetscFunctionBegin;
15620cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
15720cf1dd8SToby Isaac   if (v) PetscValidHeaderSpecific(v, PETSC_VIEWER_CLASSID, 2);
1589566063dSJacob Faibussowitsch   if (!v) PetscCall(PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject) sp), &v));
1599566063dSJacob Faibussowitsch   PetscCall(PetscSpaceGetDimension(sp, &pdim));
1609566063dSJacob Faibussowitsch   PetscCall(PetscObjectPrintClassNamePrefixType((PetscObject)sp,v));
1619566063dSJacob Faibussowitsch   PetscCall(PetscObjectTypeCompare((PetscObject) v, PETSCVIEWERASCII, &iascii));
1629566063dSJacob Faibussowitsch   PetscCall(PetscViewerASCIIPushTab(v));
163*63a3b9bcSJacob Faibussowitsch   if (iascii) PetscCall(PetscViewerASCIIPrintf(v, "Space in %" PetscInt_FMT " variables with %" PetscInt_FMT " components, size %" PetscInt_FMT "\n", sp->Nv, sp->Nc, pdim));
1649566063dSJacob Faibussowitsch   if (sp->ops->view) PetscCall((*sp->ops->view)(sp, v));
1659566063dSJacob Faibussowitsch   PetscCall(PetscViewerASCIIPopTab(v));
16620cf1dd8SToby Isaac   PetscFunctionReturn(0);
16720cf1dd8SToby Isaac }
16820cf1dd8SToby Isaac 
16920cf1dd8SToby Isaac /*@
17020cf1dd8SToby Isaac   PetscSpaceSetFromOptions - sets parameters in a PetscSpace from the options database
17120cf1dd8SToby Isaac 
172d083f849SBarry Smith   Collective on sp
17320cf1dd8SToby Isaac 
17420cf1dd8SToby Isaac   Input Parameter:
17520cf1dd8SToby Isaac . sp - the PetscSpace object to set options for
17620cf1dd8SToby Isaac 
17720cf1dd8SToby Isaac   Options Database:
1788f2aacc6SMatthew G. Knepley + -petscspace_degree <deg> - the approximation order of the space
1798f2aacc6SMatthew G. Knepley . -petscspace_variables <n> - the number of different variables, e.g. x and y
1808f2aacc6SMatthew G. Knepley - -petscspace_components <c> - the number of components, say d for a vector field
18120cf1dd8SToby Isaac 
18229b5c115SMatthew G. Knepley   Level: intermediate
18320cf1dd8SToby Isaac 
18420cf1dd8SToby Isaac .seealso PetscSpaceView()
18520cf1dd8SToby Isaac @*/
18620cf1dd8SToby Isaac PetscErrorCode PetscSpaceSetFromOptions(PetscSpace sp)
18720cf1dd8SToby Isaac {
18820cf1dd8SToby Isaac   const char    *defaultType;
18920cf1dd8SToby Isaac   char           name[256];
1905a856986SBarry Smith   PetscBool      flg;
19120cf1dd8SToby Isaac 
19220cf1dd8SToby Isaac   PetscFunctionBegin;
19320cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
19420cf1dd8SToby Isaac   if (!((PetscObject) sp)->type_name) {
19520cf1dd8SToby Isaac     defaultType = PETSCSPACEPOLYNOMIAL;
19620cf1dd8SToby Isaac   } else {
19720cf1dd8SToby Isaac     defaultType = ((PetscObject) sp)->type_name;
19820cf1dd8SToby Isaac   }
1999566063dSJacob Faibussowitsch   if (!PetscSpaceRegisterAllCalled) PetscCall(PetscSpaceRegisterAll());
20020cf1dd8SToby Isaac 
201d0609cedSBarry Smith   PetscObjectOptionsBegin((PetscObject) sp);
2029566063dSJacob Faibussowitsch   PetscCall(PetscOptionsFList("-petscspace_type", "Linear space", "PetscSpaceSetType", PetscSpaceList, defaultType, name, 256, &flg));
20320cf1dd8SToby Isaac   if (flg) {
2049566063dSJacob Faibussowitsch     PetscCall(PetscSpaceSetType(sp, name));
20520cf1dd8SToby Isaac   } else if (!((PetscObject) sp)->type_name) {
2069566063dSJacob Faibussowitsch     PetscCall(PetscSpaceSetType(sp, defaultType));
20720cf1dd8SToby Isaac   }
2087be5e748SToby Isaac   {
2099566063dSJacob Faibussowitsch     PetscCall(PetscOptionsDeprecated("-petscspace_order","-petscspace_degree","3.11",NULL));
2109566063dSJacob Faibussowitsch     PetscCall(PetscOptionsBoundedInt("-petscspace_order", "DEPRECATED: The approximation order", "PetscSpaceSetDegree", sp->degree, &sp->degree, NULL,0));
2117be5e748SToby Isaac   }
2129566063dSJacob Faibussowitsch   PetscCall(PetscOptionsBoundedInt("-petscspace_degree", "The (maximally included) polynomial degree", "PetscSpaceSetDegree", sp->degree, &sp->degree, NULL,0));
2139566063dSJacob Faibussowitsch   PetscCall(PetscOptionsBoundedInt("-petscspace_variables", "The number of different variables, e.g. x and y", "PetscSpaceSetNumVariables", sp->Nv, &sp->Nv, NULL,0));
2149566063dSJacob Faibussowitsch   PetscCall(PetscOptionsBoundedInt("-petscspace_components", "The number of components", "PetscSpaceSetNumComponents", sp->Nc, &sp->Nc, NULL,0));
21520cf1dd8SToby Isaac   if (sp->ops->setfromoptions) {
2169566063dSJacob Faibussowitsch     PetscCall((*sp->ops->setfromoptions)(PetscOptionsObject,sp));
21720cf1dd8SToby Isaac   }
21820cf1dd8SToby Isaac   /* process any options handlers added with PetscObjectAddOptionsHandler() */
2199566063dSJacob Faibussowitsch   PetscCall(PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject) sp));
220d0609cedSBarry Smith   PetscOptionsEnd();
2219566063dSJacob Faibussowitsch   PetscCall(PetscSpaceViewFromOptions(sp, NULL, "-petscspace_view"));
22220cf1dd8SToby Isaac   PetscFunctionReturn(0);
22320cf1dd8SToby Isaac }
22420cf1dd8SToby Isaac 
22520cf1dd8SToby Isaac /*@C
22620cf1dd8SToby Isaac   PetscSpaceSetUp - Construct data structures for the PetscSpace
22720cf1dd8SToby Isaac 
228d083f849SBarry Smith   Collective on sp
22920cf1dd8SToby Isaac 
23020cf1dd8SToby Isaac   Input Parameter:
23120cf1dd8SToby Isaac . sp - the PetscSpace object to setup
23220cf1dd8SToby Isaac 
23329b5c115SMatthew G. Knepley   Level: intermediate
23420cf1dd8SToby Isaac 
23520cf1dd8SToby Isaac .seealso PetscSpaceView(), PetscSpaceDestroy()
23620cf1dd8SToby Isaac @*/
23720cf1dd8SToby Isaac PetscErrorCode PetscSpaceSetUp(PetscSpace sp)
23820cf1dd8SToby Isaac {
23920cf1dd8SToby Isaac   PetscFunctionBegin;
24020cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
2419566063dSJacob Faibussowitsch   if (sp->ops->setup) PetscCall((*sp->ops->setup)(sp));
24220cf1dd8SToby Isaac   PetscFunctionReturn(0);
24320cf1dd8SToby Isaac }
24420cf1dd8SToby Isaac 
24520cf1dd8SToby Isaac /*@
24620cf1dd8SToby Isaac   PetscSpaceDestroy - Destroys a PetscSpace object
24720cf1dd8SToby Isaac 
248d083f849SBarry Smith   Collective on sp
24920cf1dd8SToby Isaac 
25020cf1dd8SToby Isaac   Input Parameter:
25120cf1dd8SToby Isaac . sp - the PetscSpace object to destroy
25220cf1dd8SToby Isaac 
25329b5c115SMatthew G. Knepley   Level: beginner
25420cf1dd8SToby Isaac 
25520cf1dd8SToby Isaac .seealso PetscSpaceView()
25620cf1dd8SToby Isaac @*/
25720cf1dd8SToby Isaac PetscErrorCode PetscSpaceDestroy(PetscSpace *sp)
25820cf1dd8SToby Isaac {
25920cf1dd8SToby Isaac   PetscFunctionBegin;
26020cf1dd8SToby Isaac   if (!*sp) PetscFunctionReturn(0);
26120cf1dd8SToby Isaac   PetscValidHeaderSpecific((*sp), PETSCSPACE_CLASSID, 1);
26220cf1dd8SToby Isaac 
263ea78f98cSLisandro Dalcin   if (--((PetscObject)(*sp))->refct > 0) {*sp = NULL; PetscFunctionReturn(0);}
26420cf1dd8SToby Isaac   ((PetscObject) (*sp))->refct = 0;
2659566063dSJacob Faibussowitsch   PetscCall(DMDestroy(&(*sp)->dm));
26620cf1dd8SToby Isaac 
2679566063dSJacob Faibussowitsch   PetscCall((*(*sp)->ops->destroy)(*sp));
2689566063dSJacob Faibussowitsch   PetscCall(PetscHeaderDestroy(sp));
26920cf1dd8SToby Isaac   PetscFunctionReturn(0);
27020cf1dd8SToby Isaac }
27120cf1dd8SToby Isaac 
27220cf1dd8SToby Isaac /*@
27320cf1dd8SToby Isaac   PetscSpaceCreate - Creates an empty PetscSpace object. The type can then be set with PetscSpaceSetType().
27420cf1dd8SToby Isaac 
275d083f849SBarry Smith   Collective
27620cf1dd8SToby Isaac 
27720cf1dd8SToby Isaac   Input Parameter:
27820cf1dd8SToby Isaac . comm - The communicator for the PetscSpace object
27920cf1dd8SToby Isaac 
28020cf1dd8SToby Isaac   Output Parameter:
28120cf1dd8SToby Isaac . sp - The PetscSpace object
28220cf1dd8SToby Isaac 
28320cf1dd8SToby Isaac   Level: beginner
28420cf1dd8SToby Isaac 
28520cf1dd8SToby Isaac .seealso: PetscSpaceSetType(), PETSCSPACEPOLYNOMIAL
28620cf1dd8SToby Isaac @*/
28720cf1dd8SToby Isaac PetscErrorCode PetscSpaceCreate(MPI_Comm comm, PetscSpace *sp)
28820cf1dd8SToby Isaac {
28920cf1dd8SToby Isaac   PetscSpace     s;
29020cf1dd8SToby Isaac 
29120cf1dd8SToby Isaac   PetscFunctionBegin;
29220cf1dd8SToby Isaac   PetscValidPointer(sp, 2);
2939566063dSJacob Faibussowitsch   PetscCall(PetscCitationsRegister(FECitation,&FEcite));
29420cf1dd8SToby Isaac   *sp  = NULL;
2959566063dSJacob Faibussowitsch   PetscCall(PetscFEInitializePackage());
29620cf1dd8SToby Isaac 
2979566063dSJacob Faibussowitsch   PetscCall(PetscHeaderCreate(s, PETSCSPACE_CLASSID, "PetscSpace", "Linear Space", "PetscSpace", comm, PetscSpaceDestroy, PetscSpaceView));
29820cf1dd8SToby Isaac 
29920cf1dd8SToby Isaac   s->degree    = 0;
30043bfef1cSToby Isaac   s->maxDegree = PETSC_DETERMINE;
30120cf1dd8SToby Isaac   s->Nc        = 1;
30220cf1dd8SToby Isaac   s->Nv        = 0;
30343bfef1cSToby Isaac   s->dim       = PETSC_DETERMINE;
3049566063dSJacob Faibussowitsch   PetscCall(DMShellCreate(comm, &s->dm));
3059566063dSJacob Faibussowitsch   PetscCall(PetscSpaceSetType(s, PETSCSPACEPOLYNOMIAL));
30620cf1dd8SToby Isaac 
30720cf1dd8SToby Isaac   *sp = s;
30820cf1dd8SToby Isaac   PetscFunctionReturn(0);
30920cf1dd8SToby Isaac }
31020cf1dd8SToby Isaac 
31120cf1dd8SToby Isaac /*@
31220cf1dd8SToby Isaac   PetscSpaceGetDimension - Return the dimension of this space, i.e. the number of basis vectors
31320cf1dd8SToby Isaac 
31420cf1dd8SToby Isaac   Input Parameter:
31520cf1dd8SToby Isaac . sp - The PetscSpace
31620cf1dd8SToby Isaac 
31720cf1dd8SToby Isaac   Output Parameter:
31820cf1dd8SToby Isaac . dim - The dimension
31920cf1dd8SToby Isaac 
32020cf1dd8SToby Isaac   Level: intermediate
32120cf1dd8SToby Isaac 
32220cf1dd8SToby Isaac .seealso: PetscSpaceGetDegree(), PetscSpaceCreate(), PetscSpace
32320cf1dd8SToby Isaac @*/
32420cf1dd8SToby Isaac PetscErrorCode PetscSpaceGetDimension(PetscSpace sp, PetscInt *dim)
32520cf1dd8SToby Isaac {
32620cf1dd8SToby Isaac   PetscFunctionBegin;
32720cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
328dadcf809SJacob Faibussowitsch   PetscValidIntPointer(dim, 2);
32943bfef1cSToby Isaac   if (sp->dim == PETSC_DETERMINE) {
3309566063dSJacob Faibussowitsch     if (sp->ops->getdimension) PetscCall((*sp->ops->getdimension)(sp, &sp->dim));
33143bfef1cSToby Isaac   }
33243bfef1cSToby Isaac   *dim = sp->dim;
33320cf1dd8SToby Isaac   PetscFunctionReturn(0);
33420cf1dd8SToby Isaac }
33520cf1dd8SToby Isaac 
33620cf1dd8SToby Isaac /*@
33720cf1dd8SToby Isaac   PetscSpaceGetDegree - Return the polynomial degrees that characterize this space
33820cf1dd8SToby Isaac 
33920cf1dd8SToby Isaac   Input Parameter:
34020cf1dd8SToby Isaac . sp - The PetscSpace
34120cf1dd8SToby Isaac 
342d8d19677SJose E. Roman   Output Parameters:
34320cf1dd8SToby Isaac + minDegree - The degree of the largest polynomial space contained in the space
34420cf1dd8SToby Isaac - maxDegree - The degree of the smallest polynomial space containing the space
34520cf1dd8SToby Isaac 
34620cf1dd8SToby Isaac   Level: intermediate
34720cf1dd8SToby Isaac 
34820cf1dd8SToby Isaac .seealso: PetscSpaceSetDegree(), PetscSpaceGetDimension(), PetscSpaceCreate(), PetscSpace
34920cf1dd8SToby Isaac @*/
35020cf1dd8SToby Isaac PetscErrorCode PetscSpaceGetDegree(PetscSpace sp, PetscInt *minDegree, PetscInt *maxDegree)
35120cf1dd8SToby Isaac {
35220cf1dd8SToby Isaac   PetscFunctionBegin;
35320cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
354dadcf809SJacob Faibussowitsch   if (minDegree) PetscValidIntPointer(minDegree, 2);
355dadcf809SJacob Faibussowitsch   if (maxDegree) PetscValidIntPointer(maxDegree, 3);
35620cf1dd8SToby Isaac   if (minDegree) *minDegree = sp->degree;
357f5a02b64SToby Isaac   if (maxDegree) *maxDegree = sp->maxDegree;
35820cf1dd8SToby Isaac   PetscFunctionReturn(0);
35920cf1dd8SToby Isaac }
36020cf1dd8SToby Isaac 
36120cf1dd8SToby Isaac /*@
36220cf1dd8SToby Isaac   PetscSpaceSetDegree - Set the degree of approximation for this space.
36320cf1dd8SToby Isaac 
36420cf1dd8SToby Isaac   Input Parameters:
36520cf1dd8SToby Isaac + sp - The PetscSpace
366d39dd5f5SToby Isaac . degree - The degree of the largest polynomial space contained in the space
367d39dd5f5SToby Isaac - maxDegree - The degree of the largest polynomial space containing the space.  One of degree and maxDegree can be PETSC_DETERMINE.
36820cf1dd8SToby Isaac 
36920cf1dd8SToby Isaac   Level: intermediate
37020cf1dd8SToby Isaac 
37120cf1dd8SToby Isaac .seealso: PetscSpaceGetDegree(), PetscSpaceCreate(), PetscSpace
37220cf1dd8SToby Isaac @*/
373d39dd5f5SToby Isaac PetscErrorCode PetscSpaceSetDegree(PetscSpace sp, PetscInt degree, PetscInt maxDegree)
37420cf1dd8SToby Isaac {
37520cf1dd8SToby Isaac   PetscFunctionBegin;
37620cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
377d39dd5f5SToby Isaac   sp->degree = degree;
378d39dd5f5SToby Isaac   sp->maxDegree = maxDegree;
37920cf1dd8SToby Isaac   PetscFunctionReturn(0);
38020cf1dd8SToby Isaac }
38120cf1dd8SToby Isaac 
38220cf1dd8SToby Isaac /*@
38320cf1dd8SToby Isaac   PetscSpaceGetNumComponents - Return the number of components for this space
38420cf1dd8SToby Isaac 
38520cf1dd8SToby Isaac   Input Parameter:
38620cf1dd8SToby Isaac . sp - The PetscSpace
38720cf1dd8SToby Isaac 
38820cf1dd8SToby Isaac   Output Parameter:
38920cf1dd8SToby Isaac . Nc - The number of components
39020cf1dd8SToby Isaac 
39120cf1dd8SToby Isaac   Note: A vector space, for example, will have d components, where d is the spatial dimension
39220cf1dd8SToby Isaac 
39320cf1dd8SToby Isaac   Level: intermediate
39420cf1dd8SToby Isaac 
39529b5c115SMatthew G. Knepley .seealso: PetscSpaceSetNumComponents(), PetscSpaceGetNumVariables(), PetscSpaceGetDimension(), PetscSpaceCreate(), PetscSpace
39620cf1dd8SToby Isaac @*/
39720cf1dd8SToby Isaac PetscErrorCode PetscSpaceGetNumComponents(PetscSpace sp, PetscInt *Nc)
39820cf1dd8SToby Isaac {
39920cf1dd8SToby Isaac   PetscFunctionBegin;
40020cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
401dadcf809SJacob Faibussowitsch   PetscValidIntPointer(Nc, 2);
40220cf1dd8SToby Isaac   *Nc = sp->Nc;
40320cf1dd8SToby Isaac   PetscFunctionReturn(0);
40420cf1dd8SToby Isaac }
40520cf1dd8SToby Isaac 
40620cf1dd8SToby Isaac /*@
40720cf1dd8SToby Isaac   PetscSpaceSetNumComponents - Set the number of components for this space
40820cf1dd8SToby Isaac 
40920cf1dd8SToby Isaac   Input Parameters:
41020cf1dd8SToby Isaac + sp - The PetscSpace
41120cf1dd8SToby Isaac - order - The number of components
41220cf1dd8SToby Isaac 
41320cf1dd8SToby Isaac   Level: intermediate
41420cf1dd8SToby Isaac 
41529b5c115SMatthew G. Knepley .seealso: PetscSpaceGetNumComponents(), PetscSpaceSetNumVariables(), PetscSpaceCreate(), PetscSpace
41620cf1dd8SToby Isaac @*/
41720cf1dd8SToby Isaac PetscErrorCode PetscSpaceSetNumComponents(PetscSpace sp, PetscInt Nc)
41820cf1dd8SToby Isaac {
41920cf1dd8SToby Isaac   PetscFunctionBegin;
42020cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
42120cf1dd8SToby Isaac   sp->Nc = Nc;
42220cf1dd8SToby Isaac   PetscFunctionReturn(0);
42320cf1dd8SToby Isaac }
42420cf1dd8SToby Isaac 
42529b5c115SMatthew G. Knepley /*@
42629b5c115SMatthew G. Knepley   PetscSpaceSetNumVariables - Set the number of variables for this space
42729b5c115SMatthew G. Knepley 
42829b5c115SMatthew G. Knepley   Input Parameters:
42929b5c115SMatthew G. Knepley + sp - The PetscSpace
43029b5c115SMatthew G. Knepley - n - The number of variables, e.g. x, y, z...
43129b5c115SMatthew G. Knepley 
43229b5c115SMatthew G. Knepley   Level: intermediate
43329b5c115SMatthew G. Knepley 
43429b5c115SMatthew G. Knepley .seealso: PetscSpaceGetNumVariables(), PetscSpaceSetNumComponents(), PetscSpaceCreate(), PetscSpace
43529b5c115SMatthew G. Knepley @*/
43620cf1dd8SToby Isaac PetscErrorCode PetscSpaceSetNumVariables(PetscSpace sp, PetscInt n)
43720cf1dd8SToby Isaac {
43820cf1dd8SToby Isaac   PetscFunctionBegin;
43920cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
44020cf1dd8SToby Isaac   sp->Nv = n;
44120cf1dd8SToby Isaac   PetscFunctionReturn(0);
44220cf1dd8SToby Isaac }
44320cf1dd8SToby Isaac 
44429b5c115SMatthew G. Knepley /*@
44529b5c115SMatthew G. Knepley   PetscSpaceGetNumVariables - Return the number of variables for this space
44629b5c115SMatthew G. Knepley 
44729b5c115SMatthew G. Knepley   Input Parameter:
44829b5c115SMatthew G. Knepley . sp - The PetscSpace
44929b5c115SMatthew G. Knepley 
45029b5c115SMatthew G. Knepley   Output Parameter:
45129b5c115SMatthew G. Knepley . Nc - The number of variables, e.g. x, y, z...
45229b5c115SMatthew G. Knepley 
45329b5c115SMatthew G. Knepley   Level: intermediate
45429b5c115SMatthew G. Knepley 
45529b5c115SMatthew G. Knepley .seealso: PetscSpaceSetNumVariables(), PetscSpaceGetNumComponents(), PetscSpaceGetDimension(), PetscSpaceCreate(), PetscSpace
45629b5c115SMatthew G. Knepley @*/
45720cf1dd8SToby Isaac PetscErrorCode PetscSpaceGetNumVariables(PetscSpace sp, PetscInt *n)
45820cf1dd8SToby Isaac {
45920cf1dd8SToby Isaac   PetscFunctionBegin;
46020cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
461dadcf809SJacob Faibussowitsch   PetscValidIntPointer(n, 2);
46220cf1dd8SToby Isaac   *n = sp->Nv;
46320cf1dd8SToby Isaac   PetscFunctionReturn(0);
46420cf1dd8SToby Isaac }
46520cf1dd8SToby Isaac 
46620cf1dd8SToby Isaac /*@C
46720cf1dd8SToby Isaac   PetscSpaceEvaluate - Evaluate the basis functions and their derivatives (jet) at each point
46820cf1dd8SToby Isaac 
46920cf1dd8SToby Isaac   Input Parameters:
47020cf1dd8SToby Isaac + sp      - The PetscSpace
47120cf1dd8SToby Isaac . npoints - The number of evaluation points, in reference coordinates
47220cf1dd8SToby Isaac - points  - The point coordinates
47320cf1dd8SToby Isaac 
47420cf1dd8SToby Isaac   Output Parameters:
47520cf1dd8SToby Isaac + B - The function evaluations in a npoints x nfuncs array
47620cf1dd8SToby Isaac . D - The derivative evaluations in a npoints x nfuncs x dim array
47720cf1dd8SToby Isaac - H - The second derivative evaluations in a npoints x nfuncs x dim x dim array
47820cf1dd8SToby Isaac 
47920cf1dd8SToby Isaac   Note: Above nfuncs is the dimension of the space, and dim is the spatial dimension. The coordinates are given
48020cf1dd8SToby Isaac   on the reference cell, not in real space.
48120cf1dd8SToby Isaac 
48229b5c115SMatthew G. Knepley   Level: beginner
48320cf1dd8SToby Isaac 
484ef0bb6c7SMatthew G. Knepley .seealso: PetscFECreateTabulation(), PetscFEGetCellTabulation(), PetscSpaceCreate()
48520cf1dd8SToby Isaac @*/
48620cf1dd8SToby Isaac PetscErrorCode PetscSpaceEvaluate(PetscSpace sp, PetscInt npoints, const PetscReal points[], PetscReal B[], PetscReal D[], PetscReal H[])
48720cf1dd8SToby Isaac {
48820cf1dd8SToby Isaac   PetscFunctionBegin;
48920cf1dd8SToby Isaac   if (!npoints) PetscFunctionReturn(0);
49020cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
491dadcf809SJacob Faibussowitsch   if (sp->Nv) PetscValidRealPointer(points, 3);
492dadcf809SJacob Faibussowitsch   if (B) PetscValidRealPointer(B, 4);
493dadcf809SJacob Faibussowitsch   if (D) PetscValidRealPointer(D, 5);
494dadcf809SJacob Faibussowitsch   if (H) PetscValidRealPointer(H, 6);
4959566063dSJacob Faibussowitsch   if (sp->ops->evaluate) PetscCall((*sp->ops->evaluate)(sp, npoints, points, B, D, H));
49620cf1dd8SToby Isaac   PetscFunctionReturn(0);
49720cf1dd8SToby Isaac }
49820cf1dd8SToby Isaac 
49920cf1dd8SToby Isaac /*@
50020cf1dd8SToby Isaac   PetscSpaceGetHeightSubspace - Get the subset of the primal space basis that is supported on a mesh point of a given height.
50120cf1dd8SToby Isaac 
50220cf1dd8SToby Isaac   If the space is not defined on mesh points of the given height (e.g. if the space is discontinuous and
50320cf1dd8SToby Isaac   pointwise values are not defined on the element boundaries), or if the implementation of PetscSpace does not
50420cf1dd8SToby Isaac   support extracting subspaces, then NULL is returned.
50520cf1dd8SToby Isaac 
50620cf1dd8SToby Isaac   This does not increment the reference count on the returned space, and the user should not destroy it.
50720cf1dd8SToby Isaac 
50820cf1dd8SToby Isaac   Not collective
50920cf1dd8SToby Isaac 
51020cf1dd8SToby Isaac   Input Parameters:
51120cf1dd8SToby Isaac + sp - the PetscSpace object
51220cf1dd8SToby Isaac - height - the height of the mesh point for which the subspace is desired
51320cf1dd8SToby Isaac 
51420cf1dd8SToby Isaac   Output Parameter:
51520cf1dd8SToby Isaac . subsp - the subspace
51620cf1dd8SToby Isaac 
51720cf1dd8SToby Isaac   Level: advanced
51820cf1dd8SToby Isaac 
51920cf1dd8SToby Isaac .seealso: PetscDualSpaceGetHeightSubspace(), PetscSpace
52020cf1dd8SToby Isaac @*/
52120cf1dd8SToby Isaac PetscErrorCode PetscSpaceGetHeightSubspace(PetscSpace sp, PetscInt height, PetscSpace *subsp)
52220cf1dd8SToby Isaac {
52320cf1dd8SToby Isaac   PetscFunctionBegin;
52420cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
52520cf1dd8SToby Isaac   PetscValidPointer(subsp, 3);
52620cf1dd8SToby Isaac   *subsp = NULL;
52720cf1dd8SToby Isaac   if (sp->ops->getheightsubspace) {
5289566063dSJacob Faibussowitsch     PetscCall((*sp->ops->getheightsubspace)(sp, height, subsp));
52920cf1dd8SToby Isaac   }
53020cf1dd8SToby Isaac   PetscFunctionReturn(0);
53120cf1dd8SToby Isaac }
532