11#include "libmesh/quadrature.h"
19 params.
addParam<Real>(
"view_factor_tol",
20 std::numeric_limits<Real>::max(),
21 "Tolerance for checking view factors. Default is to allow everything.");
23 "print_view_factor_info",
false,
"Flag to print information about computed view factors.");
24 params.
addParam<
bool>(
"normalize_view_factor",
26 "Determines if view factors are normalized to sum to one (consistent with "
27 "their definition).");
29 MooseEnum normalization_method(
"lagrange_multiplier inverse_row_sum",
"lagrange_multiplier");
30 normalization_method.addDocumentation(
"lagrange_multiplier",
"Uses Lagrange multiplier method");
31 normalization_method.addDocumentation(
"inverse_row_sum",
32 "Divides each view factor by its row sum");
35 "Normalization method to use if 'normalize_view_factor' is 'true'.");
38 "A base class for automatic computation of view factors between sidesets.");
44 _n_sides(boundaryIDs().size()),
46 _view_factor_tol(getParam<Real>(
"view_factor_tol")),
47 _normalize_view_factor(getParam<bool>(
"normalize_view_factor")),
48 _normalization_method(
50 _print_view_factor_info(getParam<bool>(
"print_view_factor_info"))
58 std::vector<BoundaryName> boundary_names = getParam<std::vector<BoundaryName>>(
"boundary");
59 for (
unsigned int j = 0; j < boundary_names.size(); ++j)
91 " not listed in boundary parameter.");
98 " not listed in boundary parameter.");
117 current_boundary_name,
120 " not in boundary parameter.");
138 for (
unsigned int i = 0; i <
_n_sides; ++i)
154 for (
unsigned int i = 0; i <
_n_sides; ++i)
155 for (
unsigned int j = i + 1; j <
_n_sides; ++j)
168 for (
unsigned int to = 0; to <
_n_sides; ++to)
177 for (
unsigned int i = 0; i <
_n_sides; ++i)
192 Real max_correction = std::numeric_limits<Real>::lowest();
193 Real min_correction = std::numeric_limits<Real>::max();
196 _console <<
"\nSum of all view factors from side i to all other faces before normalization.\n"
201 for (
unsigned int from = 0; from <
_n_sides; ++from)
206 mooseError(
"Maximum deviation of view factor row sum is ",
208 " exceeding the set tolerance of ",
215 _console <<
"\nNormalizing view factors.\n" << std::endl;
232 for (
const auto i : make_range(
_n_sides))
233 for (
const auto j : make_range(
_n_sides))
235 const Real correction =
_view_factors[i][j] - view_factors_original[i][j];
236 min_correction = std::min(correction, min_correction);
237 max_correction = std::max(correction, max_correction);
243 _console <<
"\nFinal view factors.\n" << std::endl;
244 for (
unsigned int from = 0; from <
_n_sides; ++from)
246 std::string from_name;
248 if (pair.second == from)
249 from_name = pair.first;
252 for (
unsigned int to = 0; to <
_n_sides; ++to)
256 if (pair.second == to)
257 to_name = pair.first;
259 _console << from_name <<
" (" << from_id <<
") -> " << to_name <<
" (" << to_id
266 Real max_sum_deviation_after_normalization =
maxDevRowSum();
271 _console << COLOR_CYAN <<
"Summary of the view factor computation"
273 << COLOR_DEFAULT << std::endl;
275 _console <<
"Normalization is performed." << std::endl;
277 _console <<
"Normalization is skipped." << std::endl;
278 _console << std::setw(60) << std::left <<
"Number of patches: " <<
_n_sides << std::endl;
279 _console << std::setw(60) << std::left
280 <<
"Max deviation sum = 1 before normalization: " << max_sum_deviation << std::endl;
281 _console << std::setw(60) << std::left
282 <<
"Max deviation from reciprocity before normalization: " << max_reciprocity_deviation
286 _console << std::setw(60) << std::left <<
"Maximum correction: " << max_correction << std::endl;
287 _console << std::setw(60) << std::left <<
"Minimum correction: " << min_correction << std::endl;
288 _console << std::setw(60) <<
"Max deviation sum = 1 after normalization: "
289 << max_sum_deviation_after_normalization << std::endl;
290 _console << std::setw(60) << std::left <<
"Max deviation from reciprocity after normalization: "
291 << max_reciprocity_deviation_after_normalization << std::endl;
305 for (
unsigned int i = 0; i <
_n_sides; ++i)
314 for (
unsigned int j = i + 1; j <
_n_sides; ++j)
317 Real
f = 2 * (1 + ar * ar);
318 matrix(i, i) += -1 /
f;
319 matrix(i, j) += -1 /
f * ar;
324 for (
unsigned int j = 0; j < i; ++j)
327 Real
f = 2 * (1 + ar * ar);
328 matrix(i, i) += -1 /
f * ar * ar;
329 matrix(i, j) += -1 /
f * ar;
330 rhs(i) -= ar *
devReciprocity(j, i) * (1 - ar * ar / (1 + ar * ar));
335 matrix.lu_solve(rhs, lmults);
340 for (
unsigned int i = 0; i <
_n_sides; ++i)
341 for (
unsigned int j = 0; j <
_n_sides; ++j)
345 correction = -0.5 * lmults(i);
349 Real
f = 2 * (1 + ar * ar);
350 correction = -(lmults(i) + lmults(j) * ar + 2 * ar * ar *
devReciprocity(i, j)) /
f;
354 vf_temp[i][j] += correction;
362 for (
unsigned int i = 0; i <
_n_sides; ++i)
373 mooseAssert(i <= j,
"indexHelper requires i <= j");
377 for (
unsigned int l = 0; l <
_n_sides; ++l)
378 for (
unsigned int m = l + 1; m <
_n_sides; ++m)
380 if (l == i && m == j)
boundary_id_type BoundaryID
Real f(Real x)
Test function for Brents method.
const std::vector< double > y
const std::vector< BoundaryName > & boundaryNames() const
const ConsoleStream _console
const std::string & name() const
void mooseError(Args &&... args) const
const std::string & getBoundaryName(const BoundaryID boundary_id) const
BoundaryID getBoundaryID(const BoundaryName &boundary_name) const
const Real & _current_side_volume
static InputParameters validParams()
const BoundaryID & _current_boundary_id
A base class for automatic computation of view factors between sidesets.
virtual void execute() override
const bool _normalize_view_factor
whether to normalize view factors so vf[from][:] sums to one
virtual void finalizeViewFactor()=0
a purely virtural function called in finalize, must be overriden by derived class
const Real _view_factor_tol
view factor tolerance
void normalizeUsingLagrangeMultiplier()
normalizes view factors by Lagrange multiplier method
void normalizeUsingInverseRowSum()
normalizes view factors by inverse row sum
unsigned int indexHelper(unsigned int i, unsigned int j) const
helper for finding index of correction for i,j-th entry
unsigned int getSideNameIndex(std::string name) const
helper function to get the index from the boundary name
virtual void threadJoin(const UserObject &y) override final
std::vector< std::vector< Real > > _view_factors
the view factor from side i to side j
std::unordered_map< std::string, unsigned int > _side_name_index
boundary name to index map
Real maxDevRowSum() const
maximum deviation of any view factor row sum from 1
virtual void initialize() override
virtual void threadJoinViewFactor(const UserObject &y)=0
a purely virtual function called in finalize, must be overriden by derived class
virtual void finalize() override final
unsigned int _n_sides
number of boundaries of this side uo
NormalizationMethod
How to normalize view factors.
Real devReciprocity(unsigned int i, unsigned int j) const
this function computes the deviation from reciprocity defined as Fij - Aj/Ai * Fji
const NormalizationMethod _normalization_method
How to normalize view factors.
std::vector< Real > _areas
area of the sides i
Real getViewFactor(BoundaryID from_id, BoundaryID to_id) const
public interface for obtaining view factors
Real maxDevReciprocity() const
this function computes the maximum absolute value of the deviation from reciprocity
const bool _print_view_factor_info
void checkAndNormalizeViewFactor()
this function checks & normalizes view factors to sum to one, this is not always
ViewFactorBase(const InputParameters ¶meters)
static InputParameters validParams()
Real viewFactorRowSum(unsigned int i) const
sum of a row in the view factor matrix