/[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 147 by jgs, Fri Aug 12 01:45:47 2005 UTC trunk/escript/src/FunctionSpace.cpp revision 1426 by trankine, Wed Feb 27 06:12:15 2008 UTC
# Line 1  Line 1 
1    
2  /* $Id$ */  /* $Id$ */
 /*  
  ******************************************************************************  
  *                                                                            *  
  *       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"  
3    
4  #include "escript/Data/FunctionSpace.h"  /*******************************************************
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;  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  {  {
36  }  }
37    
# Line 44  FunctionSpace::FunctionSpace(const Abstr Line 43  FunctionSpace::FunctionSpace(const Abstr
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  }  }
# Line 68  FunctionSpace::getDomain() const Line 67  FunctionSpace::getDomain() const
67    return *m_domain;    return *m_domain;
68  }  }
69    
70  std::string  const std::string &
71  FunctionSpace::toString() const  FunctionSpace::toString() const
72  {  {
73    std::stringstream temp;    std::stringstream temp;
74    temp << "Function space type: "    temp << m_domain->functionSpaceTypeAsString(m_functionSpaceType)
75         << m_domain->functionSpaceTypeAsString(m_functionSpaceType)         << " on " << m_domain->getDescription();
76    
77      type_str = temp.str();
78    
79      return type_str;
80    }
81    
82    
83    #ifdef DEBUG_PY_STRINGS
84    PyObject *
85    FunctionSpace::toPyString() const
86    {
87      boost::python::to_python_value<const std::string &> cvtr;
88      std::stringstream temp;
89    
90      temp << m_domain->functionSpaceTypeAsString(m_functionSpaceType)
91         << " on " << m_domain->getDescription();         << " on " << m_domain->getDescription();
92    return temp.str();  
93      //toString();
94      type_str = temp.str();
95    
96      return cvtr(type_str);
97  }  }
98    #endif
99    
100    
101  int  int
102  FunctionSpace::getTagFromSampleNo(int sampleNo) const  FunctionSpace::getTagFromSampleNo(int sampleNo) const
# Line 85  FunctionSpace::getTagFromSampleNo(int sa Line 105  FunctionSpace::getTagFromSampleNo(int sa
105  }  }
106    
107  int  int
108  FunctionSpace::getReferenceNoFromSampleNo(int sampleNo) const  FunctionSpace::getTagFromDataPointNo(int dataPointNo) const
109    {
110      //
111      // Get the number of samples and data-points per sample
112      int numSamples = getNumSamples();
113      int numDataPointsPerSample = getNumDPPSample();
114      int numDataPoints = numSamples * numDataPointsPerSample;
115    
116      if (numDataPointsPerSample==0) {
117        throw DataException("FunctionSpace::getTagFromDataPointNo error: no data-points associated with this object.");
118      }
119    
120      if (dataPointNo<0 || dataPointNo>numDataPoints) {
121        throw DataException("FunctionSpace::getTagFromDataPointNo error: invalid data-point number supplied.");
122      }
123    
124      //
125      // Determine the sample number which corresponds to this data-point number
126      int sampleNo = dataPointNo / numDataPointsPerSample;
127    
128      //
129      // Determine the tag number which corresponds to this sample number
130      int tagNo = getTagFromSampleNo(sampleNo);
131    
132      //
133      // return the tag number
134      return(tagNo);
135    }
136    
137    int*
138    FunctionSpace::borrowSampleReferenceIDs() const
139  {  {
140    return m_domain->getReferenceNoFromSampleNo(m_functionSpaceType,sampleNo);    return m_domain->borrowSampleReferenceIDs(m_functionSpaceType);
141  }  }
142    
143  FunctionSpace&  FunctionSpace&
144  FunctionSpace::operator=(const FunctionSpace& other)  FunctionSpace::operator=(const FunctionSpace& other)
145  {  {
   //  
146    // explicitly defined assignment operator to emphasise pointer copy    // explicitly defined assignment operator to emphasise pointer copy
   m_nullDomainValue=other.m_nullDomainValue;  
147    m_functionSpaceType=other.m_functionSpaceType;    m_functionSpaceType=other.m_functionSpaceType;
148    m_domain=other.m_domain;    m_domain=other.m_domain;
149    return *this;    return *this;
# Line 118  FunctionSpace::getX() const Line 166  FunctionSpace::getX() const
166  {  {
167    Data out=escript::Vector(0,*this,true);    Data out=escript::Vector(0,*this,true);
168    getDomain().setToX(out);    getDomain().setToX(out);
169      out.setProtection();
170    return out;    return out;
171  }  }
172    
# Line 126  FunctionSpace::getNormal() const Line 175  FunctionSpace::getNormal() const
175  {  {
176    Data out=escript::Vector(0,*this,true);    Data out=escript::Vector(0,*this,true);
177    getDomain().setToNormal(out);    getDomain().setToNormal(out);
178      out.setProtection();
179    return out;    return out;
180  }  }
181    
# Line 134  FunctionSpace::getSize() const Line 184  FunctionSpace::getSize() const
184  {  {
185    Data out=escript::Scalar(0,*this,true);    Data out=escript::Scalar(0,*this,true);
186    getDomain().setToSize(out);    getDomain().setToSize(out);
187      out.setProtection();
188    return out;    return out;
189  }  }
190    
191    void
192    FunctionSpace::setTags(const int newTag, const escript::Data& mask) const
193    {
194       if (mask.getFunctionSpace()== *this) {
195              m_domain->setTags(m_functionSpaceType,newTag,mask);
196       } else {
197              throw FunctionSpaceException("illegal function space of mask.");
198       }
199    }
200    
201  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.147  
changed lines
  Added in v.1426

  ViewVC Help
Powered by ViewVC 1.1.26