/[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 4819 - (show annotations)
Tue Apr 1 03:50:23 2014 UTC (5 years ago) by caltinay
Original Path: trunk/ripley/src/Brick.cpp
File size: 165458 byte(s)
Pattern shared ptrs

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