double dfact(double n) { if (n <= 1) return 1.0; else return n * dfact(n-1.0); }
bool CoarsenClasses::itemIsValid( const CoarsenClasses::Data& data_item, const std::shared_ptr<hier::PatchDescriptor>& descriptor) const { bool item_good = true; std::shared_ptr<hier::PatchDescriptor> pd(descriptor); if (!pd) { pd = hier::VariableDatabase::getDatabase()->getPatchDescriptor(); } const tbox::Dimension& dim = pd->getPatchDataFactory(data_item.d_dst)->getDim(); const int dst_id = data_item.d_dst; const int src_id = data_item.d_src; if (dst_id < 0) { item_good = false; TBOX_ERROR("Bad data given to CoarsenClasses...\n" << "`Destination' patch data id invalid (< 0!)" << std::endl); } if (item_good && (src_id < 0)) { item_good = false; TBOX_ERROR("Bad data given to CoarsenClasses...\n" << "`Source' patch data id invalid (< 0!)" << std::endl); } std::shared_ptr<hier::PatchDataFactory> dfact( pd->getPatchDataFactory(dst_id)); std::shared_ptr<hier::PatchDataFactory> sfact( pd->getPatchDataFactory(src_id)); if (item_good && !(sfact->validCopyTo(dfact))) { item_good = false; TBOX_ERROR("Bad data given to CoarsenClasses...\n" << "It is not a valid operation to copy from `Source' patch data \n" << pd->mapIndexToName(src_id) << " to `Destination' patch data " << pd->mapIndexToName(dst_id) << std::endl); } std::shared_ptr<hier::CoarsenOperator> coarsop(data_item.d_opcoarsen); if (item_good && coarsop) { if (coarsop->getStencilWidth(dim) > sfact->getGhostCellWidth()) { item_good = false; TBOX_ERROR("Bad data given to CoarsenClasses...\n" << "Coarsen operator " << coarsop->getOperatorName() << "\nhas larger stencil width than ghost cell width" << "of `Source' patch data" << pd->mapIndexToName(src_id) << "\noperator stencil width = " << coarsop->getStencilWidth(dim) << "\n`Source' ghost width = " << sfact->getGhostCellWidth() << std::endl); } } return item_good; }