Exemplo n.º 1
0
void
AssignSubdomainID::modify()
{
  auto & mesh = _mesh_ptr->getMesh();

  auto elem_it = mesh.elements_begin();
  const auto end_it = mesh.elements_end();

  for (; elem_it != end_it; ++elem_it)
  {
    auto elem = *elem_it;

    elem->subdomain_id() = _subdomain_id;
  }
}
MaterialVectorPostprocessor::MaterialVectorPostprocessor(const InputParameters & parameters)
  : ElementVectorPostprocessor(parameters),
    _elem_filter(getParam<std::vector<unsigned int>>("elem_ids").begin(),
                 getParam<std::vector<unsigned int>>("elem_ids").end()),
    _elem_ids(declareVector("elem_id")),
    _qp_ids(declareVector("qp_id"))
{
  auto & mat = getMaterialByName(getParam<MaterialName>("material"), true);
  auto & prop_names = mat.getSuppliedItems();
  if (mat.isBoundaryMaterial())
    mooseError(name(), ": boundary materials (i.e. ", mat.name(), ") cannot be used");

  for (auto & id : _elem_filter)
  {
    auto el = _mesh.getMesh().query_elem_ptr(id);

    // We'd better have found the requested element on *some*
    // processor.
    bool found_elem = (el != nullptr);
    this->comm().max(found_elem);

    // We might not have el on this processor in a distributed mesh,
    // but it should be somewhere and it ought to have a material
    // defined for its subdomain
    if (!found_elem || (el && !mat.hasBlocks(el->subdomain_id())))
      mooseError(name(), ": material ", mat.name(), " is not defined on element ", id);
  }

  for (auto & prop : prop_names)
  {
    if (hasMaterialProperty<Real>(prop))
      _prop_refs.push_back(&getMaterialProperty<Real>(prop));
    else if (hasMaterialProperty<unsigned int>(prop))
      _prop_refs.push_back(&getMaterialProperty<unsigned int>(prop));
    else if (hasMaterialProperty<int>(prop))
      _prop_refs.push_back(&getMaterialProperty<int>(prop));
    else
    {
      mooseWarning("property " + prop +
                   " is of unsupported type and skipped by MaterialVectorPostprocessor");
      continue;
    }
    _prop_vecs.push_back(&declareVector(prop));
    _prop_names.push_back(prop);
  }
}