OOFEM 3.0
Loading...
Searching...
No Matches
localgaussianrandomfunction.C
Go to the documentation of this file.
1/*
2 *
3 * ##### ##### ###### ###### ### ###
4 * ## ## ## ## ## ## ## ### ##
5 * ## ## ## ## #### #### ## # ##
6 * ## ## ## ## ## ## ## ##
7 * ## ## ## ## ## ## ## ##
8 * ##### ##### ## ###### ## ##
9 *
10 *
11 * OOFEM : Object Oriented Finite Element Code
12 *
13 * Copyright (C) 1993 - 2025 Borek Patzak
14 *
15 *
16 *
17 * Czech Technical University, Faculty of Civil Engineering,
18 * Department of Structural Mechanics, 166 29 Prague, Czech Republic
19 *
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License as published by the Free Software Foundation; either
23 * version 2.1 of the License, or (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Lesser General Public License for more details.
29 *
30 * You should have received a copy of the GNU Lesser General Public
31 * License along with this library; if not, write to the Free Software
32 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33 */
34
36#include "mathfem.h"
37#include "classfactory.h"
38
39#include <ctime>
40
41namespace oofem {
43
44LocalGaussianRandomFunction :: LocalGaussianRandomFunction(int num, Domain *d) : Function(num, d)
45{ }
46
47LocalGaussianRandomFunction :: ~LocalGaussianRandomFunction()
48{ }
49
50void
51LocalGaussianRandomFunction :: evaluate(FloatArray &answer, const std :: map< std :: string, FunctionArgument > &valDict, GaussPoint *gp, double param)
52{
53 answer = Vec1(evaluateAtTime(0));
54}
55
56double
57LocalGaussianRandomFunction :: evaluateAtTime(double t)
58{
60}
61
62double
63LocalGaussianRandomFunction :: evaluateVelocityAtTime(double t)
64{
65 OOFEM_ERROR("Can't generate velocity of random number");
66}
67
68double
69LocalGaussianRandomFunction :: evaluateAccelerationAtTime(double t)
70{
71 OOFEM_ERROR("Can't generate acceleration of random number");
72}
73
74void
75LocalGaussianRandomFunction :: initializeFrom(InputRecord &ir)
76{
79 randomInteger = ( long ) ( -time(NULL) );
80 int seed = 0;
82 if ( seed ) {
83 randomInteger = seed;
84 }
85}
86
87#define IA 16807
88#define IM 2147483647
89#define AM ( 1.0 / IM )
90#define IQ 127773
91#define IR 2836
92#define NTAB 32
93#define NDIV ( 1 + ( IM - 1 ) / NTAB )
94#define EPS 1.2e-7
95#define RNMX ( 1.0 - EPS )
96
97double LocalGaussianRandomFunction :: ran1(long *idum)
98{
99 long k;
100 static long iy = 0;
101 static long iv [ NTAB ];
102 double temp;
103
104 if ( * idum <= 0 || !iy ) {
105 if ( -( * idum ) < 1 ) {
106 * idum = 1;
107 } else {
108 * idum = -( * idum );
109 }
110
111 for ( int j = NTAB + 7; j >= 0; j-- ) {
112 k = ( * idum ) / IQ;
113 * idum = IA * ( * idum - k * IQ ) - IR * k;
114 if ( * idum < 0 ) {
115 * idum += IM;
116 }
117
118 if ( j < NTAB ) {
119 iv [ j ] = * idum;
120 }
121 }
122
123 iy = iv [ 0 ];
124 }
125
126 k = ( * idum ) / IQ;
127 * idum = IA * ( * idum - k * IQ ) - IR * k;
128 if ( * idum < 0 ) {
129 * idum += IM;
130 }
131
132 int j = iy / NDIV;
133 iy = iv [ j ];
134 iv [ j ] = * idum;
135 if ( ( temp = AM * iy ) > RNMX ) {
136 return RNMX;
137 } else {
138 return temp;
139 }
140}
141
142double LocalGaussianRandomFunction :: normalCdfInverse(double cdf, double a, double b)
143{
144 double x;
145 double x2;
146 if ( cdf < 0.0 || 1.0 < cdf ) {
147 OOFEM_ERROR("NORMAL_CDF_INV - Fatal error!\nCDF < 0 or 1 < CDF.");
148 }
149
150 x2 = normal01CdfInverse(cdf);
151 x = a + b * x2;
152 return x;
153}
154
155double LocalGaussianRandomFunction :: normal01CdfInverse(double p)
156{
157 double a [ 8 ] = {
158 3.3871328727963666080, 1.3314166789178437745e+2,
159 1.9715909503065514427e+3, 1.3731693765509461125e+4,
160 4.5921953931549871457e+4, 6.7265770927008700853e+4,
161 3.3430575583588128105e+4, 2.5090809287301226727e+3
162 };
163 double b [ 8 ] = {
164 1.0, 4.2313330701600911252e+1,
165 6.8718700749205790830e+2, 5.3941960214247511077e+3,
166 2.1213794301586595867e+4, 3.9307895800092710610e+4,
167 2.8729085735721942674e+4, 5.2264952788528545610e+3
168 };
169 double c [ 8 ] = {
170 1.42343711074968357734, 4.63033784615654529590,
171 5.76949722146069140550, 3.64784832476320460504,
172 1.27045825245236838258, 2.41780725177450611770e-1,
173 2.27238449892691845833e-2, 7.74545014278341407640e-4
174 };
175 double const1 = 0.180625;
176 double const2 = 1.6;
177 double d [ 8 ] = {
178 1.0, 2.05319162663775882187,
179 1.67638483018380384940, 6.89767334985100004550e-1,
180 1.48103976427480074590e-1, 1.51986665636164571966e-2,
181 5.47593808499534494600e-4, 1.05075007164441684324e-9
182 };
183 double e [ 8 ] = {
184 6.65790464350110377720, 5.46378491116411436990,
185 1.78482653991729133580, 2.96560571828504891230e-1,
186 2.65321895265761230930e-2, 1.24266094738807843860e-3,
187 2.71155556874348757815e-5, 2.01033439929228813265e-7
188 };
189 double f [ 8 ] = {
190 1.0, 5.99832206555887937690e-1,
191 1.36929880922735805310e-1, 1.48753612908506148525e-2,
192 7.86869131145613259100e-4, 1.84631831751005468180e-5,
193 1.42151175831644588870e-7, 2.04426310338993978564e-15
194 };
195 double q;
196 double r;
197 double split1 = 0.425;
198 double split2 = 5.0;
199 double value;
200
201 if ( p <= 0.0 ) {
202 value = -HUGE_VAL;
203 return value;
204 }
205
206 if ( 1.0 <= p ) {
207 value = HUGE_VAL;
208 return value;
209 }
210
211 q = p - 0.5;
212
213 if ( fabs(q) <= split1 ) {
214 r = const1 - q * q;
215 value = q * dpolyValue(8, a, r) / dpolyValue(8, b, r);
216 } else {
217 if ( q < 0.0 ) {
218 r = p;
219 } else {
220 r = 1.0 - p;
221 }
222
223 if ( r <= 0.0 ) {
224 OOFEM_ERROR("r < 0.0!");
225 }
226
227 r = sqrt( -log(r) );
228 if ( r <= split2 ) {
229 r = r - const2;
230 value = dpolyValue(8, c, r) / dpolyValue(8, d, r);
231 } else {
232 r = r - split2;
233 value = dpolyValue(8, e, r) / dpolyValue(8, f, r);
234 }
235
236 if ( q < 0.0 ) {
237 value = -value;
238 }
239 }
240
241 return value;
242}
243
244
245double LocalGaussianRandomFunction :: dpolyValue(int n, double a[], double x)
246{
247 int i;
248 double value;
249 value = 0.0;
250 for ( i = n - 1; 0 <= i; i-- ) {
251 value = value * x + a [ i ];
252 }
253
254 return value;
255}
256} // end namespace oofem
#define REGISTER_Function(class)
Function(int n, Domain *d)
Definition function.C:44
double normalCdfInverse(double cdf, double a, double b)
long randomInteger
Integer which is the input of the pseudo-random number generator.
double dpolyValue(int n, double a[], double x)
double mean
Gauss distribution parameters.
#define OOFEM_ERROR(...)
Definition error.h:79
#define IR_GIVE_OPTIONAL_FIELD(__ir, __value, __id)
Definition inputrecord.h:75
#define IR_GIVE_FIELD(__ir, __value, __id)
Definition inputrecord.h:67
#define _IFT_LocalGaussianRandomFunction_seed
#define _IFT_LocalGaussianRandomFunction_variance
#define _IFT_LocalGaussianRandomFunction_mean
static FloatArray Vec1(const double &a)
Definition floatarray.h:605

This page is part of the OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak Bořek Patzák
Project e-mail: oofem@fsv.cvut.cz
Generated at for OOFEM by doxygen 1.15.0 written by Dimitri van Heesch, © 1997-2011