https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ADFlowJunctionUserObject.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#include "MooseMesh.h"
12
15{
17
18 params.addRequiredParam<std::vector<Real>>(
19 "normals", "Flow channel outward normals or junction inward normals");
20 params.addParam<std::vector<processor_id_type>>(
21 "processor_ids", {}, "Processor IDs owning each connected flow channel element");
22
23 params.addClassDescription("Provides common interfaces for flow junction user objects");
24
25 return params;
26}
27
29 : SideUserObject(parameters),
30
31 _bnd_ids_vector(_mesh.getBoundaryIDs(boundaryNames(), false)),
32 _n_bnd_ids(_bnd_ids_vector.size()),
33 _normal(getParam<std::vector<Real>>("normals")),
34 _dir(getMaterialProperty<RealVectorValue>("direction")),
35 _n_connections(_normal.size()),
36 _processor_ids(getParam<std::vector<processor_id_type>>("processor_ids"))
37{
38 if (comm().size() > 1)
39 {
40 if (_processor_ids.size() != _n_connections)
41 mooseError("The number of entries in the 'processor_ids' parameter must equal the number of "
42 "connections (",
44 ").");
45 }
46 else
48}
49
50void
54
55unsigned int
57{
58 auto elem_side = std::make_pair(_current_elem, _current_side);
59 auto it = _elem_side_to_bnd_id_index.find(elem_side);
60 if (it == _elem_side_to_bnd_id_index.end())
61 {
62 // Get the boundary IDs associated with this (elem,side). In general, there
63 // may be more than one boundary ID associated with an (elem,side), but
64 // there should be exactly one of these boundary IDs that is seen by this
65 // user object.
66 const std::vector<BoundaryID> elem_side_bnd_ids =
68
69 // Loop over the boundary IDs for this (elem,side) pair and over the
70 // boundary IDs for this side user object; there should be exactly one match.
71 bool found_matching_boundary_id = false;
72 unsigned int boundary_id_index = 0;
73 for (unsigned int i = 0; i < elem_side_bnd_ids.size(); i++)
74 for (unsigned int j = 0; j < _n_bnd_ids; j++)
75 if (elem_side_bnd_ids[i] == _bnd_ids_vector[j])
76 {
77 if (found_matching_boundary_id)
78 mooseError(name(), ": Multiple matches for boundary ID were found");
79 else
80 {
81 found_matching_boundary_id = true;
82 boundary_id_index = j;
83 }
84 }
85
86 if (!found_matching_boundary_id)
87 {
88 std::stringstream ss;
89 ss << name() << ": No matching boundary ID was found for (elem,side) = ("
90 << _current_elem->id() << "," << _current_side << ").";
91 mooseError(ss.str());
92 }
93
94 // Check that this boundary ID index was not already found by an earlier (elem,side)
95 for (auto it_other = _elem_side_to_bnd_id_index.begin();
96 it_other != _elem_side_to_bnd_id_index.end();
97 it_other++)
98 {
99 if (it_other->second == boundary_id_index)
100 mooseError(name(), ": Multiple (elem,side) pairs had the same boundary ID index");
101 }
102
103 // Store boundary index for future use
104 _elem_side_to_bnd_id_index[elem_side] = boundary_id_index;
105
106 return boundary_id_index;
107 }
108 else
109 {
110 // get the boundary ID that is already stored in the map
111 return _elem_side_to_bnd_id_index[elem_side];
112 }
113}
114
115void
116ADFlowJunctionUserObject::checkValidConnectionIndex(const unsigned int & connection_index) const
117{
118 if (connection_index >= _n_connections)
120 ": The connection index '",
121 connection_index,
122 "' is invalid; the range of valid indices is (0, ",
123 _n_connections - 1,
124 ").");
125}
unsigned int getBoundaryIDIndex()
Gets the index of the currently executing boundary within the vector of boundary IDs given to this Si...
static InputParameters validParams()
const std::vector< BoundaryID > _bnd_ids_vector
Vector of boundary IDs for this side user object; note that BoundaryRestrictable stores these same bo...
std::vector< unsigned int > _processor_ids
Owners of each side of the junction.
const unsigned int _n_connections
Number of connected flow channels.
std::map< std::pair< const Elem *, const unsigned short int >, unsigned int > _elem_side_to_bnd_id_index
virtual void finalize() override
void checkValidConnectionIndex(const unsigned int &connection_index) const
Checks that a connection index is valid.
ADFlowJunctionUserObject(const InputParameters &parameters)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
const std::string & name() const
void mooseError(Args &&... args) const
std::vector< BoundaryID > getBoundaryIDs(const Elem *const elem, const unsigned short int side) const
const unsigned int & _current_side
static InputParameters validParams()
MooseMesh & _mesh
const Elem *const & _current_elem
const Parallel::Communicator & comm() const