https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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{
23 "Harmonic mean interpolation for finite-volume quantities using FaceInfo geometry weights.");
24 return params;
25}
26
30
31Real
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.
50 const Real eps = std::numeric_limits<Real>::min();
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}
registerMooseObject("MooseApp", FVHarmonicAverage)
Harmonic-mean interpolation using the geometric weighting stored on FaceInfo.
Real interpolate(const FaceInfo &face, Real elem_value, Real neighbor_value) const override
Face interpolation operation for this method.
static InputParameters validParams()
FVHarmonicAverage(const InputParameters &params)
Registered base class for linear FV interpolation objects.
static InputParameters validParams()
This data structure is used to store geometric and variable related metadata about each cell face in ...
Definition FaceInfo.h:38
const Elem * neighborPtr() const
Definition FaceInfo.h:88
Real gC() const
Return the geometric weighting factor.
Definition FaceInfo.h:136
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.