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

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

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

revision 94 by jgs, Wed Oct 27 00:45:54 2004 UTC revision 110 by jgs, Mon Feb 14 04:14:42 2005 UTC
# Line 38  Line 38 
38  #include "escript/Data/DataAlgorithm.h"  #include "escript/Data/DataAlgorithm.h"
39  #include "escript/Data/FunctionSpaceFactory.h"  #include "escript/Data/FunctionSpaceFactory.h"
40  #include "escript/Data/AbstractContinuousDomain.h"  #include "escript/Data/AbstractContinuousDomain.h"
41    #include "escript/Data/UnaryFuncs.h"
42    
43  using namespace std;  using namespace std;
44  using namespace boost::python;  using namespace boost::python;
# Line 49  Data::Data() Line 50  Data::Data()
50    //    //
51    // Default data is type DataEmpty    // Default data is type DataEmpty
52    DataAbstract* temp=new DataEmpty();    DataAbstract* temp=new DataEmpty();
53    m_data=shared_ptr<DataAbstract>(temp);    shared_ptr<DataAbstract> temp_data(temp);
54      m_data=temp_data;
55  }  }
56    
57  Data::Data(double value,  Data::Data(double value,
# Line 75  Data::Data(double value, Line 77  Data::Data(double value,
77    initialise(temp.getView(),what,expanded);    initialise(temp.getView(),what,expanded);
78  }  }
79    
80  Data::Data(const Data& inData):  Data::Data(const Data& inData)
   m_data(inData.m_data)  
81  {  {
82      m_data=inData.m_data;
83  }  }
84    
85  Data::Data(const Data& inData,  Data::Data(const Data& inData,
86             const DataArrayView::RegionType& region)             const DataArrayView::RegionType& region)
87  {  {
88    //    //
89    // Create data which is a subset(slice) of another Data    // Create Data which is a slice of another Data
90    DataAbstract* tmp=inData.m_data->getSlice(region);    DataAbstract* tmp = inData.m_data->getSlice(region);
91    m_data=shared_ptr<DataAbstract>(tmp);    shared_ptr<DataAbstract> temp_data(tmp);
92      m_data=temp_data;
93  }  }
94    
95  Data::Data(const Data& inData,  Data::Data(const Data& inData,
# Line 117  Data::Data(const DataTagged::TagListType Line 120  Data::Data(const DataTagged::TagListType
120             bool expanded)             bool expanded)
121  {  {
122    DataAbstract* temp=new DataTagged(tagKeys,values,defaultValue,what);    DataAbstract* temp=new DataTagged(tagKeys,values,defaultValue,what);
123    m_data=shared_ptr<DataAbstract>(temp);    shared_ptr<DataAbstract> temp_data(temp);
124      m_data=temp_data;
125    if (expanded) {    if (expanded) {
126      expand();      expand();
127    }    }
# Line 212  Data::copy(const Data& other) Line 216  Data::copy(const Data& other)
216        //        //
217        // Construct a DataExpanded copy        // Construct a DataExpanded copy
218        DataAbstract* newData=new DataExpanded(*temp);        DataAbstract* newData=new DataExpanded(*temp);
219        m_data=shared_ptr<DataAbstract>(newData);        shared_ptr<DataAbstract> temp_data(newData);
220          m_data=temp_data;
221        return;        return;
222      }      }
223    }    }
# Line 220  Data::copy(const Data& other) Line 225  Data::copy(const Data& other)
225      DataTagged* temp=dynamic_cast<DataTagged*>(other.m_data.get());      DataTagged* temp=dynamic_cast<DataTagged*>(other.m_data.get());
226      if (temp!=0) {      if (temp!=0) {
227        //        //
228        // Construct a DataTaggeded copy        // Construct a DataTagged copy
229        DataAbstract* newData=new DataTagged(*temp);        DataAbstract* newData=new DataTagged(*temp);
230        m_data=shared_ptr<DataAbstract>(newData);        shared_ptr<DataAbstract> temp_data(newData);
231          m_data=temp_data;
232        return;        return;
233      }      }
234    }    }
# Line 232  Data::copy(const Data& other) Line 238  Data::copy(const Data& other)
238        //        //
239        // Construct a DataConstant copy        // Construct a DataConstant copy
240        DataAbstract* newData=new DataConstant(*temp);        DataAbstract* newData=new DataConstant(*temp);
241        m_data=shared_ptr<DataAbstract>(newData);        shared_ptr<DataAbstract> temp_data(newData);
242          m_data=temp_data;
243          return;
244        }
245      }
246      {
247        DataEmpty* temp=dynamic_cast<DataEmpty*>(other.m_data.get());
248        if (temp!=0) {
249          //
250          // Construct a DataEmpty copy
251          DataAbstract* newData=new DataEmpty();
252          shared_ptr<DataAbstract> temp_data(newData);
253          m_data=temp_data;
254        return;        return;
255      }      }
256    }    }
# Line 284  Data::isConstant() const Line 302  Data::isConstant() const
302    return (temp!=0);    return (temp!=0);
303  }  }
304    
 Data  
 Data::getSlice(const DataArrayView::RegionType& region) const  
 {  
   return Data(*this,region);  
 }  
   
 void  
 Data::setSlice(const Data& value,  
                const DataArrayView::RegionType& region)  
 {  
   m_data->setSlice(value.m_data.get(), region);  
 }  
   
305  void  void
306  Data::expand()  Data::expand()
307  {  {
308    if (isConstant()) {    if (isConstant()) {
309      DataConstant* tempDataConst=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* tempDataConst=dynamic_cast<DataConstant*>(m_data.get());
310      DataAbstract* temp=new DataExpanded(*tempDataConst);      DataAbstract* temp=new DataExpanded(*tempDataConst);
311      m_data=shared_ptr<DataAbstract>(temp);      shared_ptr<DataAbstract> temp_data(temp);
312        m_data=temp_data;
313    } else if (isTagged()) {    } else if (isTagged()) {
314      DataTagged* tempDataTag=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* tempDataTag=dynamic_cast<DataTagged*>(m_data.get());
315      DataAbstract* temp=new DataExpanded(*tempDataTag);      DataAbstract* temp=new DataExpanded(*tempDataTag);
316      m_data=shared_ptr<DataAbstract>(temp);      shared_ptr<DataAbstract> temp_data(temp);
317        m_data=temp_data;
318    } else if (isExpanded()) {    } else if (isExpanded()) {
319      //      //
320      // do nothing      // do nothing
# Line 319  Data::expand() Line 326  Data::expand()
326  }  }
327    
328  void  void
 Data::reshapeDataPoint(const DataArrayView::ShapeType& shape)  
 {  
   m_data->reshapeDataPoint(shape);  
 }  
   
 void  
329  Data::tag()  Data::tag()
330  {  {
331    if (isConstant()) {    if (isConstant()) {
332      DataConstant* tempDataConst=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* tempDataConst=dynamic_cast<DataConstant*>(m_data.get());
333      DataAbstract* temp=new DataTagged(*tempDataConst);      DataAbstract* temp=new DataTagged(*tempDataConst);
334      m_data=shared_ptr<DataAbstract>(temp);      shared_ptr<DataAbstract> temp_data(temp);
335        m_data=temp_data;
336    } else if (isTagged()) {    } else if (isTagged()) {
337      // do nothing      // do nothing
338    } else if (isExpanded()) {    } else if (isExpanded()) {
# Line 342  Data::tag() Line 344  Data::tag()
344    }    }
345  }  }
346    
347    void
348    Data::reshapeDataPoint(const DataArrayView::ShapeType& shape)
349    {
350      m_data->reshapeDataPoint(shape);
351    }
352    
353  Data  Data
354  Data::wherePositive() const  Data::wherePositive() const
355  {  {
# Line 349  Data::wherePositive() const Line 357  Data::wherePositive() const
357  }  }
358    
359  Data  Data
360    Data::whereNegative() const
361    {
362      return escript::unaryOp(*this,bind2nd(less<double>(),0.0));
363    }
364    
365    Data
366  Data::whereNonNegative() const  Data::whereNonNegative() const
367  {  {
368    return escript::unaryOp(*this,bind2nd(greater_equal<double>(),0.0));    return escript::unaryOp(*this,bind2nd(greater_equal<double>(),0.0));
369  }  }
370    
371  Data  Data
372  Data::whereNegative() const  Data::whereNonPositive() const
373  {  {
374    return escript::unaryOp(*this,bind2nd(less<double>(),0.0));    return escript::unaryOp(*this,bind2nd(less_equal<double>(),0.0));
375  }  }
376    
377  Data  Data
# Line 367  Data::whereZero() const Line 381  Data::whereZero() const
381  }  }
382    
383  Data  Data
384    Data::whereNonZero() const
385    {
386      return escript::unaryOp(*this,bind2nd(not_equal_to<double>(),0.0));
387    }
388    
389    Data
390  Data::interpolate(const FunctionSpace& functionspace) const  Data::interpolate(const FunctionSpace& functionspace) const
391  {  {
392    return Data(*this,functionspace);    return Data(*this,functionspace);
# Line 440  Data::integrate() const Line 460  Data::integrate() const
460    // and load the array with the integral values    // and load the array with the integral values
461    boost::python::numeric::array bp_array(1.0);    boost::python::numeric::array bp_array(1.0);
462    if (rank==0) {    if (rank==0) {
463        bp_array.resize(1);
464      index = 0;      index = 0;
465      bp_array[0] = integrals[index];      bp_array[0] = integrals[index];
466    }    }
# Line 519  Data::ln() const Line 540  Data::ln() const
540    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log);
541  }  }
542    
543    Data
544    Data::sign() const
545    {
546      return escript::unaryOp(*this,escript::fsign);
547    }
548    
549    Data
550    Data::abs() const
551    {
552      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::fabs);
553    }
554    
555    Data
556    Data::neg() const
557    {
558      return escript::unaryOp(*this,negate<double>());
559    }
560    
561    Data
562    Data::pos() const
563    {
564      return (*this);
565    }
566    
567    Data
568    Data::exp() const
569    {
570      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::exp);
571    }
572    
573    Data
574    Data::sqrt() const
575    {
576      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sqrt);
577    }
578    
579  double  double
580  Data::Lsup() const  Data::Lsup() const
581  {  {
582    //    //
583    // set the initial absolute maximum value to min possible    // set the initial absolute maximum value to zero
584    return algorithm(DataAlgorithmAdapter<AbsMax>(numeric_limits<double>::min()));    return algorithm(DataAlgorithmAdapter<AbsMax>(0));
585  }  }
586    
587  double  double
588  Data::sup() const  Data::sup() const
589  {  {
590    //    //
591    // set the initial maximum value to min possible    // set the initial maximum value to min possible double
592    return algorithm(DataAlgorithmAdapter<FMax>(numeric_limits<double>::min()));    return algorithm(DataAlgorithmAdapter<FMax>(numeric_limits<double>::max()*-1));
593  }  }
594    
595  double  double
596  Data::inf() const  Data::inf() const
597  {  {
598    //    //
599    // set the initial minimum value to max possible    // set the initial minimum value to max possible double
600    return algorithm(DataAlgorithmAdapter<FMin>(numeric_limits<double>::max()));    return algorithm(DataAlgorithmAdapter<FMin>(numeric_limits<double>::max()));
601  }  }
602    
603  Data& Data::operator+=(const Data& right)  Data
604    Data::maxval() const
605    {
606      return dp_algorithm(DataAlgorithmAdapter<FMax>(numeric_limits<double>::max()*-1));
607    }
608    
609    Data
610    Data::minval() const
611    {
612      return dp_algorithm(DataAlgorithmAdapter<FMin>(numeric_limits<double>::max()));
613    }
614    
615    Data
616    Data::length() const
617    {
618      return dp_algorithm(DataAlgorithmAdapter<Length>(0));
619    }
620    
621    Data
622    Data::trace() const
623    {
624      return dp_algorithm(DataAlgorithmAdapter<Trace>(0));
625    }
626    
627    Data
628    Data::transpose(int axis) const
629    {
630      // not implemented
631      throw DataException("Error - Data::transpose not implemented yet.");
632      return Data();
633    }
634    
635    void
636    Data::saveDX(std::string fileName) const
637    {
638      getDomain().saveDX(fileName,*this);
639      return;
640    }
641    
642    void
643    Data::saveVTK(std::string fileName) const
644    {
645      getDomain().saveVTK(fileName,*this);
646      return;
647    }
648    
649    Data&
650    Data::operator+=(const Data& right)
651  {  {
652    binaryOp(right,plus<double>());    binaryOp(right,plus<double>());
653    return (*this);    return (*this);
654  }  }
655    
656  Data& Data::operator+=(const boost::python::object& right)  Data&
657    Data::operator+=(const boost::python::object& right)
658  {  {
659    binaryOp(right,plus<double>());    binaryOp(right,plus<double>());
660    return (*this);    return (*this);
661  }  }
662    
663  Data& Data::operator-=(const Data& right)  Data&
664    Data::operator-=(const Data& right)
665  {  {
666    binaryOp(right,minus<double>());    binaryOp(right,minus<double>());
667    return (*this);    return (*this);
668  }  }
669    
670  Data& Data::operator-=(const boost::python::object& right)  Data&
671    Data::operator-=(const boost::python::object& right)
672  {  {
673    binaryOp(right,minus<double>());    binaryOp(right,minus<double>());
674    return (*this);    return (*this);
675  }  }
676    
677  Data& Data::operator*=(const Data& right)  Data&
678    Data::operator*=(const Data& right)
679  {  {
680    binaryOp(right,multiplies<double>());    binaryOp(right,multiplies<double>());
681    return (*this);    return (*this);
682  }  }
683    
684  Data& Data::operator*=(const boost::python::object& right)  Data&
685    Data::operator*=(const boost::python::object& right)
686  {  {
687    binaryOp(right,multiplies<double>());    binaryOp(right,multiplies<double>());
688    return (*this);    return (*this);
689  }  }
690    
691  Data& Data::operator/=(const Data& right)  Data&
692    Data::operator/=(const Data& right)
693  {  {
694    binaryOp(right,divides<double>());    binaryOp(right,divides<double>());
695    return (*this);    return (*this);
696  }  }
697    
698  Data& Data::operator/=(const boost::python::object& right)  Data&
699    Data::operator/=(const boost::python::object& right)
700  {  {
701    binaryOp(right,divides<double>());    binaryOp(right,divides<double>());
702    return (*this);    return (*this);
703  }  }
704    
705  Data Data::powO(const boost::python::object& right) const  Data
706    Data::powO(const boost::python::object& right) const
707  {  {
708    Data result;    Data result;
709    result.copy(*this);    result.copy(*this);
# Line 599  Data Data::powO(const boost::python::obj Line 711  Data Data::powO(const boost::python::obj
711    return result;    return result;
712  }  }
713    
714  Data Data::powD(const Data& right) const  Data
715    Data::powD(const Data& right) const
716  {  {
717    Data result;    Data result;
718    result.copy(*this);    result.copy(*this);
# Line 609  Data Data::powD(const Data& right) const Line 722  Data Data::powD(const Data& right) const
722    
723  //  //
724  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namepsace this operator belongs to
725  Data escript::operator+(const Data& left, const Data& right)  Data
726    escript::operator+(const Data& left, const Data& right)
727  {  {
728    Data result;    Data result;
729    //    //
# Line 621  Data escript::operator+(const Data& left Line 735  Data escript::operator+(const Data& left
735    
736  //  //
737  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namepsace this operator belongs to
738  Data escript::operator-(const Data& left, const Data& right)  Data
739    escript::operator-(const Data& left, const Data& right)
740  {  {
741    Data result;    Data result;
742    //    //
# Line 633  Data escript::operator-(const Data& left Line 748  Data escript::operator-(const Data& left
748    
749  //  //
750  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namepsace this operator belongs to
751  Data escript::operator*(const Data& left, const Data& right)  Data
752    escript::operator*(const Data& left, const Data& right)
753  {  {
754    Data result;    Data result;
755    //    //
# Line 645  Data escript::operator*(const Data& left Line 761  Data escript::operator*(const Data& left
761    
762  //  //
763  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namepsace this operator belongs to
764  Data escript::operator/(const Data& left, const Data& right)  Data
765    escript::operator/(const Data& left, const Data& right)
766  {  {
767    Data result;    Data result;
768    //    //
# Line 657  Data escript::operator/(const Data& left Line 774  Data escript::operator/(const Data& left
774    
775  //  //
776  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namepsace this operator belongs to
777  Data escript::operator+(const Data& left, const boost::python::object& right)  Data
778    escript::operator+(const Data& left, const boost::python::object& right)
779  {  {
780    //    //
781    // Convert to DataArray format if possible    // Convert to DataArray format if possible
# Line 672  Data escript::operator+(const Data& left Line 790  Data escript::operator+(const Data& left
790    
791  //  //
792  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namepsace this operator belongs to
793  Data escript::operator-(const Data& left, const boost::python::object& right)  Data
794    escript::operator-(const Data& left, const boost::python::object& right)
795  {  {
796    //    //
797    // Convert to DataArray format if possible    // Convert to DataArray format if possible
# Line 687  Data escript::operator-(const Data& left Line 806  Data escript::operator-(const Data& left
806    
807  //  //
808  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namepsace this operator belongs to
809  Data escript::operator*(const Data& left, const boost::python::object& right)  Data
810    escript::operator*(const Data& left, const boost::python::object& right)
811  {  {
812    //    //
813    // Convert to DataArray format if possible    // Convert to DataArray format if possible
# Line 702  Data escript::operator*(const Data& left Line 822  Data escript::operator*(const Data& left
822    
823  //  //
824  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namepsace this operator belongs to
825  Data escript::operator/(const Data& left, const boost::python::object& right)  Data
826    escript::operator/(const Data& left, const boost::python::object& right)
827  {  {
828    //    //
829    // Convert to DataArray format if possible    // Convert to DataArray format if possible
# Line 717  Data escript::operator/(const Data& left Line 838  Data escript::operator/(const Data& left
838    
839  //  //
840  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namepsace this operator belongs to
841  Data escript::operator+(const boost::python::object& left, const Data& right)  Data
842    escript::operator+(const boost::python::object& left, const Data& right)
843  {  {
844    //    //
845    // Construct the result using the given value and the other parameters    // Construct the result using the given value and the other parameters
# Line 729  Data escript::operator+(const boost::pyt Line 851  Data escript::operator+(const boost::pyt
851    
852  //  //
853  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namepsace this operator belongs to
854  Data escript::operator-(const boost::python::object& left, const Data& right)  Data
855    escript::operator-(const boost::python::object& left, const Data& right)
856  {  {
857    //    //
858    // Construct the result using the given value and the other parameters    // Construct the result using the given value and the other parameters
# Line 741  Data escript::operator-(const boost::pyt Line 864  Data escript::operator-(const boost::pyt
864    
865  //  //
866  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namepsace this operator belongs to
867  Data escript::operator*(const boost::python::object& left, const Data& right)  Data
868    escript::operator*(const boost::python::object& left, const Data& right)
869  {  {
870    //    //
871    // Construct the result using the given value and the other parameters    // Construct the result using the given value and the other parameters
# Line 753  Data escript::operator*(const boost::pyt Line 877  Data escript::operator*(const boost::pyt
877    
878  //  //
879  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namepsace this operator belongs to
880  Data escript::operator/(const boost::python::object& left, const Data& right)  Data
881    escript::operator/(const boost::python::object& left, const Data& right)
882  {  {
883    //    //
884    // Construct the result using the given value and the other parameters    // Construct the result using the given value and the other parameters
# Line 765  Data escript::operator/(const boost::pyt Line 890  Data escript::operator/(const boost::pyt
890    
891  //  //
892  // NOTE: It is essential to specify the namepsace this operator belongs to  // NOTE: It is essential to specify the namepsace this operator belongs to
893  bool escript::operator==(const Data& left, const Data& right)  //bool escript::operator==(const Data& left, const Data& right)
894  {  //{
895    /*  //  /*
896    NB: this operator does very little at this point, and isn't to  //  NB: this operator does very little at this point, and isn't to
897    be relied on. Requires further implementation.  //  be relied on. Requires further implementation.
898    */  //  */
899    //
900    bool ret;  //  bool ret;
901    //
902    if (left.isEmpty()) {  //  if (left.isEmpty()) {
903      if(!right.isEmpty()) {  //    if(!right.isEmpty()) {
904        ret = false;  //      ret = false;
905      } else {  //    } else {
906        ret = true;  //      ret = true;
907      }  //    }
908    }  //  }
909    //
910    //  if (left.isConstant()) {
911    //    if(!right.isConstant()) {
912    //      ret = false;
913    //    } else {
914    //      ret = true;
915    //    }
916    // }
917    //
918    //  if (left.isTagged()) {
919    //   if(!right.isTagged()) {
920    //      ret = false;
921    //    } else {
922    //      ret = true;
923    //    }
924    //  }
925    //
926    //  if (left.isExpanded()) {
927    //    if(!right.isExpanded()) {
928    //      ret = false;
929    //    } else {
930    //      ret = true;
931    //    }
932    //  }
933    //
934    //  return ret;
935    //}
936    
937    if (left.isConstant()) {  Data
938      if(!right.isConstant()) {  Data::getItem(const boost::python::object& key) const
939        ret = false;  {
940      } else {    const DataArrayView& view=getPointDataView();
       ret = true;  
     }  
   }  
941    
942    if (left.isTagged()) {    DataArrayView::RegionType slice_region=view.getSliceRegion(key);
     if(!right.isTagged()) {  
       ret = false;  
     } else {  
       ret = true;  
     }  
   }  
943    
944    if (left.isExpanded()) {    if (slice_region.size()!=view.getRank()) {
945      if(!right.isExpanded()) {      throw DataException("Error - slice size does not match Data rank.");
       ret = false;  
     } else {  
       ret = true;  
     }  
946    }    }
947    
948    return ret;    return getSlice(slice_region);
949  }  }
950    
951  Data  Data
952  Data::getItem(const boost::python::object& key) const  Data::getSlice(const DataArrayView::RegionType& region) const
953    {
954      return Data(*this,region);
955    }
956    
957    void
958    Data::setItemO(const boost::python::object& key,
959                   const boost::python::object& value)
960  {  {
961     const DataArrayView& view=getPointDataView();    Data tempData(value,getFunctionSpace());
962     DataArrayView::RegionType slice_region=view.getSliceRegion(key);    setItemD(key,tempData);
    if (slice_region.size()!=view.getRank()) {  
      throw DataException("Error - slice size does not match Data rank.");  
      return Data();  
    }  
    //  
    // Create a new Data which is a slice of this one  
    return getSlice(slice_region);  
963  }  }
964    
965  void  void
966  Data::setItem(const boost::python::object& key,  Data::setItemD(const boost::python::object& key,
967                const Data& value)                 const Data& value)
968  {  {
969    const DataArrayView& view=getPointDataView();    const DataArrayView& view=getPointDataView();
970    DataArrayView::RegionType slice_region=view.getSliceRegion(key);    DataArrayView::RegionType slice_region=view.getSliceRegion(key);
971    if (slice_region.size()!=view.getRank()) {    if (slice_region.size()!=view.getRank()) {
972      throw DataException("Error - slice size does not match Data rank.");      throw DataException("Error - slice size does not match Data rank.");
973    }    }
974    typeMatch(value);    if (getFunctionSpace()!=value.getFunctionSpace()) {
975    setSlice(value,slice_region);       setSlice(Data(value,getFunctionSpace()),slice_region);
976      } else {
977         setSlice(value,slice_region);
978      }
979  }  }
980    
981  void  void
982  Data::typeMatch(const Data& right)  Data::setSlice(const Data& value,
983                   const DataArrayView::RegionType& region)
984    {
985      Data tempValue(value);
986      typeMatchLeft(tempValue);
987      typeMatchRight(tempValue);
988      m_data->setSlice(tempValue.m_data.get(),region);
989    }
990    
991    void
992    Data::typeMatchLeft(Data& right) const
993    {
994      if (isExpanded()){
995        right.expand();
996      } else if (isTagged()) {
997        if (right.isConstant()) {
998          right.tag();
999        }
1000      }
1001    }
1002    
1003    void
1004    Data::typeMatchRight(const Data& right)
1005  {  {
   //  
   // match the type of this to the RHS  
1006    if (isTagged()) {    if (isTagged()) {
1007      if (right.isExpanded()) {      if (right.isExpanded()) {
       //  
       // if the right hand side is expanded so must this  
1008        expand();        expand();
1009      }      }
1010    } else if (isConstant()) {    } else if (isConstant()) {
1011      if (right.isExpanded()) {      if (right.isExpanded()) {
       //  
       // if the right hand side is expanded so must this  
1012        expand();        expand();
1013      } else if (right.isTagged()) {      } else if (right.isTagged()) {
       //  
       // if the right hand side is tagged so must this  
1014        tag();        tag();
1015      }      }
1016    }    }
# Line 881  Data::setTaggedValue(int tagKey, Line 1037  Data::setTaggedValue(int tagKey,
1037    m_data->setTaggedValue(tagKey,valueDataArray.getView());    m_data->setTaggedValue(tagKey,valueDataArray.getView());
1038  }  }
1039    
1040    void
1041    Data::setRefValue(int ref,
1042                      const boost::python::numeric::array& value)
1043    {
1044      //
1045      // Construct DataArray from boost::python::object input value
1046      DataArray valueDataArray(value);
1047    
1048      //
1049      // Call DataAbstract::setRefValue
1050      m_data->setRefValue(ref,valueDataArray);
1051    }
1052    
1053    void
1054    Data::getRefValue(int ref,
1055                      boost::python::numeric::array& value)
1056    {
1057      //
1058      // Construct DataArray for boost::python::object return value
1059      DataArray valueDataArray(value);
1060    
1061      //
1062      // Load DataArray with values from data-points specified by ref
1063      m_data->getRefValue(ref,valueDataArray);
1064    
1065      //
1066      // Load values from valueDataArray into return numarray
1067    
1068      // extract the shape of the numarray
1069      int rank = value.getrank();
1070      DataArrayView::ShapeType shape;
1071      for (int i=0; i < rank; i++) {
1072        shape.push_back(extract<int>(value.getshape()[i]));
1073      }
1074    
1075      // and load the numarray with the data from the DataArray
1076      DataArrayView valueView = valueDataArray.getView();
1077    
1078      if (rank==0) {
1079        throw DataException("Data::getRefValue error: only rank 1 data handled for now.");
1080      }
1081      if (rank==1) {
1082        for (int i=0; i < shape[0]; i++) {
1083          value[i] = valueView(i);
1084        }
1085      }
1086      if (rank==2) {
1087        throw DataException("Data::getRefValue error: only rank 1 data handled for now.");
1088      }
1089      if (rank==3) {
1090        throw DataException("Data::getRefValue error: only rank 1 data handled for now.");
1091      }
1092      if (rank==4) {
1093        throw DataException("Data::getRefValue error: only rank 1 data handled for now.");
1094      }
1095    
1096    }
1097    
1098  /*  /*
1099  Note: this version removed for now. Not needed, and breaks escript.cpp  Note: this version removed for now. Not needed, and breaks escript.cpp
1100  void  void

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

  ViewVC Help
Powered by ViewVC 1.1.26