| misc.c (77ad9f2917358ad654845919921e911aaeeffe6e) | misc.c (d99fa3c5cd91a1690aedf0679cbf290d44fec74c) |
|---|---|
| 1// Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at 2// the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights 3// reserved. See files LICENSE and NOTICE for details. 4// 5// This file is part of CEED, a collection of benchmarks, miniapps, software 6// libraries and APIs for efficient high-order finite element and spectral 7// element discretizations for exascale applications. For more information and 8// source code availability see http://github.com/ceed. --- 61 unchanged lines hidden (view full) --- 70}; 71 72// Setup context data for prolongation and restriction operators 73PetscErrorCode SetupProlongRestrictCtx(MPI_Comm comm, AppCtx appCtx, DM dmC, 74 DM dmF, Vec VF, Vec VlocC, Vec VlocF, 75 CeedData ceedDataC, CeedData ceedDataF, 76 Ceed ceed, 77 UserMultProlongRestr prolongRestrCtx) { | 1// Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at 2// the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights 3// reserved. See files LICENSE and NOTICE for details. 4// 5// This file is part of CEED, a collection of benchmarks, miniapps, software 6// libraries and APIs for efficient high-order finite element and spectral 7// element discretizations for exascale applications. For more information and 8// source code availability see http://github.com/ceed. --- 61 unchanged lines hidden (view full) --- 70}; 71 72// Setup context data for prolongation and restriction operators 73PetscErrorCode SetupProlongRestrictCtx(MPI_Comm comm, AppCtx appCtx, DM dmC, 74 DM dmF, Vec VF, Vec VlocC, Vec VlocF, 75 CeedData ceedDataC, CeedData ceedDataF, 76 Ceed ceed, 77 UserMultProlongRestr prolongRestrCtx) { |
| 78 PetscErrorCode ierr; 79 PetscScalar *multArray; 80 | |
| 81 PetscFunctionBeginUser; 82 83 // PETSc objects 84 prolongRestrCtx->comm = comm; 85 prolongRestrCtx->dmC = dmC; 86 prolongRestrCtx->dmF = dmF; 87 88 // Work vectors --- 18 unchanged lines hidden (view full) --- 107 prolongRestrCtx->VecRestoreArrayRead = VecRestoreArrayRead; 108 } else { 109 prolongRestrCtx->VecGetArray = VecCUDAGetArray; 110 prolongRestrCtx->VecGetArrayRead = VecCUDAGetArrayRead; 111 prolongRestrCtx->VecRestoreArray = VecCUDARestoreArray; 112 prolongRestrCtx->VecRestoreArrayRead = VecCUDARestoreArrayRead; 113 } 114 | 78 PetscFunctionBeginUser; 79 80 // PETSc objects 81 prolongRestrCtx->comm = comm; 82 prolongRestrCtx->dmC = dmC; 83 prolongRestrCtx->dmF = dmF; 84 85 // Work vectors --- 18 unchanged lines hidden (view full) --- 104 prolongRestrCtx->VecRestoreArrayRead = VecRestoreArrayRead; 105 } else { 106 prolongRestrCtx->VecGetArray = VecCUDAGetArray; 107 prolongRestrCtx->VecGetArrayRead = VecCUDAGetArrayRead; 108 prolongRestrCtx->VecRestoreArray = VecCUDARestoreArray; 109 prolongRestrCtx->VecRestoreArrayRead = VecCUDARestoreArrayRead; 110 } 111 |
| 115 // Multiplicity vector 116 // -- Set libCEED vector 117 ierr = VecZeroEntries(VlocF); 118 ierr = prolongRestrCtx->VecGetArray(VlocF, &multArray); CHKERRQ(ierr); 119 CeedVectorSetArray(ceedDataF->xceed, appCtx->memTypeRequested, 120 CEED_USE_POINTER, multArray); 121 122 // -- Compute multiplicity 123 CeedElemRestrictionGetMultiplicity(ceedDataF->Erestrictu, ceedDataF->xceed); 124 125 // -- Restore PETSc vector 126 CeedVectorTakeArray(ceedDataF->xceed, appCtx->memTypeRequested, NULL); 127 ierr = prolongRestrCtx->VecRestoreArray(VlocF, &multArray); CHKERRQ(ierr); 128 129 // -- Local-to-global 130 ierr = VecZeroEntries(VF); CHKERRQ(ierr); 131 ierr = DMLocalToGlobal(dmF, VlocF, ADD_VALUES, VF); CHKERRQ(ierr); 132 133 // -- Global-to-local 134 ierr = VecDuplicate(VlocF, &prolongRestrCtx->multVec); CHKERRQ(ierr); 135 ierr = DMGlobalToLocal(dmF, VF, INSERT_VALUES, prolongRestrCtx->multVec); 136 CHKERRQ(ierr); 137 138 // -- Reciprocal 139 ierr = VecReciprocal(prolongRestrCtx->multVec); CHKERRQ(ierr); 140 141 // -- Reset work arrays 142 ierr = VecZeroEntries(VF); CHKERRQ(ierr); 143 ierr = VecZeroEntries(VlocF); CHKERRQ(ierr); 144 | |
| 145 PetscFunctionReturn(0); 146}; 147 148// ----------------------------------------------------------------------------- 149// Jacobian setup 150// ----------------------------------------------------------------------------- 151PetscErrorCode FormJacobian(SNES snes, Vec U, Mat J, Mat Jpre, void *ctx) { 152 PetscErrorCode ierr; --- 132 unchanged lines hidden (view full) --- 285 ierr = VecZeroEntries(MultVec); CHKERRQ(ierr); 286 ierr = DMLocalToGlobal(user->dm, Yloc, ADD_VALUES, MultVec); 287 CHKERRQ(ierr); 288 289 // -- Scale 290 ierr = VecReciprocal(MultVec); CHKERRQ(ierr); 291 ierr = VecPointwiseMult(Diagnostic, Diagnostic, MultVec); 292 | 112 PetscFunctionReturn(0); 113}; 114 115// ----------------------------------------------------------------------------- 116// Jacobian setup 117// ----------------------------------------------------------------------------- 118PetscErrorCode FormJacobian(SNES snes, Vec U, Mat J, Mat Jpre, void *ctx) { 119 PetscErrorCode ierr; --- 132 unchanged lines hidden (view full) --- 252 ierr = VecZeroEntries(MultVec); CHKERRQ(ierr); 253 ierr = DMLocalToGlobal(user->dm, Yloc, ADD_VALUES, MultVec); 254 CHKERRQ(ierr); 255 256 // -- Scale 257 ierr = VecReciprocal(MultVec); CHKERRQ(ierr); 258 ierr = VecPointwiseMult(Diagnostic, Diagnostic, MultVec); 259 |
| 293 | |
| 294 // --------------------------------------------------------------------------- 295 // Output solution vector 296 // --------------------------------------------------------------------------- 297 ierr = PetscViewerVTKOpen(comm, outputFilename, FILE_MODE_WRITE, &viewer); 298 CHKERRQ(ierr); 299 ierr = VecView(Diagnostic, viewer); CHKERRQ(ierr); 300 ierr = PetscViewerDestroy(&viewer); CHKERRQ(ierr); 301 302 // --------------------------------------------------------------------------- 303 // Cleanup 304 // --------------------------------------------------------------------------- 305 ierr = VecDestroy(&Diagnostic); CHKERRQ(ierr); 306 ierr = VecDestroy(&MultVec); CHKERRQ(ierr); 307 ierr = VecDestroy(&Yloc); CHKERRQ(ierr); 308 CeedVectorDestroy(&Yceed); 309 310 PetscFunctionReturn(0); 311}; | 260 // --------------------------------------------------------------------------- 261 // Output solution vector 262 // --------------------------------------------------------------------------- 263 ierr = PetscViewerVTKOpen(comm, outputFilename, FILE_MODE_WRITE, &viewer); 264 CHKERRQ(ierr); 265 ierr = VecView(Diagnostic, viewer); CHKERRQ(ierr); 266 ierr = PetscViewerDestroy(&viewer); CHKERRQ(ierr); 267 268 // --------------------------------------------------------------------------- 269 // Cleanup 270 // --------------------------------------------------------------------------- 271 ierr = VecDestroy(&Diagnostic); CHKERRQ(ierr); 272 ierr = VecDestroy(&MultVec); CHKERRQ(ierr); 273 ierr = VecDestroy(&Yloc); CHKERRQ(ierr); 274 CeedVectorDestroy(&Yceed); 275 276 PetscFunctionReturn(0); 277}; |