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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4626 - (hide annotations)
Wed Jan 22 06:07:34 2014 UTC (5 years, 9 months ago) by caltinay
File size: 88723 byte(s)
Eliminated all const_cast<Data*> hacks in ripley and finley now that
Data.getSampleDataRO returns a const pointer.

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