https://mooseframework.inl.gov
UnobstructedPlanarViewFactor.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 "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 
27 {
29  params.addClassDescription(
30  "Computes the view factors for planar faces in unubstructed radiative heat transfer.");
31  return params;
32 }
33 
35  : ViewFactorBase(parameters),
36  _boundary_info(nullptr),
37  _current_remote_side(nullptr),
38  _current_remote_fe(nullptr),
39  _current_remote_JxW(nullptr),
40  _current_remote_xyz(nullptr),
41  _current_remote_normals(nullptr)
42 {
43  _mesh.errorIfDistributedMesh("UnobstructedPlanarViewFactor");
44 
45  if (_mesh.dimension() == 1)
46  mooseError("View factor calculations for 1D geometry makes no sense");
47  else if (_mesh.dimension() == 2)
48  {
49  _exponent = 1;
50  _divisor = 2;
51  }
52  else
53  {
54  _exponent = 2;
56  }
57 }
58 
59 void
61 {
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 ",
70  " not in boundary parameter.");
71  unsigned int index = _side_name_index.find(current_boundary_name)->second;
72 
73  for (auto & side : _side_list)
74  {
75  auto remote_boundary_name = _mesh.getBoundaryName(std::get<2>(side));
76  if (_side_name_index.find(remote_boundary_name) != _side_name_index.end() &&
77  std::get<2>(side) != _current_boundary_id)
78  {
79  // this is the remote side index
80  unsigned int remote_index = _side_name_index.find(remote_boundary_name)->second;
81  Real & vf = _view_factors[index][remote_index];
82 
83  // compute some important quantities on the face
84  reinitFace(std::get<0>(side), std::get<1>(side));
85 
86  // loop over pairs of the qps on the current side
87  for (unsigned int qp = 0; qp < _qrule->n_points(); ++qp)
88  {
89  // loop over the qps on the remote element
90  for (unsigned int r_qp = 0; r_qp < _current_remote_JxW->size(); ++r_qp)
91  {
92  Point r2r = (_q_point[qp] - (*_current_remote_xyz)[r_qp]);
93  Real distance = r2r.norm();
94  Real cos1 = r2r * _normals[qp] / distance;
95  Real cos2 = r2r * (*_current_remote_normals)[r_qp] / distance;
96 
97  vf += _JxW[qp] * _coord[qp] * (*_current_remote_JxW)[r_qp] * _current_remote_coord[r_qp] *
98  std::abs(cos1) * std::abs(cos2) / MathUtils::pow(distance, _exponent);
99  }
100  }
101  }
102  }
103 }
104 
105 void
107 {
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  for (auto & vf : _view_factors[j])
120  vf = 0;
121  }
122 }
123 
124 void
126 {
127  const auto & vf = static_cast<const UnobstructedPlanarViewFactor &>(y);
128  for (unsigned int i = 0; i < _n_sides; ++i)
129  for (unsigned int j = 0; j < _n_sides; ++j)
130  _view_factors[i][j] += vf._view_factors[i][j];
131 }
132 
133 void
135 {
136  for (unsigned int i = 0; i < _n_sides; ++i)
137  {
139 
140  // divide view_factor Fij by Ai and pi
141  for (auto & vf : _view_factors[i])
142  vf /= (_areas[i] * _divisor);
143  }
144 }
145 
146 void
148 {
149  const Elem * current_remote_elem = _mesh.getMesh().elem_ptr(elem_id);
150  _current_remote_side = current_remote_elem->build_side_ptr(side);
152 
153  Order order = current_remote_elem->default_order();
154  unsigned int dim = _mesh.getMesh().mesh_dimension();
155  _current_remote_fe = FEBase::build(dim, FEType(order));
156  libMesh::QGauss qface(dim - 1, FEType(order).default_quadrature_order());
157  _current_remote_fe->attach_quadrature_rule(&qface);
158 
162 
163  _current_remote_fe->reinit(current_remote_elem, side);
164 
165  // set _coord
166  unsigned int n_points = _current_remote_xyz->size();
167  unsigned int rz_radial_coord = _subproblem.getAxisymmetricRadialCoord();
168  _current_remote_coord.resize(n_points);
169  switch (_assembly.coordSystem())
170  {
171  case Moose::COORD_XYZ:
172  for (unsigned int qp = 0; qp < n_points; qp++)
173  _current_remote_coord[qp] = 1.;
174  break;
175 
176  case Moose::COORD_RZ:
177  for (unsigned int qp = 0; qp < n_points; qp++)
178  _current_remote_coord[qp] = 2 * M_PI * (*_current_remote_xyz)[qp](rz_radial_coord);
179  break;
180 
182  for (unsigned int qp = 0; qp < n_points; qp++)
184  4 * M_PI * (*_current_remote_xyz)[qp](0) * (*_current_remote_xyz)[qp](0);
185  break;
186 
187  default:
188  mooseError("Unknown coordinate system");
189  break;
190  }
191 }
unsigned int getAxisymmetricRadialCoord() const
void gatherSum(T &value)
void reinitFace(dof_id_type elem_id, unsigned int side)
helper function that reinits an element face
Order
std::vector< Real > _areas
area of the sides i
virtual void finalizeViewFactor() override
a purely virtural function called in finalize, must be overriden by derived class ...
unsigned int dim
std::unordered_map< std::string, unsigned int > _side_name_index
boundary name to index map
unsigned int _n_sides
number of boundaries of this side uo
const std::vector< Point > * _current_remote_normals
const std::string & getBoundaryName(const BoundaryID boundary_id) const
const MooseArray< Point > & _q_point
const std::vector< double > y
COORD_RSPHERICAL
Real distance(const Point &p)
virtual void execute() override
A base class for automatic computation of view factors between sidesets.
const MooseArray< Real > & _JxW
void errorIfDistributedMesh(std::string name) const
const BoundaryID & _current_boundary_id
registerMooseObject("HeatTransferApp", UnobstructedPlanarViewFactor)
std::unique_ptr< libMesh::FEBase > _current_remote_fe
std::vector< std::vector< Real > > _view_factors
the view factor from side i to side j
MeshBase & getMesh()
UnobstructedPlanarViewFactor(const InputParameters &parameters)
virtual unsigned int dimension() const
Real elementVolume(const Elem *elem) const
SubProblem & _subproblem
const MooseArray< Real > & _coord
Assembly & _assembly
Computes the view factors for planar faces in unobstructed radiative heat transfer.
static InputParameters validParams()
const Moose::CoordinateSystemType & coordSystem() const
virtual void threadJoinViewFactor(const UserObject &y) override
a purely virtual function called in finalize, must be overriden by derived class
std::unique_ptr< const Elem > _current_remote_side
data of the to_elem side being initialized
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
MooseMesh & _mesh
const QBase *const & _qrule
const std::vector< Real > * _current_remote_JxW
const MooseArray< Point > & _normals
void mooseError(Args &&... args) const
const std::vector< Point > * _current_remote_xyz
void addClassDescription(const std::string &doc_string)
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
T pow(T x, int e)
uint8_t dof_id_type
virtual void initialize() override
const Real pi
std::vector< std::tuple< dof_id_type, unsigned short int, boundary_id_type > > _side_list