xref: /petsc/src/dm/dt/space/interface/space.c (revision d8d19677bbccf95218448bee62e6b87f4513e133)
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   PetscErrorCode ierr;
4520cf1dd8SToby Isaac 
4620cf1dd8SToby Isaac   PetscFunctionBegin;
4720cf1dd8SToby Isaac   ierr = PetscFunctionListAdd(&PetscSpaceList, sname, function);CHKERRQ(ierr);
4820cf1dd8SToby Isaac   PetscFunctionReturn(0);
4920cf1dd8SToby Isaac }
5020cf1dd8SToby Isaac 
5120cf1dd8SToby Isaac /*@C
5220cf1dd8SToby Isaac   PetscSpaceSetType - Builds a particular PetscSpace
5320cf1dd8SToby Isaac 
54d083f849SBarry Smith   Collective on sp
5520cf1dd8SToby Isaac 
5620cf1dd8SToby Isaac   Input Parameters:
5720cf1dd8SToby Isaac + sp   - The PetscSpace object
5820cf1dd8SToby Isaac - name - The kind of space
5920cf1dd8SToby Isaac 
6020cf1dd8SToby Isaac   Options Database Key:
6120cf1dd8SToby Isaac . -petscspace_type <type> - Sets the PetscSpace type; use -help for a list of available types
6220cf1dd8SToby Isaac 
6320cf1dd8SToby Isaac   Level: intermediate
6420cf1dd8SToby Isaac 
6520cf1dd8SToby Isaac .seealso: PetscSpaceGetType(), PetscSpaceCreate()
6620cf1dd8SToby Isaac @*/
6720cf1dd8SToby Isaac PetscErrorCode PetscSpaceSetType(PetscSpace sp, PetscSpaceType name)
6820cf1dd8SToby Isaac {
6920cf1dd8SToby Isaac   PetscErrorCode (*r)(PetscSpace);
7020cf1dd8SToby Isaac   PetscBool      match;
7120cf1dd8SToby Isaac   PetscErrorCode ierr;
7220cf1dd8SToby Isaac 
7320cf1dd8SToby Isaac   PetscFunctionBegin;
7420cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
7520cf1dd8SToby Isaac   ierr = PetscObjectTypeCompare((PetscObject) sp, name, &match);CHKERRQ(ierr);
7620cf1dd8SToby Isaac   if (match) PetscFunctionReturn(0);
7720cf1dd8SToby Isaac 
7820cf1dd8SToby Isaac   ierr = PetscSpaceRegisterAll();CHKERRQ(ierr);
7920cf1dd8SToby Isaac   ierr = PetscFunctionListFind(PetscSpaceList, name, &r);CHKERRQ(ierr);
8020cf1dd8SToby Isaac   if (!r) SETERRQ1(PetscObjectComm((PetscObject) sp), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscSpace type: %s", name);
8120cf1dd8SToby Isaac 
8220cf1dd8SToby Isaac   if (sp->ops->destroy) {
8320cf1dd8SToby Isaac     ierr             = (*sp->ops->destroy)(sp);CHKERRQ(ierr);
8420cf1dd8SToby Isaac     sp->ops->destroy = NULL;
8520cf1dd8SToby Isaac   }
8643bfef1cSToby Isaac   sp->dim = PETSC_DETERMINE;
8720cf1dd8SToby Isaac   ierr = (*r)(sp);CHKERRQ(ierr);
8820cf1dd8SToby Isaac   ierr = PetscObjectChangeTypeName((PetscObject) sp, name);CHKERRQ(ierr);
8920cf1dd8SToby Isaac   PetscFunctionReturn(0);
9020cf1dd8SToby Isaac }
9120cf1dd8SToby Isaac 
9220cf1dd8SToby Isaac /*@C
9320cf1dd8SToby Isaac   PetscSpaceGetType - Gets the PetscSpace type name (as a string) from the object.
9420cf1dd8SToby Isaac 
9520cf1dd8SToby Isaac   Not Collective
9620cf1dd8SToby Isaac 
9720cf1dd8SToby Isaac   Input Parameter:
9820cf1dd8SToby Isaac . sp  - The PetscSpace
9920cf1dd8SToby Isaac 
10020cf1dd8SToby Isaac   Output Parameter:
10120cf1dd8SToby Isaac . name - The PetscSpace type name
10220cf1dd8SToby Isaac 
10320cf1dd8SToby Isaac   Level: intermediate
10420cf1dd8SToby Isaac 
10520cf1dd8SToby Isaac .seealso: PetscSpaceSetType(), PetscSpaceCreate()
10620cf1dd8SToby Isaac @*/
10720cf1dd8SToby Isaac PetscErrorCode PetscSpaceGetType(PetscSpace sp, PetscSpaceType *name)
10820cf1dd8SToby Isaac {
10920cf1dd8SToby Isaac   PetscErrorCode ierr;
11020cf1dd8SToby Isaac 
11120cf1dd8SToby Isaac   PetscFunctionBegin;
11220cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
11320cf1dd8SToby Isaac   PetscValidPointer(name, 2);
11420cf1dd8SToby Isaac   if (!PetscSpaceRegisterAllCalled) {
11520cf1dd8SToby Isaac     ierr = PetscSpaceRegisterAll();CHKERRQ(ierr);
11620cf1dd8SToby Isaac   }
11720cf1dd8SToby Isaac   *name = ((PetscObject) sp)->type_name;
11820cf1dd8SToby Isaac   PetscFunctionReturn(0);
11920cf1dd8SToby Isaac }
12020cf1dd8SToby Isaac 
12120cf1dd8SToby Isaac /*@C
122fe2efc57SMark    PetscSpaceViewFromOptions - View from Options
123fe2efc57SMark 
124fe2efc57SMark    Collective on PetscSpace
125fe2efc57SMark 
126fe2efc57SMark    Input Parameters:
127fe2efc57SMark +  A - the PetscSpace object
128736c3998SJose E. Roman .  obj - Optional object
129736c3998SJose E. Roman -  name - command line option
130fe2efc57SMark 
131fe2efc57SMark    Level: intermediate
132fe2efc57SMark .seealso:  PetscSpace, PetscSpaceView, PetscObjectViewFromOptions(), PetscSpaceCreate()
133fe2efc57SMark @*/
134fe2efc57SMark PetscErrorCode  PetscSpaceViewFromOptions(PetscSpace A,PetscObject obj,const char name[])
135fe2efc57SMark {
136fe2efc57SMark   PetscErrorCode ierr;
137fe2efc57SMark 
138fe2efc57SMark   PetscFunctionBegin;
139fe2efc57SMark   PetscValidHeaderSpecific(A,PETSCSPACE_CLASSID,1);
140fe2efc57SMark   ierr = PetscObjectViewFromOptions((PetscObject)A,obj,name);CHKERRQ(ierr);
141fe2efc57SMark   PetscFunctionReturn(0);
142fe2efc57SMark }
143fe2efc57SMark 
144fe2efc57SMark /*@C
14520cf1dd8SToby Isaac   PetscSpaceView - Views a PetscSpace
14620cf1dd8SToby Isaac 
147d083f849SBarry Smith   Collective on sp
14820cf1dd8SToby Isaac 
149*d8d19677SJose E. Roman   Input Parameters:
15020cf1dd8SToby Isaac + sp - the PetscSpace object to view
15120cf1dd8SToby Isaac - v  - the viewer
15220cf1dd8SToby Isaac 
15329b5c115SMatthew G. Knepley   Level: beginner
15420cf1dd8SToby Isaac 
15520cf1dd8SToby Isaac .seealso PetscSpaceDestroy()
15620cf1dd8SToby Isaac @*/
15720cf1dd8SToby Isaac PetscErrorCode PetscSpaceView(PetscSpace sp, PetscViewer v)
15820cf1dd8SToby Isaac {
1590aec8e07SMatthew G. Knepley   PetscInt       pdim;
16020cf1dd8SToby Isaac   PetscBool      iascii;
16120cf1dd8SToby Isaac   PetscErrorCode ierr;
16220cf1dd8SToby Isaac 
16320cf1dd8SToby Isaac   PetscFunctionBegin;
16420cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
16520cf1dd8SToby Isaac   if (v) PetscValidHeaderSpecific(v, PETSC_VIEWER_CLASSID, 2);
16620cf1dd8SToby Isaac   if (!v) {ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject) sp), &v);CHKERRQ(ierr);}
1670aec8e07SMatthew G. Knepley   ierr = PetscSpaceGetDimension(sp, &pdim);CHKERRQ(ierr);
16820cf1dd8SToby Isaac   ierr = PetscObjectPrintClassNamePrefixType((PetscObject)sp,v);CHKERRQ(ierr);
169d9bac1caSLisandro Dalcin   ierr = PetscObjectTypeCompare((PetscObject) v, PETSCVIEWERASCII, &iascii);CHKERRQ(ierr);
17020cf1dd8SToby Isaac   ierr = PetscViewerASCIIPushTab(v);CHKERRQ(ierr);
1710aec8e07SMatthew G. Knepley   if (iascii) {ierr = PetscViewerASCIIPrintf(v, "Space in %D variables with %D components, size %D\n", sp->Nv, sp->Nc, pdim);CHKERRQ(ierr);}
17220cf1dd8SToby Isaac   if (sp->ops->view) {ierr = (*sp->ops->view)(sp, v);CHKERRQ(ierr);}
17320cf1dd8SToby Isaac   ierr = PetscViewerASCIIPopTab(v);CHKERRQ(ierr);
17420cf1dd8SToby Isaac   PetscFunctionReturn(0);
17520cf1dd8SToby Isaac }
17620cf1dd8SToby Isaac 
17720cf1dd8SToby Isaac /*@
17820cf1dd8SToby Isaac   PetscSpaceSetFromOptions - sets parameters in a PetscSpace from the options database
17920cf1dd8SToby Isaac 
180d083f849SBarry Smith   Collective on sp
18120cf1dd8SToby Isaac 
18220cf1dd8SToby Isaac   Input Parameter:
18320cf1dd8SToby Isaac . sp - the PetscSpace object to set options for
18420cf1dd8SToby Isaac 
18520cf1dd8SToby Isaac   Options Database:
1868f2aacc6SMatthew G. Knepley + -petscspace_degree <deg> - the approximation order of the space
1878f2aacc6SMatthew G. Knepley . -petscspace_variables <n> - the number of different variables, e.g. x and y
1888f2aacc6SMatthew G. Knepley - -petscspace_components <c> - the number of components, say d for a vector field
18920cf1dd8SToby Isaac 
19029b5c115SMatthew G. Knepley   Level: intermediate
19120cf1dd8SToby Isaac 
19220cf1dd8SToby Isaac .seealso PetscSpaceView()
19320cf1dd8SToby Isaac @*/
19420cf1dd8SToby Isaac PetscErrorCode PetscSpaceSetFromOptions(PetscSpace sp)
19520cf1dd8SToby Isaac {
19620cf1dd8SToby Isaac   const char    *defaultType;
19720cf1dd8SToby Isaac   char           name[256];
1985a856986SBarry Smith   PetscBool      flg;
19920cf1dd8SToby Isaac   PetscErrorCode ierr;
20020cf1dd8SToby Isaac 
20120cf1dd8SToby Isaac   PetscFunctionBegin;
20220cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
20320cf1dd8SToby Isaac   if (!((PetscObject) sp)->type_name) {
20420cf1dd8SToby Isaac     defaultType = PETSCSPACEPOLYNOMIAL;
20520cf1dd8SToby Isaac   } else {
20620cf1dd8SToby Isaac     defaultType = ((PetscObject) sp)->type_name;
20720cf1dd8SToby Isaac   }
20820cf1dd8SToby Isaac   if (!PetscSpaceRegisterAllCalled) {ierr = PetscSpaceRegisterAll();CHKERRQ(ierr);}
20920cf1dd8SToby Isaac 
21020cf1dd8SToby Isaac   ierr = PetscObjectOptionsBegin((PetscObject) sp);CHKERRQ(ierr);
21120cf1dd8SToby Isaac   ierr = PetscOptionsFList("-petscspace_type", "Linear space", "PetscSpaceSetType", PetscSpaceList, defaultType, name, 256, &flg);CHKERRQ(ierr);
21220cf1dd8SToby Isaac   if (flg) {
21320cf1dd8SToby Isaac     ierr = PetscSpaceSetType(sp, name);CHKERRQ(ierr);
21420cf1dd8SToby Isaac   } else if (!((PetscObject) sp)->type_name) {
21520cf1dd8SToby Isaac     ierr = PetscSpaceSetType(sp, defaultType);CHKERRQ(ierr);
21620cf1dd8SToby Isaac   }
2177be5e748SToby Isaac   {
2185a856986SBarry Smith     ierr = PetscOptionsDeprecated("-petscspace_order","-petscspace_degree","3.11",NULL);CHKERRQ(ierr);
2195a856986SBarry Smith     ierr = PetscOptionsBoundedInt("-petscspace_order", "DEPRECATED: The approximation order", "PetscSpaceSetDegree", sp->degree, &sp->degree, NULL,0);CHKERRQ(ierr);
2207be5e748SToby Isaac   }
2215a856986SBarry Smith   ierr = PetscOptionsBoundedInt("-petscspace_degree", "The (maximally included) polynomial degree", "PetscSpaceSetDegree", sp->degree, &sp->degree, NULL,0);CHKERRQ(ierr);
2225a856986SBarry Smith   ierr = PetscOptionsBoundedInt("-petscspace_variables", "The number of different variables, e.g. x and y", "PetscSpaceSetNumVariables", sp->Nv, &sp->Nv, NULL,0);CHKERRQ(ierr);
2235a856986SBarry Smith   ierr = PetscOptionsBoundedInt("-petscspace_components", "The number of components", "PetscSpaceSetNumComponents", sp->Nc, &sp->Nc, NULL,0);CHKERRQ(ierr);
22420cf1dd8SToby Isaac   if (sp->ops->setfromoptions) {
22520cf1dd8SToby Isaac     ierr = (*sp->ops->setfromoptions)(PetscOptionsObject,sp);CHKERRQ(ierr);
22620cf1dd8SToby Isaac   }
22720cf1dd8SToby Isaac   /* process any options handlers added with PetscObjectAddOptionsHandler() */
22820cf1dd8SToby Isaac   ierr = PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject) sp);CHKERRQ(ierr);
22920cf1dd8SToby Isaac   ierr = PetscOptionsEnd();CHKERRQ(ierr);
23020cf1dd8SToby Isaac   ierr = PetscSpaceViewFromOptions(sp, NULL, "-petscspace_view");CHKERRQ(ierr);
23120cf1dd8SToby Isaac   PetscFunctionReturn(0);
23220cf1dd8SToby Isaac }
23320cf1dd8SToby Isaac 
23420cf1dd8SToby Isaac /*@C
23520cf1dd8SToby Isaac   PetscSpaceSetUp - Construct data structures for the PetscSpace
23620cf1dd8SToby Isaac 
237d083f849SBarry Smith   Collective on sp
23820cf1dd8SToby Isaac 
23920cf1dd8SToby Isaac   Input Parameter:
24020cf1dd8SToby Isaac . sp - the PetscSpace object to setup
24120cf1dd8SToby Isaac 
24229b5c115SMatthew G. Knepley   Level: intermediate
24320cf1dd8SToby Isaac 
24420cf1dd8SToby Isaac .seealso PetscSpaceView(), PetscSpaceDestroy()
24520cf1dd8SToby Isaac @*/
24620cf1dd8SToby Isaac PetscErrorCode PetscSpaceSetUp(PetscSpace sp)
24720cf1dd8SToby Isaac {
24820cf1dd8SToby Isaac   PetscErrorCode ierr;
24920cf1dd8SToby Isaac 
25020cf1dd8SToby Isaac   PetscFunctionBegin;
25120cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
25220cf1dd8SToby Isaac   if (sp->ops->setup) {ierr = (*sp->ops->setup)(sp);CHKERRQ(ierr);}
25320cf1dd8SToby Isaac   PetscFunctionReturn(0);
25420cf1dd8SToby Isaac }
25520cf1dd8SToby Isaac 
25620cf1dd8SToby Isaac /*@
25720cf1dd8SToby Isaac   PetscSpaceDestroy - Destroys a PetscSpace object
25820cf1dd8SToby Isaac 
259d083f849SBarry Smith   Collective on sp
26020cf1dd8SToby Isaac 
26120cf1dd8SToby Isaac   Input Parameter:
26220cf1dd8SToby Isaac . sp - the PetscSpace object to destroy
26320cf1dd8SToby Isaac 
26429b5c115SMatthew G. Knepley   Level: beginner
26520cf1dd8SToby Isaac 
26620cf1dd8SToby Isaac .seealso PetscSpaceView()
26720cf1dd8SToby Isaac @*/
26820cf1dd8SToby Isaac PetscErrorCode PetscSpaceDestroy(PetscSpace *sp)
26920cf1dd8SToby Isaac {
27020cf1dd8SToby Isaac   PetscErrorCode ierr;
27120cf1dd8SToby Isaac 
27220cf1dd8SToby Isaac   PetscFunctionBegin;
27320cf1dd8SToby Isaac   if (!*sp) PetscFunctionReturn(0);
27420cf1dd8SToby Isaac   PetscValidHeaderSpecific((*sp), PETSCSPACE_CLASSID, 1);
27520cf1dd8SToby Isaac 
276ea78f98cSLisandro Dalcin   if (--((PetscObject)(*sp))->refct > 0) {*sp = NULL; PetscFunctionReturn(0);}
27720cf1dd8SToby Isaac   ((PetscObject) (*sp))->refct = 0;
27820cf1dd8SToby Isaac   ierr = DMDestroy(&(*sp)->dm);CHKERRQ(ierr);
27920cf1dd8SToby Isaac 
28020cf1dd8SToby Isaac   ierr = (*(*sp)->ops->destroy)(*sp);CHKERRQ(ierr);
28120cf1dd8SToby Isaac   ierr = PetscHeaderDestroy(sp);CHKERRQ(ierr);
28220cf1dd8SToby Isaac   PetscFunctionReturn(0);
28320cf1dd8SToby Isaac }
28420cf1dd8SToby Isaac 
28520cf1dd8SToby Isaac /*@
28620cf1dd8SToby Isaac   PetscSpaceCreate - Creates an empty PetscSpace object. The type can then be set with PetscSpaceSetType().
28720cf1dd8SToby Isaac 
288d083f849SBarry Smith   Collective
28920cf1dd8SToby Isaac 
29020cf1dd8SToby Isaac   Input Parameter:
29120cf1dd8SToby Isaac . comm - The communicator for the PetscSpace object
29220cf1dd8SToby Isaac 
29320cf1dd8SToby Isaac   Output Parameter:
29420cf1dd8SToby Isaac . sp - The PetscSpace object
29520cf1dd8SToby Isaac 
29620cf1dd8SToby Isaac   Level: beginner
29720cf1dd8SToby Isaac 
29820cf1dd8SToby Isaac .seealso: PetscSpaceSetType(), PETSCSPACEPOLYNOMIAL
29920cf1dd8SToby Isaac @*/
30020cf1dd8SToby Isaac PetscErrorCode PetscSpaceCreate(MPI_Comm comm, PetscSpace *sp)
30120cf1dd8SToby Isaac {
30220cf1dd8SToby Isaac   PetscSpace     s;
30320cf1dd8SToby Isaac   PetscErrorCode ierr;
30420cf1dd8SToby Isaac 
30520cf1dd8SToby Isaac   PetscFunctionBegin;
30620cf1dd8SToby Isaac   PetscValidPointer(sp, 2);
30720cf1dd8SToby Isaac   ierr = PetscCitationsRegister(FECitation,&FEcite);CHKERRQ(ierr);
30820cf1dd8SToby Isaac   *sp  = NULL;
30920cf1dd8SToby Isaac   ierr = PetscFEInitializePackage();CHKERRQ(ierr);
31020cf1dd8SToby Isaac 
31120cf1dd8SToby Isaac   ierr = PetscHeaderCreate(s, PETSCSPACE_CLASSID, "PetscSpace", "Linear Space", "PetscSpace", comm, PetscSpaceDestroy, PetscSpaceView);CHKERRQ(ierr);
31220cf1dd8SToby Isaac 
31320cf1dd8SToby Isaac   s->degree    = 0;
31443bfef1cSToby Isaac   s->maxDegree = PETSC_DETERMINE;
31520cf1dd8SToby Isaac   s->Nc        = 1;
31620cf1dd8SToby Isaac   s->Nv        = 0;
31743bfef1cSToby Isaac   s->dim       = PETSC_DETERMINE;
31820cf1dd8SToby Isaac   ierr = DMShellCreate(comm, &s->dm);CHKERRQ(ierr);
31920cf1dd8SToby Isaac   ierr = PetscSpaceSetType(s, PETSCSPACEPOLYNOMIAL);CHKERRQ(ierr);
32020cf1dd8SToby Isaac 
32120cf1dd8SToby Isaac   *sp = s;
32220cf1dd8SToby Isaac   PetscFunctionReturn(0);
32320cf1dd8SToby Isaac }
32420cf1dd8SToby Isaac 
32520cf1dd8SToby Isaac /*@
32620cf1dd8SToby Isaac   PetscSpaceGetDimension - Return the dimension of this space, i.e. the number of basis vectors
32720cf1dd8SToby Isaac 
32820cf1dd8SToby Isaac   Input Parameter:
32920cf1dd8SToby Isaac . sp - The PetscSpace
33020cf1dd8SToby Isaac 
33120cf1dd8SToby Isaac   Output Parameter:
33220cf1dd8SToby Isaac . dim - The dimension
33320cf1dd8SToby Isaac 
33420cf1dd8SToby Isaac   Level: intermediate
33520cf1dd8SToby Isaac 
33620cf1dd8SToby Isaac .seealso: PetscSpaceGetDegree(), PetscSpaceCreate(), PetscSpace
33720cf1dd8SToby Isaac @*/
33820cf1dd8SToby Isaac PetscErrorCode PetscSpaceGetDimension(PetscSpace sp, PetscInt *dim)
33920cf1dd8SToby Isaac {
34020cf1dd8SToby Isaac   PetscErrorCode ierr;
34120cf1dd8SToby Isaac 
34220cf1dd8SToby Isaac   PetscFunctionBegin;
34320cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
34420cf1dd8SToby Isaac   PetscValidPointer(dim, 2);
34543bfef1cSToby Isaac   if (sp->dim == PETSC_DETERMINE) {
34643bfef1cSToby Isaac     if (sp->ops->getdimension) {ierr = (*sp->ops->getdimension)(sp, &sp->dim);CHKERRQ(ierr);}
34743bfef1cSToby Isaac   }
34843bfef1cSToby Isaac   *dim = sp->dim;
34920cf1dd8SToby Isaac   PetscFunctionReturn(0);
35020cf1dd8SToby Isaac }
35120cf1dd8SToby Isaac 
35220cf1dd8SToby Isaac /*@
35320cf1dd8SToby Isaac   PetscSpaceGetDegree - Return the polynomial degrees that characterize this space
35420cf1dd8SToby Isaac 
35520cf1dd8SToby Isaac   Input Parameter:
35620cf1dd8SToby Isaac . sp - The PetscSpace
35720cf1dd8SToby Isaac 
358*d8d19677SJose E. Roman   Output Parameters:
35920cf1dd8SToby Isaac + minDegree - The degree of the largest polynomial space contained in the space
36020cf1dd8SToby Isaac - maxDegree - The degree of the smallest polynomial space containing the space
36120cf1dd8SToby Isaac 
36220cf1dd8SToby Isaac   Level: intermediate
36320cf1dd8SToby Isaac 
36420cf1dd8SToby Isaac .seealso: PetscSpaceSetDegree(), PetscSpaceGetDimension(), PetscSpaceCreate(), PetscSpace
36520cf1dd8SToby Isaac @*/
36620cf1dd8SToby Isaac PetscErrorCode PetscSpaceGetDegree(PetscSpace sp, PetscInt *minDegree, PetscInt *maxDegree)
36720cf1dd8SToby Isaac {
36820cf1dd8SToby Isaac   PetscFunctionBegin;
36920cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
37020cf1dd8SToby Isaac   if (minDegree) PetscValidPointer(minDegree, 2);
371f5a02b64SToby Isaac   if (maxDegree) PetscValidPointer(maxDegree, 3);
37220cf1dd8SToby Isaac   if (minDegree) *minDegree = sp->degree;
373f5a02b64SToby Isaac   if (maxDegree) *maxDegree = sp->maxDegree;
37420cf1dd8SToby Isaac   PetscFunctionReturn(0);
37520cf1dd8SToby Isaac }
37620cf1dd8SToby Isaac 
37720cf1dd8SToby Isaac /*@
37820cf1dd8SToby Isaac   PetscSpaceSetDegree - Set the degree of approximation for this space.
37920cf1dd8SToby Isaac 
38020cf1dd8SToby Isaac   Input Parameters:
38120cf1dd8SToby Isaac + sp - The PetscSpace
382d39dd5f5SToby Isaac . degree - The degree of the largest polynomial space contained in the space
383d39dd5f5SToby Isaac - maxDegree - The degree of the largest polynomial space containing the space.  One of degree and maxDegree can be PETSC_DETERMINE.
38420cf1dd8SToby Isaac 
38520cf1dd8SToby Isaac   Level: intermediate
38620cf1dd8SToby Isaac 
38720cf1dd8SToby Isaac .seealso: PetscSpaceGetDegree(), PetscSpaceCreate(), PetscSpace
38820cf1dd8SToby Isaac @*/
389d39dd5f5SToby Isaac PetscErrorCode PetscSpaceSetDegree(PetscSpace sp, PetscInt degree, PetscInt maxDegree)
39020cf1dd8SToby Isaac {
39120cf1dd8SToby Isaac   PetscFunctionBegin;
39220cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
393d39dd5f5SToby Isaac   sp->degree = degree;
394d39dd5f5SToby Isaac   sp->maxDegree = maxDegree;
39520cf1dd8SToby Isaac   PetscFunctionReturn(0);
39620cf1dd8SToby Isaac }
39720cf1dd8SToby Isaac 
39820cf1dd8SToby Isaac /*@
39920cf1dd8SToby Isaac   PetscSpaceGetNumComponents - Return the number of components for this space
40020cf1dd8SToby Isaac 
40120cf1dd8SToby Isaac   Input Parameter:
40220cf1dd8SToby Isaac . sp - The PetscSpace
40320cf1dd8SToby Isaac 
40420cf1dd8SToby Isaac   Output Parameter:
40520cf1dd8SToby Isaac . Nc - The number of components
40620cf1dd8SToby Isaac 
40720cf1dd8SToby Isaac   Note: A vector space, for example, will have d components, where d is the spatial dimension
40820cf1dd8SToby Isaac 
40920cf1dd8SToby Isaac   Level: intermediate
41020cf1dd8SToby Isaac 
41129b5c115SMatthew G. Knepley .seealso: PetscSpaceSetNumComponents(), PetscSpaceGetNumVariables(), PetscSpaceGetDimension(), PetscSpaceCreate(), PetscSpace
41220cf1dd8SToby Isaac @*/
41320cf1dd8SToby Isaac PetscErrorCode PetscSpaceGetNumComponents(PetscSpace sp, PetscInt *Nc)
41420cf1dd8SToby Isaac {
41520cf1dd8SToby Isaac   PetscFunctionBegin;
41620cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
41720cf1dd8SToby Isaac   PetscValidPointer(Nc, 2);
41820cf1dd8SToby Isaac   *Nc = sp->Nc;
41920cf1dd8SToby Isaac   PetscFunctionReturn(0);
42020cf1dd8SToby Isaac }
42120cf1dd8SToby Isaac 
42220cf1dd8SToby Isaac /*@
42320cf1dd8SToby Isaac   PetscSpaceSetNumComponents - Set the number of components for this space
42420cf1dd8SToby Isaac 
42520cf1dd8SToby Isaac   Input Parameters:
42620cf1dd8SToby Isaac + sp - The PetscSpace
42720cf1dd8SToby Isaac - order - The number of components
42820cf1dd8SToby Isaac 
42920cf1dd8SToby Isaac   Level: intermediate
43020cf1dd8SToby Isaac 
43129b5c115SMatthew G. Knepley .seealso: PetscSpaceGetNumComponents(), PetscSpaceSetNumVariables(), PetscSpaceCreate(), PetscSpace
43220cf1dd8SToby Isaac @*/
43320cf1dd8SToby Isaac PetscErrorCode PetscSpaceSetNumComponents(PetscSpace sp, PetscInt Nc)
43420cf1dd8SToby Isaac {
43520cf1dd8SToby Isaac   PetscFunctionBegin;
43620cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
43720cf1dd8SToby Isaac   sp->Nc = Nc;
43820cf1dd8SToby Isaac   PetscFunctionReturn(0);
43920cf1dd8SToby Isaac }
44020cf1dd8SToby Isaac 
44129b5c115SMatthew G. Knepley /*@
44229b5c115SMatthew G. Knepley   PetscSpaceSetNumVariables - Set the number of variables for this space
44329b5c115SMatthew G. Knepley 
44429b5c115SMatthew G. Knepley   Input Parameters:
44529b5c115SMatthew G. Knepley + sp - The PetscSpace
44629b5c115SMatthew G. Knepley - n - The number of variables, e.g. x, y, z...
44729b5c115SMatthew G. Knepley 
44829b5c115SMatthew G. Knepley   Level: intermediate
44929b5c115SMatthew G. Knepley 
45029b5c115SMatthew G. Knepley .seealso: PetscSpaceGetNumVariables(), PetscSpaceSetNumComponents(), PetscSpaceCreate(), PetscSpace
45129b5c115SMatthew G. Knepley @*/
45220cf1dd8SToby Isaac PetscErrorCode PetscSpaceSetNumVariables(PetscSpace sp, PetscInt n)
45320cf1dd8SToby Isaac {
45420cf1dd8SToby Isaac   PetscFunctionBegin;
45520cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
45620cf1dd8SToby Isaac   sp->Nv = n;
45720cf1dd8SToby Isaac   PetscFunctionReturn(0);
45820cf1dd8SToby Isaac }
45920cf1dd8SToby Isaac 
46029b5c115SMatthew G. Knepley /*@
46129b5c115SMatthew G. Knepley   PetscSpaceGetNumVariables - Return the number of variables for this space
46229b5c115SMatthew G. Knepley 
46329b5c115SMatthew G. Knepley   Input Parameter:
46429b5c115SMatthew G. Knepley . sp - The PetscSpace
46529b5c115SMatthew G. Knepley 
46629b5c115SMatthew G. Knepley   Output Parameter:
46729b5c115SMatthew G. Knepley . Nc - The number of variables, e.g. x, y, z...
46829b5c115SMatthew G. Knepley 
46929b5c115SMatthew G. Knepley   Level: intermediate
47029b5c115SMatthew G. Knepley 
47129b5c115SMatthew G. Knepley .seealso: PetscSpaceSetNumVariables(), PetscSpaceGetNumComponents(), PetscSpaceGetDimension(), PetscSpaceCreate(), PetscSpace
47229b5c115SMatthew G. Knepley @*/
47320cf1dd8SToby Isaac PetscErrorCode PetscSpaceGetNumVariables(PetscSpace sp, PetscInt *n)
47420cf1dd8SToby Isaac {
47520cf1dd8SToby Isaac   PetscFunctionBegin;
47620cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
47720cf1dd8SToby Isaac   PetscValidPointer(n, 2);
47820cf1dd8SToby Isaac   *n = sp->Nv;
47920cf1dd8SToby Isaac   PetscFunctionReturn(0);
48020cf1dd8SToby Isaac }
48120cf1dd8SToby Isaac 
48220cf1dd8SToby Isaac /*@C
48320cf1dd8SToby Isaac   PetscSpaceEvaluate - Evaluate the basis functions and their derivatives (jet) at each point
48420cf1dd8SToby Isaac 
48520cf1dd8SToby Isaac   Input Parameters:
48620cf1dd8SToby Isaac + sp      - The PetscSpace
48720cf1dd8SToby Isaac . npoints - The number of evaluation points, in reference coordinates
48820cf1dd8SToby Isaac - points  - The point coordinates
48920cf1dd8SToby Isaac 
49020cf1dd8SToby Isaac   Output Parameters:
49120cf1dd8SToby Isaac + B - The function evaluations in a npoints x nfuncs array
49220cf1dd8SToby Isaac . D - The derivative evaluations in a npoints x nfuncs x dim array
49320cf1dd8SToby Isaac - H - The second derivative evaluations in a npoints x nfuncs x dim x dim array
49420cf1dd8SToby Isaac 
49520cf1dd8SToby Isaac   Note: Above nfuncs is the dimension of the space, and dim is the spatial dimension. The coordinates are given
49620cf1dd8SToby Isaac   on the reference cell, not in real space.
49720cf1dd8SToby Isaac 
49829b5c115SMatthew G. Knepley   Level: beginner
49920cf1dd8SToby Isaac 
500ef0bb6c7SMatthew G. Knepley .seealso: PetscFECreateTabulation(), PetscFEGetCellTabulation(), PetscSpaceCreate()
50120cf1dd8SToby Isaac @*/
50220cf1dd8SToby Isaac PetscErrorCode PetscSpaceEvaluate(PetscSpace sp, PetscInt npoints, const PetscReal points[], PetscReal B[], PetscReal D[], PetscReal H[])
50320cf1dd8SToby Isaac {
50420cf1dd8SToby Isaac   PetscErrorCode ierr;
50520cf1dd8SToby Isaac 
50620cf1dd8SToby Isaac   PetscFunctionBegin;
50720cf1dd8SToby Isaac   if (!npoints) PetscFunctionReturn(0);
50820cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
50920cf1dd8SToby Isaac   if (sp->Nv) PetscValidPointer(points, 3);
51020cf1dd8SToby Isaac   if (B) PetscValidPointer(B, 4);
51120cf1dd8SToby Isaac   if (D) PetscValidPointer(D, 5);
51220cf1dd8SToby Isaac   if (H) PetscValidPointer(H, 6);
51320cf1dd8SToby Isaac   if (sp->ops->evaluate) {ierr = (*sp->ops->evaluate)(sp, npoints, points, B, D, H);CHKERRQ(ierr);}
51420cf1dd8SToby Isaac   PetscFunctionReturn(0);
51520cf1dd8SToby Isaac }
51620cf1dd8SToby Isaac 
51720cf1dd8SToby Isaac /*@
51820cf1dd8SToby Isaac   PetscSpaceGetHeightSubspace - Get the subset of the primal space basis that is supported on a mesh point of a given height.
51920cf1dd8SToby Isaac 
52020cf1dd8SToby Isaac   If the space is not defined on mesh points of the given height (e.g. if the space is discontinuous and
52120cf1dd8SToby Isaac   pointwise values are not defined on the element boundaries), or if the implementation of PetscSpace does not
52220cf1dd8SToby Isaac   support extracting subspaces, then NULL is returned.
52320cf1dd8SToby Isaac 
52420cf1dd8SToby Isaac   This does not increment the reference count on the returned space, and the user should not destroy it.
52520cf1dd8SToby Isaac 
52620cf1dd8SToby Isaac   Not collective
52720cf1dd8SToby Isaac 
52820cf1dd8SToby Isaac   Input Parameters:
52920cf1dd8SToby Isaac + sp - the PetscSpace object
53020cf1dd8SToby Isaac - height - the height of the mesh point for which the subspace is desired
53120cf1dd8SToby Isaac 
53220cf1dd8SToby Isaac   Output Parameter:
53320cf1dd8SToby Isaac . subsp - the subspace
53420cf1dd8SToby Isaac 
53520cf1dd8SToby Isaac   Level: advanced
53620cf1dd8SToby Isaac 
53720cf1dd8SToby Isaac .seealso: PetscDualSpaceGetHeightSubspace(), PetscSpace
53820cf1dd8SToby Isaac @*/
53920cf1dd8SToby Isaac PetscErrorCode PetscSpaceGetHeightSubspace(PetscSpace sp, PetscInt height, PetscSpace *subsp)
54020cf1dd8SToby Isaac {
54120cf1dd8SToby Isaac   PetscErrorCode ierr;
54220cf1dd8SToby Isaac 
54320cf1dd8SToby Isaac   PetscFunctionBegin;
54420cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
54520cf1dd8SToby Isaac   PetscValidPointer(subsp, 3);
54620cf1dd8SToby Isaac   *subsp = NULL;
54720cf1dd8SToby Isaac   if (sp->ops->getheightsubspace) {
54820cf1dd8SToby Isaac     ierr = (*sp->ops->getheightsubspace)(sp, height, subsp);CHKERRQ(ierr);
54920cf1dd8SToby Isaac   }
55020cf1dd8SToby Isaac   PetscFunctionReturn(0);
55120cf1dd8SToby Isaac }
552