PetscErrorCode VecMAXPY_SAMRAI( Vec y, PetscInt nv, const PetscScalar* alpha, Vec* x) { IBTK_TIMER_START(t_vec_maxpy); #ifdef DEBUG_CHECK_ASSERTIONS TBOX_ASSERT(y != PETSC_NULL); for (PetscInt i = 0; i < nv; ++i) { TBOX_ASSERT(x[i] != PETSC_NULL); } #endif static const bool interior_only = false; for (PetscInt i = 0; i < nv; ++i) { if (MathUtilities<double>::equalEps(alpha[i],1.0)) { PSVR_CAST2(y)->add(PSVR_CAST2(x[i]), PSVR_CAST2(y), interior_only); } else if (MathUtilities<double>::equalEps(alpha[i],-1.0)) { PSVR_CAST2(y)->subtract(PSVR_CAST2(y), PSVR_CAST2(x[i]), interior_only); } else { PSVR_CAST2(y)->axpy(alpha[i], PSVR_CAST2(x[i]), PSVR_CAST2(y), interior_only); } } int ierr = PetscObjectStateIncrease(reinterpret_cast<PetscObject>(y)); IBTK_CHKERRQ(ierr); IBTK_TIMER_STOP(t_vec_maxpy); PetscFunctionReturn(0); }// VecMAXPY
PetscErrorCode VecNorm_local_SAMRAI(Vec x, NormType type, PetscScalar* val) { IBTK_TIMER_START(t_vec_norm_local); #if !defined(NDEBUG) TBOX_ASSERT(x); #endif static const bool local_only = true; if (type == NORM_1) { *val = NormOps::L1Norm(PSVR_CAST2(x), local_only); } else if (type == NORM_2) { *val = NormOps::L2Norm(PSVR_CAST2(x), local_only); } else if (type == NORM_INFINITY) { *val = NormOps::maxNorm(PSVR_CAST2(x), local_only); } else if (type == NORM_1_AND_2) { val[0] = NormOps::L1Norm(PSVR_CAST2(x), local_only); val[1] = NormOps::L2Norm(PSVR_CAST2(x), local_only); } else { TBOX_ERROR("PETScSAMRAIVectorReal::norm()\n" << " vector norm type " << static_cast<int>(type) << " unsupported" << std::endl); } IBTK_TIMER_STOP(t_vec_norm_local); PetscFunctionReturn(0); } // VecNorm_local
PetscErrorCode VecWAXPY_SAMRAI( Vec w, PetscScalar alpha, Vec x, Vec y) { IBTK_TIMER_START(t_vec_waxpy); #ifdef DEBUG_CHECK_ASSERTIONS TBOX_ASSERT(x != PETSC_NULL); TBOX_ASSERT(y != PETSC_NULL); TBOX_ASSERT(w != PETSC_NULL); #endif static const bool interior_only = false; if (MathUtilities<double>::equalEps(alpha,1.0)) { PSVR_CAST2(w)->add(PSVR_CAST2(x), PSVR_CAST2(y), interior_only); } else if (MathUtilities<double>::equalEps(alpha,-1.0)) { PSVR_CAST2(w)->subtract(PSVR_CAST2(y), PSVR_CAST2(x), interior_only); } else { PSVR_CAST2(w)->axpy(alpha, PSVR_CAST2(x), PSVR_CAST2(y), interior_only); } int ierr = PetscObjectStateIncrease(reinterpret_cast<PetscObject>(w)); IBTK_CHKERRQ(ierr); IBTK_TIMER_STOP(t_vec_waxpy); PetscFunctionReturn(0); }// VecWAXPY
PetscErrorCode VecAYPX_SAMRAI(Vec y, const PetscScalar alpha, Vec x) { IBTK_TIMER_START(t_vec_aypx); #if !defined(NDEBUG) TBOX_ASSERT(x); TBOX_ASSERT(y); #endif static const bool interior_only = false; if (MathUtilities<double>::equalEps(alpha, 1.0)) { PSVR_CAST2(y)->add(PSVR_CAST2(x), PSVR_CAST2(y), interior_only); } else if (MathUtilities<double>::equalEps(alpha, -1.0)) { PSVR_CAST2(y)->subtract(PSVR_CAST2(x), PSVR_CAST2(y), interior_only); } else { PSVR_CAST2(y)->axpy(alpha, PSVR_CAST2(y), PSVR_CAST2(x), interior_only); } int ierr = PetscObjectStateIncrease(reinterpret_cast<PetscObject>(y)); IBTK_CHKERRQ(ierr); IBTK_TIMER_STOP(t_vec_aypx); PetscFunctionReturn(0); } // VecAYPX
bool PETScKrylovLinearSolver::solveSystem(SAMRAIVectorReal<NDIM, double>& x, SAMRAIVectorReal<NDIM, double>& b) { IBTK_TIMER_START(t_solve_system); #if !defined(NDEBUG) TBOX_ASSERT(d_A); #endif int ierr; // Initialize the solver, when necessary. const bool deallocate_after_solve = !d_is_initialized; if (deallocate_after_solve) initializeSolverState(x, b); #if !defined(NDEBUG) TBOX_ASSERT(d_petsc_ksp); #endif resetKSPOptions(); // Allocate scratch data. d_b->allocateVectorData(); // Solve the system using a PETSc KSP object. d_b->copyVector(Pointer<SAMRAIVectorReal<NDIM, double> >(&b, false)); d_A->setHomogeneousBc(d_homogeneous_bc); d_A->modifyRhsForBcs(*d_b); d_A->setHomogeneousBc(true); PETScSAMRAIVectorReal::replaceSAMRAIVector(d_petsc_x, Pointer<SAMRAIVectorReal<NDIM, double> >(&x, false)); PETScSAMRAIVectorReal::replaceSAMRAIVector(d_petsc_b, d_b); ierr = KSPSolve(d_petsc_ksp, d_petsc_b, d_petsc_x); IBTK_CHKERRQ(ierr); d_A->setHomogeneousBc(d_homogeneous_bc); d_A->imposeSolBcs(x); // Get iterations count and residual norm. ierr = KSPGetIterationNumber(d_petsc_ksp, &d_current_iterations); IBTK_CHKERRQ(ierr); ierr = KSPGetResidualNorm(d_petsc_ksp, &d_current_residual_norm); IBTK_CHKERRQ(ierr); d_A->setHomogeneousBc(d_homogeneous_bc); // Determine the convergence reason. KSPConvergedReason reason; ierr = KSPGetConvergedReason(d_petsc_ksp, &reason); IBTK_CHKERRQ(ierr); const bool converged = (static_cast<int>(reason) > 0); if (d_enable_logging) reportKSPConvergedReason(reason, plog); // Dealocate scratch data. d_b->deallocateVectorData(); // Deallocate the solver, when necessary. if (deallocate_after_solve) deallocateSolverState(); IBTK_TIMER_STOP(t_solve_system); return converged; } // solveSystem
PetscErrorCode VecGetLocalSize_SAMRAI(Vec v, PetscInt* size) { IBTK_TIMER_START(t_vec_get_local_size); #if !defined(NDEBUG) TBOX_ASSERT(v); #endif *size = v->map->n; IBTK_TIMER_STOP(t_vec_get_local_size); PetscFunctionReturn(0); } // VecGetLocalSize
PetscErrorCode VecMin_SAMRAI(Vec x, PetscInt* p, PetscScalar* val) { IBTK_TIMER_START(t_vec_min); #if !defined(NDEBUG) TBOX_ASSERT(x); #endif *p = -1; *val = PSVR_CAST2(x)->min(); IBTK_TIMER_STOP(t_vec_min); PetscFunctionReturn(0); } // VecMin
PetscErrorCode VecTDot_SAMRAI(Vec x, Vec y, PetscScalar* val) { IBTK_TIMER_START(t_vec_t_dot); #if !defined(NDEBUG) TBOX_ASSERT(x); TBOX_ASSERT(y); #endif *val = PSVR_CAST2(x)->dot(PSVR_CAST2(y)); IBTK_TIMER_STOP(t_vec_t_dot); PetscFunctionReturn(0); } // VecTDot
PetscErrorCode VecMaxPointwiseDivide_SAMRAI(Vec x, Vec y, PetscScalar* max) { IBTK_TIMER_START(t_vec_max_pointwise_divide); #if !defined(NDEBUG) TBOX_ASSERT(x); TBOX_ASSERT(y); #endif *max = PSVR_CAST2(x)->maxPointwiseDivide(PSVR_CAST2(y)); IBTK_TIMER_STOP(t_vec_max_pointwise_divide); PetscFunctionReturn(0); } // VecMaxPointwiseDivide
PetscErrorCode VecTDot_local_SAMRAI(Vec x, Vec y, PetscScalar* val) { IBTK_TIMER_START(t_vec_t_dot_local); #if !defined(NDEBUG) TBOX_ASSERT(x); TBOX_ASSERT(y); #endif static const bool local_only = true; *val = PSVR_CAST2(x)->dot(PSVR_CAST2(y), local_only); IBTK_TIMER_STOP(t_vec_t_dot_local); PetscFunctionReturn(0); } // VecTDot_local
PetscErrorCode VecDotNorm2_SAMRAI(Vec s, Vec t, PetscScalar* dp, PetscScalar* nm) { IBTK_TIMER_START(t_vec_dot_norm2); #if !defined(NDEBUG) TBOX_ASSERT(s); TBOX_ASSERT(t); #endif *dp = PSVR_CAST2(s)->dot(PSVR_CAST2(t)); *nm = PSVR_CAST2(t)->dot(PSVR_CAST2(t)); IBTK_TIMER_STOP(t_vec_dot_norm2); PetscFunctionReturn(0); } // VecDotNorm2_SAMRAI
PetscErrorCode VecSet_SAMRAI(Vec x, PetscScalar alpha) { IBTK_TIMER_START(t_vec_set); #if !defined(NDEBUG) TBOX_ASSERT(x); #endif static const bool interior_only = false; PSVR_CAST2(x)->setToScalar(alpha, interior_only); int ierr = PetscObjectStateIncrease(reinterpret_cast<PetscObject>(x)); IBTK_CHKERRQ(ierr); IBTK_TIMER_STOP(t_vec_set); PetscFunctionReturn(0); } // VecSet
PetscErrorCode VecCopy_SAMRAI(Vec x, Vec y) { IBTK_TIMER_START(t_vec_copy); #if !defined(NDEBUG) TBOX_ASSERT(x); TBOX_ASSERT(y); #endif static const bool interior_only = false; PSVR_CAST2(y)->copyVector(PSVR_CAST2(x), interior_only); int ierr = PetscObjectStateIncrease(reinterpret_cast<PetscObject>(y)); IBTK_CHKERRQ(ierr); IBTK_TIMER_STOP(t_vec_copy); PetscFunctionReturn(0); } // VecCopy
bool CCDivGradHypreLevelSolver::solveSystem( SAMRAIVectorReal<NDIM,double>& x, SAMRAIVectorReal<NDIM,double>& b) { IBTK_TIMER_START(t_solve_system); if (d_enable_logging) plog << d_object_name << "::solveSystem():" << std::endl; // Initialize the solver, when necessary. const bool deallocate_after_solve = !d_is_initialized; if (deallocate_after_solve) initializeSolverState(x,b); // Solve the system using the hypre solver. static const int comp = 0; const int x_idx = x.getComponentDescriptorIndex(comp); const int b_idx = b.getComponentDescriptorIndex(comp); bool converged = true; IntVector<NDIM> chkbrd_mode_id; #if (NDIM > 2) for (chkbrd_mode_id(2) = 0; chkbrd_mode_id(2) < 2; ++chkbrd_mode_id(2)) { #endif for (chkbrd_mode_id(1) = 0; chkbrd_mode_id(1) < 2; ++chkbrd_mode_id(1)) { for (chkbrd_mode_id(0) = 0; chkbrd_mode_id(0) < 2; ++chkbrd_mode_id(0)) { bool converged_mode = solveSystem(x_idx, b_idx, chkbrd_mode_id); if (d_enable_logging) { plog << d_object_name << "::solveSystem(): solver " << (converged_mode ? "converged" : "diverged") << "\n" << "chkbrd_mode_id = " << chkbrd_mode_id << "\n" << "iterations = " << d_current_its << "\n" << "residual norm = " << d_current_residual_norm << std::endl; } converged = converged && converged_mode; } } #if (NDIM > 2) } #endif // Deallocate the solver, when necessary. if (deallocate_after_solve) deallocateSolverState(); IBTK_TIMER_STOP(t_solve_system); return converged; }// solveSystem
PetscErrorCode VecGetLocalSize_SAMRAI( Vec v, PetscInt* n) { IBTK_TIMER_START(t_vec_get_local_size); #ifdef DEBUG_CHECK_ASSERTIONS TBOX_ASSERT(v != PETSC_NULL); #else NULL_USE(v); #endif *n = 0; IBTK_TIMER_STOP(t_vec_get_local_size); PetscFunctionReturn(0); }// VecGetLocalSize
PetscErrorCode VecScale_SAMRAI( Vec x, PetscScalar alpha) { IBTK_TIMER_START(t_vec_scale); #ifdef DEBUG_CHECK_ASSERTIONS TBOX_ASSERT(x != PETSC_NULL); #endif static const bool interior_only = false; PSVR_CAST2(x)->scale(alpha,PSVR_CAST2(x), interior_only); int ierr = PetscObjectStateIncrease(reinterpret_cast<PetscObject>(x)); IBTK_CHKERRQ(ierr); IBTK_TIMER_STOP(t_vec_scale); PetscFunctionReturn(0); }// VecScale
PetscErrorCode VecPointwiseDivide_SAMRAI(Vec w, Vec x, Vec y) { IBTK_TIMER_START(t_vec_pointwise_divide); #if !defined(NDEBUG) TBOX_ASSERT(x); TBOX_ASSERT(y); TBOX_ASSERT(w); #endif static const bool interior_only = false; PSVR_CAST2(w)->divide(PSVR_CAST2(x), PSVR_CAST2(y), interior_only); int ierr = PetscObjectStateIncrease(reinterpret_cast<PetscObject>(w)); IBTK_CHKERRQ(ierr); IBTK_TIMER_STOP(t_vec_pointwise_divide); PetscFunctionReturn(0); } // VecPointwiseDivide
PetscErrorCode VecMaxPointwiseDivide_SAMRAI( Vec x, Vec y, PetscScalar* max) { IBTK_TIMER_START(t_vec_max_pointwise_divide); #ifdef DEBUG_CHECK_ASSERTIONS TBOX_ASSERT(x != PETSC_NULL); TBOX_ASSERT(y != PETSC_NULL); #endif *max = PSVR_CAST2(x)->maxPointwiseDivide(PSVR_CAST2(y)); IBTK_TIMER_STOP(t_vec_max_pointwise_divide); PetscFunctionReturn(0); }// VecMaxPointwiseDivide
PetscErrorCode VecMin_SAMRAI( Vec x, PetscInt* p, PetscScalar* val) { IBTK_TIMER_START(t_vec_min); #ifdef DEBUG_CHECK_ASSERTIONS TBOX_ASSERT(x != PETSC_NULL); #endif *p = -1; *val = PSVR_CAST2(x)->min(); IBTK_TIMER_STOP(t_vec_min); PetscFunctionReturn(0); }// VecMin
PetscErrorCode VecTDot_SAMRAI( Vec x, Vec y, PetscScalar* val) { IBTK_TIMER_START(t_vec_t_dot); #ifdef DEBUG_CHECK_ASSERTIONS TBOX_ASSERT(x != PETSC_NULL); TBOX_ASSERT(y != PETSC_NULL); #endif *val = PSVR_CAST2(x)->dot(PSVR_CAST2(y)); IBTK_TIMER_STOP(t_vec_t_dot); PetscFunctionReturn(0); }// VecTDot
PetscErrorCode VecDot_local_SAMRAI( Vec x, Vec y, PetscScalar* val) { IBTK_TIMER_START(t_vec_dot_local); #ifdef DEBUG_CHECK_ASSERTIONS TBOX_ASSERT(x != PETSC_NULL); TBOX_ASSERT(y != PETSC_NULL); #endif static const bool local_only = true; *val = PSVR_CAST2(x)->dot(PSVR_CAST2(y), local_only); IBTK_TIMER_STOP(t_vec_dot_local); PetscFunctionReturn(0); }// VecDot_local
PetscErrorCode VecSetRandom_SAMRAI(Vec x, PetscRandom rctx) { IBTK_TIMER_START(t_vec_set_random); #if !defined(NDEBUG) TBOX_ASSERT(x); #endif PetscScalar lo, hi; int ierr; ierr = PetscRandomGetInterval(rctx, &lo, &hi); IBTK_CHKERRQ(ierr); PSVR_CAST2(x)->setRandomValues(hi - lo, lo); ierr = PetscObjectStateIncrease(reinterpret_cast<PetscObject>(x)); IBTK_CHKERRQ(ierr); IBTK_TIMER_STOP(t_vec_set_random); PetscFunctionReturn(0); } // VecSetRandom
PetscErrorCode VecSwap_SAMRAI(Vec x, Vec y) { IBTK_TIMER_START(t_vec_swap); #if !defined(NDEBUG) TBOX_ASSERT(x); TBOX_ASSERT(y); #endif PSVR_CAST2(x)->swapVectors(PSVR_CAST2(y)); int ierr; ierr = PetscObjectStateIncrease(reinterpret_cast<PetscObject>(x)); IBTK_CHKERRQ(ierr); ierr = PetscObjectStateIncrease(reinterpret_cast<PetscObject>(y)); IBTK_CHKERRQ(ierr); IBTK_TIMER_STOP(t_vec_swap); PetscFunctionReturn(0); } // VecSwap
void PETScNewtonKrylovSolver::deallocateSolverState() { if (!d_is_initialized) return; IBTK_TIMER_START(t_deallocate_solver_state); int ierr; // Deallocate the linear solver and operator states only if we are not // re-initializing the Newton solver. if (!d_reinitializing_solver) { if (d_krylov_solver) d_krylov_solver->deallocateSolverState(); if (d_J) d_J->deallocateOperatorState(); if (d_F) d_F->deallocateOperatorState(); } // Delete the solution and rhs vectors. PETScSAMRAIVectorReal::destroyPETScVector(d_petsc_x); d_petsc_x = NULL; d_x->freeVectorComponents(); d_x.setNull(); PETScSAMRAIVectorReal::destroyPETScVector(d_petsc_b); d_petsc_b = NULL; d_b->freeVectorComponents(); d_b.setNull(); PETScSAMRAIVectorReal::destroyPETScVector(d_petsc_r); d_petsc_r = NULL; d_r->freeVectorComponents(); d_r.setNull(); // Destroy the SNES solver. if (d_managing_petsc_snes) { ierr = SNESDestroy(&d_petsc_snes); IBTK_CHKERRQ(ierr); d_petsc_snes = NULL; } // Indicate that the solver is NOT initialized. d_is_initialized = false; IBTK_TIMER_STOP(t_deallocate_solver_state); return; } // deallocateSolverState
void CCDivGradHypreLevelSolver::deallocateSolverState() { if (!d_is_initialized) return; IBTK_TIMER_START(t_deallocate_solver_state); // Deallocate the hypre data structures. destroyHypreSolver(); deallocateHypreData(); // Indicate that the solver is NOT initialized. d_is_initialized = false; IBTK_TIMER_STOP(t_deallocate_solver_state); return; }// deallocateSolverState
void PETScKrylovLinearSolver::deallocateSolverState() { if (!d_is_initialized) return; IBTK_TIMER_START(t_deallocate_solver_state); int ierr; // Deallocate the operator and preconditioner states only if we are not // re-initializing the solver. if (!d_reinitializing_solver) { if (d_pc_solver) d_pc_solver->deallocateSolverState(); if (d_A) d_A->deallocateOperatorState(); } // Delete the solution and rhs vectors. PETScSAMRAIVectorReal::destroyPETScVector(d_petsc_x); d_petsc_x = NULL; d_x->freeVectorComponents(); d_x.setNull(); PETScSAMRAIVectorReal::destroyPETScVector(d_petsc_b); d_petsc_b = NULL; d_b->freeVectorComponents(); d_b.setNull(); // Deallocate the nullspace object. deallocateNullspaceData(); // Destroy the KSP solver. if (d_managing_petsc_ksp) { ierr = KSPDestroy(&d_petsc_ksp); IBTK_CHKERRQ(ierr); d_petsc_ksp = NULL; d_solver_has_attached_nullspace = false; } // Indicate that the solver is NOT initialized. d_is_initialized = false; IBTK_TIMER_STOP(t_deallocate_solver_state); return; } // deallocateSolverState
PetscErrorCode VecDotNorm2_SAMRAI( Vec s, Vec t, PetscScalar* dp, PetscScalar* nm) { IBTK_TIMER_START(t_vec_dot_norm2); #ifdef DEBUG_CHECK_ASSERTIONS TBOX_ASSERT(s != PETSC_NULL); TBOX_ASSERT(t != PETSC_NULL); #endif *dp = PSVR_CAST2(s)->dot(PSVR_CAST2(t)); *nm = PSVR_CAST2(t)->dot(PSVR_CAST2(t)); IBTK_TIMER_STOP(t_vec_dot_norm2); PetscFunctionReturn(0); }// VecDotNorm2_SAMRAI
PetscErrorCode VecAXPBYPCZ_SAMRAI(Vec z, PetscScalar alpha, PetscScalar beta, PetscScalar gamma, Vec x, Vec y) { IBTK_TIMER_START(t_vec_axpbypcz); #if !defined(NDEBUG) TBOX_ASSERT(x); TBOX_ASSERT(y); TBOX_ASSERT(z); #endif static const bool interior_only = false; PSVR_CAST2(z)->linearSum(alpha, PSVR_CAST2(x), gamma, PSVR_CAST2(z), interior_only); PSVR_CAST2(z)->axpy(beta, PSVR_CAST2(y), PSVR_CAST2(z), interior_only); int ierr = PetscObjectStateIncrease(reinterpret_cast<PetscObject>(z)); IBTK_CHKERRQ(ierr); IBTK_TIMER_STOP(t_vec_axpbypcz); PetscFunctionReturn(0); } // VecAXPBYPCZ
PetscErrorCode VecMTDot_local_SAMRAI(Vec x, PetscInt nv, const Vec* y, PetscScalar* val) { IBTK_TIMER_START(t_vec_m_t_dot_local); #if !defined(NDEBUG) TBOX_ASSERT(x); for (PetscInt i = 0; i < nv; ++i) { TBOX_ASSERT(y[i]); } #endif static const bool local_only = true; for (PetscInt i = 0; i < nv; ++i) { val[i] = PSVR_CAST2(x)->dot(PSVR_CAST2(y[i]), local_only); } IBTK_TIMER_STOP(t_vec_m_t_dot_local); PetscFunctionReturn(0); } // VecMTDot_local
PetscErrorCode VecPointwiseMult_SAMRAI( Vec w, Vec x, Vec y) { IBTK_TIMER_START(t_vec_pointwise_mult); #ifdef DEBUG_CHECK_ASSERTIONS TBOX_ASSERT(x != PETSC_NULL); TBOX_ASSERT(y != PETSC_NULL); TBOX_ASSERT(w != PETSC_NULL); #endif static const bool interior_only = false; PSVR_CAST2(w)->multiply(PSVR_CAST2(x), PSVR_CAST2(y), interior_only); int ierr = PetscObjectStateIncrease(reinterpret_cast<PetscObject>(w)); IBTK_CHKERRQ(ierr); IBTK_TIMER_STOP(t_vec_pointwise_mult); PetscFunctionReturn(0); }// VecPointwiseMult