MoDeNa  1.0
Software framework facilitating sequential multi-scale modelling
WrightCorrection.h
Go to the documentation of this file.
1 
10 void WrightCorrection(double *m, int nNodes);
11 
12 void WrightCorrection(double *m, int nNodes)
13 {
14  int n = 2*nNodes;
15  // dynamic allocation of new moments
16  double *m1, *m2;
17  m1 = new double[n];
18  m2 = new double[n];
19 
20  // selecting two moments, 2nd and 3rd moments
21  int i = 2;
22  int j = 3;
23 
24  // corresponding mean and variance
25  double mu = (j/(i*j-pow(i,2)))*log(m[i]/m[0]) + (i/(i*j-pow(j,2)))*log(m[j]/m[0]);
26  double sigma_var = ((2.0/(pow(j,2)))*log(m[j]/m[0])-(2.0/(i*j))*log(m[i]/m[0]))/(1.0-i/j);
27  if (sigma_var < 0)
28  {
29  sigma_var = 0.0;
30  }
31 
32  // new moments for the first distribution
33  for (int k = 0; k < n; k++)
34  {
35  m1[k] = m[0]*exp(k*mu+((pow(k,2)*sigma_var)/2.0));
36  }
37 
38  // selecting two more moments
39  i = 1;
40  j = 3;
41 
42  // corresponding mean and variance
43  mu = (j/(i*j-pow(i,2)))*log(m[i]/m[0]) + (i/(i*j-pow(j,2)))*log(m[j]/m[0]);
44  sigma_var = ((2.0/(pow(j,2)))*log(m[j]/m[0])-(2.0/(i*j))*log(m[i]/m[0]))/(1.0-i/j);
45  if (sigma_var<0)
46  {
47  sigma_var = 0.0;
48  }
49 
50  // new moments for the second distribution
51  for (int k = 0; k < n; k++)
52  {
53  m2[k] = m[0]*exp(k*mu+((pow(k,2)*sigma_var)/2.0));
54  }
55 
56  // corrected moments = arithmetic mean of the previous two moment sets.
57  for (int k = 0; k < n; k++)
58  {
59  m[k] = (m1[k] + m2[k])/2.0;
60  }
61 }
void WrightCorrection(double *m, int nNodes)
m2
(MoDeNa) Surrogate Model Template (Air, PU)
m
Bubble Growth Application Recipe.
Definition: bubbleGrowth.py:59