www.mooseframework.org
UnobstructedPlanarViewFactor.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 "Assembly.h"
12 #include "MathUtils.h"
13 
14 #include "libmesh/quadrature.h"
15 #include "libmesh/fe_base.h"
16 #include "libmesh/mesh_generation.h"
17 #include "libmesh/mesh.h"
18 #include "libmesh/string_to_enum.h"
19 #include "libmesh/quadrature_gauss.h"
20 #include "libmesh/point_locator_base.h"
21 #include "libmesh/elem.h"
22 
24 
26 
27 InputParameters
29 {
30  InputParameters params = ViewFactorBase::validParams();
31  params.addClassDescription(
32  "Computes the view factors for planar faces in unubstructed radiative heat transfer.");
33  return params;
34 }
35 
37  : ViewFactorBase(parameters),
38  _boundary_info(nullptr),
39  _current_remote_side(nullptr),
40  _current_remote_fe(nullptr),
41  _current_remote_JxW(nullptr),
42  _current_remote_xyz(nullptr),
43  _current_remote_normals(nullptr)
44 {
45  _mesh.errorIfDistributedMesh("UnobstructedPlanarViewFactor");
46 
47  if (_mesh.dimension() == 1)
48  mooseError("View factor calculations for 1D geometry makes no sense");
49  else if (_mesh.dimension() == 2)
50  {
51  _exponent = 1;
52  _divisor = 2;
53  }
54  else
55  {
56  _exponent = 2;
57  _divisor = libMesh::pi;
58  }
59 }
60 
61 void
63 {
64  auto current_boundary_name = _mesh.getBoundaryName(_current_boundary_id);
65  if (_side_name_index.find(current_boundary_name) == _side_name_index.end())
66  mooseError("Current boundary name: ",
67  current_boundary_name,
68  " with id ",
69  _current_boundary_id,
70  " not in boundary parameter.");
71  unsigned int index = _side_name_index.find(current_boundary_name)->second;
72 
73  _areas[index] += _current_side_volume;
74 
75  for (auto & side : _side_list)
76  {
77  auto remote_boundary_name = _mesh.getBoundaryName(std::get<2>(side));
78  if (_side_name_index.find(remote_boundary_name) != _side_name_index.end() &&
79  std::get<2>(side) != _current_boundary_id)
80  {
81  // this is the remote side index
82  unsigned int remote_index = _side_name_index.find(remote_boundary_name)->second;
83  Real & vf = _view_factors[index][remote_index];
84 
85  // compute some important quantities on the face
86  reinitFace(std::get<0>(side), std::get<1>(side));
87 
88  // loop over pairs of the qps on the current side
89  for (unsigned int qp = 0; qp < _qrule->n_points(); ++qp)
90  {
91  // loop over the qps on the remote element
92  for (unsigned int r_qp = 0; r_qp < _current_remote_JxW->size(); ++r_qp)
93  {
94  Point r2r = (_q_point[qp] - (*_current_remote_xyz)[r_qp]);
95  Real distance = r2r.norm();
96  Real cos1 = r2r * _normals[qp] / distance;
97  Real cos2 = r2r * (*_current_remote_normals)[r_qp] / distance;
98 
99  vf += _JxW[qp] * _coord[qp] * (*_current_remote_JxW)[r_qp] * _current_remote_coord[r_qp] *
100  std::abs(cos1) * std::abs(cos2) / MathUtils::pow(distance, _exponent);
101  }
102  }
103  }
104  }
105 }
106 
107 void
109 {
110  // get boundary info from the mesh
111  _boundary_info = &_mesh.getMesh().get_boundary_info();
112 
113  // get a list of all sides
114  _side_list = _boundary_info->build_active_side_list();
115 
116  // set view_factors to zero
117  for (unsigned int j = 0; j < _n_sides; ++j)
118  {
119  _areas[j] = 0;
120  for (auto & vf : _view_factors[j])
121  vf = 0;
122  }
123 }
124 
125 void
127 {
128  gatherSum(_areas);
129 
130  // divide view_factor Fij by Ai and pi
131  for (unsigned int i = 0; i < _n_sides; ++i)
132  for (auto & vf : _view_factors[i])
133  vf /= (_areas[i] * _divisor);
134 }
135 
136 void
138 {
139  const UnobstructedPlanarViewFactor & pps = static_cast<const UnobstructedPlanarViewFactor &>(y);
140  for (unsigned int i = 0; i < _n_sides; ++i)
141  _areas[i] += pps._areas[i];
142 }
143 
144 void
145 UnobstructedPlanarViewFactor::reinitFace(dof_id_type elem_id, unsigned int side)
146 {
147  const Elem * current_remote_elem = _mesh.getMesh().elem_ptr(elem_id);
148  _current_remote_side = current_remote_elem->build_side_ptr(side);
150 
151  Order order = current_remote_elem->default_order();
152  unsigned int dim = _mesh.getMesh().mesh_dimension();
153  _current_remote_fe = FEBase::build(dim, FEType(order));
154  QGauss qface(dim - 1, FEType(order).default_quadrature_order());
155  _current_remote_fe->attach_quadrature_rule(&qface);
156 
160 
161  _current_remote_fe->reinit(current_remote_elem, side);
162 
163  // set _coord
164  unsigned int n_points = _current_remote_xyz->size();
165  unsigned int rz_radial_coord = _subproblem.getAxisymmetricRadialCoord();
166  _current_remote_coord.resize(n_points);
167  switch (_assembly.coordSystem())
168  {
169  case Moose::COORD_XYZ:
170  for (unsigned int qp = 0; qp < n_points; qp++)
171  _current_remote_coord[qp] = 1.;
172  break;
173 
174  case Moose::COORD_RZ:
175  for (unsigned int qp = 0; qp < n_points; qp++)
176  _current_remote_coord[qp] = 2 * M_PI * (*_current_remote_xyz)[qp](rz_radial_coord);
177  break;
178 
179  case Moose::COORD_RSPHERICAL:
180  for (unsigned int qp = 0; qp < n_points; qp++)
182  4 * M_PI * (*_current_remote_xyz)[qp](0) * (*_current_remote_xyz)[qp](0);
183  break;
184 
185  default:
186  mooseError("Unknown coordinate system");
187  break;
188  }
189 }
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
UnobstructedPlanarViewFactor::initialize
virtual void initialize() override
Definition: UnobstructedPlanarViewFactor.C:108
ViewFactorBase::_areas
std::vector< Real > _areas
area of the sides i
Definition: ViewFactorBase.h:53
pow
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
Definition: ExpressionBuilder.h:673
ViewFactorBase::_n_sides
unsigned int _n_sides
number of boundaries of this side uo
Definition: ViewFactorBase.h:50
UnobstructedPlanarViewFactor::_current_remote_fe
std::unique_ptr< FEBase > _current_remote_fe
Definition: UnobstructedPlanarViewFactor.h:45
UnobstructedPlanarViewFactor::_exponent
unsigned int _exponent
Definition: UnobstructedPlanarViewFactor.h:53
ViewFactorBase::_view_factors
std::vector< std::vector< Real > > _view_factors
the view factor from side i to side j
Definition: ViewFactorBase.h:62
registerMooseObject
registerMooseObject("HeatConductionApp", UnobstructedPlanarViewFactor)
UnobstructedPlanarViewFactor::_current_remote_side
std::unique_ptr< const Elem > _current_remote_side
data of the to_elem side being initialized
Definition: UnobstructedPlanarViewFactor.h:44
UnobstructedPlanarViewFactor::validParams
static InputParameters validParams()
Definition: UnobstructedPlanarViewFactor.C:28
UnobstructedPlanarViewFactor::UnobstructedPlanarViewFactor
UnobstructedPlanarViewFactor(const InputParameters &parameters)
Definition: UnobstructedPlanarViewFactor.C:36
UnobstructedPlanarViewFactor::finalizeViewFactor
virtual void finalizeViewFactor() override
a purely virtural function called in finalize, must be overriden by derived class
Definition: UnobstructedPlanarViewFactor.C:126
UnobstructedPlanarViewFactor.h
defineLegacyParams
defineLegacyParams(UnobstructedPlanarViewFactor)
UnobstructedPlanarViewFactor::_current_remote_side_volume
Real _current_remote_side_volume
Definition: UnobstructedPlanarViewFactor.h:46
UnobstructedPlanarViewFactor::_current_remote_JxW
const std::vector< Real > * _current_remote_JxW
Definition: UnobstructedPlanarViewFactor.h:47
UnobstructedPlanarViewFactor::execute
virtual void execute() override
Definition: UnobstructedPlanarViewFactor.C:62
UnobstructedPlanarViewFactor::_side_list
std::vector< std::tuple< dof_id_type, unsigned short int, boundary_id_type > > _side_list
Definition: UnobstructedPlanarViewFactor.h:41
UnobstructedPlanarViewFactor::_current_remote_normals
const std::vector< Point > * _current_remote_normals
Definition: UnobstructedPlanarViewFactor.h:49
UnobstructedPlanarViewFactor::_current_remote_xyz
const std::vector< Point > * _current_remote_xyz
Definition: UnobstructedPlanarViewFactor.h:48
UnobstructedPlanarViewFactor
Computes the view factors for planar faces in unobstructed radiative heat transfer.
Definition: UnobstructedPlanarViewFactor.h:23
UnobstructedPlanarViewFactor::reinitFace
void reinitFace(dof_id_type elem_id, unsigned int side)
helper function that reinits an element face
Definition: UnobstructedPlanarViewFactor.C:145
UnobstructedPlanarViewFactor::threadJoinViewFactor
virtual void threadJoinViewFactor(const UserObject &y) override
a purely virtural function called in finalize, must be overriden by derived class
Definition: UnobstructedPlanarViewFactor.C:137
ViewFactorBase::validParams
static InputParameters validParams()
Definition: ViewFactorBase.C:18
UnobstructedPlanarViewFactor::_current_remote_coord
std::vector< Real > _current_remote_coord
Definition: UnobstructedPlanarViewFactor.h:50
UnobstructedPlanarViewFactor::_divisor
Real _divisor
Definition: UnobstructedPlanarViewFactor.h:54
UnobstructedPlanarViewFactor::_boundary_info
BoundaryInfo * _boundary_info
Definition: UnobstructedPlanarViewFactor.h:40