https://mooseframework.inl.gov
FVHarmonicAverage.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 
10 #include "FVHarmonicAverage.h"
11 
12 #include <algorithm>
13 #include <cmath>
14 #include <limits>
15 
17 
20 {
22  params.addClassDescription(
23  "Harmonic mean interpolation for finite-volume quantities using FaceInfo geometry weights.");
24  return params;
25 }
26 
28 {
29 }
30 
31 Real
33  const Real elem_value,
34  const Real neighbor_value) const
35 {
36  mooseAssert(face.neighborPtr(),
37  "Harmonic interpolation is intended for internal faces with a neighbor.");
38  // We will guard for the zeros below
39  mooseAssert(
40  (elem_value >= 0 && neighbor_value >= 0) || (elem_value <= 0 && neighbor_value <= 0),
41  "Harmonic interpolation requires the element and neighbor values to have the same sign.");
42 
43  const Real gc = face.gC();
44  const Real one_minus_gc = 1.0 - gc;
45 
46  // We guard against those nasty zeros here
47  const auto safe = [](const Real value)
48  {
49  // Use the smallest positive normalized value to avoid division by zero while keeping sign.
51  return std::copysign(std::max(std::abs(value), eps), value);
52  };
53 
54  // Weighted harmonic mean: 1 / (g/phi_e + (1-g)/phi_n).
55  const Real denom = gc / safe(elem_value) + one_minus_gc / safe(neighbor_value);
56  return 1.0 / denom;
57 }
static InputParameters validParams()
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
Definition: EigenADReal.h:50
int eps(unsigned int i, unsigned int j)
2D version
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Registered base class for linear FV interpolation objects.
FVHarmonicAverage(const InputParameters &params)
registerMooseObject("MooseApp", FVHarmonicAverage)
auto max(const L &left, const R &right)
This data structure is used to store geometric and variable related metadata about each cell face in ...
Definition: FaceInfo.h:37
const Elem * neighborPtr() const
Definition: FaceInfo.h:88
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
Real gC() const
Return the geometric weighting factor.
Definition: FaceInfo.h:136
static InputParameters validParams()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Real interpolate(const FaceInfo &face, Real elem_value, Real neighbor_value) const override
Face interpolation operation for this method.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
auto min(const L &left, const R &right)
Harmonic-mean interpolation using the geometric weighting stored on FaceInfo.