/[escript]/trunk/escript/src/FunctionSpace.cpp
ViewVC logotype

Diff of /trunk/escript/src/FunctionSpace.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/esys2/escript/src/Data/FunctionSpace.cpp revision 82 by jgs, Tue Oct 26 06:53:54 2004 UTC trunk/escript/src/FunctionSpace.cpp revision 1802 by jfenwick, Tue Sep 23 01:03:29 2008 UTC
# Line 1  Line 1 
 /*  
  ******************************************************************************  
  *                                                                            *  
  *       COPYRIGHT  ACcESS 2004 -  All Rights Reserved                        *  
  *                                                                            *  
  * This software is the property of ACcESS. No part of this code              *  
  * may be copied in any form or by any means without the expressed written    *  
  * consent of ACcESS.  Copying, use or modification of this software          *  
  * by any unauthorised person is illegal unless that person has a software    *  
  * license agreement with ACcESS.                                             *  
  *                                                                            *  
  ******************************************************************************  
 */  
   
 #include "escript/Data/AbstractContinuousDomain.h"  
 #include "escript/Data/FunctionSpaceException.h"  
 #include "escript/Data/Data.h"  
 #include "escript/Data/DataFactory.h"  
1    
2  #include "escript/Data/FunctionSpace.h"  /* $Id$ */
3    
4    /*******************************************************
5     *
6     *           Copyright 2003-2007 by ACceSS MNRF
7     *       Copyright 2007 by University of Queensland
8     *
9     *                http://esscc.uq.edu.au
10     *        Primary Business: Queensland, Australia
11     *  Licensed under the Open Software License version 3.0
12     *     http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15    
16    #include "FunctionSpace.h"
17    #include "FunctionSpaceException.h"
18    #include "Data.h"
19    #include "DataFactory.h"
20    
21  #include <iostream>  #include <iostream>
22  #include <sstream>  #include <sstream>
23    
24    using namespace std;
25    
26  namespace escript {  namespace escript {
27    
28  //  //
29  // Create a null domain for use with a default constructed function space  // Create a null domain for use with any default-constructed function space
30  NullDomain FunctionSpace::m_nullDomainValue;  NullDomain const FunctionSpace::nullDomainValue;
31    
32  FunctionSpace::FunctionSpace():  FunctionSpace::FunctionSpace():
33    m_domain(static_cast<AbstractDomain*>(&m_nullDomainValue)),    m_domain(static_cast<const AbstractDomain*>(&nullDomainValue)),
34    m_functionSpaceType(m_nullDomainValue.getFunctionCode())    m_functionSpaceType(nullDomainValue.getFunctionCode())
35  {  {
   //std::cout << "Called FunctionSpace DEFAULT constructor." << std::endl;  
36  }  }
37    
38  FunctionSpace::FunctionSpace(const AbstractDomain& domain, int functionSpaceType):  FunctionSpace::FunctionSpace(const AbstractDomain& domain,
39                                 int functionSpaceType):
40    m_domain(dynamic_cast<const AbstractDomain*>(&domain)),    m_domain(dynamic_cast<const AbstractDomain*>(&domain)),
41    m_functionSpaceType(functionSpaceType)    m_functionSpaceType(functionSpaceType)
42  {  {
   //std::cout << "Called FunctionSpace constructor." << std::endl;  
43    if (!m_domain->isValidFunctionSpaceType(functionSpaceType)) {    if (!m_domain->isValidFunctionSpaceType(functionSpaceType)) {
44      std::stringstream temp;      std::stringstream temp;
45      temp << "Invalid function space type: " << functionSpaceType      temp << "Invalid function space type: " << functionSpaceType
46       <<" for domain: " << m_domain->getDescription();       << " for domain: " << m_domain->getDescription();
47      throw FunctionSpaceException(temp.str());      throw FunctionSpaceException(temp.str());
48    }    }
49  }  }
50    
51  std::pair<int,int> FunctionSpace::getDataShape() const  std::pair<int,int>
52    FunctionSpace::getDataShape() const
53  {  {
54    return m_domain->getDataShape(m_functionSpaceType);    return m_domain->getDataShape(m_functionSpaceType);
55  }  }
56    
57  int FunctionSpace::getTypeCode() const  int
58    FunctionSpace::getTypeCode() const
59  {  {
60    return  m_functionSpaceType;    return  m_functionSpaceType;
61  }  }
62    
63  const AbstractDomain& FunctionSpace::getDomain() const  const
64    AbstractDomain&
65    FunctionSpace::getDomain() const
66  {  {
67    return *m_domain;    return *m_domain;
68  }  }
69    
70  std::string FunctionSpace::toString() const  std::string
71    FunctionSpace::toString() const
72  {  {
73    std::stringstream temp;    std::stringstream temp;
74    temp << "Function space type: "    temp << m_domain->functionSpaceTypeAsString(m_functionSpaceType)
        << m_domain->functionSpaceTypeAsString(m_functionSpaceType)  
75         << " on " << m_domain->getDescription();         << " on " << m_domain->getDescription();
76    
77    return temp.str();    return temp.str();
78  }  }
79    
80  int FunctionSpace::getTagFromSampleNo(int sampleNo) const  
81    #ifdef DEBUG_PY_STRINGS
82    PyObject *
83    FunctionSpace::toPyString() const
84    {
85      boost::python::to_python_value<const std::string &> cvtr;
86      std::stringstream temp;
87    
88      temp << m_domain->functionSpaceTypeAsString(m_functionSpaceType)
89           << " on " << m_domain->getDescription();
90    
91      return cvtr(temp.str());
92    }
93    #endif
94    
95    
96    int
97    FunctionSpace::getTagFromSampleNo(int sampleNo) const
98  {  {
99    return m_domain->getTagFromSampleNo(m_functionSpaceType,sampleNo);    return m_domain->getTagFromSampleNo(m_functionSpaceType,sampleNo);
100  }  }
101    
102  FunctionSpace& FunctionSpace::operator=(const FunctionSpace& other)  int
103    FunctionSpace::getTagFromDataPointNo(int dataPointNo) const
104  {  {
105    //    //
106      // Get the number of samples and data-points per sample
107      int numSamples = getNumSamples();
108      int numDataPointsPerSample = getNumDPPSample();
109      int numDataPoints = numSamples * numDataPointsPerSample;
110    
111      if (numDataPointsPerSample==0) {
112        throw DataException("FunctionSpace::getTagFromDataPointNo error: no data-points associated with this object.");
113      }
114    
115      if (dataPointNo<0 || dataPointNo>numDataPoints) {
116        throw DataException("FunctionSpace::getTagFromDataPointNo error: invalid data-point number supplied.");
117      }
118    
119      //
120      // Determine the sample number which corresponds to this data-point number
121      int sampleNo = dataPointNo / numDataPointsPerSample;
122    
123      //
124      // Determine the tag number which corresponds to this sample number
125      int tagNo = getTagFromSampleNo(sampleNo);
126    
127      //
128      // return the tag number
129      return(tagNo);
130    }
131    
132    int FunctionSpace::getReferenceIDFromDataPointNo(int dataPointNo) const
133    {
134         //
135         // Get the number of samples and data-points per sample
136         int numSamples = getNumSamples();
137         int numDataPointsPerSample = getNumDPPSample();
138         int*referenceIDs= borrowSampleReferenceIDs();
139         int numDataPoints = numSamples * numDataPointsPerSample;
140    
141         if (numDataPointsPerSample==0) {
142            throw DataException("FunctionSpace::getReferenceIDFromDataPointNo error: no data-points associated with this object.");
143         }
144         if (dataPointNo<0 || dataPointNo>numDataPoints) {
145            throw DataException("FunctionSpace::getReferenceIDFromDataPointNo error: invalid data-point number supplied.");
146         }
147         int sampleNo = dataPointNo / numDataPointsPerSample;
148         return referenceIDs[sampleNo];
149    }
150    
151    int*
152    FunctionSpace::borrowSampleReferenceIDs() const
153    {
154      return m_domain->borrowSampleReferenceIDs(m_functionSpaceType);
155    }
156    
157    FunctionSpace&
158    FunctionSpace::operator=(const FunctionSpace& other)
159    {
160    // explicitly defined assignment operator to emphasise pointer copy    // explicitly defined assignment operator to emphasise pointer copy
   m_nullDomainValue=other.m_nullDomainValue;  
161    m_functionSpaceType=other.m_functionSpaceType;    m_functionSpaceType=other.m_functionSpaceType;
162    m_domain=other.m_domain;    m_domain=other.m_domain;
163    return *this;    return *this;
164  }  }
165    
166  bool FunctionSpace::operator==(const FunctionSpace& other) const  bool
167    FunctionSpace::operator==(const FunctionSpace& other) const
168  {  {
169    return (other.m_domain==m_domain && other.m_functionSpaceType==m_functionSpaceType);    return ((*(other.m_domain)==*(m_domain)) && (other.m_functionSpaceType==m_functionSpaceType));
170  }  }
171    
172  bool FunctionSpace::operator!=(const FunctionSpace& other) const  bool
173    FunctionSpace::operator!=(const FunctionSpace& other) const
174  {  {
175    return (!(other==*this));    return !(operator==(other));
176  }  }
177    
178  escript::Data FunctionSpace::getX() const  escript::Data
179    FunctionSpace::getX() const
180  {  {
181    Data out=escript::Vector(0,*this,true);    Data out=escript::Vector(0,*this,true);
182    getDomain().setToX(out);    getDomain().setToX(out);
183      out.setProtection();
184    return out;    return out;
185  }  }
186    
187  escript::Data FunctionSpace::getNormal() const  escript::Data
188    FunctionSpace::getNormal() const
189  {  {
190    Data out=escript::Vector(0,*this,true);    Data out=escript::Vector(0,*this,true);
191    getDomain().setToNormal(out);    getDomain().setToNormal(out);
192      out.setProtection();
193    return out;    return out;
194  }  }
195    
196  escript::Data FunctionSpace::getSize() const  escript::Data
197    FunctionSpace::getSize() const
198  {  {
199    Data out=escript::Scalar(0,*this,true);    Data out=escript::Scalar(0,*this,true);
200    getDomain().setToSize(out);    getDomain().setToSize(out);
201      out.setProtection();
202    return out;    return out;
203  }  }
204    
205    void
206    FunctionSpace::setTags(const int newTag, const escript::Data& mask) const
207    {
208       if (mask.getFunctionSpace()== *this) {
209              m_domain->setTags(m_functionSpaceType,newTag,mask);
210       } else {
211              throw FunctionSpaceException("illegal function space of mask.");
212       }
213    }
214    
215    int
216    FunctionSpace::getNumberOfTagsInUse() const
217    {
218       return  m_domain->getNumberOfTagsInUse(m_functionSpaceType);
219    }
220    
221    int*
222    FunctionSpace::borrowListOfTagsInUse() const
223    {
224       return  m_domain->borrowListOfTagsInUse(m_functionSpaceType);
225    }
226    
227    std::list<int>
228    FunctionSpace::getListOfTagsSTL() const
229    {
230      std::list<int> taglist;
231      int i;
232      int* tags=borrowListOfTagsInUse();
233      for (i=0;i<getNumberOfTagsInUse();++i) taglist.push_back(tags[i]);
234      return taglist;
235    }
236    
237    
238    boost::python::list
239    FunctionSpace::getListOfTags() const
240    {
241      boost::python::list taglist;
242      int i;
243      int* tags=borrowListOfTagsInUse();
244      for (i=0;i<getNumberOfTagsInUse();++i) taglist.append(tags[i]);
245      return taglist;
246    }
247    
248    bool
249    FunctionSpace::canTag() const
250    {
251      return m_domain->canTag(m_functionSpaceType);
252    }
253    
254  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.82  
changed lines
  Added in v.1802

  ViewVC Help
Powered by ViewVC 1.1.26