xref: /petsc/src/dm/interface/dmceed.c (revision 9371c9d470a9602b6d10a8bf50c9b2280a79e45a)
1 #include <petsc/private/dmimpl.h> /*I      "petscdm.h"          I*/
2 
3 #ifdef PETSC_HAVE_LIBCEED
4 #include <petscdmceed.h>
5 
6 /*@C
7   DMGetCeed - Get the LibCEED context associated with this DM
8 
9   Not collective
10 
11   Input Parameter:
12 . DM   - The DM
13 
14   Output Parameter:
15 . ceed - The LibCEED context
16 
17   Level: intermediate
18 
19 .seealso: `DMCreate()`
20 @*/
21 PetscErrorCode DMGetCeed(DM dm, Ceed *ceed) {
22   PetscFunctionBegin;
23   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
24   PetscValidPointer(ceed, 2);
25   if (!dm->ceed) {
26     char        ceedresource[PETSC_MAX_PATH_LEN]; /* libCEED resource specifier */
27     const char *prefix;
28 
29     PetscCall(PetscStrcpy(ceedresource, "/cpu/self"));
30     PetscCall(PetscObjectGetOptionsPrefix((PetscObject)dm, &prefix));
31     PetscCall(PetscOptionsGetString(NULL, prefix, "-dm_ceed", ceedresource, sizeof(ceedresource), NULL));
32     PetscCallCEED(CeedInit(ceedresource, &dm->ceed));
33   }
34   *ceed = dm->ceed;
35   PetscFunctionReturn(0);
36 }
37 
38 #endif
39