1 #define PETSCDM_DLL 2 #include "private/daimpl.h" /*I "petscda.h" I*/ 3 4 #undef __FUNCT__ 5 #define __FUNCT__ "DAViewFromOptions" 6 /*@ 7 DAViewFromOptions - This function visualizes the DA based upon user options. 8 9 Collective on DA 10 11 Input Parameters: 12 + da - The DA 13 - title - The title (currently ignored) 14 15 Level: intermediate 16 17 .keywords: DA, view, options, database 18 .seealso: DASetFromOptions(), DAView() 19 @*/ 20 PetscErrorCode PETSCDM_DLLEXPORT DAViewFromOptions(DA da, const char title[]) 21 { 22 PetscErrorCode ierr; 23 24 PetscFunctionBegin; 25 ierr = DAView_Private(da);CHKERRQ(ierr); 26 PetscFunctionReturn(0); 27 } 28 29 #undef __FUNCT__ 30 #define __FUNCT__ "DASetTypeFromOptions_Private" 31 /* 32 DASetTypeFromOptions_Private - Sets the type of DA from user options. Defaults to a 1D DA. 33 34 Collective on Vec 35 36 Input Parameter: 37 . da - The DA 38 39 Level: intermediate 40 41 .keywords: DA, set, options, database, type 42 .seealso: DASetFromOptions(), DASetType() 43 */ 44 static PetscErrorCode DASetTypeFromOptions_Private(DA da) 45 { 46 const DAType defaultType = DA1D; 47 char typeName[256]; 48 PetscBool opt = PETSC_FALSE; 49 PetscErrorCode ierr; 50 DM_DA *dd = (DM_DA*)da->data; 51 52 PetscFunctionBegin; 53 switch (dd->dim) { 54 case 1: defaultType = DA1D; break; 55 case 2: defaultType = DA2D; break; 56 case 3: defaultType = DA3D; break; 57 } 58 if (((PetscObject)da)->type_name) { 59 defaultType = ((PetscObject)da)->type_name; 60 } 61 if (!DARegisterAllCalled) {ierr = DARegisterAll(PETSC_NULL);CHKERRQ(ierr);} 62 if (dd->dim == PETSC_DECIDE) { 63 ierr = PetscOptionsList("-da_type","DA type","DASetType",DAList,defaultType,typeName,256,&opt);CHKERRQ(ierr); 64 } 65 if (opt) { 66 ierr = DASetType(da, typeName);CHKERRQ(ierr); 67 } else { 68 ierr = DASetType(da, defaultType);CHKERRQ(ierr); 69 } 70 PetscFunctionReturn(0); 71 } 72 73 #undef __FUNCT__ 74 #define __FUNCT__ "DASetFromOptions" 75 /*@ 76 DASetFromOptions - Configures the vector from the options database. 77 78 Collective on DA 79 80 Input Parameter: 81 . da - The DA 82 83 Notes: To see all options, run your program with the -help option, or consult the <A href="../../docs/manual.pdf">Users Manual</A>. 84 Must be called after DACreate() but before the DA is used. 85 86 Level: beginner 87 88 Concepts: DA^setting options 89 Concepts: DA^setting type 90 91 .keywords: DA, set, options, database 92 .seealso: DACreate(), DASetOptionsPrefix() 93 @*/ 94 PetscErrorCode PETSCDM_DLLEXPORT DASetFromOptions(DA da) 95 { 96 PetscErrorCode ierr; 97 PetscBool flg; 98 char typeName[256]; 99 DM_DA *dd = (DM_DA*)da->data; 100 101 PetscFunctionBegin; 102 PetscValidHeaderSpecific(da,DM_CLASSID,1); 103 104 ierr = PetscOptionsBegin(((PetscObject)da)->comm,((PetscObject)da)->prefix,"DA Options","DA");CHKERRQ(ierr); 105 /* Handle DA grid sizes */ 106 if (dd->M < 0) { 107 PetscInt newM = -dd->M; 108 ierr = PetscOptionsInt("-da_grid_x","Number of grid points in x direction","DASetSizes",newM,&newM,PETSC_NULL);CHKERRQ(ierr); 109 dd->M = newM; 110 } 111 if (dd->dim > 1 && dd->N < 0) { 112 PetscInt newN = -dd->N; 113 ierr = PetscOptionsInt("-da_grid_y","Number of grid points in y direction","DASetSizes",newN,&newN,PETSC_NULL);CHKERRQ(ierr); 114 dd->N = newN; 115 } 116 if (dd->dim > 2 && dd->P < 0) { 117 PetscInt newP = -dd->P; 118 ierr = PetscOptionsInt("-da_grid_z","Number of grid points in z direction","DASetSizes",newP,&newP,PETSC_NULL);CHKERRQ(ierr); 119 dd->P = newP; 120 } 121 /* Handle DA parallel distibution */ 122 ierr = PetscOptionsInt("-da_processors_x","Number of processors in x direction","DASetNumProcs",dd->m,&dd->m,PETSC_NULL);CHKERRQ(ierr); 123 if (dd->dim > 1) {ierr = PetscOptionsInt("-da_processors_y","Number of processors in y direction","DASetNumProcs",dd->n,&dd->n,PETSC_NULL);CHKERRQ(ierr);} 124 if (dd->dim > 2) {ierr = PetscOptionsInt("-da_processors_z","Number of processors in z direction","DASetNumProcs",dd->p,&dd->p,PETSC_NULL);CHKERRQ(ierr);} 125 /* Handle DA refinement */ 126 ierr = PetscOptionsInt("-da_refine_x","Refinement ratio in x direction","DASetRefinementFactor",dd->refine_x,&dd->refine_x,PETSC_NULL);CHKERRQ(ierr); 127 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);} 128 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);} 129 /* Handle DA type options; only makes sense to call if dimension has not yet been set */ 130 ierr = DASetTypeFromOptions_Private(da);CHKERRQ(ierr); 131 132 if (!VecRegisterAllCalled) {ierr = VecRegisterAll(PETSC_NULL);CHKERRQ(ierr);} 133 ierr = PetscOptionsList("-da_vec_type","Vector type used for created vectors","DASetVecType",VecList,da->vectype,typeName,256,&flg);CHKERRQ(ierr); 134 if (flg) { 135 ierr = DASetVecType(da,typeName);CHKERRQ(ierr); 136 } 137 138 /* Handle specific DA options */ 139 if (da->ops->setfromoptions) { 140 ierr = (*da->ops->setfromoptions)(da);CHKERRQ(ierr); 141 } 142 143 /* process any options handlers added with PetscObjectAddOptionsHandler() */ 144 ierr = PetscObjectProcessOptionsHandlers((PetscObject)da);CHKERRQ(ierr); 145 ierr = PetscOptionsEnd();CHKERRQ(ierr); 146 147 ierr = DAViewFromOptions(da, ((PetscObject)da)->name);CHKERRQ(ierr); 148 PetscFunctionReturn(0); 149 } 150 151 #undef __FUNCT__ 152 #define __FUNCT__ "DACreate" 153 /*@ 154 DACreate - Creates an empty DA object. The type can then be set with DASetType(), 155 or DASetFromOptions(). 156 157 If you never call DASetType() or DASetFromOptions() it will generate an 158 error when you try to use the DA. 159 160 Collective on MPI_Comm 161 162 Input Parameter: 163 . comm - The communicator for the DA object 164 165 Output Parameter: 166 . da - The DA object 167 168 Level: beginner 169 170 .keywords: DA, create 171 .seealso: DASetType(), DASetSizes(), DADuplicate() 172 @*/ 173 PetscErrorCode PETSCDM_DLLEXPORT DACreate(MPI_Comm comm, DA *da) 174 { 175 DA d; 176 PetscErrorCode ierr; 177 DM_DA *dd; 178 179 PetscFunctionBegin; 180 PetscValidPointer(da,2); 181 *da = PETSC_NULL; 182 #ifndef PETSC_USE_DYNAMIC_LIBRARIES 183 ierr = DMInitializePackage(PETSC_NULL);CHKERRQ(ierr); 184 #endif 185 186 ierr = PetscHeaderCreate(d, _p_DM, struct _DMOps, DM_CLASSID, 0, "DM", comm, DMDestroy, DMView);CHKERRQ(ierr); 187 ierr = PetscMemzero(d->ops, sizeof(struct _DMOps));CHKERRQ(ierr); 188 ierr = PetscNewLog(d,DM_DA,&dd);CHKERRQ(ierr); 189 d->data = dd; 190 191 dd->dim = -1; 192 dd->interptype = DA_Q1; 193 dd->refine_x = 2; 194 dd->refine_y = 2; 195 dd->refine_z = 2; 196 dd->fieldname = PETSC_NULL; 197 dd->nlocal = -1; 198 dd->Nlocal = -1; 199 dd->M = -1; 200 dd->N = -1; 201 dd->P = -1; 202 dd->m = -1; 203 dd->n = -1; 204 dd->p = -1; 205 dd->w = -1; 206 dd->s = -1; 207 dd->xs = -1; dd->xe = -1; dd->ys = -1; dd->ye = -1; dd->zs = -1; dd->ze = -1; 208 dd->Xs = -1; dd->Xe = -1; dd->Ys = -1; dd->Ye = -1; dd->Zs = -1; dd->Ze = -1; 209 210 dd->gtol = PETSC_NULL; 211 dd->ltog = PETSC_NULL; 212 dd->ltol = PETSC_NULL; 213 dd->ltogmap = PETSC_NULL; 214 dd->ltogmapb = PETSC_NULL; 215 dd->ao = PETSC_NULL; 216 dd->base = -1; 217 dd->wrap = DA_NONPERIODIC; 218 dd->stencil_type = DA_STENCIL_BOX; 219 dd->interptype = DA_Q1; 220 dd->idx = PETSC_NULL; 221 dd->Nl = -1; 222 dd->lx = PETSC_NULL; 223 dd->ly = PETSC_NULL; 224 dd->lz = PETSC_NULL; 225 226 ierr = PetscStrallocpy(VECSTANDARD,&d->vectype);CHKERRQ(ierr); 227 d->ops->globaltolocalbegin = DAGlobalToLocalBegin; 228 d->ops->globaltolocalend = DAGlobalToLocalEnd; 229 d->ops->localtoglobal = DALocalToGlobal; 230 d->ops->createglobalvector = DACreateGlobalVector; 231 d->ops->createlocalvector = DACreateLocalVector; 232 d->ops->getinterpolation = DAGetInterpolation; 233 d->ops->getcoloring = DAGetColoring; 234 d->ops->getmatrix = DAGetMatrix; 235 d->ops->refine = DARefine; 236 d->ops->coarsen = DACoarsen; 237 d->ops->refinehierarchy = DARefineHierarchy; 238 d->ops->coarsenhierarchy = DACoarsenHierarchy; 239 d->ops->getinjection = DAGetInjection; 240 d->ops->getaggregates = DAGetAggregates; 241 d->ops->destroy = DADestroy; 242 d->ops->view = DAView; 243 244 *da = d; 245 PetscFunctionReturn(0); 246 } 247