xref: /petsc/src/dm/dt/space/interface/space.c (revision bcda9346efad4e5ba2d553af84eb238771ba1e25)
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
10dce8aebaSBarry Smith   PetscSpaceRegister - Adds a new `PetscSpace` implementation
1120cf1dd8SToby Isaac 
12cc4c1da9SBarry Smith   Not Collective, No Fortran Support
1320cf1dd8SToby Isaac 
1420cf1dd8SToby Isaac   Input Parameters:
1560225df5SJacob Faibussowitsch + sname    - The name of a new user-defined creation routine
1660225df5SJacob Faibussowitsch - function - The creation routine for the implementation type
1720cf1dd8SToby Isaac 
1860225df5SJacob Faibussowitsch   Example Usage:
1920cf1dd8SToby Isaac .vb
2020cf1dd8SToby Isaac     PetscSpaceRegister("my_space", MyPetscSpaceCreate);
2120cf1dd8SToby Isaac .ve
2220cf1dd8SToby Isaac 
2320cf1dd8SToby Isaac   Then, your PetscSpace type can be chosen with the procedural interface via
2420cf1dd8SToby Isaac .vb
2520cf1dd8SToby Isaac     PetscSpaceCreate(MPI_Comm, PetscSpace *);
2620cf1dd8SToby Isaac     PetscSpaceSetType(PetscSpace, "my_space");
2720cf1dd8SToby Isaac .ve
2820cf1dd8SToby Isaac   or at runtime via the option
2920cf1dd8SToby Isaac .vb
3020cf1dd8SToby Isaac     -petscspace_type my_space
3120cf1dd8SToby Isaac .ve
3220cf1dd8SToby Isaac 
3320cf1dd8SToby Isaac   Level: advanced
3420cf1dd8SToby Isaac 
35dce8aebaSBarry Smith   Note:
36dce8aebaSBarry Smith   `PetscSpaceRegister()` may be called multiple times to add several user-defined types of `PetscSpace`.  The creation function is called
37dce8aebaSBarry Smith   when the type is set to 'name'.
3820cf1dd8SToby Isaac 
39dce8aebaSBarry Smith .seealso: `PetscSpace`, `PetscSpaceRegisterAll()`, `PetscSpaceRegisterDestroy()`
4020cf1dd8SToby Isaac @*/
PetscSpaceRegister(const char sname[],PetscErrorCode (* function)(PetscSpace))41d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSpaceRegister(const char sname[], PetscErrorCode (*function)(PetscSpace))
42d71ae5a4SJacob Faibussowitsch {
4320cf1dd8SToby Isaac   PetscFunctionBegin;
449566063dSJacob Faibussowitsch   PetscCall(PetscFunctionListAdd(&PetscSpaceList, sname, function));
453ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
4620cf1dd8SToby Isaac }
4720cf1dd8SToby Isaac 
48cc4c1da9SBarry Smith /*@
49dce8aebaSBarry Smith   PetscSpaceSetType - Builds a particular `PetscSpace`
5020cf1dd8SToby Isaac 
5120f4b53cSBarry Smith   Collective
5220cf1dd8SToby Isaac 
5320cf1dd8SToby Isaac   Input Parameters:
54dce8aebaSBarry Smith + sp   - The `PetscSpace` object
5520cf1dd8SToby Isaac - name - The kind of space
5620cf1dd8SToby Isaac 
5720cf1dd8SToby Isaac   Options Database Key:
58dce8aebaSBarry Smith . -petscspace_type <type> - Sets the `PetscSpace` type; use -help for a list of available types
5920cf1dd8SToby Isaac 
6020cf1dd8SToby Isaac   Level: intermediate
6120cf1dd8SToby Isaac 
62dce8aebaSBarry Smith .seealso: `PetscSpace`, `PetscSpaceType`, `PetscSpaceGetType()`, `PetscSpaceCreate()`
6320cf1dd8SToby Isaac @*/
PetscSpaceSetType(PetscSpace sp,PetscSpaceType name)64d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSpaceSetType(PetscSpace sp, PetscSpaceType name)
65d71ae5a4SJacob Faibussowitsch {
6620cf1dd8SToby Isaac   PetscErrorCode (*r)(PetscSpace);
6720cf1dd8SToby Isaac   PetscBool match;
6820cf1dd8SToby Isaac 
6920cf1dd8SToby Isaac   PetscFunctionBegin;
7020cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
719566063dSJacob Faibussowitsch   PetscCall(PetscObjectTypeCompare((PetscObject)sp, name, &match));
723ba16761SJacob Faibussowitsch   if (match) PetscFunctionReturn(PETSC_SUCCESS);
7320cf1dd8SToby Isaac 
749566063dSJacob Faibussowitsch   PetscCall(PetscSpaceRegisterAll());
759566063dSJacob Faibussowitsch   PetscCall(PetscFunctionListFind(PetscSpaceList, name, &r));
762c71b3e2SJacob Faibussowitsch   PetscCheck(r, PetscObjectComm((PetscObject)sp), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscSpace type: %s", name);
7720cf1dd8SToby Isaac 
78dbbe0bcdSBarry Smith   PetscTryTypeMethod(sp, destroy);
7920cf1dd8SToby Isaac   sp->ops->destroy = NULL;
80dbbe0bcdSBarry Smith 
8143bfef1cSToby Isaac   sp->dim = PETSC_DETERMINE;
829566063dSJacob Faibussowitsch   PetscCall((*r)(sp));
839566063dSJacob Faibussowitsch   PetscCall(PetscObjectChangeTypeName((PetscObject)sp, name));
843ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
8520cf1dd8SToby Isaac }
8620cf1dd8SToby Isaac 
87cc4c1da9SBarry Smith /*@
88dce8aebaSBarry Smith   PetscSpaceGetType - Gets the `PetscSpaceType` (as a string) from the object.
8920cf1dd8SToby Isaac 
9020cf1dd8SToby Isaac   Not Collective
9120cf1dd8SToby Isaac 
9220cf1dd8SToby Isaac   Input Parameter:
93dce8aebaSBarry Smith . sp - The `PetscSpace`
9420cf1dd8SToby Isaac 
9520cf1dd8SToby Isaac   Output Parameter:
96dce8aebaSBarry Smith . name - The `PetscSpace` type name
9720cf1dd8SToby Isaac 
9820cf1dd8SToby Isaac   Level: intermediate
9920cf1dd8SToby Isaac 
100dce8aebaSBarry Smith .seealso: `PetscSpaceType`, `PetscSpace`, `PetscSpaceSetType()`, `PetscSpaceCreate()`
10120cf1dd8SToby Isaac @*/
PetscSpaceGetType(PetscSpace sp,PetscSpaceType * name)102d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSpaceGetType(PetscSpace sp, PetscSpaceType *name)
103d71ae5a4SJacob Faibussowitsch {
10420cf1dd8SToby Isaac   PetscFunctionBegin;
10520cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
1064f572ea9SToby Isaac   PetscAssertPointer(name, 2);
10748a46eb9SPierre Jolivet   if (!PetscSpaceRegisterAllCalled) PetscCall(PetscSpaceRegisterAll());
10820cf1dd8SToby Isaac   *name = ((PetscObject)sp)->type_name;
1093ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
11020cf1dd8SToby Isaac }
11120cf1dd8SToby Isaac 
112ffeef943SBarry Smith /*@
113dce8aebaSBarry Smith   PetscSpaceViewFromOptions - View a `PetscSpace` based on values in the options database
114fe2efc57SMark 
11520f4b53cSBarry Smith   Collective
116fe2efc57SMark 
117fe2efc57SMark   Input Parameters:
11820f4b53cSBarry Smith + A    - the `PetscSpace` object
119dce8aebaSBarry Smith . obj  - Optional object that provides the options name prefix
120dce8aebaSBarry Smith - name - command line option name
121fe2efc57SMark 
122fe2efc57SMark   Level: intermediate
12320f4b53cSBarry Smith 
124dce8aebaSBarry Smith .seealso: `PetscSpace`, `PetscSpaceView()`, `PetscObjectViewFromOptions()`, `PetscSpaceCreate()`
125fe2efc57SMark @*/
PetscSpaceViewFromOptions(PetscSpace A,PetscObject obj,const char name[])126d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSpaceViewFromOptions(PetscSpace A, PetscObject obj, const char name[])
127d71ae5a4SJacob Faibussowitsch {
128fe2efc57SMark   PetscFunctionBegin;
129fe2efc57SMark   PetscValidHeaderSpecific(A, PETSCSPACE_CLASSID, 1);
1309566063dSJacob Faibussowitsch   PetscCall(PetscObjectViewFromOptions((PetscObject)A, obj, name));
1313ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
132fe2efc57SMark }
133fe2efc57SMark 
134ffeef943SBarry Smith /*@
135dce8aebaSBarry Smith   PetscSpaceView - Views a `PetscSpace`
13620cf1dd8SToby Isaac 
13720f4b53cSBarry Smith   Collective
13820cf1dd8SToby Isaac 
139d8d19677SJose E. Roman   Input Parameters:
140dce8aebaSBarry Smith + sp - the `PetscSpace` object to view
14120cf1dd8SToby Isaac - v  - the viewer
14220cf1dd8SToby Isaac 
14329b5c115SMatthew G. Knepley   Level: beginner
14420cf1dd8SToby Isaac 
145dce8aebaSBarry Smith .seealso: `PetscSpace`, `PetscViewer`, `PetscSpaceViewFromOptions()`, `PetscSpaceDestroy()`
14620cf1dd8SToby Isaac @*/
PetscSpaceView(PetscSpace sp,PetscViewer v)147d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSpaceView(PetscSpace sp, PetscViewer v)
148d71ae5a4SJacob Faibussowitsch {
1490aec8e07SMatthew G. Knepley   PetscInt  pdim;
150*9f196a02SMartin Diehl   PetscBool isascii;
15120cf1dd8SToby Isaac 
15220cf1dd8SToby Isaac   PetscFunctionBegin;
15320cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
15420cf1dd8SToby Isaac   if (v) PetscValidHeaderSpecific(v, PETSC_VIEWER_CLASSID, 2);
1559566063dSJacob Faibussowitsch   if (!v) PetscCall(PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)sp), &v));
1569566063dSJacob Faibussowitsch   PetscCall(PetscSpaceGetDimension(sp, &pdim));
1579566063dSJacob Faibussowitsch   PetscCall(PetscObjectPrintClassNamePrefixType((PetscObject)sp, v));
158*9f196a02SMartin Diehl   PetscCall(PetscObjectTypeCompare((PetscObject)v, PETSCVIEWERASCII, &isascii));
1599566063dSJacob Faibussowitsch   PetscCall(PetscViewerASCIIPushTab(v));
160*9f196a02SMartin Diehl   if (isascii) PetscCall(PetscViewerASCIIPrintf(v, "Space in %" PetscInt_FMT " variables with %" PetscInt_FMT " components, size %" PetscInt_FMT "\n", sp->Nv, sp->Nc, pdim));
161dbbe0bcdSBarry Smith   PetscTryTypeMethod(sp, view, v);
1629566063dSJacob Faibussowitsch   PetscCall(PetscViewerASCIIPopTab(v));
1633ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
16420cf1dd8SToby Isaac }
16520cf1dd8SToby Isaac 
16620cf1dd8SToby Isaac /*@
167dce8aebaSBarry Smith   PetscSpaceSetFromOptions - sets parameters in a `PetscSpace` from the options database
16820cf1dd8SToby Isaac 
16920f4b53cSBarry Smith   Collective
17020cf1dd8SToby Isaac 
17120cf1dd8SToby Isaac   Input Parameter:
172dce8aebaSBarry Smith . sp - the `PetscSpace` object to set options for
17320cf1dd8SToby Isaac 
174dce8aebaSBarry Smith   Options Database Keys:
1758f2aacc6SMatthew G. Knepley + -petscspace_degree <deg>   - the approximation order of the space
1768f2aacc6SMatthew G. Knepley . -petscspace_variables <n>  - the number of different variables, e.g. x and y
1778f2aacc6SMatthew G. Knepley - -petscspace_components <c> - the number of components, say d for a vector field
17820cf1dd8SToby Isaac 
17929b5c115SMatthew G. Knepley   Level: intermediate
18020cf1dd8SToby Isaac 
181dce8aebaSBarry Smith .seealso: `PetscSpace`, `PetscSpaceView()`
18220cf1dd8SToby Isaac @*/
PetscSpaceSetFromOptions(PetscSpace sp)183d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSpaceSetFromOptions(PetscSpace sp)
184d71ae5a4SJacob Faibussowitsch {
18520cf1dd8SToby Isaac   const char *defaultType;
18620cf1dd8SToby Isaac   char        name[256];
1875a856986SBarry Smith   PetscBool   flg;
18820cf1dd8SToby Isaac 
18920cf1dd8SToby Isaac   PetscFunctionBegin;
19020cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
19120cf1dd8SToby Isaac   if (!((PetscObject)sp)->type_name) {
19220cf1dd8SToby Isaac     defaultType = PETSCSPACEPOLYNOMIAL;
19320cf1dd8SToby Isaac   } else {
19420cf1dd8SToby Isaac     defaultType = ((PetscObject)sp)->type_name;
19520cf1dd8SToby Isaac   }
1969566063dSJacob Faibussowitsch   if (!PetscSpaceRegisterAllCalled) PetscCall(PetscSpaceRegisterAll());
19720cf1dd8SToby Isaac 
198d0609cedSBarry Smith   PetscObjectOptionsBegin((PetscObject)sp);
1999566063dSJacob Faibussowitsch   PetscCall(PetscOptionsFList("-petscspace_type", "Linear space", "PetscSpaceSetType", PetscSpaceList, defaultType, name, 256, &flg));
20020cf1dd8SToby Isaac   if (flg) {
2019566063dSJacob Faibussowitsch     PetscCall(PetscSpaceSetType(sp, name));
20220cf1dd8SToby Isaac   } else if (!((PetscObject)sp)->type_name) {
2039566063dSJacob Faibussowitsch     PetscCall(PetscSpaceSetType(sp, defaultType));
20420cf1dd8SToby Isaac   }
2057be5e748SToby Isaac   {
2069566063dSJacob Faibussowitsch     PetscCall(PetscOptionsDeprecated("-petscspace_order", "-petscspace_degree", "3.11", NULL));
2077be5e748SToby Isaac   }
2089566063dSJacob Faibussowitsch   PetscCall(PetscOptionsBoundedInt("-petscspace_degree", "The (maximally included) polynomial degree", "PetscSpaceSetDegree", sp->degree, &sp->degree, NULL, 0));
2099566063dSJacob Faibussowitsch   PetscCall(PetscOptionsBoundedInt("-petscspace_variables", "The number of different variables, e.g. x and y", "PetscSpaceSetNumVariables", sp->Nv, &sp->Nv, NULL, 0));
2106c2660fcSDarsh Nathawani   PetscCall(PetscOptionsBoundedInt("-petscspace_components", "The number of components", "PetscSpaceSetNumComponents", sp->Nc, &sp->Nc, NULL, -1));
211dbbe0bcdSBarry Smith   PetscTryTypeMethod(sp, setfromoptions, PetscOptionsObject);
21220cf1dd8SToby Isaac   /* process any options handlers added with PetscObjectAddOptionsHandler() */
213dbbe0bcdSBarry Smith   PetscCall(PetscObjectProcessOptionsHandlers((PetscObject)sp, PetscOptionsObject));
214d0609cedSBarry Smith   PetscOptionsEnd();
2159566063dSJacob Faibussowitsch   PetscCall(PetscSpaceViewFromOptions(sp, NULL, "-petscspace_view"));
2163ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
21720cf1dd8SToby Isaac }
21820cf1dd8SToby Isaac 
219cc4c1da9SBarry Smith /*@
220dce8aebaSBarry Smith   PetscSpaceSetUp - Construct data structures for the `PetscSpace`
22120cf1dd8SToby Isaac 
22220f4b53cSBarry Smith   Collective
22320cf1dd8SToby Isaac 
22420cf1dd8SToby Isaac   Input Parameter:
225dce8aebaSBarry Smith . sp - the `PetscSpace` object to setup
22620cf1dd8SToby Isaac 
22729b5c115SMatthew G. Knepley   Level: intermediate
22820cf1dd8SToby Isaac 
229dce8aebaSBarry Smith .seealso: `PetscSpace`, `PetscSpaceView()`, `PetscSpaceDestroy()`
23020cf1dd8SToby Isaac @*/
PetscSpaceSetUp(PetscSpace sp)231d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSpaceSetUp(PetscSpace sp)
232d71ae5a4SJacob Faibussowitsch {
23320cf1dd8SToby Isaac   PetscFunctionBegin;
23420cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
235dbbe0bcdSBarry Smith   PetscTryTypeMethod(sp, setup);
2363ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
23720cf1dd8SToby Isaac }
23820cf1dd8SToby Isaac 
23920cf1dd8SToby Isaac /*@
240dce8aebaSBarry Smith   PetscSpaceDestroy - Destroys a `PetscSpace` object
24120cf1dd8SToby Isaac 
24220f4b53cSBarry Smith   Collective
24320cf1dd8SToby Isaac 
24420cf1dd8SToby Isaac   Input Parameter:
24520f4b53cSBarry Smith . sp - the `PetscSpace` object to destroy
24620cf1dd8SToby Isaac 
24729b5c115SMatthew G. Knepley   Level: beginner
24820cf1dd8SToby Isaac 
249dce8aebaSBarry Smith .seealso: `PetscSpace`, `PetscSpaceCreate()`
25020cf1dd8SToby Isaac @*/
PetscSpaceDestroy(PetscSpace * sp)251d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSpaceDestroy(PetscSpace *sp)
252d71ae5a4SJacob Faibussowitsch {
25320cf1dd8SToby Isaac   PetscFunctionBegin;
2543ba16761SJacob Faibussowitsch   if (!*sp) PetscFunctionReturn(PETSC_SUCCESS);
255f4f49eeaSPierre Jolivet   PetscValidHeaderSpecific(*sp, PETSCSPACE_CLASSID, 1);
25620cf1dd8SToby Isaac 
257f4f49eeaSPierre Jolivet   if (--((PetscObject)*sp)->refct > 0) {
2589371c9d4SSatish Balay     *sp = NULL;
2593ba16761SJacob Faibussowitsch     PetscFunctionReturn(PETSC_SUCCESS);
2609371c9d4SSatish Balay   }
261f4f49eeaSPierre Jolivet   ((PetscObject)*sp)->refct = 0;
2629566063dSJacob Faibussowitsch   PetscCall(DMDestroy(&(*sp)->dm));
26320cf1dd8SToby Isaac 
2649927e4dfSBarry Smith   PetscUseTypeMethod(*sp, destroy);
2659566063dSJacob Faibussowitsch   PetscCall(PetscHeaderDestroy(sp));
2663ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
26720cf1dd8SToby Isaac }
26820cf1dd8SToby Isaac 
26920cf1dd8SToby Isaac /*@
270dce8aebaSBarry Smith   PetscSpaceCreate - Creates an empty `PetscSpace` object. The type can then be set with `PetscSpaceSetType()`.
27120cf1dd8SToby Isaac 
272d083f849SBarry Smith   Collective
27320cf1dd8SToby Isaac 
27420cf1dd8SToby Isaac   Input Parameter:
275dce8aebaSBarry Smith . comm - The communicator for the `PetscSpace` object
27620cf1dd8SToby Isaac 
27720cf1dd8SToby Isaac   Output Parameter:
278dce8aebaSBarry Smith . sp - The `PetscSpace` object
27920cf1dd8SToby Isaac 
28020cf1dd8SToby Isaac   Level: beginner
28120cf1dd8SToby Isaac 
282dce8aebaSBarry Smith .seealso: `PetscSpace`, `PetscSpaceSetType()`, `PETSCSPACEPOLYNOMIAL`
28320cf1dd8SToby Isaac @*/
PetscSpaceCreate(MPI_Comm comm,PetscSpace * sp)284d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSpaceCreate(MPI_Comm comm, PetscSpace *sp)
285d71ae5a4SJacob Faibussowitsch {
28620cf1dd8SToby Isaac   PetscSpace s;
28720cf1dd8SToby Isaac 
28820cf1dd8SToby Isaac   PetscFunctionBegin;
2894f572ea9SToby Isaac   PetscAssertPointer(sp, 2);
2909566063dSJacob Faibussowitsch   PetscCall(PetscCitationsRegister(FECitation, &FEcite));
2919566063dSJacob Faibussowitsch   PetscCall(PetscFEInitializePackage());
29220cf1dd8SToby Isaac 
2939566063dSJacob Faibussowitsch   PetscCall(PetscHeaderCreate(s, PETSCSPACE_CLASSID, "PetscSpace", "Linear Space", "PetscSpace", comm, PetscSpaceDestroy, PetscSpaceView));
29420cf1dd8SToby Isaac   s->degree    = 0;
29543bfef1cSToby Isaac   s->maxDegree = PETSC_DETERMINE;
29620cf1dd8SToby Isaac   s->Nc        = 1;
29720cf1dd8SToby Isaac   s->Nv        = 0;
29843bfef1cSToby Isaac   s->dim       = PETSC_DETERMINE;
2999566063dSJacob Faibussowitsch   PetscCall(DMShellCreate(comm, &s->dm));
3009566063dSJacob Faibussowitsch   PetscCall(PetscSpaceSetType(s, PETSCSPACEPOLYNOMIAL));
30120cf1dd8SToby Isaac 
30220cf1dd8SToby Isaac   *sp = s;
3033ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
30420cf1dd8SToby Isaac }
30520cf1dd8SToby Isaac 
30620cf1dd8SToby Isaac /*@
30720cf1dd8SToby Isaac   PetscSpaceGetDimension - Return the dimension of this space, i.e. the number of basis vectors
30820cf1dd8SToby Isaac 
30920cf1dd8SToby Isaac   Input Parameter:
310dce8aebaSBarry Smith . sp - The `PetscSpace`
31120cf1dd8SToby Isaac 
31220cf1dd8SToby Isaac   Output Parameter:
31320cf1dd8SToby Isaac . dim - The dimension
31420cf1dd8SToby Isaac 
31520cf1dd8SToby Isaac   Level: intermediate
31620cf1dd8SToby Isaac 
31760225df5SJacob Faibussowitsch .seealso: `PetscSpace`, `PetscSpaceGetDegree()`, `PetscSpaceCreate()`
31820cf1dd8SToby Isaac @*/
PetscSpaceGetDimension(PetscSpace sp,PetscInt * dim)319d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSpaceGetDimension(PetscSpace sp, PetscInt *dim)
320d71ae5a4SJacob Faibussowitsch {
32120cf1dd8SToby Isaac   PetscFunctionBegin;
32220cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
3234f572ea9SToby Isaac   PetscAssertPointer(dim, 2);
324ad540459SPierre Jolivet   if (sp->dim == PETSC_DETERMINE) PetscTryTypeMethod(sp, getdimension, &sp->dim);
32543bfef1cSToby Isaac   *dim = sp->dim;
3263ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
32720cf1dd8SToby Isaac }
32820cf1dd8SToby Isaac 
32920cf1dd8SToby Isaac /*@
33020cf1dd8SToby Isaac   PetscSpaceGetDegree - Return the polynomial degrees that characterize this space
33120cf1dd8SToby Isaac 
33220cf1dd8SToby Isaac   Input Parameter:
333dce8aebaSBarry Smith . sp - The `PetscSpace`
33420cf1dd8SToby Isaac 
335d8d19677SJose E. Roman   Output Parameters:
336ce78bad3SBarry Smith + minDegree - The degree of the largest polynomial space contained in the space, pass `NULL` if not needed
337ce78bad3SBarry Smith - maxDegree - The degree of the smallest polynomial space containing the space, pass `NULL` if not needed
33820cf1dd8SToby Isaac 
33920cf1dd8SToby Isaac   Level: intermediate
34020cf1dd8SToby Isaac 
34160225df5SJacob Faibussowitsch .seealso: `PetscSpace`, `PetscSpaceSetDegree()`, `PetscSpaceGetDimension()`, `PetscSpaceCreate()`
34220cf1dd8SToby Isaac @*/
PetscSpaceGetDegree(PetscSpace sp,PeOp PetscInt * minDegree,PeOp PetscInt * maxDegree)343ce78bad3SBarry Smith PetscErrorCode PetscSpaceGetDegree(PetscSpace sp, PeOp PetscInt *minDegree, PeOp PetscInt *maxDegree)
344d71ae5a4SJacob Faibussowitsch {
34520cf1dd8SToby Isaac   PetscFunctionBegin;
34620cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
3474f572ea9SToby Isaac   if (minDegree) PetscAssertPointer(minDegree, 2);
3484f572ea9SToby Isaac   if (maxDegree) PetscAssertPointer(maxDegree, 3);
34920cf1dd8SToby Isaac   if (minDegree) *minDegree = sp->degree;
350f5a02b64SToby Isaac   if (maxDegree) *maxDegree = sp->maxDegree;
3513ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
35220cf1dd8SToby Isaac }
35320cf1dd8SToby Isaac 
35420cf1dd8SToby Isaac /*@
35520cf1dd8SToby Isaac   PetscSpaceSetDegree - Set the degree of approximation for this space.
35620cf1dd8SToby Isaac 
35720cf1dd8SToby Isaac   Input Parameters:
358dce8aebaSBarry Smith + sp        - The `PetscSpace`
359d39dd5f5SToby Isaac . degree    - The degree of the largest polynomial space contained in the space
360dce8aebaSBarry Smith - maxDegree - The degree of the largest polynomial space containing the space.  One of degree and maxDegree can be `PETSC_DETERMINE`.
36120cf1dd8SToby Isaac 
36220cf1dd8SToby Isaac   Level: intermediate
36320cf1dd8SToby Isaac 
36460225df5SJacob Faibussowitsch .seealso: `PetscSpace`, `PetscSpaceGetDegree()`, `PetscSpaceCreate()`
36520cf1dd8SToby Isaac @*/
PetscSpaceSetDegree(PetscSpace sp,PetscInt degree,PetscInt maxDegree)366d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSpaceSetDegree(PetscSpace sp, PetscInt degree, PetscInt maxDegree)
367d71ae5a4SJacob Faibussowitsch {
36820cf1dd8SToby Isaac   PetscFunctionBegin;
36920cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
370d39dd5f5SToby Isaac   sp->degree    = degree;
371d39dd5f5SToby Isaac   sp->maxDegree = maxDegree;
3723ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
37320cf1dd8SToby Isaac }
37420cf1dd8SToby Isaac 
37520cf1dd8SToby Isaac /*@
37620cf1dd8SToby Isaac   PetscSpaceGetNumComponents - Return the number of components for this space
37720cf1dd8SToby Isaac 
37820cf1dd8SToby Isaac   Input Parameter:
379dce8aebaSBarry Smith . sp - The `PetscSpace`
38020cf1dd8SToby Isaac 
38120cf1dd8SToby Isaac   Output Parameter:
38220cf1dd8SToby Isaac . Nc - The number of components
38320cf1dd8SToby Isaac 
38420cf1dd8SToby Isaac   Level: intermediate
38520cf1dd8SToby Isaac 
386dce8aebaSBarry Smith   Note:
387dce8aebaSBarry Smith   A vector space, for example, will have d components, where d is the spatial dimension
388dce8aebaSBarry Smith 
38960225df5SJacob Faibussowitsch .seealso: `PetscSpace`, `PetscSpaceSetNumComponents()`, `PetscSpaceGetNumVariables()`, `PetscSpaceGetDimension()`, `PetscSpaceCreate()`
39020cf1dd8SToby Isaac @*/
PetscSpaceGetNumComponents(PetscSpace sp,PetscInt * Nc)391d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSpaceGetNumComponents(PetscSpace sp, PetscInt *Nc)
392d71ae5a4SJacob Faibussowitsch {
39320cf1dd8SToby Isaac   PetscFunctionBegin;
39420cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
3954f572ea9SToby Isaac   PetscAssertPointer(Nc, 2);
39620cf1dd8SToby Isaac   *Nc = sp->Nc;
3973ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
39820cf1dd8SToby Isaac }
39920cf1dd8SToby Isaac 
40020cf1dd8SToby Isaac /*@
40120cf1dd8SToby Isaac   PetscSpaceSetNumComponents - Set the number of components for this space
40220cf1dd8SToby Isaac 
40320cf1dd8SToby Isaac   Input Parameters:
404dce8aebaSBarry Smith + sp - The `PetscSpace`
40560225df5SJacob Faibussowitsch - Nc - The number of components
40620cf1dd8SToby Isaac 
40720cf1dd8SToby Isaac   Level: intermediate
40820cf1dd8SToby Isaac 
40960225df5SJacob Faibussowitsch .seealso: `PetscSpace`, `PetscSpaceGetNumComponents()`, `PetscSpaceSetNumVariables()`, `PetscSpaceCreate()`
41020cf1dd8SToby Isaac @*/
PetscSpaceSetNumComponents(PetscSpace sp,PetscInt Nc)411d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSpaceSetNumComponents(PetscSpace sp, PetscInt Nc)
412d71ae5a4SJacob Faibussowitsch {
41320cf1dd8SToby Isaac   PetscFunctionBegin;
41420cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
41520cf1dd8SToby Isaac   sp->Nc = Nc;
4163ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
41720cf1dd8SToby Isaac }
41820cf1dd8SToby Isaac 
41929b5c115SMatthew G. Knepley /*@
42029b5c115SMatthew G. Knepley   PetscSpaceSetNumVariables - Set the number of variables for this space
42129b5c115SMatthew G. Knepley 
42229b5c115SMatthew G. Knepley   Input Parameters:
423dce8aebaSBarry Smith + sp - The `PetscSpace`
42429b5c115SMatthew G. Knepley - n  - The number of variables, e.g. x, y, z...
42529b5c115SMatthew G. Knepley 
42629b5c115SMatthew G. Knepley   Level: intermediate
42729b5c115SMatthew G. Knepley 
42860225df5SJacob Faibussowitsch .seealso: `PetscSpace`, `PetscSpaceGetNumVariables()`, `PetscSpaceSetNumComponents()`, `PetscSpaceCreate()`
42929b5c115SMatthew G. Knepley @*/
PetscSpaceSetNumVariables(PetscSpace sp,PetscInt n)430d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSpaceSetNumVariables(PetscSpace sp, PetscInt n)
431d71ae5a4SJacob Faibussowitsch {
43220cf1dd8SToby Isaac   PetscFunctionBegin;
43320cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
43420cf1dd8SToby Isaac   sp->Nv = n;
4353ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
43620cf1dd8SToby Isaac }
43720cf1dd8SToby Isaac 
43829b5c115SMatthew G. Knepley /*@
43929b5c115SMatthew G. Knepley   PetscSpaceGetNumVariables - Return the number of variables for this space
44029b5c115SMatthew G. Knepley 
44129b5c115SMatthew G. Knepley   Input Parameter:
442dce8aebaSBarry Smith . sp - The `PetscSpace`
44329b5c115SMatthew G. Knepley 
44429b5c115SMatthew G. Knepley   Output Parameter:
44560225df5SJacob Faibussowitsch . n - The number of variables, e.g. x, y, z...
44629b5c115SMatthew G. Knepley 
44729b5c115SMatthew G. Knepley   Level: intermediate
44829b5c115SMatthew G. Knepley 
44960225df5SJacob Faibussowitsch .seealso: `PetscSpace`, `PetscSpaceSetNumVariables()`, `PetscSpaceGetNumComponents()`, `PetscSpaceGetDimension()`, `PetscSpaceCreate()`
45029b5c115SMatthew G. Knepley @*/
PetscSpaceGetNumVariables(PetscSpace sp,PetscInt * n)451d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSpaceGetNumVariables(PetscSpace sp, PetscInt *n)
452d71ae5a4SJacob Faibussowitsch {
45320cf1dd8SToby Isaac   PetscFunctionBegin;
45420cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
4554f572ea9SToby Isaac   PetscAssertPointer(n, 2);
45620cf1dd8SToby Isaac   *n = sp->Nv;
4573ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
45820cf1dd8SToby Isaac }
45920cf1dd8SToby Isaac 
460cc4c1da9SBarry Smith /*@
46120cf1dd8SToby Isaac   PetscSpaceEvaluate - Evaluate the basis functions and their derivatives (jet) at each point
46220cf1dd8SToby Isaac 
46320cf1dd8SToby Isaac   Input Parameters:
464dce8aebaSBarry Smith + sp      - The `PetscSpace`
46520cf1dd8SToby Isaac . npoints - The number of evaluation points, in reference coordinates
46620cf1dd8SToby Isaac - points  - The point coordinates
46720cf1dd8SToby Isaac 
46820cf1dd8SToby Isaac   Output Parameters:
469a3b724e8SBarry Smith + B - The function evaluations in a `npoints` x `nfuncs` array
470a3b724e8SBarry Smith . D - The derivative evaluations in a `npoints` x `nfuncs` x `dim` array
471a3b724e8SBarry Smith - H - The second derivative evaluations in a `npoints` x `nfuncs` x `dim` x `dim` array
47220cf1dd8SToby Isaac 
47329b5c115SMatthew G. Knepley   Level: beginner
47420cf1dd8SToby Isaac 
475dce8aebaSBarry Smith   Note:
476a3b724e8SBarry Smith   Above `nfuncs` is the dimension of the space, and `dim` is the spatial dimension. The coordinates are given
477dce8aebaSBarry Smith   on the reference cell, not in real space.
478dce8aebaSBarry Smith 
479dce8aebaSBarry Smith .seealso: `PetscSpace`, `PetscFECreateTabulation()`, `PetscFEGetCellTabulation()`, `PetscSpaceCreate()`
48020cf1dd8SToby Isaac @*/
PetscSpaceEvaluate(PetscSpace sp,PetscInt npoints,const PetscReal points[],PeOp PetscReal B[],PeOp PetscReal D[],PeOp PetscReal H[])481ce78bad3SBarry Smith PetscErrorCode PetscSpaceEvaluate(PetscSpace sp, PetscInt npoints, const PetscReal points[], PeOp PetscReal B[], PeOp PetscReal D[], PeOp PetscReal H[])
482d71ae5a4SJacob Faibussowitsch {
48320cf1dd8SToby Isaac   PetscFunctionBegin;
4843ba16761SJacob Faibussowitsch   if (!npoints) PetscFunctionReturn(PETSC_SUCCESS);
48520cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
4864f572ea9SToby Isaac   if (sp->Nv) PetscAssertPointer(points, 3);
4874f572ea9SToby Isaac   if (B) PetscAssertPointer(B, 4);
4884f572ea9SToby Isaac   if (D) PetscAssertPointer(D, 5);
4894f572ea9SToby Isaac   if (H) PetscAssertPointer(H, 6);
490dbbe0bcdSBarry Smith   PetscTryTypeMethod(sp, evaluate, npoints, points, B, D, H);
4913ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
49220cf1dd8SToby Isaac }
49320cf1dd8SToby Isaac 
49420cf1dd8SToby Isaac /*@
49520cf1dd8SToby Isaac   PetscSpaceGetHeightSubspace - Get the subset of the primal space basis that is supported on a mesh point of a given height.
49620cf1dd8SToby Isaac 
49720f4b53cSBarry Smith   Not Collective
49820cf1dd8SToby Isaac 
49920cf1dd8SToby Isaac   Input Parameters:
50020f4b53cSBarry Smith + sp     - the `PetscSpace` object
50120cf1dd8SToby Isaac - height - the height of the mesh point for which the subspace is desired
50220cf1dd8SToby Isaac 
50320cf1dd8SToby Isaac   Output Parameter:
50420cf1dd8SToby Isaac . subsp - the subspace
50520cf1dd8SToby Isaac 
50620cf1dd8SToby Isaac   Level: advanced
50720cf1dd8SToby Isaac 
508dce8aebaSBarry Smith   Notes:
509dce8aebaSBarry Smith   If the space is not defined on mesh points of the given height (e.g. if the space is discontinuous and
510dce8aebaSBarry Smith   pointwise values are not defined on the element boundaries), or if the implementation of `PetscSpace` does not
511dce8aebaSBarry Smith   support extracting subspaces, then NULL is returned.
512dce8aebaSBarry Smith 
513dce8aebaSBarry Smith   This does not increment the reference count on the returned space, and the user should not destroy it.
514dce8aebaSBarry Smith 
515db781477SPatrick Sanan .seealso: `PetscDualSpaceGetHeightSubspace()`, `PetscSpace`
51620cf1dd8SToby Isaac @*/
PetscSpaceGetHeightSubspace(PetscSpace sp,PetscInt height,PetscSpace * subsp)517d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscSpaceGetHeightSubspace(PetscSpace sp, PetscInt height, PetscSpace *subsp)
518d71ae5a4SJacob Faibussowitsch {
51920cf1dd8SToby Isaac   PetscFunctionBegin;
52020cf1dd8SToby Isaac   PetscValidHeaderSpecific(sp, PETSCSPACE_CLASSID, 1);
5214f572ea9SToby Isaac   PetscAssertPointer(subsp, 3);
52220cf1dd8SToby Isaac   *subsp = NULL;
523dbbe0bcdSBarry Smith   PetscTryTypeMethod(sp, getheightsubspace, height, subsp);
5243ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
52520cf1dd8SToby Isaac }
526