https://mooseframework.inl.gov
InterfaceQpUserObjectBase.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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 
14 {
16  params.addClassDescription("Base class to compute a scalar value or rate across an interface");
17  params.addParam<MooseEnum>("value_type",
19  "Type of value to compute and store");
20  params.set<ExecFlagEnum>("execute_on", true) = {EXEC_INITIAL, EXEC_TIMESTEP_END};
21  return params;
22 }
23 
25  : InterfaceValueUserObject(parameters), _value_type(getParam<MooseEnum>("value_type"))
26 
27 {
28 }
29 
30 void
32 {
33  // define the boundary map and retrieve element side and boundary_ID
34  std::vector<std::tuple<dof_id_type, unsigned short int, boundary_id_type>> elem_side_bid =
36 
37  // retrieve on which boundary this UO operates
38  std::set<BoundaryID> boundaryList = boundaryIDs();
39 
40  // initialize the map_values looping over all the element and sides
41  for (unsigned int i = 0; i < elem_side_bid.size(); i++)
42  {
43  // check if this element side is part of the boundary, if so add element side to the interface
44  // map
45  if (boundaryList.find(std::get<2>(elem_side_bid[i])) != boundaryList.end())
46  {
47  // make pair
48  std::pair<dof_id_type, unsigned int> elem_side_pair =
49  std::make_pair(std::get<0>(elem_side_bid[i]), std::get<1>(elem_side_bid[i]));
50  // initialize map elemenet
51  std::vector<Real> var_values(0, 0);
52 
53  // add entry to the value map
54  _map_values[elem_side_pair] = var_values;
55  _map_JxW[elem_side_pair] = var_values;
56  }
57  }
58 }
59 
60 void
62 {
63  // find the entry on the map
64  auto it = _map_values.find(std::make_pair(_current_elem->id(), _current_side));
65  if (it != _map_values.end())
66  {
67  // insert two vector value for each qp
68  auto & vec = _map_values[std::make_pair(_current_elem->id(), _current_side)];
69  vec.resize(_qrule->n_points());
70  auto & jxw = _map_JxW[std::make_pair(_current_elem->id(), _current_side)];
71  jxw.resize(_qrule->n_points());
72 
73  // loop over qps and do stuff
74  for (unsigned int qp = 0; qp < _qrule->n_points(); ++qp)
75  {
76  // compute average value at qp
77  vec[qp] = computeRealValue(qp);
78  jxw[qp] = _JxW[qp];
79  }
80  }
81  else
82  mooseError("InterfaceQpUserObjectBase:: cannot find the required element and side");
83 }
84 
85 Real
87  const unsigned int side,
88  const unsigned int qp) const
89 {
90  auto data = _map_values.find(std::make_pair(elem, side));
91  if (data != _map_values.end())
92  return data->second[qp];
93  else
94  mooseError("getQpValue: can't find the given qp");
95 }
96 
97 Real
99  const unsigned int side) const
100 {
101  auto data = _map_values.find(std::make_pair(elem, side));
102  if (data == _map_values.end())
103  mooseError("getSideAverageValue: can't find the given qp");
104  auto weights = _map_JxW.find(std::make_pair(elem, side));
105  if (weights == _map_JxW.end())
106  mooseError("getSideAverageValue: can't find the given qp");
107 
108  Real vol = 0;
109  Real val = 0;
110  for (unsigned int i = 0; i < data->second.size(); i++)
111  {
112  val += data->second[i] * weights->second[i];
113  vol += weights->second[i];
114  }
115  return val / vol;
116 }
A special InterfaceUserObject computing average values across an interface given the average type (se...
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:21
std::map< std::pair< dof_id_type, unsigned int >, std::vector< Real > > _map_JxW
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job...
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const unsigned int & _current_side
current side of the current element
static InputParameters validParams()
const MooseArray< Real > & _JxW
const ExecFlagType EXEC_TIMESTEP_END
Definition: Moose.C:34
static MooseEnum valueOptions()
the method defining the returning value type: value, rate or increment
virtual Real computeRealValue(const unsigned int)=0
method to overrid in child classes returnig a real value
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:2985
std::map< std::pair< dof_id_type, unsigned int >, std::vector< Real > > _map_values
these maps are used to store QP data.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
InterfaceQpUserObjectBase(const InputParameters &parameters)
virtual void execute() override
Execute method.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static InputParameters validParams()
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
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...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
Real getSideAverageValue(const dof_id_type elem, const unsigned int side) const
function returning the element side average value
const Elem *const & _current_elem
current element
Real getQpValue(const dof_id_type elem, const unsigned int side, unsigned int qp) const
method returning the quadrature point value
virtual const std::set< BoundaryID > & boundaryIDs() const
Return the boundary IDs for this object.
uint8_t dof_id_type
const ExecFlagType EXEC_INITIAL
Definition: Moose.C:28