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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4334 - (hide annotations)
Thu Mar 21 06:00:14 2013 UTC (6 years, 6 months ago) by caltinay
File size: 243053 byte(s)
Preparations for Voxet (GOCAD) binary grid output + code clean up.
Changed node id's order to remove code duplication in weipa.
More work to do...

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