11 #include "MooseRandom.h"
12 #include "FEProblemBase.h"
13 #include "libmesh/utility.h"
21 InputParameters params = validParams<Function>();
22 params.addClassDescription(
"Generate noise from a fourier series");
23 params.addRequiredParam<Real>(
"lambda",
24 "Wavelength cut off (set to about twice the interfacial width)");
25 params.addParam<
unsigned int>(
27 "Number of random fourier series terms (this will result in non-periodic noise). Omit this "
28 "parameter to obtain a periodic noise distribution.");
29 params.addParam<
unsigned int>(
"seed", 12455,
"Random number generator seed");
34 : Function(parameters),
35 _lambda(getParam<Real>(
"lambda")),
36 _fe_problem(*getCheckedPointerParam<FEProblemBase *>(
"_fe_problem_base"))
39 rng.seed(0, getParam<unsigned int>(
"seed"));
41 if (isParamValid(
"num_terms"))
44 _series.resize(getParam<unsigned int>(
"num_terms"));
45 const Real scale = 2.0 * (2.0 * libMesh::pi) /
_lambda;
49 paramError(
"num_terms",
50 "If specifying the number of terms, supply a number greater than zero.");
59 const Real x = rng.rand(0) - 0.5;
60 const Real y = rng.rand(0) - 0.5;
61 f.k = RealVectorValue(x, y, 0.0);
68 f.c = rng.randNormal(0, 0.0, 1.0);
69 f.s = rng.randNormal(0, 0.0, 1.0);
76 if (!mesh.isRegularOrthogonal())
77 mooseError(
"Periodic Fourier Noise requires a regular orthogonal mesh.");
79 const Real dx = 2.0 * libMesh::pi / mesh.dimensionWidth(0);
80 const Real dy = 2.0 * libMesh::pi / mesh.dimensionWidth(1);
81 const Real rmax = 2.0 * libMesh::pi /
_lambda;
83 const int xmax = rmax / dx;
84 const int ymax = rmax / dy;
86 const Real rmax2 = rmax * rmax;
87 for (
int x = 0; x < xmax; ++x)
88 for (
int y = -ymax; y < ymax; ++y)
92 f.
k = RealVectorValue(x * dx, y * dy, 0.0);
93 if (f.
k.norm_sq() <= rmax2)
95 f.
c = rng.randNormal(0, 0.0, 1.0);
96 f.
s = rng.randNormal(0, 0.0, 1.0);
110 v += f.s * std::sin(p * f.k) + f.c * std::cos(p * f.k);