1 #include <../src/ts/characteristic/impls/da/slda.h> /*I "petsccharacteristic.h" I*/ 2 3 #undef __FUNCT__ 4 #define __FUNCT__ "CharacteristicView_DA" 5 PetscErrorCode CharacteristicView_DA(Characteristic c, PetscViewer viewer) 6 { 7 Characteristic_DA *da = (Characteristic_DA*) c->data; 8 PetscBool iascii, isstring; 9 PetscErrorCode ierr; 10 11 PetscFunctionBegin; 12 /* Pull out field names from DM */ 13 ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERASCII, &iascii);CHKERRQ(ierr); 14 ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERSTRING, &isstring);CHKERRQ(ierr); 15 if (iascii) { 16 ierr = PetscViewerASCIIPrintf(viewer," DMDA: dummy=%D\n", da->dummy);CHKERRQ(ierr); 17 } else if (isstring) { 18 ierr = PetscViewerStringSPrintf(viewer,"dummy %D", da->dummy);CHKERRQ(ierr); 19 } 20 PetscFunctionReturn(0); 21 } 22 23 #undef __FUNCT__ 24 #define __FUNCT__ "CharacteristicDestroy_DA" 25 PetscErrorCode CharacteristicDestroy_DA(Characteristic c) 26 { 27 Characteristic_DA *da = (Characteristic_DA*) c->data; 28 PetscErrorCode ierr; 29 30 PetscFunctionBegin; 31 ierr = PetscFree(da);CHKERRQ(ierr); 32 PetscFunctionReturn(0); 33 } 34 35 #undef __FUNCT__ 36 #define __FUNCT__ "CharacteristicSetUp_DA" 37 PetscErrorCode CharacteristicSetUp_DA(Characteristic c) 38 { 39 PetscMPIInt blockLen[2]; 40 MPI_Aint indices[2]; 41 MPI_Datatype oldtypes[2]; 42 PetscInt dim, numValues; 43 PetscErrorCode ierr; 44 45 ierr = DMDAGetInfo(c->velocityDA, &dim, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0,0);CHKERRQ(ierr); 46 if (c->structured) c->numIds = dim; 47 else c->numIds = 3; 48 if (c->numFieldComp > MAX_COMPONENTS) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE, "The maximum number of fields allowed is %d, you have %d. You can recompile after increasing MAX_COMPONENTS.", MAX_COMPONENTS, c->numFieldComp); 49 numValues = 4 + MAX_COMPONENTS; 50 51 /* Create new MPI datatype for communication of characteristic point structs */ 52 blockLen[0] = 1+c->numIds; indices[0] = 0; oldtypes[0] = MPIU_INT; 53 blockLen[1] = numValues; indices[1] = (1+c->numIds)*sizeof(PetscInt); oldtypes[1] = MPIU_SCALAR; 54 ierr = MPI_Type_create_struct(2, blockLen, indices, oldtypes, &c->itemType);CHKERRQ(ierr); 55 ierr = MPI_Type_commit(&c->itemType);CHKERRQ(ierr); 56 57 /* Initialize the local queue for char foot values */ 58 ierr = VecGetLocalSize(c->velocity, &c->queueMax);CHKERRQ(ierr); 59 ierr = PetscMalloc(c->queueMax * sizeof(CharacteristicPointDA2D), &c->queue);CHKERRQ(ierr); 60 c->queueSize = 0; 61 62 /* Allocate communication structures */ 63 if (c->numNeighbors <= 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE, "Invalid number of neighbors %d. Call CharactersiticSetNeighbors() before setup.", c->numNeighbors); 64 ierr = PetscMalloc(c->numNeighbors * sizeof(PetscInt), &c->needCount);CHKERRQ(ierr); 65 ierr = PetscMalloc(c->numNeighbors * sizeof(PetscInt), &c->localOffsets);CHKERRQ(ierr); 66 ierr = PetscMalloc(c->numNeighbors * sizeof(PetscInt), &c->fillCount);CHKERRQ(ierr); 67 ierr = PetscMalloc(c->numNeighbors * sizeof(PetscInt), &c->remoteOffsets);CHKERRQ(ierr); 68 ierr = PetscMalloc((c->numNeighbors-1) * sizeof(MPI_Request), &c->request);CHKERRQ(ierr); 69 ierr = PetscMalloc((c->numNeighbors-1) * sizeof(MPI_Status), &c->status);CHKERRQ(ierr); 70 PetscFunctionReturn(0); 71 } 72 73 EXTERN_C_BEGIN 74 #undef __FUNCT__ 75 #define __FUNCT__ "CharacteristicCreate_DA" 76 PetscErrorCode CharacteristicCreate_DA(Characteristic c) 77 { 78 Characteristic_DA *da; 79 PetscErrorCode ierr; 80 81 PetscFunctionBegin; 82 ierr = PetscNew(Characteristic_DA, &da);CHKERRQ(ierr); 83 ierr = PetscMemzero(da, sizeof(Characteristic_DA));CHKERRQ(ierr); 84 ierr = PetscLogObjectMemory(c, sizeof(Characteristic_DA));CHKERRQ(ierr); 85 c->data = (void*) da; 86 87 c->ops->setup = CharacteristicSetUp_DA; 88 c->ops->destroy = CharacteristicDestroy_DA; 89 c->ops->view = CharacteristicView_DA; 90 91 da->dummy = 0; 92 PetscFunctionReturn(0); 93 } 94 EXTERN_C_END 95 96 #undef __FUNCT__ 97 #define __FUNCT__ "DMDAMapCoordsToPeriodicDomain" 98 /* ----------------------------------------------------------------------------- 99 Checks for periodicity of a DM and Maps points outside of a domain back onto the domain 100 using appropriate periodicity. At the moment assumes only a 2-D DMDA. 101 ----------------------------------------------------------------------------------------*/ 102 PetscErrorCode DMDAMapCoordsToPeriodicDomain(DM da, PetscScalar *x, PetscScalar *y) 103 { 104 DMDABoundaryType bx, by; 105 PetscInt dim, gx, gy; 106 PetscErrorCode ierr; 107 108 PetscFunctionBegin; 109 ierr = DMDAGetInfo(da, &dim, &gx, &gy, 0, 0, 0, 0, 0, 0, &bx, &by, 0, 0); 110 111 if (bx == DMDA_BOUNDARY_PERIODIC) { 112 while (*x >= (PetscScalar)gx) *x -= (PetscScalar)gx; 113 while (*x < 0.0) *x += (PetscScalar)gx; 114 } 115 if (by == DMDA_BOUNDARY_PERIODIC) { 116 while (*y >= (PetscScalar)gy) *y -= (PetscScalar)gy; 117 while (*y < 0.0) *y += (PetscScalar)gy; 118 } 119 PetscFunctionReturn(ierr); 120 } 121