www.mooseframework.org
InterfaceQpValueUserObject.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
11 #include "MooseMesh.h"
13 
14 template <>
17 {
19  params.addRequiredCoupledVar("var", "The variable name");
20  params.addCoupledVar("var_neighbor", "The variable name");
21  params.addClassDescription("Test Interfae User Object computing and storing average values at "
22  "each QP across an interface");
23  return params;
24 }
25 
27  : InterfaceValueUserObject(parameters),
28  _u(coupledValue("var")),
29  _u_neighbor(parameters.isParamSetByUser("var_neighbor") ? coupledNeighborValue("var_neighbor")
30  : coupledNeighborValue("var"))
31 
32 {
33 }
34 
36 
37 void
39 {
40  // define the boundary map and retrieve element side and boundary_ID
41  std::vector<std::tuple<dof_id_type, unsigned short int, boundary_id_type>> elem_side_bid =
43 
44  // retrieve on which boundary this UO operates
45  std::set<BoundaryID> boundaryList = boundaryIDs();
46 
47  // clear map values
48  _map_values.clear();
49 
50  // initialize the map_values looping over all the element and sides
51  for (unsigned int i = 0; i < elem_side_bid.size(); i++)
52  {
53  // check if this element side is part of the boundary, if so add element side to the interface
54  // map
55  if (boundaryList.find(std::get<2>(elem_side_bid[i])) != boundaryList.end())
56  {
57  // make pair
58  std::pair<dof_id_type, unsigned int> elem_side_pair =
59  std::make_pair(std::get<0>(elem_side_bid[i]), std::get<1>(elem_side_bid[i]));
60  // initialize map elemenet
61  std::vector<Real> var_values(0, 0);
62 
63  // add entry to the value map
64  _map_values[elem_side_pair] = var_values;
65  }
66  }
67 }
68 
69 void
71 {
72  // find the entry on the map
73  auto it = _map_values.find(std::make_pair(_current_elem->id(), _current_side));
74  if (it != _map_values.end())
75  {
76  // insert two vector value for each qp
77  auto & vec = _map_values[std::make_pair(_current_elem->id(), _current_side)];
78  vec.resize(_qrule->n_points());
79 
80  // loop over qps and do stuff
81  for (unsigned int qp = 0; qp < _qrule->n_points(); ++qp)
82  // compute average value at qp
83  vec[qp] = computeInterfaceValueType(_u[qp], _u_neighbor[qp]);
84  }
85  else
86  mooseError("InterfaceQpValueUserObject:: cannot find the required element and side");
87 }
88 
89 Real
90 InterfaceQpValueUserObject::getQpValue(dof_id_type elem, unsigned int side, unsigned int qp) const
91 {
92  auto data = _map_values.find(std::make_pair(elem, side));
93  if (data != _map_values.end())
94  return data->second[qp];
95  else
96  mooseError("getMeanMatProp: can't find the given qp");
97 }
A special InterfaceUserObject computing average values across an interface given the average type (se...
std::map< std::pair< dof_id_type, unsigned int >, std::vector< Real > > _map_values
this map is used to store QP data.
This userobject collect values of a variable across an interface for each QP and compute a scalar...
virtual Real computeInterfaceValueType(const Real, const Real)
InterfaceQpValueUserObject(const InputParameters &parameters)
const QBase *const & _qrule
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const Elem *const & _current_elem
current element
registerMooseObject("MooseApp", InterfaceQpValueUserObject)
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
virtual void execute()
Execute method.
Real getQpValue(dof_id_type elem, unsigned int side, unsigned int qp) const
void buildSideList(std::vector< dof_id_type > &el, std::vector< unsigned short int > &sl, std::vector< boundary_id_type > &il)
Calls BoundaryInfo::build_side_list().
Definition: MooseMesh.C:2174
InputParameters validParams< InterfaceQpValueUserObject >()
virtual void initialize()
Called before execute() is ever called so that data can be cleared.
void addCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
InputParameters validParams< InterfaceValueUserObject >()
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
const unsigned int & _current_side
current side of the current element
virtual const std::set< BoundaryID > & boundaryIDs() const
Return the boundary IDs for this object.