/[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

revision 1388 by trankine, Fri Jan 11 07:45:58 2008 UTC revision 1872 by jfenwick, Mon Oct 13 00:18:55 2008 UTC
# Line 1  Line 1 
1    
 /* $Id$ */  
   
2  /*******************************************************  /*******************************************************
3   *  *
4   *           Copyright 2003-2007 by ACceSS MNRF  * Copyright (c) 2003-2008 by University of Queensland
5   *       Copyright 2007 by University of Queensland  * Earth Systems Science Computational Center (ESSCC)
6   *  * http://www.uq.edu.au/esscc
7   *                http://esscc.uq.edu.au  *
8   *        Primary Business: Queensland, Australia  * Primary Business: Queensland, Australia
9   *  Licensed under the Open Software License version 3.0  * Licensed under the Open Software License version 3.0
10   *     http://www.opensource.org/licenses/osl-3.0.php  * http://www.opensource.org/licenses/osl-3.0.php
11   *  *
12   *******************************************************/  *******************************************************/
13    
14    
15  #include "FunctionSpace.h"  #include "FunctionSpace.h"
16  #include "FunctionSpaceException.h"  #include "FunctionSpaceException.h"
# Line 20  Line 19 
19    
20  #include <iostream>  #include <iostream>
21  #include <sstream>  #include <sstream>
22    #include <boost/smart_ptr.hpp>
23    
24  using namespace std;  using namespace std;
25    using namespace boost;
26    
27  namespace escript {  namespace escript {
28    
29    namespace
30    {
31  //  //
32  // Create a null domain for use with any default-constructed function space  // Create a null domain for use with any default-constructed function space
33  ESCRIPT_DLL_API NullDomain FunctionSpace::m_nullDomainValue;  // NullDomain const FunctionSpace::nullDomainValue;
34    const_Domain_ptr nullDomainValue(new NullDomain());
35    }
36    
37  FunctionSpace::FunctionSpace():  FunctionSpace::FunctionSpace():
38    m_domain(static_cast<AbstractDomain*>(&m_nullDomainValue)),  //   m_domain(static_cast<const AbstractDomain*>(&nullDomainValue)),
39    m_functionSpaceType(m_nullDomainValue.getFunctionCode())    m_domain(nullDomainValue),
40      m_functionSpaceType(dynamic_cast<const NullDomain*>(nullDomainValue.get())->getFunctionCode())
41  {  {
42  }  }
43    
44  FunctionSpace::FunctionSpace(const AbstractDomain& domain,  // FunctionSpace::FunctionSpace(const AbstractDomain& domain,
45    //                              int functionSpaceType):
46    // /*  m_domain(dynamic_cast<const AbstractDomain*>(&domain)),*/
47    //   m_domain(domain.getPtr()),
48    //   m_functionSpaceType(functionSpaceType)
49    // {
50    //   if (!m_domain->isValidFunctionSpaceType(functionSpaceType)) {
51    //     std::stringstream temp;
52    //     temp << "Invalid function space type: " << functionSpaceType
53    //   << " for domain: " << m_domain->getDescription();
54    //     throw FunctionSpaceException(temp.str());
55    //   }
56    // }
57    
58    FunctionSpace::FunctionSpace(const_Domain_ptr domain,
59                               int functionSpaceType):                               int functionSpaceType):
60    m_domain(dynamic_cast<const AbstractDomain*>(&domain)),  /*  m_domain(dynamic_cast<const AbstractDomain*>(&domain)),*/
61      m_domain(domain),
62    m_functionSpaceType(functionSpaceType)    m_functionSpaceType(functionSpaceType)
63  {  {
64    if (!m_domain->isValidFunctionSpaceType(functionSpaceType)) {    if (!m_domain->isValidFunctionSpaceType(functionSpaceType)) {
# Line 48  FunctionSpace::FunctionSpace(const Abstr Line 69  FunctionSpace::FunctionSpace(const Abstr
69    }    }
70  }  }
71    
72    FunctionSpace::FunctionSpace(const FunctionSpace& other)
73    :m_domain(other.m_domain),
74    m_functionSpaceType(other.m_functionSpaceType)
75    {
76    }
77    
78  std::pair<int,int>  std::pair<int,int>
79  FunctionSpace::getDataShape() const  FunctionSpace::getDataShape() const
80  {  {
# Line 60  FunctionSpace::getTypeCode() const Line 87  FunctionSpace::getTypeCode() const
87    return  m_functionSpaceType;    return  m_functionSpaceType;
88  }  }
89    
90  const  // const
91  AbstractDomain&  // AbstractDomain&
92    const_Domain_ptr
93  FunctionSpace::getDomain() const  FunctionSpace::getDomain() const
94  {  {
95    return *m_domain;    return m_domain;
96    }
97    
98    Domain_ptr
99    FunctionSpace::getDomainPython() const
100    {
101      // cast away the const-ness because python ignores it anyway
102      return const_pointer_cast<AbstractDomain>(m_domain);
103  }  }
104    
105    
106    
107  std::string  std::string
108  FunctionSpace::toString() const  FunctionSpace::toString() const
109  {  {
110    std::stringstream temp;    std::stringstream temp;
111    temp << m_domain->functionSpaceTypeAsString(m_functionSpaceType)    temp << m_domain->functionSpaceTypeAsString(m_functionSpaceType)
112         << " on " << m_domain->getDescription();         << " on " << m_domain->getDescription();
113    
114    return temp.str();    return temp.str();
115  }  }
116    
117    
118    #ifdef DEBUG_PY_STRINGS
119    PyObject *
120    FunctionSpace::toPyString() const
121    {
122      boost::python::to_python_value<const std::string &> cvtr;
123      std::stringstream temp;
124    
125      temp << m_domain->functionSpaceTypeAsString(m_functionSpaceType)
126           << " on " << m_domain->getDescription();
127    
128      return cvtr(temp.str());
129    }
130    #endif
131    
132    
133  int  int
134  FunctionSpace::getTagFromSampleNo(int sampleNo) const  FunctionSpace::getTagFromSampleNo(int sampleNo) const
135  {  {
# Line 112  FunctionSpace::getTagFromDataPointNo(int Line 166  FunctionSpace::getTagFromDataPointNo(int
166    return(tagNo);    return(tagNo);
167  }  }
168    
169    int FunctionSpace::getReferenceIDFromDataPointNo(int dataPointNo) const
170    {
171         //
172         // Get the number of samples and data-points per sample
173         int numSamples = getNumSamples();
174         int numDataPointsPerSample = getNumDPPSample();
175         int*referenceIDs= borrowSampleReferenceIDs();
176         int numDataPoints = numSamples * numDataPointsPerSample;
177    
178         if (numDataPointsPerSample==0) {
179            throw DataException("FunctionSpace::getReferenceIDFromDataPointNo error: no data-points associated with this object.");
180         }
181         if (dataPointNo<0 || dataPointNo>numDataPoints) {
182            throw DataException("FunctionSpace::getReferenceIDFromDataPointNo error: invalid data-point number supplied.");
183         }
184         int sampleNo = dataPointNo / numDataPointsPerSample;
185         return referenceIDs[sampleNo];
186    }
187    
188  int*  int*
189  FunctionSpace::borrowSampleReferenceIDs() const  FunctionSpace::borrowSampleReferenceIDs() const
190  {  {
191    return m_domain->borrowSampleReferenceIDs(m_functionSpaceType);    return m_domain->borrowSampleReferenceIDs(m_functionSpaceType);
192  }  }
193    
194    // FunctionSpace instances should not be overwritten to point to different domains/types
195    // The only time this was actually used was in constructors and the copy constructor can deal with that
196  FunctionSpace&  FunctionSpace&
197  FunctionSpace::operator=(const FunctionSpace& other)  FunctionSpace::operator=(const FunctionSpace& other)
198  {  {
199      throw DataException("FunctionSpace::= should not be called. Programming Error.");
200    // explicitly defined assignment operator to emphasise pointer copy    // explicitly defined assignment operator to emphasise pointer copy
201    m_nullDomainValue=other.m_nullDomainValue;  /*  m_functionSpaceType=other.m_functionSpaceType;
   m_functionSpaceType=other.m_functionSpaceType;  
202    m_domain=other.m_domain;    m_domain=other.m_domain;
203    return *this;    return *this;*/
204  }  }
205    
206  bool  bool
# Line 144  escript::Data Line 219  escript::Data
219  FunctionSpace::getX() const  FunctionSpace::getX() const
220  {  {
221    Data out=escript::Vector(0,*this,true);    Data out=escript::Vector(0,*this,true);
222    getDomain().setToX(out);    getDomain()->setToX(out);
223    out.setProtection();    out.setProtection();
224    return out;    return out;
225  }  }
# Line 153  escript::Data Line 228  escript::Data
228  FunctionSpace::getNormal() const  FunctionSpace::getNormal() const
229  {  {
230    Data out=escript::Vector(0,*this,true);    Data out=escript::Vector(0,*this,true);
231    getDomain().setToNormal(out);    getDomain()->setToNormal(out);
232    out.setProtection();    out.setProtection();
233    return out;    return out;
234  }  }
# Line 162  escript::Data Line 237  escript::Data
237  FunctionSpace::getSize() const  FunctionSpace::getSize() const
238  {  {
239    Data out=escript::Scalar(0,*this,true);    Data out=escript::Scalar(0,*this,true);
240    getDomain().setToSize(out);    getDomain()->setToSize(out);
241    out.setProtection();    out.setProtection();
242    return out;    return out;
243  }  }
# Line 177  FunctionSpace::setTags(const int newTag, Line 252  FunctionSpace::setTags(const int newTag,
252     }     }
253  }  }
254    
255    int
256    FunctionSpace::getNumberOfTagsInUse() const
257    {
258       return  m_domain->getNumberOfTagsInUse(m_functionSpaceType);
259    }
260    
261    int*
262    FunctionSpace::borrowListOfTagsInUse() const
263    {
264       return  m_domain->borrowListOfTagsInUse(m_functionSpaceType);
265    }
266    
267    std::list<int>
268    FunctionSpace::getListOfTagsSTL() const
269    {
270      std::list<int> taglist;
271      int i;
272      int* tags=borrowListOfTagsInUse();
273      for (i=0;i<getNumberOfTagsInUse();++i) taglist.push_back(tags[i]);
274      return taglist;
275    }
276    
277    
278    boost::python::list
279    FunctionSpace::getListOfTags() const
280    {
281      boost::python::list taglist;
282      int i;
283      int* tags=borrowListOfTagsInUse();
284      for (i=0;i<getNumberOfTagsInUse();++i) taglist.append(tags[i]);
285      return taglist;
286    }
287    
288    bool
289    FunctionSpace::canTag() const
290    {
291      return m_domain->canTag(m_functionSpaceType);
292    }
293    
294  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.1388  
changed lines
  Added in v.1872

  ViewVC Help
Powered by ViewVC 1.1.26