xref: /petsc/src/vec/is/ao/interface/aoreg.c (revision af0996ce37bc06907c37d8d91773840993d61e62)
1 
2 #include <../src/vec/is/ao/aoimpl.h>    /*I "petscao.h"  I*/
3 
4 PetscFunctionList AOList              = NULL;
5 PetscBool         AORegisterAllCalled = PETSC_FALSE;
6 
7 #undef __FUNCT__
8 #define __FUNCT__ "AOSetType"
9 /*@C
10   AOSetType - Builds an application ordering for a particular implementation.
11 
12   Collective on AO
13 
14   Input Parameters:
15 + ao    - The AO object
16 - method - The name of the AO type
17 
18   Options Database Key:
19 . -ao_type <type> - Sets the AO type; use -help for a list of available types
20 
21   Notes:
22   See "petsc/include/petscao.h" for available AO types (for instance, AOBASIC and AOMEMORYSCALABLE).
23 
24   Level: intermediate
25 
26 .keywords: ao, set, type
27 .seealso: AOGetType(), AOCreate()
28 @*/
29 PetscErrorCode  AOSetType(AO ao, AOType method)
30 {
31   PetscErrorCode (*r)(AO);
32   PetscBool      match;
33   PetscErrorCode ierr;
34 
35   PetscFunctionBegin;
36   PetscValidHeaderSpecific(ao, AO_CLASSID,1);
37   ierr = PetscObjectTypeCompare((PetscObject)ao, method, &match);CHKERRQ(ierr);
38   if (match) PetscFunctionReturn(0);
39 
40   ierr = AORegisterAll();CHKERRQ(ierr);
41   ierr = PetscFunctionListFind(AOList,method,&r);CHKERRQ(ierr);
42   if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown AO type: %s", method);
43   if (ao->ops->destroy) {
44     ierr             = (*ao->ops->destroy)(ao);CHKERRQ(ierr);
45     ao->ops->destroy = NULL;
46   }
47 
48   ierr = (*r)(ao);CHKERRQ(ierr);
49   PetscFunctionReturn(0);
50 }
51 
52 #undef __FUNCT__
53 #define __FUNCT__ "AOGetType"
54 /*@C
55   AOGetType - Gets the AO type name (as a string) from the AO.
56 
57   Not Collective
58 
59   Input Parameter:
60 . ao  - The vector
61 
62   Output Parameter:
63 . type - The AO type name
64 
65   Level: intermediate
66 
67 .keywords: ao, get, type, name
68 .seealso: AOSetType(), AOCreate()
69 @*/
70 PetscErrorCode  AOGetType(AO ao, AOType *type)
71 {
72   PetscErrorCode ierr;
73 
74   PetscFunctionBegin;
75   PetscValidHeaderSpecific(ao, AO_CLASSID,1);
76   PetscValidPointer(type,2);
77   ierr = AORegisterAll();CHKERRQ(ierr);
78   *type = ((PetscObject)ao)->type_name;
79   PetscFunctionReturn(0);
80 }
81 
82 
83 /*--------------------------------------------------------------------------------------------------------------------*/
84 
85 #undef __FUNCT__
86 #define __FUNCT__ "AORegister"
87 /*@C
88   AORegister -
89 
90   Level: advanced
91 @*/
92 PetscErrorCode  AORegister(const char sname[], PetscErrorCode (*function)(AO))
93 {
94   PetscErrorCode ierr;
95 
96   PetscFunctionBegin;
97   ierr = PetscFunctionListAdd(&AOList,sname,function);CHKERRQ(ierr);
98   PetscFunctionReturn(0);
99 }
100 
101 
102