/[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 1871 by ksteube, Thu Sep 25 23:11:13 2008 UTC revision 1872 by jfenwick, Mon Oct 13 00:18:55 2008 UTC
# Line 19  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  NullDomain const FunctionSpace::nullDomainValue;  // NullDomain const FunctionSpace::nullDomainValue;
34    const_Domain_ptr nullDomainValue(new NullDomain());
35    }
36    
37  FunctionSpace::FunctionSpace():  FunctionSpace::FunctionSpace():
38    m_domain(static_cast<const AbstractDomain*>(&nullDomainValue)),  //   m_domain(static_cast<const AbstractDomain*>(&nullDomainValue)),
39    m_functionSpaceType(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 47  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 59  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  {  {
# Line 153  FunctionSpace::borrowSampleReferenceIDs( Line 191  FunctionSpace::borrowSampleReferenceIDs(
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_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 178  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 187  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 196  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  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26