42 #ifndef __H__UG__LIB_DISC__SPATIAL_DISC__LOGNORMAL_RANDOM_FIELD_IMPL__
43 #define __H__UG__LIB_DISC__SPATIAL_DISC__LOGNORMAL_RANDOM_FIELD_IMPL__
50 #define M_PI 3.14159265358979323846264338327950288
55 template <
typename TData,
int dim,
typename TRet>
59 for(
size_t i = 0; i <
dim; ++i)
61 for(
size_t j = 0; j <
dim; ++j)
71 template <
typename TData,
int dim,
typename TRet>
77 double fac, rsq, v1, v2, x1, x2;
88 rsq = v1 * v1 + v2 * v2;
89 }
while (rsq >= 1.0 || rsq == 0.0);
90 fac = sqrt(-2.0 * log(rsq) / rsq);
103 template<
typename TData,
int dim,
typename TRet>
106 return urand(0.0, 1.0);
109 template <
typename TData,
int dim,
typename TRet>
114 for(
int i = 0; i < m_N; i++)
115 result += cos(
VecDot(m_vRandomQvec[i], x) + m_vRandomAlpha[i]);
118 double f = m_dMean_f + sqrt(2*m_dSigma_f*m_dSigma_f/m_N)*result;
126 template <
typename TData,
int dim,
typename TRet>
130 for(
int j=0; j<
dim; j++)
131 m_sigma[j] = sqrt(1.0/sigma);
133 m_dSigma_f = sigma_f;
136 m_vRandomQvec.clear();
137 m_vRandomAlpha.clear();
141 m_vRandomQvec.resize(N);
142 for(
int j=0; j<
dim; j++)
143 for(
int i = 0; i < m_N; i++)
144 m_vRandomQvec[i][j] = m_sigma[j]*gasdev();
147 for(
int i = 0; i < m_N; i++)
148 m_vRandomAlpha.push_back(undev()*2*M_PI);
156 template <
typename TData,
int dim,
typename TRet>
159 std::stringstream ss;
162 ss <<
" LognormalRandomField<" <<
dim <<
"d> ( m_N = " << m_N <<
", m_dMean_f = " << m_dMean_f <<
163 ", m_dSigma_f = " << m_dSigma_f <<
", sigma = " << m_dSigma <<
", m_bNoExp = " <<
TrueFalseString(m_bNoExp) <<
")";
double gasdev()
Definition: lognormal_random_field_impl.h:72
std::string config_string() const
Definition: lognormal_random_field_impl.h:157
TRet evaluate(TData &D, const MathVector< dim > &x, number time, int si) const
Definition: lognormal_random_field_impl.h:56
double undev()
Definition: lognormal_random_field_impl.h:104
void set_config(size_t N, double mean_f, double sigma_f, double sigma)
Definition: lognormal_random_field_impl.h:127
double eval_K(const MathVector< dim > &x) const
Definition: lognormal_random_field_impl.h:110
double number
Definition: types.h:124
TNumber urand(TNumber lowerBound, TNumber upperBound)
uniform distributed random numbers in [lowerBound, upperBound[. Use srand to set a seed.
Definition: math_util_impl.hpp:67
vector_t::value_type VecDot(const vector_t &v1, const vector_t &v2)
returns the dot-product of two vector_ts
Definition: math_vector_functions_common_impl.hpp:385
const char * TrueFalseString(bool b)
Definition: string_util.h:437