/[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 110 by jgs, Mon Feb 14 04:14:42 2005 UTC trunk/escript/src/FunctionSpace.cpp revision 1137 by gross, Thu May 10 08:11:31 2007 UTC
# Line 1  Line 1 
1    /* $Id$ */
2  /*  /*
3   ******************************************************************************   ************************************************************
4   *                                                                            *   *          Copyright 2006 by ACcESS MNRF                   *
5   *       COPYRIGHT  ACcESS 2004 -  All Rights Reserved                        *   *                                                          *
6   *                                                                            *   *              http://www.access.edu.au                    *
7   * This software is the property of ACcESS. No part of this code              *   *       Primary Business: Queensland, Australia            *
8   * may be copied in any form or by any means without the expressed written    *   *  Licensed under the Open Software License version 3.0    *
9   * consent of ACcESS.  Copying, use or modification of this software          *   *     http://www.opensource.org/licenses/osl-3.0.php       *
10   * by any unauthorised person is illegal unless that person has a software    *   *                                                          *
11   * license agreement with ACcESS.                                             *   ************************************************************
  *                                                                            *  
  ******************************************************************************  
12  */  */
13    
14  #include "escript/Data/AbstractContinuousDomain.h"  #include "FunctionSpace.h"
15  #include "escript/Data/FunctionSpaceException.h"  #include "FunctionSpaceException.h"
16  #include "escript/Data/Data.h"  #include "Data.h"
17  #include "escript/Data/DataFactory.h"  #include "DataFactory.h"
   
 #include "escript/Data/FunctionSpace.h"  
18    
19  #include <iostream>  #include <iostream>
20  #include <sstream>  #include <sstream>
21    
22    using namespace std;
23    
24  namespace escript {  namespace escript {
25    
26  //  //
27  // Create a null domain for use with a default constructed function space  // Create a null domain for use with any default-constructed function space
28  NullDomain FunctionSpace::m_nullDomainValue;  ESCRIPT_DLL_API NullDomain FunctionSpace::m_nullDomainValue;
29    
30  FunctionSpace::FunctionSpace():  FunctionSpace::FunctionSpace():
31    m_domain(static_cast<AbstractDomain*>(&m_nullDomainValue)),    m_domain(static_cast<AbstractDomain*>(&m_nullDomainValue)),
32    m_functionSpaceType(m_nullDomainValue.getFunctionCode())    m_functionSpaceType(m_nullDomainValue.getFunctionCode())
33  {  {
   //std::cout << "Called FunctionSpace DEFAULT constructor." << std::endl;  
34  }  }
35    
36  FunctionSpace::FunctionSpace(const AbstractDomain& domain, int functionSpaceType):  FunctionSpace::FunctionSpace(const AbstractDomain& domain,
37                                 int functionSpaceType):
38    m_domain(dynamic_cast<const AbstractDomain*>(&domain)),    m_domain(dynamic_cast<const AbstractDomain*>(&domain)),
39    m_functionSpaceType(functionSpaceType)    m_functionSpaceType(functionSpaceType)
40  {  {
   //std::cout << "Called FunctionSpace constructor." << std::endl;  
41    if (!m_domain->isValidFunctionSpaceType(functionSpaceType)) {    if (!m_domain->isValidFunctionSpaceType(functionSpaceType)) {
42      std::stringstream temp;      std::stringstream temp;
43      temp << "Invalid function space type: " << functionSpaceType      temp << "Invalid function space type: " << functionSpaceType
44       <<" for domain: " << m_domain->getDescription();       << " for domain: " << m_domain->getDescription();
45      throw FunctionSpaceException(temp.str());      throw FunctionSpaceException(temp.str());
46    }    }
47  }  }
48    
49  std::pair<int,int> FunctionSpace::getDataShape() const  std::pair<int,int>
50    FunctionSpace::getDataShape() const
51  {  {
52    return m_domain->getDataShape(m_functionSpaceType);    return m_domain->getDataShape(m_functionSpaceType);
53  }  }
54    
55  int FunctionSpace::getTypeCode() const  int
56    FunctionSpace::getTypeCode() const
57  {  {
58    return  m_functionSpaceType;    return  m_functionSpaceType;
59  }  }
60    
61  const AbstractDomain& FunctionSpace::getDomain() const  const
62    AbstractDomain&
63    FunctionSpace::getDomain() const
64  {  {
65    return *m_domain;    return *m_domain;
66  }  }
67    
68  std::string FunctionSpace::toString() const  std::string
69    FunctionSpace::toString() const
70  {  {
71    std::stringstream temp;    std::stringstream temp;
72    temp << "Function space type: "    temp << m_domain->functionSpaceTypeAsString(m_functionSpaceType) << " on " << m_domain->getDescription();
        << m_domain->functionSpaceTypeAsString(m_functionSpaceType)  
        << " on " << m_domain->getDescription();  
73    return temp.str();    return temp.str();
74  }  }
75    
76  int FunctionSpace::getTagFromSampleNo(int sampleNo) const  const
77    boost::python::str
78    FunctionSpace::str() const
79  {  {
80    return m_domain->getTagFromSampleNo(m_functionSpaceType,sampleNo);    return boost::python::str(toString().c_str());
81  }  }
82    
83  int FunctionSpace::getReferenceNoFromSampleNo(int sampleNo) const  
84    int
85    FunctionSpace::getTagFromSampleNo(int sampleNo) const
86  {  {
87    return m_domain->getReferenceNoFromSampleNo(m_functionSpaceType,sampleNo);    return m_domain->getTagFromSampleNo(m_functionSpaceType,sampleNo);
88  }  }
89    
90  FunctionSpace& FunctionSpace::operator=(const FunctionSpace& other)  int
91    FunctionSpace::getTagFromDataPointNo(int dataPointNo) const
92  {  {
93    //    //
94      // Get the number of samples and data-points per sample
95      int numSamples = getNumSamples();
96      int numDataPointsPerSample = getNumDPPSample();
97      int numDataPoints = numSamples * numDataPointsPerSample;
98    
99      if (numDataPointsPerSample==0) {
100        throw DataException("FunctionSpace::getTagFromDataPointNo error: no data-points associated with this object.");
101      }
102    
103      if (dataPointNo<0 || dataPointNo>numDataPoints) {
104        throw DataException("FunctionSpace::getTagFromDataPointNo error: invalid data-point number supplied.");
105      }
106    
107      //
108      // Determine the sample number which corresponds to this data-point number
109      int sampleNo = dataPointNo / numDataPointsPerSample;
110    
111      //
112      // Determine the tag number which corresponds to this sample number
113      int tagNo = getTagFromSampleNo(sampleNo);
114    
115      //
116      // return the tag number
117      return(tagNo);
118    }
119    
120    int*
121    FunctionSpace::borrowSampleReferenceIDs() const
122    {
123      return m_domain->borrowSampleReferenceIDs(m_functionSpaceType);
124    }
125    
126    FunctionSpace&
127    FunctionSpace::operator=(const FunctionSpace& other)
128    {
129    // explicitly defined assignment operator to emphasise pointer copy    // explicitly defined assignment operator to emphasise pointer copy
130    m_nullDomainValue=other.m_nullDomainValue;    m_nullDomainValue=other.m_nullDomainValue;
131    m_functionSpaceType=other.m_functionSpaceType;    m_functionSpaceType=other.m_functionSpaceType;
# Line 92  FunctionSpace& FunctionSpace::operator=( Line 133  FunctionSpace& FunctionSpace::operator=(
133    return *this;    return *this;
134  }  }
135    
136  bool FunctionSpace::operator==(const FunctionSpace& other) const  bool
137    FunctionSpace::operator==(const FunctionSpace& other) const
138  {  {
139    return (other.m_domain==m_domain && other.m_functionSpaceType==m_functionSpaceType);    return ((*(other.m_domain)==*(m_domain)) && (other.m_functionSpaceType==m_functionSpaceType));
140  }  }
141    
142  bool FunctionSpace::operator!=(const FunctionSpace& other) const  bool
143    FunctionSpace::operator!=(const FunctionSpace& other) const
144  {  {
145    return (!(other==*this));    return !(operator==(other));
146  }  }
147    
148  escript::Data FunctionSpace::getX() const  escript::Data
149    FunctionSpace::getX() const
150  {  {
151    Data out=escript::Vector(0,*this,true);    Data out=escript::Vector(0,*this,true);
152    getDomain().setToX(out);    getDomain().setToX(out);
153      out.setProtection();
154    return out;    return out;
155  }  }
156    
157  escript::Data FunctionSpace::getNormal() const  escript::Data
158    FunctionSpace::getNormal() const
159  {  {
160    Data out=escript::Vector(0,*this,true);    Data out=escript::Vector(0,*this,true);
161    getDomain().setToNormal(out);    getDomain().setToNormal(out);
162      out.setProtection();
163    return out;    return out;
164  }  }
165    
166  escript::Data FunctionSpace::getSize() const  escript::Data
167    FunctionSpace::getSize() const
168  {  {
169    Data out=escript::Scalar(0,*this,true);    Data out=escript::Scalar(0,*this,true);
170    getDomain().setToSize(out);    getDomain().setToSize(out);
171      out.setProtection();
172    return out;    return out;
173  }  }
174    
175    void
176    FunctionSpace::setTags(const int newTag, const escript::Data& mask) const
177    {
178       if (mask.getFunctionSpace()== *this) {
179              m_domain->setTags(m_functionSpaceType,newTag,mask);
180       } else {
181              throw FunctionSpaceException("illegal function space of mask.");
182       }
183    }
184    
185  }  // end of namespace  }  // end of namespace

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

  ViewVC Help
Powered by ViewVC 1.1.26