void BJacobiPreconditioner::initializeSolverState( const SAMRAIVectorReal<NDIM,double>& x, const SAMRAIVectorReal<NDIM,double>& b) { Pointer<PatchHierarchy<NDIM> > hierarchy = x.getPatchHierarchy(); const int coarsest_ln = x.getCoarsestLevelNumber(); const int finest_ln = x.getFinestLevelNumber(); #ifdef DEBUG_CHECK_ASSERTIONS TBOX_ASSERT(hierarchy == b.getPatchHierarchy()); TBOX_ASSERT(coarsest_ln == b.getCoarsestLevelNumber()); TBOX_ASSERT(finest_ln == b.getFinestLevelNumber()); TBOX_ASSERT(x.getNumberOfComponents() == b.getNumberOfComponents()); #endif // Initialize the component preconditioners. const std::string& x_name = x.getName(); const std::string& b_name = b.getName(); for (std::map<unsigned int,Pointer<LinearSolver> >::iterator it = d_pc_map.begin(); it != d_pc_map.end(); ++it) { const int comp = it->first; SAMRAIVectorReal<NDIM,double> x_comp(x_name+"_component", hierarchy, coarsest_ln, finest_ln); x_comp.addComponent(x.getComponentVariable(comp), x.getComponentDescriptorIndex(comp), x.getControlVolumeIndex(comp)); SAMRAIVectorReal<NDIM,double> b_comp(b_name+"_component", hierarchy, coarsest_ln, finest_ln); b_comp.addComponent(b.getComponentVariable(comp), b.getComponentDescriptorIndex(comp), b.getControlVolumeIndex(comp)); d_pc_map[comp]->initializeSolverState(x_comp, b_comp); } // Indicate that the preconditioner is initialized. d_is_initialized = true; return; }// initializeSolverState
bool BJacobiPreconditioner::solveSystem( SAMRAIVectorReal<NDIM,double>& x, SAMRAIVectorReal<NDIM,double>& b) { // Initialize the preconditioner, when necessary. const bool deallocate_after_solve = !d_is_initialized; if (deallocate_after_solve) initializeSolverState(x,b); Pointer<PatchHierarchy<NDIM> > hierarchy = x.getPatchHierarchy(); const int coarsest_ln = x.getCoarsestLevelNumber(); const int finest_ln = x.getFinestLevelNumber() ; #ifdef DEBUG_CHECK_ASSERTIONS TBOX_ASSERT(x.getNumberOfComponents() == b.getNumberOfComponents()); TBOX_ASSERT(hierarchy == b.getPatchHierarchy()); TBOX_ASSERT(coarsest_ln == b.getCoarsestLevelNumber()); TBOX_ASSERT( finest_ln == b.getFinestLevelNumber() ); #endif const std::string& x_name = x.getName(); const std::string& b_name = b.getName(); bool ret_val = true; // Zero out the initial guess. #ifdef DEBUG_CHECK_ASSERTIONS TBOX_ASSERT(d_initial_guess_nonzero == false); #endif x.setToScalar(0.0, /*interior_only*/ false); for (int comp = 0; comp < x.getNumberOfComponents(); ++comp) { // Setup a SAMRAIVectorReal to correspond to the individual vector // component. std::ostringstream str; str << comp; SAMRAIVectorReal<NDIM,double> x_comp(x_name+"_component_"+str.str(), hierarchy, coarsest_ln, finest_ln); x_comp.addComponent(x.getComponentVariable(comp), x.getComponentDescriptorIndex(comp), x.getControlVolumeIndex(comp)); SAMRAIVectorReal<NDIM,double> b_comp(b_name+"_component_"+str.str(), hierarchy, coarsest_ln, finest_ln); b_comp.addComponent(b.getComponentVariable(comp), b.getComponentDescriptorIndex(comp), b.getControlVolumeIndex(comp)); // Configure the component preconditioner. Pointer<LinearSolver> pc_comp = d_pc_map[comp]; pc_comp->setInitialGuessNonzero(d_initial_guess_nonzero); pc_comp->setMaxIterations(d_max_iterations); pc_comp->setAbsoluteTolerance(d_abs_residual_tol); pc_comp->setRelativeTolerance(d_rel_residual_tol); // Apply the component preconditioner. const bool ret_val_comp = pc_comp->solveSystem(x_comp, b_comp); ret_val = ret_val && ret_val_comp; } // Deallocate the preconditioner, when necessary. if (deallocate_after_solve) deallocateSolverState(); return ret_val; }// solveSystem
bool IBImplicitModHelmholtzPETScLevelSolver::solveSystem( SAMRAIVectorReal<NDIM,double>& x, SAMRAIVectorReal<NDIM,double>& b) { IBAMR_TIMER_START(t_solve_system); int ierr; 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); #if 0 // XXXX // Configure solver. ierr = KSPSetTolerances(d_petsc_ksp, d_rel_residual_tol, d_abs_residual_tol, PETSC_DEFAULT, d_max_iterations); IBTK_CHKERRQ(ierr); ierr = KSPSetInitialGuessNonzero(d_petsc_ksp, d_initial_guess_nonzero ? PETSC_TRUE : PETSC_FALSE); IBTK_CHKERRQ(ierr); #endif // Solve the system. Pointer<PatchLevel<NDIM> > patch_level = d_hierarchy->getPatchLevel(d_level_num); const int x_idx = x.getComponentDescriptorIndex(0); Pointer<SideVariable<NDIM,double> > x_var = x.getComponentVariable(0); const int b_idx = b.getComponentDescriptorIndex(0); Pointer<SideVariable<NDIM,double> > b_var = b.getComponentVariable(0); if (d_initial_guess_nonzero) PETScVecUtilities::copyToPatchLevelVec(d_petsc_x, x_idx, x_var, patch_level); PETScVecUtilities::copyToPatchLevelVec(d_petsc_b, b_idx, b_var, patch_level); PETScVecUtilities::constrainPatchLevelVec(d_petsc_b, d_dof_index_idx, d_dof_index_var, patch_level, d_dof_index_fill); ierr = KSPSolve(d_petsc_ksp, d_petsc_b, d_petsc_x); IBTK_CHKERRQ(ierr); PETScVecUtilities::copyFromPatchLevelVec(d_petsc_x, x_idx, x_var, patch_level); typedef SideDataSynchronization::SynchronizationTransactionComponent SynchronizationTransactionComponent; // XXXX SynchronizationTransactionComponent x_synch_transaction = SynchronizationTransactionComponent(x_idx, "CONSERVATIVE_COARSEN"); Pointer<SideDataSynchronization> side_synch_op = new SideDataSynchronization(); side_synch_op->initializeOperatorState(x_synch_transaction, x.getPatchHierarchy()); side_synch_op->synchronizeData(0.0); // Log solver info. KSPConvergedReason reason; ierr = KSPGetConvergedReason(d_petsc_ksp, &reason); IBTK_CHKERRQ(ierr); const bool converged = reason > 0; if (d_enable_logging) { plog << d_object_name << "::solveSystem(): solver " << (converged ? "converged" : "diverged") << "\n" << "iterations = " << d_current_its << "\n" << "residual norm = " << d_current_residual_norm << std::endl; } // Deallocate the solver, when necessary. if (deallocate_after_solve) deallocateSolverState(); IBAMR_TIMER_STOP(t_solve_system); return converged; }// solveSystem
void CCPoissonPETScLevelSolver::setupKSPVecs(Vec& petsc_x, Vec& petsc_b, SAMRAIVectorReal<NDIM, double>& x, SAMRAIVectorReal<NDIM, double>& b, Pointer<PatchLevel<NDIM> > patch_level) { if (!d_initial_guess_nonzero) copyToPETScVec(petsc_x, x, patch_level); const int b_idx = b.getComponentDescriptorIndex(0); Pointer<CellVariable<NDIM, double> > b_var = b.getComponentVariable(0); VariableDatabase<NDIM>* var_db = VariableDatabase<NDIM>::getDatabase(); int b_adj_idx = var_db->registerClonedPatchDataIndex(b_var, b_idx); patch_level->allocatePatchData(b_adj_idx); for (PatchLevel<NDIM>::Iterator p(patch_level); p; p++) { Pointer<Patch<NDIM> > patch = patch_level->getPatch(p()); Pointer<CellData<NDIM, double> > b_data = patch->getPatchData(b_idx); Pointer<CellData<NDIM, double> > b_adj_data = patch->getPatchData(b_adj_idx); b_adj_data->copy(*b_data); if (!patch->getPatchGeometry()->intersectsPhysicalBoundary()) continue; PoissonUtilities::adjustCCBoundaryRhsEntries( patch, *b_adj_data, d_poisson_spec, d_bc_coefs, d_solution_time, d_homogeneous_bc); } PETScVecUtilities::copyToPatchLevelVec(petsc_b, b_adj_idx, d_dof_index_idx, patch_level); patch_level->deallocatePatchData(b_adj_idx); var_db->removePatchDataIndex(b_adj_idx); return; } // setupKSPVecs
void IBImplicitModHelmholtzOperator::apply( SAMRAIVectorReal<NDIM,double>& x, SAMRAIVectorReal<NDIM,double>& y) { IBAMR_TIMER_START(t_apply); SAMRAIVectorReal<NDIM,double> x_u(x.getName(), x.getPatchHierarchy(), x.getCoarsestLevelNumber(), x.getFinestLevelNumber()); x_u.addComponent(x.getComponentVariable(0), x.getComponentDescriptorIndex(0), x.getControlVolumeIndex(0)); SAMRAIVectorReal<NDIM,double> y_u(y.getName(), y.getPatchHierarchy(), y.getCoarsestLevelNumber(), y.getFinestLevelNumber()); y_u.addComponent(y.getComponentVariable(0), y.getComponentDescriptorIndex(0), y.getControlVolumeIndex(0)); // Apply the linear part of the operator with homogeneous boundary // conditions. d_helmholtz_op->apply(x_u, y_u); // Apply the nonlinear part of the operator. d_ib_SJSstar_op->applyAdd(x_u, y_u, y_u); IBAMR_TIMER_STOP(t_apply); return; }// apply
void IBImplicitModHelmholtzOperator::initializeOperatorState( const SAMRAIVectorReal<NDIM,double>& in, const SAMRAIVectorReal<NDIM,double>& out) { IBAMR_TIMER_START(t_initialize_operator_state); if (d_is_initialized) deallocateOperatorState(); SAMRAIVectorReal<NDIM,double> in_u(in.getName(), in.getPatchHierarchy(), in.getCoarsestLevelNumber(), in.getFinestLevelNumber()); in_u.addComponent(in.getComponentVariable(0), in.getComponentDescriptorIndex(0), in.getControlVolumeIndex(0)); SAMRAIVectorReal<NDIM,double> out_u(out.getName(), out.getPatchHierarchy(), out.getCoarsestLevelNumber(), out.getFinestLevelNumber()); out_u.addComponent(out.getComponentVariable(0), out.getComponentDescriptorIndex(0), out.getControlVolumeIndex(0)); d_helmholtz_op->initializeOperatorState(in_u, out_u); // d_ib_SJSstar_op->initializeOperatorState(in_u, out_u); d_is_initialized = true; IBAMR_TIMER_STOP(t_initialize_operator_state); return; }// initializeOperatorState
Pointer<SAMRAIVectorReal<NDIM,double> > FACPreconditionerStrategy::getLevelSAMRAIVectorReal( const SAMRAIVectorReal<NDIM,double>& vec, int level_num) const { std::ostringstream name_str; name_str << vec.getName() << "::level_" << level_num; Pointer<SAMRAIVectorReal<NDIM,double> > level_vec = new SAMRAIVectorReal<NDIM,double>(name_str.str(), vec.getPatchHierarchy(), level_num, level_num); for (int comp = 0; comp < vec.getNumberOfComponents(); ++comp) { level_vec->addComponent(vec.getComponentVariable(comp), vec.getComponentDescriptorIndex(comp), vec.getControlVolumeIndex(comp)); } return level_vec; }// getLevelSAMRAIVectorReal
void SCPoissonPETScLevelSolver::setupKSPVecs(Vec& petsc_x, Vec& petsc_b, SAMRAIVectorReal<NDIM, double>& x, SAMRAIVectorReal<NDIM, double>& b) { if (d_initial_guess_nonzero) copyToPETScVec(petsc_x, x); const bool level_zero = (d_level_num == 0); const int x_idx = x.getComponentDescriptorIndex(0); const int b_idx = b.getComponentDescriptorIndex(0); Pointer<SideVariable<NDIM, double> > b_var = b.getComponentVariable(0); VariableDatabase<NDIM>* var_db = VariableDatabase<NDIM>::getDatabase(); int b_adj_idx = var_db->registerClonedPatchDataIndex(b_var, b_idx); d_level->allocatePatchData(b_adj_idx); for (PatchLevel<NDIM>::Iterator p(d_level); p; p++) { Pointer<Patch<NDIM> > patch = d_level->getPatch(p()); Pointer<PatchGeometry<NDIM> > pgeom = patch->getPatchGeometry(); Pointer<SideData<NDIM, double> > x_data = patch->getPatchData(x_idx); Pointer<SideData<NDIM, double> > b_data = patch->getPatchData(b_idx); Pointer<SideData<NDIM, double> > b_adj_data = patch->getPatchData(b_adj_idx); b_adj_data->copy(*b_data); const bool at_physical_bdry = pgeom->intersectsPhysicalBoundary(); if (at_physical_bdry) { PoissonUtilities::adjustRHSAtPhysicalBoundary( *b_adj_data, patch, d_poisson_spec, d_bc_coefs, d_solution_time, d_homogeneous_bc); } const Array<BoundaryBox<NDIM> >& type_1_cf_bdry = level_zero ? Array<BoundaryBox<NDIM> >() : d_cf_boundary->getBoundaries(patch->getPatchNumber(), /* boundary type */ 1); const bool at_cf_bdry = type_1_cf_bdry.size() > 0; if (at_cf_bdry) { PoissonUtilities::adjustRHSAtCoarseFineBoundary( *b_adj_data, *x_data, patch, d_poisson_spec, type_1_cf_bdry); } } PETScVecUtilities::copyToPatchLevelVec(petsc_b, b_adj_idx, d_dof_index_idx, d_level); d_level->deallocatePatchData(b_adj_idx); var_db->removePatchDataIndex(b_adj_idx); return; } // setupKSPVecs
void StaggeredStokesOperator::apply(SAMRAIVectorReal<NDIM, double>& x, SAMRAIVectorReal<NDIM, double>& y) { IBAMR_TIMER_START(t_apply); // Get the vector components. const int U_idx = x.getComponentDescriptorIndex(0); const int P_idx = x.getComponentDescriptorIndex(1); const int A_U_idx = y.getComponentDescriptorIndex(0); const int A_P_idx = y.getComponentDescriptorIndex(1); const int U_scratch_idx = d_x->getComponentDescriptorIndex(0); Pointer<SideVariable<NDIM, double> > U_sc_var = x.getComponentVariable(0); Pointer<CellVariable<NDIM, double> > P_cc_var = x.getComponentVariable(1); Pointer<SideVariable<NDIM, double> > A_U_sc_var = y.getComponentVariable(0); Pointer<CellVariable<NDIM, double> > A_P_cc_var = y.getComponentVariable(1); // Simultaneously fill ghost cell values for all components. typedef HierarchyGhostCellInterpolation::InterpolationTransactionComponent InterpolationTransactionComponent; std::vector<InterpolationTransactionComponent> transaction_comps(2); transaction_comps[0] = InterpolationTransactionComponent(U_scratch_idx, U_idx, DATA_REFINE_TYPE, USE_CF_INTERPOLATION, DATA_COARSEN_TYPE, BDRY_EXTRAP_TYPE, CONSISTENT_TYPE_2_BDRY, d_U_bc_coefs, d_U_fill_pattern); transaction_comps[1] = InterpolationTransactionComponent(P_idx, DATA_REFINE_TYPE, USE_CF_INTERPOLATION, DATA_COARSEN_TYPE, BDRY_EXTRAP_TYPE, CONSISTENT_TYPE_2_BDRY, d_P_bc_coef, d_P_fill_pattern); d_hier_bdry_fill->resetTransactionComponents(transaction_comps); d_hier_bdry_fill->setHomogeneousBc(d_homogeneous_bc); StaggeredStokesPhysicalBoundaryHelper::setupBcCoefObjects( d_U_bc_coefs, d_P_bc_coef, U_scratch_idx, P_idx, d_homogeneous_bc); d_hier_bdry_fill->fillData(d_solution_time); StaggeredStokesPhysicalBoundaryHelper::resetBcCoefObjects(d_U_bc_coefs, d_P_bc_coef); // d_bc_helper->enforceDivergenceFreeConditionAtBoundary(U_scratch_idx); d_hier_bdry_fill->resetTransactionComponents(d_transaction_comps); // Compute the action of the operator: // // A*[U;P] := [A_U;A_P] = [(C*I+D*L)*U + Grad P; -Div U] d_hier_math_ops->grad(A_U_idx, A_U_sc_var, /*cf_bdry_synch*/ false, 1.0, P_idx, P_cc_var, d_no_fill, d_new_time); d_hier_math_ops->laplace(A_U_idx, A_U_sc_var, d_U_problem_coefs, U_scratch_idx, U_sc_var, d_no_fill, d_new_time, 1.0, A_U_idx, A_U_sc_var); d_hier_math_ops->div(A_P_idx, A_P_cc_var, -1.0, U_scratch_idx, U_sc_var, d_no_fill, d_new_time, /*cf_bdry_synch*/ true); d_bc_helper->copyDataAtDirichletBoundaries(A_U_idx, U_scratch_idx); IBAMR_TIMER_STOP(t_apply); return; } // apply
void IBImplicitModHelmholtzPETScLevelSolver::initializeSolverState( const SAMRAIVectorReal<NDIM,double>& x, const SAMRAIVectorReal<NDIM,double>& b) { IBAMR_TIMER_START(t_initialize_solver_state); // Rudimentary error checking. #ifdef DEBUG_CHECK_ASSERTIONS if (x.getNumberOfComponents() != b.getNumberOfComponents()) { TBOX_ERROR(d_object_name << "::initializeSolverState()\n" << " vectors must have the same number of components" << std::endl); } const Pointer<PatchHierarchy<NDIM> >& patch_hierarchy = x.getPatchHierarchy(); if (patch_hierarchy != b.getPatchHierarchy()) { TBOX_ERROR(d_object_name << "::initializeSolverState()\n" << " vectors must have the same hierarchy" << std::endl); } const int coarsest_ln = x.getCoarsestLevelNumber(); if (coarsest_ln < 0) { TBOX_ERROR(d_object_name << "::initializeSolverState()\n" << " coarsest level number must not be negative" << std::endl); } if (coarsest_ln != b.getCoarsestLevelNumber()) { TBOX_ERROR(d_object_name << "::initializeSolverState()\n" << " vectors must have same coarsest level number" << std::endl); } const int finest_ln = x.getFinestLevelNumber(); if (finest_ln < coarsest_ln) { TBOX_ERROR(d_object_name << "::initializeSolverState()\n" << " finest level number must be >= coarsest level number" << std::endl); } if (finest_ln != b.getFinestLevelNumber()) { TBOX_ERROR(d_object_name << "::initializeSolverState()\n" << " vectors must have same finest level number" << std::endl); } for (int ln = coarsest_ln; ln <= finest_ln; ++ln) { if (patch_hierarchy->getPatchLevel(ln).isNull()) { TBOX_ERROR(d_object_name << "::initializeSolverState()\n" << " hierarchy level " << ln << " does not exist" << std::endl); } } if (coarsest_ln != finest_ln) { TBOX_ERROR(d_object_name << "::initializeSolverState()\n" << " coarsest_ln != finest_ln in IBImplicitModHelmholtzPETScLevelSolver" << std::endl); } #endif // Deallocate the solver state if the solver is already initialized. if (d_is_initialized) deallocateSolverState(); // Get the hierarchy information. d_hierarchy = x.getPatchHierarchy(); d_level_num = x.getCoarsestLevelNumber(); #ifdef DEBUG_CHECK_ASSERTIONS TBOX_ASSERT(d_level_num == x.getFinestLevelNumber()); #endif const int x_idx = x.getComponentDescriptorIndex(0); Pointer<SideVariable<NDIM,double> > x_var = x.getComponentVariable(0); const int b_idx = b.getComponentDescriptorIndex(0); Pointer<SideVariable<NDIM,double> > b_var = b.getComponentVariable(0); // Allocate DOF index data. VariableDatabase<NDIM>* var_db = VariableDatabase<NDIM>::getDatabase(); Pointer<SideDataFactory<NDIM,double> > x_fac = var_db->getPatchDescriptor()->getPatchDataFactory(x_idx); const int depth = x_fac->getDefaultDepth(); Pointer<SideDataFactory<NDIM,int> > dof_index_fac = var_db->getPatchDescriptor()->getPatchDataFactory(d_dof_index_idx); dof_index_fac->setDefaultDepth(depth); Pointer<PatchLevel<NDIM> > level = d_hierarchy->getPatchLevel(d_level_num); if (!level->checkAllocated(d_dof_index_idx)) level->allocatePatchData(d_dof_index_idx); // Setup PETSc objects. int ierr; PETScVecUtilities::constructPatchLevelVec(d_petsc_x, x_idx, x_var, level); PETScVecUtilities::constructPatchLevelVec(d_petsc_b, b_idx, b_var, level); PETScVecUtilities::constructPatchLevelDOFIndices(d_dof_index_idx, d_dof_index_var, x_idx, x_var, level); const double C = d_poisson_spec.cIsZero() ? 0.0 : d_poisson_spec.getCConstant(); const double D = d_poisson_spec.getDConstant(); PETScMatUtilities::constructPatchLevelLaplaceOp(d_petsc_mat, C, D, x_idx, x_var, d_dof_index_idx, d_dof_index_var, level, d_dof_index_fill); if (d_SJR_mat != PETSC_NULL) { ierr = PETScMatOps::MatAXPY(d_petsc_mat, 1.0, d_SJR_mat); IBTK_CHKERRQ(ierr); } ierr = MatSetBlockSize(d_petsc_mat, NDIM); IBTK_CHKERRQ(ierr); ierr = KSPCreate(PETSC_COMM_WORLD, &d_petsc_ksp); IBTK_CHKERRQ(ierr); ierr = KSPSetOperators(d_petsc_ksp, d_petsc_mat, d_petsc_mat, SAME_PRECONDITIONER); IBTK_CHKERRQ(ierr); if (!d_options_prefix.empty()) { ierr = KSPSetOptionsPrefix(d_petsc_ksp, d_options_prefix.c_str()); IBTK_CHKERRQ(ierr); } ierr = KSPSetFromOptions(d_petsc_ksp); IBTK_CHKERRQ(ierr); // Indicate that the solver is initialized. d_is_initialized = true; IBAMR_TIMER_STOP(t_initialize_solver_state); return; }// initializeSolverState
void FACPreconditioner::initializeSolverState( const SAMRAIVectorReal<double>& solution, const SAMRAIVectorReal<double>& rhs) { /* * First get rid of current data. */ deallocateSolverState(); /* * Set hierarchy and levels to solve. */ d_patch_hierarchy = solution.getPatchHierarchy(); d_coarsest_ln = solution.getCoarsestLevelNumber(); d_finest_ln = solution.getFinestLevelNumber(); /* * Set the solution-vector-dependent scratch space. */ d_error_vector = solution.cloneVector(d_object_name + "::error"); d_error_vector->allocateVectorData(); if (d_algorithm_choice == "mccormick-s4.3") { d_tmp_error = solution.cloneVector(d_object_name + "::temporary_error"); d_tmp_error->allocateVectorData(); } d_residual_vector = rhs.cloneVector(d_object_name + "::residual"); d_residual_vector->allocateVectorData(); d_tmp_residual = rhs.cloneVector(d_object_name + "::FAC coarser residual"); d_tmp_residual->allocateVectorData(); /* * Set the controlled level operators, which depend on the number * of components in the solution vector. */ math::HierarchyDataOpsManager* ops_manager = math::HierarchyDataOpsManager::getManager(); int num_components = solution.getNumberOfComponents(); d_controlled_level_ops.resize(num_components); for (int i = 0; i < num_components; ++i) { d_controlled_level_ops[i] = ops_manager->getOperationsDouble( solution.getComponentVariable(i), d_patch_hierarchy, true); /* * Note: the variable used above is only for the purpose of determining * the variable alignment on the grid. It is not specific to any * instance. */ } /* * Error checking. */ #ifdef DEBUG_CHECK_ASSERTIONS if (d_patch_hierarchy != rhs.getPatchHierarchy()) { TBOX_ERROR(d_object_name << ": vectors must have the same hierarchy.\n"); } if (d_coarsest_ln < 0) { TBOX_ERROR(d_object_name << ": coarsest level must not be negative.\n"); } if (d_coarsest_ln > d_finest_ln) { TBOX_ERROR(d_object_name << ": coarsest level must be <= finest" << "level.\n"); } #endif for (int ln = d_coarsest_ln; ln <= d_finest_ln; ++ln) { if (!d_patch_hierarchy->getPatchLevel(ln)) { TBOX_ERROR("FACPreconditioner::initializeSolverState error ..." << "\n object name = " << d_object_name << "\n hierarchy level " << ln << " does not exist" << std::endl); } } d_fac_operator->initializeOperatorState(solution, rhs); }
void INSStaggeredVCStokesOperator::apply( const bool /*homogeneous_bc*/, SAMRAIVectorReal<NDIM,double>& x, SAMRAIVectorReal<NDIM,double>& y) { IBAMR_TIMER_START(t_apply); // Get the vector components. // const int U_in_idx = x.getComponentDescriptorIndex(0); // const int P_in_idx = x.getComponentDescriptorIndex(1); const int U_out_idx = y.getComponentDescriptorIndex(0); const int P_out_idx = y.getComponentDescriptorIndex(1); const int U_scratch_idx = d_x_scratch->getComponentDescriptorIndex(0); const int P_scratch_idx = d_x_scratch->getComponentDescriptorIndex(1); const Pointer<Variable<NDIM> >& U_out_var = y.getComponentVariable(0); const Pointer<Variable<NDIM> >& P_out_var = y.getComponentVariable(1); Pointer<SideVariable<NDIM,double> > U_out_sc_var = U_out_var; Pointer<CellVariable<NDIM,double> > P_out_cc_var = P_out_var; const Pointer<Variable<NDIM> >& U_scratch_var = d_x_scratch->getComponentVariable(0); const Pointer<Variable<NDIM> >& P_scratch_var = d_x_scratch->getComponentVariable(1); Pointer<SideVariable<NDIM,double> > U_scratch_sc_var = U_scratch_var; Pointer<CellVariable<NDIM,double> > P_scratch_cc_var = P_scratch_var; d_x_scratch->copyVector(Pointer<SAMRAIVectorReal<NDIM,double> >(&x,false)); // Reset the interpolation operators and fill the data. typedef HierarchyGhostCellInterpolation::InterpolationTransactionComponent InterpolationTransactionComponent; InterpolationTransactionComponent U_scratch_component(U_scratch_idx, U_DATA_COARSEN_TYPE, BDRY_EXTRAP_TYPE, CONSISTENT_TYPE_2_BDRY); InterpolationTransactionComponent P_scratch_component(P_scratch_idx, P_DATA_COARSEN_TYPE, BDRY_EXTRAP_TYPE, CONSISTENT_TYPE_2_BDRY); InterpolationTransactionComponent mu_component(d_mu_data_idx, MU_DATA_COARSEN_TYPE, BDRY_EXTRAP_TYPE, CONSISTENT_TYPE_2_BDRY); std::vector<InterpolationTransactionComponent> U_P_MU_components(3); U_P_MU_components[0] = U_scratch_component; U_P_MU_components[1] = P_scratch_component; U_P_MU_components[2] = mu_component; d_U_P_MU_bdry_fill_op->resetTransactionComponents(U_P_MU_components); d_U_P_MU_bdry_fill_op->fillData(d_new_time); // Setup hierarchy data ops object for U. HierarchyDataOpsManager<NDIM>* hier_ops_manager = HierarchyDataOpsManager<NDIM>::getManager(); Pointer<PatchHierarchy<NDIM> > hierarchy = y.getPatchHierarchy(); Pointer<HierarchySideDataOpsReal<NDIM,double> > hier_sc_data_ops = hier_ops_manager->getOperationsDouble(U_out_var, hierarchy, true); // Compute the action of the operator: // A*[u;p] = [(rho/dt)*u-0.5*div*(mu*(grad u + (grad u)^T)) + grad p; -div u]. // static const bool cf_bdry_synch = true; d_hier_math_ops->pointwiseMultiply( U_out_idx, U_out_sc_var, d_rho_data_idx, d_rho_var, U_scratch_idx, U_scratch_sc_var, 0.0, -1, NULL); d_hier_math_ops->vc_laplace( U_out_idx, U_out_sc_var, -0.5, 0.0, d_mu_data_idx, d_mu_var, U_scratch_idx, U_scratch_sc_var, d_no_fill_op, d_new_time, 1.0/d_dt, U_out_idx, U_out_sc_var); d_hier_math_ops->grad( U_out_idx, U_out_sc_var, cf_bdry_synch, 1.0, P_scratch_idx, P_scratch_cc_var, d_no_fill_op, d_new_time, 1.0, U_out_idx, U_out_sc_var); d_hier_math_ops->div( P_out_idx, P_out_cc_var, -1.0, U_scratch_idx, U_scratch_sc_var, d_no_fill_op, d_new_time, cf_bdry_synch); IBAMR_TIMER_STOP(t_apply); return; }// apply
bool StaggeredStokesProjectionPreconditioner::solveSystem(SAMRAIVectorReal<NDIM, double>& x, SAMRAIVectorReal<NDIM, double>& b) { IBAMR_TIMER_START(t_solve_system); // Initialize the solver (if necessary). const bool deallocate_at_completion = !d_is_initialized; if (!d_is_initialized) initializeSolverState(x, b); // Determine whether we are solving a steady-state problem. const bool steady_state = d_U_problem_coefs.cIsZero() || (d_U_problem_coefs.cIsConstant() && MathUtilities<double>::equalEps(d_U_problem_coefs.getCConstant(), 0.0)); // Get the vector components. const int F_U_idx = b.getComponentDescriptorIndex(0); const int F_P_idx = b.getComponentDescriptorIndex(1); const Pointer<Variable<NDIM> >& F_U_var = b.getComponentVariable(0); const Pointer<Variable<NDIM> >& F_P_var = b.getComponentVariable(1); Pointer<SideVariable<NDIM, double> > F_U_sc_var = F_U_var; Pointer<CellVariable<NDIM, double> > F_P_cc_var = F_P_var; const int U_idx = x.getComponentDescriptorIndex(0); const int P_idx = x.getComponentDescriptorIndex(1); const Pointer<Variable<NDIM> >& U_var = x.getComponentVariable(0); const Pointer<Variable<NDIM> >& P_var = x.getComponentVariable(1); Pointer<SideVariable<NDIM, double> > U_sc_var = U_var; Pointer<CellVariable<NDIM, double> > P_cc_var = P_var; // Setup the component solver vectors. Pointer<SAMRAIVectorReal<NDIM, double> > F_U_vec; F_U_vec = new SAMRAIVectorReal<NDIM, double>(d_object_name + "::F_U", d_hierarchy, d_coarsest_ln, d_finest_ln); F_U_vec->addComponent(F_U_sc_var, F_U_idx, d_velocity_wgt_idx, d_velocity_data_ops); Pointer<SAMRAIVectorReal<NDIM, double> > U_vec; U_vec = new SAMRAIVectorReal<NDIM, double>(d_object_name + "::U", d_hierarchy, d_coarsest_ln, d_finest_ln); U_vec->addComponent(U_sc_var, U_idx, d_velocity_wgt_idx, d_velocity_data_ops); Pointer<SAMRAIVectorReal<NDIM, double> > Phi_scratch_vec; Phi_scratch_vec = new SAMRAIVectorReal<NDIM, double>(d_object_name + "::Phi_scratch", d_hierarchy, d_coarsest_ln, d_finest_ln); Phi_scratch_vec->addComponent(d_Phi_var, d_Phi_scratch_idx, d_pressure_wgt_idx, d_pressure_data_ops); Pointer<SAMRAIVectorReal<NDIM, double> > F_Phi_vec; F_Phi_vec = new SAMRAIVectorReal<NDIM, double>(d_object_name + "::F_Phi", d_hierarchy, d_coarsest_ln, d_finest_ln); F_Phi_vec->addComponent(d_F_Phi_var, d_F_Phi_idx, d_pressure_wgt_idx, d_pressure_data_ops); Pointer<SAMRAIVectorReal<NDIM, double> > P_vec; P_vec = new SAMRAIVectorReal<NDIM, double>(d_object_name + "::P", d_hierarchy, d_coarsest_ln, d_finest_ln); P_vec->addComponent(P_cc_var, P_idx, d_pressure_wgt_idx, d_pressure_data_ops); // Allocate scratch data. for (int ln = d_coarsest_ln; ln <= d_finest_ln; ++ln) { Pointer<PatchLevel<NDIM> > level = d_hierarchy->getPatchLevel(ln); level->allocatePatchData(d_Phi_scratch_idx); level->allocatePatchData(d_F_Phi_idx); } // (1) Solve the velocity sub-problem for an initial approximation to U. // // U^* := inv(rho/dt - K*mu*L) F_U // // An approximate Helmholtz solver is used. d_velocity_solver->setHomogeneousBc(true); LinearSolver* p_velocity_solver = dynamic_cast<LinearSolver*>(d_velocity_solver.getPointer()); if (p_velocity_solver) p_velocity_solver->setInitialGuessNonzero(false); d_velocity_solver->solveSystem(*U_vec, *F_U_vec); // (2) Solve the pressure sub-problem. // // We treat two cases: // // (i) rho/dt = 0. // // In this case, // // U - U^* + G Phi = 0 // -D U = F_P // // so that // // Phi := inv(-L_p) * F_Phi = inv(-L_p) * (-F_P - D U^*) // P := -K*mu*F_Phi // // in which L_p = D*G. // // (ii) rho/dt != 0. // // In this case, // // rho (U - U^*) + G Phi = 0 // -D U = F_P // // so that // // Phi := inv(-L_rho) * F_phi = inv(-L_rho) * (-F_P - D U^*) // P := (1/dt - K*mu*L_rho)*Phi = (1/dt) Phi - K*mu*F_phi // // in which L_rho = D*(1/rho)*G. // // Approximate Poisson solvers are used in both cases. d_hier_math_ops->div(d_F_Phi_idx, d_F_Phi_var, -1.0, U_idx, U_sc_var, d_no_fill_op, d_new_time, /*cf_bdry_synch*/ true, -1.0, F_P_idx, F_P_cc_var); d_pressure_solver->setHomogeneousBc(true); LinearSolver* p_pressure_solver = dynamic_cast<LinearSolver*>(d_pressure_solver.getPointer()); p_pressure_solver->setInitialGuessNonzero(false); d_pressure_solver->solveSystem(*Phi_scratch_vec, *F_Phi_vec); if (steady_state) { d_pressure_data_ops->scale(P_idx, -d_U_problem_coefs.getDConstant(), d_F_Phi_idx); } else { d_pressure_data_ops->linearSum( P_idx, 1.0 / getDt(), d_Phi_scratch_idx, -d_U_problem_coefs.getDConstant(), d_F_Phi_idx); } // (3) Evaluate U in terms of U^* and Phi. // // We treat two cases: // // (i) rho = 0. In this case, // // U = U^* - G Phi // // (ii) rho != 0. In this case, // // U = U^* - (1.0/rho) G Phi double coef; if (steady_state) { coef = -1.0; } else { coef = d_P_problem_coefs.getDConstant(); } d_hier_math_ops->grad(U_idx, U_sc_var, /*cf_bdry_synch*/ true, coef, d_Phi_scratch_idx, d_Phi_var, d_Phi_bdry_fill_op, d_pressure_solver->getSolutionTime(), 1.0, U_idx, U_sc_var); // Account for nullspace vectors. correctNullspace(U_vec, P_vec); // Deallocate scratch data. for (int ln = d_coarsest_ln; ln <= d_finest_ln; ++ln) { Pointer<PatchLevel<NDIM> > level = d_hierarchy->getPatchLevel(ln); level->deallocatePatchData(d_Phi_scratch_idx); level->deallocatePatchData(d_F_Phi_idx); } // Deallocate the solver (if necessary). if (deallocate_at_completion) deallocateSolverState(); IBAMR_TIMER_STOP(t_solve_system); return true; } // solveSystem