void
AddSecondarySpeciesAction::act()
{
  // Checking to see if there are aqueous eqilibrium species to be added as aux variables
  if (_pars.isParamValid("secondary_species"))
  {
    std::vector<AuxVariableName> vars = getParam<std::vector<AuxVariableName> >("secondary_species");

    for (unsigned int i=0; i < vars.size(); i++)
    {
      Moose::out << "aux variables: " << vars[i] << "\t";
      FEType fe_type(Utility::string_to_enum<Order>("first"),
                     Utility::string_to_enum<FEFamily>("lagrange"));
      _problem->addAuxVariable(vars[i], fe_type);
    }
  }
  else
  {
    // Checking to see if there are solid kinetic species to be added as aux variables
    if (_pars.isParamValid("kin_reactions"))
    {
      std::vector<std::string> reactions = getParam<std::vector<std::string> >("kin_reactions");
      for (unsigned int j=0; j < reactions.size(); j++)
      {
        std::vector<std::string> tokens;
        std::string kin_species;

        // Parsing each reaction
        MooseUtils::tokenize(reactions[j], tokens, 1, "+=");

        for (unsigned int k=0; k < tokens.size(); k++)
        {
          std::vector<std::string> stos_vars;
          MooseUtils::tokenize(tokens[k], stos_vars, 1, "()");
          if(stos_vars.size() == 1)
          {
            kin_species = stos_vars[0];
            Moose::out << "I'm here and the kin_species is: " << stos_vars[0] << "\n";

          }
//           else
//             mooseError("There's no solid kinetic species.");
        }
        Moose::out << "the " << j+1 << "-th solid kinetic species: " << kin_species << "\n";
        FEType fe_type(Utility::string_to_enum<Order>("first"),
                       Utility::string_to_enum<FEFamily>("lagrange"));
        _problem->addAuxVariable(kin_species, fe_type);

      }

    }
  }

}
Exemple #2
0
bool InfHex8::contains_point (const Point& p, Real tol) const
{
  /*
   * For infinite elements with linear base interpolation:
   *
   * make use of the fact that infinite elements do not
   * live inside the envelope.  Use a fast scheme to
   * check whether point \p p is inside or outside
   * our relevant part of the envelope.  Note that
   * this is not exclusive: only when the distance is less,
   * we are safe.  Otherwise, we cannot say anything. The
   * envelope may be non-spherical, the physical point may lie
   * inside the envelope, outside the envelope, or even inside
   * this infinite element.  Therefore if this fails,
   * fall back to the FEInterface::inverse_map()
   */
  const Point my_origin (this->origin());

  /*
   * determine the minimal distance of the base from the origin
   * Use size_sq() instead of size(), it is faster
   */
  const Real min_distance_sq = std::min((Point(this->point(0)-my_origin)).size_sq(),
                                        std::min((Point(this->point(1)-my_origin)).size_sq(),
                                                 std::min((Point(this->point(2)-my_origin)).size_sq(),
                                                          (Point(this->point(3)-my_origin)).size_sq())));

  /*
   * work with 1% allowable deviation.  We can still fall
   * back to the InfFE::inverse_map()
   */
  const Real conservative_p_dist_sq = 1.01 * (Point(p-my_origin).size_sq());



  if (conservative_p_dist_sq < min_distance_sq)
    {
      /*
       * the physical point is definitely not contained in the element
       */
      return false;
    }
  else
    {
      /*
       * Declare a basic FEType.  Will use default in the base,
       * and something else (not important) in radial direction.
       */
      FEType fe_type(default_order());

      const Point mapped_point = FEInterface::inverse_map(dim(),
                                                          fe_type,
                                                          this,
                                                          p,
                                                          tol,
                                                          false);

      return FEInterface::on_reference_element(mapped_point, this->type(), tol);
    }
}
Exemple #3
0
void
ReconVarICAction::act()
{
#ifdef DEBUG
  Moose::err << "Inside the ReconVarICAction Object\n";
#endif

  if (_current_task == "add_ic")
  {
    // Set initial condition for each order parameter
    for (unsigned int op = 0; op < _op_num; ++op)
    {
      // Create variable names
      std::string var_name = _var_name_base;
      std::stringstream out;
      out << op;
      var_name.append(out.str());

      {
        // Define parameters for ReconVarIC
        InputParameters poly_params = _factory.getValidParams("ReconVarIC");
        poly_params.set<VariableName>("variable") = var_name;
        poly_params.set<unsigned int>("op_index") = op;
        poly_params.set<unsigned int>("op_num") = _op_num;
        poly_params.set<UserObjectName>("ebsd_reader") = getParam<UserObjectName>("ebsd_reader");
        poly_params.set<bool>("advanced_op_assignment") = getParam<bool>("advanced_op_assignment");
        if (isParamValid("phase"))
          poly_params.set<unsigned int>("phase") = getParam<unsigned int>("phase");

        // Add initial condition
        _problem->addInitialCondition("ReconVarIC", "Initialize_op_" + Moose::stringify(op), poly_params);
      }
    }

    // Add the elemental op
    InputParameters poly_params = _factory.getValidParams("ReconVarIC");
    poly_params.set<VariableName>("variable") = std::string(_var_name_base + "_op");
    poly_params.set<unsigned int>("op_index") = 0; // Unused
    poly_params.set<unsigned int>("op_num") = _op_num;
    poly_params.set<bool>("all_op_elemental") = true;
    poly_params.set<UserObjectName>("ebsd_reader") = getParam<UserObjectName>("ebsd_reader");
    poly_params.set<bool>("advanced_op_assignment") = getParam<bool>("advanced_op_assignment");
    if (isParamValid("phase"))
      poly_params.set<unsigned int>("phase") = getParam<unsigned int>("phase");

    // Add initial condition
    _problem->addInitialCondition("ReconVarIC", "Initialize_elem_op", poly_params);
  }
  else if (_current_task == "add_aux_variable")
  {
    Order order = CONSTANT;
    FEFamily family = MONOMIAL;
    FEType fe_type(order, family);

    _problem->addAuxVariable(std::string(_var_name_base + "_op"), fe_type);
  }
}
Exemple #4
0
void
AddNodalNormalsAction::act()
{
  // Set the order from the input
  Order order = Utility::string_to_enum<Order>(getParam<MooseEnum>("order"));
  FEFamily family = LAGRANGE;
  FEType fe_type(order, family);

  // Add 3 aux variables for each component of the normal
  if (_current_action == "add_aux_variable")
  {
    _problem->addAuxVariable("nodal_normal_x", fe_type);
    _problem->addAuxVariable("nodal_normal_y", fe_type);
    _problem->addAuxVariable("nodal_normal_z", fe_type);
  }

  // Set the execute options
  std::vector<MooseEnum> execute_options = SetupInterface::getExecuteOptions();
  execute_options[0] = "timestep_begin";

  // Create the NodalNormalsPreprocessor UserObject
  if (_current_action == "add_postprocessor")
  {
    InputParameters pars = _factory.getValidParams("NodalNormalsPreprocessor");
    pars.set<Order>("fe_order") = order;
    pars.set<FEFamily>("fe_family") = family;
    pars.set<std::vector<MooseEnum> >("execute_on") = execute_options;
    pars.set<std::vector<BoundaryName> >("boundary") = _boundary;

    if (_has_corners)
      pars.set<BoundaryName>("corner_boundary") = _corner_boundary;

    _problem->addUserObject("NodalNormalsPreprocessor", "nodal_normals_preprocessor", pars);
  }

  if (_current_action == "add_user_object")
  {
    /// Create the NodalNormalsCorner UserObject (only if corner boundary is given)
    if (_has_corners)
    {
      InputParameters pars = _factory.getValidParams("NodalNormalsCorner");
      pars.set<std::vector<MooseEnum> >("execute_on") = execute_options;
      pars.set<std::vector<BoundaryName> >("boundary") = _boundary;
      pars.set<BoundaryName>("corner_boundary") = _corner_boundary;
      _problem->addUserObject("NodalNormalsCorner", "nodal_normals_corner", pars);
    }

    /// Create the NodalNormalsEvaluator UserObject
    {
      InputParameters pars = _factory.getValidParams("NodalNormalsEvaluator");
      pars.set<std::vector<MooseEnum> >("execute_on") = execute_options;
      pars.set<std::vector<BoundaryName> >("boundary") = _boundary;
      _problem->addUserObject("NodalNormalsEvaluator", "nodal_normals_evaluator", pars);
    }
  }
}
Exemple #5
0
bool InfQuad4::contains_point (const Point& p, Real tol) const
{
  /*
   * make use of the fact that infinite elements do not
   * live inside the envelope.  Use a fast scheme to
   * check whether point \p p is inside or outside
   * our relevant part of the envelope.  Note that
   * this is not exclusive: the point may be outside
   * the envelope, but contained in another infinite element.
   * Therefore, if the distance is greater, do fall back
   * to the scheme of using FEInterface::inverse_map().
   */
  const Point origin (this->origin());

  /*
   * determine the minimal distance of the base from the origin
   * use size_sq() instead of size(), it is slightly faster
   */
  const Real min_distance_sq = std::min((Point(this->point(0)-origin)).size_sq(),
					(Point(this->point(1)-origin)).size_sq());

  /*
   * work with 1% allowable deviation.  Can still fall
   * back to the InfFE::inverse_map()
   */
  const Real conservative_p_dist_sq = 1.01 * (Point(p-origin).size_sq());

  if (conservative_p_dist_sq < min_distance_sq)
    {
      /*
       * the physical point is definitely not contained
       * in the element, return false.
       */
      return false;
    }
  else
    {
      /*
       * cannot say anything, fall back to the FEInterface::inverse_map()
       *
       * Declare a basic FEType.  Will use default in the base,
       * and something else (not important) in radial direction.
       */
      FEType fe_type(default_order());

      const Point mapped_point = FEInterface::inverse_map(dim(),
							  fe_type,
							  this,
							  p,
							  tol,
							  false);

      return FEInterface::on_reference_element(mapped_point, this->type(), tol);
    }
}
void
AddLotsOfAuxVariablesAction::act()
{

  unsigned int number = getParam<unsigned int>("number");
  for (unsigned int cur_num = 0; cur_num < number; cur_num++)
  {
    std::string var_name = name() + Moose::stringify(cur_num);
    FEType fe_type(Utility::string_to_enum<Order>(getParam<MooseEnum>("order")),
                   Utility::string_to_enum<FEFamily>(getParam<MooseEnum>("family")));

    std::set<SubdomainID> blocks;
    std::vector<SubdomainName> block_param = getParam<std::vector<SubdomainName> >("block");
    for (std::vector<SubdomainName>::iterator it = block_param.begin(); it != block_param.end(); ++it)
    {
      SubdomainID blk_id = _problem->mesh().getSubdomainID(*it);
      blocks.insert(blk_id);
    }

    bool scalar_var = false;                              // true if adding scalar variable

    if (fe_type.family == SCALAR)
    {
      _problem->addAuxScalarVariable(var_name, fe_type.order);
      scalar_var = true;
    }
    else if (blocks.empty())
      _problem->addAuxVariable(var_name, fe_type);
    else
      _problem->addAuxVariable(var_name, fe_type, &blocks);

    // Set initial condition
    Real initial = getParam<Real>("initial_condition");
    if (initial > _abs_zero_tol || initial < -_abs_zero_tol)
    {
      if (scalar_var)
      {
        // built a ScalarConstantIC object
        InputParameters params = _factory.getValidParams("ScalarConstantIC");
        params.set<VariableName>("variable") = var_name;
        params.set<Real>("value") = initial;
        _problem->addInitialCondition("ScalarConstantIC", "ic", params);
      }
      else
      {
        // built a ConstantIC object
        InputParameters params = _factory.getValidParams("ConstantIC");
        params.set<VariableName>("variable") = var_name;
        params.set<Real>("value") = initial;
        _problem->addInitialCondition("ConstantIC", "ic", params);
      }
    }
  }
}
void
AddPrimarySpeciesAction::act()
{
  for (unsigned int i = 0; i < _vars.size(); ++i)
  {
    FEType fe_type(Utility::string_to_enum<Order>("first"),
                   Utility::string_to_enum<FEFamily>("lagrange"));

    Real scale_factor = 1.0;
    _problem->addVariable(_vars[i], fe_type, scale_factor);
  }
}
void
SideSetsGeneratorBase::setup(MeshBase & mesh)
{
  mooseAssert(_fe_face == nullptr, "FE Face has already been initialized");

  unsigned int dim = mesh.mesh_dimension();

  // Setup the FE Object so we can calculate normals
  FEType fe_type(Utility::string_to_enum<Order>("CONSTANT"),
                 Utility::string_to_enum<FEFamily>("MONOMIAL"));
  _fe_face = FEBase::build(dim, fe_type);
  _qface = libmesh_make_unique<QGauss>(dim - 1, FIRST);
  _fe_face->attach_quadrature_rule(_qface.get());
}
Exemple #9
0
void
AddSideSetsBase::setup()
{
  mooseAssert(_mesh_ptr != NULL, "Mesh pointer is NULL");
  mooseAssert(_fe_face == NULL, "FE Face has already been initialized");

  unsigned int dim = _mesh_ptr->dimension();

  // Setup the FE Object so we can calculate normals
  FEType fe_type(Utility::string_to_enum<Order>("CONSTANT"), Utility::string_to_enum<FEFamily>("MONOMIAL"));
  _fe_face = (FEBase::build(dim, fe_type)).release();
  _qface = new QGauss(dim-1, FIRST);
  _fe_face->attach_quadrature_rule(_qface);
}
void
AddPrimarySpeciesAction::act()
{
  std::vector<NonlinearVariableName> vars = getParam<std::vector<NonlinearVariableName> >("primary_species");

  for (unsigned int i=0; i < vars.size(); i++)
  {
    FEType fe_type(Utility::string_to_enum<Order>("first"),
                   Utility::string_to_enum<FEFamily>("lagrange"));
    Real scale_factor = 1.0;
    _problem->addVariable(vars[i], fe_type, scale_factor);
  }

}
Exemple #11
0
void
MaxQpsThread::operator()(const ConstElemRange & range)
{
  ParallelUniqueId puid;
  _tid = puid.id;

  // For short circuiting reinit
  std::set<ElemType> seen_it;
  for (const auto & elem : range)
  {
    // Only reinit if the element type has not previously been seen
    if (seen_it.insert(elem->type()).second)
    {
      FEType fe_type(FIRST, LAGRANGE);
      unsigned int dim = elem->dim();
      unsigned int side = 0; // we assume that any element will have at least one side ;)

      // We cannot mess with the FE objects in Assembly, because we might need to request second
      // derivatives
      // later on. If we used them, we'd call reinit on them, thus making the call to request second
      // derivatives harmful (i.e. leading to segfaults/asserts). Thus, we have to use a locally
      // allocated object here.
      std::unique_ptr<FEBase> fe(FEBase::build(dim, fe_type));

      // figure out the number of qps for volume
      std::unique_ptr<QBase> qrule(QBase::build(_qtype, dim, _order));
      fe->attach_quadrature_rule(qrule.get());
      fe->reinit(elem);
      if (qrule->n_points() > _max)
        _max = qrule->n_points();

      unsigned int n_shape_funcs = fe->n_shape_functions();
      if (n_shape_funcs > _max_shape_funcs)
        _max_shape_funcs = n_shape_funcs;

      // figure out the number of qps for the face
      // NOTE: user might specify higher order rule for faces, thus possibly ending up with more qps
      // than in the volume
      std::unique_ptr<QBase> qrule_face(QBase::build(_qtype, dim - 1, _face_order));
      fe->attach_quadrature_rule(qrule_face.get());
      fe->reinit(elem, side);
      if (qrule_face->n_points() > _max)
        _max = qrule_face->n_points();
    }
  }
}
Exemple #12
0
void
MaxQpsThread::operator() (const ConstElemRange & range)
{
    ParallelUniqueId puid;
    _tid = puid.id;

    // For short circuiting reinit
    std::set<ElemType> seen_it;
    for (ConstElemRange::const_iterator elem_it = range.begin() ; elem_it != range.end(); ++elem_it)
    {
        const Elem * elem = *elem_it;

        // Only reinit if the element type has not previously been seen
        if (seen_it.insert(elem->type()).second)
        {
            FEType fe_type(FIRST, LAGRANGE);
            unsigned int dim = elem->dim();
            unsigned int side = 0;           // we assume that any element will have at least one side ;)

            // We cannot mess with the FE objects in Assembly, because we might need to request second derivatives
            // later on. If we used them, we'd call reinit on them, thus making the call to request second
            // derivatives harmful (i.e. leading to segfaults/asserts). Thus, we have to use a locally allocated object here.
            FEBase * fe = FEBase::build(dim, fe_type).release();

            // figure out the number of qps for volume
            QBase * qrule = QBase::build(_qtype, dim, _order).release();
            fe->attach_quadrature_rule(qrule);
            fe->reinit(elem);
            if (qrule->n_points() > _max)
                _max = qrule->n_points();
            delete qrule;

            // figure out the number of qps for the face
            // NOTE: user might specify higher order rule for faces, thus possibly ending up with more qps than in the volume
            QBase * qrule_face = QBase::build(_qtype, dim - 1, _face_order).release();
            fe->attach_quadrature_rule(qrule_face);
            fe->reinit(elem, side);
            if (qrule_face->n_points() > _max)
                _max = qrule_face->n_points();
            delete qrule_face;

            delete fe;
        }
    }
}
void
DisplayGhostingAction::act()
{
  if (_display_ghosting == false)
    return;

  auto n_procs = _app.n_processors();

  if (_current_task == "add_aux_variable")
  {
    FEType fe_type(CONSTANT, MONOMIAL);

    for (unsigned int i = 0; i < 2; ++i)
    {
      std::string var_name_base = (i == 0 ? "geometric" : "algebraic");
      for (decltype(n_procs) proc_id = 0; proc_id < n_procs; ++proc_id)
        _problem->addAuxVariable(var_name_base + std::to_string(proc_id), fe_type);
    }
  }
  else if (_current_task == "add_aux_kernel")
  {
    for (unsigned int i = 0; i < 2; ++i)
    {
      std::string aux_kernel_name_base = i == 0 ? "geometric" : "algebraic";
      for (decltype(n_procs) proc_id = 0; proc_id < n_procs; ++proc_id)
      {
        std::string name = aux_kernel_name_base + std::to_string(proc_id);

        auto params = _factory.getValidParams("GhostingAux");
        params.set<processor_id_type>("pid") = proc_id;
        params.set<MooseEnum>("functor_type") = aux_kernel_name_base;
        params.set<UserObjectName>("ghost_uo") = "ghost_uo";
        params.set<AuxVariableName>("variable") = name;
        params.set<bool>("include_local_elements") = _include_local;

        _problem->addAuxKernel("GhostingAux", name, params);
      }
    }
  }
  else if (_current_task == "add_user_object")
  {
    auto params = _factory.getValidParams("GhostingUserObject");
    _problem->addUserObject("GhostingUserObject", "ghost_uo", params);
  }
}
void
AddElementalFieldAction::act()
{
    std::set<SubdomainID> blocks;
    std::vector<SubdomainName> block_param = getParam<std::vector<SubdomainName> >("block");
    for (std::vector<SubdomainName>::iterator it = block_param.begin(); it != block_param.end(); ++it)
    {
        SubdomainID blk_id = _problem->mesh().getSubdomainID(*it);
        blocks.insert(blk_id);
    }

    FEType fe_type(CONSTANT, MONOMIAL);

    std::string variable = getShortName();

    if (blocks.empty())
        _problem->addAuxVariable(variable, fe_type);
    else
        _problem->addAuxVariable(variable, fe_type, &blocks);
}
void
ComputeCrackTipEnrichmentSmallStrain::computeProperties()
{
  FEType fe_type(Utility::string_to_enum<Order>("first"),
                 Utility::string_to_enum<FEFamily>("lagrange"));
  const unsigned int dim = _current_elem->dim();
  std::unique_ptr<FEBase> fe(FEBase::build(dim, fe_type));
  fe->attach_quadrature_rule(_qrule);
  _fe_phi = &(fe->get_phi());
  _fe_dphi = &(fe->get_dphi());

  if (isBoundaryMaterial())
    fe->reinit(_current_elem, _current_side);
  else
    fe->reinit(_current_elem);

  for (unsigned int i = 0; i < _BI.size(); ++i)
    crackTipEnrichementFunctionAtPoint(*(_current_elem->get_node(i)), _BI[i]);

  ComputeStrainBase::computeProperties();
}
Real
InteractionIntegralSM::computeIntegral()
{
  Real sum = 0;

  // calculate phi and dphi for this element
  FEType fe_type(Utility::string_to_enum<Order>("first"),
                 Utility::string_to_enum<FEFamily>("lagrange"));
  const unsigned int dim = _current_elem->dim();
  UniquePtr<FEBase> fe(FEBase::build(dim, fe_type));
  fe->attach_quadrature_rule(_qrule);
  _phi_curr_elem = &fe->get_phi();
  _dphi_curr_elem = &fe->get_dphi();
  fe->reinit(_current_elem);

  // calculate q for all nodes in this element
  _q_curr_elem.clear();
  unsigned int ring_base = (_q_function_type == "TOPOLOGY") ? 0 : 1;

  for (unsigned int i = 0; i < _current_elem->n_nodes(); ++i)
  {
    Node * this_node = _current_elem->get_node(i);
    Real q_this_node;

    if (_q_function_type == "GEOMETRY")
      q_this_node = _crack_front_definition->DomainIntegralQFunction(
          _crack_front_point_index, _ring_index - ring_base, this_node);
    else if (_q_function_type == "TOPOLOGY")
      q_this_node = _crack_front_definition->DomainIntegralTopologicalQFunction(
          _crack_front_point_index, _ring_index - ring_base, this_node);

    _q_curr_elem.push_back(q_this_node);
  }

  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
    sum += _JxW[_qp] * _coord[_qp] * computeQpIntegral();
  return sum;
}
Exemple #17
0
MooseSharedPointer<MooseObjectAction>
PikaCriteriaAction::createAction(const std::string & type, const std::string & name)
{
  // Set the AuxKernel action properties
  std::ostringstream long_name;
  long_name << "AuxKernels/_pika_" << name << "_aux_kernel";
  InputParameters action_params = _action_factory.getValidParams("AddKernelAction");

  action_params.set<std::string>("type") = type;
  action_params.set<ActionWarehouse *>("awh") = &_awh;
  action_params.set<std::string>("registered_identifier") = "(AutoBuilt)";
  action_params.set<std::string>("task") = "add_aux_kernel";

  // Create the action
  MooseSharedPointer<MooseObjectAction> action = MooseSharedNamespace::static_pointer_cast<MooseObjectAction>
    (_action_factory.create("AddKernelAction", long_name.str(), action_params));

  // Set the variable name other object parameters
  std::ostringstream var_name;
  var_name << "_pika_" << name << "_aux";
  InputParameters & object_params = action->getObjectParams();
  object_params.set<AuxVariableName>("variable") = var_name.str();
  object_params.set<MultiMooseEnum>("execute_on") = "timestep_end";
//  object_params.set<bool>("use_temporal_scaling") = getParam<bool>("use_temporal_scaling");
  object_params.set<Real>("coefficient") = 1.0;
  object_params.applyParameters(_pars);

  // Add the variable
  FEType fe_type(CONSTANT, MONOMIAL);
  _problem->addAuxVariable(var_name.str(), fe_type);

  // Add the postprocessors actions
  createPostprocessorActions(name, var_name.str());

  // Return the action
  return action;
}
MultiAppProjectionTransfer::MultiAppProjectionTransfer(const std::string & name, InputParameters parameters) :
    MultiAppTransfer(name, parameters),
    _to_var_name(getParam<AuxVariableName>("variable")),
    _from_var_name(getParam<VariableName>("source_variable")),
    _proj_type(getParam<MooseEnum>("proj_type")),
    _compute_matrix(true)
{
  switch (_direction)
  {
    case TO_MULTIAPP:
      {
        unsigned int n_apps = _multi_app->numGlobalApps();
        _proj_sys.resize(n_apps, NULL);
        for (unsigned int app = 0; app < n_apps; app++)
        {
          if (_multi_app->hasLocalApp(app))
          {
            MPI_Comm swapped = Moose::swapLibMeshComm(_multi_app->comm());

            FEProblem & to_problem = *_multi_app->appProblem(app);
            FEType fe_type(Utility::string_to_enum<Order>(getParam<MooseEnum>("order")),
                           Utility::string_to_enum<FEFamily>(getParam<MooseEnum>("family")));
            to_problem.addAuxVariable(_to_var_name, fe_type, NULL);

            EquationSystems & to_es = to_problem.es();
            LinearImplicitSystem & proj_sys = to_es.add_system<LinearImplicitSystem>("proj-sys-" + Utility::enum_to_string<FEFamily>(fe_type.family)
                                                                                           + "-" + Utility::enum_to_string<Order>(fe_type.order));
            _proj_var_num = proj_sys.add_variable("var", fe_type);
            proj_sys.attach_assemble_function(assemble_l2_to);

            _proj_sys[app] = &proj_sys;

            //to_problem.hideVariableFromOutput("var");           // hide the auxiliary projection variable

            Moose::swapLibMeshComm(swapped);
          }
        }
      }
      break;

    case FROM_MULTIAPP:
      {
        _proj_sys.resize(1);

        FEProblem & to_problem = *_multi_app->problem();
        FEType fe_type(Utility::string_to_enum<Order>(getParam<MooseEnum>("order")),
                       Utility::string_to_enum<FEFamily>(getParam<MooseEnum>("family")));
        to_problem.addAuxVariable(_to_var_name, fe_type, NULL);

        EquationSystems & to_es = to_problem.es();
        LinearImplicitSystem & proj_sys = to_es.add_system<LinearImplicitSystem>("proj-sys-" + Utility::enum_to_string<FEFamily>(fe_type.family)
                                                                                       + "-" + Utility::enum_to_string<Order>(fe_type.order));
        _proj_var_num = proj_sys.add_variable("var", fe_type);
        proj_sys.attach_assemble_function(assemble_l2_from);

        _proj_sys[0] = &proj_sys;

        // to_problem.hideVariableFromOutput("var");           // hide the auxiliary projection variable
      }
      break;
  }
}
Exemple #19
0
void
IMPInitializer::registerMesh(MeshBase* mesh, int level_number)
{
    const int max_levels = d_gridding_alg->getMaxLevels();
    if (level_number < 0) level_number = max_levels - 1;
    level_number = std::min(level_number, max_levels - 1);
    const unsigned int mesh_idx = static_cast<unsigned int>(d_meshes[level_number].size());
    d_meshes[level_number].push_back(mesh);

    // Compute the Cartesian grid spacing on the specified level of the mesh.
    Pointer<CartesianGridGeometry<NDIM> > grid_geom = d_hierarchy->getGridGeometry();
    const double* const dx0 = grid_geom->getDx();
    double dx[NDIM];
    std::copy(dx0, dx0 + NDIM, dx);
    for (int ln = 1; ln <= level_number; ++ln)
    {
        const IntVector<NDIM> ratio = d_gridding_alg->getRatioToCoarserLevel(ln);
        for (unsigned int d = 0; d < NDIM; ++d) dx[d] /= static_cast<double>(ratio(d));
    }
    const double dx_min = *std::min_element(dx, dx + NDIM);

    // Setup data structures for computing the positions of the material points
    // and weighting factors.
    const int dim = mesh->mesh_dimension();
    FEType fe_type(FIRST, LAGRANGE);
    AutoPtr<QBase> qrule = QBase::build(QGAUSS, dim, FIRST);
    AutoPtr<FEBase> fe(FEBase::build(dim, fe_type));
    fe->attach_quadrature_rule(qrule.get());
    const std::vector<libMesh::Point>& q_point = fe->get_xyz();
    const std::vector<double>& JxW = fe->get_JxW();
    const MeshBase::const_element_iterator el_begin = mesh->active_elements_begin();
    const MeshBase::const_element_iterator el_end = mesh->active_elements_end();

    // Count the number of material points.
    d_num_vertex[level_number].push_back(0);
    d_vertex_offset[level_number].push_back(0);
    if (mesh_idx > 0)
    {
        d_vertex_offset[level_number][mesh_idx] =
            d_vertex_offset[level_number][mesh_idx - 1] + d_num_vertex[level_number][mesh_idx - 1];
    }
    for (MeshBase::const_element_iterator el_it = el_begin; el_it != el_end; ++el_it)
    {
        const Elem* const elem = *el_it;
        const double hmax = elem->hmax();
        const int npts = std::max(MIN_POINTS, std::ceil(POINT_FACTOR * hmax / dx_min));
        const Order order = static_cast<Order>(std::min(2 * npts - 1, static_cast<int>(FORTYTHIRD)));
        if (order != qrule->get_order())
        {
            qrule = QBase::build(QGAUSS, dim, order);
            fe->attach_quadrature_rule(qrule.get());
        }
        fe->reinit(elem);
        d_num_vertex[level_number][mesh_idx] += qrule->n_points();
    }

    // Initialize the material points.
    d_vertex_posn[level_number].resize(d_vertex_posn[level_number].size() + 1);
    d_vertex_wgt[level_number].resize(d_vertex_wgt[level_number].size() + 1);
    d_vertex_subdomain_id[level_number].resize(d_vertex_subdomain_id[level_number].size() + 1);
    d_vertex_posn[level_number][mesh_idx].resize(d_num_vertex[level_number][mesh_idx]);
    d_vertex_wgt[level_number][mesh_idx].resize(d_num_vertex[level_number][mesh_idx]);
    d_vertex_subdomain_id[level_number][mesh_idx].resize(d_num_vertex[level_number][mesh_idx]);
    unsigned int k = 0;
    for (MeshBase::const_element_iterator el_it = el_begin; el_it != el_end; ++el_it)
    {
        const Elem* const elem = *el_it;
        const double hmax = elem->hmax();
        const int npts = std::max(MIN_POINTS, std::ceil(POINT_FACTOR * hmax / dx_min));
        const Order order = static_cast<Order>(std::min(2 * npts - 1, static_cast<int>(FORTYTHIRD)));
        if (order != qrule->get_order())
        {
            qrule = QBase::build(QGAUSS, dim, order);
            fe->attach_quadrature_rule(qrule.get());
        }
        fe->reinit(elem);
        for (unsigned int qp = 0; qp < qrule->n_points(); ++qp, ++k)
        {
            d_vertex_posn[level_number][mesh_idx][k] = q_point[qp];
            d_vertex_wgt[level_number][mesh_idx][k] = JxW[qp];
            d_vertex_subdomain_id[level_number][mesh_idx][k] = elem->subdomain_id();
        }
    }
    return;
} // registerMesh
Exemple #20
0
void
MaterialOutputAction::act()
{
  // Do nothing if _problem is NULL (this is the case for coupled problems)
  if (_problem == NULL)
  {
    mooseWarning("FEProblem pointer is NULL, if you are executing a coupled problem this is expected. Auto material output is not supported for this case.");
    return;
  }

  // Set the pointers to the MaterialData objects (Note, these pointers are not available at construction)
  _block_material_data = _problem->getMaterialData(0);
  _boundary_material_data = _problem->getBoundaryMaterialData(0);

  // A complete list of all Material objects
  std::vector<Material *> materials = _problem->getMaterialWarehouse(0).getMaterials();

  // Loop through each material object
  for (std::vector<Material *>::iterator material_iter = materials.begin(); material_iter != materials.end(); ++material_iter)
  {
    // Extract the names of the output objects to which the material properties will be exported
    std::set<OutputName> outputs = (*material_iter)->getOutputs();

    // Extract the property names that will actually be output
    std::vector<std::string> output_properties = (*material_iter)->getParam<std::vector<std::string> >("output_properties");

    /* Clear the list of variable names for the current material object, this list will be populated with all the
    variables names for the current material object and is needed for purposes of controlling the which output objects
    show the material property data */
    _material_variable_names.clear();

    // Only continue if the the 'outputs' input parameter is not equal to 'none'
    if (outputs.find("none") == outputs.end())
    {
      // Loop over the material property names
      const std::set<std::string> names = (*material_iter)->getSuppliedItems();
      for (std::set<std::string>::const_iterator name_iter = names.begin(); name_iter != names.end(); ++name_iter)
      {
        // Add the material property for output if the name is contained in the 'output_properties' list or if the list is empty
        if (output_properties.empty() || std::find(output_properties.begin(), output_properties.end(), *name_iter) != output_properties.end())
        {
          if (hasProperty<Real>(*name_iter))
            materialOutputHelper<Real>(*name_iter, *material_iter);

          else if (hasProperty<RealVectorValue>(*name_iter))
            materialOutputHelper<RealVectorValue>(*name_iter, *material_iter);

          else if (hasProperty<RealTensorValue>(*name_iter))
            materialOutputHelper<RealTensorValue>(*name_iter, *material_iter);

          else
            mooseWarning("The type for material property '" << *name_iter << "' is not supported for automatic output.");
        }

        // Update the OutputWarehouse
        /* If 'outputs' is supplied with a list of output objects to limit the output to this information must be communicated
         * to output objects, which is done via the OutputWarehouse */
        if (!outputs.empty())
          _output_warehouse.updateMaterialOutput(outputs, _material_variable_names);
      }
    }
  }

  // Create the AuxVariables
  FEType fe_type(CONSTANT, MONOMIAL); // currently only elemental variables are support for material property output
  for (std::set<AuxVariableName>::iterator it = _variable_names.begin(); it != _variable_names.end(); ++it)
    _problem->addAuxVariable(*it, fe_type);

  // Update the complete list of material related AuxVariables to the OutputWarehouse
  _output_warehouse.setMaterialOutputVariables(_variable_names);
}
void
MaterialOutputAction::buildMaterialOutputObjects(FEProblem * problem_ptr)
{

  // Set the pointers to the MaterialData objects (Note, these pointers are not available at construction)
  _block_material_data = problem_ptr->getMaterialData(0);
  _boundary_material_data = problem_ptr->getBoundaryMaterialData(0);

  // A complete list of all Material objects
  std::vector<Material *> materials = problem_ptr->getMaterialWarehouse(0).all();

  // Handle setting of material property output in [Outputs] sub-blocks
  // Output objects can enable material property output, the following code examines the parameters
  // for each Output object and sets a flag if any Output object has output set and also builds a list if the
  // properties are limited via the 'show_material_properties' parameters
  bool outputs_has_properties = false;
  std::set<std::string> output_object_properties;

  std::vector<Action *> output_actions =  _app.actionWarehouse().getActionsByName("add_output");
  for (std::vector<Action *>::const_iterator it = output_actions.begin(); it != output_actions.end(); ++it)
  {
    // Extract the Output action
    AddOutputAction * action = dynamic_cast<AddOutputAction *>(*it);
    mooseAssert(action != NULL, "No AddOutputAction with the name " << *it << " exists");

    // Add the material property names from the output object parameters to the list of properties to output
    InputParameters & params = action->getObjectParams();
    if (params.isParamValid("output_material_properties") && params.get<bool>("output_material_properties"))
    {
      outputs_has_properties = true;
      std::vector<std::string> prop_names = params.get<std::vector<std::string> >("show_material_properties");
      output_object_properties.insert(prop_names.begin(), prop_names.end());
    }
  }

  // Loop through each material object
  for (std::vector<Material *>::iterator material_iter = materials.begin(); material_iter != materials.end(); ++material_iter)
  {
    // Extract the names of the output objects to which the material properties will be exported
    std::set<OutputName> outputs = (*material_iter)->getOutputs();

    // Extract the property names that will actually be output
    std::vector<std::string> output_properties = (*material_iter)->getParam<std::vector<std::string> >("output_properties");

    // Append the properties listed in the Outputs block
    if (outputs_has_properties)
      output_properties.insert(output_properties.end(), output_object_properties.begin(), output_object_properties.end());

    // Clear the list of variable names for the current material object, this list will be populated with all the
    // variables names for the current material object and is needed for purposes of controlling the which output objects
    // show the material property data
    _material_variable_names.clear();

    // Create necessary outputs for the properties if:
    //   (1) The Outputs block has material output enabled
    //   (2) If the Material object itself has set the 'outputs' parameter
    if (outputs_has_properties || outputs.find("none") == outputs.end())
    {
      // Add the material property for output if the name is contained in the 'output_properties' list
      // or if the list is empty (all properties)
      const std::set<std::string> names = (*material_iter)->getSuppliedItems();
      for (std::set<std::string>::const_iterator name_iter = names.begin(); name_iter != names.end(); ++name_iter)
      {
        // Add the material property for output
        if (output_properties.empty() || std::find(output_properties.begin(), output_properties.end(), *name_iter) != output_properties.end())
        {
          if (hasProperty<Real>(*name_iter))
            materialOutputHelper<Real>(*name_iter, *material_iter);

          else if (hasProperty<RealVectorValue>(*name_iter))
            materialOutputHelper<RealVectorValue>(*name_iter, *material_iter);

          else if (hasProperty<RealTensorValue>(*name_iter))
            materialOutputHelper<RealTensorValue>(*name_iter, *material_iter);

          else
            mooseWarning("The type for material property '" << *name_iter << "' is not supported for automatic output.");
        }

        // If the material object as limited outputs, store the variables associated with the output objects
        if (!outputs.empty())
          for (std::set<OutputName>::const_iterator it = outputs.begin(); it != outputs.end(); ++it)
            _material_variable_names_map[*it].insert(_material_variable_names.begin(), _material_variable_names.end());

      }
    }
  }

  // Create the AuxVariables
  FEType fe_type(CONSTANT, MONOMIAL); // currently only elemental variables are support for material property output
  for (std::set<std::string>::iterator it = _variable_names.begin(); it != _variable_names.end(); ++it)
    problem_ptr->addAuxVariable(*it, fe_type);

  // When a Material object has 'output_properties' defined all other properties not listed must be added to
  // the hide list for the output objects so that properties that are not desired do not appear.
  for (std::map<OutputName, std::set<std::string> >::const_iterator it = _material_variable_names_map.begin();
       it != _material_variable_names_map.end(); ++it)
  {
    std::set<std::string> hide;
    std::set_difference(_variable_names.begin(), _variable_names.end(),
                        it->second.begin(), it->second.end(),
                        std::inserter(hide, hide.begin()));

    _output_warehouse.addInterfaceHideVariables(it->first, hide);
  }
}
Exemple #22
0
bool InfHex::contains_point (const Point & p, Real tol) const
{
  // For infinite elements with linear base interpolation:
  // make use of the fact that infinite elements do not
  // live inside the envelope.  Use a fast scheme to
  // check whether point \p p is inside or outside
  // our relevant part of the envelope.  Note that
  // this is not exclusive: only when the distance is less,
  // we are safe.  Otherwise, we cannot say anything. The
  // envelope may be non-spherical, the physical point may lie
  // inside the envelope, outside the envelope, or even inside
  // this infinite element.  Therefore if this fails,
  // fall back to the FEInterface::inverse_map()
  const Point my_origin (this->origin());

  // determine the minimal distance of the base from the origin
  // Use norm_sq() instead of norm(), it is faster
  Point pt0_o(this->point(0) - my_origin);
  Point pt1_o(this->point(1) - my_origin);
  Point pt2_o(this->point(2) - my_origin);
  Point pt3_o(this->point(3) - my_origin);
  const Real min_distance_sq = std::min(pt0_o.norm_sq(),
                                        std::min(pt1_o.norm_sq(),
                                                 std::min(pt2_o.norm_sq(),
                                                          pt3_o.norm_sq())));

  // work with 1% allowable deviation.  We can still fall
  // back to the InfFE::inverse_map()
  const Real conservative_p_dist_sq = 1.01 * (Point(p - my_origin).norm_sq());



  if (conservative_p_dist_sq < min_distance_sq)
    {
      // the physical point is definitely not contained in the element
      return false;
    }

  // this captures the case that the point is not (almost) in the direction of the element.:
  // first, project the problem onto the unit sphere:
  Point p_o(p - my_origin);
  pt0_o /= pt0_o.norm();
  pt1_o /= pt1_o.norm();
  pt2_o /= pt2_o.norm();
  pt3_o /= pt3_o.norm();
  p_o /= p_o.norm();


  // now, check if it is in the projected face; using that the diagonal contains
  // the largest distance between points in it
  Real max_h = std::max((pt0_o - pt2_o).norm_sq(),
                        (pt1_o - pt2_o).norm_sq())*1.01;

  if ((p_o - pt0_o).norm_sq() > max_h ||
      (p_o - pt1_o).norm_sq() > max_h ||
      (p_o - pt2_o).norm_sq() > max_h ||
      (p_o - pt3_o).norm_sq() > max_h )
    {
      // the physical point is definitely not contained in the element
      return false;
    }

  // Declare a basic FEType.  Will use default in the base,
  // and something else (not important) in radial direction.
  FEType fe_type(default_order());

  const Point mapped_point = FEInterface::inverse_map(dim(),
                                                      fe_type,
                                                      this,
                                                      p,
                                                      tol,
                                                      false);

  return FEInterface::on_reference_element(mapped_point, this->type(), tol);
}
Exemple #23
0
void
Assembly::reinitNeighborAtReference(const Elem * neighbor, const std::vector<Point> & reference_points)
{
  unsigned int neighbor_dim = neighbor->dim();

  // reinit neighbor element
  for (std::map<FEType, FEBase *>::iterator it = _fe_neighbor[neighbor_dim].begin(); it != _fe_neighbor[neighbor_dim].end(); ++it)
  {
    FEBase * fe_neighbor = it->second;
    FEType fe_type = it->first;
    FEShapeData * fesd = _fe_shape_data_face_neighbor[fe_type];

    it->second->reinit(neighbor, &reference_points);

    _current_fe_neighbor[it->first] = it->second;

    fesd->_phi.shallowCopy(const_cast<std::vector<std::vector<Real> > &>(fe_neighbor->get_phi()));
    fesd->_grad_phi.shallowCopy(const_cast<std::vector<std::vector<RealGradient> > &>(fe_neighbor->get_dphi()));
    if (_need_second_derivative[fe_type])
      fesd->_second_phi.shallowCopy(const_cast<std::vector<std::vector<RealTensor> > &>(fe_neighbor->get_d2phi()));
  }

  ArbitraryQuadrature * neighbor_rule = _holder_qrule_neighbor[neighbor_dim];
  neighbor_rule->setPoints(reference_points);
  setNeighborQRule(neighbor_rule, neighbor_dim);

  _current_neighbor_elem = neighbor;

  // Calculate the volume of the neighbor

  FEType fe_type (neighbor->default_order() , LAGRANGE);
  AutoPtr<FEBase> fe (FEBase::build(neighbor->dim(), fe_type));

  const std::vector<Real> & JxW = fe->get_JxW();
  const std::vector<Point> & q_points = fe->get_xyz();

  // The default quadrature rule should integrate the mass matrix,
  // thus it should be plenty to compute the area
  QGauss qrule (neighbor->dim(), fe_type.default_quadrature_order());
  fe->attach_quadrature_rule(&qrule);
  fe->reinit(neighbor);

  // set the coord transformation
  MooseArray<Real> coord;
  coord.resize(qrule.n_points());
  switch (_coord_type) // coord type should be the same for the neighbor
  {
  case Moose::COORD_XYZ:
    for (unsigned int qp = 0; qp < qrule.n_points(); qp++)
      coord[qp] = 1.;
    break;

  case Moose::COORD_RZ:
    for (unsigned int qp = 0; qp < qrule.n_points(); qp++)
      coord[qp] = 2 * M_PI * q_points[qp](0);
    break;

  case Moose::COORD_RSPHERICAL:
    for (unsigned int qp = 0; qp < qrule.n_points(); qp++)
      coord[qp] = 4 * M_PI * q_points[qp](0) * q_points[qp](0);
    break;

  default:
    mooseError("Unknown coordinate system");
    break;
  }

  _current_neighbor_volume = 0.;
  for (unsigned int qp = 0; qp < qrule.n_points(); qp++)
    _current_neighbor_volume += JxW[qp] * coord[qp];

  coord.release();
}