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

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

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

revision 1871 by gross, Wed Oct 8 03:03:37 2008 UTC revision 1872 by jfenwick, Mon Oct 13 00:18:55 2008 UTC
# Line 46  Data::Data() Line 46  Data::Data()
46    //    //
47    // Default data is type DataEmpty    // Default data is type DataEmpty
48    DataAbstract* temp=new DataEmpty();    DataAbstract* temp=new DataEmpty();
49    shared_ptr<DataAbstract> temp_data(temp);    m_data=temp->getPtr();
   m_data=temp_data;  
50    m_protected=false;    m_protected=false;
51  }  }
52    
# Line 63  Data::Data(double value, Line 62  Data::Data(double value,
62    
63    int len = DataTypes::noValues(dataPointShape);    int len = DataTypes::noValues(dataPointShape);
64    DataVector temp_data(len,value,len);    DataVector temp_data(len,value,len);
 //   DataArrayView temp_dataView(temp_data, dataPointShape);  
   
 //   initialise(temp_dataView, what, expanded);  
65    initialise(temp_data, dataPointShape, what, expanded);    initialise(temp_data, dataPointShape, what, expanded);
   
66    m_protected=false;    m_protected=false;
67  }  }
68    
# Line 100  Data::Data(const Data& inData, Line 95  Data::Data(const Data& inData,
95    //    //
96    // Create Data which is a slice of another Data    // Create Data which is a slice of another Data
97    DataAbstract* tmp = inData.m_data->getSlice(region);    DataAbstract* tmp = inData.m_data->getSlice(region);
98    shared_ptr<DataAbstract> temp_data(tmp);    m_data=DataAbstract_ptr(tmp);
   m_data=temp_data;  
99    m_protected=false;    m_protected=false;
100  }  }
101    
# Line 120  Data::Data(const Data& inData, Line 114  Data::Data(const Data& inData,
114      throw FunctionSpaceException("Call to probeInterpolation returned false for DataConstant.");      throw FunctionSpaceException("Call to probeInterpolation returned false for DataConstant.");
115      }      }
116      DataConstant* dc=new DataConstant(functionspace,inData.m_data->getShape(),inData.m_data->getVector());        DataConstant* dc=new DataConstant(functionspace,inData.m_data->getShape(),inData.m_data->getVector());  
117      m_data=shared_ptr<DataAbstract>(dc);      m_data=DataAbstract_ptr(dc);
118    } else {    } else {
119      Data tmp(0,inData.getDataPointShape(),functionspace,true);      Data tmp(0,inData.getDataPointShape(),functionspace,true);
120      // Note: Must use a reference or pointer to a derived object      // Note: Must use a reference or pointer to a derived object
121      // in order to get polymorphic behaviour. Shouldn't really      // in order to get polymorphic behaviour. Shouldn't really
122      // be able to create an instance of AbstractDomain but that was done      // be able to create an instance of AbstractDomain but that was done
123      // as a boost:python work around which may no longer be required.      // as a boost:python work around which may no longer be required.
124      const AbstractDomain& inDataDomain=inData.getDomain();      /*const AbstractDomain& inDataDomain=inData.getDomain();*/
125        const_Domain_ptr inDataDomain=inData.getDomain();
126      if  (inDataDomain==functionspace.getDomain()) {      if  (inDataDomain==functionspace.getDomain()) {
127        inDataDomain.interpolateOnDomain(tmp,inData);        inDataDomain->interpolateOnDomain(tmp,inData);
128      } else {      } else {
129        inDataDomain.interpolateACross(tmp,inData);        inDataDomain->interpolateACross(tmp,inData);
130      }      }
131      m_data=tmp.m_data;      m_data=tmp.m_data;
132    }    }
133    m_protected=false;    m_protected=false;
134  }  }
135    
 // Data::Data(const DataTagged::TagListType& tagKeys,  
 //            const DataTagged::ValueListType & values,  
 //            const DataArrayView& defaultValue,  
 //            const FunctionSpace& what,  
 //            bool expanded)  
 // {  
 //   DataAbstract* temp=new DataTagged(tagKeys,values,defaultValue,what);  
 //   shared_ptr<DataAbstract> temp_data(temp);  
 //   m_data=temp_data;  
 //   m_protected=false;  
 //   if (expanded) {  
 //     expand();  
 //   }  
 // }  
   
   
   
136  Data::Data(DataAbstract* underlyingdata)  Data::Data(DataAbstract* underlyingdata)
137  {  {
138      m_data=shared_ptr<DataAbstract>(underlyingdata);  //  m_data=shared_ptr<DataAbstract>(underlyingdata);
139        m_data=underlyingdata->getPtr();
140      m_protected=false;      m_protected=false;
141  }  }
142    
# Line 234  Data::Data(const object& value, Line 213  Data::Data(const object& value,
213  //     initialise(temp2_dataView, other.getFunctionSpace(), false);  //     initialise(temp2_dataView, other.getFunctionSpace(), false);
214    
215      DataConstant* t=new DataConstant(other.getFunctionSpace(),other.getDataPointShape(),temp2_data);      DataConstant* t=new DataConstant(other.getFunctionSpace(),other.getDataPointShape(),temp2_data);
216      boost::shared_ptr<DataAbstract> sp(t);  //     boost::shared_ptr<DataAbstract> sp(t);
217      m_data=sp;  //     m_data=sp;
218        m_data=DataAbstract_ptr(t);
219    
220    } else {    } else {
221      //      //
222      // Create a DataConstant with the same sample shape as other      // Create a DataConstant with the same sample shape as other
223  //     initialise(temp_dataView, other.getFunctionSpace(), false);  //     initialise(temp_dataView, other.getFunctionSpace(), false);
224      DataConstant* t=new DataConstant(asNumArray,other.getFunctionSpace());      DataConstant* t=new DataConstant(asNumArray,other.getFunctionSpace());
225      boost::shared_ptr<DataAbstract> sp(t);  //     boost::shared_ptr<DataAbstract> sp(t);
226      m_data=sp;  //     m_data=sp;
227        m_data=DataAbstract_ptr(t);
228    }    }
229    m_protected=false;    m_protected=false;
230  }  }
# Line 268  Data::initialise(const boost::python::nu Line 248  Data::initialise(const boost::python::nu
248    // within the shared_ptr constructor.    // within the shared_ptr constructor.
249    if (expanded) {    if (expanded) {
250      DataAbstract* temp=new DataExpanded(value, what);      DataAbstract* temp=new DataExpanded(value, what);
251      boost::shared_ptr<DataAbstract> temp_data(temp);  //     boost::shared_ptr<DataAbstract> temp_data(temp);
252      m_data=temp_data;  //     m_data=temp_data;
253        m_data=temp->getPtr();
254    } else {    } else {
255      DataAbstract* temp=new DataConstant(value, what);      DataAbstract* temp=new DataConstant(value, what);
256      boost::shared_ptr<DataAbstract> temp_data(temp);  //     boost::shared_ptr<DataAbstract> temp_data(temp);
257      m_data=temp_data;  //     m_data=temp_data;
258        m_data=temp->getPtr();
259    }    }
260  }  }
261    
# Line 291  Data::initialise(const DataTypes::ValueT Line 273  Data::initialise(const DataTypes::ValueT
273    // within the shared_ptr constructor.    // within the shared_ptr constructor.
274    if (expanded) {    if (expanded) {
275      DataAbstract* temp=new DataExpanded(what, shape, value);      DataAbstract* temp=new DataExpanded(what, shape, value);
276      boost::shared_ptr<DataAbstract> temp_data(temp);  //     boost::shared_ptr<DataAbstract> temp_data(temp);
277      m_data=temp_data;  //     m_data=temp_data;
278        m_data=temp->getPtr();
279    } else {    } else {
280      DataAbstract* temp=new DataConstant(what, shape, value);      DataAbstract* temp=new DataConstant(what, shape, value);
281      boost::shared_ptr<DataAbstract> temp_data(temp);  //     boost::shared_ptr<DataAbstract> temp_data(temp);
282      m_data=temp_data;  //     m_data=temp_data;
283        m_data=temp->getPtr();
284    }    }
285  }  }
286    
# Line 433  void Line 417  void
417  Data::copy(const Data& other)  Data::copy(const Data& other)
418  {  {
419    DataAbstract* temp=other.m_data->deepCopy();    DataAbstract* temp=other.m_data->deepCopy();
420    shared_ptr<DataAbstract> temp_data(temp);    DataAbstract_ptr p=temp->getPtr();
421    m_data=temp_data;    m_data=p;
422  }  }
423    
424    
# Line 617  Data::expand() Line 601  Data::expand()
601    if (isConstant()) {    if (isConstant()) {
602      DataConstant* tempDataConst=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* tempDataConst=dynamic_cast<DataConstant*>(m_data.get());
603      DataAbstract* temp=new DataExpanded(*tempDataConst);      DataAbstract* temp=new DataExpanded(*tempDataConst);
604      shared_ptr<DataAbstract> temp_data(temp);  //     shared_ptr<DataAbstract> temp_data(temp);
605      m_data=temp_data;  //     m_data=temp_data;
606        m_data=temp->getPtr();
607    } else if (isTagged()) {    } else if (isTagged()) {
608      DataTagged* tempDataTag=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* tempDataTag=dynamic_cast<DataTagged*>(m_data.get());
609      DataAbstract* temp=new DataExpanded(*tempDataTag);      DataAbstract* temp=new DataExpanded(*tempDataTag);
610      shared_ptr<DataAbstract> temp_data(temp);  //     shared_ptr<DataAbstract> temp_data(temp);
611      m_data=temp_data;  //     m_data=temp_data;
612        m_data=temp->getPtr();
613    } else if (isExpanded()) {    } else if (isExpanded()) {
614      //      //
615      // do nothing      // do nothing
# Line 640  Data::tag() Line 626  Data::tag()
626    if (isConstant()) {    if (isConstant()) {
627      DataConstant* tempDataConst=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* tempDataConst=dynamic_cast<DataConstant*>(m_data.get());
628      DataAbstract* temp=new DataTagged(*tempDataConst);      DataAbstract* temp=new DataTagged(*tempDataConst);
629      shared_ptr<DataAbstract> temp_data(temp);  //     shared_ptr<DataAbstract> temp_data(temp);
630      m_data=temp_data;  //     m_data=temp_data;
631        m_data=temp->getPtr();
632    } else if (isTagged()) {    } else if (isTagged()) {
633      // do nothing      // do nothing
634    } else if (isExpanded()) {    } else if (isExpanded()) {
# Line 709  Data::probeInterpolation(const FunctionS Line 696  Data::probeInterpolation(const FunctionS
696    if (getFunctionSpace()==functionspace) {    if (getFunctionSpace()==functionspace) {
697      return true;      return true;
698    } else {    } else {
699      const AbstractDomain& domain=getDomain();      const_Domain_ptr domain=getDomain();
700      if  (domain==functionspace.getDomain()) {      if  (*domain==*functionspace.getDomain()) {
701        return domain.probeInterpolationOnDomain(getFunctionSpace().getTypeCode(),functionspace.getTypeCode());        return domain->probeInterpolationOnDomain(getFunctionSpace().getTypeCode(),functionspace.getTypeCode());
702      } else {      } else {
703        return domain.probeInterpolationACross(getFunctionSpace().getTypeCode(),functionspace.getDomain(),functionspace.getTypeCode());        return domain->probeInterpolationACross(getFunctionSpace().getTypeCode(),*(functionspace.getDomain()),functionspace.getTypeCode());
704      }      }
705    }    }
706  }  }
# Line 731  Data::gradOn(const FunctionSpace& functi Line 718  Data::gradOn(const FunctionSpace& functi
718    DataTypes::ShapeType grad_shape=getDataPointShape();    DataTypes::ShapeType grad_shape=getDataPointShape();
719    grad_shape.push_back(functionspace.getDim());    grad_shape.push_back(functionspace.getDim());
720    Data out(0.0,grad_shape,functionspace,true);    Data out(0.0,grad_shape,functionspace,true);
721    getDomain().setToGradient(out,*this);    getDomain()->setToGradient(out,*this);
722    blocktimer_increment("grad()", blocktimer_start);    blocktimer_increment("grad()", blocktimer_start);
723    return out;    return out;
724  }  }
# Line 743  Data::grad() const Line 730  Data::grad() const
730    {    {
731      throw DataException("Error - operation not permitted on instances of DataEmpty.");      throw DataException("Error - operation not permitted on instances of DataEmpty.");
732    }    }
733    return gradOn(escript::function(getDomain()));    return gradOn(escript::function(*getDomain()));
734  }  }
735    
736  int  int
# Line 1075  Data::integrate() const Line 1062  Data::integrate() const
1062    delete[] tmp;    delete[] tmp;
1063    delete[] tmp_local;    delete[] tmp_local;
1064  #else  #else
1065    AbstractContinuousDomain::asAbstractContinuousDomain(getDomain()).setToIntegrals(integrals,*this);    AbstractContinuousDomain::asAbstractContinuousDomain(*getDomain()).setToIntegrals(integrals,*this);
1066  #endif  #endif
1067    
1068    //    //
# Line 1645  Data::saveDX(std::string fileName) const Line 1632  Data::saveDX(std::string fileName) const
1632    }    }
1633    boost::python::dict args;    boost::python::dict args;
1634    args["data"]=boost::python::object(this);    args["data"]=boost::python::object(this);
1635    getDomain().saveDX(fileName,args);    getDomain()->saveDX(fileName,args);
1636    return;    return;
1637  }  }
1638    
# Line 1658  Data::saveVTK(std::string fileName) cons Line 1645  Data::saveVTK(std::string fileName) cons
1645    }    }
1646    boost::python::dict args;    boost::python::dict args;
1647    args["data"]=boost::python::object(this);    args["data"]=boost::python::object(this);
1648    getDomain().saveVTK(fileName,args);    getDomain()->saveVTK(fileName,args);
1649    return;    return;
1650  }  }
1651    
# Line 1997  void Line 1984  void
1984  Data::setTaggedValueByName(std::string name,  Data::setTaggedValueByName(std::string name,
1985                             const boost::python::object& value)                             const boost::python::object& value)
1986  {  {
1987       if (getFunctionSpace().getDomain().isValidTagName(name)) {       if (getFunctionSpace().getDomain()->isValidTagName(name)) {
1988          int tagKey=getFunctionSpace().getDomain().getTag(name);          int tagKey=getFunctionSpace().getDomain()->getTag(name);
1989          setTaggedValue(tagKey,value);          setTaggedValue(tagKey,value);
1990       }       }
1991  }  }
# Line 2038  Data::setTaggedValue(int tagKey, Line 2025  Data::setTaggedValue(int tagKey,
2025      m_data->setTaggedValue(tagKey,tempShape, temp_data2);      m_data->setTaggedValue(tagKey,tempShape, temp_data2);
2026  }  }
2027    
 // void  
 // Data::setTaggedValueFromCPP(int tagKey,  
 //                             const DataArrayView& value)  
 // {  
 //   if (isProtected()) {  
 //         throw DataException("Error - attempt to update protected Data object.");  
 //   }  
 //   //  
 //   // Ensure underlying data object is of type DataTagged  
 //   if (isConstant()) tag();  
 //  
 //   //  
 //   // Call DataAbstract::setTaggedValue  
 //   m_data->setTaggedValue(tagKey,value);  
 // }  
2028    
2029  void  void
2030  Data::setTaggedValueFromCPP(int tagKey,  Data::setTaggedValueFromCPP(int tagKey,

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

  ViewVC Help
Powered by ViewVC 1.1.26