www.mooseframework.org
Classes | Public Member Functions | Protected Attributes | List of all members
FourierNoise Class Reference

Generate noise using random fourier series coefficients. More...

#include <FourierNoise.h>

Inheritance diagram for FourierNoise:
[legend]

Classes

struct  SeriesItem
 

Public Member Functions

 FourierNoise (const InputParameters &parameters)
 
virtual Real value (Real, const Point &p) const override
 

Protected Attributes

const Real _lambda
 selected lower lengthscale for the noise cut-off More...
 
std::vector< SeriesItem_series
 Fourier series terms. More...
 
Real _scale
 amplitude factor More...
 
FEProblemBase & _fe_problem
 FEProblem pointer for obtaining the current mesh. More...
 

Detailed Description

Generate noise using random fourier series coefficients.

Definition at line 23 of file FourierNoise.h.

Constructor & Destructor Documentation

◆ FourierNoise()

FourierNoise::FourierNoise ( const InputParameters &  parameters)

Definition at line 33 of file FourierNoise.C.

34  : Function(parameters),
35  _lambda(getParam<Real>("lambda")),
36  _fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base"))
37 {
38  MooseRandom rng;
39  rng.seed(0, getParam<unsigned int>("seed"));
40 
41  if (isParamValid("num_terms"))
42  {
43  // random terms
44  _series.resize(getParam<unsigned int>("num_terms"));
45  const Real scale = 2.0 * (2.0 * libMesh::pi) / _lambda;
46 
47  // check
48  if (_series.empty())
49  paramError("num_terms",
50  "If specifying the number of terms, supply a number greater than zero.");
51 
52  // fill terms
53  for (auto & f : _series)
54  {
55  // get a vector with length <= 0.5
56  Real r2;
57  do
58  {
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);
62  r2 = f.k.norm_sq();
63  } while (r2 > 0.25);
64 
65  // scale maximum to a wavelength of lambda
66  f.k *= scale;
67 
68  f.c = rng.randNormal(0, 0.0, 1.0);
69  f.s = rng.randNormal(0, 0.0, 1.0);
70  }
71  }
72  else
73  {
74  // k-space grid resulting in periodic noise
75  MooseMesh & mesh = _fe_problem.mesh();
76  if (!mesh.isRegularOrthogonal())
77  mooseError("Periodic Fourier Noise requires a regular orthogonal mesh.");
78 
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;
82 
83  const int xmax = rmax / dx;
84  const int ymax = rmax / dy;
85 
86  const Real rmax2 = rmax * rmax;
87  for (int x = 0; x < xmax; ++x)
88  for (int y = -ymax; y < ymax; ++y)
89  if (x > 0 || y > 0)
90  {
91  SeriesItem f;
92  f.k = RealVectorValue(x * dx, y * dy, 0.0);
93  if (f.k.norm_sq() <= rmax2)
94  {
95  f.c = rng.randNormal(0, 0.0, 1.0);
96  f.s = rng.randNormal(0, 0.0, 1.0);
97  _series.push_back(f);
98  }
99  }
100  }
101 
102  _scale = std::sqrt(1.0 / _series.size());
103 }

Member Function Documentation

◆ value()

Real FourierNoise::value ( Real  ,
const Point &  p 
) const
overridevirtual

Definition at line 106 of file FourierNoise.C.

107 {
108  Real v = 0.0;
109  for (const auto & f : _series)
110  v += f.s * std::sin(p * f.k) + f.c * std::cos(p * f.k);
111  return v * _scale;
112 }

Member Data Documentation

◆ _fe_problem

FEProblemBase& FourierNoise::_fe_problem
protected

FEProblem pointer for obtaining the current mesh.

Definition at line 51 of file FourierNoise.h.

Referenced by FourierNoise().

◆ _lambda

const Real FourierNoise::_lambda
protected

selected lower lengthscale for the noise cut-off

Definition at line 42 of file FourierNoise.h.

Referenced by FourierNoise().

◆ _scale

Real FourierNoise::_scale
protected

amplitude factor

Definition at line 48 of file FourierNoise.h.

Referenced by FourierNoise(), and value().

◆ _series

std::vector<SeriesItem> FourierNoise::_series
protected

Fourier series terms.

Definition at line 45 of file FourierNoise.h.

Referenced by FourierNoise(), and value().


The documentation for this class was generated from the following files:
FourierNoise::_scale
Real _scale
amplitude factor
Definition: FourierNoise.h:48
FourierNoise::_series
std::vector< SeriesItem > _series
Fourier series terms.
Definition: FourierNoise.h:45
FourierNoise::_fe_problem
FEProblemBase & _fe_problem
FEProblem pointer for obtaining the current mesh.
Definition: FourierNoise.h:51
FourierNoise::_lambda
const Real _lambda
selected lower lengthscale for the noise cut-off
Definition: FourierNoise.h:42