/[escript]/trunk/ripley/src/Rectangle.cpp
ViewVC logotype

Annotation of /trunk/ripley/src/Rectangle.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4618 - (hide annotations)
Wed Jan 15 04:35:19 2014 UTC (5 years, 9 months ago) by caltinay
File size: 210108 byte(s)
Implemented reverse reading of grid data from netcdf files.
Fixes #44.

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