/[escript]/branches/ripleygmg_from_3668/ripley/src/Rectangle.cpp
ViewVC logotype

Annotation of /branches/ripleygmg_from_3668/ripley/src/Rectangle.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3764 - (hide annotations)
Tue Jan 10 06:31:15 2012 UTC (7 years, 11 months ago) by caltinay
File size: 190875 byte(s)
Fixed integration now that elements overlap + code cleanup.

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