/[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 151 - (hide annotations)
Thu Sep 22 01:55:00 2005 UTC (15 years, 1 month ago) by jgs
Original Path: trunk/esys2/bruce/src/Bruce/Bruce.cpp
File size: 23919 byte(s)
Merge of development branch dev-02 back to main trunk on 2005-09-22

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     //
95     // domains in 3d space
96     if (m_origin.size()==3) {
97    
98     if (m_v0.size()==0) {
99    
100     // 0d domain in 3d space
101     if ( (m_v1.size()!=0) || (m_v2.size()!=0) ) {
102     return false;
103     }
104    
105     m_v0.clear();
106     m_v0.push_back(0);
107     m_v0.push_back(0);
108     m_v0.push_back(0);
109     m_v1.clear();
110     m_v1.push_back(0);
111     m_v1.push_back(0);
112     m_v1.push_back(0);
113     m_v2.clear();
114     m_v2.push_back(0);
115     m_v2.push_back(0);
116     m_v2.push_back(0);
117    
118     m_n0=1;
119     m_n1=1;
120     m_n2=1;
121    
122     } else if (m_v1.size()==0) {
123    
124     // 1d domain in 3d space
125     if ( (m_v0.size()!=3) || (m_v2.size()!=0) ) {
126     return false;
127     }
128    
129     m_v1.clear();
130     m_v1.push_back(0);
131     m_v1.push_back(0);
132     m_v1.push_back(0);
133     m_v2.clear();
134     m_v2.push_back(0);
135     m_v2.push_back(0);
136     m_v2.push_back(0);
137    
138     m_n1=1;
139     m_n2=1;
140    
141     } else if (m_v2.size()==0) {
142    
143     // 2d domain in 3d space
144     if ( (m_v0.size()!=3) || (m_v1.size()!=3) ) {
145     return false;
146     }
147    
148     m_v2.clear();
149     m_v2.push_back(0);
150     m_v2.push_back(0);
151     m_v2.push_back(0);
152    
153     m_n2=1;
154    
155     } else {
156    
157     // 3d domain in 3d space
158     if ( (m_v0.size()!=3) || (m_v1.size()!=3) || (m_v2.size()!=3) ) {
159     return false;
160     }
161    
162     }
163    
164     }
165    
166     //
167     // domains in 2d space
168     if (m_origin.size()==2) {
169    
170     if (m_v0.size()==0) {
171    
172     // 0d domain in 2d space
173     if (m_v1.size()!=0) {
174     return false;
175     }
176    
177     m_v0.clear();
178     m_v0.push_back(0);
179     m_v0.push_back(0);
180     m_v1.clear();
181     m_v1.push_back(0);
182     m_v1.push_back(0);
183     m_v2.clear();
184    
185     m_n0=1;
186     m_n1=1;
187     m_n2=1;
188    
189     } else if (m_v1.size()==0) {
190    
191     // 1d domain in 2d space
192     if (m_v0.size()!=2) {
193     return false;
194     }
195    
196     m_v1.clear();
197     m_v1.push_back(0);
198     m_v1.push_back(0);
199     m_v2.clear();
200    
201     m_n1=1;
202     m_n2=1;
203    
204     } else {
205    
206     // 2d domain in 2d space
207     if ( (m_v0.size()!=2) || (m_v1.size()!=2) ) {
208     return false;
209     }
210    
211     m_v2.clear();
212    
213     m_n2=1;
214    
215     }
216    
217     }
218    
219     //
220     // domains in 1d space
221     if (m_origin.size()==1) {
222    
223     if (m_v0.size()==0) {
224    
225     // 0d domain in 1d space
226     m_v0.clear();
227     m_v0.push_back(0);
228     m_v1.clear();
229     m_v2.clear();
230    
231     m_n0=1;
232     m_n1=1;
233     m_n2=1;
234    
235     } else {
236    
237     // 1d domain in 1d space
238     if (m_v0.size()!=1) {
239     return false;
240     }
241    
242     m_v1.clear();
243     m_v2.clear();
244    
245     m_n1=1;
246     m_n2=1;
247    
248     }
249    
250     }
251    
252     //
253     // domains in 0d space
254     if (m_origin.size()==0) {
255    
256     // point (0d) domain in 0d space
257     m_v0.clear();
258     m_v1.clear();
259     m_v2.clear();
260    
261     m_n0=1;
262     m_n1=1;
263     m_n2=1;
264    
265     }
266    
267     return true;
268 jgs 149 }
269    
270 jgs 150 bool
271     Bruce::isValidFunctionSpaceType(int functionSpaceCode) const
272     {
273     FunctionSpaceNamesMapType::iterator loc;
274     loc=m_functionSpaceTypeNames.find(functionSpaceCode);
275     return (loc!=m_functionSpaceTypeNames.end());
276     }
277    
278     std::string
279     Bruce::functionSpaceTypeAsString(int functionSpaceCode) const
280     {
281     FunctionSpaceNamesMapType::iterator loc;
282     loc=m_functionSpaceTypeNames.find(functionSpaceCode);
283     if (loc==m_functionSpaceTypeNames.end()) {
284     stringstream temp;
285     temp << "Error - Invalid function space type code.";
286     throw BruceException(temp.str());
287     } else {
288     return loc->second;
289     }
290     }
291    
292 jgs 149 pair<int,int>
293     Bruce::getDataShape(int functionSpaceCode) const
294     {
295 jgs 150 int numDataPointsPerSample=1;
296     int numSamples;
297    
298     switch (functionSpaceCode) {
299    
300     //
301     // Continuous functions
302     case(ContinuousFunction):
303    
304     numSamples = m_n0 * m_n1 * m_n2;
305     break;
306    
307     //
308     // Functions
309     case(Function):
310    
311     // 0d domains
312     if (getDim()==0) {
313    
314     numSamples = 0;
315    
316     // 1d domains
317     } else if (getDim()==1) {
318    
319     if (isZero(m_v0)) {
320     numSamples = 0;
321     } else {
322     numSamples = m_n0-1;
323     }
324    
325     // 2d domains
326     } else if (getDim()==2) {
327    
328     if (isZero(m_v0)) {
329     numSamples = 0;
330     } else if (isZero(m_v1)) {
331     numSamples = m_n0-1;
332     } else {
333     numSamples = (m_n0-1) * (m_n1-1);
334     }
335    
336     // 3d domains
337     } else {
338    
339     if (isZero(m_v0)) {
340     numSamples = 0;
341     } else if (isZero(m_v1)) {
342     numSamples = m_n0-1;
343     } else if (isZero(m_v2)) {
344     numSamples = (m_n0-1) * (m_n1-1);
345     } else {
346     numSamples = (m_n0-1) * (m_n1-1) * (m_n2-1);
347     }
348    
349     }
350    
351     break;
352    
353     default:
354     stringstream temp;
355     temp << "Error - Invalid function space type: "
356     << functionSpaceCode << " for domain: " << getDescription();
357     throw BruceException(temp.str());
358     break;
359    
360     }
361    
362 jgs 149 return pair<int,int>(numDataPointsPerSample,numSamples);
363     }
364    
365 jgs 150 Data
366     Bruce::getX() const
367     {
368     FunctionSpace tempFunc = continuousFunction(asAbstractContinuousDomain());
369     return tempFunc.getX();
370     }
371    
372     void
373     Bruce::setToX(escript::Data& out) const
374     {
375    
376     //
377     // determine functionSpace type expected by supplied Data object
378     int functionSpaceCode = out.getFunctionSpace().getTypeCode();
379    
380     //
381     // ensure supplied Data object has a matching number of data-points
382     // for this Bruce domain object
383     std::pair<int,int> domainShape = getDataShape(functionSpaceCode);
384     if(domainShape.first!=out.getNumDataPointsPerSample() ||
385     domainShape.second!=out.getNumSamples()) {
386     stringstream temp;
387     temp << "Error - Incompatible number of data-points Data object supplied to Bruce::setToX";
388     throw BruceException(temp.str());
389     }
390    
391     int dim = getDim();
392     int numSamples = domainShape.second;
393    
394     //
395     // ensure shape of data-points in supplied Data object matches the
396     // shape needed to store the coordinates of each data-point in this
397     // Bruce domain
398     std::vector<int> dataShape = out.getDataPointShape();
399 jgs 151 if (dim>0 && (dataShape.size()!=1 || dataShape[0]!=dim)) {
400 jgs 150 stringstream temp;
401     temp << "Error - Incompatible shape Data object supplied to Bruce::setToX";
402     throw BruceException(temp.str());
403 jgs 151 } else if (dim==0 && dataShape.size()!=0) {
404     stringstream temp;
405     temp << "Error - Incompatible shape Data object supplied to Bruce::setToX";
406     throw BruceException(temp.str());
407 jgs 150 }
408    
409     if (functionSpaceCode==ContinuousFunction) {
410    
411     //
412     // calculate the spatial coordinates of data-points
413     // located on the nodes of this Bruce domain
414    
415     if (dim==0) {
416    
417     // Bruce domains in 0d space
418    
419     int sampleNo=0;
420     DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
421     sampleNo++;
422     if (sampleNo!=numSamples) {
423     stringstream temp;
424     temp << "Bruce::setToX: Didn't iterate across correct number of samples.";
425     throw BruceException(temp.str());
426     }
427    
428     } else if (dim==1) {
429    
430     // Bruce domains in 1d space
431    
432     int sampleNo=0;
433     for (int i=0; i<m_n0; i++) {
434     DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
435     sampleData[0] = m_origin[0] + m_v0[0]*i;
436     sampleNo++;
437     }
438     if (sampleNo!=numSamples) {
439     stringstream temp;
440     temp << "Bruce::setToX: Didn't iterate across correct number of samples.";
441     throw BruceException(temp.str());
442     }
443    
444     } else if (dim==2) {
445    
446     // Bruce domains in 2d space
447    
448     int sampleNo=0;
449     for (int i=0; i<m_n0; i++) {
450     for (int j=0; j<m_n1; j++) {
451     DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
452     for (int d=0; d<dim; d++) {
453     sampleData[d] = m_origin[d] + m_v0[d]*i + m_v1[d]*j;
454     }
455     sampleNo++;
456     }
457     }
458     if (sampleNo!=numSamples) {
459     stringstream temp;
460     temp << "Bruce::setToX: Didn't iterate across correct number of samples.";
461     throw BruceException(temp.str());
462     }
463    
464     } else if (dim==3) {
465    
466     // Bruce domains in 3d space
467    
468     int sampleNo=0;
469     for (int i=0; i<m_n0; i++) {
470     for (int j=0; j<m_n1; j++) {
471     for (int k=0; k<m_n2; k++) {
472     DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
473     for (int d=0; d<dim; d++) {
474     sampleData[d] = m_origin[d] + m_v0[d]*i + m_v1[d]*j + m_v2[d]*k;
475     }
476     sampleNo++;
477     }
478     }
479     }
480     if (sampleNo!=numSamples) {
481     stringstream temp;
482     temp << "Bruce::setToX: Didn't iterate across correct number of samples.";
483     throw BruceException(temp.str());
484     }
485    
486     }
487    
488     } else if (functionSpaceCode==Function) {
489    
490     //
491     // calculate the spatial coordinates of data-points
492     // located on the cell centres of this Bruce domain
493    
494 jgs 151 if (dim==0) {
495    
496     // Bruce domains in 0d space
497    
498     stringstream temp;
499     temp << "Error - Invalid function space type: "
500     << functionSpaceCode << " for Bruce::setToX";
501     throw BruceException(temp.str());
502    
503     } else if (dim==1) {
504    
505     // Bruce domains in 1d space
506    
507     int n0max=m_n0-1;
508     int sampleNo=0;
509     if (isZero(m_v0)) {
510     stringstream temp;
511     temp << "Error - Invalid function space type: "
512     << functionSpaceCode << " for Bruce::setToX";
513     throw BruceException(temp.str());
514     } else {
515     for (int i=0; i<n0max; i++) {
516     DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
517     sampleData[0] = m_origin[0] + m_v0[0]*(i + 0.5);
518     sampleNo++;
519     }
520 jgs 150 }
521 jgs 151 if (sampleNo!=numSamples) {
522     stringstream temp;
523     temp << "Bruce::setToX: Didn't iterate across correct number of samples.";
524     throw BruceException(temp.str());
525     }
526    
527     } else if (dim==2) {
528    
529     // Bruce domains in 2d space
530    
531     int n0max=m_n0-1;
532     int n1max=m_n1-1;
533     int sampleNo=0;
534     if (isZero(m_v0)) {
535     stringstream temp;
536     temp << "Error - Invalid function space type: "
537     << functionSpaceCode << " for Bruce::setToX";
538     throw BruceException(temp.str());
539     } else if (isZero(m_v1)) {
540     for (int i=0; i<n0max; i++) {
541     DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
542     for (int d=0; d<dim; d++) {
543     sampleData[d] = m_origin[d] + m_v0[d]*(i + 0.5);
544     }
545     sampleNo++;
546     }
547     } else {
548     for (int i=0; i<n0max; i++) {
549     for (int j=0; j<n1max; j++) {
550     DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
551     for (int d=0; d<dim; d++) {
552     sampleData[d] = m_origin[d] + m_v0[d]*(i + 0.5) + m_v1[d]*(j + 0.5);
553     }
554     sampleNo++;
555     }
556     }
557     }
558     if (sampleNo!=numSamples) {
559     stringstream temp;
560     temp << "Bruce::setToX: Didn't iterate across correct number of samples.";
561     throw BruceException(temp.str());
562     }
563    
564     } else if (dim==3) {
565    
566     // Bruce domains in 3d space
567    
568     int n0max=m_n0-1;
569     int n1max=m_n1-1;
570     int n2max=m_n2-1;
571     int sampleNo=0;
572     if (isZero(m_v0)) {
573     stringstream temp;
574     temp << "Error - Invalid function space type: "
575     << functionSpaceCode << " for Bruce::setToX";
576     throw BruceException(temp.str());
577     } else if (isZero(m_v1)) {
578     for (int i=0; i<n0max; i++) {
579     DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
580     for (int d=0; d<dim; d++) {
581     sampleData[d] = m_origin[d] + m_v0[d]*(i + 0.5);
582     }
583     sampleNo++;
584     }
585     } else if (isZero(m_v2)) {
586     for (int i=0; i<n0max; i++) {
587     for (int j=0; j<n1max; j++) {
588     DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
589     for (int d=0; d<dim; d++) {
590     sampleData[d] = m_origin[d] + m_v0[d]*(i + 0.5) + m_v1[d]*(j + 0.5);
591     }
592     sampleNo++;
593     }
594     }
595     } else {
596     for (int i=0; i<n0max; i++) {
597     for (int j=0; j<n1max; j++) {
598     for (int k=0; k<n2max; k++) {
599     DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
600     for (int d=0; d<dim; d++) {
601     sampleData[d] = m_origin[d] + m_v0[d]*(i + 0.5) + m_v1[d]*(j + 0.5) + m_v2[d]*(k + 0.5);
602     }
603     sampleNo++;
604     }
605     }
606     }
607     }
608     if (sampleNo!=numSamples) {
609     stringstream temp;
610     temp << "Bruce::setToX: Didn't iterate across correct number of samples.";
611     throw BruceException(temp.str());
612     }
613    
614 jgs 150 }
615    
616     } else {
617     stringstream temp;
618     temp << "Error - Invalid function space type: "
619     << functionSpaceCode << " for domain: " << getDescription();
620     throw BruceException(temp.str());
621     }
622    
623     }
624    
625     Data
626     Bruce::getSize() const
627     {
628     FunctionSpace tempFunc = function(asAbstractContinuousDomain());
629     return tempFunc.getSize();
630     }
631    
632     void
633     Bruce::setToSize(escript::Data& out) const
634     {
635    
636 jgs 151 //
637     // determine functionSpace type expected by supplied Data object
638 jgs 150 int functionSpaceCode = out.getFunctionSpace().getTypeCode();
639    
640 jgs 151 //
641     // ensure supplied Data object has a matching number of data-points
642     // for this Bruce domain object
643 jgs 150 std::pair<int,int> domainShape = getDataShape(functionSpaceCode);
644     if(domainShape.first!=out.getNumDataPointsPerSample() ||
645     domainShape.second!=out.getNumSamples()) {
646     stringstream temp;
647 jgs 151 temp << "Error - Incompatible number of data-points Data object supplied to Bruce::setToSize";
648 jgs 150 throw BruceException(temp.str());
649     }
650    
651 jgs 151 int dim = getDim();
652     int numSamples = domainShape.second;
653    
654     //
655     // ensure shape of data-points in supplied Data object matches the
656     // shape needed to store the size of each data-point in this Bruce domain
657 jgs 150 std::vector<int> dataShape = out.getDataPointShape();
658 jgs 151 if (dataShape.size()!=1 || dataShape[0]!=1) {
659 jgs 150 stringstream temp;
660 jgs 151 temp << "Error - Incompatible shape Data object supplied to Bruce::setToSize";
661 jgs 150 throw BruceException(temp.str());
662     }
663    
664 jgs 151 double dp_size;
665 jgs 150
666     if (functionSpaceCode==ContinuousFunction) {
667    
668 jgs 151 //
669     // calculate the size of data-points
670     // located on the nodes of this Bruce domain
671 jgs 150
672 jgs 151 if (dim==0) {
673    
674     // Bruce domains in 0d space
675    
676     dp_size = 0.0;
677    
678     int sampleNo=0;
679     DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
680     sampleData[0] = dp_size;
681     sampleNo++;
682     if (sampleNo!=numSamples) {
683     stringstream temp;
684     temp << "Bruce::setToSize: Didn't iterate across correct number of samples.";
685     throw BruceException(temp.str());
686     }
687    
688     } else if (dim==1) {
689    
690     // Bruce domains in 1d space
691    
692     dp_size = m_v0[0];
693    
694     int sampleNo=0;
695     for (int i=0; i<m_n0; i++) {
696     DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
697     sampleData[0] = dp_size;
698     sampleNo++;
699     }
700     if (sampleNo!=numSamples) {
701     stringstream temp;
702     temp << "Bruce::setToSize: Didn't iterate across correct number of samples.";
703     throw BruceException(temp.str());
704     }
705    
706     } else if (dim==2) {
707    
708     // Bruce domains in 2d space
709    
710     double x = m_v0[0] + m_v1[0];
711     double y = m_v0[1] + m_v1[1];
712     dp_size = sqrt(pow(x,2)+pow(y,2));
713    
714     int sampleNo=0;
715     for (int i=0; i<m_n0; i++) {
716     for (int j=0; j<m_n1; j++) {
717     DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
718     sampleData[0] = dp_size;
719     sampleNo++;
720     }
721     }
722     if (sampleNo!=numSamples) {
723     stringstream temp;
724     temp << "Bruce::setToSize: Didn't iterate across correct number of samples.";
725     throw BruceException(temp.str());
726     }
727    
728     } else if (dim==3) {
729    
730     // Bruce domains in 3d space
731    
732     double x = m_v0[0] + m_v1[0] + m_v2[0];
733     double y = m_v0[1] + m_v1[1] + m_v2[1];
734     double z = m_v0[2] + m_v1[2] + m_v2[2];
735     dp_size = sqrt(pow(x,2)+pow(y,2)+pow(z,2));
736    
737     int sampleNo=0;
738     for (int i=0; i<m_n0; i++) {
739     for (int j=0; j<m_n1; j++) {
740     for (int k=0; k<m_n2; k++) {
741     DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
742     sampleData[0] = dp_size;
743     sampleNo++;
744     }
745     }
746     }
747     if (sampleNo!=numSamples) {
748     stringstream temp;
749     temp << "Bruce::setToSize: Didn't iterate across correct number of samples.";
750     throw BruceException(temp.str());
751     }
752    
753 jgs 150 }
754    
755     } else if (functionSpaceCode==Function) {
756    
757 jgs 151 //
758     // calculate the sizes of data-points
759     // located on the cell centres of this Bruce domain
760 jgs 150
761 jgs 151 if (dim==0) {
762    
763     // Bruce domains in 0d space
764    
765     stringstream temp;
766     temp << "Error - Invalid function space type: "
767     << functionSpaceCode << " for Bruce::setToSize";
768     throw BruceException(temp.str());
769    
770     } else if (dim==1) {
771    
772     // Bruce domains in 1d space
773    
774     dp_size = m_v0[0];
775    
776     int n0max=m_n0-1;
777     int sampleNo=0;
778     if (isZero(m_v0)) {
779     stringstream temp;
780     temp << "Error - Invalid function space type: "
781     << functionSpaceCode << " for Bruce::setToSize";
782     throw BruceException(temp.str());
783     } else {
784     for (int i=0; i<n0max; i++) {
785     DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
786     sampleData[0] = dp_size;
787     sampleNo++;
788     }
789     }
790     if (sampleNo!=numSamples) {
791     stringstream temp;
792     temp << "Bruce::setToSize: Didn't iterate across correct number of samples.";
793     throw BruceException(temp.str());
794     }
795    
796     } else if (dim==2) {
797    
798     // Bruce domains in 2d space
799    
800     double x = m_v0[0] + m_v1[0];
801     double y = m_v0[1] + m_v1[1];
802     dp_size = sqrt(pow(x,2)+pow(y,2));
803    
804     int n0max=m_n0-1;
805     int n1max=m_n1-1;
806     int sampleNo=0;
807     if (isZero(m_v0)) {
808     stringstream temp;
809     temp << "Error - Invalid function space type: "
810     << functionSpaceCode << " for Bruce::setToSize";
811     throw BruceException(temp.str());
812     } else if (isZero(m_v1)) {
813     for (int i=0; i<n0max; i++) {
814     DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
815     sampleData[0] = dp_size;
816     sampleNo++;
817     }
818     } else {
819     for (int i=0; i<n0max; i++) {
820     for (int j=0; j<n1max; j++) {
821     DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
822     sampleData[0] = dp_size;
823     sampleNo++;
824     }
825     }
826     }
827     if (sampleNo!=numSamples) {
828     stringstream temp;
829     temp << "Bruce::setToSize: Didn't iterate across correct number of samples.";
830     throw BruceException(temp.str());
831     }
832    
833     } else if (dim==3) {
834    
835     // Bruce domains in 3d space
836    
837     double x = m_v0[0] + m_v1[0] + m_v2[0];
838     double y = m_v0[1] + m_v1[1] + m_v2[1];
839     double z = m_v0[2] + m_v1[2] + m_v2[2];
840     dp_size = sqrt(pow(x,2)+pow(y,2)+pow(z,2));
841    
842     int n0max=m_n0-1;
843     int n1max=m_n1-1;
844     int n2max=m_n2-1;
845     int sampleNo=0;
846     if (isZero(m_v0)) {
847     stringstream temp;
848     temp << "Error - Invalid function space type: "
849     << functionSpaceCode << " for Bruce::setToSize";
850     throw BruceException(temp.str());
851     } else if (isZero(m_v1)) {
852     for (int i=0; i<n0max; i++) {
853     DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
854     sampleData[0] = dp_size;
855     sampleNo++;
856     }
857     } else if (isZero(m_v2)) {
858     for (int i=0; i<n0max; i++) {
859     for (int j=0; j<n1max; j++) {
860     DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
861     sampleData[0] = dp_size;
862     sampleNo++;
863     }
864     }
865     } else {
866     for (int i=0; i<n0max; i++) {
867     for (int j=0; j<n1max; j++) {
868     for (int k=0; k<n2max; k++) {
869     DataAbstract::ValueType::value_type* sampleData = out.getSampleData(sampleNo);
870     sampleData[0] = dp_size;
871     sampleNo++;
872     }
873     }
874     }
875     }
876     if (sampleNo!=numSamples) {
877     stringstream temp;
878     temp << "Bruce::setToSize: Didn't iterate across correct number of samples.";
879     throw BruceException(temp.str());
880     }
881    
882 jgs 150 }
883    
884     } else {
885     stringstream temp;
886     temp << "Error - Invalid function space type: "
887     << functionSpaceCode << " for domain: " << getDescription();
888     throw BruceException(temp.str());
889     }
890    
891     }
892    
893 jgs 149 bool
894     Bruce::operator==(const AbstractDomain& other) const
895     {
896     const Bruce* temp=dynamic_cast<const Bruce*>(&other);
897     if (temp!=0) {
898 jgs 150 if ((m_v0 != temp->m_v0) || (m_v1 != temp->m_v1) || (m_v2 != temp->m_v2)) {
899     return false;
900     }
901     if ((m_n0 != temp->m_n0) || (m_n1 != temp->m_n1) || (m_n2 != temp->m_n2)) {
902     return false;
903     }
904     if (m_origin != temp->m_origin) {
905     return false;
906     }
907     return true;
908 jgs 149 } else {
909     return false;
910     }
911     }
912    
913     bool
914     Bruce::operator!=(const AbstractDomain& other) const
915     {
916     return !(operator==(other));
917     }
918    
919 jgs 150 bool
920 jgs 151 Bruce::isZero(DimVec vec)
921 jgs 149 {
922 jgs 150 for (int i=0; i<vec.size(); i++) {
923     if (vec[i] != 0) {
924     return false;
925     }
926     }
927     return true;
928 jgs 149 }
929    
930     } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26