xref: /petsc/src/dm/impls/da/dacreate.c (revision 564755cd2444013b9df4620f3ca4ef575626a108)
1 #define PETSCDM_DLL
2 #include "private/daimpl.h"    /*I   "petscda.h"   I*/
3 
4 #undef __FUNCT__
5 #define __FUNCT__ "DMSetFromOptions_DA"
6 PetscErrorCode PETSCDM_DLLEXPORT DMSetFromOptions_DA(DM da)
7 {
8   PetscErrorCode ierr;
9   PetscBool      flg;
10   char           typeName[256];
11   DM_DA          *dd = (DM_DA*)da->data;
12 
13   PetscFunctionBegin;
14   PetscValidHeaderSpecific(da,DM_CLASSID,1);
15 
16   ierr = PetscOptionsBegin(((PetscObject)da)->comm,((PetscObject)da)->prefix,"DA Options","DA");CHKERRQ(ierr);
17     /* Handle DA grid sizes */
18     if (dd->M < 0) {
19       PetscInt newM = -dd->M;
20       ierr = PetscOptionsInt("-da_grid_x","Number of grid points in x direction","DASetSizes",newM,&newM,PETSC_NULL);CHKERRQ(ierr);
21       dd->M = newM;
22     }
23     if (dd->dim > 1 && dd->N < 0) {
24       PetscInt newN = -dd->N;
25       ierr = PetscOptionsInt("-da_grid_y","Number of grid points in y direction","DASetSizes",newN,&newN,PETSC_NULL);CHKERRQ(ierr);
26       dd->N = newN;
27     }
28     if (dd->dim > 2 && dd->P < 0) {
29       PetscInt newP = -dd->P;
30       ierr = PetscOptionsInt("-da_grid_z","Number of grid points in z direction","DASetSizes",newP,&newP,PETSC_NULL);CHKERRQ(ierr);
31       dd->P = newP;
32     }
33     /* Handle DA parallel distibution */
34     ierr = PetscOptionsInt("-da_processors_x","Number of processors in x direction","DASetNumProcs",dd->m,&dd->m,PETSC_NULL);CHKERRQ(ierr);
35     if (dd->dim > 1) {ierr = PetscOptionsInt("-da_processors_y","Number of processors in y direction","DASetNumProcs",dd->n,&dd->n,PETSC_NULL);CHKERRQ(ierr);}
36     if (dd->dim > 2) {ierr = PetscOptionsInt("-da_processors_z","Number of processors in z direction","DASetNumProcs",dd->p,&dd->p,PETSC_NULL);CHKERRQ(ierr);}
37     /* Handle DA refinement */
38     ierr = PetscOptionsInt("-da_refine_x","Refinement ratio in x direction","DASetRefinementFactor",dd->refine_x,&dd->refine_x,PETSC_NULL);CHKERRQ(ierr);
39     if (dd->dim > 1) {ierr = PetscOptionsInt("-da_refine_y","Refinement ratio in y direction","DASetRefinementFactor",dd->refine_y,&dd->refine_y,PETSC_NULL);CHKERRQ(ierr);}
40     if (dd->dim > 2) {ierr = PetscOptionsInt("-da_refine_z","Refinement ratio in z direction","DASetRefinementFactor",dd->refine_z,&dd->refine_z,PETSC_NULL);CHKERRQ(ierr);}
41 
42     if (!VecRegisterAllCalled) {ierr = VecRegisterAll(PETSC_NULL);CHKERRQ(ierr);}
43     ierr = PetscOptionsList("-da_vec_type","Vector type used for created vectors","DMSetVecType",VecList,da->vectype,typeName,256,&flg);CHKERRQ(ierr);
44     if (flg) {
45       ierr = DMSetVecType(da,typeName);CHKERRQ(ierr);
46     }
47 
48     /* process any options handlers added with PetscObjectAddOptionsHandler() */
49     ierr = PetscObjectProcessOptionsHandlers((PetscObject)da);CHKERRQ(ierr);
50   ierr = PetscOptionsEnd();CHKERRQ(ierr);
51 
52   PetscFunctionReturn(0);
53 }
54 
55 extern PetscErrorCode PETSCDM_DLLEXPORT DMCreateGlobalVector_DA(DM,Vec*);
56 extern PetscErrorCode PETSCDM_DLLEXPORT DMCreateLocalVector_DA(DM,Vec*);
57 extern PetscErrorCode PETSCDM_DLLEXPORT DMGlobalToLocalBegin_DA(DM,Vec,InsertMode,Vec);
58 extern PetscErrorCode PETSCDM_DLLEXPORT DMGlobalToLocalEnd_DA(DM,Vec,InsertMode,Vec);
59 extern PetscErrorCode PETSCDM_DLLEXPORT DMLocalToGlobalBegin_DA(DM,Vec,InsertMode,Vec);
60 extern PetscErrorCode PETSCDM_DLLEXPORT DMLocalToGlobalEnd_DA(DM,Vec,InsertMode,Vec);
61 extern PetscErrorCode PETSCDM_DLLEXPORT DMView_DA(DM,PetscViewer);
62 extern PetscErrorCode PETSCDM_DLLEXPORT DMSetUp_DA(DM);
63 extern PetscErrorCode PETSCDM_DLLEXPORT DMDestroy_DA(DM);
64 
65 #undef __FUNCT__
66 #define __FUNCT__ "DACreate"
67 /*@
68   DACreate - Creates a DA object.
69 
70   Collective on MPI_Comm
71 
72   Input Parameter:
73 . comm - The communicator for the DA object
74 
75   Output Parameter:
76 . da  - The DA object
77 
78   Level: beginner
79 
80 .keywords: DA, create
81 .seealso:  DASetSizes(), DADuplicate()
82 @*/
83 PetscErrorCode PETSCDM_DLLEXPORT DACreate(MPI_Comm comm, DM *da)
84 {
85   DM             d;
86   PetscErrorCode ierr;
87   DM_DA          *dd;
88 
89   PetscFunctionBegin;
90   PetscValidPointer(da,2);
91   *da = PETSC_NULL;
92 #ifndef PETSC_USE_DYNAMIC_LIBRARIES
93   ierr = DMInitializePackage(PETSC_NULL);CHKERRQ(ierr);
94 #endif
95 
96   ierr = PetscHeaderCreate(d, _p_DM, struct _DMOps, DM_CLASSID, 0, "DM", comm, DMDestroy, DMView);CHKERRQ(ierr);
97   ierr = PetscMemzero(d->ops, sizeof(struct _DMOps));CHKERRQ(ierr);
98   ierr = PetscNewLog(d,DM_DA,&dd);CHKERRQ(ierr);
99   d->data = dd;
100 
101   dd->dim        = -1;
102   dd->interptype = DA_Q1;
103   dd->refine_x   = 2;
104   dd->refine_y   = 2;
105   dd->refine_z   = 2;
106   dd->fieldname  = PETSC_NULL;
107   dd->nlocal     = -1;
108   dd->Nlocal     = -1;
109   dd->M          = -1;
110   dd->N          = -1;
111   dd->P          = -1;
112   dd->m          = -1;
113   dd->n          = -1;
114   dd->p          = -1;
115   dd->w          = -1;
116   dd->s          = -1;
117   dd->xs = -1; dd->xe = -1; dd->ys = -1; dd->ye = -1; dd->zs = -1; dd->ze = -1;
118   dd->Xs = -1; dd->Xe = -1; dd->Ys = -1; dd->Ye = -1; dd->Zs = -1; dd->Ze = -1;
119 
120   dd->gtol         = PETSC_NULL;
121   dd->ltog         = PETSC_NULL;
122   dd->ltol         = PETSC_NULL;
123   dd->ltogmap      = PETSC_NULL;
124   dd->ltogmapb     = PETSC_NULL;
125   dd->ao           = PETSC_NULL;
126   dd->base         = -1;
127   dd->wrap         = DA_NONPERIODIC;
128   dd->stencil_type = DA_STENCIL_BOX;
129   dd->interptype   = DA_Q1;
130   dd->idx          = PETSC_NULL;
131   dd->Nl           = -1;
132   dd->lx           = PETSC_NULL;
133   dd->ly           = PETSC_NULL;
134   dd->lz           = PETSC_NULL;
135 
136   ierr = PetscStrallocpy(VECSTANDARD,&d->vectype);CHKERRQ(ierr);
137   d->ops->globaltolocalbegin = DMGlobalToLocalBegin_DA;
138   d->ops->globaltolocalend   = DMGlobalToLocalEnd_DA;
139   d->ops->localtoglobalbegin = DMLocalToGlobalBegin_DA;
140   d->ops->localtoglobalend   = DMLocalToGlobalEnd_DA;
141   d->ops->createglobalvector = DMCreateGlobalVector_DA;
142   d->ops->createlocalvector  = DMCreateLocalVector_DA;
143   d->ops->getinterpolation   = DAGetInterpolation;
144   d->ops->getcoloring        = DAGetColoring;
145   d->ops->getmatrix          = DAGetMatrix;
146   d->ops->refine             = DARefine;
147   d->ops->coarsen            = DACoarsen;
148   d->ops->refinehierarchy    = DARefineHierarchy;
149   d->ops->coarsenhierarchy   = DACoarsenHierarchy;
150   d->ops->getinjection       = DAGetInjection;
151   d->ops->getaggregates      = DAGetAggregates;
152   d->ops->destroy            = DMDestroy_DA;
153   d->ops->view               = 0;
154   d->ops->setfromoptions     = DMSetFromOptions_DA;
155   d->ops->setup              = DMSetUp_DA;
156 
157   *da = d;
158   PetscFunctionReturn(0);
159 }
160