/[escript]/branches/diaplayground/ripley/src/Brick.cpp
ViewVC logotype

Contents of /branches/diaplayground/ripley/src/Brick.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4949 - (show annotations)
Mon May 19 05:54:58 2014 UTC (4 years, 11 months ago) by caltinay
File size: 164569 byte(s)
Fast forward to current trunk rev 4947.
All tests that don't require a direct solver pass without MPI.

1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2014 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16
17 #include <limits>
18
19 #include <ripley/Brick.h>
20 #include <esysUtils/esysFileWriter.h>
21 #include <ripley/DefaultAssembler3D.h>
22 #include <ripley/WaveAssembler3D.h>
23 #include <ripley/LameAssembler3D.h>
24 #include <ripley/domainhelpers.h>
25 #include <boost/scoped_array.hpp>
26
27 #ifdef USE_NETCDF
28 #include <netcdfcpp.h>
29 #endif
30
31 #if USE_SILO
32 #include <silo.h>
33 #ifdef ESYS_MPI
34 #include <pmpio.h>
35 #endif
36 #endif
37
38 #include <iomanip>
39
40 #include "esysUtils/EsysRandom.h"
41 #include "blocktools.h"
42
43
44 using namespace std;
45 using esysUtils::FileWriter;
46
47 namespace ripley {
48
49 int indexOfMax(int a, int b, int c) {
50 if (a > b) {
51 if (c > a) {
52 return 2;
53 }
54 return 0;
55 } else if (b > c) {
56 return 1;
57 }
58 return 2;
59 }
60
61 Brick::Brick(int n0, int n1, int n2, double x0, double y0, double z0,
62 double x1, double y1, double z1, int d0, int d1, int d2,
63 const std::vector<double>& points, const std::vector<int>& tags,
64 const simap_t& tagnamestonums,
65 escript::SubWorld_ptr w) :
66 RipleyDomain(3, w)
67 {
68 if (static_cast<long>(n0 + 1) * static_cast<long>(n1 + 1)
69 * static_cast<long>(n2 + 1) > std::numeric_limits<int>::max())
70 throw RipleyException("The number of elements has overflowed, this "
71 "limit may be raised in future releases.");
72
73 if (n0 <= 0 || n1 <= 0 || n2 <= 0)
74 throw RipleyException("Number of elements in each spatial dimension "
75 "must be positive");
76
77 // ignore subdivision parameters for serial run
78 if (m_mpiInfo->size == 1) {
79 d0=1;
80 d1=1;
81 d2=1;
82 }
83 bool warn=false;
84
85 std::vector<int> factors;
86 int ranks = m_mpiInfo->size;
87 int epr[3] = {n0,n1,n2};
88 int d[3] = {d0,d1,d2};
89 if (d0<=0 || d1<=0 || d2<=0) {
90 for (int i = 0; i < 3; i++) {
91 if (d[i] < 1) {
92 d[i] = 1;
93 continue;
94 }
95 epr[i] = -1; // can no longer be max
96 if (ranks % d[i] != 0) {
97 throw RipleyException("Invalid number of spatial subdivisions");
98 }
99 //remove
100 ranks /= d[i];
101 }
102 factorise(factors, ranks);
103 if (factors.size() != 0) {
104 warn = true;
105 }
106 }
107 while (factors.size() > 0) {
108 int i = indexOfMax(epr[0],epr[1],epr[2]);
109 int f = factors.back();
110 factors.pop_back();
111 d[i] *= f;
112 epr[i] /= f;
113 }
114 d0 = d[0]; d1 = d[1]; d2 = d[2];
115
116 // ensure number of subdivisions is valid and nodes can be distributed
117 // among number of ranks
118 if (d0*d1*d2 != m_mpiInfo->size){
119 throw RipleyException("Invalid number of spatial subdivisions");
120 }
121 if (warn) {
122 cout << "Warning: Automatic domain subdivision (d0=" << d0 << ", d1="
123 << d1 << ", d2=" << d2 << "). This may not be optimal!" << endl;
124 }
125
126 double l0 = x1-x0;
127 double l1 = y1-y0;
128 double l2 = z1-z0;
129 m_dx[0] = l0/n0;
130 m_dx[1] = l1/n1;
131 m_dx[2] = l2/n2;
132
133 if ((n0+1)%d0 > 0) {
134 n0=(int)round((float)(n0+1)/d0+0.5)*d0-1;
135 l0=m_dx[0]*n0;
136 cout << "Warning: Adjusted number of elements and length. N0="
137 << n0 << ", l0=" << l0 << endl;
138 }
139 if ((n1+1)%d1 > 0) {
140 n1=(int)round((float)(n1+1)/d1+0.5)*d1-1;
141 l1=m_dx[1]*n1;
142 cout << "Warning: Adjusted number of elements and length. N1="
143 << n1 << ", l1=" << l1 << endl;
144 }
145 if ((n2+1)%d2 > 0) {
146 n2=(int)round((float)(n2+1)/d2+0.5)*d2-1;
147 l2=m_dx[2]*n2;
148 cout << "Warning: Adjusted number of elements and length. N2="
149 << n2 << ", l2=" << l2 << endl;
150 }
151
152 if ((d0 > 1 && (n0+1)/d0<2) || (d1 > 1 && (n1+1)/d1<2) || (d2 > 1 && (n2+1)/d2<2))
153 throw RipleyException("Too few elements for the number of ranks");
154
155 m_gNE[0] = n0;
156 m_gNE[1] = n1;
157 m_gNE[2] = n2;
158 m_origin[0] = x0;
159 m_origin[1] = y0;
160 m_origin[2] = z0;
161 m_length[0] = l0;
162 m_length[1] = l1;
163 m_length[2] = l2;
164 m_NX[0] = d0;
165 m_NX[1] = d1;
166 m_NX[2] = d2;
167
168 // local number of elements (including overlap)
169 m_NE[0] = m_ownNE[0] = (d0>1 ? (n0+1)/d0 : n0);
170 if (m_mpiInfo->rank%d0>0 && m_mpiInfo->rank%d0<d0-1)
171 m_NE[0]++;
172 else if (d0>1 && m_mpiInfo->rank%d0==d0-1)
173 m_ownNE[0]--;
174
175 m_NE[1] = m_ownNE[1] = (d1>1 ? (n1+1)/d1 : n1);
176 if (m_mpiInfo->rank%(d0*d1)/d0>0 && m_mpiInfo->rank%(d0*d1)/d0<d1-1)
177 m_NE[1]++;
178 else if (d1>1 && m_mpiInfo->rank%(d0*d1)/d0==d1-1)
179 m_ownNE[1]--;
180
181 m_NE[2] = m_ownNE[2] = (d2>1 ? (n2+1)/d2 : n2);
182 if (m_mpiInfo->rank/(d0*d1)>0 && m_mpiInfo->rank/(d0*d1)<d2-1)
183 m_NE[2]++;
184 else if (d2>1 && m_mpiInfo->rank/(d0*d1)==d2-1)
185 m_ownNE[2]--;
186
187 // local number of nodes
188 m_NN[0] = m_NE[0]+1;
189 m_NN[1] = m_NE[1]+1;
190 m_NN[2] = m_NE[2]+1;
191
192 // bottom-left-front node is at (offset0,offset1,offset2) in global mesh
193 m_offset[0] = (n0+1)/d0*(m_mpiInfo->rank%d0);
194 if (m_offset[0] > 0)
195 m_offset[0]--;
196 m_offset[1] = (n1+1)/d1*(m_mpiInfo->rank%(d0*d1)/d0);
197 if (m_offset[1] > 0)
198 m_offset[1]--;
199 m_offset[2] = (n2+1)/d2*(m_mpiInfo->rank/(d0*d1));
200 if (m_offset[2] > 0)
201 m_offset[2]--;
202
203 populateSampleIds();
204 createPattern();
205
206 for (map<string, int>::const_iterator i = tagnamestonums.begin();
207 i != tagnamestonums.end(); i++) {
208 setTagMap(i->first, i->second);
209 }
210 addPoints(tags.size(), &points[0], &tags[0]);
211 }
212
213
214 Brick::~Brick()
215 {
216 }
217
218 string Brick::getDescription() const
219 {
220 return "ripley::Brick";
221 }
222
223 bool Brick::operator==(const AbstractDomain& other) const
224 {
225 const Brick* o=dynamic_cast<const Brick*>(&other);
226 if (o) {
227 return (RipleyDomain::operator==(other) &&
228 m_gNE[0]==o->m_gNE[0] && m_gNE[1]==o->m_gNE[1] && m_gNE[2]==o->m_gNE[2]
229 && m_origin[0]==o->m_origin[0] && m_origin[1]==o->m_origin[1] && m_origin[2]==o->m_origin[2]
230 && m_length[0]==o->m_length[0] && m_length[1]==o->m_length[1] && m_length[2]==o->m_length[2]
231 && m_NX[0]==o->m_NX[0] && m_NX[1]==o->m_NX[1] && m_NX[2]==o->m_NX[2]);
232 }
233
234 return false;
235 }
236
237 void Brick::readNcGrid(escript::Data& out, string filename, string varname,
238 const ReaderParameters& params) const
239 {
240 #ifdef USE_NETCDF
241 // check destination function space
242 int myN0, myN1, myN2;
243 if (out.getFunctionSpace().getTypeCode() == Nodes) {
244 myN0 = m_NN[0];
245 myN1 = m_NN[1];
246 myN2 = m_NN[2];
247 } else if (out.getFunctionSpace().getTypeCode() == Elements ||
248 out.getFunctionSpace().getTypeCode() == ReducedElements) {
249 myN0 = m_NE[0];
250 myN1 = m_NE[1];
251 myN2 = m_NE[2];
252 } else
253 throw RipleyException("readNcGrid(): invalid function space for output data object");
254
255 if (params.first.size() != 3)
256 throw RipleyException("readNcGrid(): argument 'first' must have 3 entries");
257
258 if (params.numValues.size() != 3)
259 throw RipleyException("readNcGrid(): argument 'numValues' must have 3 entries");
260
261 if (params.multiplier.size() != 3)
262 throw RipleyException("readNcGrid(): argument 'multiplier' must have 3 entries");
263 for (size_t i=0; i<params.multiplier.size(); i++)
264 if (params.multiplier[i]<1)
265 throw RipleyException("readNcGrid(): all multipliers must be positive");
266
267 // check file existence and size
268 NcFile f(filename.c_str(), NcFile::ReadOnly);
269 if (!f.is_valid())
270 throw RipleyException("readNcGrid(): cannot open file");
271
272 NcVar* var = f.get_var(varname.c_str());
273 if (!var)
274 throw RipleyException("readNcGrid(): invalid variable name");
275
276 // TODO: rank>0 data support
277 const int numComp = out.getDataPointSize();
278 if (numComp > 1)
279 throw RipleyException("readNcGrid(): only scalar data supported");
280
281 const int dims = var->num_dims();
282 boost::scoped_array<long> edges(var->edges());
283
284 // is this a slice of the data object (dims!=3)?
285 // note the expected ordering of edges (as in numpy: z,y,x)
286 if ( (dims==3 && (params.numValues[2] > edges[0] ||
287 params.numValues[1] > edges[1] ||
288 params.numValues[0] > edges[2]))
289 || (dims==2 && params.numValues[2]>1)
290 || (dims==1 && (params.numValues[2]>1 || params.numValues[1]>1)) ) {
291 throw RipleyException("readNcGrid(): not enough data in file");
292 }
293
294 // check if this rank contributes anything
295 if (params.first[0] >= m_offset[0]+myN0 ||
296 params.first[0]+params.numValues[0]*params.multiplier[0] <= m_offset[0] ||
297 params.first[1] >= m_offset[1]+myN1 ||
298 params.first[1]+params.numValues[1]*params.multiplier[1] <= m_offset[1] ||
299 params.first[2] >= m_offset[2]+myN2 ||
300 params.first[2]+params.numValues[2]*params.multiplier[2] <= m_offset[2]) {
301 return;
302 }
303
304 // now determine how much this rank has to write
305
306 // first coordinates in data object to write to
307 const int first0 = max(0, params.first[0]-m_offset[0]);
308 const int first1 = max(0, params.first[1]-m_offset[1]);
309 const int first2 = max(0, params.first[2]-m_offset[2]);
310 // indices to first value in file (not accounting for reverse yet)
311 int idx0 = max(0, m_offset[0]-params.first[0]);
312 int idx1 = max(0, m_offset[1]-params.first[1]);
313 int idx2 = max(0, m_offset[2]-params.first[2]);
314 // number of values to read
315 const int num0 = min(params.numValues[0]-idx0, myN0-first0);
316 const int num1 = min(params.numValues[1]-idx1, myN1-first1);
317 const int num2 = min(params.numValues[2]-idx2, myN2-first2);
318
319 // make sure we read the right block if going backwards through file
320 if (params.reverse[0])
321 idx0 = edges[dims-1]-num0-idx0;
322 if (dims>1 && params.reverse[1])
323 idx1 = edges[dims-2]-num1-idx1;
324 if (dims>2 && params.reverse[2])
325 idx2 = edges[dims-3]-num2-idx2;
326
327
328 vector<double> values(num0*num1*num2);
329 if (dims==3) {
330 var->set_cur(idx2, idx1, idx0);
331 var->get(&values[0], num2, num1, num0);
332 } else if (dims==2) {
333 var->set_cur(idx1, idx0);
334 var->get(&values[0], num1, num0);
335 } else {
336 var->set_cur(idx0);
337 var->get(&values[0], num0);
338 }
339
340 const int dpp = out.getNumDataPointsPerSample();
341 out.requireWrite();
342
343 // helpers for reversing
344 const int x0 = (params.reverse[0] ? num0-1 : 0);
345 const int x_mult = (params.reverse[0] ? -1 : 1);
346 const int y0 = (params.reverse[1] ? num1-1 : 0);
347 const int y_mult = (params.reverse[1] ? -1 : 1);
348 const int z0 = (params.reverse[2] ? num2-1 : 0);
349 const int z_mult = (params.reverse[2] ? -1 : 1);
350
351 for (index_t z=0; z<num2; z++) {
352 for (index_t y=0; y<num1; y++) {
353 #pragma omp parallel for
354 for (index_t x=0; x<num0; x++) {
355 const int baseIndex = first0+x*params.multiplier[0]
356 +(first1+y*params.multiplier[1])*myN0
357 +(first2+z*params.multiplier[2])*myN0*myN1;
358 const int srcIndex=(z0+z_mult*z)*num1*num0
359 +(y0+y_mult*y)*num0
360 +(x0+x_mult*x);
361 if (!isnan(values[srcIndex])) {
362 for (index_t m2=0; m2<params.multiplier[2]; m2++) {
363 for (index_t m1=0; m1<params.multiplier[1]; m1++) {
364 for (index_t m0=0; m0<params.multiplier[0]; m0++) {
365 const int dataIndex = baseIndex+m0
366 +m1*myN0
367 +m2*myN0*myN1;
368 double* dest = out.getSampleDataRW(dataIndex);
369 for (index_t q=0; q<dpp; q++) {
370 *dest++ = values[srcIndex];
371 }
372 }
373 }
374 }
375 }
376 }
377 }
378 }
379 #else
380 throw RipleyException("readNcGrid(): not compiled with netCDF support");
381 #endif
382 }
383
384 #ifdef USE_BOOSTIO
385 void Brick::readBinaryGridFromZipped(escript::Data& out, string filename,
386 const ReaderParameters& params) const
387 {
388 // the mapping is not universally correct but should work on our
389 // supported platforms
390 switch (params.dataType) {
391 case DATATYPE_INT32:
392 readBinaryGridZippedImpl<int>(out, filename, params);
393 break;
394 case DATATYPE_FLOAT32:
395 readBinaryGridZippedImpl<float>(out, filename, params);
396 break;
397 case DATATYPE_FLOAT64:
398 readBinaryGridZippedImpl<double>(out, filename, params);
399 break;
400 default:
401 throw RipleyException("readBinaryGrid(): invalid or unsupported datatype");
402 }
403 }
404 #endif
405
406 void Brick::readBinaryGrid(escript::Data& out, string filename,
407 const ReaderParameters& params) const
408 {
409 // the mapping is not universally correct but should work on our
410 // supported platforms
411 switch (params.dataType) {
412 case DATATYPE_INT32:
413 readBinaryGridImpl<int>(out, filename, params);
414 break;
415 case DATATYPE_FLOAT32:
416 readBinaryGridImpl<float>(out, filename, params);
417 break;
418 case DATATYPE_FLOAT64:
419 readBinaryGridImpl<double>(out, filename, params);
420 break;
421 default:
422 throw RipleyException("readBinaryGrid(): invalid or unsupported datatype");
423 }
424 }
425
426 template<typename ValueType>
427 void Brick::readBinaryGridImpl(escript::Data& out, const string& filename,
428 const ReaderParameters& params) const
429 {
430 // check destination function space
431 int myN0, myN1, myN2;
432 if (out.getFunctionSpace().getTypeCode() == Nodes) {
433 myN0 = m_NN[0];
434 myN1 = m_NN[1];
435 myN2 = m_NN[2];
436 } else if (out.getFunctionSpace().getTypeCode() == Elements ||
437 out.getFunctionSpace().getTypeCode() == ReducedElements) {
438 myN0 = m_NE[0];
439 myN1 = m_NE[1];
440 myN2 = m_NE[2];
441 } else
442 throw RipleyException("readBinaryGrid(): invalid function space for output data object");
443
444 if (params.first.size() != 3)
445 throw RipleyException("readBinaryGrid(): argument 'first' must have 3 entries");
446
447 if (params.numValues.size() != 3)
448 throw RipleyException("readBinaryGrid(): argument 'numValues' must have 3 entries");
449
450 if (params.multiplier.size() != 3)
451 throw RipleyException("readBinaryGrid(): argument 'multiplier' must have 3 entries");
452 for (size_t i=0; i<params.multiplier.size(); i++)
453 if (params.multiplier[i]<1)
454 throw RipleyException("readBinaryGrid(): all multipliers must be positive");
455
456 // check file existence and size
457 ifstream f(filename.c_str(), ifstream::binary);
458 if (f.fail()) {
459 throw RipleyException("readBinaryGrid(): cannot open file");
460 }
461 f.seekg(0, ios::end);
462 const int numComp = out.getDataPointSize();
463 const int filesize = f.tellg();
464 const int reqsize = params.numValues[0]*params.numValues[1]*params.numValues[2]*numComp*sizeof(ValueType);
465 if (filesize < reqsize) {
466 f.close();
467 throw RipleyException("readBinaryGrid(): not enough data in file");
468 }
469
470 // check if this rank contributes anything
471 if (params.first[0] >= m_offset[0]+myN0 ||
472 params.first[0]+params.numValues[0]*params.multiplier[0] <= m_offset[0] ||
473 params.first[1] >= m_offset[1]+myN1 ||
474 params.first[1]+params.numValues[1]*params.multiplier[1] <= m_offset[1] ||
475 params.first[2] >= m_offset[2]+myN2 ||
476 params.first[2]+params.numValues[2]*params.multiplier[2] <= m_offset[2]) {
477 f.close();
478 return;
479 }
480
481 // now determine how much this rank has to write
482
483 // first coordinates in data object to write to
484 const int first0 = max(0, params.first[0]-m_offset[0]);
485 const int first1 = max(0, params.first[1]-m_offset[1]);
486 const int first2 = max(0, params.first[2]-m_offset[2]);
487 // indices to first value in file
488 const int idx0 = max(0, m_offset[0]-params.first[0]);
489 const int idx1 = max(0, m_offset[1]-params.first[1]);
490 const int idx2 = max(0, m_offset[2]-params.first[2]);
491 // number of values to read
492 const int num0 = min(params.numValues[0]-idx0, myN0-first0);
493 const int num1 = min(params.numValues[1]-idx1, myN1-first1);
494 const int num2 = min(params.numValues[2]-idx2, myN2-first2);
495
496 out.requireWrite();
497 vector<ValueType> values(num0*numComp);
498 const int dpp = out.getNumDataPointsPerSample();
499
500 for (int z=0; z<num2; z++) {
501 for (int y=0; y<num1; y++) {
502 const int fileofs = numComp*(idx0+(idx1+y)*params.numValues[0]
503 +(idx2+z)*params.numValues[0]*params.numValues[1]);
504 f.seekg(fileofs*sizeof(ValueType));
505 f.read((char*)&values[0], num0*numComp*sizeof(ValueType));
506
507 for (int x=0; x<num0; x++) {
508 const int baseIndex = first0+x*params.multiplier[0]
509 +(first1+y*params.multiplier[1])*myN0
510 +(first2+z*params.multiplier[2])*myN0*myN1;
511 for (int m2=0; m2<params.multiplier[2]; m2++) {
512 for (int m1=0; m1<params.multiplier[1]; m1++) {
513 for (int m0=0; m0<params.multiplier[0]; m0++) {
514 const int dataIndex = baseIndex+m0
515 +m1*myN0
516 +m2*myN0*myN1;
517 double* dest = out.getSampleDataRW(dataIndex);
518 for (int c=0; c<numComp; c++) {
519 ValueType val = values[x*numComp+c];
520
521 if (params.byteOrder != BYTEORDER_NATIVE) {
522 char* cval = reinterpret_cast<char*>(&val);
523 // this will alter val!!
524 byte_swap32(cval);
525 }
526 if (!std::isnan(val)) {
527 for (int q=0; q<dpp; q++) {
528 *dest++ = static_cast<double>(val);
529 }
530 }
531 }
532 }
533 }
534 }
535 }
536 }
537 }
538
539 f.close();
540 }
541
542 #ifdef USE_BOOSTIO
543 template<typename ValueType>
544 void Brick::readBinaryGridZippedImpl(escript::Data& out, const string& filename,
545 const ReaderParameters& params) const
546 {
547 // check destination function space
548 int myN0, myN1, myN2;
549 if (out.getFunctionSpace().getTypeCode() == Nodes) {
550 myN0 = m_NN[0];
551 myN1 = m_NN[1];
552 myN2 = m_NN[2];
553 } else if (out.getFunctionSpace().getTypeCode() == Elements ||
554 out.getFunctionSpace().getTypeCode() == ReducedElements) {
555 myN0 = m_NE[0];
556 myN1 = m_NE[1];
557 myN2 = m_NE[2];
558 } else
559 throw RipleyException("readBinaryGridFromZipped(): invalid function space for output data object");
560
561 if (params.first.size() != 3)
562 throw RipleyException("readBinaryGridFromZipped(): argument 'first' must have 3 entries");
563
564 if (params.numValues.size() != 3)
565 throw RipleyException("readBinaryGridFromZipped(): argument 'numValues' must have 3 entries");
566
567 if (params.multiplier.size() != 3)
568 throw RipleyException("readBinaryGridFromZipped(): argument 'multiplier' must have 3 entries");
569 for (size_t i=0; i<params.multiplier.size(); i++)
570 if (params.multiplier[i]<1)
571 throw RipleyException("readBinaryGridFromZipped(): all multipliers must be positive");
572
573 // check file existence and size
574 ifstream f(filename.c_str(), ifstream::binary);
575 if (f.fail()) {
576 throw RipleyException("readBinaryGridFromZipped(): cannot open file");
577 }
578 f.seekg(0, ios::end);
579 const int numComp = out.getDataPointSize();
580 int filesize = f.tellg();
581 f.seekg(0, ios::beg);
582 std::vector<char> compressed(filesize);
583 f.read((char*)&compressed[0], filesize);
584 f.close();
585 std::vector<char> decompressed = unzip(compressed);
586 filesize = decompressed.size();
587 const int reqsize = params.numValues[0]*params.numValues[1]*params.numValues[2]*numComp*sizeof(ValueType);
588 if (filesize < reqsize) {
589 throw RipleyException("readBinaryGridFromZipped(): not enough data in file");
590 }
591
592 // check if this rank contributes anything
593 if (params.first[0] >= m_offset[0]+myN0 ||
594 params.first[0]+params.numValues[0]*params.multiplier[0] <= m_offset[0] ||
595 params.first[1] >= m_offset[1]+myN1 ||
596 params.first[1]+params.numValues[1]*params.multiplier[1] <= m_offset[1] ||
597 params.first[2] >= m_offset[2]+myN2 ||
598 params.first[2]+params.numValues[2]*params.multiplier[2] <= m_offset[2]) {
599 return;
600 }
601
602 // now determine how much this rank has to write
603
604 // first coordinates in data object to write to
605 const int first0 = max(0, params.first[0]-m_offset[0]);
606 const int first1 = max(0, params.first[1]-m_offset[1]);
607 const int first2 = max(0, params.first[2]-m_offset[2]);
608 // indices to first value in file
609 const int idx0 = max(0, m_offset[0]-params.first[0]);
610 const int idx1 = max(0, m_offset[1]-params.first[1]);
611 const int idx2 = max(0, m_offset[2]-params.first[2]);
612 // number of values to read
613 const int num0 = min(params.numValues[0]-idx0, myN0-first0);
614 const int num1 = min(params.numValues[1]-idx1, myN1-first1);
615 const int num2 = min(params.numValues[2]-idx2, myN2-first2);
616
617 out.requireWrite();
618 vector<ValueType> values(num0*numComp);
619 const int dpp = out.getNumDataPointsPerSample();
620
621 for (int z=0; z<num2; z++) {
622 for (int y=0; y<num1; y++) {
623 const int fileofs = numComp*(idx0+(idx1+y)*params.numValues[0]
624 +(idx2+z)*params.numValues[0]*params.numValues[1]);
625 memcpy((char*)&values[0], (char*)&decompressed[fileofs*sizeof(ValueType)], num0*numComp*sizeof(ValueType));
626
627 for (int x=0; x<num0; x++) {
628 const int baseIndex = first0+x*params.multiplier[0]
629 +(first1+y*params.multiplier[1])*myN0
630 +(first2+z*params.multiplier[2])*myN0*myN1;
631 for (int m2=0; m2<params.multiplier[2]; m2++) {
632 for (int m1=0; m1<params.multiplier[1]; m1++) {
633 for (int m0=0; m0<params.multiplier[0]; m0++) {
634 const int dataIndex = baseIndex+m0
635 +m1*myN0
636 +m2*myN0*myN1;
637 double* dest = out.getSampleDataRW(dataIndex);
638 for (int c=0; c<numComp; c++) {
639 ValueType val = values[x*numComp+c];
640
641 if (params.byteOrder != BYTEORDER_NATIVE) {
642 char* cval = reinterpret_cast<char*>(&val);
643 // this will alter val!!
644 byte_swap32(cval);
645 }
646 if (!std::isnan(val)) {
647 for (int q=0; q<dpp; q++) {
648 *dest++ = static_cast<double>(val);
649 }
650 }
651 }
652 }
653 }
654 }
655 }
656 }
657 }
658 }
659 #endif
660
661 void Brick::writeBinaryGrid(const escript::Data& in, string filename,
662 int byteOrder, int dataType) const
663 {
664 // the mapping is not universally correct but should work on our
665 // supported platforms
666 switch (dataType) {
667 case DATATYPE_INT32:
668 writeBinaryGridImpl<int>(in, filename, byteOrder);
669 break;
670 case DATATYPE_FLOAT32:
671 writeBinaryGridImpl<float>(in, filename, byteOrder);
672 break;
673 case DATATYPE_FLOAT64:
674 writeBinaryGridImpl<double>(in, filename, byteOrder);
675 break;
676 default:
677 throw RipleyException("writeBinaryGrid(): invalid or unsupported datatype");
678 }
679 }
680
681 template<typename ValueType>
682 void Brick::writeBinaryGridImpl(const escript::Data& in,
683 const string& filename, int byteOrder) const
684 {
685 // check function space and determine number of points
686 int myN0, myN1, myN2;
687 int totalN0, totalN1, totalN2;
688 if (in.getFunctionSpace().getTypeCode() == Nodes) {
689 myN0 = m_NN[0];
690 myN1 = m_NN[1];
691 myN2 = m_NN[2];
692 totalN0 = m_gNE[0]+1;
693 totalN1 = m_gNE[1]+1;
694 totalN2 = m_gNE[2]+1;
695 } else if (in.getFunctionSpace().getTypeCode() == Elements ||
696 in.getFunctionSpace().getTypeCode() == ReducedElements) {
697 myN0 = m_NE[0];
698 myN1 = m_NE[1];
699 myN2 = m_NE[2];
700 totalN0 = m_gNE[0];
701 totalN1 = m_gNE[1];
702 totalN2 = m_gNE[2];
703 } else
704 throw RipleyException("writeBinaryGrid(): invalid function space of data object");
705
706 const int numComp = in.getDataPointSize();
707 const int dpp = in.getNumDataPointsPerSample();
708 const int fileSize = sizeof(ValueType)*numComp*dpp*totalN0*totalN1*totalN2;
709
710 if (numComp > 1 || dpp > 1)
711 throw RipleyException("writeBinaryGrid(): only scalar, single-value data supported");
712
713 // from here on we know that each sample consists of one value
714 FileWriter fw;
715 fw.openFile(filename, fileSize);
716 MPIBarrier();
717
718 for (index_t z=0; z<myN2; z++) {
719 for (index_t y=0; y<myN1; y++) {
720 const int fileofs = (m_offset[0]+(m_offset[1]+y)*totalN0
721 +(m_offset[2]+z)*totalN0*totalN1)*sizeof(ValueType);
722 ostringstream oss;
723
724 for (index_t x=0; x<myN0; x++) {
725 const double* sample = in.getSampleDataRO(z*myN0*myN1+y*myN0+x);
726 ValueType fvalue = static_cast<ValueType>(*sample);
727 if (byteOrder == BYTEORDER_NATIVE) {
728 oss.write((char*)&fvalue, sizeof(fvalue));
729 } else {
730 char* value = reinterpret_cast<char*>(&fvalue);
731 oss.write(byte_swap32(value), sizeof(fvalue));
732 }
733 }
734 fw.writeAt(oss, fileofs);
735 }
736 }
737 fw.close();
738 }
739
740 void Brick::dump(const string& fileName) const
741 {
742 #if USE_SILO
743 string fn(fileName);
744 if (fileName.length() < 6 || fileName.compare(fileName.length()-5, 5, ".silo") != 0) {
745 fn+=".silo";
746 }
747
748 int driver=DB_HDF5;
749 string siloPath;
750 DBfile* dbfile = NULL;
751
752 #ifdef ESYS_MPI
753 PMPIO_baton_t* baton = NULL;
754 const int NUM_SILO_FILES = 1;
755 const char* blockDirFmt = "/block%04d";
756 #endif
757
758 if (m_mpiInfo->size > 1) {
759 #ifdef ESYS_MPI
760 baton = PMPIO_Init(NUM_SILO_FILES, PMPIO_WRITE, m_mpiInfo->comm,
761 0x1337, PMPIO_DefaultCreate, PMPIO_DefaultOpen,
762 PMPIO_DefaultClose, (void*)&driver);
763 // try the fallback driver in case of error
764 if (!baton && driver != DB_PDB) {
765 driver = DB_PDB;
766 baton = PMPIO_Init(NUM_SILO_FILES, PMPIO_WRITE, m_mpiInfo->comm,
767 0x1338, PMPIO_DefaultCreate, PMPIO_DefaultOpen,
768 PMPIO_DefaultClose, (void*)&driver);
769 }
770 if (baton) {
771 char str[64];
772 snprintf(str, 64, blockDirFmt, PMPIO_RankInGroup(baton, m_mpiInfo->rank));
773 siloPath = str;
774 dbfile = (DBfile*) PMPIO_WaitForBaton(baton, fn.c_str(), siloPath.c_str());
775 }
776 #endif
777 } else {
778 dbfile = DBCreate(fn.c_str(), DB_CLOBBER, DB_LOCAL,
779 getDescription().c_str(), driver);
780 // try the fallback driver in case of error
781 if (!dbfile && driver != DB_PDB) {
782 driver = DB_PDB;
783 dbfile = DBCreate(fn.c_str(), DB_CLOBBER, DB_LOCAL,
784 getDescription().c_str(), driver);
785 }
786 }
787
788 if (!dbfile)
789 throw RipleyException("dump: Could not create Silo file");
790
791 /*
792 if (driver==DB_HDF5) {
793 // gzip level 1 already provides good compression with minimal
794 // performance penalty. Some tests showed that gzip levels >3 performed
795 // rather badly on escript data both in terms of time and space
796 DBSetCompression("ERRMODE=FALLBACK METHOD=GZIP LEVEL=1");
797 }
798 */
799
800 boost::scoped_ptr<double> x(new double[m_NN[0]]);
801 boost::scoped_ptr<double> y(new double[m_NN[1]]);
802 boost::scoped_ptr<double> z(new double[m_NN[2]]);
803 double* coords[3] = { x.get(), y.get(), z.get() };
804 #pragma omp parallel
805 {
806 #pragma omp for
807 for (dim_t i0 = 0; i0 < m_NN[0]; i0++) {
808 coords[0][i0]=getLocalCoordinate(i0, 0);
809 }
810 #pragma omp for
811 for (dim_t i1 = 0; i1 < m_NN[1]; i1++) {
812 coords[1][i1]=getLocalCoordinate(i1, 1);
813 }
814 #pragma omp for
815 for (dim_t i2 = 0; i2 < m_NN[2]; i2++) {
816 coords[2][i2]=getLocalCoordinate(i2, 2);
817 }
818 }
819 int* dims = const_cast<int*>(getNumNodesPerDim());
820
821 // write mesh
822 DBPutQuadmesh(dbfile, "mesh", NULL, coords, dims, 3, DB_DOUBLE,
823 DB_COLLINEAR, NULL);
824
825 // write node ids
826 DBPutQuadvar1(dbfile, "nodeId", "mesh", (void*)&m_nodeId[0], dims, 3,
827 NULL, 0, DB_INT, DB_NODECENT, NULL);
828
829 // write element ids
830 dims = const_cast<int*>(getNumElementsPerDim());
831 DBPutQuadvar1(dbfile, "elementId", "mesh", (void*)&m_elementId[0],
832 dims, 3, NULL, 0, DB_INT, DB_ZONECENT, NULL);
833
834 // rank 0 writes multimesh and multivar
835 if (m_mpiInfo->rank == 0) {
836 vector<string> tempstrings;
837 vector<char*> names;
838 for (dim_t i=0; i<m_mpiInfo->size; i++) {
839 stringstream path;
840 path << "/block" << setw(4) << setfill('0') << right << i << "/mesh";
841 tempstrings.push_back(path.str());
842 names.push_back((char*)tempstrings.back().c_str());
843 }
844 vector<int> types(m_mpiInfo->size, DB_QUAD_RECT);
845 DBSetDir(dbfile, "/");
846 DBPutMultimesh(dbfile, "multimesh", m_mpiInfo->size, &names[0],
847 &types[0], NULL);
848 tempstrings.clear();
849 names.clear();
850 for (dim_t i=0; i<m_mpiInfo->size; i++) {
851 stringstream path;
852 path << "/block" << setw(4) << setfill('0') << right << i << "/nodeId";
853 tempstrings.push_back(path.str());
854 names.push_back((char*)tempstrings.back().c_str());
855 }
856 types.assign(m_mpiInfo->size, DB_QUADVAR);
857 DBPutMultivar(dbfile, "nodeId", m_mpiInfo->size, &names[0],
858 &types[0], NULL);
859 tempstrings.clear();
860 names.clear();
861 for (dim_t i=0; i<m_mpiInfo->size; i++) {
862 stringstream path;
863 path << "/block" << setw(4) << setfill('0') << right << i << "/elementId";
864 tempstrings.push_back(path.str());
865 names.push_back((char*)tempstrings.back().c_str());
866 }
867 DBPutMultivar(dbfile, "elementId", m_mpiInfo->size, &names[0],
868 &types[0], NULL);
869 }
870
871 if (m_mpiInfo->size > 1) {
872 #ifdef ESYS_MPI
873 PMPIO_HandOffBaton(baton, dbfile);
874 PMPIO_Finish(baton);
875 #endif
876 } else {
877 DBClose(dbfile);
878 }
879
880 #else // USE_SILO
881 throw RipleyException("dump: no Silo support");
882 #endif
883 }
884
885 const int* Brick::borrowSampleReferenceIDs(int fsType) const
886 {
887 switch (fsType) {
888 case Nodes:
889 case ReducedNodes: //FIXME: reduced
890 return &m_nodeId[0];
891 case DegreesOfFreedom:
892 case ReducedDegreesOfFreedom: //FIXME: reduced
893 return &m_dofId[0];
894 case Elements:
895 case ReducedElements:
896 return &m_elementId[0];
897 case FaceElements:
898 case ReducedFaceElements:
899 return &m_faceId[0];
900 case Points:
901 return &m_diracPointNodeIDs[0];
902 default:
903 break;
904 }
905
906 stringstream msg;
907 msg << "borrowSampleReferenceIDs: invalid function space type "<<fsType;
908 throw RipleyException(msg.str());
909 }
910
911 bool Brick::ownSample(int fsType, index_t id) const
912 {
913 if (getMPISize()==1)
914 return true;
915
916 switch (fsType) {
917 case Nodes:
918 case ReducedNodes: //FIXME: reduced
919 return (m_dofMap[id] < getNumDOF());
920 case DegreesOfFreedom:
921 case ReducedDegreesOfFreedom:
922 return true;
923 case Elements:
924 case ReducedElements:
925 {
926 // check ownership of element's _last_ node
927 const index_t x=id%m_NE[0] + 1;
928 const index_t y=id%(m_NE[0]*m_NE[1])/m_NE[0] + 1;
929 const index_t z=id/(m_NE[0]*m_NE[1]) + 1;
930 return (m_dofMap[x + m_NN[0]*y + m_NN[0]*m_NN[1]*z] < getNumDOF());
931 }
932 case FaceElements:
933 case ReducedFaceElements:
934 {
935 // check ownership of face element's last node
936 dim_t n=0;
937 for (size_t i=0; i<6; i++) {
938 n+=m_faceCount[i];
939 if (id<n) {
940 const index_t j=id-n+m_faceCount[i];
941 if (i>=4) { // front or back
942 const index_t first=(i==4 ? 0 : m_NN[0]*m_NN[1]*(m_NN[2]-1));
943 return (m_dofMap[first+j%m_NE[0]+1+(j/m_NE[0]+1)*m_NN[0]] < getNumDOF());
944 } else if (i>=2) { // bottom or top
945 const index_t first=(i==2 ? 0 : m_NN[0]*(m_NN[1]-1));
946 return (m_dofMap[first+j%m_NE[0]+1+(j/m_NE[0]+1)*m_NN[0]*m_NN[1]] < getNumDOF());
947 } else { // left or right
948 const index_t first=(i==0 ? 0 : m_NN[0]-1);
949 return (m_dofMap[first+(j%m_NE[1]+1)*m_NN[0]+(j/m_NE[1]+1)*m_NN[0]*m_NN[1]] < getNumDOF());
950 }
951 }
952 }
953 return false;
954 }
955 default:
956 break;
957 }
958
959 stringstream msg;
960 msg << "ownSample: invalid function space type " << fsType;
961 throw RipleyException(msg.str());
962 }
963
964 void Brick::setToNormal(escript::Data& out) const
965 {
966 if (out.getFunctionSpace().getTypeCode() == FaceElements) {
967 out.requireWrite();
968 #pragma omp parallel
969 {
970 if (m_faceOffset[0] > -1) {
971 #pragma omp for nowait
972 for (index_t k2 = 0; k2 < m_NE[2]; ++k2) {
973 for (index_t k1 = 0; k1 < m_NE[1]; ++k1) {
974 double* o = out.getSampleDataRW(m_faceOffset[0]+INDEX2(k1,k2,m_NE[1]));
975 // set vector at four quadrature points
976 *o++ = -1.; *o++ = 0.; *o++ = 0.;
977 *o++ = -1.; *o++ = 0.; *o++ = 0.;
978 *o++ = -1.; *o++ = 0.; *o++ = 0.;
979 *o++ = -1.; *o++ = 0.; *o = 0.;
980 }
981 }
982 }
983
984 if (m_faceOffset[1] > -1) {
985 #pragma omp for nowait
986 for (index_t k2 = 0; k2 < m_NE[2]; ++k2) {
987 for (index_t k1 = 0; k1 < m_NE[1]; ++k1) {
988 double* o = out.getSampleDataRW(m_faceOffset[1]+INDEX2(k1,k2,m_NE[1]));
989 // set vector at four quadrature points
990 *o++ = 1.; *o++ = 0.; *o++ = 0.;
991 *o++ = 1.; *o++ = 0.; *o++ = 0.;
992 *o++ = 1.; *o++ = 0.; *o++ = 0.;
993 *o++ = 1.; *o++ = 0.; *o = 0.;
994 }
995 }
996 }
997
998 if (m_faceOffset[2] > -1) {
999 #pragma omp for nowait
1000 for (index_t k2 = 0; k2 < m_NE[2]; ++k2) {
1001 for (index_t k0 = 0; k0 < m_NE[0]; ++k0) {
1002 double* o = out.getSampleDataRW(m_faceOffset[2]+INDEX2(k0,k2,m_NE[0]));
1003 // set vector at four quadrature points
1004 *o++ = 0.; *o++ = -1.; *o++ = 0.;
1005 *o++ = 0.; *o++ = -1.; *o++ = 0.;
1006 *o++ = 0.; *o++ = -1.; *o++ = 0.;
1007 *o++ = 0.; *o++ = -1.; *o = 0.;
1008 }
1009 }
1010 }
1011
1012 if (m_faceOffset[3] > -1) {
1013 #pragma omp for nowait
1014 for (index_t k2 = 0; k2 < m_NE[2]; ++k2) {
1015 for (index_t k0 = 0; k0 < m_NE[0]; ++k0) {
1016 double* o = out.getSampleDataRW(m_faceOffset[3]+INDEX2(k0,k2,m_NE[0]));
1017 // set vector at four quadrature points
1018 *o++ = 0.; *o++ = 1.; *o++ = 0.;
1019 *o++ = 0.; *o++ = 1.; *o++ = 0.;
1020 *o++ = 0.; *o++ = 1.; *o++ = 0.;
1021 *o++ = 0.; *o++ = 1.; *o = 0.;
1022 }
1023 }
1024 }
1025
1026 if (m_faceOffset[4] > -1) {
1027 #pragma omp for nowait
1028 for (index_t k1 = 0; k1 < m_NE[1]; ++k1) {
1029 for (index_t k0 = 0; k0 < m_NE[0]; ++k0) {
1030 double* o = out.getSampleDataRW(m_faceOffset[4]+INDEX2(k0,k1,m_NE[0]));
1031 // set vector at four quadrature points
1032 *o++ = 0.; *o++ = 0.; *o++ = -1.;
1033 *o++ = 0.; *o++ = 0.; *o++ = -1.;
1034 *o++ = 0.; *o++ = 0.; *o++ = -1.;
1035 *o++ = 0.; *o++ = 0.; *o = -1.;
1036 }
1037 }
1038 }
1039
1040 if (m_faceOffset[5] > -1) {
1041 #pragma omp for nowait
1042 for (index_t k1 = 0; k1 < m_NE[1]; ++k1) {
1043 for (index_t k0 = 0; k0 < m_NE[0]; ++k0) {
1044 double* o = out.getSampleDataRW(m_faceOffset[5]+INDEX2(k0,k1,m_NE[0]));
1045 // set vector at four quadrature points
1046 *o++ = 0.; *o++ = 0.; *o++ = 1.;
1047 *o++ = 0.; *o++ = 0.; *o++ = 1.;
1048 *o++ = 0.; *o++ = 0.; *o++ = 1.;
1049 *o++ = 0.; *o++ = 0.; *o = 1.;
1050 }
1051 }
1052 }
1053 } // end of parallel section
1054 } else if (out.getFunctionSpace().getTypeCode() == ReducedFaceElements) {
1055 out.requireWrite();
1056 #pragma omp parallel
1057 {
1058 if (m_faceOffset[0] > -1) {
1059 #pragma omp for nowait
1060 for (index_t k2 = 0; k2 < m_NE[2]; ++k2) {
1061 for (index_t k1 = 0; k1 < m_NE[1]; ++k1) {
1062 double* o = out.getSampleDataRW(m_faceOffset[0]+INDEX2(k1,k2,m_NE[1]));
1063 *o++ = -1.;
1064 *o++ = 0.;
1065 *o = 0.;
1066 }
1067 }
1068 }
1069
1070 if (m_faceOffset[1] > -1) {
1071 #pragma omp for nowait
1072 for (index_t k2 = 0; k2 < m_NE[2]; ++k2) {
1073 for (index_t k1 = 0; k1 < m_NE[1]; ++k1) {
1074 double* o = out.getSampleDataRW(m_faceOffset[1]+INDEX2(k1,k2,m_NE[1]));
1075 *o++ = 1.;
1076 *o++ = 0.;
1077 *o = 0.;
1078 }
1079 }
1080 }
1081
1082 if (m_faceOffset[2] > -1) {
1083 #pragma omp for nowait
1084 for (index_t k2 = 0; k2 < m_NE[2]; ++k2) {
1085 for (index_t k0 = 0; k0 < m_NE[0]; ++k0) {
1086 double* o = out.getSampleDataRW(m_faceOffset[2]+INDEX2(k0,k2,m_NE[0]));
1087 *o++ = 0.;
1088 *o++ = -1.;
1089 *o = 0.;
1090 }
1091 }
1092 }
1093
1094 if (m_faceOffset[3] > -1) {
1095 #pragma omp for nowait
1096 for (index_t k2 = 0; k2 < m_NE[2]; ++k2) {
1097 for (index_t k0 = 0; k0 < m_NE[0]; ++k0) {
1098 double* o = out.getSampleDataRW(m_faceOffset[3]+INDEX2(k0,k2,m_NE[0]));
1099 *o++ = 0.;
1100 *o++ = 1.;
1101 *o = 0.;
1102 }
1103 }
1104 }
1105
1106 if (m_faceOffset[4] > -1) {
1107 #pragma omp for nowait
1108 for (index_t k1 = 0; k1 < m_NE[1]; ++k1) {
1109 for (index_t k0 = 0; k0 < m_NE[0]; ++k0) {
1110 double* o = out.getSampleDataRW(m_faceOffset[4]+INDEX2(k0,k1,m_NE[0]));
1111 *o++ = 0.;
1112 *o++ = 0.;
1113 *o = -1.;
1114 }
1115 }
1116 }
1117
1118 if (m_faceOffset[5] > -1) {
1119 #pragma omp for nowait
1120 for (index_t k1 = 0; k1 < m_NE[1]; ++k1) {
1121 for (index_t k0 = 0; k0 < m_NE[0]; ++k0) {
1122 double* o = out.getSampleDataRW(m_faceOffset[5]+INDEX2(k0,k1,m_NE[0]));
1123 *o++ = 0.;
1124 *o++ = 0.;
1125 *o = 1.;
1126 }
1127 }
1128 }
1129 } // end of parallel section
1130
1131 } else {
1132 stringstream msg;
1133 msg << "setToNormal: invalid function space type "
1134 << out.getFunctionSpace().getTypeCode();
1135 throw RipleyException(msg.str());
1136 }
1137 }
1138
1139 void Brick::setToSize(escript::Data& out) const
1140 {
1141 if (out.getFunctionSpace().getTypeCode() == Elements
1142 || out.getFunctionSpace().getTypeCode() == ReducedElements) {
1143 out.requireWrite();
1144 const dim_t numQuad=out.getNumDataPointsPerSample();
1145 const double size=sqrt(m_dx[0]*m_dx[0]+m_dx[1]*m_dx[1]+m_dx[2]*m_dx[2]);
1146 #pragma omp parallel for
1147 for (index_t k = 0; k < getNumElements(); ++k) {
1148 double* o = out.getSampleDataRW(k);
1149 fill(o, o+numQuad, size);
1150 }
1151 } else if (out.getFunctionSpace().getTypeCode() == FaceElements
1152 || out.getFunctionSpace().getTypeCode() == ReducedFaceElements) {
1153 out.requireWrite();
1154 const dim_t numQuad=out.getNumDataPointsPerSample();
1155 #pragma omp parallel
1156 {
1157 if (m_faceOffset[0] > -1) {
1158 const double size=min(m_dx[1],m_dx[2]);
1159 #pragma omp for nowait
1160 for (index_t k2 = 0; k2 < m_NE[2]; ++k2) {
1161 for (index_t k1 = 0; k1 < m_NE[1]; ++k1) {
1162 double* o = out.getSampleDataRW(m_faceOffset[0]+INDEX2(k1,k2,m_NE[1]));
1163 fill(o, o+numQuad, size);
1164 }
1165 }
1166 }
1167
1168 if (m_faceOffset[1] > -1) {
1169 const double size=min(m_dx[1],m_dx[2]);
1170 #pragma omp for nowait
1171 for (index_t k2 = 0; k2 < m_NE[2]; ++k2) {
1172 for (index_t k1 = 0; k1 < m_NE[1]; ++k1) {
1173 double* o = out.getSampleDataRW(m_faceOffset[1]+INDEX2(k1,k2,m_NE[1]));
1174 fill(o, o+numQuad, size);
1175 }
1176 }
1177 }
1178
1179 if (m_faceOffset[2] > -1) {
1180 const double size=min(m_dx[0],m_dx[2]);
1181 #pragma omp for nowait
1182 for (index_t k2 = 0; k2 < m_NE[2]; ++k2) {
1183 for (index_t k0 = 0; k0 < m_NE[0]; ++k0) {
1184 double* o = out.getSampleDataRW(m_faceOffset[2]+INDEX2(k0,k2,m_NE[0]));
1185 fill(o, o+numQuad, size);
1186 }
1187 }
1188 }
1189
1190 if (m_faceOffset[3] > -1) {
1191 const double size=min(m_dx[0],m_dx[2]);
1192 #pragma omp for nowait
1193 for (index_t k2 = 0; k2 < m_NE[2]; ++k2) {
1194 for (index_t k0 = 0; k0 < m_NE[0]; ++k0) {
1195 double* o = out.getSampleDataRW(m_faceOffset[3]+INDEX2(k0,k2,m_NE[0]));
1196 fill(o, o+numQuad, size);
1197 }
1198 }
1199 }
1200
1201 if (m_faceOffset[4] > -1) {
1202 const double size=min(m_dx[0],m_dx[1]);
1203 #pragma omp for nowait
1204 for (index_t k1 = 0; k1 < m_NE[1]; ++k1) {
1205 for (index_t k0 = 0; k0 < m_NE[0]; ++k0) {
1206 double* o = out.getSampleDataRW(m_faceOffset[4]+INDEX2(k0,k1,m_NE[0]));
1207 fill(o, o+numQuad, size);
1208 }
1209 }
1210 }
1211
1212 if (m_faceOffset[5] > -1) {
1213 const double size=min(m_dx[0],m_dx[1]);
1214 #pragma omp for nowait
1215 for (index_t k1 = 0; k1 < m_NE[1]; ++k1) {
1216 for (index_t k0 = 0; k0 < m_NE[0]; ++k0) {
1217 double* o = out.getSampleDataRW(m_faceOffset[5]+INDEX2(k0,k1,m_NE[0]));
1218 fill(o, o+numQuad, size);
1219 }
1220 }
1221 }
1222 } // end of parallel section
1223
1224 } else {
1225 stringstream msg;
1226 msg << "setToSize: invalid function space type "
1227 << out.getFunctionSpace().getTypeCode();
1228 throw RipleyException(msg.str());
1229 }
1230 }
1231
1232 void Brick::Print_Mesh_Info(const bool full) const
1233 {
1234 RipleyDomain::Print_Mesh_Info(full);
1235 if (full) {
1236 cout << " Id Coordinates" << endl;
1237 cout.precision(15);
1238 cout.setf(ios::scientific, ios::floatfield);
1239 for (index_t i=0; i < getNumNodes(); i++) {
1240 cout << " " << setw(5) << m_nodeId[i]
1241 << " " << getLocalCoordinate(i%m_NN[0], 0)
1242 << " " << getLocalCoordinate(i%(m_NN[0]*m_NN[1])/m_NN[0], 1)
1243 << " " << getLocalCoordinate(i/(m_NN[0]*m_NN[1]), 2) << endl;
1244 }
1245 }
1246 }
1247
1248
1249 //protected
1250 void Brick::assembleCoordinates(escript::Data& arg) const
1251 {
1252 escriptDataC x = arg.getDataC();
1253 int numDim = m_numDim;
1254 if (!isDataPointShapeEqual(&x, 1, &numDim))
1255 throw RipleyException("setToX: Invalid Data object shape");
1256 if (!numSamplesEqual(&x, 1, getNumNodes()))
1257 throw RipleyException("setToX: Illegal number of samples in Data object");
1258
1259 arg.requireWrite();
1260 #pragma omp parallel for
1261 for (dim_t i2 = 0; i2 < m_NN[2]; i2++) {
1262 for (dim_t i1 = 0; i1 < m_NN[1]; i1++) {
1263 for (dim_t i0 = 0; i0 < m_NN[0]; i0++) {
1264 double* point = arg.getSampleDataRW(i0+m_NN[0]*i1+m_NN[0]*m_NN[1]*i2);
1265 point[0] = getLocalCoordinate(i0, 0);
1266 point[1] = getLocalCoordinate(i1, 1);
1267 point[2] = getLocalCoordinate(i2, 2);
1268 }
1269 }
1270 }
1271 }
1272
1273 //protected
1274 void Brick::assembleGradient(escript::Data& out, const escript::Data& in) const
1275 {
1276 const dim_t numComp = in.getDataPointSize();
1277 const double C0 = .044658198738520451079;
1278 const double C1 = .16666666666666666667;
1279 const double C2 = .21132486540518711775;
1280 const double C3 = .25;
1281 const double C4 = .5;
1282 const double C5 = .62200846792814621559;
1283 const double C6 = .78867513459481288225;
1284
1285 if (out.getFunctionSpace().getTypeCode() == Elements) {
1286 out.requireWrite();
1287 #pragma omp parallel
1288 {
1289 vector<double> f_000(numComp);
1290 vector<double> f_001(numComp);
1291 vector<double> f_010(numComp);
1292 vector<double> f_011(numComp);
1293 vector<double> f_100(numComp);
1294 vector<double> f_101(numComp);
1295 vector<double> f_110(numComp);
1296 vector<double> f_111(numComp);
1297 #pragma omp for
1298 for (index_t k2=0; k2 < m_NE[2]; ++k2) {
1299 for (index_t k1=0; k1 < m_NE[1]; ++k1) {
1300 for (index_t k0=0; k0 < m_NE[0]; ++k0) {
1301 memcpy(&f_000[0], in.getSampleDataRO(INDEX3(k0,k1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1302 memcpy(&f_001[0], in.getSampleDataRO(INDEX3(k0,k1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1303 memcpy(&f_010[0], in.getSampleDataRO(INDEX3(k0,k1+1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1304 memcpy(&f_011[0], in.getSampleDataRO(INDEX3(k0,k1+1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1305 memcpy(&f_100[0], in.getSampleDataRO(INDEX3(k0+1,k1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1306 memcpy(&f_101[0], in.getSampleDataRO(INDEX3(k0+1,k1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1307 memcpy(&f_110[0], in.getSampleDataRO(INDEX3(k0+1,k1+1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1308 memcpy(&f_111[0], in.getSampleDataRO(INDEX3(k0+1,k1+1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1309 double* o = out.getSampleDataRW(INDEX3(k0,k1,k2,m_NE[0],m_NE[1]));
1310 for (index_t i=0; i < numComp; ++i) {
1311 const double V0=((f_100[i]-f_000[i])*C5 + (f_111[i]-f_011[i])*C0 + (f_101[i]+f_110[i]-f_001[i]-f_010[i])*C1) / m_dx[0];
1312 const double V1=((f_110[i]-f_010[i])*C5 + (f_101[i]-f_001[i])*C0 + (f_100[i]+f_111[i]-f_000[i]-f_011[i])*C1) / m_dx[0];
1313 const double V2=((f_101[i]-f_001[i])*C5 + (f_110[i]-f_010[i])*C0 + (f_100[i]+f_111[i]-f_000[i]-f_011[i])*C1) / m_dx[0];
1314 const double V3=((f_111[i]-f_011[i])*C5 + (f_100[i]-f_000[i])*C0 + (f_101[i]+f_110[i]-f_001[i]-f_010[i])*C1) / m_dx[0];
1315 const double V4=((f_010[i]-f_000[i])*C5 + (f_111[i]-f_101[i])*C0 + (f_011[i]+f_110[i]-f_001[i]-f_100[i])*C1) / m_dx[1];
1316 const double V5=((f_110[i]-f_100[i])*C5 + (f_011[i]-f_001[i])*C0 + (f_010[i]+f_111[i]-f_000[i]-f_101[i])*C1) / m_dx[1];
1317 const double V6=((f_011[i]-f_001[i])*C5 + (f_110[i]-f_100[i])*C0 + (f_010[i]+f_111[i]-f_000[i]-f_101[i])*C1) / m_dx[1];
1318 const double V7=((f_111[i]-f_101[i])*C5 + (f_010[i]-f_000[i])*C0 + (f_011[i]+f_110[i]-f_001[i]-f_100[i])*C1) / m_dx[1];
1319 const double V8=((f_001[i]-f_000[i])*C5 + (f_111[i]-f_110[i])*C0 + (f_011[i]+f_101[i]-f_010[i]-f_100[i])*C1) / m_dx[2];
1320 const double V9=((f_101[i]-f_100[i])*C5 + (f_011[i]-f_010[i])*C0 + (f_001[i]+f_111[i]-f_000[i]-f_110[i])*C1) / m_dx[2];
1321 const double V10=((f_011[i]-f_010[i])*C5 + (f_101[i]-f_100[i])*C0 + (f_001[i]+f_111[i]-f_000[i]-f_110[i])*C1) / m_dx[2];
1322 const double V11=((f_111[i]-f_110[i])*C5 + (f_001[i]-f_000[i])*C0 + (f_011[i]+f_101[i]-f_010[i]-f_100[i])*C1) / m_dx[2];
1323 o[INDEX3(i,0,0,numComp,3)] = V0;
1324 o[INDEX3(i,1,0,numComp,3)] = V4;
1325 o[INDEX3(i,2,0,numComp,3)] = V8;
1326 o[INDEX3(i,0,1,numComp,3)] = V0;
1327 o[INDEX3(i,1,1,numComp,3)] = V5;
1328 o[INDEX3(i,2,1,numComp,3)] = V9;
1329 o[INDEX3(i,0,2,numComp,3)] = V1;
1330 o[INDEX3(i,1,2,numComp,3)] = V4;
1331 o[INDEX3(i,2,2,numComp,3)] = V10;
1332 o[INDEX3(i,0,3,numComp,3)] = V1;
1333 o[INDEX3(i,1,3,numComp,3)] = V5;
1334 o[INDEX3(i,2,3,numComp,3)] = V11;
1335 o[INDEX3(i,0,4,numComp,3)] = V2;
1336 o[INDEX3(i,1,4,numComp,3)] = V6;
1337 o[INDEX3(i,2,4,numComp,3)] = V8;
1338 o[INDEX3(i,0,5,numComp,3)] = V2;
1339 o[INDEX3(i,1,5,numComp,3)] = V7;
1340 o[INDEX3(i,2,5,numComp,3)] = V9;
1341 o[INDEX3(i,0,6,numComp,3)] = V3;
1342 o[INDEX3(i,1,6,numComp,3)] = V6;
1343 o[INDEX3(i,2,6,numComp,3)] = V10;
1344 o[INDEX3(i,0,7,numComp,3)] = V3;
1345 o[INDEX3(i,1,7,numComp,3)] = V7;
1346 o[INDEX3(i,2,7,numComp,3)] = V11;
1347 } // end of component loop i
1348 } // end of k0 loop
1349 } // end of k1 loop
1350 } // end of k2 loop
1351 } // end of parallel section
1352 } else if (out.getFunctionSpace().getTypeCode() == ReducedElements) {
1353 out.requireWrite();
1354 #pragma omp parallel
1355 {
1356 vector<double> f_000(numComp);
1357 vector<double> f_001(numComp);
1358 vector<double> f_010(numComp);
1359 vector<double> f_011(numComp);
1360 vector<double> f_100(numComp);
1361 vector<double> f_101(numComp);
1362 vector<double> f_110(numComp);
1363 vector<double> f_111(numComp);
1364 #pragma omp for
1365 for (index_t k2=0; k2 < m_NE[2]; ++k2) {
1366 for (index_t k1=0; k1 < m_NE[1]; ++k1) {
1367 for (index_t k0=0; k0 < m_NE[0]; ++k0) {
1368 memcpy(&f_000[0], in.getSampleDataRO(INDEX3(k0,k1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1369 memcpy(&f_001[0], in.getSampleDataRO(INDEX3(k0,k1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1370 memcpy(&f_010[0], in.getSampleDataRO(INDEX3(k0,k1+1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1371 memcpy(&f_011[0], in.getSampleDataRO(INDEX3(k0,k1+1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1372 memcpy(&f_100[0], in.getSampleDataRO(INDEX3(k0+1,k1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1373 memcpy(&f_101[0], in.getSampleDataRO(INDEX3(k0+1,k1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1374 memcpy(&f_110[0], in.getSampleDataRO(INDEX3(k0+1,k1+1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1375 memcpy(&f_111[0], in.getSampleDataRO(INDEX3(k0+1,k1+1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1376 double* o = out.getSampleDataRW(INDEX3(k0,k1,k2,m_NE[0],m_NE[1]));
1377 for (index_t i=0; i < numComp; ++i) {
1378 o[INDEX3(i,0,0,numComp,3)] = (f_100[i]+f_101[i]+f_110[i]+f_111[i]-f_000[i]-f_001[i]-f_010[i]-f_011[i])*C3 / m_dx[0];
1379 o[INDEX3(i,1,0,numComp,3)] = (f_010[i]+f_011[i]+f_110[i]+f_111[i]-f_000[i]-f_001[i]-f_100[i]-f_101[i])*C3 / m_dx[1];
1380 o[INDEX3(i,2,0,numComp,3)] = (f_001[i]+f_011[i]+f_101[i]+f_111[i]-f_000[i]-f_010[i]-f_100[i]-f_110[i])*C3 / m_dx[2];
1381 } // end of component loop i
1382 } // end of k0 loop
1383 } // end of k1 loop
1384 } // end of k2 loop
1385 } // end of parallel section
1386 } else if (out.getFunctionSpace().getTypeCode() == FaceElements) {
1387 out.requireWrite();
1388 #pragma omp parallel
1389 {
1390 vector<double> f_000(numComp);
1391 vector<double> f_001(numComp);
1392 vector<double> f_010(numComp);
1393 vector<double> f_011(numComp);
1394 vector<double> f_100(numComp);
1395 vector<double> f_101(numComp);
1396 vector<double> f_110(numComp);
1397 vector<double> f_111(numComp);
1398 if (m_faceOffset[0] > -1) {
1399 #pragma omp for nowait
1400 for (index_t k2=0; k2 < m_NE[2]; ++k2) {
1401 for (index_t k1=0; k1 < m_NE[1]; ++k1) {
1402 memcpy(&f_000[0], in.getSampleDataRO(INDEX3(0,k1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1403 memcpy(&f_001[0], in.getSampleDataRO(INDEX3(0,k1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1404 memcpy(&f_010[0], in.getSampleDataRO(INDEX3(0,k1+1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1405 memcpy(&f_011[0], in.getSampleDataRO(INDEX3(0,k1+1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1406 memcpy(&f_100[0], in.getSampleDataRO(INDEX3(1,k1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1407 memcpy(&f_101[0], in.getSampleDataRO(INDEX3(1,k1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1408 memcpy(&f_110[0], in.getSampleDataRO(INDEX3(1,k1+1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1409 memcpy(&f_111[0], in.getSampleDataRO(INDEX3(1,k1+1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1410 double* o = out.getSampleDataRW(m_faceOffset[0]+INDEX2(k1,k2,m_NE[1]));
1411 for (index_t i=0; i < numComp; ++i) {
1412 const double V0=((f_010[i]-f_000[i])*C6 + (f_011[i]-f_001[i])*C2) / m_dx[1];
1413 const double V1=((f_010[i]-f_000[i])*C2 + (f_011[i]-f_001[i])*C6) / m_dx[1];
1414 const double V2=((f_001[i]-f_000[i])*C6 + (f_010[i]-f_011[i])*C2) / m_dx[2];
1415 const double V3=((f_001[i]-f_000[i])*C2 + (f_011[i]-f_010[i])*C6) / m_dx[2];
1416 o[INDEX3(i,0,0,numComp,3)] = ((f_100[i]-f_000[i])*C5 + (f_111[i]-f_011[i])*C0 + (f_101[i]+f_110[i]-f_001[i]-f_010[i])*C1) / m_dx[0];
1417 o[INDEX3(i,1,0,numComp,3)] = V0;
1418 o[INDEX3(i,2,0,numComp,3)] = V2;
1419 o[INDEX3(i,0,1,numComp,3)] = ((f_110[i]-f_010[i])*C5 + (f_101[i]-f_001[i])*C0 + (f_100[i]+f_111[i]-f_000[i]-f_011[i])*C1) / m_dx[0];
1420 o[INDEX3(i,1,1,numComp,3)] = V0;
1421 o[INDEX3(i,2,1,numComp,3)] = V3;
1422 o[INDEX3(i,0,2,numComp,3)] = ((f_101[i]-f_001[i])*C5 + (f_110[i]-f_010[i])*C0 + (f_100[i]+f_111[i]-f_000[i]-f_011[i])*C1) / m_dx[0];
1423 o[INDEX3(i,1,2,numComp,3)] = V1;
1424 o[INDEX3(i,2,2,numComp,3)] = V2;
1425 o[INDEX3(i,0,3,numComp,3)] = ((f_111[i]-f_011[i])*C5 + (f_100[i]-f_000[i])*C0 + (f_101[i]+f_110[i]-f_001[i]-f_010[i])*C1) / m_dx[0];
1426 o[INDEX3(i,1,3,numComp,3)] = V1;
1427 o[INDEX3(i,2,3,numComp,3)] = V3;
1428 } // end of component loop i
1429 } // end of k1 loop
1430 } // end of k2 loop
1431 } // end of face 0
1432 if (m_faceOffset[1] > -1) {
1433 #pragma omp for nowait
1434 for (index_t k2=0; k2 < m_NE[2]; ++k2) {
1435 for (index_t k1=0; k1 < m_NE[1]; ++k1) {
1436 memcpy(&f_000[0], in.getSampleDataRO(INDEX3(m_NN[0]-2,k1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1437 memcpy(&f_001[0], in.getSampleDataRO(INDEX3(m_NN[0]-2,k1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1438 memcpy(&f_010[0], in.getSampleDataRO(INDEX3(m_NN[0]-2,k1+1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1439 memcpy(&f_011[0], in.getSampleDataRO(INDEX3(m_NN[0]-2,k1+1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1440 memcpy(&f_100[0], in.getSampleDataRO(INDEX3(m_NN[0]-1,k1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1441 memcpy(&f_101[0], in.getSampleDataRO(INDEX3(m_NN[0]-1,k1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1442 memcpy(&f_110[0], in.getSampleDataRO(INDEX3(m_NN[0]-1,k1+1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1443 memcpy(&f_111[0], in.getSampleDataRO(INDEX3(m_NN[0]-1,k1+1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1444 double* o = out.getSampleDataRW(m_faceOffset[1]+INDEX2(k1,k2,m_NE[1]));
1445 for (index_t i=0; i < numComp; ++i) {
1446 const double V0=((f_110[i]-f_100[i])*C6 + (f_111[i]-f_101[i])*C2) / m_dx[1];
1447 const double V1=((f_110[i]-f_100[i])*C2 + (f_111[i]-f_101[i])*C6) / m_dx[1];
1448 const double V2=((f_101[i]-f_100[i])*C6 + (f_111[i]-f_110[i])*C2) / m_dx[2];
1449 const double V3=((f_101[i]-f_100[i])*C2 + (f_111[i]-f_110[i])*C6) / m_dx[2];
1450 o[INDEX3(i,0,0,numComp,3)] = ((f_100[i]-f_000[i])*C5 + (f_111[i]-f_011[i])*C0 + (f_101[i]+f_110[i]-f_001[i]-f_010[i])*C1) / m_dx[0];
1451 o[INDEX3(i,1,0,numComp,3)] = V0;
1452 o[INDEX3(i,2,0,numComp,3)] = V2;
1453 o[INDEX3(i,0,1,numComp,3)] = ((f_110[i]-f_010[i])*C5 + (f_101[i]-f_001[i])*C0 + (f_100[i]+f_111[i]-f_000[i]-f_011[i])*C1) / m_dx[0];
1454 o[INDEX3(i,1,1,numComp,3)] = V0;
1455 o[INDEX3(i,2,1,numComp,3)] = V3;
1456 o[INDEX3(i,0,2,numComp,3)] = ((f_101[i]-f_001[i])*C5 + (f_110[i]-f_010[i])*C0 + (f_100[i]+f_111[i]-f_000[i]-f_011[i])*C1) / m_dx[0];
1457 o[INDEX3(i,1,2,numComp,3)] = V1;
1458 o[INDEX3(i,2,2,numComp,3)] = V2;
1459 o[INDEX3(i,0,3,numComp,3)] = ((f_111[i]-f_011[i])*C5 + (f_100[i]-f_000[i])*C0 + (f_101[i]+f_110[i]-f_001[i]-f_010[i])*C1) / m_dx[0];
1460 o[INDEX3(i,1,3,numComp,3)] = V1;
1461 o[INDEX3(i,2,3,numComp,3)] = V3;
1462 } // end of component loop i
1463 } // end of k1 loop
1464 } // end of k2 loop
1465 } // end of face 1
1466 if (m_faceOffset[2] > -1) {
1467 #pragma omp for nowait
1468 for (index_t k2=0; k2 < m_NE[2]; ++k2) {
1469 for (index_t k0=0; k0 < m_NE[0]; ++k0) {
1470 memcpy(&f_000[0], in.getSampleDataRO(INDEX3(k0,0,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1471 memcpy(&f_001[0], in.getSampleDataRO(INDEX3(k0,0,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1472 memcpy(&f_010[0], in.getSampleDataRO(INDEX3(k0,1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1473 memcpy(&f_011[0], in.getSampleDataRO(INDEX3(k0,1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1474 memcpy(&f_100[0], in.getSampleDataRO(INDEX3(k0+1,0,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1475 memcpy(&f_101[0], in.getSampleDataRO(INDEX3(k0+1,0,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1476 memcpy(&f_110[0], in.getSampleDataRO(INDEX3(k0+1,1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1477 memcpy(&f_111[0], in.getSampleDataRO(INDEX3(k0+1,1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1478 double* o = out.getSampleDataRW(m_faceOffset[2]+INDEX2(k0,k2,m_NE[0]));
1479 for (index_t i=0; i < numComp; ++i) {
1480 const double V0=((f_100[i]-f_000[i])*C6 + (f_101[i]-f_001[i])*C2) / m_dx[0];
1481 const double V1=((f_001[i]-f_000[i])*C6 + (f_101[i]-f_100[i])*C2) / m_dx[2];
1482 const double V2=((f_001[i]-f_000[i])*C2 + (f_101[i]-f_100[i])*C6) / m_dx[2];
1483 o[INDEX3(i,0,0,numComp,3)] = V0;
1484 o[INDEX3(i,1,0,numComp,3)] = ((f_010[i]-f_000[i])*C5 + (f_111[i]-f_101[i])*C0 + (f_011[i]+f_110[i]-f_001[i]-f_100[i])*C1) / m_dx[1];
1485 o[INDEX3(i,2,0,numComp,3)] = V1;
1486 o[INDEX3(i,0,1,numComp,3)] = V0;
1487 o[INDEX3(i,1,1,numComp,3)] = ((f_110[i]-f_100[i])*C5 + (f_011[i]-f_001[i])*C0 + (f_010[i]+f_111[i]-f_000[i]-f_101[i])*C1) / m_dx[1];
1488 o[INDEX3(i,2,1,numComp,3)] = V2;
1489 o[INDEX3(i,0,2,numComp,3)] = V0;
1490 o[INDEX3(i,1,2,numComp,3)] = ((f_011[i]-f_001[i])*C5 + (f_110[i]-f_100[i])*C0 + (f_010[i]+f_111[i]-f_000[i]-f_101[i])*C1) / m_dx[1];
1491 o[INDEX3(i,2,2,numComp,3)] = V1;
1492 o[INDEX3(i,0,3,numComp,3)] = V0;
1493 o[INDEX3(i,1,3,numComp,3)] = ((f_111[i]-f_101[i])*C5 + (f_010[i]-f_000[i])*C0 + (f_011[i]+f_110[i]-f_001[i]-f_100[i])*C1) / m_dx[1];
1494 o[INDEX3(i,2,3,numComp,3)] = V2;
1495 } // end of component loop i
1496 } // end of k0 loop
1497 } // end of k2 loop
1498 } // end of face 2
1499 if (m_faceOffset[3] > -1) {
1500 #pragma omp for nowait
1501 for (index_t k2=0; k2 < m_NE[2]; ++k2) {
1502 for (index_t k0=0; k0 < m_NE[0]; ++k0) {
1503 memcpy(&f_000[0], in.getSampleDataRO(INDEX3(k0,m_NN[1]-2,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1504 memcpy(&f_001[0], in.getSampleDataRO(INDEX3(k0,m_NN[1]-2,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1505 memcpy(&f_010[0], in.getSampleDataRO(INDEX3(k0,m_NN[1]-1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1506 memcpy(&f_011[0], in.getSampleDataRO(INDEX3(k0,m_NN[1]-1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1507 memcpy(&f_100[0], in.getSampleDataRO(INDEX3(k0+1,m_NN[1]-2,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1508 memcpy(&f_101[0], in.getSampleDataRO(INDEX3(k0+1,m_NN[1]-2,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1509 memcpy(&f_110[0], in.getSampleDataRO(INDEX3(k0+1,m_NN[1]-1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1510 memcpy(&f_111[0], in.getSampleDataRO(INDEX3(k0+1,m_NN[1]-1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1511 double* o = out.getSampleDataRW(m_faceOffset[3]+INDEX2(k0,k2,m_NE[0]));
1512 for (index_t i=0; i < numComp; ++i) {
1513 const double V0=((f_110[i]-f_010[i])*C6 + (f_111[i]-f_011[i])*C2) / m_dx[0];
1514 const double V1=((f_110[i]-f_010[i])*C2 + (f_111[i]-f_011[i])*C6) / m_dx[0];
1515 const double V2=((f_011[i]-f_010[i])*C6 + (f_111[i]-f_110[i])*C2) / m_dx[2];
1516 const double V3=((f_011[i]-f_010[i])*C2 + (f_111[i]-f_110[i])*C6) / m_dx[2];
1517 o[INDEX3(i,0,0,numComp,3)] = V0;
1518 o[INDEX3(i,1,0,numComp,3)] = ((f_010[i]-f_000[i])*C5 + (f_111[i]-f_101[i])*C0 + (f_011[i]+f_110[i]-f_001[i]-f_100[i])*C1) / m_dx[1];
1519 o[INDEX3(i,2,0,numComp,3)] = V2;
1520 o[INDEX3(i,0,1,numComp,3)] = V0;
1521 o[INDEX3(i,1,1,numComp,3)] = ((f_110[i]-f_100[i])*C5 + (f_011[i]-f_001[i])*C0 + (f_010[i]+f_111[i]-f_000[i]-f_101[i])*C1) / m_dx[1];
1522 o[INDEX3(i,2,1,numComp,3)] = V3;
1523 o[INDEX3(i,0,2,numComp,3)] = V1;
1524 o[INDEX3(i,1,2,numComp,3)] = ((f_011[i]-f_001[i])*C5 + (f_110[i]-f_100[i])*C0 + (f_010[i]+f_111[i]-f_000[i]-f_101[i])*C1) / m_dx[1];
1525 o[INDEX3(i,2,2,numComp,3)] = V2;
1526 o[INDEX3(i,0,3,numComp,3)] = V1;
1527 o[INDEX3(i,1,3,numComp,3)] = ((f_111[i]-f_101[i])*C5 + (f_010[i]-f_000[i])*C0 + (f_011[i]+f_110[i]-f_001[i]-f_100[i])*C1) / m_dx[1];
1528 o[INDEX3(i,2,3,numComp,3)] = V3;
1529 } // end of component loop i
1530 } // end of k0 loop
1531 } // end of k2 loop
1532 } // end of face 3
1533 if (m_faceOffset[4] > -1) {
1534 #pragma omp for nowait
1535 for (index_t k1=0; k1 < m_NE[1]; ++k1) {
1536 for (index_t k0=0; k0 < m_NE[0]; ++k0) {
1537 memcpy(&f_000[0], in.getSampleDataRO(INDEX3(k0,k1,0, m_NN[0],m_NN[1])), numComp*sizeof(double));
1538 memcpy(&f_001[0], in.getSampleDataRO(INDEX3(k0,k1,1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1539 memcpy(&f_010[0], in.getSampleDataRO(INDEX3(k0,k1+1,0, m_NN[0],m_NN[1])), numComp*sizeof(double));
1540 memcpy(&f_011[0], in.getSampleDataRO(INDEX3(k0,k1+1,1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1541 memcpy(&f_100[0], in.getSampleDataRO(INDEX3(k0+1,k1,0, m_NN[0],m_NN[1])), numComp*sizeof(double));
1542 memcpy(&f_101[0], in.getSampleDataRO(INDEX3(k0+1,k1,1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1543 memcpy(&f_110[0], in.getSampleDataRO(INDEX3(k0+1,k1+1,0, m_NN[0],m_NN[1])), numComp*sizeof(double));
1544 memcpy(&f_111[0], in.getSampleDataRO(INDEX3(k0+1,k1+1,1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1545 double* o = out.getSampleDataRW(m_faceOffset[4]+INDEX2(k0,k1,m_NE[0]));
1546 for (index_t i=0; i < numComp; ++i) {
1547 const double V0=((f_100[i]-f_000[i])*C6 + (f_110[i]-f_010[i])*C2) / m_dx[0];
1548 const double V1=((f_100[i]-f_000[i])*C2 + (f_110[i]-f_010[i])*C6) / m_dx[0];
1549 const double V2=((f_010[i]-f_000[i])*C6 + (f_110[i]-f_100[i])*C2) / m_dx[1];
1550 const double V3=((f_010[i]-f_000[i])*C2 + (f_110[i]-f_100[i])*C6) / m_dx[1];
1551 o[INDEX3(i,0,0,numComp,3)] = V0;
1552 o[INDEX3(i,1,0,numComp,3)] = V2;
1553 o[INDEX3(i,2,0,numComp,3)] = ((f_001[i]-f_000[i])*C5 + (f_111[i]-f_110[i])*C0 + (f_011[i]+f_101[i]-f_010[i]-f_100[i])*C1) / m_dx[2];
1554 o[INDEX3(i,0,1,numComp,3)] = V0;
1555 o[INDEX3(i,1,1,numComp,3)] = V3;
1556 o[INDEX3(i,2,1,numComp,3)] = ((f_101[i]-f_100[i])*C5 + (f_011[i]-f_010[i])*C0 + (f_001[i]+f_111[i]-f_000[i]-f_110[i])*C1) / m_dx[2];
1557 o[INDEX3(i,0,2,numComp,3)] = V1;
1558 o[INDEX3(i,1,2,numComp,3)] = V2;
1559 o[INDEX3(i,2,2,numComp,3)] = ((f_011[i]-f_010[i])*C5 + (f_101[i]-f_100[i])*C0 + (f_001[i]+f_111[i]-f_000[i]-f_110[i])*C1) / m_dx[2];
1560 o[INDEX3(i,0,3,numComp,3)] = V1;
1561 o[INDEX3(i,1,3,numComp,3)] = V3;
1562 o[INDEX3(i,2,3,numComp,3)] = ((f_111[i]-f_110[i])*C5 + (f_001[i]-f_000[i])*C0 + (f_011[i]+f_101[i]-f_010[i]-f_100[i])*C1) / m_dx[2];
1563 } // end of component loop i
1564 } // end of k0 loop
1565 } // end of k1 loop
1566 } // end of face 4
1567 if (m_faceOffset[5] > -1) {
1568 #pragma omp for nowait
1569 for (index_t k1=0; k1 < m_NE[1]; ++k1) {
1570 for (index_t k0=0; k0 < m_NE[0]; ++k0) {
1571 memcpy(&f_000[0], in.getSampleDataRO(INDEX3(k0,k1,m_NN[2]-2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1572 memcpy(&f_001[0], in.getSampleDataRO(INDEX3(k0,k1,m_NN[2]-1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1573 memcpy(&f_010[0], in.getSampleDataRO(INDEX3(k0,k1+1,m_NN[2]-2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1574 memcpy(&f_011[0], in.getSampleDataRO(INDEX3(k0,k1+1,m_NN[2]-1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1575 memcpy(&f_100[0], in.getSampleDataRO(INDEX3(k0+1,k1,m_NN[2]-2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1576 memcpy(&f_101[0], in.getSampleDataRO(INDEX3(k0+1,k1,m_NN[2]-1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1577 memcpy(&f_110[0], in.getSampleDataRO(INDEX3(k0+1,k1+1,m_NN[2]-2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1578 memcpy(&f_111[0], in.getSampleDataRO(INDEX3(k0+1,k1+1,m_NN[2]-1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1579 double* o = out.getSampleDataRW(m_faceOffset[5]+INDEX2(k0,k1,m_NE[0]));
1580 for (index_t i=0; i < numComp; ++i) {
1581 const double V0=((f_101[i]-f_001[i])*C6 + (f_111[i]-f_011[i])*C2) / m_dx[0];
1582 const double V1=((f_101[i]-f_001[i])*C2 + (f_111[i]-f_011[i])*C6) / m_dx[0];
1583 const double V2=((f_011[i]-f_001[i])*C6 + (f_111[i]-f_101[i])*C2) / m_dx[1];
1584 const double V3=((f_011[i]-f_001[i])*C2 + (f_111[i]-f_101[i])*C6) / m_dx[1];
1585 o[INDEX3(i,0,0,numComp,3)] = V0;
1586 o[INDEX3(i,1,0,numComp,3)] = V2;
1587 o[INDEX3(i,2,0,numComp,3)] = ((f_001[i]-f_000[i])*C5 + (f_111[i]-f_110[i])*C0 + (f_011[i]+f_101[i]-f_010[i]-f_100[i])*C1) / m_dx[2];
1588 o[INDEX3(i,0,1,numComp,3)] = V0;
1589 o[INDEX3(i,1,1,numComp,3)] = V3;
1590 o[INDEX3(i,2,1,numComp,3)] = ((f_011[i]-f_010[i])*C0 + (f_101[i]-f_100[i])*C5 + (f_001[i]+f_111[i]-f_000[i]-f_110[i])*C1) / m_dx[2];
1591 o[INDEX3(i,0,2,numComp,3)] = V1;
1592 o[INDEX3(i,1,2,numComp,3)] = V2;
1593 o[INDEX3(i,2,2,numComp,3)] = ((f_011[i]-f_010[i])*C5 + (f_101[i]-f_100[i])*C0 + (f_001[i]+f_111[i]-f_000[i]-f_110[i])*C1) / m_dx[2];
1594 o[INDEX3(i,0,3,numComp,3)] = V1;
1595 o[INDEX3(i,1,3,numComp,3)] = V3;
1596 o[INDEX3(i,2,3,numComp,3)] = ((f_001[i]-f_000[i])*C0 + (f_111[i]-f_110[i])*C5 + (f_011[i]+f_101[i]-f_010[i]-f_100[i])*C1) / m_dx[2];
1597 } // end of component loop i
1598 } // end of k0 loop
1599 } // end of k1 loop
1600 } // end of face 5
1601 } // end of parallel section
1602 } else if (out.getFunctionSpace().getTypeCode() == ReducedFaceElements) {
1603 out.requireWrite();
1604 #pragma omp parallel
1605 {
1606 vector<double> f_000(numComp);
1607 vector<double> f_001(numComp);
1608 vector<double> f_010(numComp);
1609 vector<double> f_011(numComp);
1610 vector<double> f_100(numComp);
1611 vector<double> f_101(numComp);
1612 vector<double> f_110(numComp);
1613 vector<double> f_111(numComp);
1614 if (m_faceOffset[0] > -1) {
1615 #pragma omp for nowait
1616 for (index_t k2=0; k2 < m_NE[2]; ++k2) {
1617 for (index_t k1=0; k1 < m_NE[1]; ++k1) {
1618 memcpy(&f_000[0], in.getSampleDataRO(INDEX3(0,k1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1619 memcpy(&f_001[0], in.getSampleDataRO(INDEX3(0,k1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1620 memcpy(&f_010[0], in.getSampleDataRO(INDEX3(0,k1+1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1621 memcpy(&f_011[0], in.getSampleDataRO(INDEX3(0,k1+1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1622 memcpy(&f_100[0], in.getSampleDataRO(INDEX3(1,k1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1623 memcpy(&f_101[0], in.getSampleDataRO(INDEX3(1,k1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1624 memcpy(&f_110[0], in.getSampleDataRO(INDEX3(1,k1+1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1625 memcpy(&f_111[0], in.getSampleDataRO(INDEX3(1,k1+1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1626 double* o = out.getSampleDataRW(m_faceOffset[0]+INDEX2(k1,k2,m_NE[1]));
1627 for (index_t i=0; i < numComp; ++i) {
1628 o[INDEX3(i,0,0,numComp,3)] = (f_100[i]+f_101[i]+f_110[i]+f_111[i]-f_000[i]-f_001[i]-f_010[i]-f_011[i])*C3 / m_dx[0];
1629 o[INDEX3(i,1,0,numComp,3)] = (f_010[i]+f_011[i]-f_000[i]-f_001[i])*C4 / m_dx[1];
1630 o[INDEX3(i,2,0,numComp,3)] = (f_001[i]+f_011[i]-f_000[i]-f_010[i])*C4 / m_dx[2];
1631 } // end of component loop i
1632 } // end of k1 loop
1633 } // end of k2 loop
1634 } // end of face 0
1635 if (m_faceOffset[1] > -1) {
1636 #pragma omp for nowait
1637 for (index_t k2=0; k2 < m_NE[2]; ++k2) {
1638 for (index_t k1=0; k1 < m_NE[1]; ++k1) {
1639 memcpy(&f_000[0], in.getSampleDataRO(INDEX3(m_NN[0]-2,k1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1640 memcpy(&f_001[0], in.getSampleDataRO(INDEX3(m_NN[0]-2,k1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1641 memcpy(&f_010[0], in.getSampleDataRO(INDEX3(m_NN[0]-2,k1+1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1642 memcpy(&f_011[0], in.getSampleDataRO(INDEX3(m_NN[0]-2,k1+1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1643 memcpy(&f_100[0], in.getSampleDataRO(INDEX3(m_NN[0]-1,k1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1644 memcpy(&f_101[0], in.getSampleDataRO(INDEX3(m_NN[0]-1,k1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1645 memcpy(&f_110[0], in.getSampleDataRO(INDEX3(m_NN[0]-1,k1+1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1646 memcpy(&f_111[0], in.getSampleDataRO(INDEX3(m_NN[0]-1,k1+1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1647 double* o = out.getSampleDataRW(m_faceOffset[1]+INDEX2(k1,k2,m_NE[1]));
1648 for (index_t i=0; i < numComp; ++i) {
1649 o[INDEX3(i,0,0,numComp,3)] = (f_100[i]+f_101[i]+f_110[i]+f_111[i]-f_000[i]-f_001[i]-f_010[i]-f_011[i])*C3 / m_dx[0];
1650 o[INDEX3(i,1,0,numComp,3)] = (f_110[i]+f_111[i]-f_100[i]-f_101[i])*C4 / m_dx[1];
1651 o[INDEX3(i,2,0,numComp,3)] = (f_101[i]+f_111[i]-f_100[i]-f_110[i])*C4 / m_dx[2];
1652 } // end of component loop i
1653 } // end of k1 loop
1654 } // end of k2 loop
1655 } // end of face 1
1656 if (m_faceOffset[2] > -1) {
1657 #pragma omp for nowait
1658 for (index_t k2=0; k2 < m_NE[2]; ++k2) {
1659 for (index_t k0=0; k0 < m_NE[0]; ++k0) {
1660 memcpy(&f_000[0], in.getSampleDataRO(INDEX3(k0,0,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1661 memcpy(&f_001[0], in.getSampleDataRO(INDEX3(k0,0,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1662 memcpy(&f_010[0], in.getSampleDataRO(INDEX3(k0,1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1663 memcpy(&f_011[0], in.getSampleDataRO(INDEX3(k0,1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1664 memcpy(&f_100[0], in.getSampleDataRO(INDEX3(k0+1,0,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1665 memcpy(&f_101[0], in.getSampleDataRO(INDEX3(k0+1,0,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1666 memcpy(&f_110[0], in.getSampleDataRO(INDEX3(k0+1,1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1667 memcpy(&f_111[0], in.getSampleDataRO(INDEX3(k0+1,1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1668 double* o = out.getSampleDataRW(m_faceOffset[2]+INDEX2(k0,k2,m_NE[0]));
1669 for (index_t i=0; i < numComp; ++i) {
1670 o[INDEX3(i,0,0,numComp,3)] = (f_100[i]+f_101[i]-f_000[i]-f_001[i])*C4 / m_dx[0];
1671 o[INDEX3(i,1,0,numComp,3)] = (f_010[i]+f_011[i]+f_110[i]+f_111[i]-f_000[i]-f_001[i]-f_100[i]-f_101[i])*C3 / m_dx[1];
1672 o[INDEX3(i,2,0,numComp,3)] = (f_001[i]+f_101[i]-f_000[i]-f_100[i])*C4 / m_dx[2];
1673 } // end of component loop i
1674 } // end of k0 loop
1675 } // end of k2 loop
1676 } // end of face 2
1677 if (m_faceOffset[3] > -1) {
1678 #pragma omp for nowait
1679 for (index_t k2=0; k2 < m_NE[2]; ++k2) {
1680 for (index_t k0=0; k0 < m_NE[0]; ++k0) {
1681 memcpy(&f_000[0], in.getSampleDataRO(INDEX3(k0,m_NN[1]-2,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1682 memcpy(&f_001[0], in.getSampleDataRO(INDEX3(k0,m_NN[1]-2,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1683 memcpy(&f_010[0], in.getSampleDataRO(INDEX3(k0,m_NN[1]-1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1684 memcpy(&f_011[0], in.getSampleDataRO(INDEX3(k0,m_NN[1]-1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1685 memcpy(&f_100[0], in.getSampleDataRO(INDEX3(k0+1,m_NN[1]-2,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1686 memcpy(&f_101[0], in.getSampleDataRO(INDEX3(k0+1,m_NN[1]-2,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1687 memcpy(&f_110[0], in.getSampleDataRO(INDEX3(k0+1,m_NN[1]-1,k2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1688 memcpy(&f_111[0], in.getSampleDataRO(INDEX3(k0+1,m_NN[1]-1,k2+1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1689 double* o = out.getSampleDataRW(m_faceOffset[3]+INDEX2(k0,k2,m_NE[0]));
1690 for (index_t i=0; i < numComp; ++i) {
1691 o[INDEX3(i,0,0,numComp,3)] = (f_110[i]+f_111[i]-f_010[i]-f_011[i])*C4 / m_dx[0];
1692 o[INDEX3(i,1,0,numComp,3)] = (f_010[i]+f_011[i]+f_110[i]+f_111[i]-f_000[i]-f_001[i]-f_100[i]-f_101[i])*C3 / m_dx[1];
1693 o[INDEX3(i,2,0,numComp,3)] = (f_011[i]+f_111[i]-f_010[i]-f_110[i])*C4 / m_dx[2];
1694 } // end of component loop i
1695 } // end of k0 loop
1696 } // end of k2 loop
1697 } // end of face 3
1698 if (m_faceOffset[4] > -1) {
1699 #pragma omp for nowait
1700 for (index_t k1=0; k1 < m_NE[1]; ++k1) {
1701 for (index_t k0=0; k0 < m_NE[0]; ++k0) {
1702 memcpy(&f_000[0], in.getSampleDataRO(INDEX3(k0,k1,0, m_NN[0],m_NN[1])), numComp*sizeof(double));
1703 memcpy(&f_001[0], in.getSampleDataRO(INDEX3(k0,k1,1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1704 memcpy(&f_010[0], in.getSampleDataRO(INDEX3(k0,k1+1,0, m_NN[0],m_NN[1])), numComp*sizeof(double));
1705 memcpy(&f_011[0], in.getSampleDataRO(INDEX3(k0,k1+1,1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1706 memcpy(&f_100[0], in.getSampleDataRO(INDEX3(k0+1,k1,0, m_NN[0],m_NN[1])), numComp*sizeof(double));
1707 memcpy(&f_101[0], in.getSampleDataRO(INDEX3(k0+1,k1,1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1708 memcpy(&f_110[0], in.getSampleDataRO(INDEX3(k0+1,k1+1,0, m_NN[0],m_NN[1])), numComp*sizeof(double));
1709 memcpy(&f_111[0], in.getSampleDataRO(INDEX3(k0+1,k1+1,1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1710 double* o = out.getSampleDataRW(m_faceOffset[4]+INDEX2(k0,k1,m_NE[0]));
1711 for (index_t i=0; i < numComp; ++i) {
1712 o[INDEX3(i,0,0,numComp,3)] = (f_100[i]+f_110[i]-f_000[i]-f_010[i])*C4 / m_dx[0];
1713 o[INDEX3(i,1,0,numComp,3)] = (f_010[i]+f_110[i]-f_000[i]-f_100[i])*C4 / m_dx[1];
1714 o[INDEX3(i,2,0,numComp,3)] = (f_001[i]+f_011[i]+f_101[i]+f_111[i]-f_000[i]-f_010[i]-f_100[i]-f_110[i])*C4 / m_dx[2];
1715 } // end of component loop i
1716 } // end of k0 loop
1717 } // end of k1 loop
1718 } // end of face 4
1719 if (m_faceOffset[5] > -1) {
1720 #pragma omp for nowait
1721 for (index_t k1=0; k1 < m_NE[1]; ++k1) {
1722 for (index_t k0=0; k0 < m_NE[0]; ++k0) {
1723 memcpy(&f_000[0], in.getSampleDataRO(INDEX3(k0,k1,m_NN[2]-2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1724 memcpy(&f_001[0], in.getSampleDataRO(INDEX3(k0,k1,m_NN[2]-1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1725 memcpy(&f_010[0], in.getSampleDataRO(INDEX3(k0,k1+1,m_NN[2]-2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1726 memcpy(&f_011[0], in.getSampleDataRO(INDEX3(k0,k1+1,m_NN[2]-1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1727 memcpy(&f_100[0], in.getSampleDataRO(INDEX3(k0+1,k1,m_NN[2]-2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1728 memcpy(&f_101[0], in.getSampleDataRO(INDEX3(k0+1,k1,m_NN[2]-1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1729 memcpy(&f_110[0], in.getSampleDataRO(INDEX3(k0+1,k1+1,m_NN[2]-2, m_NN[0],m_NN[1])), numComp*sizeof(double));
1730 memcpy(&f_111[0], in.getSampleDataRO(INDEX3(k0+1,k1+1,m_NN[2]-1, m_NN[0],m_NN[1])), numComp*sizeof(double));
1731 double* o = out.getSampleDataRW(m_faceOffset[5]+INDEX2(k0,k1,m_NE[0]));
1732 for (index_t i=0; i < numComp; ++i) {
1733 o[INDEX3(i,0,0,numComp,3)] = (f_101[i]+f_111[i]-f_001[i]-f_011[i])*C4 / m_dx[0];
1734 o[INDEX3(i,1,0,numComp,3)] = (f_011[i]+f_111[i]-f_001[i]-f_101[i])*C4 / m_dx[1];
1735 o[INDEX3(i,2,0,numComp,3)] = (f_001[i]+f_011[i]+f_101[i]+f_111[i]-f_000[i]-f_010[i]-f_100[i]-f_110[i])*C3 / m_dx[2];
1736 } // end of component loop i
1737 } // end of k0 loop
1738 } // end of k1 loop
1739 } // end of face 5
1740 } // end of parallel section
1741 }
1742 }
1743
1744 //protected
1745 void Brick::assembleIntegrate(vector<double>& integrals, const escript::Data& arg) const
1746 {
1747 const dim_t numComp = arg.getDataPointSize();
1748 const index_t left = (m_offset[0]==0 ? 0 : 1);
1749 const index_t bottom = (m_offset[1]==0 ? 0 : 1);
1750 const index_t front = (m_offset[2]==0 ? 0 : 1);
1751 const int fs = arg.getFunctionSpace().getTypeCode();
1752 if (fs == Elements && arg.actsExpanded()) {
1753 const double w_0 = m_dx[0]*m_dx[1]*m_dx[2]/8.;
1754 #pragma omp parallel
1755 {
1756 vector<double> int_local(numComp, 0);
1757 #pragma omp for nowait
1758 for (index_t k2 = front; k2 < front+m_ownNE[2]; ++k2) {
1759 for (index_t k1 = bottom; k1 < bottom+m_ownNE[1]; ++k1) {
1760 for (index_t k0 = left; k0 < left+m_ownNE[0]; ++k0) {
1761 const double* f = arg.getSampleDataRO(INDEX3(k0, k1, k2, m_NE[0], m_NE[1]));
1762 for (index_t i=0; i < numComp; ++i) {
1763 const double f_0 = f[INDEX2(i,0,numComp)];
1764 const double f_1 = f[INDEX2(i,1,numComp)];
1765 const double f_2 = f[INDEX2(i,2,numComp)];
1766 const double f_3 = f[INDEX2(i,3,numComp)];
1767 const double f_4 = f[INDEX2(i,4,numComp)];
1768 const double f_5 = f[INDEX2(i,5,numComp)];
1769 const double f_6 = f[INDEX2(i,6,numComp)];
1770 const double f_7 = f[INDEX2(i,7,numComp)];
1771 int_local[i]+=(f_0+f_1+f_2+f_3+f_4+f_5+f_6+f_7)*w_0;
1772 } // end of component loop i
1773 } // end of k0 loop
1774 } // end of k1 loop
1775 } // end of k2 loop
1776
1777 #pragma omp critical
1778 for (index_t i=0; i<numComp; i++)
1779 integrals[i]+=int_local[i];
1780 } // end of parallel section
1781
1782 } else if (fs==ReducedElements || (fs==Elements && !arg.actsExpanded())) {
1783 const double w_0 = m_dx[0]*m_dx[1]*m_dx[2];
1784 #pragma omp parallel
1785 {
1786 vector<double> int_local(numComp, 0);
1787 #pragma omp for nowait
1788 for (index_t k2 = front; k2 < front+m_ownNE[2]; ++k2) {
1789 for (index_t k1 = bottom; k1 < bottom+m_ownNE[1]; ++k1) {
1790 for (index_t k0 = left; k0 < left+m_ownNE[0]; ++k0) {
1791 const double* f = arg.getSampleDataRO(INDEX3(k0, k1, k2, m_NE[0], m_NE[1]));
1792 for (index_t i=0; i < numComp; ++i) {
1793 int_local[i]+=f[i]*w_0;
1794 } // end of component loop i
1795 } // end of k0 loop
1796 } // end of k1 loop
1797 } // end of k2 loop
1798
1799 #pragma omp critical
1800 for (index_t i=0; i<numComp; i++)
1801 integrals[i]+=int_local[i];
1802 } // end of parallel section
1803
1804 } else if (fs == FaceElements && arg.actsExpanded()) {
1805 const double w_0 = m_dx[1]*m_dx[2]/4.;
1806 const double w_1 = m_dx[0]*m_dx[2]/4.;
1807 const double w_2 = m_dx[0]*m_dx[1]/4.;
1808 #pragma omp parallel
1809 {
1810 vector<double> int_local(numComp, 0);
1811 if (m_faceOffset[0] > -1) {
1812 #pragma omp for nowait
1813 for (index_t k2 = front; k2 < front+m_ownNE[2]; ++k2) {
1814 for (index_t k1 = bottom; k1 < bottom+m_ownNE[1]; ++k1) {
1815 const double* f = arg.getSampleDataRO(m_faceOffset[0]+INDEX2(k1,k2,m_NE[1]));
1816 for (index_t i=0; i < numComp; ++i) {
1817 const double f_0 = f[INDEX2(i,0,numComp)];
1818