Log In | Get Help   
Home My Page Projects Code Snippets Project Openings Mareframe
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files
[mareframe] Annotation of /trunk/gadget/lengthgroup.cc
[mareframe] / trunk / gadget / lengthgroup.cc Repository:
ViewVC logotype

Annotation of /trunk/gadget/lengthgroup.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : agomez 1 #include "lengthgroup.h"
2 :     #include "errorhandler.h"
3 :     #include "gadget.h"
4 :     #include "global.h"
5 :     //Constructor for length division with even increments
6 :     LengthGroupDivision::LengthGroupDivision(double MinL, double MaxL, double DL) : error(0), Dl(DL) {
7 :     if ((MaxL < MinL) || (MinL < 0.0) || (Dl < verysmall)) {
8 :     error = 1;
9 :     return;
10 :     }
11 :    
12 :     int i;
13 :     minlen = MinL;
14 :     maxlen = MaxL;
15 :     double tmp = (maxlen - minlen) / Dl;
16 :     size = int(tmp + rathersmall);
17 :     if (size == 0) {
18 :     error = 1;
19 :     return;
20 :     }
21 :    
22 :     meanlength.resize(size, 0.0);
23 :     minlength.resize(size, 0.0);
24 :     for (i = 0; i < size; i++) {
25 :     minlength[i] = minlen + (Dl * i);
26 :     meanlength[i] = minlength[i] + (Dl * 0.5);
27 :     }
28 :     }
29 :    
30 :     //Constructor for length division with uneven increments
31 :     LengthGroupDivision::LengthGroupDivision(const DoubleVector& Breaks) : error(0), Dl(0.0) {
32 :     if ((Breaks.Size() < 2) || (Breaks[0] < 0.0)) {
33 :     error = 1;
34 :     return;
35 :     }
36 :    
37 :     int i;
38 :     size = Breaks.Size() - 1;
39 :     minlen = Breaks[0];
40 :     maxlen = Breaks[size];
41 :     Dl = Breaks[1] - Breaks[0];
42 :     meanlength.resize(size, 0.0);
43 :     minlength.resize(size, 0.0);
44 :    
45 :     for (i = 0; i < size; i++) {
46 :     //JMB first some error checks ...
47 :     if ((Breaks[i] > Breaks[i + 1]) || (isEqual(Breaks[i], Breaks[i + 1]))) {
48 :     error = 1;
49 :     return;
50 :     }
51 :     //... and check to see if the step lengths are actually equal
52 :     if (!isZero(Dl) && !isSmall(Breaks[i + 1] - Breaks[i] - Dl))
53 :     Dl = 0.0;
54 :     }
55 :    
56 :     //finally store the mean and minimum lengths for the length division
57 :     if (isZero(Dl)) {
58 :     for (i = 0; i < size; i++) {
59 :     minlength[i] = Breaks[i];
60 :     meanlength[i] = 0.5 * (Breaks[i] + Breaks[i + 1]);
61 :     }
62 :     } else {
63 :     for (i = 0; i < size; i++) {
64 :     minlength[i] = minlen + (Dl * i);
65 :     meanlength[i] = minlength[i] + (Dl * 0.5);
66 :     }
67 :     }
68 :     }
69 :    
70 :     LengthGroupDivision::LengthGroupDivision(const LengthGroupDivision& l)
71 :     : error(l.error), size(l.size), Dl(l.Dl), minlen(l.minlen), maxlen(l.maxlen),
72 :     meanlength(l.meanlength), minlength(l.minlength) {
73 :     }
74 :    
75 :     int LengthGroupDivision::numLengthGroup(double len) const {
76 :     //check if len equals the minimum length
77 :     if (isSmall(minlen - len))
78 :     return 0;
79 :    
80 :     //check if len equals the maximum length
81 :     if (isSmall(maxlen - len))
82 :     return size - 1;
83 :    
84 :     int i;
85 :     for (i = 0; i < size; i++)
86 :     if ((isSmall(minlength[i] - len)) || ((minlength[i] < len) && (len < this->maxLength(i))))
87 :     return i;
88 :    
89 :     //failed to find length group that matches len
90 :     return -1;
91 :     }
92 :    
93 :     double LengthGroupDivision::meanLength(int i) const {
94 :     if (i >= size)
95 :     return meanlength[size - 1];
96 :     return meanlength[i];
97 :     }
98 :    
99 :     double LengthGroupDivision::minLength(int i) const {
100 :     if (i >= size)
101 :     return minlength[size - 1];
102 :     return minlength[i];
103 :     }
104 :    
105 :     double LengthGroupDivision::maxLength(int i) const {
106 :     if (i >= (size - 1))
107 :     return maxlen;
108 :     return minlength[i + 1];
109 :     }
110 :    
111 :     int LengthGroupDivision::Combine(const LengthGroupDivision* const addition) {
112 :     if ((minlen > addition->minLength(addition->numLengthGroups() - 1))
113 :     || (this->minLength(size - 1) < addition->minLength()))
114 :     return 0;
115 :    
116 :     int i, j;
117 :     i = j = 0;
118 :     if (((minlen < addition->minLength()) || (isEqual(minlen, addition->minLength()))) &&
119 :     ((this->minLength(size - 1) > addition->minLength(addition->numLengthGroups() - 1)) ||
120 :     (isEqual(this->minLength(size - 1), addition->minLength(addition->numLengthGroups() - 1))))) {
121 :    
122 :     //only check if the divisions are the same in the overlapping region.
123 :     while (this->minLength(i) < addition->minLength())
124 :     i++;
125 :     for (j = 0; j < addition->numLengthGroups(); j++) {
126 :     if (!(isEqual(this->minLength(i + j), addition->minLength(j)))) {
127 :     error = 1;
128 :     return 0;
129 :     }
130 :     }
131 :     return 1;
132 :     }
133 :    
134 :     double tempmin = min(minlen, addition->minLength());
135 :     double tempmax = max(maxlen, addition->maxLength());
136 :     DoubleVector lower, middle;
137 :    
138 :     if ((minlen > addition->minLength()) || (isEqual(minlen, addition->minLength()))) {
139 :     for (; minlen > addition->minLength(i); i++) {
140 :     lower.resize(1, addition->minLength(i));
141 :     middle.resize(1, addition->meanLength(i));
142 :     }
143 :     for (; j - i < size && j < addition->numLengthGroups(); j++) {
144 :     if (!(isEqual(this->minLength(j - i), addition->minLength(j)))) {
145 :     error = 1;
146 :     return 0;
147 :     }
148 :     lower.resize(1, this->minLength(j - i));
149 :     middle.resize(1, this->meanLength(j - i));
150 :     }
151 :     if (j - i >= size) {
152 :     for (; j < addition->numLengthGroups(); j++) {
153 :     lower.resize(1, addition->minLength(j));
154 :     middle.resize(1, addition->meanLength(j));
155 :     }
156 :     } else {
157 :     for (; j - i < size; j++) {
158 :     lower.resize(1, this->minLength(j - i));
159 :     middle.resize(1, this->meanLength(j - i));
160 :     }
161 :     }
162 :    
163 :     } else {
164 :     for (; this->minLength(i) < addition->minLength(); i++) {
165 :     lower.resize(1, this->minLength(i));
166 :     middle.resize(1, this->meanLength(i));
167 :     }
168 :     for (j = 0; j < addition->numLengthGroups(); j++) {
169 :     lower.resize(1, addition->minLength(j));
170 :     middle.resize(1, addition->meanLength(j));
171 :     }
172 :     }
173 :    
174 :     //set this to the new division
175 :     if (!(isEqual(Dl, addition->dl())))
176 :     Dl = 0.0;
177 :     for (i = 0; i < size; i++) {
178 :     minlength[i] = lower[i];
179 :     meanlength[i] = middle[i];
180 :     }
181 :     size = lower.Size();
182 :     for (; i < size; i++) {
183 :     minlength.resize(1, lower[i]);
184 :     meanlength.resize(1, middle[i]);
185 :     }
186 :     minlen = tempmin;
187 :     maxlen = tempmax;
188 :     return 1;
189 :     }
190 :    
191 :     void LengthGroupDivision::Print(ofstream& outfile) const {
192 :     int i;
193 :     outfile << "Length group division with " << size << " length groups from " << minlen
194 :     << " up to " << maxlen << endl << TAB;
195 :     for (i = 0; i < size; i++)
196 :     outfile << minlength[i] << sep;
197 :     outfile << maxlen << endl;
198 :     }
199 :    
200 :     void LengthGroupDivision::printError() const {
201 :     handle.logMessage(LOGWARN, "Minimum length of length group division is", this->minLength());
202 :     handle.logMessage(LOGWARN, "Maximum length of length group division is", this->maxLength());
203 :     }
204 :    
205 :     int checkLengthGroupStructure(const LengthGroupDivision* finer,
206 :     const LengthGroupDivision* coarser) {
207 :    
208 :     int c, f;
209 :     double minlength, maxlength;
210 :    
211 :     //check to see if the intersection is empty
212 :     minlength = max(coarser->minLength(), finer->minLength());
213 :     maxlength = min(coarser->maxLength(), finer->maxLength());
214 :     if ((minlength > maxlength) || isSmall(maxlength - minlength)) {
215 :     handle.logMessage(LOGWARN, "Error when checking length structure - empty intersection");
216 :     finer->printError();
217 :     coarser->printError();
218 :     return 0;
219 :     }
220 :    
221 :     //if the length groups have the same dl then no need to check any further
222 :     if (isSmall(finer->dl() - coarser->dl()))
223 :     return 1;
224 :    
225 :     //now we need to check the length grouping for the intersection
226 :     for (f = finer->numLengthGroup(minlength); f < finer->numLengthGroup(maxlength); f++) {
227 :     c = coarser->numLengthGroup(finer->minLength(f));
228 :     if (c == -1) {
229 :     handle.logMessage(LOGWARN, "Error when checking length structure for the following lengthgroups");
230 :     finer->printError();
231 :     coarser->printError();
232 :     return 0;
233 :     }
234 :    
235 :     if ((coarser->minLength(c) > (finer->minLength(f) + rathersmall)) ||
236 :     (finer->maxLength(f) > (coarser->maxLength(c) + rathersmall))) {
237 :    
238 :     handle.logMessage(LOGWARN, "Error when checking length structure for length group", f);
239 :     finer->printError();
240 :     coarser->printError();
241 :     return 0;
242 :     }
243 :     }
244 :     return 1;
245 :     }

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge