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 {
62  auto current_boundary_name = _mesh.getBoundaryName(_current_boundary_id);
63  if (_side_name_index.find(current_boundary_name) == _side_name_index.end())
64  mooseError("Current boundary name: ",
65  current_boundary_name,
66  " with id ",
68  " not in boundary parameter.");
69  unsigned int index = _side_name_index.find(current_boundary_name)->second;
70 
71  _areas[index] += _current_side_volume;
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 {
108  // get boundary info from the mesh
109  _boundary_info = &_mesh.getMesh().get_boundary_info();
110 
111  // get a list of all sides
112  _side_list = _boundary_info->build_active_side_list();
113 
114  // set view_factors to zero
115  for (unsigned int j = 0; j < _n_sides; ++j)
116  {
117  _areas[j] = 0;
118  for (auto & vf : _view_factors[j])
119  vf = 0;
120  }
121 }
122 
123 void
125 {
126  gatherSum(_areas);
127 
128  // divide view_factor Fij by Ai and pi
129  for (unsigned int i = 0; i < _n_sides; ++i)
130  for (auto & vf : _view_factors[i])
131  vf /= (_areas[i] * _divisor);
132 }
133 
134 void
136 {
137  const auto & pps = static_cast<const UnobstructedPlanarViewFactor &>(y);
138  for (unsigned int i = 0; i < _n_sides; ++i)
139  _areas[i] += pps._areas[i];
140 }
141 
142 void
144 {
145  const Elem * current_remote_elem = _mesh.getMesh().elem_ptr(elem_id);
146  _current_remote_side = current_remote_elem->build_side_ptr(side);
148 
149  Order order = current_remote_elem->default_order();
150  unsigned int dim = _mesh.getMesh().mesh_dimension();
151  _current_remote_fe = FEBase::build(dim, FEType(order));
152  libMesh::QGauss qface(dim - 1, FEType(order).default_quadrature_order());
153  _current_remote_fe->attach_quadrature_rule(&qface);
154 
158 
159  _current_remote_fe->reinit(current_remote_elem, side);
160 
161  // set _coord
162  unsigned int n_points = _current_remote_xyz->size();
163  unsigned int rz_radial_coord = _subproblem.getAxisymmetricRadialCoord();
164  _current_remote_coord.resize(n_points);
165  switch (_assembly.coordSystem())
166  {
167  case Moose::COORD_XYZ:
168  for (unsigned int qp = 0; qp < n_points; qp++)
169  _current_remote_coord[qp] = 1.;
170  break;
171 
172  case Moose::COORD_RZ:
173  for (unsigned int qp = 0; qp < n_points; qp++)
174  _current_remote_coord[qp] = 2 * M_PI * (*_current_remote_xyz)[qp](rz_radial_coord);
175  break;
176 
178  for (unsigned int qp = 0; qp < n_points; qp++)
180  4 * M_PI * (*_current_remote_xyz)[qp](0) * (*_current_remote_xyz)[qp](0);
181  break;
182 
183  default:
184  mooseError("Unknown coordinate system");
185  break;
186  }
187 }
unsigned int getAxisymmetricRadialCoord() const
void reinitFace(dof_id_type elem_id, unsigned int side)
helper function that reinits an element face
Order
Assembly & _assembly
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::string & getBoundaryName(BoundaryID boundary_id)
const std::vector< Point > * _current_remote_normals
const MooseArray< Point > & _q_point
const std::vector< double > y
COORD_RSPHERICAL
Real distance(const Point &p)
A base class for automatic computation of view factors between sidesets.
SubProblem & _subproblem
const MooseArray< Real > & _JxW
const Real & _current_side_volume
void errorIfDistributedMesh(std::string name) const
const BoundaryID & _current_boundary_id
registerMooseObject("HeatTransferApp", UnobstructedPlanarViewFactor)
std::unique_ptr< libMesh::FEBase > _current_remote_fe
void gatherSum(T &value)
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
const MooseArray< Real > & _coord
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
const Real pi
std::vector< std::tuple< dof_id_type, unsigned short int, boundary_id_type > > _side_list