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__ "DASetFromOptions" 31 /*@ 32 DASetFromOptions - Configures the vector from the options database. 33 34 Collective on DA 35 36 Input Parameter: 37 . da - The DA 38 39 Notes: To see all options, run your program with the -help option, or consult the <A href="../../docs/manual.pdf">Users Manual</A>. 40 Must be called after DACreate() but before the DA is used. 41 42 Level: beginner 43 44 Concepts: DA^setting options 45 Concepts: DA^setting type 46 47 .keywords: DA, set, options, database 48 .seealso: DACreate(), DASetOptionsPrefix() 49 @*/ 50 PetscErrorCode PETSCDM_DLLEXPORT DASetFromOptions(DA da) 51 { 52 PetscErrorCode ierr; 53 PetscBool flg; 54 char typeName[256]; 55 DM_DA *dd = (DM_DA*)da->data; 56 57 PetscFunctionBegin; 58 PetscValidHeaderSpecific(da,DM_CLASSID,1); 59 60 ierr = PetscOptionsBegin(((PetscObject)da)->comm,((PetscObject)da)->prefix,"DA Options","DA");CHKERRQ(ierr); 61 /* Handle DA grid sizes */ 62 if (dd->M < 0) { 63 PetscInt newM = -dd->M; 64 ierr = PetscOptionsInt("-da_grid_x","Number of grid points in x direction","DASetSizes",newM,&newM,PETSC_NULL);CHKERRQ(ierr); 65 dd->M = newM; 66 } 67 if (dd->dim > 1 && dd->N < 0) { 68 PetscInt newN = -dd->N; 69 ierr = PetscOptionsInt("-da_grid_y","Number of grid points in y direction","DASetSizes",newN,&newN,PETSC_NULL);CHKERRQ(ierr); 70 dd->N = newN; 71 } 72 if (dd->dim > 2 && dd->P < 0) { 73 PetscInt newP = -dd->P; 74 ierr = PetscOptionsInt("-da_grid_z","Number of grid points in z direction","DASetSizes",newP,&newP,PETSC_NULL);CHKERRQ(ierr); 75 dd->P = newP; 76 } 77 /* Handle DA parallel distibution */ 78 ierr = PetscOptionsInt("-da_processors_x","Number of processors in x direction","DASetNumProcs",dd->m,&dd->m,PETSC_NULL);CHKERRQ(ierr); 79 if (dd->dim > 1) {ierr = PetscOptionsInt("-da_processors_y","Number of processors in y direction","DASetNumProcs",dd->n,&dd->n,PETSC_NULL);CHKERRQ(ierr);} 80 if (dd->dim > 2) {ierr = PetscOptionsInt("-da_processors_z","Number of processors in z direction","DASetNumProcs",dd->p,&dd->p,PETSC_NULL);CHKERRQ(ierr);} 81 /* Handle DA refinement */ 82 ierr = PetscOptionsInt("-da_refine_x","Refinement ratio in x direction","DASetRefinementFactor",dd->refine_x,&dd->refine_x,PETSC_NULL);CHKERRQ(ierr); 83 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);} 84 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);} 85 86 if (!VecRegisterAllCalled) {ierr = VecRegisterAll(PETSC_NULL);CHKERRQ(ierr);} 87 ierr = PetscOptionsList("-da_vec_type","Vector type used for created vectors","DASetVecType",VecList,da->vectype,typeName,256,&flg);CHKERRQ(ierr); 88 if (flg) { 89 ierr = DASetVecType(da,typeName);CHKERRQ(ierr); 90 } 91 92 /* process any options handlers added with PetscObjectAddOptionsHandler() */ 93 ierr = PetscObjectProcessOptionsHandlers((PetscObject)da);CHKERRQ(ierr); 94 ierr = PetscOptionsEnd();CHKERRQ(ierr); 95 96 ierr = DAViewFromOptions(da, ((PetscObject)da)->name);CHKERRQ(ierr); 97 PetscFunctionReturn(0); 98 } 99 100 #undef __FUNCT__ 101 #define __FUNCT__ "DACreate" 102 /*@ 103 DACreate - Creates a DA object. 104 105 Collective on MPI_Comm 106 107 Input Parameter: 108 . comm - The communicator for the DA object 109 110 Output Parameter: 111 . da - The DA object 112 113 Level: beginner 114 115 .keywords: DA, create 116 .seealso: DASetSizes(), DADuplicate() 117 @*/ 118 PetscErrorCode PETSCDM_DLLEXPORT DACreate(MPI_Comm comm, DA *da) 119 { 120 DA d; 121 PetscErrorCode ierr; 122 DM_DA *dd; 123 124 PetscFunctionBegin; 125 PetscValidPointer(da,2); 126 *da = PETSC_NULL; 127 #ifndef PETSC_USE_DYNAMIC_LIBRARIES 128 ierr = DMInitializePackage(PETSC_NULL);CHKERRQ(ierr); 129 #endif 130 131 ierr = PetscHeaderCreate(d, _p_DM, struct _DMOps, DM_CLASSID, 0, "DM", comm, DMDestroy, DMView);CHKERRQ(ierr); 132 ierr = PetscMemzero(d->ops, sizeof(struct _DMOps));CHKERRQ(ierr); 133 ierr = PetscNewLog(d,DM_DA,&dd);CHKERRQ(ierr); 134 d->data = dd; 135 136 dd->dim = -1; 137 dd->interptype = DA_Q1; 138 dd->refine_x = 2; 139 dd->refine_y = 2; 140 dd->refine_z = 2; 141 dd->fieldname = PETSC_NULL; 142 dd->nlocal = -1; 143 dd->Nlocal = -1; 144 dd->M = -1; 145 dd->N = -1; 146 dd->P = -1; 147 dd->m = -1; 148 dd->n = -1; 149 dd->p = -1; 150 dd->w = -1; 151 dd->s = -1; 152 dd->xs = -1; dd->xe = -1; dd->ys = -1; dd->ye = -1; dd->zs = -1; dd->ze = -1; 153 dd->Xs = -1; dd->Xe = -1; dd->Ys = -1; dd->Ye = -1; dd->Zs = -1; dd->Ze = -1; 154 155 dd->gtol = PETSC_NULL; 156 dd->ltog = PETSC_NULL; 157 dd->ltol = PETSC_NULL; 158 dd->ltogmap = PETSC_NULL; 159 dd->ltogmapb = PETSC_NULL; 160 dd->ao = PETSC_NULL; 161 dd->base = -1; 162 dd->wrap = DA_NONPERIODIC; 163 dd->stencil_type = DA_STENCIL_BOX; 164 dd->interptype = DA_Q1; 165 dd->idx = PETSC_NULL; 166 dd->Nl = -1; 167 dd->lx = PETSC_NULL; 168 dd->ly = PETSC_NULL; 169 dd->lz = PETSC_NULL; 170 171 ierr = PetscStrallocpy(VECSTANDARD,&d->vectype);CHKERRQ(ierr); 172 d->ops->globaltolocalbegin = DAGlobalToLocalBegin; 173 d->ops->globaltolocalend = DAGlobalToLocalEnd; 174 d->ops->localtoglobal = DALocalToGlobal; 175 d->ops->createglobalvector = DACreateGlobalVector; 176 d->ops->createlocalvector = DACreateLocalVector; 177 d->ops->getinterpolation = DAGetInterpolation; 178 d->ops->getcoloring = DAGetColoring; 179 d->ops->getmatrix = DAGetMatrix; 180 d->ops->refine = DARefine; 181 d->ops->coarsen = DACoarsen; 182 d->ops->refinehierarchy = DARefineHierarchy; 183 d->ops->coarsenhierarchy = DACoarsenHierarchy; 184 d->ops->getinjection = DAGetInjection; 185 d->ops->getaggregates = DAGetAggregates; 186 d->ops->destroy = DADestroy; 187 d->ops->view = DAView; 188 d->ops->setfromoptions = DASetFromOptions; 189 d->ops->setup = DASetUp; 190 191 *da = d; 192 PetscFunctionReturn(0); 193 } 194