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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3750 - (show annotations)
Fri Dec 23 01:20:34 2011 UTC (7 years, 10 months ago) by caltinay
Original Path: branches/ripleygmg_from_3668/ripley/src/Rectangle.cpp
File size: 112712 byte(s)
Checkpoint - reinstated DOF FS and tried to fix couple blocks...

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