/[escript]/trunk/bruce/src/Bruce/Bruce.cpp
ViewVC logotype

Annotation of /trunk/bruce/src/Bruce/Bruce.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 153 - (hide annotations)
Tue Oct 25 01:51:20 2005 UTC (15 years ago) by jgs
Original Path: trunk/esys2/bruce/src/Bruce/Bruce.cpp
File size: 21579 byte(s)
Merge of development branch dev-02 back to main trunk on 2005-10-25

1 jgs 149 // $Id$
2     /*
3     ******************************************************************************
4     * *
5     * COPYRIGHT ACcESS 2005 - All Rights Reserved *
6     * *
7     * This software is the property of ACcESS. No part of this code *
8     * may be copied in any form or by any means without the expressed written *
9     * consent of ACcESS. Copying, use or modification of this software *
10     * by any unauthorised person is illegal unless that person has a software *
11     * license agreement with ACcESS. *
12     * *
13     ******************************************************************************
14     */
15    
16     #include "bruce/Bruce/Bruce.h"
17 jgs 150 #include "bruce/Bruce/BruceException.h"
18 jgs 149
19     using namespace std;
20     using namespace escript;
21    
22     namespace bruce {
23    
24 jgs 150 const int Bruce::ContinuousFunction=0;
25     const int Bruce::Function=1;
26 jgs 149
27 jgs 150 Bruce::FunctionSpaceNamesMapType Bruce::m_functionSpaceTypeNames;
28    
29 jgs 149 Bruce::Bruce()
30     {
31 jgs 150 setFunctionSpaceTypeNames();
32 jgs 149 }
33    
34 jgs 150 Bruce::Bruce(DimVec v0, DimVec v1, DimVec v2,
35     int n0, int n1, int n2,
36     DimVec origin):
37     m_v0(v0), m_v1(v1), m_v2(v2),
38     m_n0(n0), m_n1(n1), m_n2(n2),
39     m_origin(origin)
40 jgs 149 {
41 jgs 150 if (!checkParameters()) {
42     stringstream temp;
43     temp << "Error - Invalid parameters supplied to constructor.";
44     throw BruceException(temp.str());
45     }
46     setFunctionSpaceTypeNames();
47 jgs 149 }
48    
49 jgs 150 Bruce::Bruce(const Bruce& other):
50     m_v0(other.m_v0), m_v1(other.m_v1), m_v2(other.m_v2),
51     m_n0(other.m_n0), m_n1(other.m_n1), m_n2(other.m_n2),
52     m_origin(other.m_origin)
53     {
54     setFunctionSpaceTypeNames();
55     }
56    
57 jgs 149 Bruce::~Bruce()
58     {
59 jgs 150 m_n0=-1;
60     m_n1=-1;
61     m_n2=-1;
62     m_origin.clear();
63     m_v0.clear();
64     m_v1.clear();
65     m_v2.clear();
66 jgs 149 }
67    
68 jgs 150 void
69     Bruce::setFunctionSpaceTypeNames()
70     {
71     m_functionSpaceTypeNames.insert
72     (FunctionSpaceNamesMapType::value_type(Function,"Bruce_Function"));
73     m_functionSpaceTypeNames.insert
74     (FunctionSpaceNamesMapType::value_type(ContinuousFunction,"Bruce_ContinuousFunction"));
75     }
76    
77 jgs 149 bool
78 jgs 150 Bruce::checkParameters()
79 jgs 149 {
80 jgs 150 if (m_origin.size()>3) {
81     return false;
82     }
83    
84     if (m_n0<1) {
85     m_n0=1;
86     }
87     if (m_n1<1) {
88     m_n1=1;
89     }
90     if (m_n2<1) {
91     m_n2=1;
92     }
93    
94 jgs 153 // reorder vectors and point counts according to point counts
95    
96 jgs 150 //
97     // domains in 3d space
98     if (m_origin.size()==3) {
99    
100     if (m_v0.size()==0) {
101    
102     // 0d domain in 3d space
103     if ( (m_v1.size()!=0) || (m_v2.size()!=0) ) {
104     return false;
105     }
106    
107     m_v0.clear();
108     m_v0.push_back(0);
109     m_v0.push_back(0);
110     m_v0.push_back(0);
111     m_v1.clear();
112     m_v1.push_back(0);
113     m_v1.push_back(0);
114     m_v1.push_back(0);
115     m_v2.clear();
116     m_v2.push_back(0);
117     m_v2.push_back(0);
118     m_v2.push_back(0);
119    
120     m_n0=1;
121     m_n1=1;
122     m_n2=1;
123    
124     } else if (m_v1.size()==0) {
125    
126     // 1d domain in 3d space
127     if ( (m_v0.size()!=3) || (m_v2.size()!=0) ) {
128     return false;
129     }
130    
131     m_v1.clear();
132     m_v1.push_back(0);
133     m_v1.push_back(0);
134     m_v1.push_back(0);
135     m_v2.clear();
136     m_v2.push_back(0);
137     m_v2.push_back(0);
138     m_v2.push_back(0);
139    
140     m_n1=1;
141     m_n2=1;
142    
143     } else if (m_v2.size()==0) {
144    
145     // 2d domain in 3d space
146     if ( (m_v0.size()!=3) || (m_v1.size()!=3) ) {
147     return false;
148     }
149    
150     m_v2.clear();
151     m_v2.push_back(0);
152     m_v2.push_back(0);
153     m_v2.push_back(0);
154    
155     m_n2=1;
156    
157     } else {
158    
159     // 3d domain in 3d space
160     if ( (m_v0.size()!=3) || (m_v1.size()!=3) || (m_v2.size()!=3) ) {
161     return false;
162     }
163    
164     }
165    
166     }
167    
168     //
169     // domains in 2d space
170     if (m_origin.size()==2) {
171    
172     if (m_v0.size()==0) {
173    
174     // 0d domain in 2d space
175     if (m_v1.size()!=0) {
176     return false;
177     }
178    
179     m_v0.clear();
180     m_v0.push_back(0);
181     m_v0.push_back(0);
182     m_v1.clear();
183     m_v1.push_back(0);
184     m_v1.push_back(0);
185     m_v2.clear();
186    
187     m_n0=1;
188     m_n1=1;
189     m_n2=1;
190    
191     } else if (m_v1.size()==0) {
192    
193     // 1d domain in 2d space
194     if (m_v0.size()!=2) {
195     return false;
196     }
197    
198     m_v1.clear();
199     m_v1.push_back(0);
200     m_v1.push_back(0);
201     m_v2.clear();
202    
203     m_n1=1;
204     m_n2=1;
205    
206     } else {
207    
208     // 2d domain in 2d space
209     if ( (m_v0.size()!=2) || (m_v1.size()!=2) ) {
210     return false;
211     }
212    
213     m_v2.clear();
214    
215     m_n2=1;
216    
217     }
218    
219     }
220    
221     //
222     // domains in 1d space
223     if (m_origin.size()==1) {
224    
225     if (m_v0.size()==0) {
226    
227     // 0d domain in 1d space
228     m_v0.clear();
229     m_v0.push_back(0);
230     m_v1.clear();
231     m_v2.clear();
232    
233     m_n0=1;
234     m_n1=1;
235     m_n2=1;
236    
237     } else {
238    
239     // 1d domain in 1d space
240     if (m_v0.size()!=1) {
241     return false;
242     }
243    
244     m_v1.clear();
245     m_v2.clear();
246    
247     m_n1=1;
248     m_n2=1;
249    
250     }
251    
252     }
253    
254     //
255     // domains in 0d space
256     if (m_origin.size()==0) {
257    
258     // point (0d) domain in 0d space
259     m_v0.clear();
260     m_v1.clear();
261     m_v2.clear();
262    
263     m_n0=1;
264     m_n1=1;
265     m_n2=1;
266    
267     }
268    
269     return true;
270 jgs 149 }
271    
272 jgs 150 bool
273     Bruce::isValidFunctionSpaceType(int functionSpaceCode) const
274     {
275     FunctionSpaceNamesMapType::iterator loc;
276     loc=m_functionSpaceTypeNames.find(functionSpaceCode);
277     return (loc!=m_functionSpaceTypeNames.end());
278     }
279    
280     std::string
281     Bruce::functionSpaceTypeAsString(int functionSpaceCode) const
282     {
283     FunctionSpaceNamesMapType::iterator loc;
284     loc=m_functionSpaceTypeNames.find(functionSpaceCode);
285     if (loc==m_functionSpaceTypeNames.end()) {
286     stringstream temp;
287     temp << "Error - Invalid function space type code.";
288     throw BruceException(temp.str());
289     } else {
290     return loc->second;
291     }
292     }
293    
294 jgs 149 pair<int,int>
295     Bruce::getDataShape(int functionSpaceCode) const
296     {
297 jgs 150 int numDataPointsPerSample=1;
298     int numSamples;
299    
300     switch (functionSpaceCode) {
301    
302     //
303     // Continuous functions
304     case(ContinuousFunction):
305    
306     numSamples = m_n0 * m_n1 * m_n2;
307     break;
308    
309     //
310     // Functions
311     case(Function):
312    
313     // 0d domains
314     if (getDim()==0) {
315    
316     numSamples = 0;
317    
318     // 1d domains
319     } else if (getDim()==1) {
320    
321     if (isZero(m_v0)) {
322     numSamples = 0;
323     } else {
324     numSamples = m_n0-1;
325     }
326    
327     // 2d domains
328     } else if (getDim()==2) {
329    
330     if (isZero(m_v0)) {
331     numSamples = 0;
332     } else if (isZero(m_v1)) {
333     numSamples = m_n0-1;
334     } else {
335     numSamples = (m_n0-1) * (m_n1-1);
336     }
337    
338     // 3d domains
339     } else {
340    
341     if (isZero(m_v0)) {
342     numSamples = 0;
343     } else if (isZero(m_v1)) {
344     numSamples = m_n0-1;
345     } else if (isZero(m_v2)) {
346     numSamples = (m_n0-1) * (m_n1-1);
347     } else {
348     numSamples = (m_n0-1) * (m_n1-1) * (m_n2-1);
349     }
350    
351     }
352    
353     break;
354    
355     default:
356     stringstream temp;
357     temp << "Error - Invalid function space type: "
358     << functionSpaceCode << " for domain: " << getDescription();
359     throw BruceException(temp.str());
360     break;
361    
362     }
363    
364 jgs 149 return pair<int,int>(numDataPointsPerSample,numSamples);
365     }
366    
367 jgs 150 Data
368     Bruce::getX() const
369     {
370     FunctionSpace tempFunc = continuousFunction(asAbstractContinuousDomain());
371     return tempFunc.getX();
372     }
373    
374     void
375     Bruce::setToX(escript::Data& out) const
376     {
377    
378     //
379     // determine functionSpace type expected by supplied Data object
380     int functionSpaceCode = out.getFunctionSpace().getTypeCode();
381    
382     //
383     // ensure supplied Data object has a matching number of data-points
384     // for this Bruce domain object
385     std::pair<int,int> domainShape = getDataShape(functionSpaceCode);
386     if(domainShape.first!=out.getNumDataPointsPerSample() ||
387     domainShape.second!=out.getNumSamples()) {
388     stringstream temp;
389     temp << "Error - Incompatible number of data-points Data object supplied to Bruce::setToX";
390     throw BruceException(temp.str());
391     }
392    
393     int dim = getDim();
394     int numSamples = domainShape.second;
395    
396     //
397     // ensure shape of data-points in supplied Data object matches the
398     // shape needed to store the coordinates of each data-point in this
399     // Bruce domain
400     std::vector<int> dataShape = out.getDataPointShape();
401 jgs 151 if (dim>0 && (dataShape.size()!=1 || dataShape[0]!=dim)) {
402 jgs 150 stringstream temp;
403     temp << "Error - Incompatible shape Data object supplied to Bruce::setToX";
404     throw BruceException(temp.str());
405 jgs 151 } else if (dim==0 && dataShape.size()!=0) {
406     stringstream temp;
407     temp << "Error - Incompatible shape Data object supplied to Bruce::setToX";
408     throw BruceException(temp.str());
409 jgs 150 }
410    
411     if (functionSpaceCode==ContinuousFunction) {
412    
413     //
414     // calculate the spatial coordinates of data-points
415     // located on the nodes of this Bruce domain
416    
417     if (dim==0) {
418    
419     // Bruce domains in 0d space
420    
421     int sampleNo=0;
422     DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
423    
424     } else if (dim==1) {
425    
426     // Bruce domains in 1d space
427    
428     for (int i=0; i<m_n0; i++) {
429 jgs 153 int sampleNo=i;
430 jgs 150 DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
431     sampleData[0] = m_origin[0] + m_v0[0]*i;
432     }
433    
434     } else if (dim==2) {
435    
436     // Bruce domains in 2d space
437    
438     for (int i=0; i<m_n0; i++) {
439     for (int j=0; j<m_n1; j++) {
440 jgs 153 int sampleNo=(m_n1*i)+j;
441 jgs 150 DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
442     for (int d=0; d<dim; d++) {
443     sampleData[d] = m_origin[d] + m_v0[d]*i + m_v1[d]*j;
444     }
445     }
446     }
447    
448     } else if (dim==3) {
449    
450     // Bruce domains in 3d space
451    
452     for (int i=0; i<m_n0; i++) {
453     for (int j=0; j<m_n1; j++) {
454     for (int k=0; k<m_n2; k++) {
455 jgs 153 int sampleNo=(m_n1*m_n2*i)+(m_n2*j)+k;
456 jgs 150 DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
457     for (int d=0; d<dim; d++) {
458     sampleData[d] = m_origin[d] + m_v0[d]*i + m_v1[d]*j + m_v2[d]*k;
459     }
460     }
461     }
462     }
463    
464     }
465    
466     } else if (functionSpaceCode==Function) {
467    
468     //
469     // calculate the spatial coordinates of data-points
470     // located on the cell centres of this Bruce domain
471    
472 jgs 151 if (dim==0) {
473    
474     // Bruce domains in 0d space
475    
476     stringstream temp;
477     temp << "Error - Invalid function space type: "
478     << functionSpaceCode << " for Bruce::setToX";
479     throw BruceException(temp.str());
480    
481     } else if (dim==1) {
482    
483     // Bruce domains in 1d space
484    
485     int n0max=m_n0-1;
486     if (isZero(m_v0)) {
487     stringstream temp;
488     temp << "Error - Invalid function space type: "
489     << functionSpaceCode << " for Bruce::setToX";
490     throw BruceException(temp.str());
491     } else {
492     for (int i=0; i<n0max; i++) {
493 jgs 153 int sampleNo=i;
494 jgs 151 DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
495     sampleData[0] = m_origin[0] + m_v0[0]*(i + 0.5);
496     }
497 jgs 150 }
498 jgs 151
499     } else if (dim==2) {
500    
501     // Bruce domains in 2d space
502    
503     int n0max=m_n0-1;
504     int n1max=m_n1-1;
505     if (isZero(m_v0)) {
506     stringstream temp;
507     temp << "Error - Invalid function space type: "
508     << functionSpaceCode << " for Bruce::setToX";
509     throw BruceException(temp.str());
510     } else if (isZero(m_v1)) {
511     for (int i=0; i<n0max; i++) {
512 jgs 153 int sampleNo=i;
513 jgs 151 DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
514     for (int d=0; d<dim; d++) {
515     sampleData[d] = m_origin[d] + m_v0[d]*(i + 0.5);
516     }
517     }
518     } else {
519     for (int i=0; i<n0max; i++) {
520     for (int j=0; j<n1max; j++) {
521 jgs 153 int sampleNo=(n1max*i)+j;
522 jgs 151 DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
523     for (int d=0; d<dim; d++) {
524     sampleData[d] = m_origin[d] + m_v0[d]*(i + 0.5) + m_v1[d]*(j + 0.5);
525     }
526     }
527     }
528     }
529    
530     } else if (dim==3) {
531    
532     // Bruce domains in 3d space
533    
534     int n0max=m_n0-1;
535     int n1max=m_n1-1;
536     int n2max=m_n2-1;
537     if (isZero(m_v0)) {
538     stringstream temp;
539     temp << "Error - Invalid function space type: "
540     << functionSpaceCode << " for Bruce::setToX";
541     throw BruceException(temp.str());
542     } else if (isZero(m_v1)) {
543     for (int i=0; i<n0max; i++) {
544 jgs 153 int sampleNo=i;
545 jgs 151 DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
546     for (int d=0; d<dim; d++) {
547     sampleData[d] = m_origin[d] + m_v0[d]*(i + 0.5);
548     }
549     }
550     } else if (isZero(m_v2)) {
551     for (int i=0; i<n0max; i++) {
552     for (int j=0; j<n1max; j++) {
553 jgs 153 int sampleNo=(n1max*i)+j;
554 jgs 151 DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
555     for (int d=0; d<dim; d++) {
556     sampleData[d] = m_origin[d] + m_v0[d]*(i + 0.5) + m_v1[d]*(j + 0.5);
557     }
558     }
559     }
560     } else {
561     for (int i=0; i<n0max; i++) {
562     for (int j=0; j<n1max; j++) {
563     for (int k=0; k<n2max; k++) {
564 jgs 153 int sampleNo=(n1max*n2max*i)+(n2max*j)+k;
565 jgs 151 DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
566     for (int d=0; d<dim; d++) {
567     sampleData[d] = m_origin[d] + m_v0[d]*(i + 0.5) + m_v1[d]*(j + 0.5) + m_v2[d]*(k + 0.5);
568     }
569     }
570     }
571     }
572     }
573    
574 jgs 150 }
575    
576     } else {
577     stringstream temp;
578     temp << "Error - Invalid function space type: "
579     << functionSpaceCode << " for domain: " << getDescription();
580     throw BruceException(temp.str());
581     }
582    
583     }
584    
585     Data
586     Bruce::getSize() const
587     {
588     FunctionSpace tempFunc = function(asAbstractContinuousDomain());
589     return tempFunc.getSize();
590     }
591    
592     void
593     Bruce::setToSize(escript::Data& out) const
594     {
595    
596 jgs 151 //
597     // determine functionSpace type expected by supplied Data object
598 jgs 150 int functionSpaceCode = out.getFunctionSpace().getTypeCode();
599    
600 jgs 151 //
601     // ensure supplied Data object has a matching number of data-points
602     // for this Bruce domain object
603 jgs 150 std::pair<int,int> domainShape = getDataShape(functionSpaceCode);
604     if(domainShape.first!=out.getNumDataPointsPerSample() ||
605     domainShape.second!=out.getNumSamples()) {
606     stringstream temp;
607 jgs 151 temp << "Error - Incompatible number of data-points Data object supplied to Bruce::setToSize";
608 jgs 150 throw BruceException(temp.str());
609     }
610    
611 jgs 151 int dim = getDim();
612     int numSamples = domainShape.second;
613    
614     //
615     // ensure shape of data-points in supplied Data object matches the
616     // shape needed to store the size of each data-point in this Bruce domain
617 jgs 150 std::vector<int> dataShape = out.getDataPointShape();
618 jgs 153 // this check should be satisfied by Data objects passed to setToSize, but
619     // FunctionSpace::getSize() seems to create an object which is larger than
620     // this... either way, this method can deal with this
621     /*
622 jgs 151 if (dataShape.size()!=1 || dataShape[0]!=1) {
623 jgs 150 stringstream temp;
624 jgs 151 temp << "Error - Incompatible shape Data object supplied to Bruce::setToSize";
625 jgs 150 throw BruceException(temp.str());
626     }
627 jgs 153 */
628 jgs 150
629 jgs 151 double dp_size;
630 jgs 150
631     if (functionSpaceCode==ContinuousFunction) {
632    
633 jgs 151 //
634     // calculate the size of data-points
635     // located on the nodes of this Bruce domain
636 jgs 150
637 jgs 151 if (dim==0) {
638    
639     // Bruce domains in 0d space
640    
641     dp_size = 0.0;
642    
643     int sampleNo=0;
644     DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
645     sampleData[0] = dp_size;
646    
647     } else if (dim==1) {
648    
649     // Bruce domains in 1d space
650    
651     dp_size = m_v0[0];
652    
653     for (int i=0; i<m_n0; i++) {
654 jgs 153 int sampleNo=i;
655 jgs 151 DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
656     sampleData[0] = dp_size;
657     }
658    
659     } else if (dim==2) {
660    
661     // Bruce domains in 2d space
662    
663     double x = m_v0[0] + m_v1[0];
664     double y = m_v0[1] + m_v1[1];
665     dp_size = sqrt(pow(x,2)+pow(y,2));
666    
667     for (int i=0; i<m_n0; i++) {
668     for (int j=0; j<m_n1; j++) {
669 jgs 153 int sampleNo=(m_n1*i)+j;
670 jgs 151 DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
671     sampleData[0] = dp_size;
672     }
673     }
674    
675     } else if (dim==3) {
676    
677     // Bruce domains in 3d space
678    
679     double x = m_v0[0] + m_v1[0] + m_v2[0];
680     double y = m_v0[1] + m_v1[1] + m_v2[1];
681     double z = m_v0[2] + m_v1[2] + m_v2[2];
682     dp_size = sqrt(pow(x,2)+pow(y,2)+pow(z,2));
683    
684     for (int i=0; i<m_n0; i++) {
685     for (int j=0; j<m_n1; j++) {
686     for (int k=0; k<m_n2; k++) {
687 jgs 153 int sampleNo=(m_n1*m_n2*i)+(m_n2*j)+k;
688 jgs 151 DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
689     sampleData[0] = dp_size;
690     }
691     }
692     }
693    
694 jgs 150 }
695    
696     } else if (functionSpaceCode==Function) {
697    
698 jgs 151 //
699     // calculate the sizes of data-points
700     // located on the cell centres of this Bruce domain
701 jgs 150
702 jgs 151 if (dim==0) {
703    
704     // Bruce domains in 0d space
705    
706     stringstream temp;
707     temp << "Error - Invalid function space type: "
708     << functionSpaceCode << " for Bruce::setToSize";
709     throw BruceException(temp.str());
710    
711     } else if (dim==1) {
712    
713     // Bruce domains in 1d space
714    
715     dp_size = m_v0[0];
716    
717     int n0max=m_n0-1;
718     if (isZero(m_v0)) {
719     stringstream temp;
720     temp << "Error - Invalid function space type: "
721     << functionSpaceCode << " for Bruce::setToSize";
722     throw BruceException(temp.str());
723     } else {
724     for (int i=0; i<n0max; i++) {
725 jgs 153 int sampleNo=i;
726 jgs 151 DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
727     sampleData[0] = dp_size;
728     }
729     }
730    
731     } else if (dim==2) {
732    
733     // Bruce domains in 2d space
734    
735     double x = m_v0[0] + m_v1[0];
736     double y = m_v0[1] + m_v1[1];
737     dp_size = sqrt(pow(x,2)+pow(y,2));
738    
739     int n0max=m_n0-1;
740     int n1max=m_n1-1;
741     if (isZero(m_v0)) {
742     stringstream temp;
743     temp << "Error - Invalid function space type: "
744     << functionSpaceCode << " for Bruce::setToSize";
745     throw BruceException(temp.str());
746     } else if (isZero(m_v1)) {
747     for (int i=0; i<n0max; i++) {
748 jgs 153 int sampleNo=i;
749 jgs 151 DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
750     sampleData[0] = dp_size;
751     }
752     } else {
753     for (int i=0; i<n0max; i++) {
754     for (int j=0; j<n1max; j++) {
755 jgs 153 int sampleNo=(n1max*i)+j;
756 jgs 151 DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
757     sampleData[0] = dp_size;
758     }
759     }
760     }
761    
762     } else if (dim==3) {
763    
764     // Bruce domains in 3d space
765    
766     double x = m_v0[0] + m_v1[0] + m_v2[0];
767     double y = m_v0[1] + m_v1[1] + m_v2[1];
768     double z = m_v0[2] + m_v1[2] + m_v2[2];
769     dp_size = sqrt(pow(x,2)+pow(y,2)+pow(z,2));
770    
771     int n0max=m_n0-1;
772     int n1max=m_n1-1;
773     int n2max=m_n2-1;
774     if (isZero(m_v0)) {
775     stringstream temp;
776     temp << "Error - Invalid function space type: "
777     << functionSpaceCode << " for Bruce::setToSize";
778     throw BruceException(temp.str());
779     } else if (isZero(m_v1)) {
780     for (int i=0; i<n0max; i++) {
781 jgs 153 int sampleNo=i;
782 jgs 151 DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
783     sampleData[0] = dp_size;
784     }
785     } else if (isZero(m_v2)) {
786     for (int i=0; i<n0max; i++) {
787     for (int j=0; j<n1max; j++) {
788 jgs 153 int sampleNo=(n1max*i)+j;
789 jgs 151 DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
790     sampleData[0] = dp_size;
791     }
792     }
793     } else {
794     for (int i=0; i<n0max; i++) {
795     for (int j=0; j<n1max; j++) {
796     for (int k=0; k<n2max; k++) {
797 jgs 153 int sampleNo=(n2max*n1max*i)+(n1max*j)+k;
798 jgs 151 DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
799     sampleData[0] = dp_size;
800     }
801     }
802     }
803     }
804    
805 jgs 150 }
806    
807     } else {
808     stringstream temp;
809     temp << "Error - Invalid function space type: "
810     << functionSpaceCode << " for domain: " << getDescription();
811     throw BruceException(temp.str());
812     }
813    
814     }
815    
816 jgs 149 bool
817     Bruce::operator==(const AbstractDomain& other) const
818     {
819     const Bruce* temp=dynamic_cast<const Bruce*>(&other);
820     if (temp!=0) {
821 jgs 150 if ((m_v0 != temp->m_v0) || (m_v1 != temp->m_v1) || (m_v2 != temp->m_v2)) {
822     return false;
823     }
824     if ((m_n0 != temp->m_n0) || (m_n1 != temp->m_n1) || (m_n2 != temp->m_n2)) {
825     return false;
826     }
827     if (m_origin != temp->m_origin) {
828     return false;
829     }
830     return true;
831 jgs 149 } else {
832     return false;
833     }
834     }
835    
836     bool
837     Bruce::operator!=(const AbstractDomain& other) const
838     {
839     return !(operator==(other));
840     }
841    
842 jgs 153 int
843     Bruce::getTagFromSampleNo(int functionSpaceCode, int sampleNo) const
844     {
845     return 0;
846     }
847    
848     int
849     Bruce::getReferenceNoFromSampleNo(int functionSpaceCode, int sampleNo) const
850     {
851     return 0;
852     }
853    
854 jgs 150 bool
855 jgs 151 Bruce::isZero(DimVec vec)
856 jgs 149 {
857 jgs 150 for (int i=0; i<vec.size(); i++) {
858     if (vec[i] != 0) {
859     return false;
860     }
861     }
862     return true;
863 jgs 149 }
864    
865     } // end of namespace

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26