MoDeNa  1.0
Software framework facilitating sequential multi-scale modelling
differenceTable.h
Go to the documentation of this file.
1 
69 void enterMoments(double *mom, const int nNodes);
70 void enterWeightsNodes(double *we, double *vi, int nNodes);
71 void weightsNodesToMoms(double *mom, double *we, double *vi, int nNodes);
72 void printMoms(const double *m, int nNodes);
73 bool momentsPositivite(const double *moments, int &nNodes);
74 void normalizeMom(double *m, int nNodes);
75 void denormalizeMom(double *m, double M0, int nNodes);
76 void initializeDifferenceTable(double **differenceTable, int nNodes);
77 void printDifferenceTable(double **differenceTable, int nNodes);
78 void buildDifferenceTable(double **differenceTable, double *mom, int nNodes);
79 int isRealizable(double **differenceTable, int nNodes);
80 double vectorNorm(vector<double> const& v);
81 
82 void enterMoments(double *mom, const int nNodes)
83 {
84  for (int i = 0; i < 2*nNodes; i++)
85  {
86  cout << "\tm[" << i << "] = "; cin >> mom[i];
87  }
88  cout << endl;
89 }
90 void enterWeightsNodes(double *we, double *vi, int nNodes)
91 {
92  for(int j = 0; j < nNodes; j++)
93  {
94  cout << "\twe[" << j << "] = "; cin >> we[j];
95  cout << "\tvi[" << j << "] = "; cin >> vi[j];
96  cout << endl;
97  }
98 }
99 void weightsNodesToMoms(double *mom, double *we, double *vi, int nNodes)
100 {
101  for(int k = 0; k < 2*nNodes; k++)
102  {
103  for (int i = 0; i < nNodes; i++)
104  {
105  if (k == 0)
106  {
107  mom[k] += we[i];
108  }
109  else
110  {
111  mom[k] += we[i]*pow(vi[i],k);
112  }
113  }
114  }
115 }
116 void printMoms(const double *m, int nNodes)
117 {
118  for(int i = 0; i < 2*nNodes; i++)
119  {
120  cout << "\tm[" << i << "] = " << m[i] << endl;
121  }
122 }
123 
124 bool momentsPositivite(const double *moments, int &nNodes)
125 {
126  int noMoms = 2*nNodes;
127  for (int i = 0; i < noMoms; i++)
128  {
129  if (moments[i] < 0.0)
130  {
131  cout << "m[" << i << "] is negative!" << endl;
132  return false;
133  // exit(1);
134  }
135  }
136  return true;
137 }
138 
139 void normalizeMom(double *m, int nNodes)
140 {
141  for (int i = 2*nNodes; i >= 0; i--)
142  {
143  m[i] = m[i]/m[0];
144  }
145 }
146 
147 void denormalizeMom(double *m, double M0, int nNodes)
148 {
149  for (int i = 0; i < 2*nNodes; i++)
150  {
151  m[i] = m[i]*M0;
152  }
153 }
154 
155 void initializeDifferenceTable(double **differenceTable, int nNodes)
156 {
157  for (int r = 0; r < 2*nNodes; r++)
158  {
159  for (int c = 0; c < 2*nNodes; c++)
160  {
161  differenceTable[r][c] = 0.0;
162  }
163  }
164 }
165 
166 void printDifferenceTable(double **differenceTable, int nNodes)
167 {
168  cout << endl << "Table of Difference: \n";
169  for (int r = 0; r < 2*nNodes; r++)
170  {
171  for (int c = 0; c < 2*nNodes; c++)
172  {
173  // formatting decimals
174  cout.setf(ios::fixed);
175  cout.setf(ios::showpoint);
176  cout.precision(10);
177  cout << differenceTable[r][c] << " ";
178  }
179  cout << endl;
180  }
181 }
182 
183 void buildDifferenceTable(double **differenceTable, double *mom, int nNodes)
184 {
185  for (int i = 0; i < 2*nNodes; i++)
186  {
187  differenceTable[i][0] = log(mom[i]);
188  }
189  for (int j = 1; j <= 2*nNodes; j++)
190  {
191  for (int k = 0; k < (2*nNodes - j); k++)
192  {
193  differenceTable[k][j] = differenceTable[k+1][j-1]-differenceTable[k][j-1];
194  }
195  }
196 }
197 
198 int isRealizable(double **differenceTable, int nNodes)
199 {
200  int realizable = 0;
201  for (int r = 0; r < (2*nNodes-2); r++)
202  {
203  if (differenceTable[r][2] < 0.0)
204  {
205  // cerr << "Warning Unrealizable Moments!";
206  realizable = 1;
207  }
208  }
209  return realizable;
210 }
211 
212 double vectorNorm(vector<double> const& v)
213 {
214  double result = 0.0;
215  for (unsigned int i = 0; i < v.size(); ++i)
216  {
217  result += v[i]*v[i];
218  }
219  return (sqrt(result));
220 }
void printDifferenceTable(double **differenceTable, int nNodes)
prints the difference table
void denormalizeMom(double *m, double M0, int nNodes)
de-normalizes the moments
void printMoms(const double *m, int nNodes)
prints moments
void enterMoments(double *mom, const int nNodes)
input the moments
bool momentsPositivite(const double *moments, int &nNodes)
void buildDifferenceTable(double **differenceTable, double *mom, int nNodes)
constructs the difference table
void enterWeightsNodes(double *we, double *vi, int nNodes)
inputs weights and nodes of quadrature
m
Bubble Growth Application Recipe.
Definition: bubbleGrowth.py:59
void initializeDifferenceTable(double **differenceTable, int nNodes)
initializes the difference table
void weightsNodesToMoms(double *mom, double *we, double *vi, int nNodes)
converts weights and nodes to moments
double vectorNorm(vector< double > const &v)
normalized vector used in McGraw correction algorithm
void normalizeMom(double *m, int nNodes)
normalizes the moments
int isRealizable(double **differenceTable, int nNodes)
checks if the moments are realizable