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

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

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

revision 110 by jgs, Mon Feb 14 04:14:42 2005 UTC revision 149 by jgs, Thu Sep 1 03:31:39 2005 UTC
# Line 1  Line 1 
1    /* $Id$ */
2  /*  /*
3   ******************************************************************************   ******************************************************************************
4   *                                                                            *   *                                                                            *
# Line 22  Line 23 
23  #include <iostream>  #include <iostream>
24  #include <sstream>  #include <sstream>
25    
26    using namespace std;
27    
28  namespace escript {  namespace escript {
29    
30  //  //
31  // Create a null domain for use with a default constructed function space  // Create a null domain for use with any default-constructed function space
32  NullDomain FunctionSpace::m_nullDomainValue;  NullDomain FunctionSpace::m_nullDomainValue;
33    
34  FunctionSpace::FunctionSpace():  FunctionSpace::FunctionSpace():
35    m_domain(static_cast<AbstractDomain*>(&m_nullDomainValue)),    m_domain(static_cast<AbstractDomain*>(&m_nullDomainValue)),
36    m_functionSpaceType(m_nullDomainValue.getFunctionCode())    m_functionSpaceType(m_nullDomainValue.getFunctionCode())
37  {  {
   //std::cout << "Called FunctionSpace DEFAULT constructor." << std::endl;  
38  }  }
39    
40  FunctionSpace::FunctionSpace(const AbstractDomain& domain, int functionSpaceType):  FunctionSpace::FunctionSpace(const AbstractDomain& domain,
41                                 int functionSpaceType):
42    m_domain(dynamic_cast<const AbstractDomain*>(&domain)),    m_domain(dynamic_cast<const AbstractDomain*>(&domain)),
43    m_functionSpaceType(functionSpaceType)    m_functionSpaceType(functionSpaceType)
44  {  {
   //std::cout << "Called FunctionSpace constructor." << std::endl;  
45    if (!m_domain->isValidFunctionSpaceType(functionSpaceType)) {    if (!m_domain->isValidFunctionSpaceType(functionSpaceType)) {
46      std::stringstream temp;      std::stringstream temp;
47      temp << "Invalid function space type: " << functionSpaceType      temp << "Invalid function space type: " << functionSpaceType
48       <<" for domain: " << m_domain->getDescription();       << " for domain: " << m_domain->getDescription();
49      throw FunctionSpaceException(temp.str());      throw FunctionSpaceException(temp.str());
50    }    }
51  }  }
52    
53  std::pair<int,int> FunctionSpace::getDataShape() const  std::pair<int,int>
54    FunctionSpace::getDataShape() const
55  {  {
56    return m_domain->getDataShape(m_functionSpaceType);    return m_domain->getDataShape(m_functionSpaceType);
57  }  }
58    
59  int FunctionSpace::getTypeCode() const  int
60    FunctionSpace::getTypeCode() const
61  {  {
62    return  m_functionSpaceType;    return  m_functionSpaceType;
63  }  }
64    
65  const AbstractDomain& FunctionSpace::getDomain() const  const
66    AbstractDomain&
67    FunctionSpace::getDomain() const
68  {  {
69    return *m_domain;    return *m_domain;
70  }  }
71    
72  std::string FunctionSpace::toString() const  std::string
73    FunctionSpace::toString() const
74  {  {
75    std::stringstream temp;    std::stringstream temp;
76    temp << "Function space type: "    temp << "Function space type: "
# Line 72  std::string FunctionSpace::toString() co Line 79  std::string FunctionSpace::toString() co
79    return temp.str();    return temp.str();
80  }  }
81    
82  int FunctionSpace::getTagFromSampleNo(int sampleNo) const  int
83    FunctionSpace::getTagFromSampleNo(int sampleNo) const
84  {  {
85    return m_domain->getTagFromSampleNo(m_functionSpaceType,sampleNo);    return m_domain->getTagFromSampleNo(m_functionSpaceType,sampleNo);
86  }  }
87    
88  int FunctionSpace::getReferenceNoFromSampleNo(int sampleNo) const  int
89    FunctionSpace::getTagFromDataPointNo(int dataPointNo) const
90    {
91      //
92      // Get the number of samples and data-points per sample
93      int numSamples = getNumSamples();
94      int numDataPointsPerSample = getNumDPPSample();
95      int numDataPoints = numSamples * numDataPointsPerSample;
96    
97      if (numDataPointsPerSample==0) {
98        throw DataException("FunctionSpace::getTagFromDataPointNo error: no data-points associated with this object.");
99      }
100    
101      if (dataPointNo<0 || dataPointNo>numDataPoints) {
102        throw DataException("FunctionSpace::getTagFromDataPointNo error: invalid data-point number supplied.");
103      }
104    
105      //
106      // Determine the sample number which corresponds to this data-point number
107      int sampleNo = dataPointNo / numDataPointsPerSample;
108    
109      //
110      // Determine the tag number which corresponds to this sample number
111      int tagNo = getTagFromSampleNo(sampleNo);
112    
113      //
114      // return the tag number
115      return(tagNo);
116    }
117    
118    int
119    FunctionSpace::getReferenceNoFromSampleNo(int sampleNo) const
120  {  {
121    return m_domain->getReferenceNoFromSampleNo(m_functionSpaceType,sampleNo);    return m_domain->getReferenceNoFromSampleNo(m_functionSpaceType,sampleNo);
122  }  }
123    
124  FunctionSpace& FunctionSpace::operator=(const FunctionSpace& other)  FunctionSpace&
125    FunctionSpace::operator=(const FunctionSpace& other)
126  {  {
   //  
127    // explicitly defined assignment operator to emphasise pointer copy    // explicitly defined assignment operator to emphasise pointer copy
128    m_nullDomainValue=other.m_nullDomainValue;    m_nullDomainValue=other.m_nullDomainValue;
129    m_functionSpaceType=other.m_functionSpaceType;    m_functionSpaceType=other.m_functionSpaceType;
# Line 92  FunctionSpace& FunctionSpace::operator=( Line 131  FunctionSpace& FunctionSpace::operator=(
131    return *this;    return *this;
132  }  }
133    
134  bool FunctionSpace::operator==(const FunctionSpace& other) const  bool
135    FunctionSpace::operator==(const FunctionSpace& other) const
136  {  {
137    return (other.m_domain==m_domain && other.m_functionSpaceType==m_functionSpaceType);    return ((*(other.m_domain)==*(m_domain)) && (other.m_functionSpaceType==m_functionSpaceType));
138  }  }
139    
140  bool FunctionSpace::operator!=(const FunctionSpace& other) const  bool
141    FunctionSpace::operator!=(const FunctionSpace& other) const
142  {  {
143    return (!(other==*this));    return !(operator==(other));
144  }  }
145    
146  escript::Data FunctionSpace::getX() const  escript::Data
147    FunctionSpace::getX() const
148  {  {
149    Data out=escript::Vector(0,*this,true);    Data out=escript::Vector(0,*this,true);
150    getDomain().setToX(out);    getDomain().setToX(out);
151    return out;    return out;
152  }  }
153    
154  escript::Data FunctionSpace::getNormal() const  escript::Data
155    FunctionSpace::getNormal() const
156  {  {
157    Data out=escript::Vector(0,*this,true);    Data out=escript::Vector(0,*this,true);
158    getDomain().setToNormal(out);    getDomain().setToNormal(out);
159    return out;    return out;
160  }  }
161    
162  escript::Data FunctionSpace::getSize() const  escript::Data
163    FunctionSpace::getSize() const
164  {  {
165    Data out=escript::Scalar(0,*this,true);    Data out=escript::Scalar(0,*this,true);
166    getDomain().setToSize(out);    getDomain().setToSize(out);

Legend:
Removed from v.110  
changed lines
  Added in v.149

  ViewVC Help
Powered by ViewVC 1.1.26