/[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 97 by jgs, Tue Dec 14 05:39:33 2004 UTC revision 110 by jgs, Mon Feb 14 04:14:42 2005 UTC
# Line 460  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 539  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  {  {
# Line 552  Data::sup() const Line 589  Data::sup() const
589  {  {
590    //    //
591    // set the initial maximum value to min possible double    // 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
# Line 566  Data::inf() const Line 603  Data::inf() const
603  Data  Data
604  Data::maxval() const  Data::maxval() const
605  {  {
606    // not implemented - will use dp_algorithm    return dp_algorithm(DataAlgorithmAdapter<FMax>(numeric_limits<double>::max()*-1));
   return (*this);  
607  }  }
608    
609  Data  Data
610  Data::minval() const  Data::minval() const
611  {  {
612    // not implemented - will use dp_algorithm    return dp_algorithm(DataAlgorithmAdapter<FMin>(numeric_limits<double>::max()));
   return (*this);  
613  }  }
614    
615  Data  Data
616  Data::length() const  Data::length() const
617  {  {
618    // not implemented - will use dp_algorithm    return dp_algorithm(DataAlgorithmAdapter<Length>(0));
   return (*this);  
619  }  }
620    
621  Data  Data
622  Data::trace() const  Data::trace() const
623  {  {
624    // not implemented - will use dp_algorithm    return dp_algorithm(DataAlgorithmAdapter<Trace>(0));
   return (*this);  
625  }  }
626    
627  Data  Data
628  Data::transpose(int axis) const  Data::transpose(int axis) const
629  {  {
630    // not implemented    // not implemented
631    return (*this);    throw DataException("Error - Data::transpose not implemented yet.");
632      return Data();
633  }  }
634    
635  Data  void
636  Data::sign() const  Data::saveDX(std::string fileName) const
 {  
   return escript::unaryOp(*this,escript::fsign);  
 }  
   
 Data  
 Data::abs() const  
 {  
   return escript::unaryOp(*this,(Data::UnaryDFunPtr)::fabs);  
 }  
   
 Data  
 Data::neg() const  
 {  
   return escript::unaryOp(*this,negate<double>());  
 }  
   
 Data  
 Data::pos() const  
 {  
   return (*this);  
 }  
   
 Data  
 Data::exp() const  
637  {  {
638    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::exp);    getDomain().saveDX(fileName,*this);
639      return;
640  }  }
641    
642  Data  void
643  Data::sqrt() const  Data::saveVTK(std::string fileName) const
644  {  {
645    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sqrt);    getDomain().saveVTK(fileName,*this);
646      return;
647  }  }
648    
649  Data&  Data&
# Line 959  Data::setItemD(const boost::python::obje Line 971  Data::setItemD(const boost::python::obje
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    setSlice(value,slice_region);    if (getFunctionSpace()!=value.getFunctionSpace()) {
975         setSlice(Data(value,getFunctionSpace()),slice_region);
976      } else {
977         setSlice(value,slice_region);
978      }
979  }  }
980    
981  void  void
# Line 1021  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.97  
changed lines
  Added in v.110

  ViewVC Help
Powered by ViewVC 1.1.26