https://mooseframework.inl.gov
Loading...
Searching...
No Matches
WeightedTransition.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 "WeightedTransition.h"
11
12WeightedTransition::WeightedTransition(const Real & x_center, const Real & transition_width)
13 : SmoothTransition(x_center, transition_width)
14{
15}
16
17Real
18WeightedTransition::value(const Real & x, const Real & f1, const Real & f2) const
19{
20 if (x <= _x1)
21 return f1;
22 else if (x >= _x2)
23 return f2;
24 else
25 {
26 const Real w = weight(x);
27 return w * f1 + (1.0 - w) * f2;
28 }
29}
30
31Real
33 const Real & x, const Real & f1, const Real & f2, const Real & df1dx, const Real & df2dx) const
34{
35 if (x <= _x1)
36 return df1dx;
37 else if (x >= _x2)
38 return df2dx;
39 else
40 {
41 const Real w = weight(x);
42 const Real dwdx = -0.5 * std::sin(M_PI / (_x2 - _x1) * (x - _x1)) * M_PI / (_x2 - _x1);
43 return w * df1dx + (1.0 - w) * df2dx + dwdx * (f1 - f2);
44 }
45}
46
47Real
48WeightedTransition::weight(const Real & x) const
49{
50 return 0.5 * (std::cos(M_PI / (_x2 - _x1) * (x - _x1)) + 1.0);
51}
const std::vector< double > x
Base class for smooth transitions between two functions of one variable.
const Real _x1
Left end point of transition.
const Real _x2
Right end point of transition.
Real derivative(const Real &x, const Real &f1, const Real &f2, const Real &df1dx, const Real &df2dx) const
Computes the derivative of the transition value.
WeightedTransition(const Real &x_center, const Real &transition_width)
Constructor.
Real weight(const Real &x) const
Computes the weight of the first function.
virtual Real value(const Real &x, const Real &f1, const Real &f2) const override
Computes the transition value.