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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4657 - (hide annotations)
Thu Feb 6 06:12:20 2014 UTC (5 years, 10 months ago) by jfenwick
File size: 89000 byte(s)
I changed some files.
Updated copyright notices, added GeoComp.



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