40 {
41
42 m = 0;
43
46 std::cerr << " Field map is not available for interpolation.\n";
47 status = -10;
48 return;
49 }
50
51 double x = xin, y = yin, z = zin;
52
53 bool xMirrored = false;
54 const double cellsx = xMaxBoundingBox - xMinBoundingBox;
56 x = xMinBoundingBox + fmod(x - xMinBoundingBox, cellsx);
57 if (x < xMinBoundingBox) x += cellsx;
59 double xNew = xMinBoundingBox + fmod(x - xMinBoundingBox, cellsx);
60 if (xNew < xMinBoundingBox) xNew += cellsx;
61 int nx = int(floor(0.5 + (xNew - x) / cellsx));
62 if (nx != 2 * (nx / 2)) {
63 xNew = xMinBoundingBox + xMaxBoundingBox - xNew;
64 xMirrored = true;
65 }
66 x = xNew;
67 }
68 bool yMirrored = false;
69 const double cellsy = yMaxBoundingBox - yMinBoundingBox;
71 y = yMinBoundingBox + fmod(y - yMinBoundingBox, cellsy);
72 if (y < yMinBoundingBox) y += cellsy;
74 double yNew = yMinBoundingBox + fmod(y - yMinBoundingBox, cellsy);
75 if (yNew < yMinBoundingBox) yNew += cellsy;
76 int ny = int(floor(0.5 + (yNew - y) / cellsy));
77 if (ny != 2 * (ny / 2)) {
78 yNew = yMinBoundingBox + yMaxBoundingBox - yNew;
79 yMirrored = true;
80 }
81 y = yNew;
82 }
83
84
85 if (x < xMinBoundingBox || x > xMaxBoundingBox || y < yMinBoundingBox ||
86 y > yMaxBoundingBox) {
87 status = -11;
88 return;
89 }
90 if (hasRangeZ) {
91 if (z < zMinBoundingBox || z > zMaxBoundingBox) {
92 status = -11;
93 return;
94 }
95 }
96
97
98 ex = ey = ez = p = 0.;
99
100 status = 0;
101
102 int i = lastElement;
103 switch (elements[i].type) {
104 case 1:
105 if (CheckLine(x, y, i)) {
106 ex = w[0] * vertices[elements[i].vertex[0]].ex +
107 w[1] * vertices[elements[i].vertex[1]].ex;
108 ey = w[0] * vertices[elements[i].vertex[0]].ey +
109 w[1] * vertices[elements[i].vertex[1]].ey;
110 p = w[0] * vertices[elements[i].vertex[0]].p +
111 w[1] * vertices[elements[i].vertex[1]].p;
112 if (xMirrored) ex = -ex;
113 if (yMirrored) ey = -ey;
114 m = regions[elements[i].region].medium;
115 if (!regions[elements[i].region].drift || m == 0) status = -5;
116 return;
117 }
118 break;
119 case 2:
120 if (CheckTriangle(x, y, i)) {
121 ex = w[0] * vertices[elements[i].vertex[0]].ex +
122 w[1] * vertices[elements[i].vertex[1]].ex +
123 w[2] * vertices[elements[i].vertex[2]].ex;
124 ey = w[0] * vertices[elements[i].vertex[0]].ey +
125 w[1] * vertices[elements[i].vertex[1]].ey +
126 w[2] * vertices[elements[i].vertex[2]].ey;
127 p = w[0] * vertices[elements[i].vertex[0]].p +
128 w[1] * vertices[elements[i].vertex[1]].p +
129 w[2] * vertices[elements[i].vertex[2]].p;
130 if (xMirrored) ex = -ex;
131 if (yMirrored) ey = -ey;
132 m = regions[elements[i].region].medium;
133 if (!regions[elements[i].region].drift || m == 0) status = -5;
134 return;
135 }
136 break;
137 case 3:
138 if (CheckRectangle(x, y, i)) {
139 ex = w[0] * vertices[elements[i].vertex[0]].ex +
140 w[1] * vertices[elements[i].vertex[1]].ex +
141 w[2] * vertices[elements[i].vertex[2]].ex +
142 w[3] * vertices[elements[i].vertex[3]].ex;
143 ey = w[0] * vertices[elements[i].vertex[0]].ey +
144 w[1] * vertices[elements[i].vertex[1]].ey +
145 w[2] * vertices[elements[i].vertex[2]].ey +
146 w[3] * vertices[elements[i].vertex[3]].ey;
147 p = w[0] * vertices[elements[i].vertex[0]].p +
148 w[1] * vertices[elements[i].vertex[1]].p +
149 w[2] * vertices[elements[i].vertex[2]].p +
150 w[3] * vertices[elements[i].vertex[3]].p;
151 if (xMirrored) ex = -ex;
152 if (yMirrored) ey = -ey;
153 m = regions[elements[i].region].medium;
154 if (!regions[elements[i].region].drift || m == 0) status = -5;
155 return;
156 }
157 break;
158 default:
160 std::cerr << " Unknown element type (" << elements[i].type << ").\n";
161 status = -11;
162 return;
163 break;
164 }
165
166
167
168 for (int j = elements[lastElement].nNeighbours; j--;) {
169 i = elements[lastElement].neighbours[j];
170 if (x < vertices[elements[i].vertex[0]].x) continue;
171 switch (elements[i].type) {
172 case 1:
173 if (CheckLine(x, y, i)) {
174 ex = w[0] * vertices[elements[i].vertex[0]].ex +
175 w[1] * vertices[elements[i].vertex[1]].ex;
176 ey = w[0] * vertices[elements[i].vertex[0]].ey +
177 w[1] * vertices[elements[i].vertex[1]].ey;
178 p = w[0] * vertices[elements[i].vertex[0]].p +
179 w[1] * vertices[elements[i].vertex[1]].p;
180 if (xMirrored) ex = -ex;
181 if (yMirrored) ey = -ey;
182 lastElement = i;
183 m = regions[elements[i].region].medium;
184 if (!regions[elements[i].region].drift || m == 0) status = -5;
185 return;
186 }
187 break;
188 case 2:
189 if (CheckTriangle(x, y, i)) {
190 ex = w[0] * vertices[elements[i].vertex[0]].ex +
191 w[1] * vertices[elements[i].vertex[1]].ex +
192 w[2] * vertices[elements[i].vertex[2]].ex;
193 ey = w[0] * vertices[elements[i].vertex[0]].ey +
194 w[1] * vertices[elements[i].vertex[1]].ey +
195 w[2] * vertices[elements[i].vertex[2]].ey;
196 p = w[0] * vertices[elements[i].vertex[0]].p +
197 w[1] * vertices[elements[i].vertex[1]].p +
198 w[2] * vertices[elements[i].vertex[2]].p;
199 if (xMirrored) ex = -ex;
200 if (yMirrored) ey = -ey;
201 lastElement = i;
202 m = regions[elements[i].region].medium;
203 if (!regions[elements[i].region].drift || m == 0) status = -5;
204 return;
205 }
206 break;
207 case 3:
208 if (CheckRectangle(x, y, i)) {
209 ex = w[0] * vertices[elements[i].vertex[0]].ex +
210 w[1] * vertices[elements[i].vertex[1]].ex +
211 w[2] * vertices[elements[i].vertex[2]].ex +
212 w[3] * vertices[elements[i].vertex[3]].ex;
213 ey = w[0] * vertices[elements[i].vertex[0]].ey +
214 w[1] * vertices[elements[i].vertex[1]].ey +
215 w[2] * vertices[elements[i].vertex[2]].ey +
216 w[3] * vertices[elements[i].vertex[3]].ey;
217 p = w[0] * vertices[elements[i].vertex[0]].p +
218 w[1] * vertices[elements[i].vertex[1]].p +
219 w[2] * vertices[elements[i].vertex[2]].p +
220 w[3] * vertices[elements[i].vertex[3]].p;
221 if (xMirrored) ex = -ex;
222 if (yMirrored) ey = -ey;
223 lastElement = i;
224 m = regions[elements[i].region].medium;
225 if (!regions[elements[i].region].drift || m == 0) status = -5;
226 return;
227 }
228 break;
229 default:
231 std::cerr << " Invalid element type (" << elements[i].type << ").\n";
232 status = -11;
233 return;
234 break;
235 }
236 }
237
238
239
240 for (i = nElements; i--;) {
241 if (x < vertices[elements[i].vertex[0]].x) continue;
242 switch (elements[i].type) {
243 case 1:
244 if (CheckLine(x, y, i)) {
245 ex = w[0] * vertices[elements[i].vertex[0]].ex +
246 w[1] * vertices[elements[i].vertex[1]].ex;
247 ey = w[0] * vertices[elements[i].vertex[0]].ey +
248 w[1] * vertices[elements[i].vertex[1]].ey;
249 p = w[0] * vertices[elements[i].vertex[0]].p +
250 w[1] * vertices[elements[i].vertex[1]].p;
251 if (xMirrored) ex = -ex;
252 if (yMirrored) ey = -ey;
253 lastElement = i;
254 m = regions[elements[i].region].medium;
255 if (!regions[elements[i].region].drift || m == 0) status = -5;
256 return;
257 }
258 break;
259 case 2:
260 if (CheckTriangle(x, y, i)) {
261 ex = w[0] * vertices[elements[i].vertex[0]].ex +
262 w[1] * vertices[elements[i].vertex[1]].ex +
263 w[2] * vertices[elements[i].vertex[2]].ex;
264 ey = w[0] * vertices[elements[i].vertex[0]].ey +
265 w[1] * vertices[elements[i].vertex[1]].ey +
266 w[2] * vertices[elements[i].vertex[2]].ey;
267 p = w[0] * vertices[elements[i].vertex[0]].p +
268 w[1] * vertices[elements[i].vertex[1]].p +
269 w[2] * vertices[elements[i].vertex[2]].p;
270 if (xMirrored) ex = -ex;
271 if (yMirrored) ey = -ey;
272 lastElement = i;
273 m = regions[elements[i].region].medium;
274 if (!regions[elements[i].region].drift || m == 0) status = -5;
275 return;
276 }
277 break;
278 case 3:
279 if (CheckRectangle(x, y, i)) {
280 ex = w[0] * vertices[elements[i].vertex[0]].ex +
281 w[1] * vertices[elements[i].vertex[1]].ex +
282 w[2] * vertices[elements[i].vertex[2]].ex +
283 w[3] * vertices[elements[i].vertex[3]].ex;
284 ey = w[0] * vertices[elements[i].vertex[0]].ey +
285 w[1] * vertices[elements[i].vertex[1]].ey +
286 w[2] * vertices[elements[i].vertex[2]].ey +
287 w[3] * vertices[elements[i].vertex[3]].ey;
288 p = w[0] * vertices[elements[i].vertex[0]].p +
289 w[1] * vertices[elements[i].vertex[1]].p +
290 w[2] * vertices[elements[i].vertex[2]].p +
291 w[3] * vertices[elements[i].vertex[3]].p;
292 if (xMirrored) ex = -ex;
293 if (yMirrored) ey = -ey;
294 lastElement = i;
295 m = regions[elements[i].region].medium;
296 if (!regions[elements[i].region].drift || m == 0) status = -5;
297 return;
298 }
299 break;
300 default:
302 std::cerr << " Invalid element type (" << elements[i].type << ").\n";
303 status = -11;
304 return;
305 break;
306 }
307 }
308
311 std::cerr << " Point (" << x << ", " << y << ") is outside the mesh.\n";
312 }
313 status = -6;
314 return;
315}