bool BlockRestrictable::hasBlockMaterialPropertyHelper(const std::string & prop_name) { // Reference to MaterialWarehouse for testing and retrieving block ids MaterialWarehouse & material_warehouse = _blk_feproblem->getMaterialWarehouse(_blk_tid); // Complete set of ids that this object is active const std::set<SubdomainID> & ids = hasBlocks(Moose::ANY_BLOCK_ID) ? meshBlockIDs() : blockIDs(); // Loop over each id for this object for (std::set<SubdomainID>::const_iterator id_it = ids.begin(); id_it != ids.end(); ++id_it) { // Storage of material properties that have been DECLARED on this id std::set<std::string> declared_props; // If block materials exist, populated the set of properties that were declared if (material_warehouse.hasMaterials(*id_it)) { std::vector<Material *> mats = material_warehouse.getMaterials(*id_it); for (std::vector<Material *>::iterator mat_it = mats.begin(); mat_it != mats.end(); ++mat_it) { const std::set<std::string> & mat_props = (*mat_it)->getSuppliedItems(); declared_props.insert(mat_props.begin(), mat_props.end()); } } // If the supplied property is not in the list of properties on the current id, return false if (declared_props.find(prop_name) == declared_props.end()) return false; } // If you get here the supplied property is defined on all blocks return true; }
bool BlockRestrictable::hasBlockMaterialPropertyHelper(const std::string & prop_name) { // Reference to MaterialWarehouse for testing and retrieving block ids const MaterialWarehouse & warehouse = _blk_feproblem->getMaterialWarehouse(); // Complete set of ids that this object is active const std::set<SubdomainID> & ids = hasBlocks(Moose::ANY_BLOCK_ID) ? meshBlockIDs() : blockIDs(); // Loop over each id for this object for (const auto & id : ids) { // Storage of material properties that have been DECLARED on this id std::set<std::string> declared_props; // If block materials exist, populated the set of properties that were declared if (warehouse.hasActiveBlockObjects(id)) { const std::vector<MooseSharedPointer<Material> > & mats = warehouse.getActiveBlockObjects(id); for (const auto & mat : mats) { const std::set<std::string> & mat_props = mat->getSuppliedItems(); declared_props.insert(mat_props.begin(), mat_props.end()); } } // If the supplied property is not in the list of properties on the current id, return false if (declared_props.find(prop_name) == declared_props.end()) return false; } // If you get here the supplied property is defined on all blocks return true; }
bool BlockRestrictable::hasBlocks(SubdomainName name) const { // Create a vector and utilize the getSubdomainIDs function, which // handles the ANY_BLOCK_ID (getSubdomainID does not) std::vector<SubdomainName> names(1); names[0] = name; return hasBlocks(_blk_mesh->getSubdomainIDs(names)); }
bool Material::hasBlockMaterialPropertyHelper(const std::string & name) { // Reference to MaterialWarehouse for testing and retrieving block ids MaterialWarehouse & material_warehouse = _fe_problem.getMaterialWarehouse(_tid); // Complete set of ids that this object is active const std::set<SubdomainID> & ids = hasBlocks(Moose::ANY_BLOCK_ID) ? meshBlockIDs() : blockIDs(); // Flags for the various material types bool neighbor = getParam<bool>("_neighbor"); bool bnd = getParam<bool>("_bnd"); // Define function pointers to the correct has/get methods for the type of material bool(MaterialWarehouse::*has_func)(SubdomainID) const; std::vector<Material *> & (MaterialWarehouse::*get_func)(SubdomainID); if (bnd && neighbor) { has_func = &MaterialWarehouse::hasNeighborMaterials; get_func = &MaterialWarehouse::getNeighborMaterials; } else if (bnd && !neighbor) { has_func = &MaterialWarehouse::hasFaceMaterials; get_func = &MaterialWarehouse::getFaceMaterials; } else { has_func = &MaterialWarehouse::hasMaterials; get_func = &MaterialWarehouse::getMaterials; } // Loop over each id for this object for (std::set<SubdomainID>::const_iterator id_it = ids.begin(); id_it != ids.end(); ++id_it) { // Storage of material properties that have been DECLARED on this id std::set<std::string> declared_props; // If block materials exist, populated the set of properties that were declared if ((material_warehouse.*has_func)(*id_it)) { std::vector<Material *> mats = (material_warehouse.*get_func)(*id_it); for (std::vector<Material *>::iterator mat_it = mats.begin(); mat_it != mats.end(); ++mat_it) { const std::set<std::string> & mat_props = (*mat_it)->getSuppliedItems(); declared_props.insert(mat_props.begin(), mat_props.end()); } } // If the supplied property is not in the list of properties on the current id, return false if (declared_props.find(name) == declared_props.end()) return false; } // If you get here the supplied property is defined on all blocks return true; }
bool BlockRestrictable::hasBlocks(std::vector<SubdomainID> ids) const { std::set<SubdomainID> ids_set(ids.begin(), ids.end()); return hasBlocks(ids_set); }
bool BlockRestrictable::hasBlocks(std::vector<SubdomainName> names) const { return hasBlocks(_blk_mesh->getSubdomainIDs(names)); }
BlkResTestDiffusion::BlkResTestDiffusion(const InputParameters & parameters) : Kernel(modifyParams(parameters)) { // Get an test enum from the kernel parameters MooseEnum test = parameters.get<MooseEnum>("test"); // test that hasBlocks is working if (test == "hasBlocks") { // Define a SubdomainName vector for testing against std::vector<SubdomainName> id_names(2); id_names[0] = "1"; id_names[1] = "2"; // Define a SubdomainID vector for testing against std::vector<SubdomainID> ids(2); ids[0] = 1; ids[1] = 2; // Define a SubdomainID set for testing against std::set<SubdomainID> id_set(ids.begin(), ids.end()); // Test true single SudomainName input if (!hasBlocks("1")) mooseError("Test 1: hasBlocks(SubdomainName) = true failed"); // Test false of single Subdomain input if (hasBlocks("3")) mooseError("Test 2: hasBlocks(SubdomainName) = false failed"); // Test true vector SubdomainName input if (!hasBlocks(id_names)) mooseError("Test 3: hasBlocks(std::vector<SubdomainName>) = true failed"); // Test false vector SudomainName input id_names.push_back("3"); if (hasBlocks(id_names)) mooseError("Test 4: hasBlocks(std::vector<SubdomainName>) = false failed"); // Test true single SubdomainID input if (!hasBlocks(1)) mooseError("Test 5: hasBlocks(SubdomainID) = true failed"); // Test false single SubdomainID input if (hasBlocks(5)) mooseError("Test 6: hasBlocks(SubdomainID) = false failed"); // Test true for std::vector<SubdomainID> if (!hasBlocks(ids)) mooseError("Test 7: hasBlocks(std::vector<SubdomainID>) = true failed"); // Test false for std::vector<SubdomainID> ids.push_back(4); if (hasBlocks(ids)) mooseError("Test 8: hasBlocks(std::vector<SubdomainID>) = false failed"); // Test true for std::set<SubdomainID> if (!hasBlocks(id_set)) mooseError("Test 9: hasBlocks(std::set<SubdomainID) = true failed"); // Test false for std::set<SubdomainID> id_set.insert(12); if (hasBlocks(id_set)) mooseError("Test 10: hasBlocks(std::set<SubdomainID>) = false failed"); // This is the expected error, all the above tests passed mooseError("hasBlocks testing passed"); } // Test of stored ANY_BLOCK_ID on object else if (test == "hasBlocks_ANY_BLOCK_ID") { // Test that ANY_BLOCK_ID is working if (hasBlocks(1)) mooseError("hasBlocks_ANY_BLOCK_ID test passed"); else mooseError("hasBlocks_ANY_BLOCK_ID test failed"); } // Test that the blocks() method is working else if (test == "blocks") { const std::vector<SubdomainName> & blks = blocks(); if (blks[0] == "1" && blks[1] == "2" && blks.size() == 2) mooseError("Blocks testing passed"); // expected error else mooseError("Blocks testing failed"); } // Test that the getSubdomains() is working else if (test == "blockIDs") { const std::set<SubdomainID> & ids = blockIDs(); if (ids.count(1) == 1 && ids.count(2) == 1) mooseError("blockIDs testing passed"); // expected error else mooseError("blockIDs testing failed"); } // Test that the isSubset() is working else if (test == "isBlockSubset") { std::set<SubdomainID> sub_id; sub_id.insert(10); sub_id.insert(1); sub_id.insert(4); sub_id.insert(2); if (isBlockSubset(sub_id)) mooseError("isBlockSubset testing passed"); // expected error else mooseError("isBlockSubset testing failed"); } // Test that hasMaterialPropertyBlock is working properly else if (test == "hasBlockMaterialProperty_true") { if (hasBlockMaterialProperty<Real>("a")) mooseError("hasBlockMaterialProperty is true, test passed"); // expected error else mooseError("hasBlockMaterialProperty is false, test failed"); } else if (test == "hasBlockMaterialProperty_false") { if (hasBlockMaterialProperty<Real>("b")) mooseError("hasBlockMaterialProperty is true, test failed"); else mooseError("hasBlockMaterialProperty is false, test passed"); // expected error } }