void
PFCRFFVariablesAction::act()
{
#ifdef DEBUG
  Moose::err << "Inside the PFCRFFVariablesAction Object\n";
  Moose::err << "VariableBase: " << _L_name_base << "\torder: " << getParam<MooseEnum>("order")
             << "\tfamily: " << getParam<MooseEnum>("family") << std::endl;
#endif

  // Loop through the number of L variables
  for (unsigned int l = 0; l < _num_L; ++l)
  {
    // Create L base name
    std::string L_name = _L_name_base + Moose::stringify(l);

    // Create real L variable
    const std::string real_name = L_name + "_real";
    _problem->addVariable(real_name,
                          FEType(Utility::string_to_enum<Order>(getParam<MooseEnum>("order")),
                                 Utility::string_to_enum<FEFamily>(getParam<MooseEnum>("family"))),
                          getParam<Real>("scaling"));

    if (l > 0)
    {
      // Create imaginary L variable IF l > 0
      std::string imag_name = L_name + "_imag";
      _problem->addVariable(
          imag_name,
          FEType(Utility::string_to_enum<Order>(getParam<MooseEnum>("order")),
                 Utility::string_to_enum<FEFamily>(getParam<MooseEnum>("family"))),
          getParam<Real>("scaling"));
    }
  }
}
Exemple #2
0
ConservedAction::ConservedAction(const InputParameters & params)
  : Action(params),
    _solve_type(getParam<MooseEnum>("solve_type").getEnum<SolveType>()),
    _var_name(name()),
    _scaling(getParam<Real>("scaling"))
{
  switch (_solve_type)
  {
    case SolveType::DIRECT:
      _fe_type = FEType(Utility::string_to_enum<Order>("THIRD"),
                        Utility::string_to_enum<FEFamily>("HERMITE"));
      if (!parameters().isParamSetByAddParam("order") &&
          !parameters().isParamSetByAddParam("family"))
        mooseWarning("Order and family autoset to third and hermite in ConservedAction");
      break;
    case SolveType::REVERSE_SPLIT:
    case SolveType::FORWARD_SPLIT:
      _fe_type = FEType(Utility::string_to_enum<Order>(getParam<MooseEnum>("order")),
                        Utility::string_to_enum<FEFamily>(getParam<MooseEnum>("family")));
      // Set name of chemical potential variable
      _chempot_name = "chem_pot_" + _var_name;
      break;
    default:
      mooseError("Incorrect solve_type in ConservedAction");
  }
}
Exemple #3
0
Assembly::Assembly(SystemBase & sys, CouplingMatrix * & cm, THREAD_ID tid) :
    _sys(sys),
    _cm(cm),
    _dof_map(_sys.dofMap()),
    _tid(tid),
    _mesh(sys.mesh()),
    _mesh_dimension(_mesh.dimension()),
    _current_qrule(NULL),
    _current_qrule_volume(NULL),
    _current_qrule_arbitrary(NULL),
    _current_qrule_face(NULL),
    _current_qface_arbitrary(NULL),
    _current_qrule_neighbor(NULL),

    _current_elem(NULL),
    _current_side(0),
    _current_side_elem(NULL),
    _current_neighbor_elem(NULL),
    _current_neighbor_side(0),
    _current_node(NULL),
    _current_neighbor_node(NULL),

    _should_use_fe_cache(false),
    _currently_fe_caching(true),

    _cached_residual_values(2), // The 2 is for TIME and NONTIME
    _cached_residual_rows(2), // The 2 is for TIME and NONTIME

    _max_cached_residuals(0),
    _max_cached_jacobians(0),
    _block_diagonal_matrix(false)
{
  // Build fe's for the helpers
  getFE(FEType(FIRST, LAGRANGE));
  getFEFace(FEType(FIRST, LAGRANGE));

  // Build an FE helper object for this type for each dimension up to the dimension of the current mesh
  for(unsigned int dim=1; dim<=_mesh_dimension; dim++)
  {
    _holder_fe_helper[dim] = &_fe[dim][FEType(FIRST, LAGRANGE)];
    (*_holder_fe_helper[dim])->get_phi();
    (*_holder_fe_helper[dim])->get_dphi();
    (*_holder_fe_helper[dim])->get_xyz();
    (*_holder_fe_helper[dim])->get_JxW();

    _holder_fe_face_helper[dim] = &_fe_face[dim][FEType(FIRST, LAGRANGE)];
    (*_holder_fe_face_helper[dim])->get_phi();
    (*_holder_fe_face_helper[dim])->get_dphi();
    (*_holder_fe_face_helper[dim])->get_xyz();
    (*_holder_fe_face_helper[dim])->get_JxW();
    (*_holder_fe_face_helper[dim])->get_normals();
  }
}
void
HHPFCRFFSplitVariablesAction::act()
{
#ifdef DEBUG
  Moose::err << "Inside the HHPFCRFFSplitVariablesAction Object\n";
  Moose::err << "VariableBase: " << _L_name_base
            << "\torder: " << getParam<MooseEnum>("order")
            << "\tfamily: " << getParam<MooseEnum>("family") << std::endl;
#endif

  // Loop through the number of L variables
  for (unsigned int l = 0; l < _num_L; ++l)
  {
    // Create L base name
    std::string L_name = _L_name_base;
    std::stringstream out;
    out << l;
    L_name.append(out.str());

    // Create real L variable
    std::string real_name = L_name;
    real_name.append("_real");


#ifdef DEBUG
    Moose::err << "Real name = " << real_name << std::endl;
#endif

    _problem->addVariable(real_name,
                          FEType(Utility::string_to_enum<Order>(getParam<MooseEnum>("order")),
                                 Utility::string_to_enum<FEFamily>(getParam<MooseEnum>("family"))),
                          getParam<Real>("scaling"));

    if (l > 0)
    {
      // Create imaginary L variable IF l > 0
      std::string imag_name = L_name;
      imag_name.append("_imag");

#ifdef DEBUG
      Moose::err << "Imaginary name = " << imag_name << std::endl;
#endif

      _problem->addVariable(imag_name,
                            FEType(Utility::string_to_enum<Order>(getParam<MooseEnum>("order")),
                                   Utility::string_to_enum<FEFamily>(getParam<MooseEnum>("family"))),
                            getParam<Real>("scaling"));
    }
  }
}
void
PolycrystalVariablesAction::act()
{
#ifdef DEBUG
  Moose::err << "Inside the PolycrystalVariablesAction Object\n";
  Moose::err << "VariableBase: " << _var_name_base
            << "\torder: " << getParam<std::string>("order")
            << "\tfamily: " << getParam<std::string>("family") << std::endl;
#endif

// Loop through the number of order parameters

  for (unsigned int crys = 0; crys<_crys_num; crys++)
  {
    //Create variable names
    std::string var_name = _var_name_base;
    std::stringstream out;
    out << crys;
    var_name.append(out.str());

    _problem->addVariable(var_name,
                          FEType(Utility::string_to_enum<Order>(getParam<std::string>("order")),
                                 Utility::string_to_enum<FEFamily>(getParam<std::string>("family"))),
                          getParam<Real>("scaling"));
  }
}
void
BubblesConcVarsAction::act()
{
  if (_current_task == "add_variable")
  {
    for (unsigned int i = 0; i < _G; ++i)
    {
      Real scale = 1.0;
      _problem->addVariable(_c[i],
                            FEType(Utility::string_to_enum<Order>(_order),
                                   Utility::string_to_enum<FEFamily>(_family)),
                            scale);
    }
  }
  else if (_current_task == "add_ic" && isParamValid("initial_condition"))
  {
    for (unsigned int i = 0; i < _G; ++i)
    {
      InputParameters poly_params = _factory.getValidParams("ConstantIC");
      poly_params.set<VariableName>("variable") = _c[i];
      if ( i == 0 )
        poly_params.set<Real>("value") = getParam<Real>("c1_initial_condition");
      else if ( i == 1 )
        poly_params.set<Real>("value") = getParam<Real>("c2_initial_condition");
      else
      {
        poly_params.set<Real>("value") = _ic / _widths[i];
      }
      _problem->addInitialCondition("ConstantIC", "Initialize_" + 1+i, poly_params);
    }
  }
}
void
ContactPenetrationVarAction::act()
{
  if (!_problem->getDisplacedProblem())
    mooseError("Contact requires updated coordinates.  Use the 'displacements = ...' line in the Mesh block.");

  _problem->addAuxVariable("penetration",
                           FEType(Utility::string_to_enum<Order>(getParam<MooseEnum>("order")),
                                  Utility::string_to_enum<FEFamily>("LAGRANGE")));
}
Exemple #8
0
void
PorousFlowActionBase::addDarcyAux(const RealVectorValue & gravity)
{
  if (_current_task == "add_aux_variable")
  {
    _problem->addAuxVariable("darcy_vel_x",
                             FEType(Utility::string_to_enum<Order>("CONSTANT"),
                                    Utility::string_to_enum<FEFamily>("MONOMIAL")));
    _problem->addAuxVariable("darcy_vel_y",
                             FEType(Utility::string_to_enum<Order>("CONSTANT"),
                                    Utility::string_to_enum<FEFamily>("MONOMIAL")));
    _problem->addAuxVariable("darcy_vel_z",
                             FEType(Utility::string_to_enum<Order>("CONSTANT"),
                                    Utility::string_to_enum<FEFamily>("MONOMIAL")));
  }

  if (_current_task == "add_aux_kernel")
  {
    std::string aux_kernel_type = "PorousFlowDarcyVelocityComponent";
    InputParameters params = _factory.getValidParams(aux_kernel_type);

    params.set<RealVectorValue>("gravity") = gravity;
    params.set<UserObjectName>("PorousFlowDictator") = _dictator_name;
    params.set<ExecFlagEnum>("execute_on") = EXEC_TIMESTEP_END;

    std::string aux_kernel_name = "PorousFlowActionBase_Darcy_x_Aux";
    params.set<MooseEnum>("component") = "x";
    params.set<AuxVariableName>("variable") = "darcy_vel_x";
    _problem->addAuxKernel(aux_kernel_type, aux_kernel_name, params);

    aux_kernel_name = "PorousFlowActionBase_Darcy_y_Aux";
    params.set<MooseEnum>("component") = "y";
    params.set<AuxVariableName>("variable") = "darcy_vel_y";
    _problem->addAuxKernel(aux_kernel_type, aux_kernel_name, params);

    aux_kernel_name = "PorousFlowActionBase_Darcy_z_Aux";
    params.set<MooseEnum>("component") = "z";
    params.set<AuxVariableName>("variable") = "darcy_vel_z";
    _problem->addAuxKernel(aux_kernel_type, aux_kernel_name, params);
  }
}
Exemple #9
0
void
NodalAreaVarAction::act()
{
  std::string short_name(_name);
  // Chop off "Contact/"
  short_name.erase(0, 8);

  _problem->addAuxVariable("nodal_area_"+ short_name,
                           FEType(Utility::string_to_enum<Order>(getParam<MooseEnum>("order")),
                                  Utility::string_to_enum<FEFamily>("LAGRANGE")));

}
void
SetupResidualDebugAction::act()
{
  if (_problem.get() == NULL)
    return;

  _problem->getNonlinearSystem().debuggingResiduals(true);

  // debug variable residuals
  for (std::vector<NonlinearVariableName>::const_iterator it = _show_var_residual.begin(); it != _show_var_residual.end(); ++it)
  {
    NonlinearVariableName var_name = *it;

    // add aux-variable
    MooseVariable & var = _problem->getVariable(0, var_name);
    const std::set<SubdomainID> & subdomains = var.activeSubdomains();

    std::stringstream aux_var_ss;
    aux_var_ss << "residual_" << var.name();
    std::string aux_var_name = aux_var_ss.str();

    if (subdomains.empty())
      _problem->addAuxVariable(aux_var_name, FEType(FIRST, LAGRANGE));
    else
      _problem->addAuxVariable(aux_var_name, FEType(FIRST, LAGRANGE), &subdomains);

    // add aux-kernel
    std::stringstream kern_ss;
    kern_ss << "residual_" << var.name() << "_kernel";
    std::string kern_name = kern_ss.str();

    InputParameters params = _factory.getValidParams("DebugResidualAux");
    params.set<AuxVariableName>("variable") = aux_var_name;
    params.set<NonlinearVariableName>("debug_variable") = var.name();
    params.set<MultiMooseEnum>("execute_on") = "linear";
    _problem->addAuxKernel("DebugResidualAux", kern_name, params);
    params.set<MultiMooseEnum>("execute_on") = "timestep_end";
    _problem->addAuxKernel("DebugResidualAux", kern_name, params);
  }
}
Exemple #11
0
void
Assembly::reinitNeighborAtPhysical(const Elem * neighbor, const std::vector<Point> & physical_points)
{
  std::vector<Point> reference_points;

  unsigned int neighbor_dim = neighbor->dim();
  FEInterface::inverse_map(neighbor_dim, FEType(), neighbor, physical_points, reference_points);

  reinitNeighborAtReference(neighbor, reference_points);

  // Save off the physical points
  _current_physical_points = physical_points;
}
void
ThermalContactAuxVarsAction::act()
{
  /*
  [./gap_value]
    order = FIRST
    family = LAGRANGE
  [../]
  [./penetration]
    order = FIRST
    family = LAGRANGE
  [../]
  */

  bool quadrature = getParam<bool>("quadrature");

  // We need to add variables only once per variable name.  However, we don't know how many unique variable
  //   names we will have.  So, we'll always add them.

  MooseEnum order = getParam<MooseEnum>("order");
  std::string family = "LAGRANGE";

  std::string penetration_var_name("penetration");

  if(quadrature)
  {
    order = "CONSTANT";
    family = "MONOMIAL";
    penetration_var_name = "qpoint_penetration";
  }

  _problem->addAuxVariable(penetration_var_name,
    FEType(Utility::string_to_enum<Order>(order),
           Utility::string_to_enum<FEFamily>(family)));
  _problem->addAuxVariable(getGapValueName(_pars),
    FEType(Utility::string_to_enum<Order>(order),
           Utility::string_to_enum<FEFamily>(family)));

}
Exemple #13
0
void
Assembly::reinitElemAndNeighbor(const Elem * elem, unsigned int side, const Elem * neighbor, unsigned int neighbor_side)
{
  _current_neighbor_side = neighbor_side;

  reinit(elem, side);

  unsigned int neighbor_dim = neighbor->dim();

  std::vector<Point> reference_points;
  FEInterface::inverse_map(neighbor_dim, FEType(), neighbor, _current_q_points_face.stdVector(), reference_points);

  reinitNeighborAtReference(neighbor, reference_points);
}
void
DisplacementGradientsAction::act()
{
  unsigned int ngrad = _displacement_gradients.size();

  if (_current_task == "add_variable")
  {
    // Loop through the gij variables
    Real scaling = getParam<Real>("scaling");
    for (unsigned int i = 0; i < ngrad; ++i)
    {
      // Create displacement gradient variables
      _problem->addVariable(_displacement_gradients[i],
                            FEType(Utility::string_to_enum<Order>("FIRST"),
                                   Utility::string_to_enum<FEFamily>("LAGRANGE")),
                            scaling);
    }
  }
  else if (_current_task == "add_material")
  {
    InputParameters params = _factory.getValidParams("StrainGradDispDerivatives");
    params.set<std::vector<VariableName> >("displacement_gradients") = _displacement_gradients;
    params.set<std::vector<SubdomainName> >("block") = std::vector<SubdomainName>(1, "0");
    _problem->addMaterial("StrainGradDispDerivatives", "strain_grad_disp_derivatives", params);
  }
  else if (_current_task == "add_kernel")
  {
    unsigned int ndisp = _displacements.size();
    if (ndisp * ndisp != ngrad)
      mooseError("Number of displacement gradient variables must be the square of the number of displacement variables.");

    // Loop through the displacements
    unsigned int i = 0;
    for (unsigned int j = 0; j < ndisp; ++j)
      for (unsigned int k = 0; k < ndisp; ++k)
      {
        InputParameters params = _factory.getValidParams("GradientComponent");
        params.set<NonlinearVariableName>("variable") = _displacement_gradients[i];
        params.set<std::vector<VariableName> >("v") = std::vector<VariableName>(1, _displacements[j]);
        params.set<unsigned int>("component") = k;
        _problem->addKernel("GradientComponent", _displacement_gradients[i] + "_grad_kernel", params);
        ++i;
      }
  }
  else
    mooseError("Internal error.");
}
Exemple #15
0
void
Assembly::reinitAtPhysical(const Elem * elem, const std::vector<Point> & physical_points)
{
  _current_elem = elem;
  _current_neighbor_elem = NULL;

  std::vector<Point> reference_points;

  FEInterface::inverse_map(elem->dim(), FEType(), elem, physical_points, reference_points);

  _currently_fe_caching = false;

  reinit(elem, reference_points);

  // Save off the physical points
  _current_physical_points = physical_points;
}
QComposite<QSubCell>::QComposite(const unsigned int d,
                                 const Order o) :
  QSubCell(d,o), // explicitly call base class constructor
  _q_subcell(d,o),
  _lagrange_fe(FEBase::build (d, FEType (FIRST, LAGRANGE)))
{
  // explicitly call the init function in 1D since the
  // other tensor-product rules require this one.
  // note that EDGE will not be used internally, however
  // if we called the function with INVALID_ELEM it would try to
  // be smart and return, thinking it had already done the work.
  if (_dim == 1)
    QSubCell::init(EDGE2);

  libmesh_assert (_lagrange_fe.get() != NULL);

  _lagrange_fe->attach_quadrature_rule (&_q_subcell);
}
Exemple #17
0
void ExodusII_IO::copy_elemental_solution(System & system,
                                          std::string system_var_name,
                                          std::string exodus_var_name,
                                          unsigned int timestep)
{
  if (!exio_helper->opened_for_reading)
    libmesh_error_msg("ERROR, ExodusII file must be opened for reading before copying an elemental solution!");

  // Map from element ID to elemental variable value.  We need to use
  // a map here rather than a vector (e.g. elem_var_values) since the
  // libmesh element numbering can contain "holes".  This is the case
  // if we are reading elemental var values from an adaptively refined
  // mesh that has not been sequentially renumbered.
  std::map<dof_id_type, Real> elem_var_value_map;
  exio_helper->read_elemental_var_values(exodus_var_name, timestep, elem_var_value_map);

  const unsigned int var_num = system.variable_number(system_var_name);
  if (system.variable_type(var_num) != FEType(CONSTANT, MONOMIAL))
    libmesh_error_msg("Error! Trying to copy elemental solution into a variable that is not of CONSTANT MONOMIAL type.");

  std::map<dof_id_type, Real>::iterator
    it = elem_var_value_map.begin(),
    end = elem_var_value_map.end();

  for (; it!=end; ++it)
    {
      const Elem * elem = MeshInput<MeshBase>::mesh().query_elem(it->first);

      if (!elem)
        libmesh_error_msg("Error! Mesh returned NULL pointer for elem " << it->first);

      if (elem->n_comp(system.number(), var_num) > 0)
        {
          dof_id_type dof_index = elem->dof_number(system.number(), var_num, 0);

          // If the dof_index is local to this processor, set the value
          if ((dof_index >= system.solution->first_local_index()) && (dof_index < system.solution->last_local_index()))
            system.solution->set (dof_index, it->second);
        }
    }

  system.solution->close();
  system.update();
}
Exemple #18
0
void
PorousFlowActionBase::addSaturationAux(unsigned phase)
{
  std::string phase_str = Moose::stringify(phase);

  if (_current_task == "add_aux_variable")
    _problem->addAuxVariable("saturation" + phase_str,
                             FEType(Utility::string_to_enum<Order>("CONSTANT"),
                                    Utility::string_to_enum<FEFamily>("MONOMIAL")));

  if (_current_task == "add_aux_kernel")
  {
    std::string aux_kernel_type = "MaterialStdVectorAux";
    InputParameters params = _factory.getValidParams(aux_kernel_type);

    std::string aux_kernel_name = "PorousFlowActionBase_SaturationAux" + phase_str;
    params.set<MaterialPropertyName>("property") = "PorousFlow_saturation_qp";
    params.set<unsigned>("index") = phase;
    params.set<AuxVariableName>("variable") = "saturation" + phase_str;
    params.set<ExecFlagEnum>("execute_on") = EXEC_TIMESTEP_END;
    _problem->addAuxKernel(aux_kernel_type, aux_kernel_name, params);
  }
}
Exemple #19
0
InfFE<Dim,T_radial,T_map>::InfFE (const FEType & fet) :
  FEBase       (Dim, fet),

  _n_total_approx_sf (0),
  _n_total_qp        (0),

  base_qrule   (libmesh_nullptr),
  radial_qrule (libmesh_nullptr),
  base_elem    (libmesh_nullptr),
  base_fe      (libmesh_nullptr),

  // initialize the current_fe_type to all the same
  // values as \p fet (since the FE families and coordinate
  // map type should @e not change), but use an invalid order
  // for the radial part (since this is the only order
  // that may change!).
  // the data structures like \p phi etc are not initialized
  // through the constructor, but throught reinit()
  current_fe_type ( FEType(fet.order,
                           fet.family,
                           INVALID_ORDER,
                           fet.radial_family,
                           fet.inf_map) )

{
  // Sanity checks
  libmesh_assert_equal_to (T_radial, fe_type.radial_family);
  libmesh_assert_equal_to (T_map, fe_type.inf_map);

  // build the base_fe object, handle the UniquePtr
  if (Dim != 1)
    {
      UniquePtr<FEBase> ap_fb(FEBase::build(Dim-1, fet));
      base_fe = ap_fb.release();
    }
}
void
ImageGrainVariableAction::act()
{
#ifdef DEBUG
  Moose::err << "Inside the ImageGrainVariableAction Object\n"
             << "VariableBase: " << _var_name_base
             << "\torder: " << getParam<std::string>("order")
             << "\tfamily: " << getParam<std::string>("family") << std::endl;
#endif

  // Loop through the number of order parameters
  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());

    _problem->addAuxVariable(var_name,
                                 FEType(Utility::string_to_enum<Order>(getParam<std::string>("order")),
                                 Utility::string_to_enum<FEFamily>(getParam<std::string>("family"))));
  }
}
Exemple #21
0
void
RichardsMaterial::computeProperties()
{
  // Grab reference to linear Lagrange finite element object pointer,
  // currently this is always a linear Lagrange element, so this might need to
  // be generalized if we start working with higher-order elements...
  FEBase * & fe(_assembly.getFE(getParam<bool>("linear_shape_fcns") ? FEType(FIRST, LAGRANGE) : FEType(SECOND, LAGRANGE), _current_elem->dim()));

  // Grab references to FE object's mapping data from the _subproblem's FE object
  const std::vector<Real>& dxidx(fe->get_dxidx());
  const std::vector<Real>& dxidy(fe->get_dxidy());
  const std::vector<Real>& dxidz(fe->get_dxidz());
  const std::vector<Real>& detadx(fe->get_detadx());
  const std::vector<Real>& detady(fe->get_detady());
  const std::vector<Real>& detadz(fe->get_detadz());
  const std::vector<Real>& dzetadx(fe->get_dzetadx());
  const std::vector<Real>& dzetady(fe->get_dzetady());
  const std::vector<Real>& dzetadz(fe->get_dzetadz());

  // this gets run for each element
  for (unsigned int qp=0; qp<_qrule->n_points(); qp++)
  {

    _porosity[qp] = _material_por + (*_por_change)[qp];
    _porosity_old[qp] = _material_por + (*_por_change_old)[qp];

    _permeability[qp] = _material_perm;
    for (unsigned int i=0; i<3; i++)
      for (unsigned int j=0; j<3; j++)
        _permeability[qp](i,j) *= std::pow(10,(*_perm_change[3*i+j])[qp]);

    _gravity[qp] = _material_gravity;

    _viscosity[qp].resize(_num_p);

    _density_old[qp].resize(_num_p);
    _density[qp].resize(_num_p);
    _ddensity[qp].resize(_num_p);
    _d2density[qp].resize(_num_p);

    _rel_perm[qp].resize(_num_p);
    _drel_perm[qp].resize(_num_p);
    _d2rel_perm[qp].resize(_num_p);

    _seff_old[qp].resize(_num_p);
    _seff[qp].resize(_num_p);
    _dseff[qp].resize(_num_p);
    _d2seff[qp].resize(_num_p);

    _sat_old[qp].resize(_num_p);
    _sat[qp].resize(_num_p);
    _dsat[qp].resize(_num_p);
    _d2sat[qp].resize(_num_p);


    for (unsigned int i=0 ; i<_num_p; ++i)
    {
      _viscosity[qp][i] = _material_viscosity[i];

      _density_old[qp][i] = (*_material_density_UO[i]).density((*_pressure_old_vals[i])[qp]);
      _density[qp][i] = (*_material_density_UO[i]).density((*_pressure_vals[i])[qp]);
      _ddensity[qp][i] = (*_material_density_UO[i]).ddensity((*_pressure_vals[i])[qp]);
      _d2density[qp][i] = (*_material_density_UO[i]).d2density((*_pressure_vals[i])[qp]);

      _seff_old[qp][i] = (*_material_seff_UO[i]).seff(_pressure_old_vals, qp);
      _seff[qp][i] = (*_material_seff_UO[i]).seff(_pressure_vals, qp);

      _dseff[qp][i].resize(_num_p);
      _dseff[qp][i] = (*_material_seff_UO[i]).dseff(_pressure_vals, qp);

      _d2seff[qp][i].resize(_num_p);
      for (unsigned int j=0 ; j<_num_p; ++j)
      {
        _d2seff[qp][i][j].resize(_num_p);
      }
      _d2seff[qp][i] = (*_material_seff_UO[i]).d2seff(_pressure_vals, qp);

      _sat_old[qp][i] = (*_material_sat_UO[i]).sat(_seff_old[qp][i]);
      _sat[qp][i] = (*_material_sat_UO[i]).sat(_seff[qp][i]);
      //Moose::out << "qp= " << qp << " i= " << i << " pressure= " << (*_pressure_vals[0])[qp] << " " << (*_pressure_vals[1])[qp] << " sat= " << _sat[qp][i] << "\n";
      _dsat[qp][i].resize(_num_p);
      for (unsigned int j=0 ; j<_num_p; ++j)
      {
        _dsat[qp][i][j] = (*_material_sat_UO[i]).dsat(_seff[qp][i])*_dseff[qp][i][j]; // could optimise
      }
      _d2sat[qp][i].resize(_num_p);
      for (unsigned int j=0 ; j<_num_p; ++j)
      {
        _d2sat[qp][i][j].resize(_num_p);
        for (unsigned int k=0 ; k<_num_p; ++k)
        {
          _d2sat[qp][i][j][k] = (*_material_sat_UO[i]).d2sat(_seff[qp][i])*_dseff[qp][i][j]*_dseff[qp][i][k] + (*_material_sat_UO[i]).dsat(_seff[qp][i])*_d2seff[qp][i][j][k];
        }
      }

      _rel_perm[qp][i] = (*_material_relperm_UO[i]).relperm(_seff[qp][i]);
      _drel_perm[qp][i] = (*_material_relperm_UO[i]).drelperm(_seff[qp][i]);
      _d2rel_perm[qp][i] =(* _material_relperm_UO[i]).d2relperm(_seff[qp][i]);

    }


    // Now SUPG stuff
    _tauvel_SUPG[qp].resize(_num_p);
    _dtauvel_SUPG_dgradp[qp].resize(_num_p);
    _dtauvel_SUPG_dp[qp].resize(_num_p);

    // Bounds checking on element data and putting into vector form
    mooseAssert(qp < dxidx.size(), "Insufficient data in dxidx array!");
    mooseAssert(qp < dxidy.size(), "Insufficient data in dxidy array!");
    mooseAssert(qp < dxidz.size(), "Insufficient data in dxidz array!");
    if (_mesh.dimension() >= 2)
    {
      mooseAssert(qp < detadx.size(), "Insufficient data in detadx array!");
      mooseAssert(qp < detady.size(), "Insufficient data in detady array!");
      mooseAssert(qp < detadz.size(), "Insufficient data in detadz array!");
    }
    if (_mesh.dimension() >= 3)
    {
      mooseAssert(qp < dzetadx.size(), "Insufficient data in dzetadx array!");
      mooseAssert(qp < dzetady.size(), "Insufficient data in dzetady array!");
      mooseAssert(qp < dzetadz.size(), "Insufficient data in dzetadz array!");
    }

    // CHECK : Does this work spherical, cylindrical, etc?
    RealVectorValue xi_prime(dxidx[qp], dxidy[qp], dxidz[qp]);
    RealVectorValue eta_prime, zeta_prime;
    if (_mesh.dimension() >= 2)
    {
      eta_prime(0) = detadx[qp];
      eta_prime(1) = detady[qp];
    }
    if (_mesh.dimension() == 3)
    {
      eta_prime(2) = detadz[qp];
      zeta_prime(0) = dzetadx[qp];
      zeta_prime(1) = dzetady[qp];
      zeta_prime(2) = dzetadz[qp];
    }

    for (unsigned int i=0 ; i<_num_p; ++i)
    {
      RealVectorValue vel = (*_material_SUPG_UO[i]).velSUPG(_permeability[qp], (*_grad_p[i])[qp], _density[qp][i], _gravity[qp]);
      RealTensorValue dvel_dgradp = (*_material_SUPG_UO[i]).dvelSUPG_dgradp(_permeability[qp]);
      RealVectorValue dvel_dp = (*_material_SUPG_UO[i]).dvelSUPG_dp(_permeability[qp], _ddensity[qp][i], _gravity[qp]);
      RealVectorValue bb = (*_material_SUPG_UO[i]).bb(vel, _mesh.dimension(), xi_prime, eta_prime, zeta_prime);
      RealVectorValue dbb2_dgradp = (*_material_SUPG_UO[i]).dbb2_dgradp(vel, dvel_dgradp, xi_prime, eta_prime, zeta_prime);
      Real dbb2_dp = (*_material_SUPG_UO[i]).dbb2_dp(vel, dvel_dp, xi_prime, eta_prime, zeta_prime);
      Real tau = (*_material_SUPG_UO[i]).tauSUPG(vel, _trace_perm, bb);
      RealVectorValue dtau_dgradp = (*_material_SUPG_UO[i]).dtauSUPG_dgradp(vel, dvel_dgradp, _trace_perm, bb, dbb2_dgradp);
      Real dtau_dp = (*_material_SUPG_UO[i]).dtauSUPG_dp(vel, dvel_dp, _trace_perm, bb, dbb2_dp);

      _tauvel_SUPG[qp][i] = tau*vel;

      _dtauvel_SUPG_dgradp[qp][i] = tau*dvel_dgradp;
      for (unsigned int j=0 ; j<3; ++j)
        for (unsigned int k=0 ; k<3; ++k)
          _dtauvel_SUPG_dgradp[qp][i](j,k) += dtau_dgradp(j)*vel(k); // this is outerproduct - maybe libmesh can do it better?

      _dtauvel_SUPG_dp[qp][i] = dtau_dp*vel + tau*dvel_dp;
    }
  }
}
Exemple #22
0
void
StressDivergenceTruss::initialSetup()
{
  _orientation = &_subproblem.assembly(_tid).getFE(FEType(), _current_elem->dim())->get_dxyzdxi();
}
Exemple #23
0
void
OversampleOutput::initOversample()
{
  // Perform the mesh cloning, if needed
  if (_change_position || _oversample)
    cloneMesh();
  else
    return;

  // Re-position the oversampled mesh
  if (_change_position)
    for (MeshBase::node_iterator nd = _mesh_ptr->getMesh().nodes_begin(); nd != _mesh_ptr->getMesh().nodes_end(); ++nd)
      *(*nd) += _position;

  // Perform the mesh refinement
  if (_oversample)
  {
    MeshRefinement mesh_refinement(_mesh_ptr->getMesh());
    mesh_refinement.uniformly_refine(_refinements);
  }

  // Create the new EquationSystems
  _es_ptr = new EquationSystems(_mesh_ptr->getMesh());

  // Reference the system from which we are copying
  EquationSystems & source_es = _problem_ptr->es();

  // Initialize the _mesh_functions vector
  unsigned int num_systems = source_es.n_systems();
  _mesh_functions.resize(num_systems);

  // Loop over the number of systems
  for (unsigned int sys_num = 0; sys_num < num_systems; sys_num++)
  {
    // Reference to the current system
    System & source_sys = source_es.get_system(sys_num);

    // Add the system to the new EquationsSystems
    ExplicitSystem & dest_sys = _es_ptr->add_system<ExplicitSystem>(source_sys.name());

    // Loop through the variables in the System
    unsigned int num_vars = source_sys.n_vars();
    if (num_vars > 0)
    {
      _mesh_functions[sys_num].resize(num_vars);
      _serialized_solution = NumericVector<Number>::build(_communicator);
      _serialized_solution->init(source_sys.n_dofs(), false, SERIAL);

      // Need to pull down a full copy of this vector on every processor so we can get values in parallel
      source_sys.solution->localize(*_serialized_solution);

      // Add the variables to the system... simultaneously creating MeshFunctions for them.
      for (unsigned int var_num = 0; var_num < num_vars; var_num++)
      {
        // Add the variable, allow for first and second lagrange
        const FEType & fe_type = source_sys.variable_type(var_num);
        FEType second(SECOND, LAGRANGE);
        if (fe_type == second)
          dest_sys.add_variable(source_sys.variable_name(var_num), second);
        else
          dest_sys.add_variable(source_sys.variable_name(var_num), FEType());
      }
    }
  }

  // Initialize the newly created EquationSystem
  _es_ptr->init();
}
void
MultiAppNearestNodeTransfer::execute()
{
  Moose::out << "Beginning NearestNodeTransfer " << _name << std::endl;

  switch(_direction)
  {
    case TO_MULTIAPP:
    {
      FEProblem & from_problem = *_multi_app->problem();
      MooseVariable & from_var = from_problem.getVariable(0, _from_var_name);

      MeshBase * from_mesh = NULL;

      if (_displaced_source_mesh && from_problem.getDisplacedProblem())
      {
        mooseError("Cannot use a NearestNode transfer from a displaced mesh to a MultiApp!");
        from_mesh = &from_problem.getDisplacedProblem()->mesh().getMesh();
      }
      else
        from_mesh = &from_problem.mesh().getMesh();

      SystemBase & from_system_base = from_var.sys();

      System & from_sys = from_system_base.system();
      unsigned int from_sys_num = from_sys.number();

      // Only works with a serialized mesh to transfer from!
      mooseAssert(from_sys.get_mesh().is_serial(), "MultiAppNearestNodeTransfer only works with SerialMesh!");

      unsigned int from_var_num = from_sys.variable_number(from_var.name());

      // EquationSystems & from_es = from_sys.get_equation_systems();

      //Create a serialized version of the solution vector
      NumericVector<Number> * serialized_solution = NumericVector<Number>::build().release();
      serialized_solution->init(from_sys.n_dofs(), false, SERIAL);

      // Need to pull down a full copy of this vector on every processor so we can get values in parallel
      from_sys.solution->localize(*serialized_solution);

      for(unsigned int i=0; i<_multi_app->numGlobalApps(); i++)
      {
        if (_multi_app->hasLocalApp(i))
        {
          MPI_Comm swapped = Moose::swapLibMeshComm(_multi_app->comm());

          // Loop over the master nodes and set the value of the variable
          System * to_sys = find_sys(_multi_app->appProblem(i)->es(), _to_var_name);

          if (!to_sys)
            mooseError("Cannot find variable "<<_to_var_name<<" for "<<_name<<" Transfer");

          unsigned int sys_num = to_sys->number();
          unsigned int var_num = to_sys->variable_number(_to_var_name);

          NumericVector<Real> & solution = _multi_app->appTransferVector(i, _to_var_name);

          MeshBase * mesh = NULL;

          if (_displaced_target_mesh && _multi_app->appProblem(i)->getDisplacedProblem())
            mesh = &_multi_app->appProblem(i)->getDisplacedProblem()->mesh().getMesh();
          else
            mesh = &_multi_app->appProblem(i)->mesh().getMesh();

          bool is_nodal = to_sys->variable_type(var_num).family == LAGRANGE;

          if (is_nodal)
          {
            MeshBase::const_node_iterator node_it = mesh->local_nodes_begin();
            MeshBase::const_node_iterator node_end = mesh->local_nodes_end();

            for(; node_it != node_end; ++node_it)
            {
              Node * node = *node_it;

              Point actual_position = *node+_multi_app->position(i);

              if (node->n_dofs(sys_num, var_num) > 0) // If this variable has dofs at this node
              {
                // The zero only works for LAGRANGE!
                dof_id_type dof = node->dof_number(sys_num, var_num, 0);

                // Swap back
                Moose::swapLibMeshComm(swapped);

                Real distance = 0; // Just to satisfy the last argument

                MeshBase::const_node_iterator from_nodes_begin = from_mesh->nodes_begin();
                MeshBase::const_node_iterator from_nodes_end   = from_mesh->nodes_end();

                Node * nearest_node = NULL;

                if (_fixed_meshes)
                {
                  if (_node_map.find(node->id()) == _node_map.end())  // Haven't cached it yet
                  {
                    nearest_node = getNearestNode(actual_position, distance, from_nodes_begin, from_nodes_end);
                    _node_map[node->id()] = nearest_node;
                    _distance_map[node->id()] = distance;
                  }
                  else
                  {
                    nearest_node = _node_map[node->id()];
                    //distance = _distance_map[node->id()];
                  }
                }
                else
                  nearest_node = getNearestNode(actual_position, distance, from_nodes_begin, from_nodes_end);

                // Assuming LAGRANGE!
                dof_id_type from_dof = nearest_node->dof_number(from_sys_num, from_var_num, 0);
                Real from_value = (*serialized_solution)(from_dof);

                // Swap again
                swapped = Moose::swapLibMeshComm(_multi_app->comm());

                solution.set(dof, from_value);
              }
            }
          }
          else // Elemental
          {
            MeshBase::const_element_iterator elem_it = mesh->local_elements_begin();
            MeshBase::const_element_iterator elem_end = mesh->local_elements_end();

            for(; elem_it != elem_end; ++elem_it)
            {
              Elem * elem = *elem_it;

              Point centroid = elem->centroid();
              Point actual_position = centroid+_multi_app->position(i);

              if (elem->n_dofs(sys_num, var_num) > 0) // If this variable has dofs at this elem
              {
                // The zero only works for LAGRANGE!
                dof_id_type dof = elem->dof_number(sys_num, var_num, 0);

                // Swap back
                Moose::swapLibMeshComm(swapped);

                Real distance = 0; // Just to satisfy the last argument

                MeshBase::const_node_iterator from_nodes_begin = from_mesh->nodes_begin();
                MeshBase::const_node_iterator from_nodes_end   = from_mesh->nodes_end();

                Node * nearest_node = NULL;

                if (_fixed_meshes)
                {
                  if (_node_map.find(elem->id()) == _node_map.end())  // Haven't cached it yet
                  {
                    nearest_node = getNearestNode(actual_position, distance, from_nodes_begin, from_nodes_end);
                    _node_map[elem->id()] = nearest_node;
                    _distance_map[elem->id()] = distance;
                  }
                  else
                  {
                    nearest_node = _node_map[elem->id()];
                    //distance = _distance_map[elem->id()];
                  }
                }
                else
                  nearest_node = getNearestNode(actual_position, distance, from_nodes_begin, from_nodes_end);

                // Assuming LAGRANGE!
                dof_id_type from_dof = nearest_node->dof_number(from_sys_num, from_var_num, 0);
                Real from_value = (*serialized_solution)(from_dof);

                // Swap again
                swapped = Moose::swapLibMeshComm(_multi_app->comm());

                solution.set(dof, from_value);
              }
            }
          }

          solution.close();
          to_sys->update();

          // Swap back
          Moose::swapLibMeshComm(swapped);
        }
      }

      delete serialized_solution;

      break;
    }
    case FROM_MULTIAPP:
    {
      FEProblem & to_problem = *_multi_app->problem();
      MooseVariable & to_var = to_problem.getVariable(0, _to_var_name);
      SystemBase & to_system_base = to_var.sys();

      System & to_sys = to_system_base.system();

      NumericVector<Real> & to_solution = *to_sys.solution;

      unsigned int to_sys_num = to_sys.number();

      // Only works with a serialized mesh to transfer to!
      mooseAssert(to_sys.get_mesh().is_serial(), "MultiAppNearestNodeTransfer only works with SerialMesh!");

      unsigned int to_var_num = to_sys.variable_number(to_var.name());

      // EquationSystems & to_es = to_sys.get_equation_systems();

      MeshBase * to_mesh = NULL;

      if (_displaced_target_mesh && to_problem.getDisplacedProblem())
        to_mesh = &to_problem.getDisplacedProblem()->mesh().getMesh();
      else
        to_mesh = &to_problem.mesh().getMesh();

      bool is_nodal = to_sys.variable_type(to_var_num) == FEType();

      dof_id_type n_nodes = to_mesh->n_nodes();
      dof_id_type n_elems = to_mesh->n_elem();

      ///// All of the following are indexed off to_node->id() or to_elem->id() /////

      // Minimum distances from each node in the "to" mesh to a node in
      std::vector<Real> min_distances;

      // The node ids in the "from" mesh that this processor has found to be the minimum distances to the "to" nodes
      std::vector<dof_id_type> min_nodes;

      // After the call to maxloc() this will tell us which processor actually has the minimum
      std::vector<unsigned int> min_procs;

      // The global multiapp ID that this processor found had the minimum distance node in it.
      std::vector<unsigned int> min_apps;


      if (is_nodal)
      {
        min_distances.resize(n_nodes, std::numeric_limits<Real>::max());
        min_nodes.resize(n_nodes);
        min_procs.resize(n_nodes);
        min_apps.resize(n_nodes);
      }
      else
      {
        min_distances.resize(n_elems, std::numeric_limits<Real>::max());
        min_nodes.resize(n_elems);
        min_procs.resize(n_elems);
        min_apps.resize(n_elems);
      }

      for(unsigned int i=0; i<_multi_app->numGlobalApps(); i++)
      {
        if (!_multi_app->hasLocalApp(i))
          continue;

        MPI_Comm swapped = Moose::swapLibMeshComm(_multi_app->comm());

        FEProblem & from_problem = *_multi_app->appProblem(i);
        MooseVariable & from_var = from_problem.getVariable(0, _from_var_name);
        SystemBase & from_system_base = from_var.sys();

        System & from_sys = from_system_base.system();

        // Only works with a serialized mesh to transfer from!
        mooseAssert(from_sys.get_mesh().is_serial(), "MultiAppNearestNodeTransfer only works with SerialMesh!");

        // unsigned int from_var_num = from_sys.variable_number(from_var.name());

        // EquationSystems & from_es = from_sys.get_equation_systems();

        MeshBase * from_mesh = NULL;

        if (_displaced_source_mesh && from_problem.getDisplacedProblem())
          from_mesh = &from_problem.getDisplacedProblem()->mesh().getMesh();
        else
          from_mesh = &from_problem.mesh().getMesh();

        MeshTools::BoundingBox app_box = MeshTools::processor_bounding_box(*from_mesh, libMesh::processor_id());
        Point app_position = _multi_app->position(i);

        Moose::swapLibMeshComm(swapped);

        if (is_nodal)
        {
          MeshBase::const_node_iterator to_node_it = to_mesh->nodes_begin();
          MeshBase::const_node_iterator to_node_end = to_mesh->nodes_end();

          for(; to_node_it != to_node_end; ++to_node_it)
          {
            Node * to_node = *to_node_it;
            unsigned int to_node_id = to_node->id();

            Real current_distance = 0;

            MPI_Comm swapped = Moose::swapLibMeshComm(_multi_app->comm());

            MeshBase::const_node_iterator from_nodes_begin = from_mesh->local_nodes_begin();
            MeshBase::const_node_iterator from_nodes_end   = from_mesh->local_nodes_end();

            Node * nearest_node = NULL;

            if (_fixed_meshes)
            {
              if (_node_map.find(to_node->id()) == _node_map.end())  // Haven't cached it yet
              {
                nearest_node = getNearestNode(*to_node-app_position, current_distance, from_nodes_begin, from_nodes_end);
                _node_map[to_node->id()] = nearest_node;
                _distance_map[to_node->id()] = current_distance;
              }
              else
              {
                nearest_node = _node_map[to_node->id()];
                current_distance = _distance_map[to_node->id()];
              }
            }
            else
              nearest_node = getNearestNode(*to_node-app_position, current_distance, from_nodes_begin, from_nodes_end);

            Moose::swapLibMeshComm(swapped);

            // TODO: Logic bug when we are using caching.  "current_distance" is set by a call to getNearestNode which is
            // skipped in that case.  We shouldn't be relying on it or stuffing it in another data structure
            if (current_distance < min_distances[to_node->id()])
            {
              min_distances[to_node_id] = current_distance;
              min_nodes[to_node_id] = nearest_node->id();
              min_apps[to_node_id] = i;
            }
          }
        }
        else // Elemental
        {
          MeshBase::const_element_iterator to_elem_it = to_mesh->elements_begin();
          MeshBase::const_element_iterator to_elem_end = to_mesh->elements_end();

          for(; to_elem_it != to_elem_end; ++to_elem_it)
          {
            Elem * to_elem = *to_elem_it;
            unsigned int to_elem_id = to_elem->id();

            Point actual_position = to_elem->centroid()-app_position;

            Real current_distance = 0;

            MPI_Comm swapped = Moose::swapLibMeshComm(_multi_app->comm());

            MeshBase::const_node_iterator from_nodes_begin = from_mesh->local_nodes_begin();
            MeshBase::const_node_iterator from_nodes_end   = from_mesh->local_nodes_end();

            Node * nearest_node = NULL;

            if (_fixed_meshes)
            {
              if (_node_map.find(to_elem->id()) == _node_map.end())  // Haven't cached it yet
              {
                nearest_node = getNearestNode(actual_position, current_distance, from_nodes_begin, from_nodes_end);
                _node_map[to_elem->id()] = nearest_node;
                _distance_map[to_elem->id()] = current_distance;
              }
              else
              {
                nearest_node = _node_map[to_elem->id()];
                current_distance = _distance_map[to_elem->id()];
              }
            }
            else
              nearest_node = getNearestNode(actual_position, current_distance, from_nodes_begin, from_nodes_end);

            Moose::swapLibMeshComm(swapped);

            // TODO: Logic bug when we are using caching.  "current_distance" is set by a call to getNearestNode which is
            // skipped in that case.  We shouldn't be relying on it or stuffing it in another data structure
            if (current_distance < min_distances[to_elem->id()])
            {
              min_distances[to_elem_id] = current_distance;
              min_nodes[to_elem_id] = nearest_node->id();
              min_apps[to_elem_id] = i;
            }
          }
        }
      }

/*
      // We're going to need serialized solution vectors for each app
      // We could try to only do it for the apps that have mins in them...
      // but it's tough because this is a collective operation... so that would have to be coordinated
      std::vector<NumericVector<Number> *> serialized_from_solutions(_multi_app->numGlobalApps());

      if (_multi_app->hasApp())
      {
        // Swap
        MPI_Comm swapped = Moose::swapLibMeshComm(_multi_app->comm());

        for(unsigned int i=0; i<_multi_app->numGlobalApps(); i++)
        {
          if (!_multi_app->hasLocalApp(i))
            continue;

          FEProblem & from_problem = *_multi_app->appProblem(i);
          MooseVariable & from_var = from_problem.getVariable(0, _from_var_name);
          SystemBase & from_system_base = from_var.sys();

          System & from_sys = from_system_base.system();

          //Create a serialized version of the solution vector
          serialized_from_solutions[i] = NumericVector<Number>::build().release();
          serialized_from_solutions[i]->init(from_sys.n_dofs(), false, SERIAL);

          // Need to pull down a full copy of this vector on every processor so we can get values in parallel
          from_sys.solution->localize(*serialized_from_solutions[i]);
        }

        // Swap back
        Moose::swapLibMeshComm(swapped);
      }
*/

      // We've found the nearest nodes for this processor.  We need to see which processor _actually_ found the nearest though
      Parallel::minloc(min_distances, min_procs);

      // Now loop through min_procs and see if _this_ processor had the actual minimum for any nodes.
      // If it did then we're going to go get the value from that nearest node and transfer its value
      processor_id_type proc_id = libMesh::processor_id();

      for(unsigned int j=0; j<min_procs.size(); j++)
      {
        if (min_procs[j] == proc_id) // This means that this processor really did find the minumum so we need to transfer the value
        {
          // The zero only works for LAGRANGE!
          dof_id_type to_dof = 0;

          if (is_nodal)
          {
            Node & to_node = to_mesh->node(j);
            to_dof = to_node.dof_number(to_sys_num, to_var_num, 0);
          }
          else
          {
            Elem & to_elem = *to_mesh->elem(j);
            to_dof = to_elem.dof_number(to_sys_num, to_var_num, 0);
          }

          // The app that has the nearest node in it
          unsigned int from_app_num = min_apps[j];

          mooseAssert(_multi_app->hasLocalApp(from_app_num), "Something went very wrong!");

          // Swap
          MPI_Comm swapped = Moose::swapLibMeshComm(_multi_app->comm());

          FEProblem & from_problem = *_multi_app->appProblem(from_app_num);
          MooseVariable & from_var = from_problem.getVariable(0, _from_var_name);
          SystemBase & from_system_base = from_var.sys();

          System & from_sys = from_system_base.system();
          unsigned int from_sys_num = from_sys.number();

          unsigned int from_var_num = from_sys.variable_number(from_var.name());

          // EquationSystems & from_es = from_sys.get_equation_systems();

          MeshBase * from_mesh = NULL;

          if (_displaced_source_mesh && from_problem.getDisplacedProblem())
            from_mesh = &from_problem.getDisplacedProblem()->mesh().getMesh();
          else
            from_mesh = &from_problem.mesh().getMesh();

          Node & from_node = from_mesh->node(min_nodes[j]);

          // Assuming LAGRANGE!
          dof_id_type from_dof = from_node.dof_number(from_sys_num, from_var_num, 0);
          Real from_value = (*from_sys.solution)(from_dof);

          // Swap back
          Moose::swapLibMeshComm(swapped);

          to_solution.set(to_dof, from_value);
        }
      }

      to_solution.close();
      to_sys.update();

      break;
    }
  }

  Moose::out << "Finished NearestNodeTransfer " << _name << std::endl;
}
void
DomainIntegralAction::act()
{
  const std::string uo_name("crackFrontDefinition");
  const std::string ak_base_name("q");
  const std::string av_base_name("q");
  const std::string pp_base_name("J");
  const unsigned int num_crack_front_nodes = calcNumCrackFrontNodes();

  if (_current_task == "add_user_object")
  {
    const std::string uo_type_name("CrackFrontDefinition");

    InputParameters params = _factory.getValidParams(uo_type_name);
    params.set<std::vector<MooseEnum> >("execute_on")[0] = "initial";
    params.set<MooseEnum>("crack_direction_method") = _direction_method_moose_enum;
    params.set<MooseEnum>("crack_end_direction_method") = _end_direction_method_moose_enum;
    if (_have_crack_direction_vector)
    {
      params.set<RealVectorValue>("crack_direction_vector") = _crack_direction_vector;
    }
    if (_have_crack_direction_vector_end_1)
    {
      params.set<RealVectorValue>("crack_direction_vector_end_1") = _crack_direction_vector_end_1;
    }
    if (_have_crack_direction_vector_end_2)
    {
      params.set<RealVectorValue>("crack_direction_vector_end_2") = _crack_direction_vector_end_2;
    }
    if (_crack_mouth_boundary_names.size() != 0)
    {
      params.set<std::vector<BoundaryName> >("crack_mouth_boundary") = _crack_mouth_boundary_names;
    }
    params.set<bool>("2d") = _treat_as_2d;
    params.set<unsigned int>("axis_2d") = _axis_2d;
    params.set<std::vector<BoundaryName> >("boundary") = _boundary_names;
    params.set<bool>("use_displaced_mesh") = _use_displaced_mesh;

    _problem->addUserObject(uo_type_name, uo_name, params);
  }
  else if (_current_task == "add_aux_variable")
  {
    for (unsigned int ring_index=0; ring_index<_radius_inner.size(); ++ring_index)
    {
      if (_treat_as_2d)
      {
        std::ostringstream av_name_stream;
        av_name_stream<<av_base_name<<"_"<<ring_index+1;
        _problem->addAuxVariable(av_name_stream.str(),
                                 FEType(Utility::string_to_enum<Order>(_order),
                                        Utility::string_to_enum<FEFamily>(_family)));
      }
      else
      {
        for (unsigned int cfn_index=0; cfn_index<num_crack_front_nodes; ++cfn_index)
        {
          std::ostringstream av_name_stream;
          av_name_stream<<av_base_name<<"_"<<cfn_index+1<<"_"<<ring_index+1;
          _problem->addAuxVariable(av_name_stream.str(),
                                   FEType(Utility::string_to_enum<Order>(_order),
                                          Utility::string_to_enum<FEFamily>(_family)));
        }
      }
    }
  }
  else if (_current_task == "add_aux_kernel")
  {
    const std::string ak_type_name("DomainIntegralQFunction");
    InputParameters params = _factory.getValidParams(ak_type_name);
    params.set<std::vector<MooseEnum> >("execute_on")[0] = "initial";
    params.set<UserObjectName>("crack_front_definition") = uo_name;
    params.set<bool>("use_displaced_mesh") = _use_displaced_mesh;

    for (unsigned int ring_index=0; ring_index<_radius_inner.size(); ++ring_index)
    {
      params.set<Real>("j_integral_radius_inner") = _radius_inner[ring_index];
      params.set<Real>("j_integral_radius_outer") = _radius_outer[ring_index];
      if (_treat_as_2d)
      {
        std::ostringstream ak_name_stream;
        ak_name_stream<<ak_base_name<<"_"<<ring_index+1;
        std::ostringstream av_name_stream;
        av_name_stream<<av_base_name<<"_"<<ring_index+1;
        params.set<AuxVariableName>("variable") = av_name_stream.str();
        _problem->addAuxKernel(ak_type_name, ak_name_stream.str(), params);
      }
      else
      {
        for (unsigned int cfn_index=0; cfn_index<num_crack_front_nodes; ++cfn_index)
        {
          std::ostringstream ak_name_stream;
          ak_name_stream<<ak_base_name<<"_"<<cfn_index+1<<"_"<<ring_index+1;
          std::ostringstream av_name_stream;
          av_name_stream<<av_base_name<<"_"<<cfn_index+1<<"_"<<ring_index+1;
          params.set<AuxVariableName>("variable") = av_name_stream.str();
          params.set<unsigned int>("crack_front_node_index") = cfn_index;
          _problem->addAuxKernel(ak_type_name, ak_name_stream.str(), params);
        }
      }
    }
  }
  else if (_current_task == "add_postprocessor")
  {
    if (_integrals.count(J_INTEGRAL) != 0)
    {
      const std::string pp_type_name("JIntegral");
      InputParameters params = _factory.getValidParams(pp_type_name);
      params.set<std::vector<MooseEnum> >("execute_on")[0] = "timestep";
      params.set<UserObjectName>("crack_front_definition") = uo_name;
      params.set<bool>("use_displaced_mesh") = _use_displaced_mesh;
      for (unsigned int ring_index=0; ring_index<_radius_inner.size(); ++ring_index)
      {
        if (_treat_as_2d)
        {
          std::ostringstream av_name_stream;
          av_name_stream<<av_base_name<<"_"<<ring_index+1;
          std::ostringstream pp_name_stream;
          pp_name_stream<<pp_base_name<<"_"<<ring_index+1;
          std::vector<VariableName> qvars;
          qvars.push_back(av_name_stream.str());
          params.set<std::vector<VariableName> >("q") = qvars;
          _problem->addPostprocessor(pp_type_name,pp_name_stream.str(),params);
        }
        else
        {
          for (unsigned int cfn_index=0; cfn_index<num_crack_front_nodes; ++cfn_index)
          {
            std::ostringstream av_name_stream;
            av_name_stream<<av_base_name<<"_"<<cfn_index+1<<"_"<<ring_index+1;
            std::ostringstream pp_name_stream;
            pp_name_stream<<pp_base_name<<"_"<<cfn_index+1<<"_"<<ring_index+1;
            std::vector<VariableName> qvars;
            qvars.push_back(av_name_stream.str());
            params.set<std::vector<VariableName> >("q") = qvars;
            params.set<unsigned int>("crack_front_node_index") = cfn_index;
            _problem->addPostprocessor(pp_type_name,pp_name_stream.str(),params);
          }
        }
      }
    }
    if (_integrals.count(INTERACTION_INTEGRAL_KI) != 0)
    {
      const std::string pp_base_name("II");
      const std::string pp_type_name("InteractionIntegral");
      InputParameters params = _factory.getValidParams(pp_type_name);
      params.set<std::vector<MooseEnum> >("execute_on")[0] = "timestep";
      params.set<UserObjectName>("crack_front_definition") = uo_name;
      params.set<bool>("use_displaced_mesh") = _use_displaced_mesh;
      params.set<Real>("poissons_ratio") = _poissons_ratio;
      params.set<Real>("youngs_modulus") = _youngs_modulus;
      params.set<std::vector<VariableName> >("disp_x") = std::vector<VariableName>(1,_disp_x);
      params.set<std::vector<VariableName> >("disp_y") = std::vector<VariableName>(1,_disp_y);
      if (_disp_z !="")
        params.set<std::vector<VariableName> >("disp_z") = std::vector<VariableName>(1,_disp_z);
      params.set<std::string>("aux_stress") = "aux_stress_I";
      params.set<std::string>("aux_disp") = "aux_disp_I";
      params.set<std::string>("aux_grad_disp") = "aux_grad_disp_I";
      params.set<std::string>("aux_strain") = "aux_strain_I";
      params.set<Real>("K_factor") = 0.5 * _youngs_modulus / (1 - std::pow(_poissons_ratio,2));
      for (unsigned int ring_index=0; ring_index<_radius_inner.size(); ++ring_index)
      {
        if (_treat_as_2d)
        {
          std::ostringstream av_name_stream;
          av_name_stream<<av_base_name<<"_"<<ring_index+1;
          std::ostringstream pp_name_stream;
          pp_name_stream<<pp_base_name<<"_"<<"KI"<<"_"<<ring_index+1;
          std::vector<VariableName> qvars;
          qvars.push_back(av_name_stream.str());
          params.set<std::vector<VariableName> >("q") = qvars;
          _problem->addPostprocessor(pp_type_name,pp_name_stream.str(),params);
        }
        else
        {
          for (unsigned int cfn_index=0; cfn_index<num_crack_front_nodes; ++cfn_index)
          {
            std::ostringstream av_name_stream;
            av_name_stream<<av_base_name<<"_"<<cfn_index+1<<"_"<<ring_index+1;
            std::ostringstream pp_name_stream;
            pp_name_stream<<pp_base_name<<"_"<<"KI"<<"_"<<cfn_index+1<<"_"<<ring_index+1;
            std::vector<VariableName> qvars;
            qvars.push_back(av_name_stream.str());
            params.set<std::vector<VariableName> >("q") = qvars;
            params.set<unsigned int>("crack_front_node_index") = cfn_index;
            _problem->addPostprocessor(pp_type_name,pp_name_stream.str(),params);
          }
        }
      }
    }
    if (_integrals.count(INTERACTION_INTEGRAL_KII) != 0)
    {
      const std::string pp_base_name("II");
      const std::string pp_type_name("InteractionIntegral");
      InputParameters params = _factory.getValidParams(pp_type_name);
      params.set<std::vector<MooseEnum> >("execute_on")[0] = "timestep";
      params.set<UserObjectName>("crack_front_definition") = uo_name;
      params.set<bool>("use_displaced_mesh") = _use_displaced_mesh;
      params.set<Real>("poissons_ratio") = _poissons_ratio;
      params.set<Real>("youngs_modulus") = _youngs_modulus;
      params.set<std::vector<VariableName> >("disp_x") = std::vector<VariableName>(1,_disp_x);
      params.set<std::vector<VariableName> >("disp_y") = std::vector<VariableName>(1,_disp_y);
      if (_disp_z !="")
        params.set<std::vector<VariableName> >("disp_z") = std::vector<VariableName>(1,_disp_z);
      params.set<std::string>("aux_stress") = "aux_stress_II";
      params.set<std::string>("aux_disp") = "aux_disp_II";
      params.set<std::string>("aux_grad_disp") = "aux_grad_disp_II";
      params.set<std::string>("aux_strain") = "aux_strain_II";
      params.set<Real>("K_factor") = 0.5 * _youngs_modulus / (1 - std::pow(_poissons_ratio,2));
      for (unsigned int ring_index=0; ring_index<_radius_inner.size(); ++ring_index)
      {
        if (_treat_as_2d)
        {
          std::ostringstream av_name_stream;
          av_name_stream<<av_base_name<<"_"<<ring_index+1;
          std::ostringstream pp_name_stream;
          pp_name_stream<<pp_base_name<<"_"<<"KII"<<"_"<<ring_index+1;
          std::vector<VariableName> qvars;
          qvars.push_back(av_name_stream.str());
          params.set<std::vector<VariableName> >("q") = qvars;
          _problem->addPostprocessor(pp_type_name,pp_name_stream.str(),params);
        }
        else
        {
          for (unsigned int cfn_index=0; cfn_index<num_crack_front_nodes; ++cfn_index)
          {
            std::ostringstream av_name_stream;
            av_name_stream<<av_base_name<<"_"<<cfn_index+1<<"_"<<ring_index+1;
            std::ostringstream pp_name_stream;
            pp_name_stream<<pp_base_name<<"_"<<"KII"<<"_"<<cfn_index+1<<"_"<<ring_index+1;
            std::vector<VariableName> qvars;
            qvars.push_back(av_name_stream.str());
            params.set<std::vector<VariableName> >("q") = qvars;
            params.set<unsigned int>("crack_front_node_index") = cfn_index;
            _problem->addPostprocessor(pp_type_name,pp_name_stream.str(),params);
          }
        }
      }
    }
    if (_integrals.count(INTERACTION_INTEGRAL_KIII) != 0)
    {
      const std::string pp_base_name("II");
      const std::string pp_type_name("InteractionIntegral");
      InputParameters params = _factory.getValidParams(pp_type_name);
      params.set<std::vector<MooseEnum> >("execute_on")[0] = "timestep";
      params.set<UserObjectName>("crack_front_definition") = uo_name;
      params.set<bool>("use_displaced_mesh") = _use_displaced_mesh;
      params.set<Real>("poissons_ratio") = _poissons_ratio;
      params.set<Real>("youngs_modulus") = _youngs_modulus;
      params.set<std::vector<VariableName> >("disp_x") = std::vector<VariableName>(1,_disp_x);
      params.set<std::vector<VariableName> >("disp_y") = std::vector<VariableName>(1,_disp_y);
      if (_disp_z !="")
        params.set<std::vector<VariableName> >("disp_z") = std::vector<VariableName>(1,_disp_z);
      params.set<std::string>("aux_stress") = "aux_stress_III";
      params.set<std::string>("aux_disp") = "aux_disp_III";
      params.set<std::string>("aux_grad_disp") = "aux_grad_disp_III";
      params.set<std::string>("aux_strain") = "aux_strain_III";
      params.set<Real>("K_factor") = 0.5 * _youngs_modulus / (2 * (1 + _poissons_ratio));
      for (unsigned int ring_index=0; ring_index<_radius_inner.size(); ++ring_index)
      {
        if (_treat_as_2d)
        {
          std::ostringstream av_name_stream;
          av_name_stream<<av_base_name<<"_"<<ring_index+1;
          std::ostringstream pp_name_stream;
          pp_name_stream<<pp_base_name<<"_"<<"KIII"<<"_"<<ring_index+1;
          std::vector<VariableName> qvars;
          qvars.push_back(av_name_stream.str());
          params.set<std::vector<VariableName> >("q") = qvars;
          _problem->addPostprocessor(pp_type_name,pp_name_stream.str(),params);
        }
        else
        {
          for (unsigned int cfn_index=0; cfn_index<num_crack_front_nodes; ++cfn_index)
          {
            std::ostringstream av_name_stream;
            av_name_stream<<av_base_name<<"_"<<cfn_index+1<<"_"<<ring_index+1;
            std::ostringstream pp_name_stream;
            pp_name_stream<<pp_base_name<<"_"<<"KIII"<<"_"<<cfn_index+1<<"_"<<ring_index+1;
            std::vector<VariableName> qvars;
            qvars.push_back(av_name_stream.str());
            params.set<std::vector<VariableName> >("q") = qvars;
            params.set<unsigned int>("crack_front_node_index") = cfn_index;
            _problem->addPostprocessor(pp_type_name,pp_name_stream.str(),params);
          }
        }
      }
    }
    for (unsigned int i=0; i<_output_variables.size(); ++i)
    {
      const std::string ov_base_name(_output_variables[i]);
      const std::string pp_type_name("CrackFrontData");
      InputParameters params = _factory.getValidParams(pp_type_name);
      params.set<std::vector<MooseEnum> >("execute_on")[0] = "timestep";
      params.set<UserObjectName>("crack_front_definition") = uo_name;
      if (_treat_as_2d)
      {
        std::ostringstream pp_name_stream;
        pp_name_stream<<ov_base_name<<"_crack";
        params.set<VariableName>("variable") = _output_variables[i];
        _problem->addPostprocessor(pp_type_name,pp_name_stream.str(),params);
      }
      else
      {
        for (unsigned int cfn_index=0; cfn_index<num_crack_front_nodes; ++cfn_index)
        {
          std::ostringstream pp_name_stream;
          pp_name_stream<<ov_base_name<<"_crack_"<<cfn_index+1;
          params.set<VariableName>("variable") = _output_variables[i];
          params.set<unsigned int>("crack_front_node_index") = cfn_index;
          _problem->addPostprocessor(pp_type_name,pp_name_stream.str(),params);
        }
      }
    }
  }
  else if (_current_task == "add_material")
  {

    int n_int_integrals(0);
    int i_ki;
    int i_kii;
    int i_kiii;

    if (_integrals.count(INTERACTION_INTEGRAL_KI)  != 0)
    {
      i_ki = n_int_integrals;
      n_int_integrals++;
    }
    if (_integrals.count(INTERACTION_INTEGRAL_KII)  != 0)
    {
      i_kii = n_int_integrals;
      n_int_integrals++;
    }
    if (_integrals.count(INTERACTION_INTEGRAL_KIII)  != 0)
    {
      i_kiii = n_int_integrals;
      n_int_integrals++;
    }

    std::vector<MooseEnum> sif_mode_enum_vec(InteractionIntegralAuxFields::getSIFModesVec(n_int_integrals));

    if (_integrals.count(INTERACTION_INTEGRAL_KI)  != 0)
      sif_mode_enum_vec[i_ki] = "KI";
    if (_integrals.count(INTERACTION_INTEGRAL_KII)  != 0)
      sif_mode_enum_vec[i_kii] = "KII";
    if (_integrals.count(INTERACTION_INTEGRAL_KIII)  != 0)
      sif_mode_enum_vec[i_kiii] = "KIII";

    if (sif_mode_enum_vec.size() > 0)
    {
      const std::string mater_name("interactionIntegralAuxFields");
      const std::string mater_type_name("InteractionIntegralAuxFields");

      InputParameters params = _factory.getValidParams(mater_type_name);
      params.set<UserObjectName>("crack_front_definition") = uo_name;
      params.set<bool>("use_displaced_mesh") = _use_displaced_mesh;
      params.set<std::vector<MooseEnum> >("sif_modes") = sif_mode_enum_vec;
      params.set<Real>("poissons_ratio") = _poissons_ratio;
      params.set<Real>("youngs_modulus") = _youngs_modulus;
      params.set<std::vector<SubdomainName> >("block") = _blocks;

      _problem->addMaterial(mater_type_name,mater_name,params);
    }
  }
}
void
MultiAppCopyTransfer::execute()
{
  _console << "Beginning CopyTransfer " << name() << std::endl;

  switch (_direction)
  {
    case TO_MULTIAPP:
    {
      FEProblem & from_problem = _multi_app->problem();
      MooseVariable & from_var = from_problem.getVariable(0, _from_var_name);

      MeshBase * from_mesh = NULL;

      from_mesh = &from_problem.mesh().getMesh();

      SystemBase & from_system_base = from_var.sys();

      System & from_sys = from_system_base.system();
      unsigned int from_sys_num = from_sys.number();

      // Only works with a serialized mesh to transfer from!
      mooseAssert(from_sys.get_mesh().is_serial(), "MultiAppCopyTransfer only works with ReplicatedMesh!");

      unsigned int from_var_num = from_sys.variable_number(from_var.name());

      //Create a serialized version of the solution vector
//      NumericVector<Number> * serialized_solution = NumericVector<Number>::build(from_sys.comm()).release();
//      serialized_solution->init(from_sys.n_dofs(), false, SERIAL);

      // Need to pull down a full copy of this vector on every processor so we can get values in parallel
//      from_sys.solution->localize(*serialized_solution);

      for (unsigned int i=0; i<_multi_app->numGlobalApps(); i++)
      {
        if (_multi_app->hasLocalApp(i))
        {
          MPI_Comm swapped = Moose::swapLibMeshComm(_multi_app->comm());

          // Loop over the master nodes and set the value of the variable
          System * to_sys = find_sys(_multi_app->appProblem(i).es(), _to_var_name);

          unsigned int sys_num = to_sys->number();
          unsigned int var_num = to_sys->variable_number(_to_var_name);

          NumericVector<Real> & solution = _multi_app->appTransferVector(i, _to_var_name);

          MeshBase * mesh = NULL;

          mesh = &_multi_app->appProblem(i).mesh().getMesh();

          bool is_nodal = to_sys->variable_type(var_num).family == LAGRANGE;

          if (is_nodal)
          {
            MeshBase::const_node_iterator node_it = mesh->local_nodes_begin();
            MeshBase::const_node_iterator node_end = mesh->local_nodes_end();

            for (; node_it != node_end; ++node_it)
            {
              Node * node = *node_it;
              unsigned int node_id = node->id();

              if (node->n_dofs(sys_num, var_num) > 0) // If this variable has dofs at this node
              {
                // The zero only works for LAGRANGE!
                dof_id_type dof = node->dof_number(sys_num, var_num, 0);

                // Swap back
                Moose::swapLibMeshComm(swapped);

                Node * from_node = from_mesh->node_ptr(node_id);

                // Assuming LAGRANGE!
                dof_id_type from_dof = from_node->dof_number(from_sys_num, from_var_num, 0);
                //Real from_value = (*serialized_solution)(from_dof);
                Real from_value = (*from_sys.solution)(from_dof);

                // Swap again
                swapped = Moose::swapLibMeshComm(_multi_app->comm());

                solution.set(dof, from_value);
              }
            }
          }
          else // Elemental
          {
            mooseError("MultiAppCopyTransfer can only be used on nodal variables");
          }

          solution.close();
          to_sys->update();

          // Swap back
          Moose::swapLibMeshComm(swapped);
        }
      }

//      delete serialized_solution;

      break;
    }
    case FROM_MULTIAPP:
    {
      FEProblem & to_problem = _multi_app->problem();
      MooseVariable & to_var = to_problem.getVariable(0, _to_var_name);
      SystemBase & to_system_base = to_var.sys();

      System & to_sys = to_system_base.system();

      NumericVector<Real> & to_solution = *to_sys.solution;

      unsigned int to_sys_num = to_sys.number();

      // Only works with a serialized mesh to transfer to!
      mooseAssert(to_sys.get_mesh().is_serial(), "MultiAppCopyTransfer only works with ReplicatedMesh!");

      unsigned int to_var_num = to_sys.variable_number(to_var.name());

      MeshBase * to_mesh = NULL;

      to_mesh = &to_problem.mesh().getMesh();

      bool is_nodal = to_sys.variable_type(to_var_num) == FEType();

      for (unsigned int i=0; i<_multi_app->numGlobalApps(); i++)
      {
        if (!_multi_app->hasLocalApp(i))
          continue;

        MPI_Comm swapped = Moose::swapLibMeshComm(_multi_app->comm());

        FEProblem & from_problem = _multi_app->appProblem(i);
        MooseVariable & from_var = from_problem.getVariable(0, _from_var_name);
        SystemBase & from_system_base = from_var.sys();

        System & from_sys = from_system_base.system();

        unsigned int from_sys_num = from_sys.number();

        unsigned int from_var_num = from_sys.variable_number(from_var.name());

        // Only works with a serialized mesh to transfer from!
        mooseAssert(from_sys.get_mesh().is_serial(), "MultiAppCopyTransfer only works with ReplicatedMesh!");

        //Create a serialized version of the solution vector
//        NumericVector<Number> * serialized_solution = NumericVector<Number>::build(from_sys.comm()).release();
//        serialized_solution->init(from_sys.n_dofs(), false, SERIAL);

        // Need to pull down a full copy of this vector on every processor so we can get values in parallel
//        from_sys.solution->localize(*serialized_solution);


        MeshBase * from_mesh = &from_problem.mesh().getMesh();

        Moose::swapLibMeshComm(swapped);

        if (is_nodal)
        {
          MeshBase::const_node_iterator to_node_it = to_mesh->local_nodes_begin();
          MeshBase::const_node_iterator to_node_end = to_mesh->local_nodes_end();

          for (; to_node_it != to_node_end; ++to_node_it)
          {
            Node * to_node = *to_node_it;
            unsigned int to_node_id = to_node->id();

            // The zero only works for LAGRANGE!
            dof_id_type to_dof = to_node->dof_number(to_sys_num, to_var_num, 0);

            MPI_Comm swapped = Moose::swapLibMeshComm(_multi_app->comm());

            Node * from_node = from_mesh->node_ptr(to_node_id);

            // Assuming LAGRANGE!
            dof_id_type from_dof = from_node->dof_number(from_sys_num, from_var_num, 0);
            //Real from_value = (*serialized_solution)(from_dof);
            Real from_value = (*from_sys.solution)(from_dof);

            // Swap back
            Moose::swapLibMeshComm(swapped);

            to_solution.set(to_dof, from_value);
          }
        }
        else // Elemental
        {
          mooseError("MultiAppCopyTransfer can only be used on nodal variables");
        }

//        delete serialized_solution;
      }

      to_solution.close();
      to_sys.update();

      break;
    }
  }

  _console << "Finished CopyTransfer " << name() << std::endl;
}
void NavierStokesMaterial::compute_h_supg(unsigned qp)
{
  // Grab reference to linear Lagrange finite element object pointer,
  // currently this is always a linear Lagrange element, so this might need to
  // be generalized if we start working with higher-order elements...
  FEBase*& fe(_assembly.getFE(FEType(), _current_elem->dim()));

  // Grab references to FE object's mapping data from the _subproblem's FE object
  const std::vector<Real>& dxidx(fe->get_dxidx());
  const std::vector<Real>& dxidy(fe->get_dxidy());
  const std::vector<Real>& dxidz(fe->get_dxidz());
  const std::vector<Real>& detadx(fe->get_detadx());
  const std::vector<Real>& detady(fe->get_detady());
  const std::vector<Real>& detadz(fe->get_detadz());
  const std::vector<Real>& dzetadx(fe->get_dzetadx()); // Empty in 2D
  const std::vector<Real>& dzetady(fe->get_dzetady()); // Empty in 2D
  const std::vector<Real>& dzetadz(fe->get_dzetadz()); // Empty in 2D

  // Bounds checking on element data
  mooseAssert(qp < dxidx.size(), "Insufficient data in dxidx array!");
  mooseAssert(qp < dxidy.size(), "Insufficient data in dxidy array!");
  mooseAssert(qp < dxidz.size(), "Insufficient data in dxidz array!");

  mooseAssert(qp < detadx.size(), "Insufficient data in detadx array!");
  mooseAssert(qp < detady.size(), "Insufficient data in detady array!");
  mooseAssert(qp < detadz.size(), "Insufficient data in detadz array!");

  if (_mesh_dimension == 3)
  {
    mooseAssert(qp < dzetadx.size(), "Insufficient data in dzetadx array!");
    mooseAssert(qp < dzetady.size(), "Insufficient data in dzetady array!");
    mooseAssert(qp < dzetadz.size(), "Insufficient data in dzetadz array!");
  }

  // The velocity vector at this quadrature point.
  RealVectorValue U(_u_vel[qp],_v_vel[qp],_w_vel[qp]);

  // Pull out element inverse map values at the current qp into a little dense matrix
  Real dxi_dx[3][3] = {{0.,0.,0.}, {0.,0.,0.}, {0.,0.,0.}};

  dxi_dx[0][0] = dxidx[qp];  dxi_dx[0][1] = dxidy[qp];
  dxi_dx[1][0] = detadx[qp]; dxi_dx[1][1] = detady[qp];

  // OK to access third entries on 2D elements if LIBMESH_DIM==3, though they
  // may be zero...
  if (LIBMESH_DIM == 3)
  {
    /**/             /**/               dxi_dx[0][2] = dxidz[qp];
    /**/             /**/               dxi_dx[1][2] = detadz[qp];
  }

  // The last row of entries available only for 3D elements.
  if (_mesh_dimension == 3)
  {
    dxi_dx[2][0] = dzetadx[qp];   dxi_dx[2][1] = dzetady[qp];   dxi_dx[2][2] = dzetadz[qp];
  }

  // Construct the g_ij = d(xi_k)/d(x_j) * d(xi_k)/d(x_i) matrix
  // from Ben and Bova's paper by summing over k...
  Real g[3][3] = {{0.,0.,0.}, {0.,0.,0.}, {0.,0.,0.}};
  for (unsigned i=0; i<3; ++i)
    for (unsigned j=0; j<3; ++j)
      for (unsigned k=0; k<3; ++k)
        g[i][j] += dxi_dx[k][j] * dxi_dx[k][i];

  // Compute the denominator of the h_supg term: U * (g) * U
  Real denom = 0.;
  for (unsigned i=0; i<3; ++i)
    for (unsigned j=0; j<3; ++j)
      denom += U(j) * g[i][j] * U(i);

  // Compute h_supg.  Some notes:
  // .) The 2 coefficient in this term should be a 1 if we are using tets/triangles.
  // .) The denominator will be identically zero only if the velocity
  //    is identically zero, in which case we can't divide by it.
  if (denom != 0.0)
    _hsupg[qp] = 2.* sqrt( U.size_sq() / denom );
  else
    _hsupg[qp] = 0.;

  // Debugging: Just use hmin for the element!
  _hsupg[qp] = _current_elem->hmin();
}
Exemple #28
0
void
PorousFlowActionBase::addStressAux()
{
  if (_current_task == "add_aux_variable")
  {
    _problem->addAuxVariable("stress_xx",
                             FEType(Utility::string_to_enum<Order>("CONSTANT"),
                                    Utility::string_to_enum<FEFamily>("MONOMIAL")));
    _problem->addAuxVariable("stress_xy",
                             FEType(Utility::string_to_enum<Order>("CONSTANT"),
                                    Utility::string_to_enum<FEFamily>("MONOMIAL")));
    _problem->addAuxVariable("stress_xz",
                             FEType(Utility::string_to_enum<Order>("CONSTANT"),
                                    Utility::string_to_enum<FEFamily>("MONOMIAL")));
    _problem->addAuxVariable("stress_yx",
                             FEType(Utility::string_to_enum<Order>("CONSTANT"),
                                    Utility::string_to_enum<FEFamily>("MONOMIAL")));
    _problem->addAuxVariable("stress_yy",
                             FEType(Utility::string_to_enum<Order>("CONSTANT"),
                                    Utility::string_to_enum<FEFamily>("MONOMIAL")));
    _problem->addAuxVariable("stress_yz",
                             FEType(Utility::string_to_enum<Order>("CONSTANT"),
                                    Utility::string_to_enum<FEFamily>("MONOMIAL")));
    _problem->addAuxVariable("stress_zx",
                             FEType(Utility::string_to_enum<Order>("CONSTANT"),
                                    Utility::string_to_enum<FEFamily>("MONOMIAL")));
    _problem->addAuxVariable("stress_zy",
                             FEType(Utility::string_to_enum<Order>("CONSTANT"),
                                    Utility::string_to_enum<FEFamily>("MONOMIAL")));
    _problem->addAuxVariable("stress_zz",
                             FEType(Utility::string_to_enum<Order>("CONSTANT"),
                                    Utility::string_to_enum<FEFamily>("MONOMIAL")));
  }

  if (_current_task == "add_aux_kernel")
  {
    std::string aux_kernel_type = "RankTwoAux";
    InputParameters params = _factory.getValidParams(aux_kernel_type);

    params.set<MaterialPropertyName>("rank_two_tensor") = "stress";
    params.set<ExecFlagEnum>("execute_on") = EXEC_TIMESTEP_END;

    std::string aux_kernel_name = "PorousFlowAction_stress_xx";
    params.set<AuxVariableName>("variable") = "stress_xx";
    params.set<unsigned>("index_i") = 0;
    params.set<unsigned>("index_j") = 0;
    _problem->addAuxKernel(aux_kernel_type, aux_kernel_name, params);

    aux_kernel_name = "PorousFlowAction_stress_xy";
    params.set<AuxVariableName>("variable") = "stress_xy";
    params.set<unsigned>("index_i") = 0;
    params.set<unsigned>("index_j") = 1;
    _problem->addAuxKernel(aux_kernel_type, aux_kernel_name, params);

    aux_kernel_name = "PorousFlowAction_stress_xz";
    params.set<AuxVariableName>("variable") = "stress_xz";
    params.set<unsigned>("index_i") = 0;
    params.set<unsigned>("index_j") = 2;
    _problem->addAuxKernel(aux_kernel_type, aux_kernel_name, params);

    aux_kernel_name = "PorousFlowAction_stress_yx";
    params.set<AuxVariableName>("variable") = "stress_yx";
    params.set<unsigned>("index_i") = 1;
    params.set<unsigned>("index_j") = 0;
    _problem->addAuxKernel(aux_kernel_type, aux_kernel_name, params);

    aux_kernel_name = "PorousFlowAction_stress_yy";
    params.set<AuxVariableName>("variable") = "stress_yy";
    params.set<unsigned>("index_i") = 1;
    params.set<unsigned>("index_j") = 1;
    _problem->addAuxKernel(aux_kernel_type, aux_kernel_name, params);

    aux_kernel_name = "PorousFlowAction_stress_yz";
    params.set<AuxVariableName>("variable") = "stress_yz";
    params.set<unsigned>("index_i") = 1;
    params.set<unsigned>("index_j") = 2;
    _problem->addAuxKernel(aux_kernel_type, aux_kernel_name, params);

    aux_kernel_name = "PorousFlowAction_stress_zx";
    params.set<AuxVariableName>("variable") = "stress_zx";
    params.set<unsigned>("index_i") = 2;
    params.set<unsigned>("index_j") = 0;
    _problem->addAuxKernel(aux_kernel_type, aux_kernel_name, params);

    aux_kernel_name = "PorousFlowAction_stress_zy";
    params.set<AuxVariableName>("variable") = "stress_zy";
    params.set<unsigned>("index_i") = 2;
    params.set<unsigned>("index_j") = 1;
    _problem->addAuxKernel(aux_kernel_type, aux_kernel_name, params);

    aux_kernel_name = "PorousFlowAction_stress_zz";
    params.set<AuxVariableName>("variable") = "stress_zz";
    params.set<unsigned>("index_i") = 2;
    params.set<unsigned>("index_j") = 2;
    _problem->addAuxKernel(aux_kernel_type, aux_kernel_name, params);
  }
}
void
CHPFCRFFSplitVariablesAction::act()
{
  MultiMooseEnum execute_options(SetupInterface::getExecuteOptions());
  execute_options = "timestep_begin";

  // Setup MultiApp
  InputParameters poly_params = _factory.getValidParams("TransientMultiApp");
  poly_params.set<MooseEnum>("app_type") = "PhaseFieldApp";
  poly_params.set<MultiMooseEnum>("execute_on") = execute_options;
  poly_params.set<std::vector<std::string> >("input_files") = _sub_filenames;
  poly_params.set<unsigned int>("max_procs_per_app") = 1;

  Point one(0.0, 0.0, 0.0);

  std::vector<Point > positions;
  positions.push_back(one);

  poly_params.set<std::vector<Point> >("positions") = positions;

  _problem->addMultiApp("TransientMultiApp", "HHEquationSolver", poly_params);

  poly_params = _factory.getValidParams("MultiAppNearestNodeTransfer");
  poly_params.set<MooseEnum>("direction") = "to_multiapp";
  poly_params.set<MultiMooseEnum>("execute_on") = execute_options;
  poly_params.set<AuxVariableName>("variable") = _n_name;
  poly_params.set<VariableName>("source_variable") = _n_name;
  poly_params.set<MultiAppName>("multi_app") = "HHEquationSolver";


  // Create Name for Transfer
  std::string trans_name = _n_name;
  trans_name.append("_trans");

  _problem->addTransfer("MultiAppNearestNodeTransfer", trans_name, poly_params);

#ifdef DEBUG
  Moose::err << "Inside the CHPFCRFFSplitVariablesAction Object\n";
  Moose::err << "VariableBase: " << _L_name_base
            << "\torder: " << getParam<MooseEnum>("order")
            << "\tfamily: " << getParam<MooseEnum>("family") << std::endl;
#endif

  // Loop through the number of L variables
  for (unsigned int l = 0; l < _num_L; ++l)
  {
    // Create L base name
    std::string L_name = _L_name_base;
    std::stringstream out;
    out << l;
    L_name.append(out.str());

    // Create real L variable
    std::string real_name = L_name;
    real_name.append("_real");


#ifdef DEBUG
    Moose::err << "Real name = " << real_name << std::endl;
#endif

    _problem->addAuxVariable(real_name,
                             FEType(Utility::string_to_enum<Order>(getParam<MooseEnum>("order")),
                                    Utility::string_to_enum<FEFamily>(getParam<MooseEnum>("family"))));

    poly_params = _factory.getValidParams("MultiAppNearestNodeTransfer");
    poly_params.set<MooseEnum>("direction") = "from_multiapp";
    poly_params.set<AuxVariableName>("variable") = real_name;
    poly_params.set<VariableName>("source_variable") = real_name;
    poly_params.set<MultiAppName>("multi_app") = "HHEquationSolver";


    // Create Name for Transfer
    std::string trans_name = real_name;
    trans_name.append("_trans");

    _problem->addTransfer("MultiAppNearestNodeTransfer", trans_name, poly_params);

    if (l > 0)
    {
      // Create imaginary L variable IF l > 0
      std::string imag_name = L_name;
      imag_name.append("_imag");

#ifdef DEBUG
      Moose::err << "Imaginary name = " << imag_name << std::endl;
#endif

      _problem->addAuxVariable(imag_name,
                               FEType(Utility::string_to_enum<Order>(getParam<MooseEnum>("order")),
                                      Utility::string_to_enum<FEFamily>(getParam<MooseEnum>("family"))));

      poly_params = _factory.getValidParams("MultiAppNearestNodeTransfer");
      poly_params.set<MooseEnum>("direction") = "from_multiapp";
      poly_params.set<AuxVariableName>("variable") = imag_name;
      poly_params.set<VariableName>("source_variable") = imag_name;
      poly_params.set<MultiAppName>("multi_app") = "HHEquationSolver";

      // Create Name for Transfer
      std::string trans_name = imag_name;
      trans_name.append("_trans");

      _problem->addTransfer("MultiAppNearestNodeTransfer", trans_name, poly_params);
    }

  }

}
Exemple #30
0
int main(int argc, char** argv)
{
    LibMeshInit init(argc, argv);

    GetPot cl(argc, argv);

    int dim = -1;
    if (!cl.search("--dim"))
    {
        std::cerr << "No --dim argument found!" << std::endl;
        usage_error(argv[0]);
    }
    dim = cl.next(dim);

    Mesh mesh(dim);

    if(!cl.search("--input"))
    {
        std::cerr << "No --input argument found!" << std::endl;
        usage_error(argv[0]);
    }
    const char* meshname = cl.next("mesh.xda");

    mesh.read(meshname);
    std::cout << "Loaded mesh " << meshname << std::endl;

    if(!cl.search("--newbcid"))
    {
        std::cerr << "No --bcid argument found!" << std::endl;
        usage_error(argv[0]);
    }
    boundary_id_type bcid = 0;
    bcid = cl.next(bcid);

    Point minnormal(-std::numeric_limits<Real>::max(),
                    -std::numeric_limits<Real>::max(),
                    -std::numeric_limits<Real>::max());
    Point maxnormal(std::numeric_limits<Real>::max(),
                    std::numeric_limits<Real>::max(),
                    std::numeric_limits<Real>::max());
    Point minpoint(-std::numeric_limits<Real>::max(),
                   -std::numeric_limits<Real>::max(),
                   -std::numeric_limits<Real>::max());
    Point maxpoint(std::numeric_limits<Real>::max(),
                   std::numeric_limits<Real>::max(),
                   std::numeric_limits<Real>::max());

    if (cl.search("--minnormalx"))
        minnormal(0) = cl.next(minnormal(0));
    if (cl.search("--minnormalx"))
        minnormal(0) = cl.next(minnormal(0));
    if (cl.search("--maxnormalx"))
        maxnormal(0) = cl.next(maxnormal(0));
    if (cl.search("--minnormaly"))
        minnormal(1) = cl.next(minnormal(1));
    if (cl.search("--maxnormaly"))
        maxnormal(1) = cl.next(maxnormal(1));
    if (cl.search("--minnormalz"))
        minnormal(2) = cl.next(minnormal(2));
    if (cl.search("--maxnormalz"))
        maxnormal(2) = cl.next(maxnormal(2));

    if (cl.search("--minpointx"))
        minpoint(0) = cl.next(minpoint(0));
    if (cl.search("--maxpointx"))
        maxpoint(0) = cl.next(maxpoint(0));
    if (cl.search("--minpointy"))
        minpoint(1) = cl.next(minpoint(1));
    if (cl.search("--maxpointy"))
        maxpoint(1) = cl.next(maxpoint(1));
    if (cl.search("--minpointz"))
        minpoint(2) = cl.next(minpoint(2));
    if (cl.search("--maxpointz"))
        maxpoint(2) = cl.next(maxpoint(2));

    std::cout << "min point = " << minpoint << std::endl;
    std::cout << "max point = " << maxpoint << std::endl;
    std::cout << "min normal = " << minnormal << std::endl;
    std::cout << "max normal = " << maxnormal << std::endl;

    bool matcholdbcid = false;
    boundary_id_type oldbcid = 0;
    if (cl.search("--oldbcid"))
    {
        matcholdbcid = true;
        oldbcid = cl.next(oldbcid);
        if (oldbcid < 0)
            oldbcid = BoundaryInfo::invalid_id;
    }

    AutoPtr<FEBase> fe = FEBase::build(dim, FEType(FIRST,LAGRANGE));
    QGauss qface(dim-1, CONSTANT);
    fe->attach_quadrature_rule(&qface);
    const std::vector<Point> &face_points = fe->get_xyz();
    const std::vector<Point> &face_normals = fe->get_normals();

    MeshBase::element_iterator           el = mesh.elements_begin();
    const MeshBase::element_iterator end_el = mesh.elements_end();
    for (; el != end_el; ++el)
    {
        Elem *elem = *el;
        unsigned int n_sides = elem->n_sides();
        for (unsigned int s=0; s != n_sides; ++s)
        {
            if (elem->neighbor(s))
                continue;

            fe->reinit(elem,s);
            const Point &p = face_points[0];
            const Point &n = face_normals[0];

//std::cout << "elem = " << elem->id() << std::endl;
//std::cout << "centroid = " << elem->centroid() << std::endl;
//std::cout << "p = " << p << std::endl;
//std::cout << "n = " << n << std::endl;

            if (p(0) > minpoint(0) && p(0) < maxpoint(0) &&
                    p(1) > minpoint(1) && p(1) < maxpoint(1) &&
                    p(2) > minpoint(2) && p(2) < maxpoint(2) &&
                    n(0) > minnormal(0) && n(0) < maxnormal(0) &&
                    n(1) > minnormal(1) && n(1) < maxnormal(1) &&
                    n(2) > minnormal(2) && n(2) < maxnormal(2))
            {
                if (matcholdbcid &&
                        mesh.boundary_info->boundary_id(elem, s) != oldbcid)
                    continue;
                mesh.boundary_info->remove_side(elem, s);
                mesh.boundary_info->add_side(elem, s, bcid);
//std::cout << "Set element " << elem->id() << " side " << s <<
//             " to boundary " << bcid << std::endl;
            }
        }
    }

    std::string outputname;
    if(cl.search("--output"))
    {
        outputname = cl.next("mesh.xda");
    }
    else
    {
        outputname = "new.";
        outputname += meshname;
    }


    mesh.write(outputname.c_str());
    std::cout << "Wrote mesh " << outputname << std::endl;

    return 0;
}