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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3757 - (show annotations)
Fri Jan 6 04:48:27 2012 UTC (7 years, 11 months ago) by caltinay
File size: 104957 byte(s)
Implemented ownSample() for DOF and Elements.

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

  ViewVC Help
Powered by ViewVC 1.1.26