www.mooseframework.org
ViewFactorBase.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 
10 #include "ViewFactorBase.h"
11 #include "libmesh/quadrature.h"
12 
13 #include <limits>
14 
16 
17 InputParameters
19 {
20  InputParameters params = SideUserObject::validParams();
21  params.addParam<Real>("view_factor_tol",
22  std::numeric_limits<Real>::max(),
23  "Tolerance for checking view factors. Default is to allow everything.");
24  params.addParam<bool>("normalize_view_factor",
25  true,
26  "Determines if view factors are normalized to sum to one (consistent with "
27  "their definition).");
28  params.addClassDescription(
29  "A base class for automatic computation of view factors between sidesets.");
30  return params;
31 }
32 
33 ViewFactorBase::ViewFactorBase(const InputParameters & parameters)
34  : SideUserObject(parameters),
35  _n_sides(boundaryIDs().size()),
36  _areas(_n_sides),
37  _view_factor_tol(getParam<Real>("view_factor_tol")),
38  _normalize_view_factor(getParam<bool>("normalize_view_factor"))
39 {
40  // sizing the view factor array
41  _view_factors.resize(_n_sides);
42  for (auto & v : _view_factors)
43  v.resize(_n_sides);
44 
45  // set up the map from the side id to the local index & side name to local index
46  std::vector<BoundaryName> boundary_names = getParam<std::vector<BoundaryName>>("boundary");
47  for (unsigned int j = 0; j < boundary_names.size(); ++j)
48  _side_name_index[boundary_names[j]] = j;
49 }
50 
51 Real
52 ViewFactorBase::getViewFactor(BoundaryID from_id, BoundaryID to_id) const
53 {
54  auto from_name = _mesh.getBoundaryName(from_id);
55  auto to_name = _mesh.getBoundaryName(to_id);
56 
57  return getViewFactor(from_name, to_name);
58 }
59 
60 Real
61 ViewFactorBase::getViewFactor(BoundaryName from_name, BoundaryName to_name) const
62 {
63  auto from = _side_name_index.find(from_name);
64  auto to = _side_name_index.find(to_name);
65  if (from == _side_name_index.end())
66  mooseError("Boundary id ",
67  _mesh.getBoundaryID(from_name),
68  " with name ",
69  from_name,
70  " not listed in boundary parameter.");
71 
72  if (to == _side_name_index.end())
73  mooseError("Boundary id ",
74  _mesh.getBoundaryID(to_name),
75  " with name ",
76  to_name,
77  " not listed in boundary parameter.");
78 
79  return _view_factors[from->second][to->second];
80 }
81 
82 void
84 {
85  // do some communication before finalizing view_factors
86  for (unsigned int i = 0; i < _n_sides; ++i)
87  gatherSum(_view_factors[i]);
88 
91 }
92 
93 void
94 ViewFactorBase::threadJoin(const UserObject & y)
95 {
96  const ViewFactorBase & pps = static_cast<const ViewFactorBase &>(y);
97  for (unsigned int i = 0; i < _n_sides; ++i)
98  {
99  for (unsigned int j = 0; j < _n_sides; ++j)
100  _view_factors[i][j] += pps._view_factors[i][j];
101  }
103 }
104 
105 void
107 {
108  for (unsigned int from = 0; from < _n_sides; ++from)
109  {
110  Real s = 0;
111  for (unsigned int to = 0; to < _n_sides; ++to)
112  s += _view_factors[from][to];
113 
114  if (std::abs(1 - s) > _view_factor_tol)
115  mooseError("View factor from boundary ", boundaryNames()[from], " add to ", s);
116 
118  for (unsigned int to = 0; to < _n_sides; ++to)
119  _view_factors[from][to] /= s;
120  }
121 }
ViewFactorBase.h
ViewFactorBase
A base class for automatic computation of view factors between sidesets.
Definition: ViewFactorBase.h:23
ViewFactorBase::_side_name_index
std::unordered_map< std::string, unsigned int > _side_name_index
boundary name to index map
Definition: ViewFactorBase.h:65
ViewFactorBase::finalize
virtual void finalize() override final
Definition: ViewFactorBase.C:83
ViewFactorBase::_normalize_view_factor
const bool _normalize_view_factor
whether to normalize view factors so vf[from][:] sums to one
Definition: ViewFactorBase.h:59
ViewFactorBase::finalizeViewFactor
virtual void finalizeViewFactor()=0
a purely virtural function called in finalize, must be overriden by derived class
ViewFactorBase::_n_sides
unsigned int _n_sides
number of boundaries of this side uo
Definition: ViewFactorBase.h:50
ViewFactorBase::_view_factors
std::vector< std::vector< Real > > _view_factors
the view factor from side i to side j
Definition: ViewFactorBase.h:62
ViewFactorBase::_view_factor_tol
const Real _view_factor_tol
view factor tolerance
Definition: ViewFactorBase.h:56
ViewFactorBase::getViewFactor
Real getViewFactor(BoundaryID from_id, BoundaryID to_id) const
public interface for obtaining view factors
Definition: ViewFactorBase.C:52
ViewFactorBase::ViewFactorBase
ViewFactorBase(const InputParameters &parameters)
Definition: ViewFactorBase.C:33
ViewFactorBase::threadJoinViewFactor
virtual void threadJoinViewFactor(const UserObject &y)=0
a purely virtural function called in finalize, must be overriden by derived class
ViewFactorBase::checkAndNormalizeViewFactor
void checkAndNormalizeViewFactor()
this function checks & normalizes view factors to sum to one, this is not always
Definition: ViewFactorBase.C:106
validParams
InputParameters validParams()
ViewFactorBase::threadJoin
virtual void threadJoin(const UserObject &y) override final
Definition: ViewFactorBase.C:94
defineLegacyParams
defineLegacyParams(ViewFactorBase)
ViewFactorBase::validParams
static InputParameters validParams()
Definition: ViewFactorBase.C:18